Commit b96166f1 authored by robert's avatar robert Committed by Rahix

Add get_player und set_shifts cheats

parent 8a381b4e
......@@ -19,6 +19,8 @@ pub fn initialize_cheats(handle: gamestate::StateMachineHandle) {
#[derive(Debug, Clone)]
pub enum CheatCommand {
SetSanity(f32),
SetShifts(u32),
GetPlayer(),
}
fn get_cheat_state() -> anyhow::Result<&'static gamestate::StateMachineHandle> {
......@@ -65,3 +67,28 @@ pub fn cheat_set_sanity(val: f32) -> Result<(), wasm_bindgen::JsValue> {
Err(err) => Err(wasm_bindgen::JsValue::from_str(&format!("{}", err))),
}
}
#[wasm_bindgen]
pub fn cheat_set_shifts(val: u32) -> Result<(), wasm_bindgen::JsValue> {
match || -> anyhow::Result<()> {
let state = get_cheat_state()?;
state.do_cheat(CheatCommand::SetShifts(val));
Ok(())
}() {
// this is not nice
Ok(()) => Ok(()),
Err(err) => Err(wasm_bindgen::JsValue::from_str(&format!("{}", err))),
}
}
#[wasm_bindgen]
pub fn cheat_get_player() -> Result<(), wasm_bindgen::JsValue> {
match || -> anyhow::Result<()> {
let state = get_cheat_state()?;
state.do_cheat(CheatCommand::GetPlayer());
Ok(())
}() {
// this is not nice
Ok(()) => Ok(()),
Err(err) => Err(wasm_bindgen::JsValue::from_str(&format!("{}", err))),
}
}
......@@ -125,6 +125,14 @@ impl gamestate::State for HeavenState {
self.player.sanity = val;
gamestate::Transition::Keep
}
gamestate::Event::Cheat(cheats::CheatCommand::SetShifts(val)) => {
self.player.shifts_completed = val;
gamestate::Transition::Keep
}
gamestate::Event::Cheat(cheats::CheatCommand::GetPlayer()) => {
crate::console_warn!("Player: {:?}", self.player);
gamestate::Transition::Keep
}
event => {
crate::console_warn!("unknown event: {:?}", event);
gamestate::Transition::Keep
......
......@@ -144,6 +144,9 @@ impl gamestate::State for InGameState {
gamestate::Event::Cheat(cheats::CheatCommand::SetSanity(val)) => {
player.sanity = val;
}
gamestate::Event::Cheat(cheats::CheatCommand::GetPlayer()) => {
crate::console_warn!("Player: {:?}", player);
}
event => {
crate::console_warn!("unknown event: {:?}", event);
}
......
......@@ -6,5 +6,7 @@ wasm.start();
(window as any).cheats = {
set_sanity: wasm.cheat_set_sanity,
set_shifts: wasm.cheat_set_shifts,
get_player: wasm.cheat_get_player,
enable: wasm.cheat_enable,
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment