1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::{
    constants::ReturnCode,
    objects::{OwnedStructure, RoomObject, Store, Structure},
    prelude::*,
};
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
    /// An object representing a [`StructurePowerSpawn`], which can process
    /// power to contribute to your GPL as well as renewing power creeps.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#StructurePowerSpawn)
    #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
    #[derive(Clone, Debug)]
    pub type StructurePowerSpawn;

    /// The [`Store`] of the power spawn, which can contain power and energy.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#StructurePowerSpawn.store)
    #[wasm_bindgen(method, getter)]
    pub fn store(this: &StructurePowerSpawn) -> Store;

    /// Process power, consuming 1 power and [`POWER_SPAWN_ENERGY_RATIO`] energy
    /// and increasing your GPL by one point.
    ///
    /// [Screeps documentation](https://docs.screeps.com/api/#StructurePowerSpawn.processPower)
    ///
    /// [`POWER_SPAWN_ENERGY_RATIO`]:
    /// crate::constants::numbers::POWER_SPAWN_ENERGY_RATIO
    #[wasm_bindgen(method, js_name = processPower)]
    pub fn process_power(this: &StructurePowerSpawn) -> ReturnCode;
}

impl HasStore for StructurePowerSpawn {
    fn store(&self) -> Store {
        Self::store(self)
    }
}