rpgx_wasm/engine/
pawn.rs

1use crate::prelude::WasmCoordinates; // Assuming you have a WasmTile wrapper
2use rpgx::prelude::Pawn;
3use wasm_bindgen::prelude::*;
4
5#[wasm_bindgen(js_name = Pawn)]
6pub struct WasmPawn {
7    inner: Pawn,
8}
9
10#[wasm_bindgen(js_class = Pawn)]
11impl WasmPawn {
12    #[wasm_bindgen(constructor)]
13    pub fn new(pointer: WasmCoordinates, texture_id: u32) -> WasmPawn {
14        WasmPawn {
15            inner: Pawn {
16                pointer: pointer.into_inner(),
17                texture_id,
18            },
19        }
20    }
21
22    #[wasm_bindgen(getter)]
23    pub fn pointer(&self) -> WasmCoordinates {
24        WasmCoordinates::from_inner(self.inner.pointer.clone())
25    }
26
27    #[wasm_bindgen(setter)]
28    pub fn set_tile(&mut self, pointer: WasmCoordinates) {
29        self.inner.pointer = pointer.into_inner();
30    }
31
32    #[wasm_bindgen(getter, js_name = textureId)]
33    pub fn texture_id(&self) -> u32 {
34        self.inner.texture_id
35    }
36
37    #[wasm_bindgen(setter, js_name = textureId)]
38    pub fn set_texture_id(&mut self, texture_id: u32) {
39        self.inner.texture_id = texture_id;
40    }
41}
42
43impl WasmPawn {
44    // Converts WasmPawn into the inner Pawn
45    pub fn into_inner(self) -> Pawn {
46        self.inner
47    }
48
49    // Creates WasmPawn from inner Pawn
50    pub fn from_inner(inner: Pawn) -> WasmPawn {
51        WasmPawn { inner }
52    }
53
54    // Access inner reference
55    pub fn inner(&self) -> &Pawn {
56        &self.inner
57    }
58
59    pub fn inner_mut(&mut self) -> &mut Pawn {
60        &mut self.inner
61    }
62}