Skip to content

Commit

Permalink
better tileset initialization in some minor cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammin committed Aug 28, 2023
1 parent 54325ba commit 631f42b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions Assets/LDtkUnity/Editor/ScriptedImporter/LDtkPpuInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ namespace LDtkUnity.Editor
{
internal struct LDtkPpuInitializer
{
public string ImporterPath;
public string ProjectPath;
public int PixelsPerUnit;

public LDtkPpuInitializer(int ppu, string projectPath)
public LDtkPpuInitializer(int ppu, string projectPath, string importerPath)
{
PixelsPerUnit = ppu;
ProjectPath = projectPath;
ImporterPath = importerPath;
}

public bool OnResetImporter()
Expand All @@ -23,7 +25,11 @@ public bool OnResetImporter()
}

int defaultGridSize = -1;
if (!LDtkJsonDigger.GetDefaultGridSize(ProjectPath, ref defaultGridSize))
if (ImporterPath != ProjectPath && AssetImporter.GetAtPath(ProjectPath) is LDtkProjectImporter projectImporter)
{
defaultGridSize = projectImporter.PixelsPerUnit;
}
else if (!LDtkJsonDigger.GetDefaultGridSize(ProjectPath, ref defaultGridSize))
{
//if problem, then default to what LDtk also defaults to upon a new project
defaultGridSize = LDtkImporterConsts.DEFAULT_PPU;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal sealed class LDtkProjectImporter : LDtkJsonImporter<LDtkProjectFile>
//this will run upon standard reset, but also upon the meta file generation during the first import
private void Reset()
{
LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, assetPath);
LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, assetPath, assetPath);
if (ppu.OnResetImporter())
{
_pixelsPerUnit = ppu.PixelsPerUnit;
Expand Down Expand Up @@ -149,7 +149,7 @@ protected override void Import()

//if for whatever reason (or backwards compatibility), if the ppu is -1 in any capacity
Profiler.BeginSample("SetPixelsPerUnit");
LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, assetPath);
LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, assetPath, assetPath);
if (ppu.TryInitializePixelsPerUnit(json.DefaultGridSize))
{
_pixelsPerUnit = ppu.PixelsPerUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal sealed partial class LDtkTilesetImporter : LDtkJsonImporter<LDtkTileset
//this will run upon standard reset, but also upon the meta file generation during the first import
private void Reset()
{
LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, GetProjectPath());
LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, GetProjectPath(), assetPath);
if (ppu.OnResetImporter())
{
_pixelsPerUnit = ppu.PixelsPerUnit;
Expand Down Expand Up @@ -101,7 +101,7 @@ protected override void Import()
Profiler.EndSample();

Profiler.BeginSample("SetPixelsPerUnit");
LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, GetProjectPath());
LDtkPpuInitializer ppu = new LDtkPpuInitializer(_pixelsPerUnit, GetProjectPath(), assetPath);
if (ppu.OnResetImporter())
{
_pixelsPerUnit = ppu.PixelsPerUnit;
Expand Down

0 comments on commit 631f42b

Please sign in to comment.