Unit test fixes and code cleanup
This commit is contained in:
parent
79996ccd34
commit
ffb9068fb6
12
Makefile
12
Makefile
|
@ -17,8 +17,8 @@ setup: clean
|
||||||
# `make build` to build the binary.
|
# `make build` to build the binary.
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
go build $(LDFLAGS) -i -o bin/sketchymaze cmd/doodle/main.go
|
go build $(LDFLAGS) -o bin/sketchymaze cmd/doodle/main.go
|
||||||
go build $(LDFLAGS) -i -o bin/doodad cmd/doodad/main.go
|
go build $(LDFLAGS) -o bin/doodad cmd/doodad/main.go
|
||||||
|
|
||||||
# `make buildall` to run all build steps including doodads.
|
# `make buildall` to run all build steps including doodads.
|
||||||
.PHONY: buildall
|
.PHONY: buildall
|
||||||
|
@ -28,15 +28,15 @@ buildall: doodads build
|
||||||
.PHONY: build-free
|
.PHONY: build-free
|
||||||
build-free:
|
build-free:
|
||||||
gofmt -w .
|
gofmt -w .
|
||||||
go build $(LDFLAGS) -tags="shareware" -i -o bin/sketchymaze cmd/doodle/main.go
|
go build $(LDFLAGS) -tags="shareware" -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/doodad cmd/doodad/main.go
|
||||||
|
|
||||||
# `make build-debug` to build the binary in developer mode.
|
# `make build-debug` to build the binary in developer mode.
|
||||||
.PHONY: build-debug
|
.PHONY: build-debug
|
||||||
build-debug:
|
build-debug:
|
||||||
gofmt -w .
|
gofmt -w .
|
||||||
go build $(LDFLAGS) -tags="developer" -i -o bin/sketchymaze cmd/doodle/main.go
|
go build $(LDFLAGS) -tags="developer" -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/doodad cmd/doodad/main.go
|
||||||
|
|
||||||
# `make bindata` generates the embedded binary assets package.
|
# `make bindata` generates the embedded binary assets package.
|
||||||
.PHONY: bindata
|
.PHONY: bindata
|
||||||
|
|
|
@ -11,7 +11,7 @@ const (
|
||||||
Summary = "A drawing-based maze game"
|
Summary = "A drawing-based maze game"
|
||||||
Version = "0.13.2"
|
Version = "0.13.2"
|
||||||
Website = "https://www.sketchymaze.com"
|
Website = "https://www.sketchymaze.com"
|
||||||
Copyright = "2022 Noah Petherbridge"
|
Copyright = "2023 Noah Petherbridge"
|
||||||
Byline = "a game by Noah Petherbridge."
|
Byline = "a game by Noah Petherbridge."
|
||||||
|
|
||||||
// Update check URL
|
// Update check URL
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
func TestCollisionFunctions(t *testing.T) {
|
func TestCollisionFunctions(t *testing.T) {
|
||||||
// Create a basic level for testing.
|
// Create a basic level for testing.
|
||||||
grid := level.NewChunker(1000)
|
grid := level.NewChunker(128)
|
||||||
solid := &level.Swatch{
|
solid := &level.Swatch{
|
||||||
Name: "solid",
|
Name: "solid",
|
||||||
Color: render.Black,
|
Color: render.Black,
|
||||||
|
|
|
@ -94,7 +94,7 @@ func TestHistory(t *testing.T) {
|
||||||
// Add a few more points.
|
// Add a few more points.
|
||||||
for i := 3; i <= 6; i++ {
|
for i := 3; i <= 6; i++ {
|
||||||
H.AddStroke(&Stroke{
|
H.AddStroke(&Stroke{
|
||||||
PointA: render.NewPoint(int32(i), int32(i)),
|
PointA: render.NewPoint(i, i),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
shouldInt("after adding more strokes", 6, H.Size())
|
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.
|
// Overflow past our history size to test rollover.
|
||||||
for i := 8; i <= 16; i++ {
|
for i := 8; i <= 16; i++ {
|
||||||
H.AddStroke(&Stroke{
|
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())
|
shouldInt("after tons of new history, size is capped out", 10, H.Size())
|
||||||
|
|
|
@ -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
|
// mode when you click an existing Doodad and it "pops" out of the canvas
|
||||||
// and onto the cursor to be repositioned.
|
// and onto the cursor to be repositioned.
|
||||||
drawing.OnDragStart = func(actor *level.Actor) {
|
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)
|
u.startDragActor(nil, actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
Package gamepad provides game controller logic for the game.
|
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
|
The gamepad controls are currently hard-coded for Xbox 360 style controllers, and the
|
||||||
controller mappings vary depending on the "mode" of control.
|
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
|
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
|
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
|
PrimaryButton: A or X button
|
||||||
SecondaryButton: B or Y button
|
SecondaryButton: B or Y button
|
||||||
|
|
||||||
Mouse Mode
|
# Mouse Mode
|
||||||
|
|
||||||
- Left stick moves the mouse cursor (a cursor sprite is drawn on screen)
|
- Left stick moves the mouse cursor (a cursor sprite is drawn on screen)
|
||||||
- Right stick scrolls the level (title screen or level editor)
|
- 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)
|
- Left Trigger (L2) closes the top-most window in the Editor (Backspace key)
|
||||||
- Right Shoulder toggles between Mouse Mode and other scene-specific mode.
|
- Right Shoulder toggles between Mouse Mode and other scene-specific mode.
|
||||||
|
|
||||||
Gameplay Mode
|
# Gameplay Mode
|
||||||
|
|
||||||
- Left stick moves the player character (left/right only).
|
- Left stick moves the player character (left/right only).
|
||||||
- D-Pad also 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 {
|
if len(ev.Controllers) > 0 {
|
||||||
for idx, ctrl := range ev.Controllers {
|
for idx, ctrl := range ev.Controllers {
|
||||||
SetControllerIndex(idx)
|
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
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
// Test the high level Chunker.
|
// Test the high level Chunker.
|
||||||
func TestChunker(t *testing.T) {
|
func TestChunker(t *testing.T) {
|
||||||
c := level.NewChunker(1000)
|
c := level.NewChunker(128)
|
||||||
|
|
||||||
// Test swatches.
|
// Test swatches.
|
||||||
var (
|
var (
|
||||||
|
@ -239,7 +239,7 @@ func TestMapAccessor(t *testing.T) {
|
||||||
|
|
||||||
// Test the ChunkCoordinate function.
|
// Test the ChunkCoordinate function.
|
||||||
func TestChunkCoordinates(t *testing.T) {
|
func TestChunkCoordinates(t *testing.T) {
|
||||||
c := level.NewChunker(1000)
|
c := level.NewChunker(128)
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
In render.Point
|
In render.Point
|
||||||
|
|
|
@ -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
|
// Is our chunk cache getting too full? e.g. on full level
|
||||||
// sweeps where a whole zip file's worth of chunks are scanned.
|
// sweeps where a whole zip file's worth of chunks are scanned.
|
||||||
if balance.ChunkerLRUCacheMax > 0 && len(c.Chunks) > balance.ChunkerLRUCacheMax {
|
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()
|
c.chunkMu.Lock()
|
||||||
defer c.chunkMu.Unlock()
|
defer c.chunkMu.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -10,14 +10,14 @@ import (
|
||||||
|
|
||||||
func TestWorldSize(t *testing.T) {
|
func TestWorldSize(t *testing.T) {
|
||||||
type TestCase struct {
|
type TestCase struct {
|
||||||
Size int
|
Size uint8
|
||||||
Points []render.Point
|
Points []render.Point
|
||||||
Expect render.Rect
|
Expect render.Rect
|
||||||
Zero render.Rect // expected WorldSizePositive
|
Zero render.Rect // expected WorldSizePositive
|
||||||
}
|
}
|
||||||
var tests = []TestCase{
|
var tests = []TestCase{
|
||||||
{
|
{
|
||||||
Size: 1000,
|
Size: 200,
|
||||||
Points: []render.Point{
|
Points: []render.Point{
|
||||||
render.NewPoint(0, 0), // chunk 0,0
|
render.NewPoint(0, 0), // chunk 0,0
|
||||||
render.NewPoint(512, 788), // 0,0
|
render.NewPoint(512, 788), // 0,0
|
||||||
|
@ -86,9 +86,9 @@ func TestWorldSize(t *testing.T) {
|
||||||
|
|
||||||
func TestViewportChunks(t *testing.T) {
|
func TestViewportChunks(t *testing.T) {
|
||||||
// Initialize a 100 chunk image with 5x5 chunks.
|
// Initialize a 100 chunk image with 5x5 chunks.
|
||||||
var ChunkSize int = 100
|
var ChunkSize uint8 = 100
|
||||||
var Offset int = 50
|
var Offset int = 50
|
||||||
c := level.NewChunker(int(ChunkSize))
|
c := level.NewChunker(ChunkSize)
|
||||||
sw := &level.Swatch{
|
sw := &level.Swatch{
|
||||||
Name: "solid",
|
Name: "solid",
|
||||||
Color: render.Black,
|
Color: render.Black,
|
||||||
|
@ -106,8 +106,8 @@ func TestViewportChunks(t *testing.T) {
|
||||||
for x := -2; x <= 2; x++ {
|
for x := -2; x <= 2; x++ {
|
||||||
for y := -2; y <= 2; y++ {
|
for y := -2; y <= 2; y++ {
|
||||||
point := render.NewPoint(
|
point := render.NewPoint(
|
||||||
x*ChunkSize+Offset,
|
x*int(ChunkSize)+Offset,
|
||||||
y*ChunkSize+Offset,
|
y*int(ChunkSize)+Offset,
|
||||||
)
|
)
|
||||||
fmt.Printf("in chunk: %d,%d set pt: %s\n",
|
fmt.Printf("in chunk: %d,%d set pt: %s\n",
|
||||||
x, y, point,
|
x, y, point,
|
||||||
|
|
|
@ -194,14 +194,14 @@ func (fs *FileSystem) MigrateZipfile(zf *zip.Writer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := filesDeleted[file.Name]; ok {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip files currently in memory.
|
// Skip files currently in memory.
|
||||||
if fs.filemap != nil {
|
if fs.filemap != nil {
|
||||||
if _, ok := fs.filemap[file.Name]; ok {
|
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
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,7 @@ func (m *Level) ToZipfile() ([]byte, error) {
|
||||||
if n, err := writer.Write(header); err != nil {
|
if n, err := writer.Write(header); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
log.Debug("Written level.json to zipfile: %s bytes", n)
|
log.Debug("Written level.json to zipfile: %d bytes", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -420,7 +420,7 @@ func (w *Canvas) loopEditable(ev *event.State) error {
|
||||||
baseColor, err := chunker.Get(cursor)
|
baseColor, err := chunker.Get(cursor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
limit = balance.FloodToolVoidLimit
|
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.
|
// If no change, do nothing.
|
||||||
|
|
|
@ -70,7 +70,7 @@ func TestWallpaper(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wp, err := FromImage(nil, img, "dummy")
|
wp, err := FromImage(img, "dummy")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Couldn't create FromImage: %s", err)
|
t.Errorf("Couldn't create FromImage: %s", err)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user