add world position properties to LdtkLevel and update scene builder
This commit is contained in:
@@ -52,10 +52,6 @@ public partial class LdtkResourceImporter : EditorImportPlugin
|
|||||||
var scene = new PackedScene();
|
var scene = new PackedScene();
|
||||||
scene.Pack(rootNode);
|
scene.Pack(rootNode);
|
||||||
|
|
||||||
var newSceneNodeCount = scene.GetState().GetNodeCount();
|
|
||||||
|
|
||||||
GD.Print($"New scene node count: {newSceneNodeCount}, expected: {rootNode.GetChildCount() + 1} (including root)");
|
|
||||||
|
|
||||||
// 4. Save the generated scene
|
// 4. Save the generated scene
|
||||||
var destinationPath = $"{savePath}.{_GetSaveExtension()}";
|
var destinationPath = $"{savePath}.{_GetSaveExtension()}";
|
||||||
var error = ResourceSaver.Save(scene, destinationPath);
|
var error = ResourceSaver.Save(scene, destinationPath);
|
||||||
|
@@ -34,7 +34,6 @@ public class LdtkSceneBuilder
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A helper function to recursively set the owner on all children.
|
|
||||||
private void SetOwnerRecursive(Node node, Node owner)
|
private void SetOwnerRecursive(Node node, Node owner)
|
||||||
{
|
{
|
||||||
foreach (var child in node.GetChildren())
|
foreach (var child in node.GetChildren())
|
||||||
@@ -47,6 +46,7 @@ public class LdtkSceneBuilder
|
|||||||
private Node2D BuildLevel(LdtkLevel level)
|
private Node2D BuildLevel(LdtkLevel level)
|
||||||
{
|
{
|
||||||
var levelRoot = new Node2D { Name = level.Identifier };
|
var levelRoot = new Node2D { Name = level.Identifier };
|
||||||
|
levelRoot.Position = new Vector2(level.WorldX, level.WorldY);
|
||||||
|
|
||||||
foreach (var layer in level.LayerInstances.Reverse())
|
foreach (var layer in level.LayerInstances.Reverse())
|
||||||
{
|
{
|
||||||
|
@@ -7,6 +7,12 @@ public class LdtkLevel
|
|||||||
[JsonPropertyName("identifier")]
|
[JsonPropertyName("identifier")]
|
||||||
public string Identifier { get; set; }
|
public string Identifier { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("worldX")]
|
||||||
|
public int WorldX { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("worldY")]
|
||||||
|
public int WorldY { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("layerInstances")]
|
[JsonPropertyName("layerInstances")]
|
||||||
public LdtkLayerInstance[] LayerInstances { get; set; }
|
public LdtkLayerInstance[] LayerInstances { get; set; }
|
||||||
}
|
}
|
Reference in New Issue
Block a user