[Add] Universal modifier system, shop, inventory & persistence
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>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class ShopController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private ShopCatalog catalog;
|
||||
[SerializeField] private ShopView shopView;
|
||||
[SerializeField] private CurrencyBank currencyBank;
|
||||
|
||||
private ShopModel model;
|
||||
|
||||
public ShopCatalog Catalog => catalog;
|
||||
|
||||
public void Initialize(ShopModel shopModel)
|
||||
{
|
||||
model = shopModel;
|
||||
|
||||
shopView.OnBuyClicked += HandleBuyClicked;
|
||||
|
||||
if (currencyBank != null)
|
||||
currencyBank.OnBalanceChanged += HandleCurrencyChanged;
|
||||
|
||||
model.OnItemPurchased += HandleItemPurchased;
|
||||
|
||||
shopView.Populate(catalog.AvailableModifiers, model);
|
||||
shopView.UpdateCurrencyDisplay(currencyBank != null ? currencyBank.Balance : 0);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (shopView != null)
|
||||
shopView.OnBuyClicked -= HandleBuyClicked;
|
||||
|
||||
if (currencyBank != null)
|
||||
currencyBank.OnBalanceChanged -= HandleCurrencyChanged;
|
||||
|
||||
if (model != null)
|
||||
model.OnItemPurchased -= HandleItemPurchased;
|
||||
}
|
||||
|
||||
private void HandleBuyClicked(ModifierData data)
|
||||
{
|
||||
model.TryPurchase(data);
|
||||
}
|
||||
|
||||
private void HandleCurrencyChanged(int newBalance)
|
||||
{
|
||||
shopView.UpdateCurrencyDisplay(newBalance);
|
||||
shopView.RefreshStates(catalog.AvailableModifiers, model);
|
||||
}
|
||||
|
||||
private void HandleItemPurchased(ModifierData data)
|
||||
{
|
||||
shopView.RefreshStates(catalog.AvailableModifiers, model);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user