using Godot; using Newlon.Components.Zombies; using System.Collections.Generic; namespace Newlon.Components.Level; public partial class ZombieLevelPreviewer : Node2D { public void OnLevelStateChanged(RuntimeLevelData.LevelStates state) { switch (state) { case RuntimeLevelData.LevelStates.ChooseYourSeeds: SetupZombies(); break; case RuntimeLevelData.LevelStates.Pregame: break; default: QueueFree(); break; } } public void SetupZombies() { var to_spawn = FindUnique(); foreach (var zombie in to_spawn) { var rng_x = (float)GD.RandRange(0.0, 2.0); var rng_y = (float)GD.RandRange(1.0, 5.0); var spawned = zombie.Scene.Instantiate(); spawned.DisableBrain(); AddChild(spawned); spawned.Position += new Vector2(rng_x*Utility.TileWidth, rng_y*Utility.TileHeight); } } public List FindUnique() { List zombies = new(); foreach (var wave in RuntimeLevelData.Instance.levelResource.waves) { foreach (var spawn in wave.zombiesOrdered) { foreach (var zombie in spawn.zombies) { if (zombie == null || zombies.Contains(zombie)) continue; zombies.Add(zombie); } } } return zombies; } }