Skip to content

Commit

Permalink
Fix http API for environments (broken by localization)
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Dec 6, 2023
1 parent ed09461 commit f5b9b33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Assets/Scripts/API/ApiManager.cs
Expand Up @@ -573,8 +573,8 @@ private string ScriptTemplateSubstitution(string html)
string wallpaperGroups = JsonConvert.SerializeObject(Enum.GetNames(typeof(PointSymmetry.Family)));
html = html.Replace("{{wallpaperGroupsJson}}", wallpaperGroups);

string[] environmentNameList = EnvironmentCatalog.m_Instance.AllEnvironments
.Select(x => x.Description.Replace(" ", ""))
string[] environmentNameList = EnvironmentCatalog.m_Instance.m_EnvironmentDescriptions
.Select(x => x.Replace(" ", ""))
.ToArray();

string environmentsJson = JsonConvert.SerializeObject(environmentNameList);
Expand Down
9 changes: 9 additions & 0 deletions Assets/Scripts/EnvironmentCatalog.cs
Expand Up @@ -15,6 +15,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Localization.Settings;

namespace TiltBrush
{
Expand All @@ -30,6 +31,9 @@ public class EnvironmentCatalog : MonoBehaviour
private bool m_IsLoading;
private Dictionary<Guid, Environment> m_GuidToEnvironment;

// Used by the HTTP API because you can't GetLocalizedString in a background thread.
public List<string> m_EnvironmentDescriptions;

public IEnumerable<Environment> AllEnvironments
{
get { return m_GuidToEnvironment.Values; }
Expand All @@ -43,6 +47,7 @@ void Awake()
{
m_Instance = this;
m_GuidToEnvironment = new Dictionary<Guid, Environment>();
m_EnvironmentDescriptions = new List<string>();
}

public bool IsLoading { get { return m_IsLoading; } }
Expand All @@ -63,6 +68,10 @@ public void BeginReload()
continue;
}
m_GuidToEnvironment[env.m_Guid] = env;
// TODO - do we want the API to always use English?
// env.m_EnvironmentDescription.LocaleOverride = LocalizationSettings.AvailableLocales.GetLocale(SystemLanguage.English);
m_EnvironmentDescriptions.Add(env.Description);
// env.m_EnvironmentDescription.LocaleOverride = null;
}

Resources.UnloadUnusedAssets();
Expand Down

0 comments on commit f5b9b33

Please sign in to comment.