Commit 0f20277f authored by Rahix's avatar Rahix 🦀

Add second macro for cheats

parent 564163c5
......@@ -32,3 +32,33 @@ pub fn angel_system(args: TokenStream, input: TokenStream) -> TokenStream {
)
.into()
}
#[proc_macro_attribute]
pub fn wasm_bindgen_anyhow(_args: TokenStream, input: TokenStream) -> TokenStream {
let f = syn::parse_macro_input!(input as syn::ItemFn);
let fname = f.sig.ident;
let attrs = f.attrs;
let inputs = f.sig.inputs;
let block = f.block;
let stmts = block.stmts;
let rtype = f.sig.output;
let vis = f.vis;
quote::quote!(
#[wasm_bindgen]
#(#attrs)*
#vis fn #fname(#inputs) -> Result<(), wasm_bindgen::JsValue> {
match || #rtype {
#(#stmts)*
}() {
Ok(()) => Ok(()),
Err(err) => Err(
wasm_bindgen::JsValue::from_str(&format!("{}", err))
),
}
}
)
.into()
}
......@@ -54,41 +54,23 @@ pub fn cheat_enable(password: &str) {
}
}
#[wasm_bindgen]
pub fn cheat_set_sanity(val: f32) -> Result<(), wasm_bindgen::JsValue> {
match || -> anyhow::Result<()> {
// this is nice
let state = get_cheat_state()?;
state.do_cheat(CheatCommand::SetSanity(val))?;
Ok(())
}() {
// this is not nice
Ok(()) => Ok(()),
Err(err) => Err(wasm_bindgen::JsValue::from_str(&format!("{}", err))),
}
#[macro_impl::wasm_bindgen_anyhow]
pub fn cheat_set_sanity(val: f32) -> anyhow::Result<()> {
let state = get_cheat_state()?;
state.do_cheat(CheatCommand::SetSanity(val))?;
Ok(())
}
#[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))),
}
#[macro_impl::wasm_bindgen_anyhow]
pub fn cheat_set_shifts(val: u32) -> anyhow::Result<()> {
let state = get_cheat_state()?;
state.do_cheat(CheatCommand::SetShifts(val))?;
Ok(())
}
#[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))),
}
#[macro_impl::wasm_bindgen_anyhow]
pub fn cheat_get_player() -> anyhow::Result<()> {
let state = get_cheat_state()?;
state.do_cheat(CheatCommand::GetPlayer())?;
Ok(())
}
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