Skip to content

Commit

Permalink
finished tileset def layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammin committed Mar 9, 2024
1 parent 5d6e200 commit 27f4d37
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace LDtkUnity
public sealed class LDtkDefinitionObjectIntGridValueGroup : ScriptableObject
{
[field: Tooltip("User defined color")]
public Color Color { get; set; }
public Color Color { get; private set; }

[field: Tooltip("User defined string identifier")]
public string Identifier { get; set; }
public string Identifier { get; private set; }

[field: Tooltip("Group unique ID")]
public int Uid { get; set; }
public int Uid { get; private set; }

internal void Populate(LDtkDefinitionObjectsCache cache, IntGridValueGroupDefinition def)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,95 +5,58 @@ namespace LDtkUnity
[HelpURL(LDtkHelpURL.LDTK_JSON_TilesetDefJson)]
public sealed class LDtkDefinitionObjectTileset : ScriptableObject
{
/// <summary>
/// Grid-based size
/// </summary>
[field: Tooltip("Grid-based size")]
[field: SerializeField] public Vector2Int CSize { get; private set; }

/// <summary>
/// An array of custom tile metadata
/// </summary>
[field: SerializeField] public TileCustomMetadata[] CustomData { get; private set; }

/// <summary>
/// If this value is set, then it means that this atlas uses an internal LDtk atlas image
/// instead of a loaded one. Possible values: &lt;`null`&gt;, `LdtkIcons`
/// </summary>
[field: SerializeField] public EmbedAtlas? EmbedAtlas { get; private set; }

/// <summary>
/// Tileset tags using Enum values specified by `tagsSourceEnumId`. This array contains 1
/// element per Enum value, which contains an array of all Tile IDs that are tagged with it.
/// </summary>
[field: SerializeField] public EnumTagValue[] EnumTags { get; private set; }

/// <summary>
/// User defined unique identifier
/// </summary>
[field: Tooltip("If this value is set, then it means that this atlas uses an internal LDtk atlas image instead of a loaded one. Possible values: &lt;`null`&gt;, `LdtkIcons`")]
[field: SerializeField] public bool EmbedAtlas { get; private set; }

[field: Tooltip("User defined unique identifier")]
[field: SerializeField] public string Identifier { get; private set; }

/// <summary>
/// Distance in pixels from image borders
/// </summary>

[field: Tooltip("Distance in pixels from image borders")]
[field: SerializeField] public int Padding { get; private set; }

/// <summary>
/// Image size in pixels
/// </summary>

[field: Tooltip("Image size in pixels")]
[field: SerializeField] public Vector2Int PxSize { get; private set; }

/// <summary>
/// Path to the source file, relative to the current project JSON file<br/> It can be null
/// if no image was provided, or when using an embed atlas.
/// </summary>

[field: Tooltip("Path to the source file, relative to the current project JSON file. It can be null if no image was provided, or when using an embed atlas.")]
[field: SerializeField] public string RelPath { get; private set; }

/// <summary>
/// Space in pixels between all tiles
/// </summary>
[field: Tooltip("Space in pixels between all tiles")]
[field: SerializeField] public int Spacing { get; private set; }

/// <summary>
/// An array of user-defined tags to organize the Tilesets
/// </summary>

[field: Tooltip("An array of user-defined tags to organize the Tilesets")]
[field: SerializeField] public string[] Tags { get; private set; }

/// <summary>
/// Optional Enum definition used for this tileset meta-data
/// </summary>

[field: Tooltip("Optional Enum definition used for this tileset meta-data")]
[field: SerializeField] public LDtkDefinitionObjectEnum TagsSourceEnum { get; private set; }

[field: SerializeField] public int TileGridSize { get; private set; }

/// <summary>
/// Unique Int identifier
/// </summary>

[field: Tooltip("Unique Int identifier")]
[field: SerializeField] public int Uid { get; private set; }

#region EditorOnly

/// <summary>
/// The following data is used internally for various optimizations. It's always synced with
/// source image changes.
/// </summary>
#region VeryEditorOnly

[field: Tooltip("Tileset tags using Enum values specified by `tagsSourceEnumId`. This array contains 1 element per Enum value, which contains an array of all Tile IDs that are tagged with it.")]
[field: SerializeField] private EnumTagValue[] EnumTags { get; set; }
[field: Tooltip("An array of custom tile metadata")]
[field: SerializeField] private TileCustomMetadata[] CustomData { get; set; }

[field: Header("Internal")]
[field: SerializeField] public System.Collections.Generic.Dictionary<string, object> CachedPixelData { get; private set; }
[field: Tooltip("The following data is used internally for various optimizations. It's always synced with source image changes.")]
[field: SerializeField] private System.Collections.Generic.Dictionary<string, object> CachedPixelData { get; set; }

/// <summary>
/// Array of group of tiles selections, only meant to be used in the editor
/// </summary>
[field: SerializeField] public System.Collections.Generic.Dictionary<string, object>[] SavedSelections { get; private set; }
[field: Tooltip("Array of group of tiles selections, only meant to be used in the editor")]
[field: SerializeField] private System.Collections.Generic.Dictionary<string, object>[] SavedSelections { get; set; }

#endregion

internal void Populate(LDtkDefinitionObjectsCache cache, TilesetDefinition def)
{
name = $"Tileset_{def.Identifier}";

CSize = def.UnityCSize;
CustomData = def.CustomData; //todo make serialized
EmbedAtlas = def.EmbedAtlas; //todo make serialized
EnumTags = def.EnumTags; //todo make serialized
EmbedAtlas = def.EmbedAtlas != null;
Identifier = def.Identifier;
Padding = def.Padding;
PxSize = def.UnityPxSize;
Expand All @@ -103,8 +66,14 @@ internal void Populate(LDtkDefinitionObjectsCache cache, TilesetDefinition def)
TagsSourceEnum = cache.GetObject(cache.Enums, def.TagsSourceEnumUid);
TileGridSize = def.TileGridSize;
Uid = def.Uid;
CachedPixelData = def.CachedPixelData; //todo make serialized
SavedSelections = def.SavedSelections; //todo make serialized

//ignore these, the data is in the tiles instead
//CustomData = def.CustomData;
//EnumTags = def.EnumTags;

//these are very editor-only. don't make serialized at all
//CachedPixelData = def.CachedPixelData;
//SavedSelections = def.SavedSelections;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ namespace LDtkUnity
[HelpURL(LDtkHelpURL.LDTK_JSON_TilesetRect)]
public sealed class LDtkDefinitionObjectTilesetRectangle : ScriptableObject
{
/// <summary>
/// Rect in the tileset image
/// </summary>
[field: Tooltip("Rect in the tileset image")]
[field: SerializeField] public RectInt Rectangle { get; private set; }

/// <summary>
/// The tileset
/// </summary>
[field: Tooltip("The tileset")]
[field: SerializeField] public LDtkDefinitionObjectTileset Tileset { get; private set; }


//public LDtkTilesetTile Tile; //todo eventually add a reference to the tile.

//public LDtkTilesetTile Tile; //todo eventually add a reference to the actual tile that's in the tileset definition file. maybe this object doesnt need to exist at all.

public void Populate(LDtkDefinitionObjectsCache cache, TilesetRectangle def)
{
Expand Down

0 comments on commit 27f4d37

Please sign in to comment.