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>
43 lines
999 B
C#
43 lines
999 B
C#
using Newtonsoft.Json;
|
|
using UnityEngine;
|
|
|
|
public static class SaveSystem
|
|
{
|
|
private const string SaveKey = "YachtDice_SaveData";
|
|
|
|
public static void Save(SaveData data)
|
|
{
|
|
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
|
|
PlayerPrefs.SetString(SaveKey, json);
|
|
PlayerPrefs.Save();
|
|
}
|
|
|
|
public static SaveData Load()
|
|
{
|
|
if (!PlayerPrefs.HasKey(SaveKey))
|
|
return new SaveData();
|
|
|
|
string json = PlayerPrefs.GetString(SaveKey);
|
|
|
|
try
|
|
{
|
|
return JsonConvert.DeserializeObject<SaveData>(json) ?? new SaveData();
|
|
}
|
|
catch (JsonException e)
|
|
{
|
|
Debug.LogWarning($"Failed to deserialize save data, returning default: {e.Message}");
|
|
return new SaveData();
|
|
}
|
|
}
|
|
|
|
public static void Delete()
|
|
{
|
|
PlayerPrefs.DeleteKey(SaveKey);
|
|
}
|
|
|
|
public static bool HasSave()
|
|
{
|
|
return PlayerPrefs.HasKey(SaveKey);
|
|
}
|
|
}
|