Skip to content

Commit

Permalink
Merge branch 'develop' into upgrade-1.5.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	Assets/LDtkUnity/CHANGELOG.md
#	Assets/LDtkUnity/Editor/ScriptedImporter/LDtkImporterConsts.cs
#	Assets/LDtkUnity/LDtkTilesetExporter.zip
#	Assets/LDtkUnity/Samples~/Samples/AutoLayers_1_basic.ldtk
#	Assets/LDtkUnity/Samples~/Samples/AutoLayers_2_stamps.ldtk
#	Assets/LDtkUnity/Samples~/Samples/AutoLayers_3_Mosaic.ldtk
#	Assets/LDtkUnity/Samples~/Samples/AutoLayers_4_Assistant.ldtk
#	Assets/LDtkUnity/Samples~/Samples/AutoLayers_5_Advanced.ldtk
#	Assets/LDtkUnity/Samples~/Samples/AutoLayers_6_OptionalRules.ldtk
#	Assets/LDtkUnity/Samples~/Samples/SeparateLevelFiles.ldtk
#	Assets/LDtkUnity/Samples~/Samples/Test_file_for_API_showing_all_features.ldtk
#	Assets/LDtkUnity/Samples~/Samples/Typical_2D_platformer_example.ldtk
#	Assets/LDtkUnity/Samples~/Samples/Typical_TopDown_example.ldtk
#	Assets/LDtkUnity/Samples~/Samples/WorldMap_Free_layout.ldtk
#	Assets/LDtkUnity/Samples~/Samples/WorldMap_GridVania_layout.ldtk
  • Loading branch information
Cammin committed Jan 12, 2024
2 parents 2edcb38 + a3d612f commit 05e54d0
Show file tree
Hide file tree
Showing 62 changed files with 1,438 additions and 386 deletions.
15 changes: 12 additions & 3 deletions Assets/LDtkUnity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# 4.1.1
###### January 1, 2024
- Updated json support & samples for [LDtk 1.5](https://ldtk.io/json/#changes;1.5.0)
# 4.2.0
###### January 3, 2023
- Updated json support & samples for [LDtk 1.5.2](https://ldtk.io/json/#changes;1.5.2)
- Added support for the additional Table-of-content data from LDtk 1.5
- Except the `Fields`; will come later
- Deprecated `LDtkTableOfContents.GetEntities`, use `GetEntry` instead
- Added LDtkPreprocessor: Use to read/modify any json data before GameObject hierarchies are created
- Improved the experience with the tileset export app
- Instead of the export app looking for an active windows process to get the project name, it's a new parameter in the command.
- The export app will now pause if errors are encountered to enable easier reading

### Note
- This version has an update to the tileset export app, and the command to run is changed. So follow these two steps:
- Select your LDtk project file, and you will be able to install a newer version with the click of a button.
- Copy the new command from the importer inspector, and paste it into your LDtk project settings and Re-save.

# 4.1.0
###### October 23, 2023
Expand Down
14 changes: 7 additions & 7 deletions Assets/LDtkUnity/Editor/Builders/LDtkBuilderEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ namespace LDtkUnity.Editor
internal sealed class LDtkBuilderEntity : LDtkBuilderLayer
{
private readonly WorldLayout _layout;
private readonly LDtkPostProcessorCache _postProcess;
private readonly LDtkAssetProcessorActionCache _assetProcess;
private readonly LDtkLinearLevelVector _linearVector;

private EntityInstance _entity;
private GameObject _entityObj;


public LDtkBuilderEntity(LDtkProjectImporter project, LDtkComponentLayer layerComponent, LDtkSortingOrder sortingOrder, LDtkLinearLevelVector linearVector, WorldLayout layout, LDtkPostProcessorCache postProcess, LDtkJsonImporter importer)
public LDtkBuilderEntity(LDtkProjectImporter project, LDtkComponentLayer layerComponent, LDtkSortingOrder sortingOrder, LDtkLinearLevelVector linearVector, WorldLayout layout, LDtkAssetProcessorActionCache assetProcess, LDtkJsonImporter importer)
: base(project, layerComponent, sortingOrder, importer)
{
_linearVector = linearVector;
_layout = layout;
_postProcess = postProcess;
_assetProcess = assetProcess;
}

//this is to maintain uniqueness in the import process
Expand Down Expand Up @@ -95,13 +95,13 @@ private void InterfaceEvents(LDtkFields fields)
LayerInstance layer = Layer;
EntityInstance entity = _entity;

_postProcess.TryAddInterfaceEvent<ILDtkImportedLayer>(behaviors, e => e.OnLDtkImportLayer(layer));
_assetProcess.TryAddInterfaceEvent<ILDtkImportedLayer>(behaviors, e => e.OnLDtkImportLayer(layer));
if (fields != null)
{
_postProcess.TryAddInterfaceEvent<ILDtkImportedFields>(behaviors, e => e.OnLDtkImportFields(fields));
_assetProcess.TryAddInterfaceEvent<ILDtkImportedFields>(behaviors, e => e.OnLDtkImportFields(fields));
}
_postProcess.TryAddInterfaceEvent<ILDtkImportedEntity>(behaviors, e => e.OnLDtkImportEntity(entity));
_postProcess.TryAddInterfaceEvent<ILDtkImportedSortingOrder>(behaviors, e => e.OnLDtkImportSortingOrder(sortingOrder));
_assetProcess.TryAddInterfaceEvent<ILDtkImportedEntity>(behaviors, e => e.OnLDtkImportEntity(entity));
_assetProcess.TryAddInterfaceEvent<ILDtkImportedSortingOrder>(behaviors, e => e.OnLDtkImportSortingOrder(sortingOrder));
}

private void ScaleEntity()
Expand Down
19 changes: 7 additions & 12 deletions Assets/LDtkUnity/Editor/Builders/LDtkBuilderLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal sealed class LDtkBuilderLevel
private readonly Level _level;
private readonly WorldLayout _worldLayout;
private readonly LDtkLinearLevelVector _linearVector;
private readonly LDtkPostProcessorCache _postProcess;
private readonly LDtkAssetProcessorActionCache _assetProcess;

private GameObject _levelGameObject;
private LDtkComponentLevel _levelComponent;
Expand All @@ -28,12 +28,12 @@ internal sealed class LDtkBuilderLevel
private LDtkBuilderEntity _entityBuilder;
private LDtkBuilderLevelBackground _backgroundBuilder;

public LDtkBuilderLevel(LDtkProjectImporter project, LdtkJson json, WorldLayout world, Level level, LDtkPostProcessorCache postProcess, LDtkJsonImporter importer, LDtkLinearLevelVector linearVector = null)
public LDtkBuilderLevel(LDtkProjectImporter project, LdtkJson json, WorldLayout world, Level level, LDtkAssetProcessorActionCache assetProcess, LDtkJsonImporter importer, LDtkLinearLevelVector linearVector = null)
{
_project = project;
_json = json;
_level = level;
_postProcess = postProcess;
_assetProcess = assetProcess;
_importer = importer;
_worldLayout = world;
_linearVector = linearVector;
Expand All @@ -57,12 +57,7 @@ public void BuildLevel()
}

BuildLevelProcess();
SetupPostProcessing();
}

private void SetupPostProcessing()
{
LDtkPostProcessorInvoker.AddPostProcessLevel(_postProcess, _levelGameObject, _json);
LDtkAssetProcessorInvoker.AddPostProcessLevel(_assetProcess, _levelGameObject, _json);
}

private bool CanTryBuildLevel()
Expand Down Expand Up @@ -133,9 +128,9 @@ private void BuildFields()

if (addedFields)
{
_postProcess.TryAddInterfaceEvent<ILDtkImportedFields>(monoBehaviours, levelComponent => levelComponent.OnLDtkImportFields(lDtkFields));
_assetProcess.TryAddInterfaceEvent<ILDtkImportedFields>(monoBehaviours, levelComponent => levelComponent.OnLDtkImportFields(lDtkFields));
}
_postProcess.TryAddInterfaceEvent<ILDtkImportedLevel>(monoBehaviours, levelComponent => levelComponent.OnLDtkImportLevel(level));
_assetProcess.TryAddInterfaceEvent<ILDtkImportedLevel>(monoBehaviours, levelComponent => levelComponent.OnLDtkImportLevel(level));
}

private void AddIidComponent()
Expand Down Expand Up @@ -285,7 +280,7 @@ void SetupTileBuilder()
{
BuildLayerGameObject();

_entityBuilder = new LDtkBuilderEntity(_project, _layerComponent, _sortingOrder, _linearVector, _worldLayout, _postProcess, _importer);
_entityBuilder = new LDtkBuilderEntity(_project, _layerComponent, _sortingOrder, _linearVector, _worldLayout, _assetProcess, _importer);

_entityBuilder.SetLayer(layer);

Expand Down
22 changes: 6 additions & 16 deletions Assets/LDtkUnity/Editor/Builders/LDtkBuilderProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class LDtkProjectBuilder
private readonly LDtkProjectImporter _project;
private readonly LdtkJson _json;
private readonly World[] _worlds;
private LDtkPostProcessorCache _actions;
private LDtkAssetProcessorActionCache _actions;

public GameObject RootObject { get; private set; } = null;

Expand All @@ -29,9 +29,11 @@ public void BuildProject()

LDtkIidComponentBank.Release();

_actions = new LDtkPostProcessorCache();
BuildProcess();
_actions.PostProcess();
_actions = new LDtkAssetProcessorActionCache();
CreateRootObject();
BuildWorlds();
LDtkAssetProcessorInvoker.AddPostProcessProject(_actions, RootObject);
_actions.Process();

LDtkIidComponentBank.Release();
}
Expand Down Expand Up @@ -64,13 +66,6 @@ private bool TryCanBuildProject()

return true;
}

private void BuildProcess()
{
CreateRootObject();
BuildWorlds();
AddProjectPostProcess();
}

private void BuildWorlds()
{
Expand All @@ -88,11 +83,6 @@ private void BuildWorlds()
}
}

private void AddProjectPostProcess()
{
LDtkPostProcessorInvoker.AddPostProcessProject(_actions, RootObject);
}

private void CreateRootObject()
{
RootObject = new GameObject(_project.AssetName);
Expand Down
8 changes: 4 additions & 4 deletions Assets/LDtkUnity/Editor/Builders/LDtkBuilderWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ internal sealed class LDtkBuilderWorld
private readonly LDtkJsonImporter _importer;
private readonly LdtkJson _json;
private readonly World _world;
private readonly LDtkPostProcessorCache _postProcess;
private readonly LDtkAssetProcessorActionCache _assetProcess;
private readonly LDtkLinearLevelVector _linearVector = new LDtkLinearLevelVector();

private readonly GameObject _worldObject;

public LDtkBuilderWorld(GameObject worldObj, LDtkProjectImporter project, LdtkJson json, World world, LDtkPostProcessorCache postProcess, LDtkJsonImporter importer)
public LDtkBuilderWorld(GameObject worldObj, LDtkProjectImporter project, LdtkJson json, World world, LDtkAssetProcessorActionCache assetProcess, LDtkJsonImporter importer)
{
_worldObject = worldObj;
_project = project;
_json = json;
_world = world;
_postProcess = postProcess;
_assetProcess = assetProcess;
_importer = importer;
}

Expand All @@ -30,7 +30,7 @@ public void BuildWorld()
foreach (Level lvl in _world.Levels)
{
WorldLayout layout = _world.WorldLayout.HasValue ? _world.WorldLayout.Value : WorldLayout.Free;
LDtkBuilderLevel levelBuilder = new LDtkBuilderLevel(_project, _json, layout, lvl, _postProcess, _importer, _linearVector);
LDtkBuilderLevel levelBuilder = new LDtkBuilderLevel(_project, _json, layout, lvl, _assetProcess, _importer, _linearVector);

Profiler.BeginSample("SetParent Level to World");
GameObject levelObj = levelBuilder.StubGameObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ internal sealed class LDtkEditorCommandUpdater
public LDtkEditorCommandUpdater(string projectPath)
{
ProjectPath = projectPath;
Command = GetCommand();
ProjectName = Path.GetFileNameWithoutExtension(projectPath);
Command = GetCommand();
}

private string GetCommand()
Expand All @@ -34,6 +34,9 @@ private string GetCommand()
//backslashes break deserialization
commandContent = LDtkPathUtility.CleanPathSlashes(commandContent);

//append the project name!
commandContent += $" {ProjectName}";

//Debug.Log($"fromPath {fromPath}");
//Debug.Log($"appPath {appPath}");
//Debug.Log($"relPath {relPath}");
Expand Down Expand Up @@ -287,7 +290,7 @@ public bool HasCustomCommand(LdtkJson data, out string reason)
}
}

reason = $"A command to the above path doesn't exists";
reason = $"A command to the above path doesn't exists or needs to be updated";
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace LDtkUnity.Editor
{
internal sealed class LDtkPostProcessorCache
/// <summary>
/// An object that would be stored somewhere to accumulate actions, and then run them all later.
/// The stored actions are sorted by order before </summary>
internal sealed class LDtkAssetProcessorActionCache
{
private readonly List<LDtkPostProcessorAction> _postprocessActions = new List<LDtkPostProcessorAction>();
private readonly List<LDtkAssetProcessorAction> _assetProcessActions = new List<LDtkAssetProcessorAction>();

public void AddPostProcessAction(int order, Action action, string debugInfo)
public void AddProcessAction(int order, Action action, string debugInfo)
{
_postprocessActions.Add(new LDtkPostProcessorAction()
_assetProcessActions.Add(new LDtkAssetProcessorAction()
{
Action = action,
Order = order,
Expand All @@ -24,34 +27,34 @@ public void TryAddInterfaceEvent<T>(MonoBehaviour[] behaviors, Action<T> action)
{
if (component is T imported)
{
AddPostProcessAction(
AddProcessAction(
imported.GetPostprocessOrder(),
() => { action.Invoke(imported); },
$"Interface\t<{typeof(T).Name}>\t({component.gameObject.name})");
}
}
}

public void PostProcess()
public void Process()
{
if (_postprocessActions == null)
if (_assetProcessActions == null)
{
LDtkDebug.LogError("LDtkPostProcessorCache not initialized first");
return;
}

//sort everything to that execution is based on the user's custom inputs
_postprocessActions.Sort();
_assetProcessActions.Sort();

if (LDtkPrefs.VerboseLogging)
{
foreach (LDtkPostProcessorAction action in _postprocessActions)
foreach (LDtkAssetProcessorAction action in _assetProcessActions)
{
LDtkDebug.Log($"Postprocess: {action}");
LDtkDebug.Log($"Process: {action}");
}
}

foreach (LDtkPostProcessorAction action in _postprocessActions)
foreach (LDtkAssetProcessorAction action in _assetProcessActions)
{
try
{
Expand All @@ -64,4 +67,21 @@ public void PostProcess()
}
}
}

internal sealed class LDtkAssetProcessorAction : IComparable<LDtkAssetProcessorAction>
{
public int Order = 0;
public Action Action;
public string DebugInfo;

public int CompareTo(LDtkAssetProcessorAction other)
{
return Order.CompareTo(other.Order);
}

public override string ToString()
{
return $"{Order}\t{DebugInfo}";
}
}
}
Loading

0 comments on commit 05e54d0

Please sign in to comment.