[Add] Dice & Refactor private names
This commit is contained in:
@@ -28,18 +28,18 @@ namespace YachtDice.UI
|
||||
private const int UpperBonusThreshold = 63;
|
||||
private const int UpperBonusValue = 35;
|
||||
|
||||
private GameManager gameManager;
|
||||
private ScoringSystem scoringSystem;
|
||||
private DiceManager diceManager;
|
||||
private CurrencyBank currencyBank;
|
||||
private ShopController shopController;
|
||||
private InventoryController inventoryController;
|
||||
private ModifierRegistry modifierRegistry;
|
||||
private CategoryCatalog categoryCatalog;
|
||||
private ModifierCatalog modifierCatalog;
|
||||
private DiceCatalog diceCatalog;
|
||||
private ShopModel shopModel;
|
||||
private PlayerModel playerModel;
|
||||
private GameManager _gameManager;
|
||||
private ScoringSystem _scoringSystem;
|
||||
private DiceManager _diceManager;
|
||||
private CurrencyBank _currencyBank;
|
||||
private ShopController _shopController;
|
||||
private InventoryController _inventoryController;
|
||||
private ModifierRegistry _modifierRegistry;
|
||||
private CategoryCatalog _categoryCatalog;
|
||||
private ModifierCatalog _modifierCatalog;
|
||||
private DiceCatalog _diceCatalog;
|
||||
private ShopModel _shopModel;
|
||||
private PlayerModel _playerModel;
|
||||
|
||||
[Inject]
|
||||
public void Construct(
|
||||
@@ -56,18 +56,18 @@ namespace YachtDice.UI
|
||||
ShopModel shopModel,
|
||||
PlayerModel playerModel)
|
||||
{
|
||||
this.gameManager = gameManager;
|
||||
this.scoringSystem = scoringSystem;
|
||||
this.diceManager = diceManager;
|
||||
this.currencyBank = currencyBank;
|
||||
this.shopController = shopController;
|
||||
this.inventoryController = inventoryController;
|
||||
this.modifierRegistry = modifierRegistry;
|
||||
this.categoryCatalog = categoryCatalog;
|
||||
this.modifierCatalog = modifierCatalog;
|
||||
this.diceCatalog = diceCatalog;
|
||||
this.shopModel = shopModel;
|
||||
this.playerModel = playerModel;
|
||||
this._gameManager = gameManager;
|
||||
this._scoringSystem = scoringSystem;
|
||||
this._diceManager = diceManager;
|
||||
this._currencyBank = currencyBank;
|
||||
this._shopController = shopController;
|
||||
this._inventoryController = inventoryController;
|
||||
this._modifierRegistry = modifierRegistry;
|
||||
this._categoryCatalog = categoryCatalog;
|
||||
this._modifierCatalog = modifierCatalog;
|
||||
this._diceCatalog = diceCatalog;
|
||||
this._shopModel = shopModel;
|
||||
this._playerModel = playerModel;
|
||||
}
|
||||
|
||||
// ── Lifecycle ──────────────────────────────────────────────
|
||||
@@ -75,11 +75,11 @@ namespace YachtDice.UI
|
||||
private void Start()
|
||||
{
|
||||
// Model → Controller
|
||||
gameManager.OnTurnStarted += HandleTurnStarted;
|
||||
gameManager.OnRollComplete += HandleRollComplete;
|
||||
gameManager.OnScored += HandleScored;
|
||||
gameManager.OnGameOver += HandleGameOver;
|
||||
diceManager.OnDiceSettled += HandleDiceSettled;
|
||||
_gameManager.OnTurnStarted += HandleTurnStarted;
|
||||
_gameManager.OnRollComplete += HandleRollComplete;
|
||||
_gameManager.OnScored += HandleScored;
|
||||
_gameManager.OnGameOver += HandleGameOver;
|
||||
_diceManager.OnDiceSettled += HandleDiceSettled;
|
||||
|
||||
// View → Controller
|
||||
scoreCardView.OnCategorySelected += HandleCategorySelected;
|
||||
@@ -90,25 +90,25 @@ namespace YachtDice.UI
|
||||
gameInfoView.OnInventoryClicked += HandleInventoryClicked;
|
||||
|
||||
// Currency & Player state
|
||||
currencyBank.OnBalanceChanged += HandleCurrencyChanged;
|
||||
playerModel.OnChanged += HandlePlayerChangedForSave;
|
||||
_currencyBank.OnBalanceChanged += HandleCurrencyChanged;
|
||||
_playerModel.OnChanged += HandlePlayerChangedForSave;
|
||||
|
||||
// Initialize
|
||||
scoreCardView.Initialize(categoryCatalog);
|
||||
scoreCardView.Initialize(_categoryCatalog);
|
||||
LoadSaveData();
|
||||
gameInfoView.SetCurrencyText(currencyBank.Balance);
|
||||
gameInfoView.SetCurrencyText(_currencyBank.Balance);
|
||||
|
||||
// Start the game after all subscriptions are in place
|
||||
gameManager.StartNewGame();
|
||||
_gameManager.StartNewGame();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
gameManager.OnTurnStarted -= HandleTurnStarted;
|
||||
gameManager.OnRollComplete -= HandleRollComplete;
|
||||
gameManager.OnScored -= HandleScored;
|
||||
gameManager.OnGameOver -= HandleGameOver;
|
||||
diceManager.OnDiceSettled -= HandleDiceSettled;
|
||||
_gameManager.OnTurnStarted -= HandleTurnStarted;
|
||||
_gameManager.OnRollComplete -= HandleRollComplete;
|
||||
_gameManager.OnScored -= HandleScored;
|
||||
_gameManager.OnGameOver -= HandleGameOver;
|
||||
_diceManager.OnDiceSettled -= HandleDiceSettled;
|
||||
|
||||
scoreCardView.OnCategorySelected -= HandleCategorySelected;
|
||||
dicePanelView.OnRollClicked -= HandleRollClicked;
|
||||
@@ -117,10 +117,10 @@ namespace YachtDice.UI
|
||||
gameInfoView.OnShopClicked -= HandleShopClicked;
|
||||
gameInfoView.OnInventoryClicked -= HandleInventoryClicked;
|
||||
|
||||
currencyBank.OnBalanceChanged -= HandleCurrencyChanged;
|
||||
_currencyBank.OnBalanceChanged -= HandleCurrencyChanged;
|
||||
|
||||
if (playerModel != null)
|
||||
playerModel.OnChanged -= HandlePlayerChangedForSave;
|
||||
if (_playerModel != null)
|
||||
_playerModel.OnChanged -= HandlePlayerChangedForSave;
|
||||
}
|
||||
|
||||
// ── Save / Load ─────────────────────────────────────────
|
||||
@@ -129,51 +129,51 @@ namespace YachtDice.UI
|
||||
{
|
||||
SaveData save = SaveSystem.Load();
|
||||
|
||||
if (save.Currency > 0)
|
||||
currencyBank.SetBalance(save.Currency);
|
||||
if (save.currency > 0)
|
||||
_currencyBank.SetBalance(save.currency);
|
||||
|
||||
if (modifierCatalog != null && save.OwnedModifiers.Count > 0)
|
||||
if (_modifierCatalog != null && save.ownedModifiers.Count > 0)
|
||||
{
|
||||
var entries = new List<ModifierSaveEntry>();
|
||||
var permanentIds = new HashSet<string>();
|
||||
|
||||
for (int i = 0; i < save.OwnedModifiers.Count; i++)
|
||||
for (int i = 0; i < save.ownedModifiers.Count; i++)
|
||||
{
|
||||
var oldEntry = save.OwnedModifiers[i];
|
||||
var def = modifierCatalog.FindById(oldEntry.ModifierId);
|
||||
var oldEntry = save.ownedModifiers[i];
|
||||
var def = _modifierCatalog.FindById(oldEntry.modifierId);
|
||||
|
||||
if (def == null)
|
||||
{
|
||||
Debug.LogWarning($"Modifier '{oldEntry.ModifierId}' not found in catalog, skipping.");
|
||||
Debug.LogWarning($"Modifier '{oldEntry.modifierId}' not found in catalog, skipping.");
|
||||
continue;
|
||||
}
|
||||
|
||||
entries.Add(new ModifierSaveEntry
|
||||
{
|
||||
ModifierId = oldEntry.ModifierId,
|
||||
IsActive = oldEntry.IsActive,
|
||||
RemainingUses = oldEntry.RemainingUses,
|
||||
Stacks = oldEntry.Stacks,
|
||||
CustomState = oldEntry.CustomState,
|
||||
modifierId = oldEntry.modifierId,
|
||||
isActive = oldEntry.isActive,
|
||||
remainingUses = oldEntry.remainingUses,
|
||||
stacks = oldEntry.stacks,
|
||||
customState = oldEntry.customState,
|
||||
});
|
||||
|
||||
if (!def.HasLimitedUses)
|
||||
permanentIds.Add(def.Id);
|
||||
}
|
||||
|
||||
modifierRegistry.LoadSaveData(entries, modifierCatalog);
|
||||
shopModel.LoadPurchasedPermanentIds(permanentIds);
|
||||
_modifierRegistry.LoadSaveData(entries, _modifierCatalog);
|
||||
_shopModel.LoadPurchasedPermanentIds(permanentIds);
|
||||
}
|
||||
|
||||
if (diceCatalog != null && save.OwnedDiceIds != null && save.OwnedDiceIds.Count > 0)
|
||||
if (_diceCatalog != null && save.ownedDiceIds != null && save.ownedDiceIds.Count > 0)
|
||||
{
|
||||
playerModel.Dice.LoadSaveData(save.OwnedDiceIds, diceCatalog);
|
||||
_playerModel.Dice.LoadSaveData(save.ownedDiceIds, _diceCatalog);
|
||||
|
||||
var dicePermIds = new HashSet<string>(save.OwnedDiceIds);
|
||||
var existingIds = shopModel.GetPurchasedPermanentIds();
|
||||
var dicePermIds = new HashSet<string>(save.ownedDiceIds);
|
||||
var existingIds = _shopModel.GetPurchasedPermanentIds();
|
||||
foreach (var id in dicePermIds)
|
||||
existingIds.Add(id);
|
||||
shopModel.LoadPurchasedPermanentIds(existingIds);
|
||||
_shopModel.LoadPurchasedPermanentIds(existingIds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,14 +181,14 @@ namespace YachtDice.UI
|
||||
{
|
||||
var save = new SaveData
|
||||
{
|
||||
Currency = currencyBank.Balance,
|
||||
OwnedDiceIds = playerModel.Dice.GetSaveData(),
|
||||
currency = _currencyBank.Balance,
|
||||
ownedDiceIds = _playerModel.Dice.GetSaveData(),
|
||||
};
|
||||
|
||||
var entries = modifierRegistry.GetSaveData();
|
||||
var entries = _modifierRegistry.GetSaveData();
|
||||
for (int i = 0; i < entries.Count; i++)
|
||||
{
|
||||
save.OwnedModifiers.Add(entries[i]);
|
||||
save.ownedModifiers.Add(entries[i]);
|
||||
}
|
||||
|
||||
SaveSystem.Save(save);
|
||||
@@ -198,7 +198,7 @@ namespace YachtDice.UI
|
||||
|
||||
private void HandleTurnStarted(int turn)
|
||||
{
|
||||
int totalCategoryCount = categoryCatalog.Count;
|
||||
int totalCategoryCount = _categoryCatalog.Count;
|
||||
gameInfoView.SetTurnText(turn, totalCategoryCount);
|
||||
dicePanelView.ResetForNewTurn();
|
||||
dicePanelView.SetRollButtonState(true, 0, maxRollsPerTurn);
|
||||
@@ -207,11 +207,11 @@ namespace YachtDice.UI
|
||||
|
||||
private void HandleRollComplete(int rollNumber)
|
||||
{
|
||||
bool canRollAgain = gameManager.CanRoll;
|
||||
bool canRollAgain = _gameManager.CanRoll;
|
||||
dicePanelView.SetRollButtonState(canRollAgain, rollNumber, maxRollsPerTurn);
|
||||
dicePanelView.SetDiceInteractable(true);
|
||||
|
||||
int[] values = diceManager.GetCurrentValues();
|
||||
int[] values = _diceManager.GetCurrentValues();
|
||||
dicePanelView.SetAllDiceValues(values);
|
||||
|
||||
UpdatePreviewScores();
|
||||
@@ -244,32 +244,32 @@ namespace YachtDice.UI
|
||||
|
||||
private void HandleRollClicked()
|
||||
{
|
||||
if (!gameManager.CanRoll) return;
|
||||
if (!_gameManager.CanRoll) return;
|
||||
|
||||
dicePanelView.SetRollButtonState(false, gameManager.CurrentRoll, maxRollsPerTurn);
|
||||
dicePanelView.SetRollButtonState(false, _gameManager.CurrentRoll, maxRollsPerTurn);
|
||||
dicePanelView.SetDiceInteractable(false);
|
||||
scoreCardView.SetAllInteractable(false);
|
||||
|
||||
gameManager.Roll();
|
||||
_gameManager.Roll();
|
||||
}
|
||||
|
||||
private void HandleDiceToggled(int index)
|
||||
{
|
||||
if (gameManager.CurrentRoll == 0) return;
|
||||
if (diceManager.IsAnyRolling) return;
|
||||
if (_gameManager.CurrentRoll == 0) return;
|
||||
if (_diceManager.IsAnyRolling) return;
|
||||
|
||||
gameManager.ToggleDiceLock(index);
|
||||
_gameManager.ToggleDiceLock(index);
|
||||
|
||||
bool isLocked = diceManager.IsLocked(index);
|
||||
bool isLocked = _diceManager.IsLocked(index);
|
||||
dicePanelView.SetDiceLocked(index, isLocked);
|
||||
}
|
||||
|
||||
private void HandleCategorySelected(CategoryDefinition category)
|
||||
{
|
||||
if (!gameManager.CanScore) return;
|
||||
if (scoringSystem.IsCategoryUsed(category)) return;
|
||||
if (!_gameManager.CanScore) return;
|
||||
if (_scoringSystem.IsCategoryUsed(category)) return;
|
||||
|
||||
gameManager.ScoreInCategory(category);
|
||||
_gameManager.ScoreInCategory(category);
|
||||
}
|
||||
|
||||
private void HandleNewGameClicked()
|
||||
@@ -277,17 +277,17 @@ namespace YachtDice.UI
|
||||
gameInfoView.HideGameOver();
|
||||
scoreCardView.ResetAll();
|
||||
dicePanelView.ResetForNewGame();
|
||||
gameManager.StartNewGame();
|
||||
_gameManager.StartNewGame();
|
||||
}
|
||||
|
||||
private void HandleShopClicked()
|
||||
{
|
||||
shopController.ToggleVisibility();
|
||||
_shopController.ToggleVisibility();
|
||||
}
|
||||
|
||||
private void HandleInventoryClicked()
|
||||
{
|
||||
inventoryController.ToggleVisibility();
|
||||
_inventoryController.ToggleVisibility();
|
||||
}
|
||||
|
||||
private void HandleCurrencyChanged(int newBalance)
|
||||
@@ -304,16 +304,16 @@ namespace YachtDice.UI
|
||||
|
||||
private void UpdatePreviewScores()
|
||||
{
|
||||
var dice = diceManager.GetDice();
|
||||
var dice = _diceManager.GetDice();
|
||||
var previews = new Dictionary<CategoryDefinition, int>();
|
||||
var allCategories = categoryCatalog.All;
|
||||
var allCategories = _categoryCatalog.All;
|
||||
|
||||
for (int i = 0; i < allCategories.Count; i++)
|
||||
{
|
||||
var cat = allCategories[i];
|
||||
if (scoringSystem.IsCategoryUsed(cat)) continue;
|
||||
if (_scoringSystem.IsCategoryUsed(cat)) continue;
|
||||
|
||||
ScoreResult result = scoringSystem.PreviewScore(dice, cat);
|
||||
ScoreResult result = _scoringSystem.PreviewScore(dice, cat);
|
||||
previews[cat] = result.FinalScore;
|
||||
}
|
||||
|
||||
@@ -332,13 +332,13 @@ namespace YachtDice.UI
|
||||
private int CalculateUpperSum()
|
||||
{
|
||||
int upperSum = 0;
|
||||
var allCategories = categoryCatalog.All;
|
||||
var allCategories = _categoryCatalog.All;
|
||||
|
||||
for (int i = 0; i < allCategories.Count; i++)
|
||||
{
|
||||
if (!allCategories[i].IsUpperSection) continue;
|
||||
|
||||
int catScore = scoringSystem.GetCategoryScore(allCategories[i]);
|
||||
int catScore = _scoringSystem.GetCategoryScore(allCategories[i]);
|
||||
if (catScore >= 0) upperSum += catScore;
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ namespace YachtDice.UI
|
||||
|
||||
private int CalculateDisplayTotal()
|
||||
{
|
||||
int total = scoringSystem.TotalScore;
|
||||
int total = _scoringSystem.TotalScore;
|
||||
int upperSum = CalculateUpperSum();
|
||||
|
||||
if (upperSum >= UpperBonusThreshold)
|
||||
|
||||
Reference in New Issue
Block a user