Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: use new LevelIid type in LevelEvent, LevelSet, and LevelSelection, plus other improvements #219

Merged
merged 23 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b3e231d
refactor: make resources a directory module for now
Trouv Aug 12, 2023
1ef7523
feat: move LevelSelection to its own file
Trouv Aug 12, 2023
de66555
feat: add LevelIid::get for getting the level Iid as a String
Trouv Aug 12, 2023
c964406
feat: use LevelIid as inner type for LevelSelection::Iid, and provide…
Trouv Aug 12, 2023
5fc6b5d
refactor: move LevelSet to its own module
Trouv Aug 12, 2023
ab5cd4b
feat: use LevelIid in LevelSet
Trouv Aug 13, 2023
0487e7a
feat: implement iterator conversion for LevelSet
Trouv Aug 13, 2023
5d0a77c
feat: improve memory management of pre-spawning levels
Trouv Aug 13, 2023
eb1e5e4
feat: do a little more borrowing in apply_level_set
Trouv Aug 13, 2023
c3e7d19
refactor: move LevelEvent to its own module
Trouv Aug 13, 2023
422af79
feat: update LevelEvent to use LevelIids internally
Trouv Aug 13, 2023
138be29
docs(example): update level set example to use LevelIids
Trouv Aug 13, 2023
5775e48
test: add one more test case to string_converts_to_and_from_level_iid
Trouv Aug 13, 2023
f870ab2
docs: fix doc links for LevelSet
Trouv Aug 13, 2023
d6b258c
feat: change from_iid to from_iids which accepts a generic iterator
Trouv Aug 13, 2023
cd010b5
feat: update level_set example to use LevelSet::from_iids
Trouv Aug 13, 2023
ebd4e6c
test: add another trivial test for LevelSet
Trouv Aug 13, 2023
07aebe0
docs: properly link to Component in LevelIid docs
Trouv Aug 13, 2023
660cccb
docs: update imports in components module to adjust for moved/unused …
Trouv Aug 13, 2023
db7696b
docs: update LevelSelection docs with proper links and a doctest
Trouv Aug 13, 2023
e8b55fb
docs: fix typo in LevelSelection::is_match docs
Trouv Aug 13, 2023
8e7d2e0
docs: no longer use unused unused import in resources module
Trouv Aug 13, 2023
3d6d6a3
docs: fix code links in LevelEvent docs
Trouv Aug 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: use LevelIid as inner type for LevelSelection::Iid, and provide…
… a more convenient constructor
  • Loading branch information
Trouv committed Aug 12, 2023
commit c964406616fe0af07991ae7b50385fee4f2d9c31
2 changes: 1 addition & 1 deletion examples/platformer/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ pub fn update_level_selection(
&& player_transform.translation.y > level_bounds.min.y
&& !level_selection.is_match(&0, ldtk_level.data())
{
*level_selection = LevelSelection::Iid(ldtk_level.data().iid.clone());
*level_selection = LevelSelection::iid(ldtk_level.data().iid.clone());
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/resources/level_selection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ldtk::Level;
use crate::{ldtk::Level, LevelIid};
use bevy::prelude::*;

/// Resource for choosing which level(s) to spawn.
Expand All @@ -16,7 +16,7 @@ pub enum LevelSelection {
/// Spawn level from its index in the LDtk file's list of levels.
Index(usize),
/// Spawn level with the given level `iid`.
Iid(String),
Iid(LevelIid),
/// Spawn level with the given level `uid`.
Uid(i32),
}
Expand All @@ -28,11 +28,15 @@ impl Default for LevelSelection {
}

impl LevelSelection {
pub fn iid(iid: impl Into<String>) -> Self {
LevelSelection::Iid(LevelIid::new(iid))
}

pub fn is_match(&self, index: &usize, level: &Level) -> bool {
match self {
LevelSelection::Identifier(s) => *s == level.identifier,
LevelSelection::Index(i) => *i == *index,
LevelSelection::Iid(i) => *i == level.iid,
LevelSelection::Iid(i) => *i.get() == level.iid,
LevelSelection::Uid(u) => *u == level.uid,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn pre_spawn_level(
let mut translation = Vec3::ZERO;

if let LevelSpawnBehavior::UseWorldTranslation { .. } = ldtk_settings.level_spawn_behavior {
if let Some(level) = ldtk_asset.get_level(&LevelSelection::Iid(level_iid.to_string())) {
if let Some(level) = ldtk_asset.get_level(&LevelSelection::iid(level_iid)) {
let level_coords = ldtk_pixel_coords_to_translation(
IVec2::new(level.world_x, level.world_y + level.px_hei),
0,
Expand All @@ -203,7 +203,7 @@ fn pre_spawn_level(
})
.insert(Name::new(
ldtk_asset
.get_level(&LevelSelection::Iid(level_iid.to_string()))
.get_level(&LevelSelection::iid(level_iid))
.unwrap()
.identifier
.to_owned(),
Expand Down