Skip to content

Commit

Permalink
generates scriptableobjects for definitions. tile rects not generated…
Browse files Browse the repository at this point in the history
… yet. need more tooltips instead of summaries. still need to provide some nullables
  • Loading branch information
Cammin committed Mar 4, 2024
1 parent a1b99e7 commit 0be3698
Show file tree
Hide file tree
Showing 34 changed files with 1,355 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,15 @@ public partial class AutoLayerRuleDefinition : ILDtkUid
/// Cell start offset
/// </value>
[IgnoreDataMember] public Vector2Int UnityOffset => new Vector2Int(XOffset, YOffset);

/// <value>
/// Min random offset for tile pos
/// </value>
[IgnoreDataMember] public Vector2Int UnityTileRandomMin => new Vector2Int(TileRandomXMin, TileRandomYMin);

/// <value>
/// Max random offset for tile pos
/// </value>
[IgnoreDataMember] public Vector2Int UnityTileRandomMax => new Vector2Int(TileRandomXMax, TileRandomYMax);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace LDtkUnity
{
[ExcludeFromDocs]//keep like this until we add custom functionality
public partial class AutoLayerRuleGroup : ILDtkUid
{
[IgnoreDataMember] public Color UnityColor => Color.ToColor();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.Serialization;
using UnityEngine;

namespace LDtkUnity
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public partial class EnumValueDefinition
/// <value>
/// Optional color
/// </value>
[IgnoreDataMember] public Color UnityColor => Color.ToColor(); //todo figure out that this actually works. could use with drawing the color in the imposter inspector?
[IgnoreDataMember] public Color UnityColor => Color.ToColor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public partial class LayerDefinition : ILDtkUid, ILDtkIdentifier
/// </value>
[IgnoreDataMember] public Vector2 TilePivot => new Vector2(TilePivotX, TilePivotY);

/// <summary>
/// User defined color for the UI
/// </summary>
[IgnoreDataMember] public Color UnityUiColor => UiColor.ToColor();

/// <value>
/// Returns true if this layer is an IntGrid layer.
/// </value>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using UnityEngine;

namespace LDtkUnity
{
[HelpURL(LDtkHelpURL.LDTK_JSON_AutoRuleDef)]
[Serializable]
public class LDtkDefinitionObjectAutoLayerRule : ScriptableObject
{
[field: Header("Internal")]
[field: Tooltip("If FALSE, the rule effect isn't applied, and no tiles are generated.")]
[field: SerializeField] public bool Active { get; private set; }

[field: SerializeField] public float Alpha { get; private set; }

[field: Tooltip("When TRUE, the rule will prevent other rules to be applied in the same cell if it matches (TRUE by default).")]
[field: SerializeField] public bool BreakOnMatch { get; private set; }

[field: Tooltip("Chances for this rule to be applied (0 to 1)")]
[field: SerializeField] public float Chance { get; private set; }

[field: Tooltip("Checker mode Possible values: `None`, `Horizontal`, `Vertical`")]
[field: SerializeField] public Checker Checker { get; private set; }

[field: Tooltip("If TRUE, allow rule to be matched by flipping its pattern horizontally")]
[field: SerializeField] public bool FlipX { get; private set; }

[field: Tooltip("If TRUE, allow rule to be matched by flipping its pattern vertically")]
[field: SerializeField] public bool FlipY { get; private set; }

/// <summary>
/// If TRUE, then the rule should be re-evaluated by the editor at one point
/// </summary>
[field: Tooltip("")]
[field: SerializeField] public bool Invalidated { get; private set; }

/// <summary>
/// Default IntGrid value when checking cells outside of level bounds
/// </summary>
[field: Tooltip("")]
[field: SerializeField] public int? OutOfBoundsValue { get; private set; }

/// <summary>
/// Rule pattern (size x size)
/// </summary>
[field: Tooltip("")]
[field: SerializeField] public int[] Pattern { get; private set; }

/// <summary>
/// If TRUE, enable Perlin filtering to only apply rule on specific random area
/// </summary>
[field: Tooltip("")]
[field: SerializeField] public bool PerlinActive { get; private set; }

[field: SerializeField] public float PerlinOctaves { get; private set; }

[field: SerializeField] public float PerlinScale { get; private set; }

[field: SerializeField] public float PerlinSeed { get; private set; }

/// <summary>
/// Pivot of a tile stamp (0-1 both axis)
/// </summary>
[field: Tooltip("")]
[field: SerializeField] public Vector2 Pivot { get; private set; }

/// <summary>
/// Pattern width and height. Should only be 1,3,5 or 7.
/// </summary>
[field: Tooltip("")]
[field: SerializeField] public int Size { get; private set; }

/// <summary>
/// Defines how tileIds array is used Possible values: `Single`, `Stamp`
/// </summary>
[field: Tooltip("")]
[field: SerializeField] public TileMode TileMode { get; private set; }

/// <summary>
/// Max random offset for tile pos
/// </summary>
[field: Tooltip("")]
[field: SerializeField] public Vector2Int TileRandomMax { get; private set; }

/// <summary>
/// Min random offset for tile pos
/// </summary>
[field: Tooltip("")]
[field: SerializeField] public Vector2Int TileRandomMin { get; private set; }

[field: Tooltip("Array containing all the possible tile IDs rectangles (picked randomly).")]
[field: SerializeField] public int[][] TileRectsIds { get; private set; }

[field: Tooltip("Tile offset")]
[field: SerializeField] public Vector2Int TileOffset { get; private set; }

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

[field: Tooltip("Cell coord modulo")]
[field: SerializeField] public Vector2Int Modulo { get; private set; }

[field: Tooltip("Cell start offset")]
[field: SerializeField] public Vector2Int Offset { get; private set; }

internal void Populate(LDtkDefinitionObjectsCache cache, AutoLayerRuleDefinition def)
{
name = $"Rule_{def.Uid}";

Active = def.Active;
Alpha = def.Alpha;
BreakOnMatch = def.BreakOnMatch;
Chance = def.Chance;
Checker = def.Checker;
FlipX = def.FlipX;
FlipY = def.FlipY;
Invalidated = def.Invalidated;
OutOfBoundsValue = def.OutOfBoundsValue; //todo make serializable
Pattern = def.Pattern;
PerlinActive = def.PerlinActive;
PerlinOctaves = def.PerlinOctaves;
PerlinScale = def.PerlinScale;
PerlinSeed = def.PerlinSeed;
Pivot = def.UnityPivot;
Size = def.Size;
TileMode = def.TileMode;
TileRandomMax = def.UnityTileRandomMax;
TileRandomMin = def.UnityTileRandomMin;
TileRectsIds = def.TileRectsIds; //todo make serializable
TileOffset = def.UnityOffset;
Uid = def.Uid;
Modulo = def.UnityModulo;
Offset = def.UnityOffset;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Linq;
using UnityEngine;

namespace LDtkUnity
{
[HelpURL(LDtkHelpURL.LDTK_JSON_LayerDefJson)]
public class LDtkDefinitionObjectAutoLayerRuleGroup : ScriptableObject
{
[field: Header("Internal")]
[field: SerializeField] public bool Active { get; private set; }

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

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

[field: SerializeField] public LDtkDefinitionObjectTilesetRectangle Icon { get; private set; }

[field: SerializeField] public bool IsOptional { get; private set; }

[field: SerializeField] public string Name { get; private set; }

[field: SerializeField] public string[] RequiredBiomeValues { get; private set; }

[field: SerializeField] public LDtkDefinitionObjectAutoLayerRule[] Rules { get; private set; }

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

[field: SerializeField] public bool UsesWizard { get; private set; }

internal void Populate(LDtkDefinitionObjectsCache cache, AutoLayerRuleGroup def)
{
name = $"RuleGroup_{def.Uid}_{def.Name}";

Active = def.Active;
BiomeRequirementMode = def.BiomeRequirementMode;
Color = def.UnityColor;
if (def.Icon != null)
{
Icon = ScriptableObject.CreateInstance<LDtkDefinitionObjectTilesetRectangle>();
Icon.Populate(cache, def.Icon);
}
IsOptional = def.IsOptional;
Name = def.Name;
RequiredBiomeValues = def.RequiredBiomeValues;
Rules = def.Rules.Select(p => cache.GetObject(cache.Rules, p.Uid)).ToArray();
Uid = def.Uid;
UsesWizard = def.UsesWizard;

for (int i = 0; i < Rules.Length; i++)
{
Rules[i].Populate(cache, def.Rules[i]);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0be3698

Please sign in to comment.