From 5eb3c5d0dae4a1491b145d9bd9a3d7549b39fe1a Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Mon, 27 Nov 2023 18:12:50 -0700 Subject: [PATCH 1/2] Handle object returns for RoomTerrain::get_raw_buffer_to_array --- CHANGELOG.md | 1 + src/objects/impls/room_terrain.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46f3c646..0925e723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Unreleased - Implement `JsCollectionIntoValue` for `Direction`, making the `JsHashMap` returned by `game::map::describe_exits` able to be used +- Handle object return properly from `RoomTerrain::get_raw_buffer_to_array` when built in dev mode 0.16.1 (2023-10-11) =================== diff --git a/src/objects/impls/room_terrain.rs b/src/objects/impls/room_terrain.rs index ed37062f..ed163e73 100644 --- a/src/objects/impls/room_terrain.rs +++ b/src/objects/impls/room_terrain.rs @@ -30,7 +30,7 @@ extern "C" { // and when called with a destination, it can only ever return a return code int #[wasm_bindgen(method, js_name = getRawBuffer)] - fn get_raw_buffer_to_array_internal(this: &RoomTerrain, destination: &Uint8Array) -> i8; + fn get_raw_buffer_to_array_internal(this: &RoomTerrain, destination: &Uint8Array) -> JsValue; } impl RoomTerrain { @@ -58,6 +58,13 @@ impl RoomTerrain { /// [Screeps documentation](https://docs.screeps.com/api/#Room.Terrain.getRawBuffer) #[inline] pub fn get_raw_buffer_to_array(&self, destination: &Uint8Array) -> Result<(), ErrorCode> { - ErrorCode::result_from_i8(self.get_raw_buffer_to_array_internal(destination)) + let val = self.get_raw_buffer_to_array_internal(destination); + + // val is integer if error; if object it's another reference to the Uint8Array; function + // was successful in that case + match val.as_f64() { + Some(n) => ErrorCode::result_from_i8(n as i8), + None => Ok(()) + } } } From 480f91eff5b1868a8351b870588b4d5eb8e3b754 Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Mon, 27 Nov 2023 18:13:25 -0700 Subject: [PATCH 2/2] fmt --- src/objects/impls/room_terrain.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/objects/impls/room_terrain.rs b/src/objects/impls/room_terrain.rs index ed163e73..fe193694 100644 --- a/src/objects/impls/room_terrain.rs +++ b/src/objects/impls/room_terrain.rs @@ -60,11 +60,11 @@ impl RoomTerrain { pub fn get_raw_buffer_to_array(&self, destination: &Uint8Array) -> Result<(), ErrorCode> { let val = self.get_raw_buffer_to_array_internal(destination); - // val is integer if error; if object it's another reference to the Uint8Array; function - // was successful in that case + // val is integer if error; if object it's another reference to the Uint8Array; + // function was successful in that case match val.as_f64() { Some(n) => ErrorCode::result_from_i8(n as i8), - None => Ok(()) + None => Ok(()), } } }