screeps-game-api icon indicating copy to clipboard operation
screeps-game-api copied to clipboard

feat: use gloo_utils for parsing

Open NekoFluff opened this issue 2 years ago • 3 comments

This PR does two things:

  1. Use JSValue::.into_serde() from gloo utils. I was having problems with the serde_wasm_bindgen::from_value. More specifically, I kept seeing: caught exception: SyntaxError: Unexpected token {
  2. By adding Serialize to the Path enum, we can easily call move_by_path using the serialized/stringified version of the Path.

e.g.

creep.move_by_path(&JsValue::from_str(&path.to_string()))

NekoFluff avatar Sep 21 '23 00:09 NekoFluff

Close it, merge it, w/e you wish. I couldn't get serde_wasm_bindgen working locally so I just wanted to leave this here if anyone else encountered a similar issue.

NekoFluff avatar Sep 21 '23 00:09 NekoFluff

Tried to reproduce this, and wasn't able to - can you provide any more info about how you're calling this that it's not working? I'm doing a simple test of find_path_to from one Position to another with a default callback and it's deserializing the returned result happily via serde-wasm-bindgen.

shanemadden avatar Oct 12 '23 02:10 shanemadden

Hmm interesting. I haven't played screeps in a hot second, but I can pull up my code and give it another whirl with the main branch this weekend to see if the issue still persists.

NekoFluff avatar Dec 08 '23 18:12 NekoFluff