WIP reworking the item repository
This commit is contained in:
@@ -16,6 +16,7 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
[Export] public FieldState FieldState = FieldState.Tilled;
|
||||
[Export] public InteractionArea2D PlantingInteraction;
|
||||
[Export] public Node2D PlantingPlaceholder;
|
||||
[Export] public ItemRepository ItemRepository;
|
||||
|
||||
|
||||
public Vector2 FieldPosition;
|
||||
@@ -83,24 +84,25 @@ public partial class FieldBehaviour2D : Sprite2D
|
||||
if (item == null || PlantingPlaceholder.GetChildCount() > 0)
|
||||
return success;
|
||||
|
||||
PackedScene? plantPrefab = item.blueprint.itemPrefab;
|
||||
string prefabPath = ItemRepository.TryGetPrefabPath(item.blueprint);
|
||||
|
||||
if (plantPrefab != null)
|
||||
if (prefabPath != null)
|
||||
{
|
||||
Node plantInstance = plantPrefab.Instantiate();
|
||||
if (plantInstance is Node2D plant2d)
|
||||
{
|
||||
PlantingPlaceholder.AddChild(plant2d);
|
||||
plant2d.GlobalPosition = PlantingPlaceholder.GlobalPosition;
|
||||
PlantBehaviour2D? plantBehaviour = plant2d as PlantBehaviour2D;
|
||||
|
||||
if (plantBehaviour != null)
|
||||
{
|
||||
plantBehaviour.Field = this;
|
||||
}
|
||||
|
||||
success = true;
|
||||
// todo: Error: cannot convert value at key from string to object
|
||||
PackedScene prefab = ResourceLoader.Load<PackedScene>(prefabPath, nameof(PackedScene));
|
||||
Node2D plant2d = prefab.Instantiate<Node2D>();
|
||||
PlantingPlaceholder.AddChild(plant2d);
|
||||
plant2d.GlobalPosition = PlantingPlaceholder.GlobalPosition;
|
||||
PlantBehaviour2D? plantBehaviour = plant2d as PlantBehaviour2D;
|
||||
|
||||
if (plantBehaviour != null)
|
||||
{
|
||||
plantBehaviour.Field = this;
|
||||
}
|
||||
|
||||
success = true;
|
||||
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
Reference in New Issue
Block a user