using Godot; using Newlon.Components; using Newlon.Components.Level; using Newlon.Components.Plants; using Newlon.Components.Zombies; public partial class InitialPackedSceneSpawner : Node { public void OnLevelStateChanged(RuntimeLevelData.LevelStates state) { if (state == RuntimeLevelData.LevelStates.ChooseYourSeeds) { for (int i = 0; i < RuntimeLevelData.LevelResource.initialScenes.Count; i++) { var packed = RuntimeLevelData.LevelResource.initialScenes[i]; if (packed == null) continue; var scene = packed.Instantiate(); if (scene is Node2D node) { int x = i % 9; int y = i / 9; var position = FieldParams.LeftFieldBoundary + new Vector2((x + 0.5f) * FieldParams.TileWidth, (y + 0.5f) * FieldParams.TileHeight); if (node is Entity entity) { var brainDisabler = new LevelStateBrainDisabler(); entity.DisableBrain(); entity.AddChild(brainDisabler); if (entity is RuntimeZombieData) { PoolContainer.Instance.Structures.AddChild(node); node.GlobalPosition = position; } else if (entity is RuntimePlantData plant) { PoolContainer.Instance.Plants.AddChild(plant); node.GlobalPosition = position; plant.Resource = GameRegistry.GetPlantByName(plant.internal_id); PoolContainer.Instance.EntityField[plant.Resource.Layer].Add(plant.GlobalPosition, plant); } else { PoolContainer.Instance.Structures.AddChild(entity); node.GlobalPosition = position; PoolContainer.Instance.EntityField[1].Add(entity.GlobalPosition, entity); } } else { PoolContainer.Instance.Structures.AddChild(node); } } } } } }