refactor: unify runtime sets, update naming of event channels (#17)
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Some general refactors:
Turns HeroPartySO into a runtime set class.
Make runtime set an IEnumerable
Simplify name of events

Reviewed-on: #17
Reviewed-by: zephyr <zephyr@noreply.localhost>
Co-authored-by: Michael <mep053@gmail.com>
Co-committed-by: Michael <mep053@gmail.com>
This commit is contained in:
2023-08-12 22:26:36 -05:00
committed by madxmike
parent 7b48612c4b
commit ad725ee518
21 changed files with 104 additions and 80 deletions

View File

@@ -1,11 +0,0 @@
using UnityEngine;
namespace DefaultNamespace
{
[CreateAssetMenu(menuName = "Enemy Runtime Set", fileName =
"EnemyRuntimeSet")]
public class EnemyRuntimeSetSO : RuntimeSetSO<Enemy>
{
}
}

View File

@@ -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<SpawnWaveSO> OnEventRaised;

View File

@@ -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<HeroUnit> unitList = new List<HeroUnit>();
public ReadOnlyCollection<HeroUnit> UnitList => unitList.AsReadOnly();
public void Add(HeroUnit unit) { unitList.Add(unit); }
public void Remove(HeroUnit unit) { unitList.Remove(unit); }
public int Count => unitList.Count;
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f0603cf6e7f1d884e89c3eb6a478a96c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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")]
/// <summary>
@@ -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()
{

3
Assets/Scripts/RuntimeSet.meta generated Normal file
View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e9f6f30f3d8e4445a4a25d03245b2645
timeCreated: 1691632737

View File

@@ -0,0 +1,10 @@
using DefaultNamespace;
using UnityEngine;
namespace RuntimeSet
{
[CreateAssetMenu(fileName = "EnemyRuntimeSet",menuName = "Runtime Set/Enemy")]
public class EnemyRuntimeSetSO : RuntimeSetSO<Enemy>
{
}
}

View File

@@ -0,0 +1,9 @@
using UnityEngine;
namespace RuntimeSet
{
[CreateAssetMenu(fileName = "EnemyRuntimeSet",menuName = "Runtime Set/Hero Unit")]
public class HeroUnitRuntimeSetSO : RuntimeSetSO<HeroUnit>
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0ec1a0df7a5949a2959596c722680f76
timeCreated: 1691632762

View File

@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RuntimeSet
{
public abstract class RuntimeSetSO<T> : ScriptableObject, IEnumerable<T>
{
[HideInInspector] [SerializeField] private List<T> items = new();
protected IReadOnlyCollection<T> 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<T> GetEnumerator()
{
return items.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

View File

@@ -1,26 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
public abstract class RuntimeSetSO<T> : ScriptableObject
{
[HideInInspector] [SerializeField] private List<T> items = new();
public IReadOnlyCollection<T> 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);
}
}
}

View File

@@ -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<SpawnPackSO> packs;

View File

@@ -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;