feat: Add watering (#27)
This commit is contained in:
@@ -10,6 +10,9 @@ pub struct Tile {
|
||||
#[derive(Component)]
|
||||
pub struct CropVisual;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct WaterVisual;
|
||||
|
||||
#[derive(Component, Default, Serialize, Deserialize, Clone, Debug)]
|
||||
pub enum TileState {
|
||||
#[default]
|
||||
@@ -17,6 +20,7 @@ pub enum TileState {
|
||||
Empty,
|
||||
Occupied {
|
||||
seed: ItemType,
|
||||
watered: bool,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use components::CropVisual;
|
||||
use components::{CropVisual, WaterVisual};
|
||||
|
||||
pub mod components;
|
||||
pub mod consts;
|
||||
@@ -55,6 +55,17 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, config: Res<Gam
|
||||
Visibility::Hidden,
|
||||
ZIndex(1),
|
||||
));
|
||||
parent.spawn((
|
||||
WaterVisual,
|
||||
AseSlice {
|
||||
name: "Water".into(),
|
||||
aseprite: asset_server.load("crop.aseprite"),
|
||||
},
|
||||
Sprite::default(),
|
||||
Transform::default(),
|
||||
Visibility::Hidden,
|
||||
ZIndex(2),
|
||||
));
|
||||
})
|
||||
.id();
|
||||
column.push(tile_entity);
|
||||
@@ -78,7 +89,8 @@ fn cleanup(mut commands: Commands, tile_query: Query<Entity, With<Tile>>) {
|
||||
|
||||
fn update_tiles(
|
||||
mut query: Query<(&TileState, &mut AseSlice, &Children)>,
|
||||
mut crop_query: Query<&mut Visibility, With<CropVisual>>,
|
||||
mut crop_query: Query<&mut Visibility, (With<CropVisual>, Without<WaterVisual>)>,
|
||||
mut water_query: Query<&mut Visibility, (With<WaterVisual>, Without<CropVisual>)>,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
for (state, mut slice, children) in &mut query {
|
||||
@@ -102,6 +114,12 @@ fn update_tiles(
|
||||
_ => Visibility::Hidden,
|
||||
};
|
||||
}
|
||||
if let Ok(mut visibility) = water_query.get_mut(child) {
|
||||
*visibility = match state {
|
||||
TileState::Occupied { watered: true, .. } => Visibility::Visible,
|
||||
_ => Visibility::Hidden,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ fn debug_click(
|
||||
seed: ItemType::BerrySeed {
|
||||
name: "Debug".into(),
|
||||
},
|
||||
watered: false,
|
||||
},
|
||||
TileState::Occupied { .. } => TileState::Unclaimed,
|
||||
},
|
||||
|
||||
@@ -157,8 +157,27 @@ fn handle_continue(
|
||||
mut phase_res: ResMut<CurrentPhase>,
|
||||
mut session_tracker: ResMut<SessionTracker>,
|
||||
settings: Res<TimerSettings>,
|
||||
mut tile_query: Query<&mut TileState>,
|
||||
) {
|
||||
for _ in messages.read() {
|
||||
let entering_break = if let Phase::Finished { completed_phase } = &phase_res.0 {
|
||||
matches!(**completed_phase, Phase::Focus { .. })
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
next_phase(&mut phase_res, &mut session_tracker, &settings);
|
||||
|
||||
if entering_break {
|
||||
println!("Resetting watered state for all crops.");
|
||||
for mut state in tile_query.iter_mut() {
|
||||
if let TileState::Occupied { seed, .. } = &*state {
|
||||
*state = TileState::Occupied {
|
||||
seed: seed.clone(),
|
||||
watered: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@ use crate::prelude::*;
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum InteractionAction {
|
||||
Plant(ItemType),
|
||||
Water,
|
||||
}
|
||||
|
||||
impl InteractionAction {
|
||||
pub fn get_name(&self, game_config: &GameConfig) -> String {
|
||||
match self {
|
||||
InteractionAction::Plant(item) => format!("Pflanze {}", item.singular(game_config)),
|
||||
InteractionAction::Water => "Gießen".into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +21,7 @@ impl InteractionAction {
|
||||
) -> Option<AseSlice> {
|
||||
match self {
|
||||
InteractionAction::Plant(item) => Some(item.get_sprite(asset_server, game_config)),
|
||||
InteractionAction::Water => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +51,15 @@ impl InteractionAction {
|
||||
}
|
||||
}
|
||||
|
||||
match tile_state {
|
||||
TileState::Occupied { watered, .. } => {
|
||||
if !*watered {
|
||||
options.push(InteractionAction::Water);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
options
|
||||
}
|
||||
|
||||
@@ -81,6 +93,7 @@ impl InteractionAction {
|
||||
println!("Planting {:?}", seed_type);
|
||||
*tile_state = TileState::Occupied {
|
||||
seed: seed_type.clone(),
|
||||
watered: false,
|
||||
};
|
||||
} else {
|
||||
println!("No {:?} in inventory!", seed_type);
|
||||
@@ -89,6 +102,17 @@ impl InteractionAction {
|
||||
println!("Tile is not empty, cannot plant.");
|
||||
}
|
||||
}
|
||||
InteractionAction::Water => {
|
||||
if let TileState::Occupied { seed, .. } = &*tile_state {
|
||||
println!("Watering {:?}", seed);
|
||||
*tile_state = TileState::Occupied {
|
||||
seed: seed.clone(),
|
||||
watered: true,
|
||||
};
|
||||
} else {
|
||||
println!("Tile is not occupied, cannot water.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user