diff --git a/pets-lib/src/battle/mod.rs b/pets-lib/src/battle/mod.rs index 9a247dcd..70d80481 100644 --- a/pets-lib/src/battle/mod.rs +++ b/pets-lib/src/battle/mod.rs @@ -98,9 +98,7 @@ impl INode2D for BattleEngine { fn ready(&mut self) { // The node that contains the text labels below let cont = self.base().get_node_as("%Choices"); - - use crate::wrapped::from_children_of; - self.choices = from_children_of(cont); + self.choices = crate::wrapped::from_children_of(cont); } fn process(&mut self, _delta: f64) { diff --git a/pets-lib/src/main_menu.rs b/pets-lib/src/main_menu.rs index 1f82e429..723a54c3 100644 --- a/pets-lib/src/main_menu.rs +++ b/pets-lib/src/main_menu.rs @@ -118,8 +118,6 @@ impl INode2D for TitleScreen { } fn ready(&mut self) { - // use MainMenuChoice::*; - // The node that contains the text labels below let cont = self.base().get_node_as("Background/MenuChoices"); self.choices = crate::wrapped::from_children_of(cont); diff --git a/pets-lib/src/world/interaction/manager.rs b/pets-lib/src/world/interaction/manager.rs index 06a94332..0603f0a7 100644 --- a/pets-lib/src/world/interaction/manager.rs +++ b/pets-lib/src/world/interaction/manager.rs @@ -11,11 +11,11 @@ use crate::world::interaction::zone::InteractionZone; use crate::world::playercb::PlayerCB; #[derive(GodotClass)] -#[class(init, base=Node2D)] +#[class(base=Node2D)] pub struct InteractionManager { #[base] node: Base, - prompt_txt: Option>, + prompt_txt: OnReady>, /// All interaction zones the player is inside zones: Vec>, @@ -33,10 +33,6 @@ impl InteractionManager { self.zones.retain(|v| *v != obj); } - pub fn prompt_txt(&mut self) -> &mut Gd { - self.prompt_txt.as_mut().unwrap() - } - /// "ummm ackshually, this is not a singleton" pub fn singleton() -> Gd { // using this cool godot feature I just found... @@ -73,8 +69,17 @@ impl InteractionManager { #[godot_api] impl INode2D for InteractionManager { + fn init(node: Base) -> Self { + Self { + node, + prompt_txt: OnReady::manual(), + zones: vec![], + } + } + fn ready(&mut self) { - self.prompt_txt = Some(self.base().get_node_as("Prompt")); + let prompt_txt = self.base().get_node_as("Prompt"); + self.prompt_txt.init(prompt_txt); } fn process(&mut self, _delta: f64) { @@ -82,16 +87,14 @@ impl INode2D for InteractionManager { let Some(zone) = self.closest_zone() else { // if no zones, hide the prompt - self.prompt_txt().hide(); - + self.prompt_txt.hide(); return; }; - let txt = self.prompt_txt(); - txt.show(); - // move the prompt to the zone - txt.set_position(zone.get_position() + Vector2::new(0.0, -50.0)); + self.prompt_txt.show(); + self.prompt_txt + .set_position(zone.get_position() + Vector2::new(0.0, -50.0)); } fn unhandled_input(&mut self, event: Gd) { diff --git a/pets-lib/src/world/pchar_node.rs b/pets-lib/src/world/pchar_node.rs index 6ec7538c..f0a75983 100644 --- a/pets-lib/src/world/pchar_node.rs +++ b/pets-lib/src/world/pchar_node.rs @@ -5,15 +5,15 @@ use godot::engine::Sprite2D; use godot::prelude::*; #[derive(GodotClass)] -#[class(init, base=Node2D)] +#[class(base=Node2D)] pub struct PCharNode { #[base] - node: Base, + base: Base, - sprite: Option>, - anim_player: Option>, - anim_tree: Option>, - anim_state: Option>, + sprite: OnReady>, + anim_player: OnReady>, + anim_tree: OnReady>, + anim_state: OnReady>, } #[godot_api] @@ -23,11 +23,8 @@ impl PCharNode { let mode_str = if moving { "Run" } else { "Idle" }; let anim_path = format!("parameters/{mode_str}/blend_position"); - self.anim_tree - .as_mut() - .unwrap() - .set(anim_path.into(), Variant::from(inputs)); - self.anim_state.as_mut().unwrap().travel(mode_str.into()); + self.anim_tree.set(anim_path.into(), Variant::from(inputs)); + self.anim_state.travel(mode_str.into()); } } @@ -57,14 +54,27 @@ macro_rules! load_pchar_scene_under { #[godot_api] impl INode2D for PCharNode { + fn init(base: Base) -> Self { + Self { + base, + sprite: OnReady::manual(), + anim_player: OnReady::manual(), + anim_tree: OnReady::manual(), + anim_state: OnReady::manual(), + } + } + fn ready(&mut self) { - self.sprite = Some(self.base().get_node_as("Sprite2D")); - self.anim_player = Some(self.base().get_node_as("AnimationPlayer")); + let sprite = self.base().get_node_as("Sprite2D"); + let anim_player = self.base().get_node_as("AnimationPlayer"); + self.sprite.init(sprite); + self.anim_player.init(anim_player); let mut tree = self.base().get_node_as::("AnimationTree"); tree.set_active(true); - self.anim_state = tree.get("parameters/playback".into()).to(); + let anim_state = tree.get("parameters/playback".into()).to(); + self.anim_state.init(anim_state); - self.anim_tree = Some(tree); + self.anim_tree.init(tree); } }