feat: track total berries earned in session and savegames (#61)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::{features::inventory::ui::open_inventory, prelude::*};
|
||||
use crate::features::phase::components::SessionTracker;
|
||||
use components::*;
|
||||
|
||||
pub mod components;
|
||||
@@ -42,11 +43,14 @@ fn debug_modify_berries(
|
||||
mut inventory: ResMut<Inventory>,
|
||||
mut items: Query<&mut ItemStack>,
|
||||
keys: Res<ButtonInput<KeyCode>>,
|
||||
mut session_tracker: ResMut<SessionTracker>,
|
||||
) {
|
||||
if keys.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]) {
|
||||
if keys.just_pressed(KeyCode::ArrowUp) {
|
||||
println!("Adding 1 berry using debug bind");
|
||||
inventory.update_item_stack(&mut commands, &mut items, ItemType::Berry, 1);
|
||||
if inventory.update_item_stack(&mut commands, &mut items, ItemType::Berry, 1) {
|
||||
session_tracker.total_berries_earned += 1;
|
||||
}
|
||||
} else if keys.just_pressed(KeyCode::ArrowDown) {
|
||||
println!("Removing 1 berry using debug bind");
|
||||
inventory.update_item_stack(&mut commands, &mut items, ItemType::Berry, -1);
|
||||
|
||||
@@ -62,4 +62,5 @@ impl Default for TimerSettings {
|
||||
#[derive(Resource, Debug, Default, Serialize, Deserialize, Clone)]
|
||||
pub struct SessionTracker {
|
||||
pub completed_focus_phases: u32,
|
||||
pub total_berries_earned: u32,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::prelude::*;
|
||||
use crate::{features::phase::components::SessionTracker, prelude::*};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum InteractionAction {
|
||||
@@ -88,6 +88,7 @@ impl InteractionAction {
|
||||
item_stack_query: &mut Query<&mut ItemStack>,
|
||||
commands: &mut Commands,
|
||||
game_config: &GameConfig,
|
||||
session_tracker: &mut SessionTracker,
|
||||
) {
|
||||
let Ok(tile_entity) = grid.get_tile(pos) else {
|
||||
println!("Error during interaction: Couldn't get tile_entity");
|
||||
@@ -165,6 +166,7 @@ impl InteractionAction {
|
||||
ItemType::Berry,
|
||||
config.grants as i32,
|
||||
);
|
||||
session_tracker.total_berries_earned += config.grants;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +192,7 @@ fn perform_interaction(
|
||||
mut item_stack_query: Query<&mut ItemStack>,
|
||||
mut commands: Commands,
|
||||
config: Res<GameConfig>,
|
||||
mut session_tracker: ResMut<crate::features::phase::components::SessionTracker>,
|
||||
) {
|
||||
for (pos, mut target_component, path_queue) in pom_query.iter_mut() {
|
||||
if let Some(target) = target_component.target {
|
||||
@@ -215,6 +216,7 @@ fn perform_interaction(
|
||||
&mut item_stack_query,
|
||||
&mut commands,
|
||||
&config,
|
||||
&mut session_tracker,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ struct PartialSaveData {
|
||||
#[derive(Deserialize)]
|
||||
struct PartialSessionTracker {
|
||||
completed_focus_phases: u32,
|
||||
#[serde(default)]
|
||||
total_berries_earned: u32,
|
||||
}
|
||||
|
||||
impl SavegamePath {
|
||||
@@ -77,7 +79,7 @@ impl SavegamePath {
|
||||
savegames.push(SavegameInfo {
|
||||
path: SavegamePath(path),
|
||||
index,
|
||||
total_berries: 0, // TODO: add total_berries
|
||||
total_berries: data.session_tracker.total_berries_earned,
|
||||
completed_focus: data.session_tracker.completed_focus_phases,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user