Skip to content

Commit

Permalink
Improvements over localization data.
Browse files Browse the repository at this point in the history
  • Loading branch information
isadorasophia committed Dec 8, 2023
1 parent f43ba6a commit db51afc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Murder.Editor/CustomEditors/CharacterEditor_Dialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void DrawLines(ScriptInformation info, Dialog dialog)
if (line.Text is not null)
{
// Centralizes the text vertically.
string value = LocalizationServices.GetLocalizedString(line.Text);
string value = LocalizationServices.GetLocalizedString(line.Text.Value);

float textHeight = (ImGui.GetItemRectSize().Y -
ImGui.CalcTextSize(value, wrapWidth: ImGui.GetWindowContentRegionMax().X - ImGui.GetCursorPosX()).Y) / 2f;
Expand Down
2 changes: 1 addition & 1 deletion src/Murder.Editor/Data/EditorDataManager_Dialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public bool ReloadDialogs(bool force = false)
string dialogsPackedPath = FileHelper.GetPath(Path.Join(EditorSettings.SourcePackedPath, GameProfile.DialoguesPath));

string descriptorPath = Path.Join(dialogsPackedPath, _dialogsDescriptorName);
if (force || !FileLoadHelpers.ShouldRecalculate(dialogsRawResourcesPath, descriptorPath))
if (!force && !FileLoadHelpers.ShouldRecalculate(dialogsRawResourcesPath, descriptorPath))
{
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Murder/Core/Dialogs/CharacterRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ string FormatText(string? input)
DialogEdge choices = ActiveSituation.Edges[dialog.Id];

(Guid speaker, string? portrait) = (titleLine.Speaker ?? _character.Speaker, titleLine.Portrait);
string title = FormatText(LocalizationServices.GetLocalizedString(titleLine.Text));
string title = FormatText(LocalizationServices.TryGetLocalizedString(titleLine.Text));

var choicesArray = ImmutableArray.CreateBuilder<string>();
foreach (int c in choices.Dialogs)
Expand All @@ -563,7 +563,7 @@ string FormatText(string? input)
continue;
}

choicesArray.Add(FormatText(LocalizationServices.GetLocalizedString(choice.Lines[0].Text)));
choicesArray.Add(FormatText(LocalizationServices.TryGetLocalizedString(choice.Lines[0].Text)));
}

return new(speaker, portrait, title, choicesArray.ToImmutable());
Expand All @@ -582,7 +582,7 @@ private Line FormatLine(Line line)
line = line.WithSpeakerAndPortrait(_character.Speaker, _character.Portrait);
}

if (!BlackboardHelpers.FormatText(LocalizationServices.GetLocalizedString(text), out string result))
if (!BlackboardHelpers.FormatText(LocalizationServices.GetLocalizedString(text.Value), out string result))
{
return line;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Murder/Data/GameDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ protected async Task LoadContentAsync()
LoadAssetsAtPath(Path.Join(_binResourcesDirectory, GameProfile.AssetResourcesPath, GameProfile.ContentECSPath));

LoadAllSaves();
ChangeLanguage(Game.Preferences.Language);

CallAfterLoadContent = true;
}
Expand Down Expand Up @@ -430,8 +431,6 @@ private void LoadGameSettings()
GameProfile = CreateGameProfile();
GameProfile.MakeGuid();
}

ChangeLanguage(Game.Preferences.Language);
}

public MonoWorld CreateWorldInstanceFromSave(Guid guid, Camera2D camera)
Expand Down
20 changes: 9 additions & 11 deletions src/Murder/Services/LocalizationServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@ public static class LocalizationServices
{
public static LocalizationAsset GetCurrentLocalization() => Game.Data.Localization;

public static string GetLocalizedString(LocalizedString? localized)
{
if (localized is null)
{
return string.Empty;
}
public static string? TryGetLocalizedString(LocalizedString? localized) =>
localized is null ? null : GetLocalizedString(localized.Value);

if (localized.Value.OverrideText is not null)
public static string GetLocalizedString(LocalizedString localized)
{
if (localized.OverrideText is not null)
{
return localized.Value.OverrideText;
return localized.OverrideText;
}

LocalizationAsset asset = Game.Data.Localization;

LocalizedStringData? data = asset.TryGetResource(localized.Value.Id) ??
Game.Data.GetDefaultLocalization().TryGetResource(localized.Value.Id);
LocalizedStringData? data = asset.TryGetResource(localized.Id) ??
Game.Data.GetDefaultLocalization().TryGetResource(localized.Id);

if (data is null)
{
GameLogger.Error($"Unable to acquire resource for {localized.Value.Id}.");
GameLogger.Error($"Unable to acquire resource for {localized.Id}.");
return string.Empty;
}

Expand Down

0 comments on commit db51afc

Please sign in to comment.