From 52a2545692c1844e24189f0efe99806c1594e708 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Fri, 19 Apr 2019 16:21:04 -0700 Subject: [PATCH] Remove ScreenshotKey Event, Add F* Key Handlers * The F3 key now toggles the Debug Overlay, which is now OFF by default. * The F4 key now toggles the Debug Collision Boxes feature. --- README.md | 25 +++++++++++----------- lib/events/events.go | 45 +++++++++++++++++++--------------------- lib/render/sdl/events.go | 32 +++++++++++++++++++++++++++- pkg/doodle.go | 8 +++++++ pkg/fps.go | 2 +- pkg/level/chunker.go | 2 -- pkg/uix/canvas.go | 4 +--- 7 files changed, 74 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 01319ad..2135e48 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,14 @@ Escape Exit the program otherwise. Enter - Open and close the developer console, and run commands while the console - is open. + Open and close the developer console, and run commands while the + console is open. + +F3 + Toggle the Debug Overlay. + +F4 + Toggle debug collision hitboxes. ``` In Play Mode: @@ -51,13 +57,6 @@ Cursor Keys Move the player around. ``` -In Edit Mode: - -``` -F12 - Take a screenshot (generate a PNG based on level data) -``` - ## Developer Console Press `Enter` at any time to open the developer console. @@ -68,14 +67,14 @@ Commands supported: new Create a new map in Edit Mode. -save [filename.json] +save [filename] Save the current map in Edit Mode. The filename is required if the map has not been saved yet. -edit [filename.json] - Open a map in Edit Mode. +edit [filename] + Open a map or doodad in Edit Mode. -play [filename.json] +play [filename] Open a map in Play Mode. echo diff --git a/lib/events/events.go b/lib/events/events.go index eca4e23..9c650fb 100644 --- a/lib/events/events.go +++ b/lib/events/events.go @@ -11,16 +11,14 @@ type State struct { Button1 *BoolTick Button2 *BoolTick - // Screenshot key. - ScreenshotKey *BoolTick - EscapeKey *BoolTick - EnterKey *BoolTick - ShiftActive *BoolTick - KeyName *StringTick - Up *BoolTick - Left *BoolTick - Right *BoolTick - Down *BoolTick + EscapeKey *BoolTick + EnterKey *BoolTick + ShiftActive *BoolTick + KeyName *StringTick + Up *BoolTick + Left *BoolTick + Right *BoolTick + Down *BoolTick // Cursor positions. CursorX *Int32Tick @@ -33,20 +31,19 @@ type State struct { // New creates a new event state manager. func New() *State { return &State{ - Button1: &BoolTick{}, - Button2: &BoolTick{}, - ScreenshotKey: &BoolTick{}, - EscapeKey: &BoolTick{}, - EnterKey: &BoolTick{}, - ShiftActive: &BoolTick{}, - KeyName: &StringTick{}, - Up: &BoolTick{}, - Left: &BoolTick{}, - Right: &BoolTick{}, - Down: &BoolTick{}, - CursorX: &Int32Tick{}, - CursorY: &Int32Tick{}, - Resized: &BoolTick{}, + Button1: &BoolTick{}, + Button2: &BoolTick{}, + EscapeKey: &BoolTick{}, + EnterKey: &BoolTick{}, + ShiftActive: &BoolTick{}, + KeyName: &StringTick{}, + Up: &BoolTick{}, + Left: &BoolTick{}, + Right: &BoolTick{}, + Down: &BoolTick{}, + CursorX: &Int32Tick{}, + CursorY: &Int32Tick{}, + Resized: &BoolTick{}, } } diff --git a/lib/render/sdl/events.go b/lib/render/sdl/events.go index e5a76fb..3ec1a92 100644 --- a/lib/render/sdl/events.go +++ b/lib/render/sdl/events.go @@ -19,6 +19,14 @@ var ( // Poll for events. func (r *Renderer) Poll() (*events.State, error) { s := r.events + + // helper function to push keyboard key names on keyDown events only. + pushKey := func(name string, state uint8) { + if state == 1 { + s.KeyName.Push(name) + } + } + for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch t := event.(type) { case *sdl.QuitEvent: @@ -103,8 +111,30 @@ func (r *Renderer) Poll() (*events.State, error) { continue } s.EnterKey.Push(t.State == 1) + case sdl.SCANCODE_F1: + pushKey("F1", t.State) + case sdl.SCANCODE_F2: + pushKey("F2", t.State) + case sdl.SCANCODE_F3: + pushKey("F3", t.State) + case sdl.SCANCODE_F4: + pushKey("F4", t.State) + case sdl.SCANCODE_F5: + pushKey("F5", t.State) + case sdl.SCANCODE_F6: + pushKey("F6", t.State) + case sdl.SCANCODE_F7: + pushKey("F7", t.State) + case sdl.SCANCODE_F8: + pushKey("F8", t.State) + case sdl.SCANCODE_F9: + pushKey("F9", t.State) + case sdl.SCANCODE_F10: + pushKey("F10", t.State) + case sdl.SCANCODE_F11: + pushKey("F11", t.State) case sdl.SCANCODE_F12: - s.ScreenshotKey.Push(t.State == 1) + pushKey("F12", t.State) case sdl.SCANCODE_UP: s.Up.Push(t.State == 1) case sdl.SCANCODE_LEFT: diff --git a/pkg/doodle.go b/pkg/doodle.go index b99b9fa..6f9bfc1 100644 --- a/pkg/doodle.go +++ b/pkg/doodle.go @@ -118,6 +118,14 @@ func (d *Doodle) Run() error { break } + if ev.KeyName.Now == "F3" { + DebugOverlay = !DebugOverlay + ev.KeyName.Read() + } else if ev.KeyName.Now == "F4" { + DebugCollision = !DebugCollision + ev.KeyName.Read() + } + // Run the scene's logic. err = d.Scene.Loop(d, ev) if err != nil { diff --git a/pkg/fps.go b/pkg/fps.go index 358fb18..e74125a 100644 --- a/pkg/fps.go +++ b/pkg/fps.go @@ -17,7 +17,7 @@ const maxSamples = 100 // Debug mode options, these can be enabled in the dev console // like: boolProp DebugOverlay true var ( - DebugOverlay = true + DebugOverlay = false DebugCollision = false DebugTextPadding int32 = 8 diff --git a/pkg/level/chunker.go b/pkg/level/chunker.go index 3477363..05735bc 100644 --- a/pkg/level/chunker.go +++ b/pkg/level/chunker.go @@ -6,7 +6,6 @@ import ( "math" "git.kirsle.net/apps/doodle/lib/render" - "git.kirsle.net/apps/doodle/pkg/log" ) // Chunker is the data structure that manages the chunks of a level, and @@ -30,7 +29,6 @@ func NewChunker(size int) *Chunker { // on disk) to connect references to the swatches in the palette. func (c *Chunker) Inflate(pal *Palette) error { for coord, chunk := range c.Chunks { - log.Debug("Chunker.Inflate: expanding chunk %s", coord) chunk.Point = coord chunk.Size = c.Size chunk.Inflate(pal) diff --git a/pkg/uix/canvas.go b/pkg/uix/canvas.go index f86bda7..38278c3 100644 --- a/pkg/uix/canvas.go +++ b/pkg/uix/canvas.go @@ -169,9 +169,7 @@ func (w *Canvas) Loop(ev *events.State) error { if err := w.loopFollowActor(ev); err != nil { log.Error("Follow actor: %s", err) // not fatal but nice to know } - if err := w.loopConstrainScroll(); err != nil { - log.Debug("loopConstrainScroll: %s", err) - } + _ = w.loopConstrainScroll() // Remove any actors that were destroyed the previous tick. var newActors []*Actor