Added GameManager to glue systems together
parent
cd378a9e82
commit
7492d96cee
|
|
@ -5,7 +5,13 @@
|
||||||
[ext_resource type="PackedScene" uid="uid://drs6h7ks4r2ta" path="res://prefabs/player/player.tscn" id="3_u2ss0"]
|
[ext_resource type="PackedScene" uid="uid://drs6h7ks4r2ta" path="res://prefabs/player/player.tscn" id="3_u2ss0"]
|
||||||
[ext_resource type="PackedScene" uid="uid://blutrglw7mycx" path="res://prefabs/ui/ui.tscn" id="4_356oe"]
|
[ext_resource type="PackedScene" uid="uid://blutrglw7mycx" path="res://prefabs/ui/ui.tscn" id="4_356oe"]
|
||||||
|
|
||||||
[node name="TurnManager" type="TurnManager"]
|
[node name="GameManager" type="GameManager" node_paths=PackedStringArray("_time_manager", "_turn_manager")]
|
||||||
|
_time_manager = NodePath("TimeManager")
|
||||||
|
_turn_manager = NodePath("TurnManager")
|
||||||
|
|
||||||
|
[node name="TimeManager" type="TimeManager" parent="."]
|
||||||
|
|
||||||
|
[node name="TurnManager" type="TurnManager" parent="."]
|
||||||
|
|
||||||
[node name="World" type="Level" parent="." node_paths=PackedStringArray("background", "foreground")]
|
[node name="World" type="Level" parent="." node_paths=PackedStringArray("background", "foreground")]
|
||||||
background = NodePath("Background")
|
background = NodePath("Background")
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ texture_region_size = Vector2i(32, 32)
|
||||||
2:3/0 = 0
|
2:3/0 = 0
|
||||||
2:3/0/custom_data_0 = true
|
2:3/0/custom_data_0 = true
|
||||||
0:3/0 = 0
|
0:3/0 = 0
|
||||||
|
0:3/0/custom_data_0 = true
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
tile_size = Vector2i(32, 32)
|
tile_size = Vector2i(32, 32)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
use godot::{classes::*, prelude::*};
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Debug, GodotClass)]
|
||||||
|
#[class(init, base=Node)]
|
||||||
|
pub struct GameManager {
|
||||||
|
#[export]
|
||||||
|
_time_manager: Option<Gd<TimeManager>>,
|
||||||
|
#[export]
|
||||||
|
_turn_manager: Option<Gd<TurnManager>>,
|
||||||
|
|
||||||
|
base: Base<Node>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[godot_api]
|
||||||
|
impl INode for GameManager {}
|
||||||
|
|
||||||
|
#[godot_api]
|
||||||
|
impl GameManager {
|
||||||
|
pub fn get<T: Inherits<Node>>(node: Gd<T>) -> Gd<Self> {
|
||||||
|
find_in_parents(node).expect("Getting GameManager")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[func]
|
||||||
|
pub fn from_node(node: Gd<Node>) -> Gd<Self> {
|
||||||
|
find_in_parents(node).expect("Getting GameManager")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[func]
|
||||||
|
pub fn time(&self) -> Gd<TimeManager> {
|
||||||
|
self._time_manager
|
||||||
|
.clone()
|
||||||
|
.expect("Getting TimeManager for GameManager")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[func]
|
||||||
|
pub fn turn(&self) -> Gd<TurnManager> {
|
||||||
|
self._turn_manager
|
||||||
|
.clone()
|
||||||
|
.expect("Getting TurnManager for GameManager")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, GodotClass)]
|
||||||
|
#[class(init, base=Node)]
|
||||||
|
pub struct TimeManager {
|
||||||
|
time_of_day: i32,
|
||||||
|
|
||||||
|
base: Base<Node>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[godot_api]
|
||||||
|
impl INode for TimeManager {}
|
||||||
|
|
||||||
|
#[godot_api]
|
||||||
|
impl TimeManager {
|
||||||
|
#[func]
|
||||||
|
pub fn reset_time(&mut self) {
|
||||||
|
self.time_of_day = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[func]
|
||||||
|
pub fn advance_time(&mut self, amount: i32) {
|
||||||
|
self.time_of_day += amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ use godot::prelude::*;
|
||||||
|
|
||||||
pub struct VelhoExtension;
|
pub struct VelhoExtension;
|
||||||
|
|
||||||
|
mod game_manager;
|
||||||
mod gathering;
|
mod gathering;
|
||||||
mod grid;
|
mod grid;
|
||||||
mod inventory;
|
mod inventory;
|
||||||
|
|
@ -9,6 +10,7 @@ mod turn;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
|
pub use super::game_manager::*;
|
||||||
pub use super::gathering::*;
|
pub use super::gathering::*;
|
||||||
pub use super::grid::*;
|
pub use super::grid::*;
|
||||||
pub use super::inventory::*;
|
pub use super::inventory::*;
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ impl TurnManager {
|
||||||
self.current_actor = None;
|
self.current_actor = None;
|
||||||
self.round_queue = self.new_round();
|
self.round_queue = self.new_round();
|
||||||
if !self.round_queue.is_empty() {
|
if !self.round_queue.is_empty() {
|
||||||
self.base_mut().propagate_call_ex("on_round_start").done();
|
GameManager::get(self.to_gd()).propagate_call("on_round_start");
|
||||||
self.start_next_turn();
|
self.start_next_turn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,10 +81,9 @@ impl TurnManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_actor_turn_end(&mut self, action: GString) {
|
fn on_actor_turn_end(&mut self, action: GString) {
|
||||||
let actor = self.current_actor.clone();
|
GameManager::get(self.to_gd())
|
||||||
self.base_mut()
|
|
||||||
.propagate_call_ex("on_turn_end")
|
.propagate_call_ex("on_turn_end")
|
||||||
.args(&varray![actor, action])
|
.args(&varray![self.current_actor, action])
|
||||||
.done();
|
.done();
|
||||||
self.start_next_turn();
|
self.start_next_turn();
|
||||||
}
|
}
|
||||||
|
|
@ -127,11 +126,8 @@ impl INode2D for TurnActor {
|
||||||
fn ready(&mut self) {}
|
fn ready(&mut self) {}
|
||||||
|
|
||||||
fn enter_tree(&mut self) {
|
fn enter_tree(&mut self) {
|
||||||
let manager: Option<Gd<TurnManager>> = find_in_parents(self.to_gd());
|
let managers = GameManager::get(self.to_gd());
|
||||||
match manager {
|
managers.bind().turn().bind_mut().register(self.to_gd())
|
||||||
Some(mut manager) => manager.bind_mut().register(self.to_gd()),
|
|
||||||
None => godot_error!("No TurnManager found for TurnActor"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue