From ad725ee518bdfecfbe94c84f595b4019c9b41eb3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 12 Aug 2023 22:26:36 -0500 Subject: [PATCH] refactor: unify runtime sets, update naming of event channels (#17) Some general refactors: Turns HeroPartySO into a runtime set class. Make runtime set an IEnumerable Simplify name of events Reviewed-on: https://git.sunturtle.xyz/studio/idle-survivors/pulls/17 Reviewed-by: zephyr Co-authored-by: Michael Co-committed-by: Michael --- Assets/Prefabs/Hero.prefab | 2 +- Assets/Runtime Sets/PlayerParty.asset | 15 +++++++ Assets/Runtime Sets/PlayerParty.asset.meta | 8 ++++ Assets/Scenes/test.unity | 6 +-- Assets/Scripts/EnemyRuntimeSetSO.cs | 11 ----- ...OEventChannelSO.cs => SpawnWaveEventSO.cs} | 4 +- ...nelSO.cs.meta => SpawnWaveEventSO.cs.meta} | 0 Assets/Scripts/HeroPartySO.cs | 16 -------- Assets/Scripts/HeroPartySO.cs.meta | 11 ----- Assets/Scripts/HeroUnit.cs | 9 ++-- Assets/Scripts/RuntimeSet.meta | 3 ++ .../Scripts/RuntimeSet/EnemyRuntimeSetSO.cs | 10 +++++ .../EnemyRuntimeSetSO.cs.meta | 0 .../Scripts/RuntimeSet/HeroUnitRuntimeSet.cs | 9 ++++ .../RuntimeSet/HeroUnitRuntimeSet.cs.meta | 3 ++ Assets/Scripts/RuntimeSet/RuntimeSetSO.cs | 41 +++++++++++++++++++ .../{ => RuntimeSet}/RuntimeSetSO.cs.meta | 0 Assets/Scripts/RuntimeSetSO.cs | 26 ------------ Assets/Scripts/Wave/SpawnWaveSO.cs | 2 +- Assets/Scripts/Wave/WaveSpawner.cs | 5 ++- Assets/TestsPlaymode/HeroPartyTest.cs | 3 +- 21 files changed, 104 insertions(+), 80 deletions(-) create mode 100644 Assets/Runtime Sets/PlayerParty.asset create mode 100644 Assets/Runtime Sets/PlayerParty.asset.meta delete mode 100644 Assets/Scripts/EnemyRuntimeSetSO.cs rename Assets/Scripts/Events/{SpawnWaveSOEventChannelSO.cs => SpawnWaveEventSO.cs} (66%) rename Assets/Scripts/Events/{SpawnWaveSOEventChannelSO.cs.meta => SpawnWaveEventSO.cs.meta} (100%) delete mode 100644 Assets/Scripts/HeroPartySO.cs delete mode 100644 Assets/Scripts/HeroPartySO.cs.meta create mode 100644 Assets/Scripts/RuntimeSet.meta create mode 100644 Assets/Scripts/RuntimeSet/EnemyRuntimeSetSO.cs rename Assets/Scripts/{ => RuntimeSet}/EnemyRuntimeSetSO.cs.meta (100%) create mode 100644 Assets/Scripts/RuntimeSet/HeroUnitRuntimeSet.cs create mode 100644 Assets/Scripts/RuntimeSet/HeroUnitRuntimeSet.cs.meta create mode 100644 Assets/Scripts/RuntimeSet/RuntimeSetSO.cs rename Assets/Scripts/{ => RuntimeSet}/RuntimeSetSO.cs.meta (100%) delete mode 100644 Assets/Scripts/RuntimeSetSO.cs diff --git a/Assets/Prefabs/Hero.prefab b/Assets/Prefabs/Hero.prefab index 9bc0de0..450932d 100644 --- a/Assets/Prefabs/Hero.prefab +++ b/Assets/Prefabs/Hero.prefab @@ -50,7 +50,7 @@ MonoBehaviour: level: 0 xp: 0 attrs: {fileID: 0} - _party: {fileID: 11400000, guid: c9a46588e6ec04d4d91bb80fdffd7869, type: 2} + _party: {fileID: 11400000, guid: 2fdb3d0bb73994d4ba32eb41950b8f15, type: 2} --- !u!1 &4632618406133265053 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Runtime Sets/PlayerParty.asset b/Assets/Runtime Sets/PlayerParty.asset new file mode 100644 index 0000000..995aacd --- /dev/null +++ b/Assets/Runtime Sets/PlayerParty.asset @@ -0,0 +1,15 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0ec1a0df7a5949a2959596c722680f76, type: 3} + m_Name: PlayerParty + m_EditorClassIdentifier: + items: [] diff --git a/Assets/Runtime Sets/PlayerParty.asset.meta b/Assets/Runtime Sets/PlayerParty.asset.meta new file mode 100644 index 0000000..62ef502 --- /dev/null +++ b/Assets/Runtime Sets/PlayerParty.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2fdb3d0bb73994d4ba32eb41950b8f15 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/test.unity b/Assets/Scenes/test.unity index 7ab66de..dae1c0f 100644 --- a/Assets/Scenes/test.unity +++ b/Assets/Scenes/test.unity @@ -527,9 +527,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bb718e52728142e4a8db081fd6a36a70, type: 3} m_Name: m_EditorClassIdentifier: - startNewSpawnWaveEventChannel: {fileID: 11400000, guid: 3f9039af54fd5d240b144e1ab3bbeb72, type: 2} - endSpawnWaveEventChannel: {fileID: 11400000, guid: b8a8049e92364834ebac76909a03324b, type: 2} - enemyRuntimeSet: {fileID: 11400000, guid: 7c32c32e039cdda409e8a56d2e320f2d, type: 2} + startNewSpawnWaveEvent: {fileID: 11400000, guid: 3f9039af54fd5d240b144e1ab3bbeb72, type: 2} + endSpawnWaveEventEvent: {fileID: 11400000, guid: b8a8049e92364834ebac76909a03324b, type: 2} + activeEnemies: {fileID: 11400000, guid: 7c32c32e039cdda409e8a56d2e320f2d, type: 2} spawnCenter: {fileID: 19609788} minimumSpawnRadius: 10 timeBetweenClearedWaves: 0 diff --git a/Assets/Scripts/EnemyRuntimeSetSO.cs b/Assets/Scripts/EnemyRuntimeSetSO.cs deleted file mode 100644 index 6ac0946..0000000 --- a/Assets/Scripts/EnemyRuntimeSetSO.cs +++ /dev/null @@ -1,11 +0,0 @@ -using UnityEngine; - -namespace DefaultNamespace -{ - [CreateAssetMenu(menuName = "Enemy Runtime Set", fileName = - "EnemyRuntimeSet")] - public class EnemyRuntimeSetSO : RuntimeSetSO - { - - } -} \ No newline at end of file diff --git a/Assets/Scripts/Events/SpawnWaveSOEventChannelSO.cs b/Assets/Scripts/Events/SpawnWaveEventSO.cs similarity index 66% rename from Assets/Scripts/Events/SpawnWaveSOEventChannelSO.cs rename to Assets/Scripts/Events/SpawnWaveEventSO.cs index f633948..6fe225d 100644 --- a/Assets/Scripts/Events/SpawnWaveSOEventChannelSO.cs +++ b/Assets/Scripts/Events/SpawnWaveEventSO.cs @@ -4,8 +4,8 @@ using Wave; namespace Events { - [CreateAssetMenu(menuName = "Events/Spawn Wave SO Event Channel")] - public class SpawnWaveSOEventChannelSO : ScriptableObject + [CreateAssetMenu(menuName = "Events/Spawn Wave Event")] + public class SpawnWaveEventSO : ScriptableObject { public event UnityAction OnEventRaised; diff --git a/Assets/Scripts/Events/SpawnWaveSOEventChannelSO.cs.meta b/Assets/Scripts/Events/SpawnWaveEventSO.cs.meta similarity index 100% rename from Assets/Scripts/Events/SpawnWaveSOEventChannelSO.cs.meta rename to Assets/Scripts/Events/SpawnWaveEventSO.cs.meta diff --git a/Assets/Scripts/HeroPartySO.cs b/Assets/Scripts/HeroPartySO.cs deleted file mode 100644 index 9017a62..0000000 --- a/Assets/Scripts/HeroPartySO.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using UnityEngine; - -[CreateAssetMenu(fileName = "HeroParty", menuName = "Hero Party")] -public class HeroPartySO : ScriptableObject -{ - [SerializeField] - private List unitList = new List(); - public ReadOnlyCollection UnitList => unitList.AsReadOnly(); - - public void Add(HeroUnit unit) { unitList.Add(unit); } - public void Remove(HeroUnit unit) { unitList.Remove(unit); } - public int Count => unitList.Count; -} diff --git a/Assets/Scripts/HeroPartySO.cs.meta b/Assets/Scripts/HeroPartySO.cs.meta deleted file mode 100644 index 3898e62..0000000 --- a/Assets/Scripts/HeroPartySO.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: f0603cf6e7f1d884e89c3eb6a478a96c -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/HeroUnit.cs b/Assets/Scripts/HeroUnit.cs index 273a2e3..87ab0e2 100644 --- a/Assets/Scripts/HeroUnit.cs +++ b/Assets/Scripts/HeroUnit.cs @@ -1,9 +1,8 @@ -using System.Collections; -using System.Collections.Generic; +using System.Runtime.CompilerServices; +using RuntimeSet; using UnityEngine; using UnityEngine.Assertions; -using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("TestsPlaymode")] /// @@ -17,8 +16,8 @@ public class HeroUnit : MonoBehaviour [SerializeField] private long level; [SerializeField] private long xp; [SerializeField] private HeroAttributesSO attrs; - [SerializeField] private HeroPartySO _party; - internal HeroPartySO party => _party; + [SerializeField] private HeroUnitRuntimeSetSO _party; + internal HeroUnitRuntimeSetSO party => _party; private void OnEnable() { diff --git a/Assets/Scripts/RuntimeSet.meta b/Assets/Scripts/RuntimeSet.meta new file mode 100644 index 0000000..d3dc1e1 --- /dev/null +++ b/Assets/Scripts/RuntimeSet.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e9f6f30f3d8e4445a4a25d03245b2645 +timeCreated: 1691632737 \ No newline at end of file diff --git a/Assets/Scripts/RuntimeSet/EnemyRuntimeSetSO.cs b/Assets/Scripts/RuntimeSet/EnemyRuntimeSetSO.cs new file mode 100644 index 0000000..18c500d --- /dev/null +++ b/Assets/Scripts/RuntimeSet/EnemyRuntimeSetSO.cs @@ -0,0 +1,10 @@ +using DefaultNamespace; +using UnityEngine; + +namespace RuntimeSet +{ + [CreateAssetMenu(fileName = "EnemyRuntimeSet",menuName = "Runtime Set/Enemy")] + public class EnemyRuntimeSetSO : RuntimeSetSO + { + } +} \ No newline at end of file diff --git a/Assets/Scripts/EnemyRuntimeSetSO.cs.meta b/Assets/Scripts/RuntimeSet/EnemyRuntimeSetSO.cs.meta similarity index 100% rename from Assets/Scripts/EnemyRuntimeSetSO.cs.meta rename to Assets/Scripts/RuntimeSet/EnemyRuntimeSetSO.cs.meta diff --git a/Assets/Scripts/RuntimeSet/HeroUnitRuntimeSet.cs b/Assets/Scripts/RuntimeSet/HeroUnitRuntimeSet.cs new file mode 100644 index 0000000..3f855b8 --- /dev/null +++ b/Assets/Scripts/RuntimeSet/HeroUnitRuntimeSet.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace RuntimeSet +{ + [CreateAssetMenu(fileName = "EnemyRuntimeSet",menuName = "Runtime Set/Hero Unit")] + public class HeroUnitRuntimeSetSO : RuntimeSetSO + { + } +} \ No newline at end of file diff --git a/Assets/Scripts/RuntimeSet/HeroUnitRuntimeSet.cs.meta b/Assets/Scripts/RuntimeSet/HeroUnitRuntimeSet.cs.meta new file mode 100644 index 0000000..a0a40be --- /dev/null +++ b/Assets/Scripts/RuntimeSet/HeroUnitRuntimeSet.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0ec1a0df7a5949a2959596c722680f76 +timeCreated: 1691632762 \ No newline at end of file diff --git a/Assets/Scripts/RuntimeSet/RuntimeSetSO.cs b/Assets/Scripts/RuntimeSet/RuntimeSetSO.cs new file mode 100644 index 0000000..caa83b5 --- /dev/null +++ b/Assets/Scripts/RuntimeSet/RuntimeSetSO.cs @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace RuntimeSet +{ + public abstract class RuntimeSetSO : ScriptableObject, IEnumerable + { + [HideInInspector] [SerializeField] private List items = new(); + + protected IReadOnlyCollection Items => items; + public bool IsEmpty => items.Count == 0; + public int Count => items.Count; + + public void Add(T item) + { + if (!items.Contains(item)) + { + items.Add(item); + } + } + + public void Remove(T item) + { + if (items.Contains(item)) + { + items.Remove(item); + } + } + + public IEnumerator GetEnumerator() + { + return items.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/RuntimeSetSO.cs.meta b/Assets/Scripts/RuntimeSet/RuntimeSetSO.cs.meta similarity index 100% rename from Assets/Scripts/RuntimeSetSO.cs.meta rename to Assets/Scripts/RuntimeSet/RuntimeSetSO.cs.meta diff --git a/Assets/Scripts/RuntimeSetSO.cs b/Assets/Scripts/RuntimeSetSO.cs deleted file mode 100644 index 1686dfb..0000000 --- a/Assets/Scripts/RuntimeSetSO.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -public abstract class RuntimeSetSO : ScriptableObject -{ - [HideInInspector] [SerializeField] private List items = new(); - - public IReadOnlyCollection Items => items; - public bool IsEmpty => items.Count == 0; - - public void Add(T thing) - { - if (!items.Contains(thing)) - { - items.Add(thing); - } - } - - public void Remove(T thing) - { - if (items.Contains(thing)) - { - items.Remove(thing); - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/Wave/SpawnWaveSO.cs b/Assets/Scripts/Wave/SpawnWaveSO.cs index c7c3956..5299739 100644 --- a/Assets/Scripts/Wave/SpawnWaveSO.cs +++ b/Assets/Scripts/Wave/SpawnWaveSO.cs @@ -4,7 +4,7 @@ using UnityEngine.Serialization; namespace Wave { - [CreateAssetMenu(fileName = "SpawnWave", menuName = "Spawn Wave", order = 0)] + [CreateAssetMenu(fileName = "SpawnWave", menuName = "Spawn/Wave", order = 0)] public class SpawnWaveSO : ScriptableObject { [SerializeField] private List packs; diff --git a/Assets/Scripts/Wave/WaveSpawner.cs b/Assets/Scripts/Wave/WaveSpawner.cs index 3d53c16..8425b28 100644 --- a/Assets/Scripts/Wave/WaveSpawner.cs +++ b/Assets/Scripts/Wave/WaveSpawner.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using DefaultNamespace; using Events; +using RuntimeSet; using UnityEngine; using UnityEngine.Assertions; using Random = UnityEngine.Random; @@ -12,8 +13,8 @@ namespace Wave { public class WaveSpawner : MonoBehaviour { - [SerializeField] private SpawnWaveSOEventChannelSO startNewSpawnWaveEventChannel; - [SerializeField] private SpawnWaveSOEventChannelSO endSpawnWaveEventChannel; + [SerializeField] private SpawnWaveEventSO startNewSpawnWaveEventChannel; + [SerializeField] private SpawnWaveEventSO endSpawnWaveEventChannel; [SerializeField] private EnemyRuntimeSetSO enemyRuntimeSet; [SerializeField] private Transform spawnCenter; diff --git a/Assets/TestsPlaymode/HeroPartyTest.cs b/Assets/TestsPlaymode/HeroPartyTest.cs index 05effaa..e180d9c 100644 --- a/Assets/TestsPlaymode/HeroPartyTest.cs +++ b/Assets/TestsPlaymode/HeroPartyTest.cs @@ -1,5 +1,4 @@ using System.Collections; -using System.Collections.Generic; using NUnit.Framework; using UnityEditor; using UnityEngine; @@ -18,6 +17,6 @@ public class HeroPartyTest Assert.AreEqual(1, hero.party.Count); Object.Destroy(instance); yield return null; - Assert.IsEmpty(hero.party.UnitList); + Assert.IsEmpty(hero.party); } }