-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenderedTermLoader.cs
82 lines (65 loc) · 3.32 KB
/
GenderedTermLoader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GenderedTerms {
public class GenderedTermLoader : MonoBehaviour {
private FungusHelper fungusHelper;
public void Start() {
fungusHelper = FungusHelper.Instance;
// need to wait until Fungus populates the Global Variables after a scene load - this is done after Start()
// otherwise, our values could be overwritten by Fungus
StartCoroutine(UpdateAllGenderedTermVariablesAsync());
}
private IEnumerator UpdateAllGenderedTermVariablesAsync() {
// should do a more robust check of when the Global Variables have been populated, but this is sufficient
yield return new WaitForSeconds(0.1f);
UpdateAllGenderedTermVariables();
}
public void UpdateAllGenderedTermVariables() {
List<DynamicGenderCharacter> characters = DynamicGenderCharacterGameData.GetCharacters();
foreach (DynamicGenderCharacter character in characters) {
UpdateGenderedTermVariablesForCharacter(character);
}
}
private void UpdateGenderedTermVariablesForCharacter(DynamicGenderCharacter character) {
Pronoun? pronounOrNull = ReadPronounFromFungusVar(character.PronounVarName);
if (!pronounOrNull.HasValue) {
Debug.LogWarning("Unable to load Fungus variables for character: " + character.Name);
return;
}
Pronoun pronoun = pronounOrNull.Value;
Dictionary<GenderedTermType, string> genderedTermsByTermType = GenderedTermDictionary.GetGenderedTermsForPronoun(pronoun);
foreach (KeyValuePair<GenderedTermType, string> gameScriptVarNamePair in character.GameScriptVarNames) {
GenderedTermType termType = gameScriptVarNamePair.Key;
string gameScriptVarName = gameScriptVarNamePair.Value;
string genderedTerm;
if (!genderedTermsByTermType.TryGetValue(termType, out genderedTerm)) {
Debug.LogWarning("Unknown gendered term type \"" + termType.ToString() + "\" for " + character.Name + "not in dictionary.");
continue;
}
// check if we need to capitalize this gendered term
if (gameScriptVarName.Contains(DynamicGenderCharacterGameData.CAP_SUFFIX)) {
genderedTerm = CapitalizeString(genderedTerm);
}
fungusHelper.UpdateVariable(gameScriptVarName, genderedTerm);
}
}
private Pronoun? ReadPronounFromFungusVar(string varName) {
string pronounString = fungusHelper.GetVariable(varName);
if (pronounString == null) {
Debug.LogWarning("Pronoun variable \"" + varName + "\" not found in global variables.");
return null;
}
try {
return PronounParser.FromString(pronounString);
} catch (ArgumentException) {
Debug.LogError("Unsupported pronoun: \"" + pronounString + "\".");
return null;
}
}
private static string CapitalizeString(string value) {
return char.ToUpper(value[0]) + value.Substring(1);
}
}
}