Reworked the fieldservice
This commit is contained in:
@@ -62,20 +62,26 @@ public partial class FarmingControls : Node3D
|
||||
{
|
||||
if(FieldParent == null || _fieldPrefab == null)
|
||||
return;
|
||||
|
||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||
|
||||
if (fieldInstance is Node3D field3d)
|
||||
// get current player position and adjust it to field / dictionary needs
|
||||
Vector3 playerPos = _movingPlayer.GlobalPosition;
|
||||
playerPos = new Vector3(AdjustValue(playerPos.X), 0.1f, AdjustValue(playerPos.Z));
|
||||
Vector2I intPosition = new Vector2I((int) playerPos.X, (int) playerPos.Z);
|
||||
|
||||
// only instantiate a field if there isn't one already.
|
||||
if(FieldParent.Get(intPosition) == null)
|
||||
{
|
||||
Vector3 playerPos = _movingPlayer.GlobalPosition;
|
||||
playerPos = new Vector3(AdjustValue(playerPos.X), 0.1f, AdjustValue(playerPos.Z));
|
||||
field3d.Position = playerPos;
|
||||
Vector2I intPosition = new Vector2I((int) playerPos.X, (int) playerPos.Z);
|
||||
FieldParent.AddEntry(intPosition, FieldState.Tilled);
|
||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||
if (fieldInstance is Node3D field3d)
|
||||
{
|
||||
// add dictionary entry for the field
|
||||
FieldParent.TryAddEntry(intPosition, field3d as FieldBehaviour);
|
||||
|
||||
// reposition and reparent the instance
|
||||
field3d.Position = playerPos;
|
||||
FieldParent.AddChild(fieldInstance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FieldParent.AddChild(fieldInstance);
|
||||
}
|
||||
|
||||
private float AdjustValue(float value)
|
||||
|
||||
Reference in New Issue
Block a user