[Refactor] Replace enum-driven modifier system with data-driven SO composition
Replace the entire static, enum-based modifier pipeline with a composition-based, data-driven architecture using ScriptableObject polymorphism. New modifiers can now be created by assembling SO building blocks (Conditions + Effects + Behaviors) — no core code edits needed. New architecture: - Core/: TriggerType, ModifierPhase, ModifierContext, ICondition, IEffect - Definition/: ModifierDefinitionSO, ModifierBehaviorSO, ConditionSO, EffectSO, ModifierCatalogSO - Conditions/: DieValueCondition, CategoryCondition, MinScoreCondition, DiceCountCondition - Effects/: AddFlat, AddPerDie, Multiply, MultiplyPerDie, PostMultiply, AddCurrency, ConsumeCharge - Runtime/: ModifierInstance, ModifierRegistry (non-static service) - Pipeline/: async ModifierPipeline with phase ordering, tracing, anti-recursion - Editor/: ModifierDefinitionValidator with menu items - Events/: GameEventBus (non-static typed dispatcher) - DI/: GameLifetimeScope (VContainer composition root) Deleted old system: ModifierData, ModifierEffect, ModifierEnums, ModifierPipeline (static), ModifierRuntime, ModifierTarget, ShopCatalog, ModifierAssetCreator. Updated: ScoringSystem (VContainer + async), InventoryModel (delegates to ModifierRegistry), ShopModel (uses ModifierDefinitionSO), GameController (VContainer injection), SaveData (uses Runtime.ModifierSaveEntry), all views/controllers, and all test files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YachtDice.Modifiers.Core;
|
||||
|
||||
namespace YachtDice.Modifiers.Definition
|
||||
{
|
||||
[CreateAssetMenu(fileName = "NewModifier", menuName = "YachtDice/Modifiers/Definition")]
|
||||
public class ModifierDefinitionSO : ScriptableObject
|
||||
{
|
||||
[Header("Identity")]
|
||||
[SerializeField] private string id;
|
||||
[SerializeField] private string displayName;
|
||||
[SerializeField, TextArea] private string description;
|
||||
[SerializeField] private Sprite icon;
|
||||
[SerializeField] private ModifierRarity rarity;
|
||||
|
||||
[Header("Economy")]
|
||||
[SerializeField] private int shopPrice;
|
||||
[SerializeField] private int sellPrice;
|
||||
|
||||
[Header("Durability")]
|
||||
[SerializeField] private bool hasLimitedUses;
|
||||
[SerializeField] private int maxUses;
|
||||
[SerializeField] private int maxStacks = 1;
|
||||
|
||||
[Header("Behaviors")]
|
||||
[SerializeField] private List<ModifierBehaviorSO> behaviors = new();
|
||||
|
||||
public string Id => id;
|
||||
public string DisplayName => displayName;
|
||||
public string Description => description;
|
||||
public Sprite Icon => icon;
|
||||
public ModifierRarity Rarity => rarity;
|
||||
public int ShopPrice => shopPrice;
|
||||
public int SellPrice => sellPrice;
|
||||
public bool HasLimitedUses => hasLimitedUses;
|
||||
public int MaxUses => maxUses;
|
||||
public int MaxStacks => maxStacks;
|
||||
public IReadOnlyList<ModifierBehaviorSO> Behaviors => behaviors;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static ModifierDefinitionSO CreateForTest(
|
||||
string id,
|
||||
List<ModifierBehaviorSO> behaviors,
|
||||
bool hasLimitedUses = false,
|
||||
int maxUses = 0,
|
||||
int shopPrice = 100,
|
||||
int sellPrice = 50,
|
||||
ModifierRarity rarity = ModifierRarity.Common)
|
||||
{
|
||||
var so = CreateInstance<ModifierDefinitionSO>();
|
||||
so.id = id;
|
||||
so.displayName = id;
|
||||
so.description = id;
|
||||
so.rarity = rarity;
|
||||
so.shopPrice = shopPrice;
|
||||
so.sellPrice = sellPrice;
|
||||
so.hasLimitedUses = hasLimitedUses;
|
||||
so.maxUses = maxUses;
|
||||
so.behaviors = behaviors ?? new List<ModifierBehaviorSO>();
|
||||
return so;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user