From 2e8da8cb6948664a77fa73cb0c66e0cc27419dc5 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 1 Mar 2026 22:19:04 +0100 Subject: Switch font to Cinzel variable font --- draw.go | 26 ++++++++++---------------- fonts/Cinzel-VariableFont_wght.ttf | Bin 0 -> 126348 bytes main.go | 6 ++++-- physics/move.go | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) create mode 100644 fonts/Cinzel-VariableFont_wght.ttf diff --git a/draw.go b/draw.go index 62960ea..baa8a08 100644 --- a/draw.go +++ b/draw.go @@ -13,6 +13,12 @@ import ( "github.com/hajimehoshi/ebiten/v2/vector" ) +func (g *Game) font(size float64) *text.GoTextFace { + f := &text.GoTextFace{Source: g.FaceSource, Size: size} + f.SetVariation(text.MustParseTag("wght"), 500) + return f +} + func (g *Game) Draw(screen *ebiten.Image) { x, y := ebiten.CursorPosition() cursor := physics.Point{X: x, Y: y} @@ -38,10 +44,7 @@ func (g *Game) Draw(screen *ebiten.Image) { op := &text.DrawOptions{} op.GeoM.Translate(float64(position.X+5), float64(position.Y+30)) op.ColorScale.ScaleWithColor(color.White) - text.Draw(screen, resourceText, &text.GoTextFace{ - Source: g.FaceSource, - Size: 40, - }, op) + text.Draw(screen, resourceText, g.font(40), op) } if mask&ecs.CM_Spawn == ecs.CM_Spawn { spawn := g.Spawn[i] @@ -49,10 +52,7 @@ func (g *Game) Draw(screen *ebiten.Image) { op := &text.DrawOptions{} op.GeoM.Translate(float64(position.X+5), float64(position.Y+70)) op.ColorScale.ScaleWithColor(color.White) - text.Draw(screen, spawnText, &text.GoTextFace{ - Source: g.FaceSource, - Size: 40, - }, op) + text.Draw(screen, spawnText, g.font(40), op) if spawn.SpawnTarget.Ok { spawnTarget := spawn.SpawnTarget.Value vector.DrawFilledCircle(screen, float32(spawnTarget.X+50), float32(spawnTarget.Y+50), 30, Red, true) @@ -91,10 +91,7 @@ func drawTopBanner(screen *ebiten.Image, g *Game) { op := &text.DrawOptions{} op.GeoM.Translate(25, 25) op.ColorScale.ScaleWithColor(color.Black) - text.Draw(screen, resourceText, &text.GoTextFace{ - Source: g.FaceSource, - Size: 100, - }, op) + text.Draw(screen, resourceText, g.font(100), op) } func drawBottomBanner(screen *ebiten.Image, g *Game) { @@ -114,8 +111,5 @@ func drawBottomBanner(screen *ebiten.Image, g *Game) { op := &text.DrawOptions{} op.GeoM.Translate(25, float64(float32(bannerTop)+25)) op.ColorScale.ScaleWithColor(color.Black) - text.Draw(screen, shortcuts, &text.GoTextFace{ - Source: g.FaceSource, - Size: 60, - }, op) + text.Draw(screen, shortcuts, g.font(60), op) } diff --git a/fonts/Cinzel-VariableFont_wght.ttf b/fonts/Cinzel-VariableFont_wght.ttf new file mode 100644 index 0000000..0ae41bc Binary files /dev/null and b/fonts/Cinzel-VariableFont_wght.ttf differ diff --git a/main.go b/main.go index 4e2edf8..3d538b4 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ import ( "github.com/hajimehoshi/ebiten/v2/text/v2" "github.com/martinlehoux/kagamigo/kcore" "golang.org/x/exp/slog" - "golang.org/x/image/font/gofont/goregular" + ) type Action string @@ -205,7 +205,9 @@ func main() { game := &Game{ ResourceAmount: 150, } - s, err := text.NewGoTextFaceSource(bytes.NewReader(goregular.TTF)) + fontData, err := os.ReadFile("fonts/Cinzel-VariableFont_wght.ttf") + kcore.Expect(err, "failed to read font") + s, err := text.NewGoTextFaceSource(bytes.NewReader(fontData)) kcore.Expect(err, "failed to create font source") game.FaceSource = s ironMineBuilder := NewEntityBuilder().WithSolid(NewFilledRectangleImage(physics.Point{X: 100, Y: 100}, color.RGBA{0x80, 0x80, 0x80, 0xff})).WithResourceSource(1000).WithSelectable("square", selection.Building) diff --git a/physics/move.go b/physics/move.go index b898ec7..78b97b7 100644 --- a/physics/move.go +++ b/physics/move.go @@ -194,7 +194,7 @@ func UpdateMoveSystem(moveMap MoveMap, masks []ecs.Mask, moves []Move, positions } // About to snap to next cell — check it's still free if moveMap.Blocked[next] { - slog.Info("cell blocked on arrival, repathing", slog.String("next", next.String())) + slog.Debug("cell blocked on arrival, repathing", slog.String("next", next.String())) path, ok := SearchPath(*position, move.Destination, moveMap) if !ok { slog.Info("no path found", slog.String("destination", move.Destination.String())) -- cgit v1.3