Unit test fixes and code cleanup

pull/93/head
Noah 2023-12-02 12:33:14 -08:00
parent 79996ccd34
commit ffb9068fb6
13 changed files with 30 additions and 30 deletions

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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())

View File

@ -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)
}

View File

@ -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 {

View File

@ -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

View File

@ -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()

View File

@ -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,

View File

@ -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
}
}

View File

@ -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)
}
}

View File

@ -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.

View File

@ -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()