Added decoration assets and placement. Currently all placeholders are replaced, need to implement a chance based system.
This commit is contained in:
@@ -2,7 +2,7 @@ using Godot;
|
||||
|
||||
public class Placeholder
|
||||
{
|
||||
string name;
|
||||
public string name;
|
||||
public Vector3 pos;
|
||||
|
||||
public Placeholder(string name, Vector3 pos){
|
||||
|
||||
@@ -27,4 +27,17 @@ public partial class ResourceLoader
|
||||
|
||||
return tileMeshes;
|
||||
}
|
||||
|
||||
public static Dictionary<string, MeshInstance3D> LoadDecorations()
|
||||
{
|
||||
Dictionary<string, MeshInstance3D> decorationMeshes = new Dictionary<string, MeshInstance3D>();
|
||||
PackedScene decorationCollection = GD.Load<PackedScene>($"res://Assets/Objects/Decorations.glb");
|
||||
Node root = decorationCollection.Instantiate();
|
||||
foreach (MeshInstance3D child in root.GetChildren())
|
||||
{
|
||||
decorationMeshes.Add(child.Name.ToString().ToLower(), child);
|
||||
}
|
||||
|
||||
return decorationMeshes;
|
||||
}
|
||||
}
|
||||
|
||||
+23
-6
@@ -1,11 +1,13 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static GameData;
|
||||
|
||||
public partial class World : Node3D
|
||||
{
|
||||
public Dictionary<string, MeshInstance3D> tileMeshes;
|
||||
public Dictionary<string, MeshInstance3D> decorationMeshes;
|
||||
public Dictionary<string, List<Placeholder>> tilePlaceholders;
|
||||
PackedScene layerPrefab = ResourceLoader.LoadLayerPrefab();
|
||||
private Dictionary<string, MultiMeshInstance3D> multiMeshes = new();
|
||||
@@ -17,6 +19,7 @@ public partial class World : Node3D
|
||||
{
|
||||
WFC.FillAdjacencies();
|
||||
tileMeshes = ResourceLoader.LoadTiles();
|
||||
decorationMeshes = ResourceLoader.LoadDecorations();
|
||||
tilePlaceholders = new Dictionary<string, List<Placeholder>>();
|
||||
foreach (var kvp in tileMeshes)
|
||||
{
|
||||
@@ -113,13 +116,27 @@ public partial class World : Node3D
|
||||
mm.SetInstanceTransform(i, list[i]);
|
||||
if (placeholders.Count > 0)
|
||||
{
|
||||
Node3D robot;
|
||||
foreach (Placeholder placeholder in placeholders)
|
||||
Node3D decoration;
|
||||
|
||||
Mesh mesh = decorationMeshes.Values.ToList()[0].Mesh;
|
||||
for(int j = 0; j < placeholders.Count; j++)
|
||||
{
|
||||
robot = ResourceLoader.LoadRobotPrefab().Instantiate<Node3D>();
|
||||
robot.Position = placeholder.pos + list[i].Origin;
|
||||
AddChild(robot);
|
||||
}
|
||||
foreach (MeshInstance3D meshes in decorationMeshes.Values)
|
||||
{
|
||||
if (meshes.Name.ToString().ToLower() == placeholders[j].name.ToLower())
|
||||
{
|
||||
mesh = meshes.Mesh;
|
||||
break;
|
||||
}
|
||||
}
|
||||
decoration = new MeshInstance3D();
|
||||
(decoration as MeshInstance3D).Mesh = mesh;
|
||||
decoration.Transform = list[i];
|
||||
decoration.Position += placeholders[j].pos;
|
||||
decoration.Name = placeholders[j].name + j;
|
||||
decoration.Rotate(Vector3.Up, Mathf.DegToRad(-90));
|
||||
layer.AddChild(decoration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user