[Add] Dice & Refactor private names
This commit is contained in:
@@ -11,18 +11,18 @@ namespace YachtDice.Inventory
|
||||
{
|
||||
[SerializeField] private InventoryView inventoryView;
|
||||
|
||||
private InventoryModel model;
|
||||
private ScoringSystem scoringSystem;
|
||||
private CurrencyBank currencyBank;
|
||||
private InventoryModel _model;
|
||||
private ScoringSystem _scoringSystem;
|
||||
private CurrencyBank _currencyBank;
|
||||
|
||||
public InventoryModel Model => model;
|
||||
public InventoryModel Model => _model;
|
||||
|
||||
[Inject]
|
||||
public void Construct(InventoryModel model, ScoringSystem scoringSystem, CurrencyBank currencyBank)
|
||||
{
|
||||
this.model = model;
|
||||
this.scoringSystem = scoringSystem;
|
||||
this.currencyBank = currencyBank;
|
||||
this._model = model;
|
||||
this._scoringSystem = scoringSystem;
|
||||
this._currencyBank = currencyBank;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -31,8 +31,8 @@ namespace YachtDice.Inventory
|
||||
inventoryView.OnDeactivateClicked += HandleDeactivate;
|
||||
inventoryView.OnSellClicked += HandleSell;
|
||||
|
||||
model.OnInventoryChanged += HandleInventoryChanged;
|
||||
scoringSystem.OnCategoryConfirmed += HandleCategoryConfirmed;
|
||||
_model.OnInventoryChanged += HandleInventoryChanged;
|
||||
_scoringSystem.OnCategoryConfirmed += HandleCategoryConfirmed;
|
||||
|
||||
RefreshView();
|
||||
}
|
||||
@@ -46,11 +46,11 @@ namespace YachtDice.Inventory
|
||||
inventoryView.OnSellClicked -= HandleSell;
|
||||
}
|
||||
|
||||
if (model != null)
|
||||
model.OnInventoryChanged -= HandleInventoryChanged;
|
||||
if (_model != null)
|
||||
_model.OnInventoryChanged -= HandleInventoryChanged;
|
||||
|
||||
if (scoringSystem != null)
|
||||
scoringSystem.OnCategoryConfirmed -= HandleCategoryConfirmed;
|
||||
if (_scoringSystem != null)
|
||||
_scoringSystem.OnCategoryConfirmed -= HandleCategoryConfirmed;
|
||||
}
|
||||
|
||||
public void ToggleVisibility()
|
||||
@@ -65,12 +65,12 @@ namespace YachtDice.Inventory
|
||||
|
||||
private void HandleActivate(ModifierInstance instance)
|
||||
{
|
||||
model.TryActivate(instance);
|
||||
_model.TryActivate(instance);
|
||||
}
|
||||
|
||||
private void HandleDeactivate(ModifierInstance instance)
|
||||
{
|
||||
model.Deactivate(instance);
|
||||
_model.Deactivate(instance);
|
||||
}
|
||||
|
||||
private void HandleSell(ModifierInstance instance)
|
||||
@@ -78,10 +78,10 @@ namespace YachtDice.Inventory
|
||||
if (instance.Definition == null) return;
|
||||
|
||||
int sellPrice = instance.Definition.SellPrice;
|
||||
model.RemoveModifier(instance);
|
||||
_model.RemoveModifier(instance);
|
||||
|
||||
if (currencyBank != null)
|
||||
currencyBank.Add(sellPrice);
|
||||
if (_currencyBank != null)
|
||||
_currencyBank.Add(sellPrice);
|
||||
}
|
||||
|
||||
private void HandleInventoryChanged()
|
||||
@@ -91,13 +91,13 @@ namespace YachtDice.Inventory
|
||||
|
||||
private void HandleCategoryConfirmed(CategoryDefinition category, ScoreResult result)
|
||||
{
|
||||
model.ConsumeUseOnActive();
|
||||
_model.ConsumeUseOnActive();
|
||||
}
|
||||
|
||||
private void RefreshView()
|
||||
{
|
||||
if (inventoryView != null && model != null)
|
||||
inventoryView.Refresh(model.OwnedModifiers, model.MaxActiveSlots);
|
||||
if (inventoryView != null && _model != null)
|
||||
inventoryView.Refresh(_model.OwnedModifiers, _model.MaxActiveSlots);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,39 +7,39 @@ namespace YachtDice.Inventory
|
||||
{
|
||||
public class InventoryModel
|
||||
{
|
||||
private readonly ModifierRegistry registry;
|
||||
private readonly ModifierRegistry _registry;
|
||||
|
||||
public event Action OnInventoryChanged;
|
||||
public event Action<IReadOnlyList<ModifierInstance>> OnActiveModifiersChanged;
|
||||
|
||||
public InventoryModel(ModifierRegistry registry)
|
||||
{
|
||||
this.registry = registry;
|
||||
this._registry = registry;
|
||||
|
||||
registry.OnChanged += () => OnInventoryChanged?.Invoke();
|
||||
registry.OnActiveModifiersChanged += list => OnActiveModifiersChanged?.Invoke(list);
|
||||
}
|
||||
|
||||
public IReadOnlyList<ModifierInstance> OwnedModifiers => registry.All;
|
||||
public int MaxActiveSlots => registry.MaxActiveSlots;
|
||||
public int ActiveCount => registry.ActiveCount;
|
||||
public IReadOnlyList<ModifierInstance> OwnedModifiers => _registry.All;
|
||||
public int MaxActiveSlots => _registry.MaxActiveSlots;
|
||||
public int ActiveCount => _registry.ActiveCount;
|
||||
|
||||
public void SetMaxActiveSlots(int slots) => registry.SetMaxActiveSlots(slots);
|
||||
public void SetMaxActiveSlots(int slots) => _registry.SetMaxActiveSlots(slots);
|
||||
|
||||
public void AddModifier(ModifierDefinition definition) => registry.Add(definition);
|
||||
public void AddModifier(ModifierDefinition definition) => _registry.Add(definition);
|
||||
|
||||
public void RemoveModifier(ModifierInstance instance) => registry.Remove(instance);
|
||||
public void RemoveModifier(ModifierInstance instance) => _registry.Remove(instance);
|
||||
|
||||
public bool TryActivate(ModifierInstance instance) => registry.TryActivate(instance);
|
||||
public bool TryActivate(ModifierInstance instance) => _registry.TryActivate(instance);
|
||||
|
||||
public void Deactivate(ModifierInstance instance) => registry.Deactivate(instance);
|
||||
public void Deactivate(ModifierInstance instance) => _registry.Deactivate(instance);
|
||||
|
||||
public void ConsumeUseOnActive() => registry.ConsumeChargesOnActive();
|
||||
public void ConsumeUseOnActive() => _registry.ConsumeChargesOnActive();
|
||||
|
||||
public List<ModifierDefinition> GetActiveModifierDefinitions()
|
||||
{
|
||||
var result = new List<ModifierDefinition>();
|
||||
var active = registry.Active;
|
||||
var active = _registry.Active;
|
||||
for (int i = 0; i < active.Count; i++)
|
||||
result.Add(active[i].Definition);
|
||||
return result;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace YachtDice.Inventory
|
||||
[SerializeField] private Color activeColor = new(0.7f, 1f, 0.7f);
|
||||
[SerializeField] private Color inactiveColor = Color.white;
|
||||
|
||||
private ModifierInstance instance;
|
||||
private ModifierInstance _instance;
|
||||
|
||||
public event Action<ModifierInstance> OnActivateClicked;
|
||||
public event Action<ModifierInstance> OnDeactivateClicked;
|
||||
@@ -31,17 +31,17 @@ namespace YachtDice.Inventory
|
||||
private void Awake()
|
||||
{
|
||||
if (activateButton != null)
|
||||
activateButton.onClick.AddListener(() => OnActivateClicked?.Invoke(instance));
|
||||
activateButton.onClick.AddListener(() => OnActivateClicked?.Invoke(_instance));
|
||||
if (deactivateButton != null)
|
||||
deactivateButton.onClick.AddListener(() => OnDeactivateClicked?.Invoke(instance));
|
||||
deactivateButton.onClick.AddListener(() => OnDeactivateClicked?.Invoke(_instance));
|
||||
if (sellButton != null)
|
||||
sellButton.onClick.AddListener(() => OnSellClicked?.Invoke(instance));
|
||||
sellButton.onClick.AddListener(() => OnSellClicked?.Invoke(_instance));
|
||||
}
|
||||
|
||||
public void Setup(ModifierInstance modifierInstance, bool canActivateMore)
|
||||
{
|
||||
instance = modifierInstance;
|
||||
var def = instance.Definition;
|
||||
_instance = modifierInstance;
|
||||
var def = _instance.Definition;
|
||||
|
||||
if (def == null) return;
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace YachtDice.Inventory
|
||||
if (def.HasLimitedUses)
|
||||
{
|
||||
usesText.gameObject.SetActive(true);
|
||||
usesText.text = $"{instance.RemainingUses}/{def.MaxUses}";
|
||||
usesText.text = $"{_instance.RemainingUses}/{def.MaxUses}";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -64,7 +64,7 @@ namespace YachtDice.Inventory
|
||||
|
||||
if (sellPriceText != null) sellPriceText.text = def.SellPrice.ToString();
|
||||
|
||||
bool isActive = instance.IsActive;
|
||||
bool isActive = _instance.IsActive;
|
||||
|
||||
if (activateButton != null)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace YachtDice.Inventory
|
||||
[SerializeField] private TMP_Text slotCountText;
|
||||
[SerializeField] private Button closeButton;
|
||||
|
||||
private readonly List<InventorySlotView> spawnedSlots = new();
|
||||
private readonly List<InventorySlotView> _spawnedSlots = new();
|
||||
|
||||
public event Action<ModifierInstance> OnActivateClicked;
|
||||
public event Action<ModifierInstance> OnDeactivateClicked;
|
||||
@@ -52,7 +52,7 @@ namespace YachtDice.Inventory
|
||||
slot.OnActivateClicked += HandleActivate;
|
||||
slot.OnDeactivateClicked += HandleDeactivate;
|
||||
slot.OnSellClicked += HandleSell;
|
||||
spawnedSlots.Add(slot);
|
||||
_spawnedSlots.Add(slot);
|
||||
}
|
||||
|
||||
if (slotCountText != null)
|
||||
@@ -61,14 +61,14 @@ namespace YachtDice.Inventory
|
||||
|
||||
private void ClearSlots()
|
||||
{
|
||||
for (int i = 0; i < spawnedSlots.Count; i++)
|
||||
for (int i = 0; i < _spawnedSlots.Count; i++)
|
||||
{
|
||||
spawnedSlots[i].OnActivateClicked -= HandleActivate;
|
||||
spawnedSlots[i].OnDeactivateClicked -= HandleDeactivate;
|
||||
spawnedSlots[i].OnSellClicked -= HandleSell;
|
||||
Destroy(spawnedSlots[i].gameObject);
|
||||
_spawnedSlots[i].OnActivateClicked -= HandleActivate;
|
||||
_spawnedSlots[i].OnDeactivateClicked -= HandleDeactivate;
|
||||
_spawnedSlots[i].OnSellClicked -= HandleSell;
|
||||
Destroy(_spawnedSlots[i].gameObject);
|
||||
}
|
||||
spawnedSlots.Clear();
|
||||
_spawnedSlots.Clear();
|
||||
}
|
||||
|
||||
private void HandleActivate(ModifierInstance inst) => OnActivateClicked?.Invoke(inst);
|
||||
|
||||
Reference in New Issue
Block a user