Level Data decentralization
This commit is contained in:
parent
76b33db91f
commit
e3613b132e
12 changed files with 52 additions and 28 deletions
|
|
@ -6,20 +6,28 @@ public partial class PlantField : Node2D
|
|||
private readonly Vector2 tile = new Vector2(Utility.TileWidth, Utility.TileHeight);
|
||||
|
||||
private PlantResource _resource;
|
||||
private PlantSlot _slot;
|
||||
private Seedpacket _slot;
|
||||
private bool _previousCanPlace;
|
||||
|
||||
public static PlantField Instance {get; private set;}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
LevelController.Instance.PlantField = this;
|
||||
Instance = this;
|
||||
_plantSetter = GetChild<Sprite2D>(0);
|
||||
}
|
||||
|
||||
public void SetPlant(PlantSlot slot, PlantResource plant)
|
||||
public void SetPlant(Seedpacket slot, PlantResource plant)
|
||||
{
|
||||
_resource = plant;
|
||||
_slot = slot;
|
||||
}
|
||||
|
||||
public void ResetPlant()
|
||||
{
|
||||
SetPlant(null,null);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
// Getting and storing global mouse position, setting plant-poiner to it
|
||||
|
|
@ -35,8 +43,8 @@ public partial class PlantField : Node2D
|
|||
|
||||
bool canPlace = _resource != null
|
||||
&& inBoundary
|
||||
&& LevelController.Instance.Pools.EntityField[_resource.Layer].ContainsKey(expected_pos) == false
|
||||
&& LevelController.Instance.LevelData.CheckSpendSun(_resource.Cost);
|
||||
&& PoolContainer.Instance.EntityField[_resource.Layer].ContainsKey(expected_pos) == false
|
||||
&& RuntimeLevelData.Instance.CheckSpendSun(_resource.Cost);
|
||||
|
||||
// Setting visuals
|
||||
if (_previousCanPlace != canPlace)
|
||||
|
|
@ -69,14 +77,14 @@ public partial class PlantField : Node2D
|
|||
if (@event.IsActionPressed("primary_action") && _previousCanPlace)
|
||||
{
|
||||
var plant = _resource.Scene.Instantiate<RuntimePlantData>();
|
||||
LevelController.Instance.Pools.Plants.AddChild(plant);
|
||||
PoolContainer.Instance.Plants.AddChild(plant);
|
||||
plant.GlobalPosition = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14);
|
||||
plant.Resource = _resource;
|
||||
plant.Line = (int)plant.GlobalPosition.Y/Utility.TileHeight;
|
||||
|
||||
LevelController.Instance.Pools.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant as IEntity);
|
||||
PoolContainer.Instance.EntityField[_resource.Layer].Add(plant.GlobalPosition, plant as IEntity);
|
||||
|
||||
LevelController.Instance.LevelData.SpendSun(_resource.Cost);
|
||||
RuntimeLevelData.Instance.SpendSun(_resource.Cost);
|
||||
|
||||
// Unfocusing and recharging slot
|
||||
_slot.Recharge();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue