Commit 8d9456f5 authored by Rahix's avatar Rahix 🦀
Browse files

Rename `state` to `gamestate`

We currently have a `state` and a `states` module.  This is confusing,
rename the state module to `gamestate` to make a more obvious
distinction.
parent 6e37e8c3
......@@ -3,8 +3,8 @@ use wasm_bindgen::prelude::*;
pub mod colliders;
pub mod colors;
pub mod components;
pub mod gamestate;
pub mod resources;
pub mod state;
pub mod states;
pub mod svg_loader;
pub mod systems;
......@@ -13,6 +13,6 @@ pub mod utils;
#[wasm_bindgen]
pub fn start() -> Result<(), JsValue> {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
state::StateMachine::launch(states::MainMenuState::new());
gamestate::StateMachine::launch(states::MainMenuState::new());
Ok(())
}
use crate::colors;
use crate::components;
use crate::gamestate;
use crate::resources;
use crate::state;
use crate::states;
use crate::utils;
......@@ -78,14 +78,14 @@ impl HeavenState {
}
}
impl state::State for HeavenState {
fn init(&mut self, init: state::StateInitializer) -> state::Transition {
impl gamestate::State for HeavenState {
fn init(&mut self, init: gamestate::StateInitializer) -> gamestate::Transition {
init.register_onclick("heaven-start-shift");
self.gui_svg
.style()
.set_property("display", "block")
.unwrap();
state::Transition::Loop
gamestate::Transition::Loop
}
fn deinit(&mut self) {
......@@ -95,7 +95,7 @@ impl state::State for HeavenState {
.unwrap();
}
fn update(&mut self) -> state::Transition {
fn update(&mut self) -> gamestate::Transition {
{
let rendering = self.resources.get_mut::<resources::Rendering>().unwrap();
rendering.set_fill_style(&colors::BACKGROUND);
......@@ -105,17 +105,17 @@ impl state::State for HeavenState {
self.node_schedule
.execute(&mut self.node_world, &mut self.resources);
state::Transition::Loop
gamestate::Transition::Loop
}
fn event(&mut self, target: &str, event: state::Event) -> state::Transition {
fn event(&mut self, target: &str, event: gamestate::Event) -> gamestate::Transition {
match (target, event) {
("heaven-start-shift", state::Event::MouseClick { .. }) => {
state::Transition::push(states::LevelLoadingState::new())
("heaven-start-shift", gamestate::Event::MouseClick { .. }) => {
gamestate::Transition::push(states::LevelLoadingState::new())
}
(target, event) => {
crate::console_log!("unknown event from {:?}: {:?}", target, event);
state::Transition::Keep
gamestate::Transition::Keep
}
}
}
......
use crate::colliders;
use crate::colors;
use crate::gamestate;
use crate::resources;
use crate::state;
use crate::svg_loader;
use crate::systems;
use crate::utils;
......@@ -48,15 +48,15 @@ impl InGameState {
}
}
impl state::State for InGameState {
fn init(&mut self, init: state::StateInitializer) -> state::Transition {
impl gamestate::State for InGameState {
fn init(&mut self, init: gamestate::StateInitializer) -> gamestate::Transition {
self.gui_svg
.style()
.set_property("display", "block")
.unwrap();
init.register_keyevents();
state::Transition::Loop
gamestate::Transition::Loop
}
fn deinit(&mut self) {
......@@ -70,12 +70,12 @@ impl state::State for InGameState {
.unwrap();
}
fn event(&mut self, _target: &str, event: state::Event) -> state::Transition {
fn event(&mut self, _target: &str, event: gamestate::Event) -> gamestate::Transition {
crate::console_log!("event: {:?}", event);
state::Transition::Keep
gamestate::Transition::Keep
}
fn update(&mut self) -> state::Transition {
fn update(&mut self) -> gamestate::Transition {
{
let rendering = self.resources.get::<resources::Rendering>().unwrap();
rendering.set_fill_style(&colors::BACKGROUND);
......@@ -87,9 +87,9 @@ impl state::State for InGameState {
camera.position.x > 50.0
};
if done {
state::Transition::Pop
gamestate::Transition::Pop
} else {
state::Transition::Loop
gamestate::Transition::Loop
}
}
}
......@@ -3,8 +3,8 @@ use std::rc;
use crate::colors;
use crate::components;
use crate::gamestate;
use crate::resources;
use crate::state;
use crate::states;
use crate::svg_loader;
......@@ -50,12 +50,12 @@ impl LevelLoadingState {
}
}
impl state::State for LevelLoadingState {
fn init(&mut self, _init: state::StateInitializer) -> state::Transition {
state::Transition::Loop
impl gamestate::State for LevelLoadingState {
fn init(&mut self, _init: gamestate::StateInitializer) -> gamestate::Transition {
gamestate::Transition::Loop
}
fn update(&mut self) -> state::Transition {
fn update(&mut self) -> gamestate::Transition {
{
let rendering = self.resources.get_mut::<resources::Rendering>().unwrap();
rendering.set_fill_style(&colors::BACKGROUND);
......@@ -68,9 +68,9 @@ impl state::State for LevelLoadingState {
// TODO: Polling the future/promise here is really ugly ...
if let Some(level) = self.svg_level.borrow_mut().take() {
crate::console_log!("Level was loaded!");
state::Transition::replace(states::InGameState::new(level))
gamestate::Transition::replace(states::InGameState::new(level))
} else {
state::Transition::Loop
gamestate::Transition::Loop
}
}
}
use crate::state;
use crate::gamestate;
use crate::states;
use crate::utils;
......@@ -14,14 +14,14 @@ impl MainMenuState {
}
}
impl state::State for MainMenuState {
fn init(&mut self, init: state::StateInitializer) -> state::Transition {
impl gamestate::State for MainMenuState {
fn init(&mut self, init: gamestate::StateInitializer) -> gamestate::Transition {
init.register_onclick("main-menu-play");
self.gui_svg
.style()
.set_property("display", "block")
.unwrap();
state::Transition::Sleep
gamestate::Transition::Sleep
}
fn deinit(&mut self) {
......@@ -31,14 +31,14 @@ impl state::State for MainMenuState {
.unwrap();
}
fn event(&mut self, target: &str, event: state::Event) -> state::Transition {
fn event(&mut self, target: &str, event: gamestate::Event) -> gamestate::Transition {
match (target, event) {
("main-menu-play", state::Event::MouseClick { .. }) => {
state::Transition::push(states::HeavenState::new())
("main-menu-play", gamestate::Event::MouseClick { .. }) => {
gamestate::Transition::push(states::HeavenState::new())
}
(target, event) => {
crate::console_log!("unknown event from {:?}: {:?}", target, event);
state::Transition::Keep
gamestate::Transition::Keep
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment