-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add level locale types and begin splitting internal_levels and …
…external_levels features (#237) As part of the rework of the asset types, it is useful to be able to define types that are generic over the "level locale" of the project they represent. The terminology level locale refers to whether or not the project uses internal levels (level data embedded in the main project asset) or external levels (level data stored in separate individual-level files). Such a generic type is able to define different implementations of the same trait for the two locales, or the same implementation of the same trait, or even completely different methods between the two locales. To facilitate this, this PR adds a `LevelLocale` trait, which is mostly a marker trait implemented by the new `InternalLevels` and `ExternalLevels` unit structs. It does provide an associated type to the sort of level metadata that is created for the two locales, but other than that it will mostly be used as a trait bound for generic types. The fact that the trait is private means that users will not be able to create new locales that don't fit into the canonical asset type design defined here. This also introduces the `internal_levels` and `external_levels` features. These two features are not mutually exclusive, but at least one of them does need to be enabled. The eventual asset type design will hide most things behind these features so users can slightly optimize their compilation if they want to. (Ignore broken doc-links here, they will no longer be broken in future PRs)
- Loading branch information
Showing
7 changed files
with
84 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use bevy::reflect::Reflect; | ||
|
||
#[cfg(feature = "internal_levels")] | ||
use crate::assets::LevelMetadata; | ||
|
||
#[cfg(feature = "external_levels")] | ||
use crate::assets::ExternalLevelMetadata; | ||
|
||
/// Trait for marker types describing the location of levels. | ||
/// | ||
/// Used as a trait bound to parameterize [`LdtkJsonWithMetadata`]. | ||
/// Also provides an associated type defining the level metadata type for the locale. | ||
/// | ||
/// Only implemented by [`InternalLevels`] and [`ExternalLevels`]. | ||
/// | ||
/// [`LdtkJsonWithMetadata`]: crate::assets::LdtkJsonWithMetadata | ||
pub trait LevelLocale { | ||
/// Level metadata type used for this locale. | ||
type Metadata; | ||
} | ||
|
||
#[cfg(feature = "internal_levels")] | ||
/// Marker type for indicating an internal-levels LDtk project. | ||
/// | ||
/// Used to parameterize [`LdtkJsonWithMetadata`]. | ||
/// | ||
/// [`LdtkJsonWithMetadata`]: crate::assets::LdtkJsonWithMetadata | ||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Reflect)] | ||
pub struct InternalLevels; | ||
|
||
#[cfg(feature = "internal_levels")] | ||
impl LevelLocale for InternalLevels { | ||
type Metadata = LevelMetadata; | ||
} | ||
|
||
#[cfg(feature = "external_levels")] | ||
/// Marker type for indicating an external-levels LDtk projects. | ||
/// | ||
/// Used to parameterize [`LdtkJsonWithMetadata`]. | ||
/// | ||
/// [`LdtkJsonWithMetadata`]: crate::assets::LdtkJsonWithMetadata | ||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Reflect)] | ||
pub struct ExternalLevels; | ||
|
||
#[cfg(feature = "external_levels")] | ||
impl LevelLocale for ExternalLevels { | ||
type Metadata = ExternalLevelMetadata; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters