Plant field hologram rework

This commit is contained in:
Фёдор Веселов 2024-10-02 21:45:54 +05:00
commit 435ca455f0
6 changed files with 23 additions and 21 deletions

View file

@ -6,7 +6,7 @@ namespace Newlon.Components.Level;
public partial class PlantField : Node2D
{
private Sprite2D _plantSetter;
private Node2D _plantSetter;
private PlantResource _resource;
private Seedpacket _slot;
private bool _previousCanPlace;
@ -16,13 +16,23 @@ public partial class PlantField : Node2D
public override void _Ready()
{
Instance = this;
_plantSetter = GetChild<Sprite2D>(0);
_plantSetter = GetChild<Node2D>(0);
}
public void SetPlant(Seedpacket slot, PlantResource plant)
{
_resource = plant;
_slot = slot;
if (plant == null)
{
_plantSetter.GetChild(0).QueueFree();
}
else
{
var scene = plant.Scene.Instantiate<Node2D>();
_plantSetter.AddChild(scene);
scene.UseParentMaterial = true;
}
}
public void ResetPlant()
@ -66,7 +76,6 @@ public partial class PlantField : Node2D
if (canPlace)
_plantSetter.GlobalPosition = expected_pos;
_plantSetter.Texture = _resource?.Preview;
}
public override void _UnhandledInput(InputEvent @event)