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. 2 (#220)
Browse files Browse the repository at this point in the history
* Removing some methods from TopDownScene trait

* Removing impl of Tile for Zone tile kind

* Removing the Tile trait
  • Loading branch information
porkbrain authored Jul 20, 2024
1 parent d24eebe commit d2136f7
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 263 deletions.
17 changes: 12 additions & 5 deletions main_game_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod vec2_ext;
use bevy::{app::AppExit, prelude::*};
use bevy_pixel_camera::PixelCameraPlugin;
pub use common_ext;
use prelude::rscn::TscnInBevy;

use crate::prelude::*;

Expand Down Expand Up @@ -48,7 +49,7 @@ pub fn windowed_app() -> App {
main_game_lib::top_down::environmental_objects::door=debug,\
main_game_lib::top_down::cameras=debug,\
main_game_lib::top_down::layout=debug,\
scene_building1_player_floor=trace,\
main_game_lib::rscn=debug,\
"
.to_string(),
..default()
Expand Down Expand Up @@ -103,12 +104,12 @@ pub fn windowed_app() -> App {
common_loading_screen::Plugin,
common_store::Plugin,
common_story::Plugin,
crate::top_down::Plugin,
common_visuals::Plugin,
cutscene::Plugin,
PixelCameraPlugin,
crate::hud::Plugin,
crate::cutscene::Plugin,
crate::dialog::Plugin,
crate::hud::Plugin,
crate::top_down::Plugin,
PixelCameraPlugin,
));

info!("Plugins added");
Expand Down Expand Up @@ -139,3 +140,9 @@ fn begin_loading_static_assets_on_startup(
fn exit(mut exit: EventWriter<AppExit>) {
exit.send(AppExit::Success);
}

impl<T: TopDownScene> TscnInBevy for T {
fn tscn_asset_path() -> String {
format!("scenes/{}.tscn", T::name())
}
}
10 changes: 0 additions & 10 deletions main_game_lib/src/rscn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ pub use loader::{LoaderError, TscnLoader};
use serde::{Deserialize, Serialize};
pub use spawner::TscnSpawner;

use crate::top_down::TopDownScene;

/// A helper component that is always in an entity with
/// [`bevy::prelude::SpatialBundle`].
/// Translated a simple point from Godot.
Expand Down Expand Up @@ -171,8 +169,6 @@ pub struct SpriteFrames {
}

/// Marks scene as "can be loaded from .tscn".
///
/// Autoimplemented for [`TopDownScene`]s.
pub trait TscnInBevy: Send + Sync + 'static {
/// Asset path of the `.tscn` file associated with this scene.
fn tscn_asset_path() -> String;
Expand All @@ -189,12 +185,6 @@ pub struct TscnTreeHandle<T> {
_phantom: std::marker::PhantomData<T>,
}

impl<T: TopDownScene> TscnInBevy for T {
fn tscn_asset_path() -> String {
format!("scenes/{}.tscn", T::name())
}
}

/// Parses Godot's .tscn file with very strict requirements on the content.
/// We only support nodes and parameters that are relevant to our game.
/// We panic on unsupported content aggressively.
Expand Down
6 changes: 1 addition & 5 deletions main_game_lib/src/top_down/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};

use self::npc::BehaviorTree;
use crate::top_down::{
layout::{ysort, Tile, TileIndex, TopDownScene, LAYOUT},
layout::{ysort, TileIndex, TopDownScene, LAYOUT},
npc::NpcInTheMap,
InspectLabelCategory, Player, TileKind, TileMap,
};
Expand Down Expand Up @@ -972,10 +972,6 @@ mod tests {
struct TestScene;

impl TopDownScene for TestScene {
fn bounds() -> [i32; 4] {
[-1000, 1000, -1000, 1000]
}

fn name() -> &'static str {
unreachable!()
}
Expand Down
Loading

0 comments on commit d2136f7

Please sign in to comment.