Created
August 14, 2025 18:17
-
-
Save Kielan/1366476fb6c0c28492e56edfa4024d6c to your computer and use it in GitHub Desktop.
Example Impl of FF7/BOTW Inventory in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Player { | |
state: State, | |
} | |
impl Player { | |
fn new() -> Self { | |
Self { state: PlayerCharacterInstance } | |
} | |
fn collect(&mut self, ability: Transition) { | |
match (&self.state, power) { | |
(&self.state, ItemPickup) => self.state = PlayerCharacterInstanceNewStateItemPickup(ItemPickup), | |
(_, ItemPickupAntipattern) => self.state = PlayerCharacterInstanceNewStateItemPickupAntipattern(ItemPickupAntipattern), | |
(_, ItemPickupTest) => { | |
printl!("item picked up") | |
} | |
} | |
} | |
} | |
fn main() { | |
let mut player_instance = Player::new(); | |
player_instance.collect(ItemPickup); | |
player_instance.collect(ItemPickupAntipattern); | |
player_instance.collect(ItemPickupTest); | |
assert!(player_instance.state == PlayerCharacterInstanceStateItemPickup); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment