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.
physics
Noah 2019-04-19 16:21:04 -07:00
parent 2a162a86dd
commit 52a2545692
7 changed files with 74 additions and 44 deletions

View File

@ -40,8 +40,14 @@ Escape
Exit the program otherwise. Exit the program otherwise.
Enter Enter
Open and close the developer console, and run commands while the console Open and close the developer console, and run commands while the
is open. console is open.
F3
Toggle the Debug Overlay.
F4
Toggle debug collision hitboxes.
``` ```
In Play Mode: In Play Mode:
@ -51,13 +57,6 @@ Cursor Keys
Move the player around. Move the player around.
``` ```
In Edit Mode:
```
F12
Take a screenshot (generate a PNG based on level data)
```
## Developer Console ## Developer Console
Press `Enter` at any time to open the developer console. Press `Enter` at any time to open the developer console.
@ -68,14 +67,14 @@ Commands supported:
new new
Create a new map in Edit Mode. 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 Save the current map in Edit Mode. The filename is required if the map has
not been saved yet. not been saved yet.
edit [filename.json] edit [filename]
Open a map in Edit Mode. Open a map or doodad in Edit Mode.
play [filename.json] play [filename]
Open a map in Play Mode. Open a map in Play Mode.
echo <text> echo <text>

View File

@ -11,16 +11,14 @@ type State struct {
Button1 *BoolTick Button1 *BoolTick
Button2 *BoolTick Button2 *BoolTick
// Screenshot key. EscapeKey *BoolTick
ScreenshotKey *BoolTick EnterKey *BoolTick
EscapeKey *BoolTick ShiftActive *BoolTick
EnterKey *BoolTick KeyName *StringTick
ShiftActive *BoolTick Up *BoolTick
KeyName *StringTick Left *BoolTick
Up *BoolTick Right *BoolTick
Left *BoolTick Down *BoolTick
Right *BoolTick
Down *BoolTick
// Cursor positions. // Cursor positions.
CursorX *Int32Tick CursorX *Int32Tick
@ -33,20 +31,19 @@ type State struct {
// New creates a new event state manager. // New creates a new event state manager.
func New() *State { func New() *State {
return &State{ return &State{
Button1: &BoolTick{}, Button1: &BoolTick{},
Button2: &BoolTick{}, Button2: &BoolTick{},
ScreenshotKey: &BoolTick{}, EscapeKey: &BoolTick{},
EscapeKey: &BoolTick{}, EnterKey: &BoolTick{},
EnterKey: &BoolTick{}, ShiftActive: &BoolTick{},
ShiftActive: &BoolTick{}, KeyName: &StringTick{},
KeyName: &StringTick{}, Up: &BoolTick{},
Up: &BoolTick{}, Left: &BoolTick{},
Left: &BoolTick{}, Right: &BoolTick{},
Right: &BoolTick{}, Down: &BoolTick{},
Down: &BoolTick{}, CursorX: &Int32Tick{},
CursorX: &Int32Tick{}, CursorY: &Int32Tick{},
CursorY: &Int32Tick{}, Resized: &BoolTick{},
Resized: &BoolTick{},
} }
} }

View File

@ -19,6 +19,14 @@ var (
// Poll for events. // Poll for events.
func (r *Renderer) Poll() (*events.State, error) { func (r *Renderer) Poll() (*events.State, error) {
s := r.events 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() { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch t := event.(type) { switch t := event.(type) {
case *sdl.QuitEvent: case *sdl.QuitEvent:
@ -103,8 +111,30 @@ func (r *Renderer) Poll() (*events.State, error) {
continue continue
} }
s.EnterKey.Push(t.State == 1) 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: case sdl.SCANCODE_F12:
s.ScreenshotKey.Push(t.State == 1) pushKey("F12", t.State)
case sdl.SCANCODE_UP: case sdl.SCANCODE_UP:
s.Up.Push(t.State == 1) s.Up.Push(t.State == 1)
case sdl.SCANCODE_LEFT: case sdl.SCANCODE_LEFT:

View File

@ -118,6 +118,14 @@ func (d *Doodle) Run() error {
break 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. // Run the scene's logic.
err = d.Scene.Loop(d, ev) err = d.Scene.Loop(d, ev)
if err != nil { if err != nil {

View File

@ -17,7 +17,7 @@ const maxSamples = 100
// Debug mode options, these can be enabled in the dev console // Debug mode options, these can be enabled in the dev console
// like: boolProp DebugOverlay true // like: boolProp DebugOverlay true
var ( var (
DebugOverlay = true DebugOverlay = false
DebugCollision = false DebugCollision = false
DebugTextPadding int32 = 8 DebugTextPadding int32 = 8

View File

@ -6,7 +6,6 @@ import (
"math" "math"
"git.kirsle.net/apps/doodle/lib/render" "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 // 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. // on disk) to connect references to the swatches in the palette.
func (c *Chunker) Inflate(pal *Palette) error { func (c *Chunker) Inflate(pal *Palette) error {
for coord, chunk := range c.Chunks { for coord, chunk := range c.Chunks {
log.Debug("Chunker.Inflate: expanding chunk %s", coord)
chunk.Point = coord chunk.Point = coord
chunk.Size = c.Size chunk.Size = c.Size
chunk.Inflate(pal) chunk.Inflate(pal)

View File

@ -169,9 +169,7 @@ func (w *Canvas) Loop(ev *events.State) error {
if err := w.loopFollowActor(ev); err != nil { if err := w.loopFollowActor(ev); err != nil {
log.Error("Follow actor: %s", err) // not fatal but nice to know log.Error("Follow actor: %s", err) // not fatal but nice to know
} }
if err := w.loopConstrainScroll(); err != nil { _ = w.loopConstrainScroll()
log.Debug("loopConstrainScroll: %s", err)
}
// Remove any actors that were destroyed the previous tick. // Remove any actors that were destroyed the previous tick.
var newActors []*Actor var newActors []*Actor