using System; using System.Collections.Generic; using System.ComponentModel; using TMPro; using UnityEngine; using static Dice; /// <summary> /// Handles listing the modifiers occurring in the dice roll /// </summary> public class DiceModifierConnector : MonoBehaviour { [Header("Text Fields")] [SerializeField] private TextMeshProUGUI nameTextField; // Reference to the text area that lists the name of the modifier [SerializeField] private TextMeshProUGUI valueTextField; // Reference to the text area that lists the dice or values [SerializeField] private TextMeshProUGUI typeTextField; // Refernece to the text area that indicates what type of damage is being inflicted public void InjectName(string name) => nameTextField.text = name; public void InjectValue(string value) => valueTextField.text = value; public void InjectDice(params DiceR[] dices) { valueTextField.text = string.Empty; Dictionary<DiceR, int> diceValues = new Dictionary<DiceR, int>() { { DiceR.Four, 0 }, { DiceR.Six, 0 }, { DiceR.Eight, 0 }, { DiceR.Ten, 0 }, { DiceR.Twelve, 0 }, { DiceR.Twenty, 0 } }; foreach (DiceR dice in dices) diceValues[dice] += 1; int counter = 1; foreach (KeyValuePair<DiceR, int> diceDataPiece in diceValues) { if (diceDataPiece.Value is not 0) { switch ((int)diceDataPiece.Key) { case 0: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D4"; else valueTextField.text += $"{diceDataPiece.Value}D4\n"; break; case 1: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D6"; else valueTextField.text += $"{diceDataPiece.Value}D6\n"; break; case 2: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D8"; else valueTextField.text += $"{diceDataPiece.Value}D8\n"; break; case 3: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D10"; else valueTextField.text += $"{diceDataPiece.Value}D10\n"; break; case 4: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D12"; else valueTextField.text += $"{diceDataPiece.Value}D12\n"; break; case 5: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D20"; else valueTextField.text += $"{diceDataPiece.Value}D20\n"; break; default: valueTextField.text += $"Error"; break; } } ++counter; } } public void InjectDice(params Dice[] dices) { valueTextField.text = string.Empty; Dictionary<Dice, int> diceValues = new Dictionary<Dice, int>() { { new DFour(), 0 }, { new DSix(), 0 }, { new DEight(), 0 }, { new DTen(), 0 }, { new DTwelve(), 0 }, { new DTwenty(), 0 } }; foreach (Dice dice in dices) diceValues[dice] += 1; int counter = 1; foreach (KeyValuePair<Dice, int> diceDataPiece in diceValues) { if (diceDataPiece.Value is not 0) { switch (diceDataPiece.Key.Sides) { case 4: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D4"; else valueTextField.text += $"{diceDataPiece.Value}D4\n"; break; case 6: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D6"; else valueTextField.text += $"{diceDataPiece.Value}D6\n"; break; case 8: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D8"; else valueTextField.text += $"{diceDataPiece.Value}D8\n"; break; case 10: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D10"; else valueTextField.text += $"{diceDataPiece.Value}D10\n"; break; case 12: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D12"; else valueTextField.text += $"{diceDataPiece.Value}D12\n"; break; case 20: if (counter == diceValues.Count) valueTextField.text += $"{diceDataPiece.Value}D20"; else valueTextField.text += $"{diceDataPiece.Value}D20\n"; break; default: valueTextField.text += $"Error"; break; } } ++counter; } } public void InjectType(object type) { if (type is SpellSO.Element element) { typeTextField.text = element switch { SpellSO.Element.Normal => "Normal", SpellSO.Element.Fire => "Fire", SpellSO.Element.Water => "Water", SpellSO.Element.Earth => "Earth", SpellSO.Element.Poison => "Poison", SpellSO.Element.Ice => "Ice", SpellSO.Element.Wind => "Wind", SpellSO.Element.Darkness => "Darkness", SpellSO.Element.Light => "Light", SpellSO.Element.Necro => "Necrotic", SpellSO.Element.Strange => "Strange", SpellSO.Element.Energy => "Energy", _ => throw new InvalidEnumArgumentException(), }; } else if (type is WeaponSO.Type weaponType) { typeTextField.text = weaponType switch { WeaponSO.Type.Sharp => "Sharp", WeaponSO.Type.Blunt => "Blunt", WeaponSO.Type.Ranged => "Ranged", WeaponSO.Type.Magic => "Magic", WeaponSO.Type.Extended => "Extended", WeaponSO.Type.Firearm => "Firearm", WeaponSO.Type.None => "Error", _ => throw new InvalidEnumArgumentException(), }; } else throw new TypeLoadException(); } public void DeactivateTypeInfo() => typeTextField.enabled = false; }