generated from tipragot/rust
Add resources system (#111)
All checks were successful
Rust Checks / checks (push) Successful in 3m5s
All checks were successful
Rust Checks / checks (push) Successful in 3m5s
closes: #71 Reviewed-on: #111 Reviewed-by: Raphaël <r.lauray@outlook.fr> Co-authored-by: CoCo_Sol007 <solois.corentin@gmail.com> Co-committed-by: CoCo_Sol007 <solois.corentin@gmail.com>
This commit is contained in:
parent
129f219401
commit
106cabe951
|
@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
|
||||||
pub mod camera;
|
pub mod camera;
|
||||||
pub mod map;
|
pub mod map;
|
||||||
pub mod networking;
|
pub mod networking;
|
||||||
|
pub mod resources;
|
||||||
pub mod scenes;
|
pub mod scenes;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ use border_wars::map::ownership::OwnershipPlugin;
|
||||||
use border_wars::map::renderer::RendererPlugin;
|
use border_wars::map::renderer::RendererPlugin;
|
||||||
use border_wars::map::selected_tile::SelectTilePlugin;
|
use border_wars::map::selected_tile::SelectTilePlugin;
|
||||||
use border_wars::networking::NetworkingPlugin;
|
use border_wars::networking::NetworkingPlugin;
|
||||||
|
use border_wars::resources::ResourcesPlugin;
|
||||||
use border_wars::scenes::ScenesPlugin;
|
use border_wars::scenes::ScenesPlugin;
|
||||||
use border_wars::ui::UiPlugin;
|
use border_wars::ui::UiPlugin;
|
||||||
|
|
||||||
|
@ -21,5 +22,6 @@ fn main() {
|
||||||
.add_plugins(MapGenerationPlugin)
|
.add_plugins(MapGenerationPlugin)
|
||||||
.add_plugins(UiPlugin)
|
.add_plugins(UiPlugin)
|
||||||
.add_plugins(OwnershipPlugin)
|
.add_plugins(OwnershipPlugin)
|
||||||
|
.add_plugins(ResourcesPlugin)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
52
crates/border-wars/src/resources.rs
Normal file
52
crates/border-wars/src/resources.rs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
//! All program related to the resources of the game.
|
||||||
|
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
/// The plugin that manage the resources.
|
||||||
|
pub struct ResourcesPlugin;
|
||||||
|
|
||||||
|
impl Plugin for ResourcesPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_event::<ResetResources>()
|
||||||
|
.insert_resource(Resources::initial())
|
||||||
|
.add_systems(Update, handle_reset_resources);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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,
|
||||||
|
}
|
||||||
|
|
||||||
|
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<ResetResources>,
|
||||||
|
mut resources: ResMut<Resources>,
|
||||||
|
) {
|
||||||
|
for _ in reset_resources_event.read() {
|
||||||
|
*resources = Resources::initial();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue