Skip to content

Commit

Permalink
Merge pull request #80 from Trouv/tile_data
Browse files Browse the repository at this point in the history
Tile data components, logic, and refactors relating to conversion functions and level spawning.
  • Loading branch information
Trouv authored Apr 24, 2022
2 parents 681ab57 + 6b1f656 commit 73a37c1
Show file tree
Hide file tree
Showing 6 changed files with 783 additions and 554 deletions.
29 changes: 29 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ impl From<TilePos> for GridCoords {
}
}

impl From<GridCoords> for TilePos {
fn from(grid_coords: GridCoords) -> Self {
TilePos(grid_coords.x as u32, grid_coords.y as u32)
}
}

impl Add<GridCoords> for GridCoords {
type Output = GridCoords;
fn add(self, rhs: GridCoords) -> Self::Output {
Expand Down Expand Up @@ -173,6 +179,10 @@ impl MulAssign<GridCoords> for GridCoords {
}

impl GridCoords {
pub fn new(x: i32, y: i32) -> GridCoords {
GridCoords { x, y }
}

/// Creates a [GridCoords] from the entity information available to the
/// [LdtkEntity::bundle_entity] method.
///
Expand All @@ -186,6 +196,25 @@ impl GridCoords {
}
}

/// [Component] for storing user-defined custom data for a paticular tile in an LDtk tileset
/// definition.
///
/// Automatically inserted on any tiles with metadata.
#[derive(Clone, Eq, PartialEq, Debug, Default, Hash, Component)]
pub struct TileMetadata {
pub data: String,
}

/// [Component] for storing user-defined, enum-based tags for a particular tile in an LDtk tileset
/// definition.
///
/// Automatically inserted on any tiles with enum tags.
#[derive(Clone, Eq, PartialEq, Debug, Default, Hash, Component)]
pub struct TileEnumTags {
pub tags: Vec<String>,
pub source_enum_uid: Option<i32>,
}

#[derive(Clone, Default, Bundle)]
pub(crate) struct TileGridBundle {
#[bundle]
Expand Down
Loading

0 comments on commit 73a37c1

Please sign in to comment.