[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:
@@ -3,13 +3,15 @@ using UnityEngine;
|
||||
using YachtDice.Economy;
|
||||
using YachtDice.Inventory;
|
||||
using YachtDice.Shop;
|
||||
using YachtDice.Modifiers;
|
||||
using YachtDice.Modifiers.Definition;
|
||||
using YachtDice.Modifiers.Runtime;
|
||||
|
||||
namespace YachtDice.Tests
|
||||
{
|
||||
public sealed class ShopModelTests
|
||||
{
|
||||
private CurrencyBank bank;
|
||||
private ModifierRegistry registry;
|
||||
private InventoryModel inventory;
|
||||
private ShopModel shop;
|
||||
|
||||
@@ -20,7 +22,8 @@ namespace YachtDice.Tests
|
||||
bank = go.AddComponent<CurrencyBank>();
|
||||
bank.SetBalance(500);
|
||||
|
||||
inventory = new InventoryModel(5);
|
||||
registry = new ModifierRegistry(5);
|
||||
inventory = new InventoryModel(registry);
|
||||
shop = new ShopModel(bank, inventory);
|
||||
}
|
||||
|
||||
@@ -31,11 +34,19 @@ namespace YachtDice.Tests
|
||||
Object.DestroyImmediate(go.gameObject);
|
||||
}
|
||||
|
||||
private ModifierDefinitionSO CreateDef(string id = "test",
|
||||
bool hasLimitedUses = false, int maxUses = 0,
|
||||
int shopPrice = 100, int sellPrice = 50)
|
||||
{
|
||||
return ModifierDefinitionSO.CreateForTest(id, null,
|
||||
hasLimitedUses: hasLimitedUses, maxUses: maxUses,
|
||||
shopPrice: shopPrice, sellPrice: sellPrice);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryPurchase_SucceedsWithSufficientCurrency()
|
||||
{
|
||||
var mod = ModifierData.CreateForTest("test", ModifierScope.SelectedCategory,
|
||||
ModifierEffectType.AddFlatToFinalScore, 10f, shopPrice: 100);
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
bool result = shop.TryPurchase(mod);
|
||||
|
||||
@@ -48,8 +59,7 @@ namespace YachtDice.Tests
|
||||
public void TryPurchase_FailsWhenBroke()
|
||||
{
|
||||
bank.SetBalance(10);
|
||||
var mod = ModifierData.CreateForTest("test", ModifierScope.SelectedCategory,
|
||||
ModifierEffectType.AddFlatToFinalScore, 10f, shopPrice: 100);
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
bool result = shop.TryPurchase(mod);
|
||||
|
||||
@@ -61,9 +71,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void TryPurchase_PermanentCannotBeBoughtTwice()
|
||||
{
|
||||
var mod = ModifierData.CreateForTest("perm", ModifierScope.SelectedCategory,
|
||||
ModifierEffectType.AddFlatToFinalScore, 10f,
|
||||
durability: ModifierDurability.Permanent, shopPrice: 100);
|
||||
var mod = CreateDef("perm", shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(mod);
|
||||
bool secondResult = shop.TryPurchase(mod);
|
||||
@@ -76,9 +84,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void TryPurchase_LimitedCanBeReBought()
|
||||
{
|
||||
var mod = ModifierData.CreateForTest("limited", ModifierScope.SelectedCategory,
|
||||
ModifierEffectType.AddFlatToFinalScore, 10f,
|
||||
durability: ModifierDurability.LimitedUses, maxUses: 3, shopPrice: 100);
|
||||
var mod = CreateDef("limited", hasLimitedUses: true, maxUses: 3, shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(mod);
|
||||
bool secondResult = shop.TryPurchase(mod);
|
||||
@@ -91,11 +97,10 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void TryPurchase_FiresPurchaseEvent()
|
||||
{
|
||||
ModifierData purchased = null;
|
||||
shop.OnItemPurchased += data => purchased = data;
|
||||
ModifierDefinitionSO purchased = null;
|
||||
shop.OnItemPurchased += def => purchased = def;
|
||||
|
||||
var mod = ModifierData.CreateForTest("test", ModifierScope.SelectedCategory,
|
||||
ModifierEffectType.AddFlatToFinalScore, 10f, shopPrice: 100);
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(mod);
|
||||
|
||||
@@ -106,8 +111,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void GetItemState_Available_WhenCanAfford()
|
||||
{
|
||||
var mod = ModifierData.CreateForTest("test", ModifierScope.SelectedCategory,
|
||||
ModifierEffectType.AddFlatToFinalScore, 10f, shopPrice: 100);
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
Assert.AreEqual(ShopItemState.Available, shop.GetItemState(mod));
|
||||
}
|
||||
@@ -116,8 +120,7 @@ namespace YachtDice.Tests
|
||||
public void GetItemState_TooExpensive_WhenCannotAfford()
|
||||
{
|
||||
bank.SetBalance(10);
|
||||
var mod = ModifierData.CreateForTest("test", ModifierScope.SelectedCategory,
|
||||
ModifierEffectType.AddFlatToFinalScore, 10f, shopPrice: 100);
|
||||
var mod = CreateDef("test", shopPrice: 100);
|
||||
|
||||
Assert.AreEqual(ShopItemState.TooExpensive, shop.GetItemState(mod));
|
||||
}
|
||||
@@ -125,9 +128,7 @@ namespace YachtDice.Tests
|
||||
[Test]
|
||||
public void GetItemState_Owned_WhenPermanentPurchased()
|
||||
{
|
||||
var mod = ModifierData.CreateForTest("perm", ModifierScope.SelectedCategory,
|
||||
ModifierEffectType.AddFlatToFinalScore, 10f,
|
||||
durability: ModifierDurability.Permanent, shopPrice: 100);
|
||||
var mod = CreateDef("perm", shopPrice: 100);
|
||||
|
||||
shop.TryPurchase(mod);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user