From 1fa3c8f26803a662f57d5cf123a09c6aaee436c6 Mon Sep 17 00:00:00 2001 From: CoCo_Sol007 Date: Fri, 5 Apr 2024 07:40:04 +0200 Subject: [PATCH 1/4] save --- crates/border-wars/src/lib.rs | 1 + crates/border-wars/src/resources.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 crates/border-wars/src/resources.rs diff --git a/crates/border-wars/src/lib.rs b/crates/border-wars/src/lib.rs index fc115d4..836b4c8 100644 --- a/crates/border-wars/src/lib.rs +++ b/crates/border-wars/src/lib.rs @@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize}; pub mod camera; pub mod map; pub mod networking; +pub mod resources; pub mod scenes; pub mod ui; diff --git a/crates/border-wars/src/resources.rs b/crates/border-wars/src/resources.rs new file mode 100644 index 0000000..a9058f9 --- /dev/null +++ b/crates/border-wars/src/resources.rs @@ -0,0 +1,16 @@ +//! ToDo + +use bevy::prelude::*; + +/// The resources of the game. +#[derive(Resource, Default)] +pub struct Resources { + /// The stone resource. + pub stone: u32, + + /// The wood resource. + pub wood: u32, + + /// The food resource. + pub food: u32, +} -- 2.43.4 From 562c7bbab6b028ea005305e12d80f502e441efe9 Mon Sep 17 00:00:00 2001 From: CoCo_Sol007 Date: Fri, 5 Apr 2024 08:50:35 +0200 Subject: [PATCH 2/4] save --- crates/border-wars/src/main.rs | 2 ++ crates/border-wars/src/resources.rs | 36 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/crates/border-wars/src/main.rs b/crates/border-wars/src/main.rs index a7c9a63..9abc85c 100644 --- a/crates/border-wars/src/main.rs +++ b/crates/border-wars/src/main.rs @@ -7,6 +7,7 @@ use border_wars::map::ownership::OwnershipPlugin; use border_wars::map::renderer::RendererPlugin; use border_wars::map::selected_tile::SelectTilePlugin; use border_wars::networking::NetworkingPlugin; +use border_wars::resources::ResourcesPlugin; use border_wars::scenes::ScenesPlugin; use border_wars::ui::UiPlugin; @@ -21,5 +22,6 @@ fn main() { .add_plugins(MapGenerationPlugin) .add_plugins(UiPlugin) .add_plugins(OwnershipPlugin) + .add_plugins(ResourcesPlugin) .run(); } diff --git a/crates/border-wars/src/resources.rs b/crates/border-wars/src/resources.rs index a9058f9..52e3f6e 100644 --- a/crates/border-wars/src/resources.rs +++ b/crates/border-wars/src/resources.rs @@ -2,6 +2,17 @@ use bevy::prelude::*; +/// The resources plugin. +pub struct ResourcesPlugin; + +impl Plugin for ResourcesPlugin { + fn build(&self, app: &mut App) { + app.add_event::() + .insert_resource(Resources::initial()) + .add_systems(Update, handle_reset_resources); + } +} + /// The resources of the game. #[derive(Resource, Default)] pub struct Resources { @@ -14,3 +25,28 @@ pub struct Resources { /// The food resource. pub food: u32, } + +impl Resources { + /// Returns the initial resources of the game. + const fn initial() -> Self { + Self { + stone: 100, + wood: 100, + food: 100, + } + } +} + +/// An event send to reset the resources of the game. +#[derive(Event)] +pub struct ResetResources; + +/// Handles the reset resources event. +fn handle_reset_resources( + mut reset_resources_event: EventReader, + mut resources: ResMut, +) { + for _ in reset_resources_event.read() { + *resources = Resources::initial(); + } +} -- 2.43.4 From dde57a6e5079b8d7eb7502eb44fe7819f973e8f8 Mon Sep 17 00:00:00 2001 From: CoCo_Sol007 Date: Fri, 5 Apr 2024 08:57:36 +0200 Subject: [PATCH 3/4] add doc --- crates/border-wars/src/resources.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/border-wars/src/resources.rs b/crates/border-wars/src/resources.rs index 52e3f6e..273cd72 100644 --- a/crates/border-wars/src/resources.rs +++ b/crates/border-wars/src/resources.rs @@ -1,4 +1,4 @@ -//! ToDo +//! All program related to the resources of the game. use bevy::prelude::*; -- 2.43.4 From b983fc04d8413048dc2961ffebe61d687b00b2eb Mon Sep 17 00:00:00 2001 From: CoCo_Sol007 Date: Fri, 5 Apr 2024 12:46:05 +0200 Subject: [PATCH 4/4] change docs --- crates/border-wars/src/resources.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/border-wars/src/resources.rs b/crates/border-wars/src/resources.rs index 273cd72..b5b5b7c 100644 --- a/crates/border-wars/src/resources.rs +++ b/crates/border-wars/src/resources.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; -/// The resources plugin. +/// The plugin that manage the resources. pub struct ResourcesPlugin; impl Plugin for ResourcesPlugin { -- 2.43.4