Add cheat code to send power to all actors

pull/93/head
Noah 2023-02-18 14:21:07 -08:00
parent 03cd1d4ca0
commit 856de848c9
8 changed files with 52 additions and 7 deletions

View File

@ -26,6 +26,9 @@ Other miscellaneous changes:
help with touchscreen devices, where it is difficult to touch the help with touchscreen devices, where it is difficult to touch the
properties button without accidentally dragging the actor elsewhere properties button without accidentally dragging the actor elsewhere
on your level as might happen with the Actor Tool! 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) * Start distributing AppImage releases for GNU/Linux (64-bit and 32-bit)
Some technical changes: Some technical changes:

View File

@ -293,7 +293,7 @@ func showChunker(c *cli.Context, ch *level.Chunker) {
fmt.Println("") fmt.Println("")
} }
func chunkTypeToName(v int) string { func chunkTypeToName(v uint64) string {
switch v { switch v {
case level.MapType: case level.MapType:
return "map" return "map"

View File

@ -34,6 +34,7 @@ var (
CheatDebugWaitScreen = "test wait screen" CheatDebugWaitScreen = "test wait screen"
CheatUnlockLevels = "master key" CheatUnlockLevels = "master key"
CheatSkipLevel = "warp whistle" CheatSkipLevel = "warp whistle"
CheatFreeEnergy = "tesla"
) )
// Global cheat boolean states. // Global cheat boolean states.

View File

@ -7,9 +7,11 @@ import (
"git.kirsle.net/SketchyMaze/doodle/pkg/balance" "git.kirsle.net/SketchyMaze/doodle/pkg/balance"
"git.kirsle.net/SketchyMaze/doodle/pkg/modal" "git.kirsle.net/SketchyMaze/doodle/pkg/modal"
"git.kirsle.net/SketchyMaze/doodle/pkg/modal/loadscreen" "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/shmem"
"git.kirsle.net/SketchyMaze/doodle/pkg/windows" "git.kirsle.net/SketchyMaze/doodle/pkg/windows"
"git.kirsle.net/go/ui" "git.kirsle.net/go/ui"
"github.com/dop251/goja"
) )
// IsDefaultPlayerCharacter checks whether the DefaultPlayerCharacter doodad has // 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.") 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: case balance.CheatDebugLoadScreen:
loadscreen.ShowWithProgress() loadscreen.ShowWithProgress()
loadscreen.SetSubtitle("Loading: /dev/null", "Loadscreen testing.") loadscreen.SetSubtitle("Loading: /dev/null", "Loadscreen testing.")

View File

@ -9,6 +9,7 @@ import (
"sync" "sync"
"git.kirsle.net/SketchyMaze/doodle/pkg/balance" "git.kirsle.net/SketchyMaze/doodle/pkg/balance"
"git.kirsle.net/SketchyMaze/doodle/pkg/log"
"git.kirsle.net/go/render" "git.kirsle.net/go/render"
) )
@ -281,13 +282,16 @@ func (a *MapAccessor) UnmarshalBinary(compressed []byte) error {
sw, err3 = binary.ReadUvarint(reader) sw, err3 = binary.ReadUvarint(reader)
) )
point := render.NewPoint(int(x), int(y)) // We expect all 3 errors to be EOF together if the binary is formed correctly.
a.grid[point] = NewSparseSwatch(int(sw))
if err1 != nil || err2 != nil || err3 != nil { 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 break
} }
point := render.NewPoint(int(x), int(y))
a.grid[point] = NewSparseSwatch(int(sw))
} }
return nil return nil

View File

@ -218,7 +218,7 @@ func ChunkFromZipfile(zf *zip.Reader, layer int, coord render.Point) (*Chunk, er
// Read from the new binary format. // Read from the new binary format.
if file, err := zf.Open(binfile); err == nil { 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) bin, err := ioutil.ReadAll(file)
if err != nil { if err != nil {
return nil, err return nil, err
@ -229,7 +229,7 @@ func ChunkFromZipfile(zf *zip.Reader, layer int, coord render.Point) (*Chunk, er
return nil, err return nil, err
} }
} else if file, err := zf.Open(jsonfile); err == nil { } 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) bin, err := ioutil.ReadAll(file)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -353,6 +353,11 @@ func (s *PlayScene) Canvas() *uix.Canvas {
return s.drawing 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 // SetPlayerCharacter changes the doodad used for the player, by destroying the
// current player character and making it from scratch. // current player character and making it from scratch.
func (s *PlayScene) SetPlayerCharacter(filename string) { func (s *PlayScene) SetPlayerCharacter(filename string) {

View File

@ -65,6 +65,11 @@ func (vm *VM) Set(name string, v interface{}) error {
return vm.vm.Set(name, v) 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 // RegisterLevelHooks registers accessors to the level hooks
// and Doodad API for Play Mode. // and Doodad API for Play Mode.
func (vm *VM) RegisterLevelHooks() error { func (vm *VM) RegisterLevelHooks() error {