<commit_before>package main

import (
	"fmt"
	"image/color"
	"time"

	twodee "../libs/twodee"
)

type HudLayer struct {
	text        *twodee.TextRenderer
	regularFont *twodee.FontFace
	planetFont  *twodee.FontFace
	globalText  *twodee.TextCache
	timeText    *twodee.TextCache
	tempText    map[int]*twodee.TextCache
	popText     map[int]*twodee.TextCache
	bounds      twodee.Rectangle
	App         *Application
	game        *GameLayer
}

func NewHudLayer(app *Application, game *GameLayer) (layer *HudLayer, err error) {
	var (
		regularFont *twodee.FontFace
		planetFont  *twodee.FontFace
		background  = color.Transparent
		font        = "assets/fonts/Exo-SemiBold.ttf"
	)
	if regularFont, err = twodee.NewFontFace(font, 24, color.RGBA{255, 255, 255, 255}, background); err != nil {
		return
	}
	if planetFont, err = twodee.NewFontFace(font, 18, color.RGBA{255, 255, 255, 255}, background); err != nil {
		return
	}
	layer = &HudLayer{
		regularFont: regularFont,
		planetFont:  planetFont,
		tempText:    map[int]*twodee.TextCache{},
		popText:     map[int]*twodee.TextCache{},
		globalText:  twodee.NewTextCache(regularFont),
		timeText:    twodee.NewTextCache(regularFont),
		App:         app,
		bounds:      twodee.Rect(0, 0, 1024, 768),
		game:        game,
	}
	err = layer.Reset()
	return
}

func (l *HudLayer) Delete() {
	if l.text != nil {
		l.text.Delete()
	}
	for _, v := range l.tempText {
		v.Delete()
	}
	for _, v := range l.popText {
		v.Delete()
	}
	l.globalText.Delete()
	l.timeText.Delete()
}

func (l *HudLayer) Render() {
	var (
		textCache     *twodee.TextCache
		planetPos     twodee.Point
		screenPos     twodee.Point
		adjust        twodee.Point
		ok            bool
		text          string
		x, y          float32
		maxX          = l.bounds.Max.X
		maxY          = l.bounds.Max.Y
		aggPopulation = l.game.Sim.GetPopulation()
		maxPopulation = l.game.Sim.GetMaxPopulation()
	)
	l.text.Bind()

	// Display Aggregate Population Count
	text = fmt.Sprintf("POPULATION: %d     RECORD: %d", aggPopulation, maxPopulation)
	l.globalText.SetText(text)
	if l.globalText.Texture != nil {
		y = maxY - float32(l.globalText.Texture.Height)
		l.text.Draw(l.globalText.Texture, 5, y)
	}

	// Display time remaining.
	s := int64(l.game.DurLeft.Seconds())
	m := s / 60
	s = s % 60
	l.timeText.SetText(fmt.Sprintf("%d:%2d", m, s))
	if l.timeText.Texture != nil {
		y = maxY - float32(l.timeText.Texture.Height)
		// Some fudged padding to make sure there's room for the clock.
		x = maxX - 60.0<commit_msg>Better game clock printing.<commit_after>package main

import (
	"fmt"
	"image/color"
	"time"

	twodee "../libs/twodee"
)

type HudLayer struct {
	text        *twodee.TextRenderer
	regularFont *twodee.FontFace
	planetFont  *twodee.FontFace
	globalText  *twodee.TextCache
	timeText    *twodee.TextCache
	tempText    map[int]*twodee.TextCache
	popText     map[int]*twodee.TextCache
	bounds      twodee.Rectangle
	App         *Application
	game        *GameLayer
}

func NewHudLayer(app *Application, game *GameLayer) (layer *HudLayer, err error) {
	var (
		regularFont *twodee.FontFace
		planetFont  *twodee.FontFace
		background  = color.Transparent
		font        = "assets/fonts/Exo-SemiBold.ttf"
	)
	if regularFont, err = twodee.NewFontFace(font, 24, color.RGBA{255, 255, 255, 255}, background); err != nil {
		return
	}
	if planetFont, err = twodee.NewFontFace(font, 18, color.RGBA{255, 255, 255, 255}, background); err != nil {
		return
	}
	layer = &HudLayer{
		regularFont: regularFont,
		planetFont:  planetFont,
		tempText:    map[int]*twodee.TextCache{},
		popText:     map[int]*twodee.TextCache{},
		globalText:  twodee.NewTextCache(regularFont),
		timeText:    twodee.NewTextCache(regularFont),
		App:         app,
		bounds:      twodee.Rect(0, 0, 1024, 768),
		game:        game,
	}
	err = layer.Reset()
	return
}

func (l *HudLayer) Delete() {
	if l.text != nil {
		l.text.Delete()
	}
	for _, v := range l.tempText {
		v.Delete()
	}
	for _, v := range l.popText {
		v.Delete()
	}
	l.globalText.Delete()
	l.timeText.Delete()
}

func (l *HudLayer) Render() {
	var (
		textCache     *twodee.TextCache
		planetPos     twodee.Point
		screenPos     twodee.Point
		adjust        twodee.Point
		ok            bool
		text          string
		x, y          float32
		maxX          = l.bounds.Max.X
		maxY          = l.bounds.Max.Y
		aggPopulation = l.game.Sim.GetPopulation()
		maxPopulation = l.game.Sim.GetMaxPopulation()
	)
	l.text.Bind()

	// Display Aggregate Population Count
	text = fmt.Sprintf("POPULATION: %d     RECORD: %d", aggPopulation, maxPopulation)
	l.globalText.SetText(text)
	if l.globalText.Texture != nil {
		y = maxY - float32(l.globalText.Texture.Height)
		l.text.Draw(l.globalText.Texture, 5, y)
	}

	// Display time remaining.
	s := int64(l.game.DurLeft.Seconds())
	m := s / 60
	s = s % 60
	if m > 0 {
		text = fmt.Sprintf("%d:%02d", m, s)
	} else {
		text = fmt.Sprintf("%02d", s)
	}
	l.timeText.SetText(text)
	if l.timeText.Texture != nil {
		y = maxY - float32(l.timeText.Texture.Height)
		// Some fudged padding to make sure there's room for the clock.
		x = maxX - 60.0
{'fraction_non_alphanumeric': 0.129796397807361, 'fraction_numerical': 0.02192638997650744, 'mean_word_length': 2.9512761020881673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5853769', 'n_tokens_mistral': 2130, 'n_tokens_neox': 1939, 'n_words': 421}