Skip to content

Commit

Permalink
Implement passive code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
necrashter committed Dec 7, 2023
1 parent 4ca469a commit 3de020f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ impl Plugin for SimulationPlugin {
.register_type::<IsEntityCap>()
.add_event::<SpawnEvent>()
.init_resource::<Simulation>()
.init_resource::<PassiveCodeGen>()
.add_systems(Startup, spawn_entity_caps)
.add_systems(Update, spawn_entities.in_set(AppSet::Simulate));
.add_systems(
Update,
(spawn_entities, generate_passive_code).in_set(AppSet::Simulate),
);
}
}

Expand Down Expand Up @@ -127,3 +131,31 @@ fn spawn_entity_caps(mut commands: Commands) {
IsEntityCap,
));
}

/// Resource for handling passive code generation.
#[derive(Resource)]
pub struct PassiveCodeGen {
pub timer: Timer,
pub increase: f64,
}

impl Default for PassiveCodeGen {
fn default() -> Self {
Self {
timer: Timer::from_seconds(2.0, TimerMode::Repeating),
increase: 0.0,
}
}
}

/// System for handling passive code generation.
fn generate_passive_code(
time: Res<Time>,
mut passive_code_gen: ResMut<PassiveCodeGen>,
mut simulation: ResMut<Simulation>,
) {
if passive_code_gen.timer.tick(time.delta()).just_finished() {
passive_code_gen.timer.reset();
simulation.lines += passive_code_gen.increase;
}
}
16 changes: 16 additions & 0 deletions src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rand::Rng;
use strum::EnumCount;

use crate::config::Config;
use crate::simulation::PassiveCodeGen;
use crate::simulation::Simulation;
use crate::simulation::SpawnEvent;
use crate::state::editor_screen::spawn_editor_screen;
Expand Down Expand Up @@ -419,6 +420,21 @@ generate_upgrade_list!(
..default()
},

// Passive code generation

ProceduralMacro: Upgrade {
name: "ProceduralMacroPlugin".to_string(),
description: "Periodically generates lines of code. By default, generates 1 line of code every 2 seconds.".to_string(),
base_cost: 50.0,
tech_debt: 1.0,
weight: 0.5,
remaining: 1,
install: Some(world.register_system(|mut passive_code_gen: ResMut<PassiveCodeGen>| {
passive_code_gen.increase = 1.0;
})),
..default()
},

// Misc

DesignDocument: Upgrade {
Expand Down

0 comments on commit 3de020f

Please sign in to comment.