feat: Implement crop withering mechanics (#28)
This commit is contained in:
@@ -22,6 +22,10 @@ pub enum TileState {
|
||||
seed: ItemType,
|
||||
watered: bool,
|
||||
growth_stage: u32,
|
||||
#[serde(default)]
|
||||
withered: bool,
|
||||
#[serde(default)]
|
||||
dry_counter: u8,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,8 @@ fn debug_click(
|
||||
},
|
||||
watered: false,
|
||||
growth_stage: 0,
|
||||
withered: false,
|
||||
dry_counter: 0,
|
||||
},
|
||||
TileState::Occupied { .. } => TileState::Unclaimed,
|
||||
},
|
||||
|
||||
@@ -176,21 +176,34 @@ pub fn handle_continue(
|
||||
seed,
|
||||
watered,
|
||||
growth_stage,
|
||||
withered,
|
||||
dry_counter,
|
||||
} = &*state
|
||||
{
|
||||
let mut new_stage = *growth_stage;
|
||||
let mut new_withered = *withered;
|
||||
let mut new_dry_counter = *dry_counter;
|
||||
|
||||
if *watered {
|
||||
new_dry_counter = 0;
|
||||
if let Some(config) = seed.get_seed_config(&game_config) {
|
||||
if new_stage < config.growth_stages {
|
||||
if new_stage < config.growth_stages && !new_withered {
|
||||
new_stage += 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
new_dry_counter += 1;
|
||||
if new_dry_counter >= 2 {
|
||||
new_withered = true;
|
||||
}
|
||||
}
|
||||
|
||||
*state = TileState::Occupied {
|
||||
seed: seed.clone(),
|
||||
watered: false,
|
||||
growth_stage: new_stage,
|
||||
withered: new_withered,
|
||||
dry_counter: new_dry_counter,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,8 @@ impl InteractionAction {
|
||||
seed: seed_type.clone(),
|
||||
watered: false,
|
||||
growth_stage: 0,
|
||||
withered: false,
|
||||
dry_counter: 0,
|
||||
};
|
||||
} else {
|
||||
println!("No {:?} in inventory!", seed_type);
|
||||
@@ -102,12 +104,20 @@ impl InteractionAction {
|
||||
}
|
||||
}
|
||||
InteractionAction::Water => {
|
||||
if let TileState::Occupied { seed, growth_stage, .. } = &*tile_state {
|
||||
if let TileState::Occupied {
|
||||
seed,
|
||||
growth_stage,
|
||||
withered,
|
||||
..
|
||||
} = &*tile_state
|
||||
{
|
||||
println!("Watering {:?}", seed);
|
||||
*tile_state = TileState::Occupied {
|
||||
seed: seed.clone(),
|
||||
watered: true,
|
||||
growth_stage: *growth_stage,
|
||||
withered: *withered,
|
||||
dry_counter: 0,
|
||||
};
|
||||
} else {
|
||||
println!("Tile is not occupied, cannot water.");
|
||||
|
||||
@@ -86,6 +86,8 @@ fn test_crop_growth_logic() {
|
||||
seed: seed_type.clone(),
|
||||
watered: true,
|
||||
growth_stage: 0,
|
||||
withered: false,
|
||||
dry_counter: 0,
|
||||
},
|
||||
),
|
||||
(
|
||||
@@ -95,6 +97,8 @@ fn test_crop_growth_logic() {
|
||||
seed: seed_type.clone(),
|
||||
watered: false,
|
||||
growth_stage: 0,
|
||||
withered: false,
|
||||
dry_counter: 0,
|
||||
},
|
||||
),
|
||||
(
|
||||
@@ -104,6 +108,8 @@ fn test_crop_growth_logic() {
|
||||
seed: seed_type.clone(),
|
||||
watered: true,
|
||||
growth_stage: 2, // Max
|
||||
withered: false,
|
||||
dry_counter: 0,
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
@@ -180,6 +180,8 @@ fn test_water_crop() {
|
||||
seed: seed_type.clone(),
|
||||
watered: false,
|
||||
growth_stage: 0,
|
||||
withered: false,
|
||||
dry_counter: 0,
|
||||
},
|
||||
)],
|
||||
vec![],
|
||||
|
||||
@@ -95,6 +95,8 @@ fn test_find_path_around_obstacle() {
|
||||
},
|
||||
watered: false,
|
||||
growth_stage: 0,
|
||||
withered: false,
|
||||
dry_counter: 0,
|
||||
};
|
||||
let obstacles = vec![
|
||||
(2, 2, obstacle.clone()),
|
||||
@@ -148,6 +150,8 @@ fn test_find_path_no_path() {
|
||||
},
|
||||
watered: false,
|
||||
growth_stage: 0,
|
||||
withered: false,
|
||||
dry_counter: 0,
|
||||
};
|
||||
let obstacles = vec![
|
||||
(2, 0, obstacle.clone()),
|
||||
|
||||
Reference in New Issue
Block a user