From ffb9068fb6b051eb1948637783e93f65506b5449 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 2 Dec 2023 12:33:14 -0800 Subject: [PATCH] Unit test fixes and code cleanup --- Makefile | 12 ++++++------ pkg/branding/branding.go | 2 +- pkg/collision/level_test.go | 2 +- pkg/drawtool/history_test.go | 4 ++-- pkg/editor_ui.go | 2 +- pkg/gamepad/gamepad.go | 10 +++++----- pkg/level/chunk_test.go | 4 ++-- pkg/level/chunker.go | 2 +- pkg/level/chunker_test.go | 12 ++++++------ pkg/level/filesystem.go | 4 ++-- pkg/level/fmt_json.go | 2 +- pkg/uix/canvas_editable.go | 2 +- pkg/wallpaper/wallpaper_test.go | 2 +- 13 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 73281b1..5f0a70f 100644 --- a/Makefile +++ b/Makefile @@ -17,8 +17,8 @@ setup: clean # `make build` to build the binary. .PHONY: build build: - go build $(LDFLAGS) -i -o bin/sketchymaze cmd/doodle/main.go - go build $(LDFLAGS) -i -o bin/doodad cmd/doodad/main.go + go build $(LDFLAGS) -o bin/sketchymaze cmd/doodle/main.go + go build $(LDFLAGS) -o bin/doodad cmd/doodad/main.go # `make buildall` to run all build steps including doodads. .PHONY: buildall @@ -28,15 +28,15 @@ buildall: doodads build .PHONY: build-free build-free: gofmt -w . - go build $(LDFLAGS) -tags="shareware" -i -o bin/sketchymaze cmd/doodle/main.go - go build $(LDFLAGS) -tags="shareware" -i -o bin/doodad cmd/doodad/main.go + go build $(LDFLAGS) -tags="shareware" -o bin/sketchymaze cmd/doodle/main.go + go build $(LDFLAGS) -tags="shareware" -o bin/doodad cmd/doodad/main.go # `make build-debug` to build the binary in developer mode. .PHONY: build-debug build-debug: gofmt -w . - go build $(LDFLAGS) -tags="developer" -i -o bin/sketchymaze cmd/doodle/main.go - go build $(LDFLAGS) -tags="developer" -i -o bin/doodad cmd/doodad/main.go + go build $(LDFLAGS) -tags="developer" -o bin/sketchymaze cmd/doodle/main.go + go build $(LDFLAGS) -tags="developer" -o bin/doodad cmd/doodad/main.go # `make bindata` generates the embedded binary assets package. .PHONY: bindata diff --git a/pkg/branding/branding.go b/pkg/branding/branding.go index ea1551b..b5dc5b4 100644 --- a/pkg/branding/branding.go +++ b/pkg/branding/branding.go @@ -11,7 +11,7 @@ const ( Summary = "A drawing-based maze game" Version = "0.13.2" Website = "https://www.sketchymaze.com" - Copyright = "2022 Noah Petherbridge" + Copyright = "2023 Noah Petherbridge" Byline = "a game by Noah Petherbridge." // Update check URL diff --git a/pkg/collision/level_test.go b/pkg/collision/level_test.go index c3854ef..792f360 100644 --- a/pkg/collision/level_test.go +++ b/pkg/collision/level_test.go @@ -12,7 +12,7 @@ import ( func TestCollisionFunctions(t *testing.T) { // Create a basic level for testing. - grid := level.NewChunker(1000) + grid := level.NewChunker(128) solid := &level.Swatch{ Name: "solid", Color: render.Black, diff --git a/pkg/drawtool/history_test.go b/pkg/drawtool/history_test.go index 431821f..fd87d89 100644 --- a/pkg/drawtool/history_test.go +++ b/pkg/drawtool/history_test.go @@ -94,7 +94,7 @@ func TestHistory(t *testing.T) { // Add a few more points. for i := 3; i <= 6; i++ { H.AddStroke(&Stroke{ - PointA: render.NewPoint(int32(i), int32(i)), + PointA: render.NewPoint(i, i), }) } shouldInt("after adding more strokes", 6, H.Size()) @@ -116,7 +116,7 @@ func TestHistory(t *testing.T) { // Overflow past our history size to test rollover. for i := 8; i <= 16; i++ { H.AddStroke(&Stroke{ - PointA: render.NewPoint(int32(i), int32(i)), + PointA: render.NewPoint(i, i), }) } shouldInt("after tons of new history, size is capped out", 10, H.Size()) diff --git a/pkg/editor_ui.go b/pkg/editor_ui.go index 75b2c34..352d5f4 100644 --- a/pkg/editor_ui.go +++ b/pkg/editor_ui.go @@ -419,7 +419,7 @@ func (u *EditorUI) SetupCanvas(d *Doodle) *uix.Canvas { // mode when you click an existing Doodad and it "pops" out of the canvas // and onto the cursor to be repositioned. drawing.OnDragStart = func(actor *level.Actor) { - log.Warn("drawing.OnDragStart: grab actor %s", actor) + log.Warn("drawing.OnDragStart: grab actor %s", actor.Filename) u.startDragActor(nil, actor) } diff --git a/pkg/gamepad/gamepad.go b/pkg/gamepad/gamepad.go index deb7ba4..8fa49ec 100644 --- a/pkg/gamepad/gamepad.go +++ b/pkg/gamepad/gamepad.go @@ -1,12 +1,12 @@ /* Package gamepad provides game controller logic for the game. -Controls +# Controls The gamepad controls are currently hard-coded for Xbox 360 style controllers, and the controller mappings vary depending on the "mode" of control. -N Style and X Style +# N Style and X Style If the gamepad control is set to "NStyle" then the A/B and X/Y buttons will be swapped to match the labels of a Nintendo style controller. Since the game has relatively few @@ -16,7 +16,7 @@ defined as: PrimaryButton: A or X button SecondaryButton: B or Y button -Mouse Mode +# Mouse Mode - Left stick moves the mouse cursor (a cursor sprite is drawn on screen) - Right stick scrolls the level (title screen or level editor) @@ -26,7 +26,7 @@ Mouse Mode - Left Trigger (L2) closes the top-most window in the Editor (Backspace key) - Right Shoulder toggles between Mouse Mode and other scene-specific mode. -Gameplay Mode +# Gameplay Mode - Left stick moves the player character (left/right only). - D-Pad also moves the player character (left/right only). @@ -125,7 +125,7 @@ func Loop(ev *event.State) { if len(ev.Controllers) > 0 { for idx, ctrl := range ev.Controllers { SetControllerIndex(idx) - log.Info("Gamepad: using controller #%d (%d) as Player 1", idx, ctrl.Name()) + log.Info("Gamepad: using controller #%d (%s) as Player 1", idx, ctrl.Name()) break } } else { diff --git a/pkg/level/chunk_test.go b/pkg/level/chunk_test.go index 33112e8..43c4300 100644 --- a/pkg/level/chunk_test.go +++ b/pkg/level/chunk_test.go @@ -10,7 +10,7 @@ import ( // Test the high level Chunker. func TestChunker(t *testing.T) { - c := level.NewChunker(1000) + c := level.NewChunker(128) // Test swatches. var ( @@ -239,7 +239,7 @@ func TestMapAccessor(t *testing.T) { // Test the ChunkCoordinate function. func TestChunkCoordinates(t *testing.T) { - c := level.NewChunker(1000) + c := level.NewChunker(128) type testCase struct { In render.Point diff --git a/pkg/level/chunker.go b/pkg/level/chunker.go index ee97442..6a305d4 100644 --- a/pkg/level/chunker.go +++ b/pkg/level/chunker.go @@ -341,7 +341,7 @@ func (c *Chunker) GetChunk(p render.Point) (*Chunk, bool) { // Is our chunk cache getting too full? e.g. on full level // sweeps where a whole zip file's worth of chunks are scanned. if balance.ChunkerLRUCacheMax > 0 && len(c.Chunks) > balance.ChunkerLRUCacheMax { - log.Error("Chunks in memory (%d) exceeds LRU cache cap of %d, freeing random chunks") + log.Error("Chunks in memory (%d) exceeds LRU cache cap of %d, freeing random chunks", len(c.Chunks), balance.ChunkerLRUCacheMax) c.chunkMu.Lock() defer c.chunkMu.Unlock() diff --git a/pkg/level/chunker_test.go b/pkg/level/chunker_test.go index fa1f7f9..dff40fd 100644 --- a/pkg/level/chunker_test.go +++ b/pkg/level/chunker_test.go @@ -10,14 +10,14 @@ import ( func TestWorldSize(t *testing.T) { type TestCase struct { - Size int + Size uint8 Points []render.Point Expect render.Rect Zero render.Rect // expected WorldSizePositive } var tests = []TestCase{ { - Size: 1000, + Size: 200, Points: []render.Point{ render.NewPoint(0, 0), // chunk 0,0 render.NewPoint(512, 788), // 0,0 @@ -86,9 +86,9 @@ func TestWorldSize(t *testing.T) { func TestViewportChunks(t *testing.T) { // Initialize a 100 chunk image with 5x5 chunks. - var ChunkSize int = 100 + var ChunkSize uint8 = 100 var Offset int = 50 - c := level.NewChunker(int(ChunkSize)) + c := level.NewChunker(ChunkSize) sw := &level.Swatch{ Name: "solid", Color: render.Black, @@ -106,8 +106,8 @@ func TestViewportChunks(t *testing.T) { for x := -2; x <= 2; x++ { for y := -2; y <= 2; y++ { point := render.NewPoint( - x*ChunkSize+Offset, - y*ChunkSize+Offset, + x*int(ChunkSize)+Offset, + y*int(ChunkSize)+Offset, ) fmt.Printf("in chunk: %d,%d set pt: %s\n", x, y, point, diff --git a/pkg/level/filesystem.go b/pkg/level/filesystem.go index 2701db6..5af8a5c 100644 --- a/pkg/level/filesystem.go +++ b/pkg/level/filesystem.go @@ -194,14 +194,14 @@ func (fs *FileSystem) MigrateZipfile(zf *zip.Writer) error { } if _, ok := filesDeleted[file.Name]; ok { - log.Debug("Skip copying attachment %s: was marked for deletion") + log.Debug("Skip copying attachment %s: was marked for deletion", file.Name) continue } // Skip files currently in memory. if fs.filemap != nil { if _, ok := fs.filemap[file.Name]; ok { - log.Debug("Skip copying attachment %s: one is loaded in memory") + log.Debug("Skip copying attachment %s: one is loaded in memory", file.Name) continue } } diff --git a/pkg/level/fmt_json.go b/pkg/level/fmt_json.go index 3d578c1..f7af93d 100644 --- a/pkg/level/fmt_json.go +++ b/pkg/level/fmt_json.go @@ -167,7 +167,7 @@ func (m *Level) ToZipfile() ([]byte, error) { if n, err := writer.Write(header); err != nil { return nil, err } else { - log.Debug("Written level.json to zipfile: %s bytes", n) + log.Debug("Written level.json to zipfile: %d bytes", n) } } diff --git a/pkg/uix/canvas_editable.go b/pkg/uix/canvas_editable.go index c8d9903..90977e2 100644 --- a/pkg/uix/canvas_editable.go +++ b/pkg/uix/canvas_editable.go @@ -420,7 +420,7 @@ func (w *Canvas) loopEditable(ev *event.State) error { baseColor, err := chunker.Get(cursor) if err != nil { limit = balance.FloodToolVoidLimit - log.Warn("FloodTool: couldn't get base color at %s: %s (got %s)", cursor, err) + log.Warn("FloodTool: couldn't get base color at %s: %s (got %s)", cursor, err, baseColor.Color) } // If no change, do nothing. diff --git a/pkg/wallpaper/wallpaper_test.go b/pkg/wallpaper/wallpaper_test.go index 4efcecf..1a61f4d 100644 --- a/pkg/wallpaper/wallpaper_test.go +++ b/pkg/wallpaper/wallpaper_test.go @@ -70,7 +70,7 @@ func TestWallpaper(t *testing.T) { } } - wp, err := FromImage(nil, img, "dummy") + wp, err := FromImage(img, "dummy") if err != nil { t.Errorf("Couldn't create FromImage: %s", err) t.FailNow()