From 856de848c9d4bee71e8eb1ed3ca9b4d37fde9606 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 18 Feb 2023 14:21:07 -0800 Subject: [PATCH] Add cheat code to send power to all actors --- Changes.md | 3 +++ cmd/doodad/commands/show.go | 2 +- pkg/balance/cheats.go | 1 + pkg/cheats.go | 27 +++++++++++++++++++++++++++ pkg/level/chunk_map.go | 12 ++++++++---- pkg/level/chunker_zipfile.go | 4 ++-- pkg/play_scene.go | 5 +++++ pkg/scripting/vm.go | 5 +++++ 8 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Changes.md b/Changes.md index 7cb3617..a73f449 100644 --- a/Changes.md +++ b/Changes.md @@ -26,6 +26,9 @@ Other miscellaneous changes: help with touchscreen devices, where it is difficult to touch the properties button without accidentally dragging the actor elsewhere on your level as might happen with the Actor Tool! +* New cheat code: `tesla` will send a power signal to ALL actors on the + current level in play mode - opening all electric doors and trapdoors. + May cause fun chaos during gameplay. Probably not very useful. * Start distributing AppImage releases for GNU/Linux (64-bit and 32-bit) Some technical changes: diff --git a/cmd/doodad/commands/show.go b/cmd/doodad/commands/show.go index 2144d17..01fddfa 100644 --- a/cmd/doodad/commands/show.go +++ b/cmd/doodad/commands/show.go @@ -293,7 +293,7 @@ func showChunker(c *cli.Context, ch *level.Chunker) { fmt.Println("") } -func chunkTypeToName(v int) string { +func chunkTypeToName(v uint64) string { switch v { case level.MapType: return "map" diff --git a/pkg/balance/cheats.go b/pkg/balance/cheats.go index d7b3344..f742023 100644 --- a/pkg/balance/cheats.go +++ b/pkg/balance/cheats.go @@ -34,6 +34,7 @@ var ( CheatDebugWaitScreen = "test wait screen" CheatUnlockLevels = "master key" CheatSkipLevel = "warp whistle" + CheatFreeEnergy = "tesla" ) // Global cheat boolean states. diff --git a/pkg/cheats.go b/pkg/cheats.go index 1e4699b..c7a1660 100644 --- a/pkg/cheats.go +++ b/pkg/cheats.go @@ -7,9 +7,11 @@ import ( "git.kirsle.net/SketchyMaze/doodle/pkg/balance" "git.kirsle.net/SketchyMaze/doodle/pkg/modal" "git.kirsle.net/SketchyMaze/doodle/pkg/modal/loadscreen" + "git.kirsle.net/SketchyMaze/doodle/pkg/scripting" "git.kirsle.net/SketchyMaze/doodle/pkg/shmem" "git.kirsle.net/SketchyMaze/doodle/pkg/windows" "git.kirsle.net/go/ui" + "github.com/dop251/goja" ) // IsDefaultPlayerCharacter checks whether the DefaultPlayerCharacter doodad has @@ -199,6 +201,31 @@ func (c Command) cheatCommand(d *Doodle) bool { d.FlashError("Use this cheat in Play Mode to toggle invincibility.") } + case balance.CheatFreeEnergy: + if isPlay { + playScene.SetCheated() + d.Flash("Power toggle sent to all actors in the level.") + for _, a := range playScene.Canvas().Actors() { + // Hacky stuff here - just a fun cheat code anyway. + vm := playScene.ScriptSupervisor().To(a.ID()) + value := vm.Get("__tesla") + if value == nil || !value.ToBoolean() { + vm.Set("__tesla", true) + value = vm.Get("__tesla") + } else if value.ToBoolean() { + vm.Set("__tesla", false) + value = vm.Get("__tesla") + } + vm.Inbound <- scripting.Message{ + Name: "power", + SenderID: a.ID(), + Args: []goja.Value{value}, + } + } + } else { + d.FlashError("Use this cheat in Play Mode to send power to all actors (chaotic!).") + } + case balance.CheatDebugLoadScreen: loadscreen.ShowWithProgress() loadscreen.SetSubtitle("Loading: /dev/null", "Loadscreen testing.") diff --git a/pkg/level/chunk_map.go b/pkg/level/chunk_map.go index 99329f7..652b50c 100644 --- a/pkg/level/chunk_map.go +++ b/pkg/level/chunk_map.go @@ -9,6 +9,7 @@ import ( "sync" "git.kirsle.net/SketchyMaze/doodle/pkg/balance" + "git.kirsle.net/SketchyMaze/doodle/pkg/log" "git.kirsle.net/go/render" ) @@ -281,13 +282,16 @@ func (a *MapAccessor) UnmarshalBinary(compressed []byte) error { sw, err3 = binary.ReadUvarint(reader) ) - point := render.NewPoint(int(x), int(y)) - a.grid[point] = NewSparseSwatch(int(sw)) - + // We expect all 3 errors to be EOF together if the binary is formed correctly. if err1 != nil || err2 != nil || err3 != nil { - // log.Error("Break read loop: %s; %s; %s", err1, err2, err3) + if err1 == nil || err2 == nil || err3 == nil { + log.Error("MapAccessor.UnmarshalBinary: found odd number of varints!") + } break } + + point := render.NewPoint(int(x), int(y)) + a.grid[point] = NewSparseSwatch(int(sw)) } return nil diff --git a/pkg/level/chunker_zipfile.go b/pkg/level/chunker_zipfile.go index f6612d2..380c736 100644 --- a/pkg/level/chunker_zipfile.go +++ b/pkg/level/chunker_zipfile.go @@ -218,7 +218,7 @@ func ChunkFromZipfile(zf *zip.Reader, layer int, coord render.Point) (*Chunk, er // Read from the new binary format. if file, err := zf.Open(binfile); err == nil { - log.Debug("Reading binary compressed chunk from %s", binfile) + // log.Debug("Reading binary compressed chunk from %s", binfile) bin, err := ioutil.ReadAll(file) if err != nil { return nil, err @@ -229,7 +229,7 @@ func ChunkFromZipfile(zf *zip.Reader, layer int, coord render.Point) (*Chunk, er return nil, err } } else if file, err := zf.Open(jsonfile); err == nil { - log.Debug("Reading JSON encoded chunk from %s", jsonfile) + // log.Debug("Reading JSON encoded chunk from %s", jsonfile) bin, err := ioutil.ReadAll(file) if err != nil { return nil, err diff --git a/pkg/play_scene.go b/pkg/play_scene.go index 03fe151..d65a732 100644 --- a/pkg/play_scene.go +++ b/pkg/play_scene.go @@ -353,6 +353,11 @@ func (s *PlayScene) Canvas() *uix.Canvas { return s.drawing } +// ScriptSupervisor returns the scripting supervisor for play mode. +func (s *PlayScene) ScriptSupervisor() *scripting.Supervisor { + return s.scripting +} + // SetPlayerCharacter changes the doodad used for the player, by destroying the // current player character and making it from scratch. func (s *PlayScene) SetPlayerCharacter(filename string) { diff --git a/pkg/scripting/vm.go b/pkg/scripting/vm.go index 3d4f709..9423c3c 100644 --- a/pkg/scripting/vm.go +++ b/pkg/scripting/vm.go @@ -65,6 +65,11 @@ func (vm *VM) Set(name string, v interface{}) error { return vm.vm.Set(name, v) } +// Get a value from the VM. +func (vm *VM) Get(name string) goja.Value { + return vm.vm.Get(name) +} + // RegisterLevelHooks registers accessors to the level hooks // and Doodad API for Play Mode. func (vm *VM) RegisterLevelHooks() error {