ba626acb9b
Replace hardcoded BonusForOnes/MultiplierForSixes with data-driven modifier system supporting 2 scopes (SelectedCategory, AnyCategoryClosed), 4 effect types, durability modes (Permanent, LimitedUses), and configurable targets via ScriptableObject (ModifierData). - Modifier domain: ModifierEnums, ModifierTarget, ModifierData, ModifierRuntime, ModifierEffect (dict-based strategy), ModifierPipeline (4-pass: cat-additive → cat-multiplicative → final-additive → final-multiplicative) - ScoringSystem: replaced old modifier list with ModifierPipeline integration, added OnCategoryConfirmed event - Shop MVC: ShopCatalog (SO), ShopModel, ShopView, ShopItemView, ShopController - Inventory MVC: InventoryModel (activate/deactivate/sell/durability), InventoryView, InventorySlotView, InventoryController - CurrencyBank: editor-adjustable balance with events - Persistence: SaveData + SaveSystem (Newtonsoft JSON + PlayerPrefs) - Editor: ModifierAssetCreator menu item to generate 6 example modifiers + catalog - Tests: 6 test classes covering effects, pipeline, scoring, shop, inventory, save - GameController: wired shop/inventory/save lifecycle - GameInfoView: added currency display, shop/inventory toggle buttons Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
89 lines
2.2 KiB
C#
89 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
|
|
public sealed class SaveSystemTests
|
|
{
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
SaveSystem.Delete();
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
SaveSystem.Delete();
|
|
}
|
|
|
|
[Test]
|
|
public void SaveAndLoad_RoundTrip_PreservesData()
|
|
{
|
|
var data = new SaveData
|
|
{
|
|
Currency = 999,
|
|
OwnedModifiers = new List<ModifierSaveEntry>
|
|
{
|
|
new() { ModifierId = "mod1", IsActive = true, RemainingUses = 3 },
|
|
new() { ModifierId = "mod2", IsActive = false, RemainingUses = -1 }
|
|
}
|
|
};
|
|
|
|
SaveSystem.Save(data);
|
|
var loaded = SaveSystem.Load();
|
|
|
|
Assert.AreEqual(999, loaded.Currency);
|
|
Assert.AreEqual(2, loaded.OwnedModifiers.Count);
|
|
Assert.AreEqual("mod1", loaded.OwnedModifiers[0].ModifierId);
|
|
Assert.IsTrue(loaded.OwnedModifiers[0].IsActive);
|
|
Assert.AreEqual(3, loaded.OwnedModifiers[0].RemainingUses);
|
|
Assert.AreEqual("mod2", loaded.OwnedModifiers[1].ModifierId);
|
|
Assert.IsFalse(loaded.OwnedModifiers[1].IsActive);
|
|
}
|
|
|
|
[Test]
|
|
public void Load_MissingKey_ReturnsDefault()
|
|
{
|
|
var loaded = SaveSystem.Load();
|
|
|
|
Assert.IsNotNull(loaded);
|
|
Assert.AreEqual(0, loaded.Currency);
|
|
Assert.AreEqual(0, loaded.OwnedModifiers.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void HasSave_ReturnsFalseWhenEmpty()
|
|
{
|
|
Assert.IsFalse(SaveSystem.HasSave());
|
|
}
|
|
|
|
[Test]
|
|
public void HasSave_ReturnsTrueAfterSave()
|
|
{
|
|
SaveSystem.Save(new SaveData { Currency = 100 });
|
|
|
|
Assert.IsTrue(SaveSystem.HasSave());
|
|
}
|
|
|
|
[Test]
|
|
public void Delete_RemovesSaveData()
|
|
{
|
|
SaveSystem.Save(new SaveData { Currency = 100 });
|
|
SaveSystem.Delete();
|
|
|
|
Assert.IsFalse(SaveSystem.HasSave());
|
|
}
|
|
|
|
[Test]
|
|
public void Load_CorruptJson_ReturnsDefault()
|
|
{
|
|
PlayerPrefs.SetString("YachtDice_SaveData", "{invalid json!!!");
|
|
PlayerPrefs.Save();
|
|
|
|
var loaded = SaveSystem.Load();
|
|
|
|
Assert.IsNotNull(loaded);
|
|
Assert.AreEqual(0, loaded.Currency);
|
|
}
|
|
}
|