From c57417a583816bcd1c3d33a8422c5c91275d0377 Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 22 Oct 2023 15:28:34 -0400 Subject: [PATCH] PR corrections --- Assets/Scripts/LevelConfig/WaveConfig.cs | 8 +++-- Assets/Scripts/LevelConfig/WaveObserver.cs | 34 ++++++++++----------- Assets/Scripts/LevelManager/LevelManager.cs | 2 +- Assets/Scripts/Tiles/SpawnerTile.cs | 7 +++-- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Assets/Scripts/LevelConfig/WaveConfig.cs b/Assets/Scripts/LevelConfig/WaveConfig.cs index 34c1052..afee1dd 100644 --- a/Assets/Scripts/LevelConfig/WaveConfig.cs +++ b/Assets/Scripts/LevelConfig/WaveConfig.cs @@ -36,10 +36,12 @@ public class WaveConfig : ScriptableObject return _nestedGroupSpawn; } } - public float GetInterval() + public float Interval { - float interval = _gameDuration * 60.0f / (_enemySum > 0 ? _enemySum.ToFloat() : SumCount()); - return interval; + get { + float interval = _gameDuration * 60.0f / (_enemySum > 0 ? _enemySum.ToFloat() : SumCount()); + return interval; + } } /** * Returns the updated game interval after adjusting to enemies spawned at the start diff --git a/Assets/Scripts/LevelConfig/WaveObserver.cs b/Assets/Scripts/LevelConfig/WaveObserver.cs index 42b5ad4..3229353 100644 --- a/Assets/Scripts/LevelConfig/WaveObserver.cs +++ b/Assets/Scripts/LevelConfig/WaveObserver.cs @@ -14,23 +14,21 @@ public class WaveObserver : Singleton private List _intervalTiming = new List(); private bool _once = true; private int _currentGroupIndex = 0; - public WaveConfig LevelConfig + + public void SetLevelConfig(WaveConfig config) { - set + _levelConfig = config; + _copyConstantSpawn = new List(); + _copyGroupSpawn = new List(); + _groupSpawnTimers = new List(); + foreach (EnemyType enemy in _levelConfig.ConstantSpawn) { - _levelConfig = value; - _copyConstantSpawn = new List(); - _copyGroupSpawn = new List(); - _groupSpawnTimers = new List(); - foreach (EnemyType enemy in _levelConfig.ConstantSpawn) - { - _copyConstantSpawn.Add(enemy.Count); - } - for (int index = 0; index < _levelConfig.NestedGroupSpawn.Count; index++) - { - _copyGroupSpawn.Add(_levelConfig.NestedGroupSpawn[index]); - _groupSpawnTimers.Add(_levelConfig.NestedGroupSpawn[index].triggerTime); - } + _copyConstantSpawn.Add(enemy.Count); + } + for (int index = 0; index < _levelConfig.NestedGroupSpawn.Count; index++) + { + _copyGroupSpawn.Add(_levelConfig.NestedGroupSpawn[index]); + _groupSpawnTimers.Add(_levelConfig.NestedGroupSpawn[index].triggerTime); } } @@ -49,7 +47,7 @@ public class WaveObserver : Singleton if (_once) { _once = false; - spawnerSubject.GroupSpawnTimers = _groupSpawnTimers; + spawnerSubject.SetGroupSpawnTimers(_groupSpawnTimers); } } @@ -60,7 +58,7 @@ public class WaveObserver : Singleton public void NotifySpawned(SpawnerTile spawnerSubject) { GameObject paramPrefab = spawnerSubject.Prefab; - spawnerSubject.ChangeSpawnSpeed(_levelConfig.GetInterval() * _spawnerTiming); + spawnerSubject.ChangeSpawnSpeed(_levelConfig.Interval * _spawnerTiming); if (paramPrefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject())) { int currentCount = 0; @@ -152,7 +150,7 @@ public class WaveObserver : Singleton { index = rand.Next(_subjects.Count); } while (_intervalTiming.Count <= index); - spawnerTile.ChangeSpawnSpeed(_levelConfig.GetInterval() * _intervalTiming[index]); + spawnerTile.ChangeSpawnSpeed(_levelConfig.Interval * _intervalTiming[index]); _intervalTiming.Remove(index); } diff --git a/Assets/Scripts/LevelManager/LevelManager.cs b/Assets/Scripts/LevelManager/LevelManager.cs index a181634..940bd8f 100644 --- a/Assets/Scripts/LevelManager/LevelManager.cs +++ b/Assets/Scripts/LevelManager/LevelManager.cs @@ -166,7 +166,7 @@ public class LevelManager : Singleton _currentLevel = level; _waveObserver = WaveObserver.Instance; - _waveObserver.LevelConfig = _currentLevel.WaveConfig; + _waveObserver.SetLevelConfig(_currentLevel.WaveConfig); Grid grid = Object.FindObjectOfType(); //create new grid if there is none if (!grid) diff --git a/Assets/Scripts/Tiles/SpawnerTile.cs b/Assets/Scripts/Tiles/SpawnerTile.cs index 7aac2ca..b37aa4f 100644 --- a/Assets/Scripts/Tiles/SpawnerTile.cs +++ b/Assets/Scripts/Tiles/SpawnerTile.cs @@ -17,11 +17,12 @@ public class SpawnerTile : LevelTile private bool _stopped = false; private bool _cooldownEnded = false; private List _groupSpawnTimers = new List(); - public List GroupSpawnTimers + + public void SetGroupSpawnTimers(List groupSpawnTimers) { - set + for (int i = 0; i < groupSpawnTimers.Count-1; i++) { - _groupSpawnTimers = value; + _groupSpawnTimers.Add(groupSpawnTimers[i]); } }