2019-06-27 01:36:54 +00:00
|
|
|
// +build js,wasm
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2019-06-27 05:44:08 +00:00
|
|
|
"syscall/js"
|
|
|
|
|
2022-09-24 22:17:25 +00:00
|
|
|
doodle "git.kirsle.net/SketchyMaze/doodle/pkg"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/balance"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/branding"
|
|
|
|
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
|
2019-12-31 02:13:28 +00:00
|
|
|
"git.kirsle.net/go/render"
|
|
|
|
"git.kirsle.net/go/render/canvas"
|
2019-06-27 01:36:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fmt.Printf("Hello world\n")
|
|
|
|
// testRawCanvas()
|
|
|
|
|
2019-06-27 03:33:24 +00:00
|
|
|
// Enable workarounds.
|
|
|
|
balance.DisableChunkTextureCache = true
|
2019-06-27 05:44:08 +00:00
|
|
|
js.Global().Get("sessionStorage").Call("clear")
|
2019-06-27 03:33:24 +00:00
|
|
|
|
2019-06-27 01:36:54 +00:00
|
|
|
// HTML5 Canvas engine.
|
|
|
|
engine, _ := canvas.New("canvas")
|
|
|
|
engine.AddEventListeners()
|
|
|
|
|
|
|
|
game := doodle.New(true, engine)
|
|
|
|
game.SetupEngine()
|
|
|
|
|
2019-06-27 03:33:24 +00:00
|
|
|
doodle.DebugOverlay = true
|
|
|
|
|
2019-06-27 01:36:54 +00:00
|
|
|
// Manually inform Doodle of the canvas size since it can't control
|
|
|
|
// the size on its own.
|
|
|
|
w, h := engine.WindowSize()
|
|
|
|
game.SetWindowSize(w, h)
|
|
|
|
|
|
|
|
// game.Goto(&doodle.GUITestScene{})
|
2019-06-27 05:44:08 +00:00
|
|
|
game.Goto(&doodle.EditorScene{})
|
2019-06-27 01:36:54 +00:00
|
|
|
|
|
|
|
game.Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
func testRawCanvas() {
|
|
|
|
engine, _ := canvas.New("canvas")
|
|
|
|
engine.SetTitle(
|
|
|
|
fmt.Sprintf("%s v%s", branding.AppName, branding.Version),
|
|
|
|
)
|
|
|
|
fmt.Printf("Got engine: %+v\n", engine)
|
|
|
|
engine.Clear(render.Green)
|
|
|
|
|
2019-07-14 21:18:44 +00:00
|
|
|
for pt := range render.IterLine(render.NewPoint(20, 20), render.NewPoint(300, 300)) {
|
2019-06-27 01:36:54 +00:00
|
|
|
engine.DrawPoint(render.Red, pt)
|
|
|
|
}
|
|
|
|
|
|
|
|
engine.DrawLine(render.Blue, render.NewPoint(20, 300), render.NewPoint(300, 20))
|
|
|
|
|
|
|
|
engine.DrawRect(render.Black, render.Rect{
|
|
|
|
X: 5,
|
|
|
|
Y: 5,
|
|
|
|
W: 10,
|
|
|
|
H: 10,
|
|
|
|
})
|
|
|
|
engine.DrawBox(render.White, render.Rect{
|
|
|
|
X: 5,
|
|
|
|
Y: 5,
|
|
|
|
W: 10,
|
|
|
|
H: 10,
|
|
|
|
})
|
|
|
|
|
|
|
|
engine.DrawBox(render.Purple, render.Rect{
|
|
|
|
X: 25,
|
|
|
|
Y: 5,
|
|
|
|
W: 10,
|
|
|
|
H: 10,
|
|
|
|
})
|
|
|
|
|
|
|
|
engine.DrawText(render.Text{
|
|
|
|
Text: "Hello world!",
|
|
|
|
FontFilename: "DejaVuSans",
|
|
|
|
Size: 14,
|
|
|
|
}, render.NewPoint(400, 400))
|
|
|
|
|
|
|
|
size, _ := engine.ComputeTextRect(render.Text{
|
|
|
|
Text: "Hello world! blah blah",
|
|
|
|
FontFilename: "DejaVuSans",
|
|
|
|
Size: 14,
|
|
|
|
})
|
|
|
|
log.Info("text rect: %+v", size)
|
|
|
|
_ = engine
|
|
|
|
}
|