Skip to content

Commit

Permalink
Read Mage Light example strings from CSV
Browse files Browse the repository at this point in the history
Master CSV file provided.
  • Loading branch information
Interkarma committed Oct 11, 2023
1 parent 909d1c5 commit 3a251d1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 11 deletions.
75 changes: 64 additions & 11 deletions Assets/Scripts/Game/MagicAndEffects/Effects/Illusion/MageLight.cs
Expand Up @@ -14,6 +14,7 @@
using DaggerfallConnect.Arena2;
using DaggerfallWorkshop.Utility;
using DaggerfallWorkshop.Game.Entity;
using System.Collections.Generic;

namespace DaggerfallWorkshop.Game.MagicAndEffects.MagicEffects
{
Expand All @@ -38,6 +39,7 @@ public class MageLight : IncumbentEffect
new Color32(101, 137, 120, 255) // Arcane
};

Dictionary<string, string> stringTable = null;
Light myLight = null;
VariantProperties[] variantProperties = new VariantProperties[totalVariants];

Expand Down Expand Up @@ -76,6 +78,16 @@ public override EffectProperties Properties

#endregion

#region Construtors

public MageLight()
{
// Attempt to import replacement text from CSV
LoadText();
}

#endregion

#region Overrides

public override void SetProperties()
Expand Down Expand Up @@ -211,32 +223,73 @@ void SetVariantProperties(VariantTypes variant)

#region Text

// Text strings are hardcoded in this example effect
// They could also be sourced from text tables or any other text API/method accessible to the game/mod

const string groupName = "Mage Light";
// Default strings
string groupName = "Mage Light";
string[] subGroupNames = { "Inferno", "Rime", "Venom", "Storm", "Arcane" };
const string effectDescription = "Creates a soft light around caster.";
string effectDescription = "Creates a soft light around caster.";
string durationSpellMaker = "Duration: Rounds you will be illuminated.";
string durationSpellBook = "Duration: %bdr + %adr per %cld level(s)";
string chanceText = "Chance: N/A";
string magnitudeText = "Magnitude: N/A";

/// <summary>
/// Try to load replacement text from a CSV in StreamingAssets/Text if one is provided.
/// Spell templates are read and stored in multiple places so CSV could be loaded multiple times.
/// CSV will also be loaded anytime spell is instantiated or text required.
/// For a more sophisticated setup use a centralised text database and only load text once.
/// </summary>
void LoadText()
{
const string csvFilename = "Example_MageLight.csv";

if (stringTable != null)
return;

stringTable = StringTableCSVParser.LoadDictionary(csvFilename);
if (stringTable == null || stringTable.Count == 0)
return;

if (stringTable.ContainsKey("groupName"))
groupName = stringTable["groupName"];

if (stringTable.ContainsKey("subGroupNames"))
subGroupNames = TextManager.Instance.SplitTextList(stringTable["subGroupNames"]);

if (stringTable.ContainsKey("effectDescription"))
effectDescription = stringTable["effectDescription"];

if (stringTable.ContainsKey("durationSpellMaker"))
durationSpellMaker = stringTable["durationSpellMaker"];

if (stringTable.ContainsKey("durationSpellBook"))
durationSpellBook = stringTable["durationSpellBook"];

if (stringTable.ContainsKey("chance"))
chanceText = stringTable["chance"];

if (stringTable.ContainsKey("magnitude"))
magnitudeText = stringTable["magnitude"];
}

TextFile.Token[] GetSpellMakerDescription()
{
return DaggerfallUnity.Instance.TextProvider.CreateTokens(
TextFile.Formatting.JustifyCenter,
groupName,
effectDescription,
"Duration: Rounds you will be illuminated.",
"Chance: N/A",
"Magnitude: N/A");
durationSpellMaker,
chanceText,
magnitudeText);
}

TextFile.Token[] GetSpellBookDescription()
{
return DaggerfallUnity.Instance.TextProvider.CreateTokens(
TextFile.Formatting.JustifyCenter,
groupName,
"Duration: %bdr + %adr per %cld level(s)",
"Chance: N/A",
"Magnitude: N/A",
durationSpellBook,
chanceText,
magnitudeText,
effectDescription);
}

Expand Down
@@ -0,0 +1,13 @@
Key,Value
about,This CSV provides text records for the example custom spell MageLight.
groupName,Mage Light
subGroupNames,"Inferno
Rime
Venom
Storm
Arcane"
effectDescription,Creates a soft light around caster.
durationSpellMaker,Duration: Rounds you will be illuminated.
durationSpellBook,Duration: %bdr + %adr per %cld level(s)
chance,Chance: N/A
magnitude,Magnitude: N/A

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a251d1

Please sign in to comment.