Skip to content

Commit

Permalink
Fix lookup issue for localized quest name
Browse files Browse the repository at this point in the history
Localized quest name is now stored properly in live quest instance.
Fixed issue where subsequent lookup would not return localized quest name due to wrong key.
  • Loading branch information
Interkarma committed Oct 9, 2023
1 parent 25a77ee commit e914214
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions Assets/Scripts/Game/Questing/QuestMachine.cs
Expand Up @@ -20,6 +20,7 @@
using DaggerfallWorkshop.Game.Questing.Actions;
using DaggerfallWorkshop.Game.Serialization;
using UnityEngine.Localization.Settings;
using System.Globalization;

namespace DaggerfallWorkshop.Game.Questing
{
Expand Down Expand Up @@ -60,6 +61,12 @@ public class QuestMachine : MonoBehaviour
const string diseasesTableFileName = "Quests-Diseases";
const string spellsTableFileName = "Quests-Spells";

// Localization
const string localizedFilenameSuffix = "-LOC";
const string fileExtension = ".txt";
const string textFolderName = "Text";
const string questsFolderName = "Quests";

// Data tables
Table globalVarsTable;
Table staticMessagesTable;
Expand Down Expand Up @@ -665,8 +672,9 @@ public Quest ParseQuest(string questName, string[] questSource, int factionId =
Parser parser = new Parser();
Quest quest = parser.Parse(questSource, factionId, partialParse);

// Parse localized version of quest file (if present)
ParseLocalizedQuestText(questName);
// Parse localized version of quest file (if present) and store display name in quest
if (ParseLocalizedQuestText(questName))
quest.DisplayName = GetLocalizedQuestDisplayName(questName);

return quest;
}
Expand Down Expand Up @@ -1582,6 +1590,15 @@ public void SetStoredExceptions(StoredException[] exceptions)
/// <returns>Localized name of quest if found, otherwise string.Empty.</returns>
public string GetLocalizedQuestDisplayName(string questName)
{
// Remove ".txt" file extension from quest name if present
if (questName.EndsWith(fileExtension, false, CultureInfo.InvariantCulture))
questName = questName.Substring(0, questName.Length - fileExtension.Length);

// Return quest name if already parsed
if (localizedQuestNames.ContainsKey(questName))
return localizedQuestNames[questName];

// Try to parse and return name or empty string on failure
return ParseLocalizedQuestText(questName) ? localizedQuestNames[questName] : string.Empty;
}

Expand Down Expand Up @@ -1619,11 +1636,6 @@ bool RemoveQuestSiteLink(ulong questUID)
/// <returns>True if localized text was loaded, otherwise false.</returns>
bool ParseLocalizedQuestText(string questName)
{
const string localizedFilenameSuffix = "-LOC";
const string fileExtension = ".txt";
const string textFolderName = "Text";
const string questsFolderName = "Quests";

// Compose filename of localized quest
string filename = questName;
string fileNoExt = Path.GetFileNameWithoutExtension(filename);
Expand Down

0 comments on commit e914214

Please sign in to comment.