|
@@ -25,12 +25,29 @@ use damage_system::DamageSystem;
|
|
mod gui;
|
|
mod gui;
|
|
mod gamelog;
|
|
mod gamelog;
|
|
|
|
|
|
|
|
+rltk::add_wasm_support!();
|
|
|
|
+
|
|
#[derive(PartialEq, Copy, Clone)]
|
|
#[derive(PartialEq, Copy, Clone)]
|
|
pub enum RunState { AwaitingInput, PreRun, PlayerTurn, MonsterTurn }
|
|
pub enum RunState { AwaitingInput, PreRun, PlayerTurn, MonsterTurn }
|
|
|
|
|
|
pub struct State {
|
|
pub struct State {
|
|
pub ecs: World,
|
|
pub ecs: World,
|
|
- pub systems: Dispatcher<'static, 'static>
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl State {
|
|
|
|
+ fn run_systems(&mut self) {
|
|
|
|
+ let mut mapindex = MapIndexingSystem{};
|
|
|
|
+ mapindex.run_now(&self.ecs);
|
|
|
|
+ let mut vis = VisibilitySystem{};
|
|
|
|
+ vis.run_now(&self.ecs);
|
|
|
|
+ let mut mob = MonsterAI{};
|
|
|
|
+ mob.run_now(&self.ecs);
|
|
|
|
+ let mut melee = MeleeCombatSystem{};
|
|
|
|
+ melee.run_now(&self.ecs);
|
|
|
|
+ let mut damage = DamageSystem{};
|
|
|
|
+ damage.run_now(&self.ecs);
|
|
|
|
+ self.ecs.maintain();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
impl GameState for State {
|
|
impl GameState for State {
|
|
@@ -44,18 +61,18 @@ impl GameState for State {
|
|
|
|
|
|
match newrunstate {
|
|
match newrunstate {
|
|
RunState::PreRun => {
|
|
RunState::PreRun => {
|
|
- self.systems.dispatch(&self.ecs);
|
|
|
|
|
|
+ self.run_systems();
|
|
newrunstate = RunState::AwaitingInput;
|
|
newrunstate = RunState::AwaitingInput;
|
|
}
|
|
}
|
|
RunState::AwaitingInput => {
|
|
RunState::AwaitingInput => {
|
|
newrunstate = player_input(self, ctx);
|
|
newrunstate = player_input(self, ctx);
|
|
}
|
|
}
|
|
RunState::PlayerTurn => {
|
|
RunState::PlayerTurn => {
|
|
- self.systems.dispatch(&self.ecs);
|
|
|
|
|
|
+ self.run_systems();
|
|
newrunstate = RunState::MonsterTurn;
|
|
newrunstate = RunState::MonsterTurn;
|
|
}
|
|
}
|
|
RunState::MonsterTurn => {
|
|
RunState::MonsterTurn => {
|
|
- self.systems.dispatch(&self.ecs);
|
|
|
|
|
|
+ self.run_systems();
|
|
newrunstate = RunState::AwaitingInput;
|
|
newrunstate = RunState::AwaitingInput;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -82,17 +99,10 @@ impl GameState for State {
|
|
}
|
|
}
|
|
|
|
|
|
fn main() {
|
|
fn main() {
|
|
- let mut context = Rltk::init_simple8x8(80, 50, "Hello Rust World", "../resources");
|
|
|
|
|
|
+ let mut context = Rltk::init_simple8x8(80, 50, "Hello Rust World", "resources");
|
|
context.with_post_scanlines(true);
|
|
context.with_post_scanlines(true);
|
|
let mut gs = State {
|
|
let mut gs = State {
|
|
ecs: World::new(),
|
|
ecs: World::new(),
|
|
- systems : DispatcherBuilder::new()
|
|
|
|
- .with(MapIndexingSystem{}, "map_indexing_system", &[])
|
|
|
|
- .with(VisibilitySystem{}, "visibility_system", &[])
|
|
|
|
- .with(MonsterAI{}, "monster_ai", &["visibility_system", "map_indexing_system"])
|
|
|
|
- .with(MeleeCombatSystem{}, "melee_combat", &["monster_ai"])
|
|
|
|
- .with(DamageSystem{}, "damage", &["melee_combat"])
|
|
|
|
- .build(),
|
|
|
|
};
|
|
};
|
|
gs.ecs.register::<Position>();
|
|
gs.ecs.register::<Position>();
|
|
gs.ecs.register::<Renderable>();
|
|
gs.ecs.register::<Renderable>();
|