Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Scenes refactor pt. 3: Use new computed states (#221)
Browse files Browse the repository at this point in the history
* Adding computed states to app

* Moving systems that were not conditioned on TopDownScene generic to plugin registration hook

* Removing standard state semantics

* Stable ordering of zone groups when generating map ron
  • Loading branch information
porkbrain authored Jul 20, 2024
1 parent d2136f7 commit 1e89c6a
Show file tree
Hide file tree
Showing 46 changed files with 475 additions and 747 deletions.
2 changes: 1 addition & 1 deletion main_game/assets/maps/building1_player_floor.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(
zones: (
inner: {Zone(Bed): (zone_group: (6), zone_size: 30, zone_successors: [Zone(PlayerApartment)]), Zone(BottomLeftApartmentBathroomDoor): (zone_group: (7), zone_size: 42, zone_successors: [Zone(BottomLeftApartment)]), Zone(BottomLeftApartmentDoor): (zone_group: (7), zone_size: 37, zone_successors: [Zone(BottomLeftApartment), Zone(Hallway)]), Zone(BottomLeftApartment): (zone_group: (7), zone_size: 2187, zone_successors: [Zone(BottomLeftApartmentBathroomDoor), Zone(BottomLeftApartmentDoor), Zone(BottomRightApartment), Zone(Hallway)]), Zone(BottomRightApartmentDoor): (zone_group: (7), zone_size: 35, zone_successors: [Zone(BottomRightApartment), Zone(Hallway)]), Zone(BottomRightApartment): (zone_group: (7), zone_size: 1050, zone_successors: [Zone(BottomLeftApartment), Zone(BottomRightApartmentDoor), Zone(Hallway)]), Zone(Elevator): (zone_group: (7), zone_size: 68, zone_successors: [Zone(Hallway)]), Zone(Hallway): (zone_group: (6), zone_size: 1550, zone_successors: [Zone(BottomLeftApartmentDoor), Zone(BottomLeftApartment), Zone(BottomRightApartmentDoor), Zone(BottomRightApartment), Zone(Elevator), Zone(PlayerApartment), Zone(PlayerDoor)]), Zone(Meditation): (zone_group: (6), zone_size: 125, zone_successors: [Zone(PlayerApartment)]), Zone(PlayerApartment): (zone_group: (6), zone_size: 2725, zone_successors: [Zone(Bed), Zone(Hallway), Zone(Meditation), Zone(PlayerDoor), Zone(Tea)]), Zone(PlayerDoor): (zone_group: (6), zone_size: 64, zone_successors: [Zone(Hallway), Zone(PlayerApartment)]), Zone(Tea): (zone_group: (6), zone_size: 45, zone_successors: [Zone(PlayerApartment)])},
inner: {Zone(Bed): (zone_group: (5), zone_size: 30, zone_successors: [Zone(PlayerApartment)]), Zone(BottomLeftApartmentBathroomDoor): (zone_group: (6), zone_size: 42, zone_successors: [Zone(BottomLeftApartment)]), Zone(BottomLeftApartmentDoor): (zone_group: (6), zone_size: 37, zone_successors: [Zone(BottomLeftApartment), Zone(Hallway)]), Zone(BottomLeftApartment): (zone_group: (6), zone_size: 2187, zone_successors: [Zone(BottomLeftApartmentBathroomDoor), Zone(BottomLeftApartmentDoor), Zone(BottomRightApartment), Zone(Hallway)]), Zone(BottomRightApartmentDoor): (zone_group: (6), zone_size: 35, zone_successors: [Zone(BottomRightApartment), Zone(Hallway)]), Zone(BottomRightApartment): (zone_group: (6), zone_size: 1050, zone_successors: [Zone(BottomLeftApartment), Zone(BottomRightApartmentDoor), Zone(Hallway)]), Zone(Elevator): (zone_group: (6), zone_size: 68, zone_successors: [Zone(Hallway)]), Zone(Hallway): (zone_group: (5), zone_size: 1550, zone_successors: [Zone(BottomLeftApartmentDoor), Zone(BottomLeftApartment), Zone(BottomRightApartmentDoor), Zone(BottomRightApartment), Zone(Elevator), Zone(PlayerApartment), Zone(PlayerDoor)]), Zone(Meditation): (zone_group: (5), zone_size: 125, zone_successors: [Zone(PlayerApartment)]), Zone(PlayerApartment): (zone_group: (5), zone_size: 2725, zone_successors: [Zone(Bed), Zone(Hallway), Zone(Meditation), Zone(PlayerDoor), Zone(Tea)]), Zone(PlayerDoor): (zone_group: (5), zone_size: 64, zone_successors: [Zone(Hallway), Zone(PlayerApartment)]), Zone(Tea): (zone_group: (5), zone_size: 45, zone_successors: [Zone(PlayerApartment)])},
),
squares: {
(x: -81, y: -59): [Wall, Empty, Zone(BottomLeftApartment)],
Expand Down
7 changes: 5 additions & 2 deletions main_game/src/new_game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use bevy::{
};
use common_store::{DialogStore, GlobalStore};
use common_story::Character;
use main_game_lib::{dialog, state::GlobalGameState};
use main_game_lib::{
dialog,
state::{GlobalGameState, WhichTopDownScene},
};

pub(crate) fn on_enter(
mut next_state: ResMut<NextState<GlobalGameState>>,
Expand Down Expand Up @@ -37,5 +40,5 @@ pub(crate) fn on_enter(
dialog::TypedNamespace::InitialPhoebe,
);

next_state.set(GlobalGameState::LoadingBuilding1PlayerFloor);
next_state.set(WhichTopDownScene::Building1PlayerFloor.loading());
}
20 changes: 8 additions & 12 deletions main_game_lib/src/cutscene/enter_an_elevator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,16 @@ pub fn spawn(
fn on_took_the_elevator(cmd: &mut Commands, store: &GlobalStore) {
// get current state, from that infer quitting state
cmd.add(|w: &mut World| {
let quitting_state = w
.get_resource::<State<GlobalGameState>>()
.unwrap() // SAFETY: always present
.state_semantics()
.unwrap() // SAFETY: used in topdown scenes
.quitting;
let current_top_down_scene = **w
.get_resource::<State<WhichTopDownScene>>()
.expect("Elevator can only be used in top down scenes");

// SAFETY: always present
let mut next_state =
w.get_resource_mut::<NextState<GlobalGameState>>().unwrap();
next_state.set(quitting_state);
next_state.set(GlobalGameState::LeavingTopDownScene(
current_top_down_scene,
));
});

match store
Expand Down Expand Up @@ -307,11 +306,8 @@ pub fn start_with_open_elevator_and_close_it(
elevator.get_mut::<TextureAtlas>().unwrap().index = last_frame;
// start the animation as soon as we are in running state
fn is_in_running_global_state(w: &World, _: Entity) -> bool {
// SAFETY: GlobalGameState always present
let current_state = w.get_resource::<State<GlobalGameState>>().unwrap();
current_state
.state_semantics()
.is_some_and(|sem| sem.running == **current_state)
w.get_resource::<State<InTopDownScene>>()
.is_some_and(|scene| scene.is_running())
}
elevator.insert(common_visuals::BeginAtlasAnimation::run(
is_in_running_global_state,
Expand Down
4 changes: 3 additions & 1 deletion main_game_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ pub fn windowed_app() -> App {
info!("Initializing Don't Count The Sheep");

app.init_state::<GlobalGameState>()
.add_computed_state::<WhichTopDownScene>()
.add_computed_state::<InTopDownScene>()
.init_resource::<GlobalGameStateTransition>()
// TODO: load from save file
.init_resource::<player_stats::PlayerStats>()
.insert_resource(ClearColor(PRIMARY_COLOR))
.init_resource::<GlobalGameStateTransition>()
.init_asset::<crate::rscn::TscnTree>()
.init_asset_loader::<crate::rscn::TscnLoader>()
.init_asset_loader::<common_assets::ignore_loader::Loader>();
Expand Down
Loading

0 comments on commit 1e89c6a

Please sign in to comment.