Noah Petherbridge
20771fbe13
Add the JSON format for embedding Actors (Doodad instances) inside of a Level. I made a test map that manually inserted a couple of actors. Actors are given to the Canvas responsible for the Level via the function `InstallActors()`. So it means you'll call LoadLevel and then InstallActors to hook everything up. The Canvas creates sub-Canvas widgets from each Actor. After drawing the main level geometry from the Canvas.Chunker, it calls the drawActors() function which does the same but for Actors. Levels keep a global map of all Actors that exist. For any Actors that are visible within the Viewport, their sub-Canvas widgets are presented appropriately on top of the parent Canvas. In case their sub-Canvas overlaps the parent's boundaries, their sub-Canvas is resized and moved appropriately. - Allow the MainWindow to be resized at run time, and the UI recalculates its sizing and position. - Made the in-game Shell properties editable via environment variables. The kirsle.env file sets a blue and pink color scheme. - Begin the ground work for Levels and Doodads to embed files inside their data via the level.FileSystem type. - UI: Labels can now contain line break characters. It will appropriately render multiple lines of render.Text and take into account the proper BoxSize to contain them all. - Add environment variable DOODLE_DEBUG_ALL=true that will turn on ALL debug overlay and visualization options. - Add debug overlay to "tag" each Canvas widget with some of its details, like its Name and World Position. Can be enabled with the environment variable DEBUG_CANVAS_LABEL=true - Improved the FPS debug overlay to show in labeled columns and multiple colors, with easy ability to add new data points to it.
72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package render_test
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"git.kirsle.net/apps/doodle/render"
|
|
)
|
|
|
|
func TestIntersection(t *testing.T) {
|
|
newRect := func(x, y, w, h int) render.Rect {
|
|
return render.Rect{
|
|
X: int32(x),
|
|
Y: int32(y),
|
|
W: int32(w),
|
|
H: int32(h),
|
|
}
|
|
}
|
|
|
|
type TestCase struct {
|
|
A render.Rect
|
|
B render.Rect
|
|
Expect bool
|
|
}
|
|
var tests = []TestCase{
|
|
{
|
|
A: newRect(0, 0, 1000, 1000),
|
|
B: newRect(200, 200, 100, 100),
|
|
Expect: true,
|
|
},
|
|
{
|
|
A: newRect(200, 200, 100, 100),
|
|
B: newRect(0, 0, 1000, 1000),
|
|
Expect: true,
|
|
},
|
|
{
|
|
A: newRect(0, 0, 100, 100),
|
|
B: newRect(100, 0, 100, 100),
|
|
Expect: true,
|
|
},
|
|
{
|
|
A: newRect(0, 0, 99, 99),
|
|
B: newRect(100, 0, 99, 99),
|
|
Expect: false,
|
|
},
|
|
{
|
|
// Real coords of a test doodad!
|
|
A: newRect(183, 256, 283, 356),
|
|
B: newRect(0, -232, 874, 490),
|
|
Expect: true,
|
|
},
|
|
{
|
|
A: newRect(183, 256, 283, 356),
|
|
B: newRect(0, -240, 874, 490),
|
|
Expect: false, // XXX: must be true
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
actual := test.A.Intersects(test.B)
|
|
if actual != test.Expect {
|
|
t.Errorf(
|
|
"%s collision with %s: expected %s, got %s",
|
|
test.A,
|
|
test.B,
|
|
strconv.FormatBool(test.Expect),
|
|
strconv.FormatBool(actual),
|
|
)
|
|
}
|
|
}
|
|
}
|