Skip to content

Commit

Permalink
Add RTFM upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Dec 7, 2023
1 parent c01e202 commit 8859791
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
21 changes: 1 addition & 20 deletions src/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use rand::Rng;

use crate::physics::Velocity;
use crate::state::editor_screen::WrapWithinSceneView;
use crate::upgrade::UpgradeEvent;
use crate::upgrade::UpgradeList;
use crate::util::OverflowDespawnQueue;
use crate::AppRoot;
use crate::AppSet;
Expand All @@ -21,13 +19,7 @@ impl Plugin for SimulationPlugin {
.add_event::<SpawnEvent>()
.init_resource::<Simulation>()
.add_systems(Startup, spawn_entity_caps)
.add_systems(
Update,
(
count_upgrades_and_tech_debt.in_set(AppSet::Simulate),
spawn_entities.in_set(AppSet::Simulate),
),
);
.add_systems(Update, spawn_entities.in_set(AppSet::Simulate));
}
}

Expand All @@ -40,17 +32,6 @@ pub struct Simulation {
pub tech_debt: f64,
}

fn count_upgrades_and_tech_debt(
mut events: EventReader<UpgradeEvent>,
upgrade_list: Res<UpgradeList>,
mut simulation: ResMut<Simulation>,
) {
for event in events.read() {
simulation.upgrades += 1;
simulation.tech_debt += upgrade_list[event.0].tech_debt;
}
}

#[derive(Event, Reflect)]
pub struct SpawnEvent(pub Vec2);

Expand Down
40 changes: 35 additions & 5 deletions src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ impl Plugin for UpgradePlugin {
.add_systems(Startup, load_upgrade_list)
.add_systems(
Update,
(install_upgrades, run_installed_upgrades, apply_deferred)
.chain()
.in_set(AppSet::RunUpgrades),
(
(install_upgrades, run_installed_upgrades, apply_deferred)
.chain()
.in_set(AppSet::RunUpgrades),
process_new_installed_upgrades.in_set(AppSet::Simulate),
),
);
}
}
Expand Down Expand Up @@ -155,6 +158,18 @@ fn run_installed_upgrades(world: &mut World) {
}
}

fn process_new_installed_upgrades(
mut events: EventReader<UpgradeEvent>,
mut upgrade_list: ResMut<UpgradeList>,
mut simulation: ResMut<Simulation>,
) {
for event in events.read() {
upgrade_list[event.0].remaining -= 1;
simulation.upgrades += 1;
simulation.tech_debt += upgrade_list[event.0].tech_debt;
}
}

#[derive(Resource, Default)]
pub struct UpgradeList(pub Vec<Upgrade>);

Expand Down Expand Up @@ -292,13 +307,28 @@ generate_upgrade_list!(
TenXDev: Upgrade {
name: "10x Dev".to_string(),
description: "Multiplies the number of characters typed per key press by 10.".to_string(),
base_cost: 50.0,
base_cost: 100.0,
tech_debt: 0.0,
weight: 0.5,
install: Some(world.register_system(|mut typer_query: Query<&mut CodeTyper>| {
for mut typer in &mut typer_query {
typer.chars_per_key *= 10;
}
})),
..default()
}
},
Rtfm: Upgrade {
name: "RTFM".to_string(),
description: "Multiplies the number of characters typed per key press by 2.".to_string(),
base_cost: 50.0,
tech_debt: -1.0,
weight: 0.5,
remaining: 4,
install: Some(world.register_system(|mut typer_query: Query<&mut CodeTyper>| {
for mut typer in &mut typer_query {
typer.chars_per_key *= 2;
}
})),
..default()
},
);

0 comments on commit 8859791

Please sign in to comment.