Skip to content

Commit 466719d

Browse files
committed
Pango update
Code update as recommended by Pango.
1 parent 024f013 commit 466719d

9 files changed

Lines changed: 24 additions & 28 deletions

File tree

Assets/Scripts/API/Save/CharacterRecord.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using DaggerfallWorkshop.Game.Entity;
1919
using DaggerfallWorkshop.Game.Formulas;
2020
using DaggerfallWorkshop;
21-
using DaggerfallWorkshop.Localization;
2221

2322
namespace DaggerfallConnect.Save
2423
{
@@ -175,7 +174,6 @@ void ReadCharacterData()
175174
parsedData.currentStats = ReadStats(reader);
176175
parsedData.baseStats = ReadStats(reader);
177176
parsedData.gender = ReadGender(reader);
178-
GrammarManager.grammarProcessor.SetHeroGender(parsedData.gender);
179177
parsedData.transportationFlags = ReadTransportationFlags(reader);
180178
parsedData.minMetalToHit = reader.ReadByte();
181179
parsedData.race = ReadRace(reader);

Assets/Scripts/Game/Questing/Person.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public override void SetResource(string line)
230230
if (careerAllianceGroup.Success)
231231
careerAllianceName = careerAllianceGroup.Value;
232232

233-
// Gender
233+
// GenderNums
234234
Group genderGroup = option.Groups["gender"];
235235
if (genderGroup.Success)
236236
genderName = genderGroup.Value;
@@ -294,10 +294,8 @@ public override bool ExpandMacro(MacroTypes macro, out string textOut)
294294
// This will be used for subsequent pronoun macros, etc.
295295
ParentQuest.LastResourceReferenced = this;
296296

297-
// Send the person's genre to grammar processor
298-
if (ParentQuest.LastResourceReferenced == null)
299-
GrammarManager.grammarProcessor.SetNPCGender(Genders.Male);
300-
else GrammarManager.grammarProcessor.SetNPCGender(ParentQuest.LastResourceReferenced.Gender);
297+
// Send the person's gender to the grammar processor
298+
GrammarManager.grammarProcessor.SetNPCGenderGetter(() => ParentQuest.LastResourceReferenced?.Gender ?? Genders.Male);
301299

302300
Place dialogPlace = GetDialogPlace();
303301
if (dialogPlace != null)

Assets/Scripts/Game/Serialization/SerializablePlayer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using System.Linq;
1919
using DaggerfallWorkshop.Game.Items;
2020
using DaggerfallConnect.Arena2;
21-
using DaggerfallWorkshop.Localization;
2221

2322
namespace DaggerfallWorkshop.Game.Serialization
2423
{
@@ -275,7 +274,6 @@ public void RestoreSaveData(object dataIn)
275274
PlayerEntity entity = playerEntityBehaviour.Entity as PlayerEntity;
276275

277276
entity.Gender = data.playerEntity.gender;
278-
GrammarManager.grammarProcessor.SetHeroGender(entity.Gender);
279277
entity.BirthRaceTemplate = data.playerEntity.raceTemplate;
280278
entity.FaceIndex = data.playerEntity.faceIndex;
281279
entity.Reflexes = data.playerEntity.reflexes;

Assets/Scripts/Game/TextManager.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,9 @@ private string GetDefaultCollectionName(TextCollections collection)
357357
public string GetLocalizedText(string key, TextCollections collection = TextCollections.Internal, bool exception = false)
358358
{
359359
string localizedText;
360-
string processedLocalizedText;
361360
if (TryGetLocalizedText(GetRuntimeCollectionName(collection), key, out localizedText))
362361
{
363-
processedLocalizedText = GrammarManager.grammarProcessor.ProcessGrammar(localizedText);
364-
return processedLocalizedText;
362+
return GrammarManager.grammarProcessor.ProcessGrammar(localizedText);
365363
}
366364
else if (TryGetLocalizedText(GetDefaultCollectionName(collection), key, out localizedText))
367365
return localizedText;

Assets/Scripts/Game/UserInterfaceWindows/CreateCharGenderSelect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ protected override void Setup()
6060
void MaleButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
6161
{
6262
SelectedGender = Genders.Male;
63-
GrammarManager.grammarProcessor.SetHeroGender(SelectedGender);
63+
GrammarManager.grammarProcessor.SetHeroGenderGetter(() => Genders.Male);
6464
CloseWindow();
6565
}
6666

6767
void FemaleButton_OnMouseClick(BaseScreenComponent sender, Vector2 position)
6868
{
6969
SelectedGender = Genders.Female;
70-
GrammarManager.grammarProcessor.SetHeroGender(SelectedGender);
70+
GrammarManager.grammarProcessor.SetHeroGenderGetter(() => Genders.Female);
7171
CloseWindow();
7272
}
7373

Assets/Scripts/Game/UserInterfaceWindows/DaggerfallTalkWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ protected virtual void SetQuestionAnswerPairInConversationListbox(string questio
12651265
textLabelQuestion.textLabel.MaxWidth = (int)(textLabelQuestion.textLabel.MaxWidth * textBlockSizeModernConversationStyle);
12661266
textLabelQuestion.textLabel.BackgroundColor = textcolorQuestionBackgroundModernConversationStyle;
12671267
}
1268-
listboxConversation.AddItem(GrammarManager.grammarProcessor.ProcessGrammar(answer), out textLabelAnswer);
1268+
listboxConversation.AddItem(GrammarManager.grammarProcessor.ProcessGrammar(answer), out textLabelAnswer);
12691269
textLabelAnswer.selectedTextColor = textcolorHighlighted;
12701270
textLabelAnswer.textLabel.HorizontalAlignment = HorizontalAlignment.Left;
12711271
textLabelAnswer.textLabel.HorizontalTextAlignment = TextLabel.HorizontalTextAlignmentSetting.Left;

Assets/Scripts/Game/Utility/StartGameBehaviour.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using DaggerfallWorkshop.Game.Questing;
2626
using DaggerfallWorkshop.Game.MagicAndEffects;
2727
using DaggerfallWorkshop.Game.MagicAndEffects.MagicEffects;
28+
using DaggerfallWorkshop.Localization;
2829

2930
namespace DaggerfallWorkshop.Game.Utility
3031
{
@@ -142,6 +143,9 @@ void InvokeStartMethod()
142143
// This mainly just prevents all SongPlayers from starting at once
143144
GameManager.Instance.PlayerEnterExit.DisableAllParents();
144145

146+
// Provide hero's gender to the grammar processor
147+
GrammarManager.grammarProcessor.SetHeroGenderGetter(() => GameManager.Instance.PlayerEntity.Gender);
148+
145149
switch (StartMethod)
146150
{
147151
case StartMethods.Void:

Assets/Scripts/Localization/DefaultGrammarRules.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
using DaggerfallWorkshop.Game.Entity;
10+
using System;
1011

1112
namespace DaggerfallWorkshop.Localization.LanguageRules
1213
{
@@ -17,20 +18,18 @@ public override string ProcessGrammar(string text)
1718
// Process the grammar tokens
1819
return text;
1920
}
20-
21-
public override void SetHeroGender(Genders Gender)
22-
{
23-
// Locally store the genre of the hero so that it can be used
21+
public override void SetHeroGenderGetter(Func<Genders> HeroGenderGetter)
22+
{
23+
// Provide access to the genre of the hero so that it can be used
2424
// by the grammar tokens
2525

2626
}
27-
28-
public override void SetNPCGender(Genders Gender)
29-
{
30-
// Locally store the genre of a NPC so that it can be used
27+
public override void SetNPCGenderGetter(Func<Genders> NPCGenderGetter)
28+
{
29+
// Provide access to the genre of a NPC so that it can be used
3130
// by the grammar tokens
3231

33-
}
34-
}
32+
}
33+
}
3534
}
3635

Assets/Scripts/Localization/Grammar.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88

99
using DaggerfallWorkshop.Game.Entity;
1010
using DaggerfallWorkshop.Localization.LanguageRules;
11+
using System;
1112

1213
namespace DaggerfallWorkshop.Localization
1314
{
1415
public abstract class GrammarRules
1516
{
1617
public abstract string ProcessGrammar(string text);
17-
public abstract void SetHeroGender(Genders Gender);
18-
public abstract void SetNPCGender(Genders Gender);
18+
public abstract void SetHeroGenderGetter(Func<Genders> HeroGenderGetter);
19+
public abstract void SetNPCGenderGetter(Func<Genders> NPCGenderGetter);
1920
}
2021

2122
public static class GrammarManager
2223
{
23-
public static GrammarRules grammarProcessor = (GrammarRules) new DefaultGrammarRules();
24+
public static GrammarRules grammarProcessor = new DefaultGrammarRules();
2425
}
2526
}
2627

0 commit comments

Comments
 (0)