mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
Optimization (Part 1?) (#589)
* Well lets try check this * Some changes * Change * Well * Change ControllerManager.Update * Nothing * Optimaze more? * Fix error build * Fix win check * Change * Fix * Optimaze some roles in OnCheckPlayerPosition * More optimaze * Full optimaze roles in OnGlobalFixedUpdate * Optimaze some add-ons * ProgressText * Change * Optimaze NameNotifyManager * Optimaze NotifyRoles and some roles * Move the displayed version * Some changes * Optimaze OnFixedUpdate in some roles * Fix bugs * Optimaze IsActive & V4 version * Optimaze MapRoom.DoorsUpdate * Cache TryCatch in IsActive * Change * Fix * More optimze TaskPanelBehaviour * Cache GetRoleColor & ColorString & AllStringNames & Change RemoveHtmlTags * Cache TryCast VentilationSystem & ICriticalSabotage & IUsable and more optimaze * Fix CountAlivePlayers * Fix exceptios * Replace some CachedAllPlayerControls to EnumeratePlayerControls * Replace some CachedAlivePlayerControls to EnumerateAlivePlayerControls * Fixes * Fix modded clients * Fix errors * Fix again * Optimaze & add null check * Fix crash in Starlight * Use only Main.PluginVersion in LobbySharingAPI * Optimaze code in FixedUpdate * Fix * Optimize GetProgressText for Roles * Some changes in Translations * Cache Enum.GetValues and StringBuilder * Changes * CustomRole.ColoredTextByRole() * Optimaze Lobby & Meeting * ColorStringPrefix => ColorPrefix * Add null check * Remove * Fixes & optimaze * Fixes * Changes * Fix * Fix * Fix * Remove * Fix * Change * Revert
This commit is contained in:
1 parent
3370ac8483
commit
7929a4b83e
245 files changed
+5603
-3340
No files matched your search
+65
-29
@@ -7,7 +7,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace EHR;
|
||||
|
||||
@@ -143,34 +142,44 @@ public static class Translator
|
||||
|
||||
public static string GetString(string s, Dictionary<string, string> replacementDic = null, bool console = false)
|
||||
{
|
||||
if (SubmergedCompatibility.IsSubmerged() && int.TryParse(s, out int roomNumber) && roomNumber is >= 128 and <= 135)
|
||||
s = $"SubmergedRoomName.{roomNumber}";
|
||||
SupportedLangs langId;
|
||||
int modLanguageId = Options.IsLoaded ? Options.ModLanguage.GetValue() : 0;
|
||||
|
||||
if (GameStates.InGame && Options.CurrentGameMode == CustomGameMode.Deathrace && int.TryParse(s, out roomNumber) && Deathrace.CoordinateChecks.ContainsKey(roomNumber))
|
||||
s = "Deathrace.CoordinateCheck";
|
||||
|
||||
SupportedLangs langId = TranslationController.InstanceExists ? TranslationController.Instance.currentLanguage.languageID : SupportedLangs.English;
|
||||
if (console) langId = SupportedLangs.English;
|
||||
|
||||
if (Main.ForceOwnLanguage.Value) langId = GetUserTrueLang();
|
||||
|
||||
int modLanguageId = 0;
|
||||
|
||||
if (Options.IsLoaded)
|
||||
if (console)
|
||||
langId = SupportedLangs.English;
|
||||
else
|
||||
{
|
||||
modLanguageId = Options.ModLanguage.GetValue();
|
||||
if (modLanguageId != 0) langId = (SupportedLangs)(modLanguageId + 100 - 1);
|
||||
if (modLanguageId != 0)
|
||||
langId = (SupportedLangs)(modLanguageId + 99);
|
||||
else if (Main.ForceOwnLanguage.Value)
|
||||
langId = GetUserTrueLang();
|
||||
else
|
||||
langId = TranslationController.InstanceExists
|
||||
? TranslationController.Instance.currentLanguage.languageID
|
||||
: SupportedLangs.English;
|
||||
}
|
||||
|
||||
if (GameStates.InGame)
|
||||
{
|
||||
int roomNumber = -1;
|
||||
if (SubmergedCompatibility.IsSubmerged() && int.TryParse(s, out roomNumber) && roomNumber is >= 128 and <= 135)
|
||||
s = $"SubmergedRoomName.{roomNumber}";
|
||||
|
||||
if (Options.CurrentGameMode == CustomGameMode.Deathrace)
|
||||
{
|
||||
if ((roomNumber != -1 || int.TryParse(s, out roomNumber)) && Deathrace.CoordinateChecks.ContainsKey(roomNumber))
|
||||
s = "Deathrace.CoordinateCheck";
|
||||
}
|
||||
}
|
||||
|
||||
string str = GetString(s, langId);
|
||||
|
||||
if (replacementDic != null)
|
||||
if (replacementDic != null && replacementDic.Count > 0)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> rd in replacementDic)
|
||||
str = str.Replace(rd.Key, rd.Value);
|
||||
}
|
||||
|
||||
if (modLanguageId == 1) // Hungarian (none of the fonts support ő/ű and innersloth doesn't care, thankfully at least German has ö/ü)
|
||||
if (modLanguageId == 1 && (str.Contains('ő') || str.Contains('ű'))) // Hungarian (none of the fonts support ő/ű and innersloth doesn't care, thankfully at least German has ö/ü)
|
||||
str = str.Replace("ő", "ö", StringComparison.CurrentCultureIgnoreCase).Replace("ű", "ü", StringComparison.CurrentCultureIgnoreCase);
|
||||
|
||||
return str;
|
||||
@@ -178,15 +187,17 @@ public static class Translator
|
||||
|
||||
public static string GetString(string str, SupportedLangs langId)
|
||||
{
|
||||
var res = $"*{str}";
|
||||
|
||||
try
|
||||
{
|
||||
if (TranslateMaps.TryGetValue(str, out Dictionary<int, string> dic) && (!dic.TryGetValue((int)langId, out res) || string.IsNullOrEmpty(res) || (langId is not SupportedLangs.SChinese and not SupportedLangs.TChinese && Regex.IsMatch(res, @"[\u4e00-\u9fa5]") && res == GetString(str, SupportedLangs.SChinese))))
|
||||
res = langId == SupportedLangs.English ? $"*{str}" : GetString(str, SupportedLangs.English);
|
||||
if (TranslateMaps.TryGetValue(str, out var dic))
|
||||
{
|
||||
if (dic.TryGetValue((int)langId, out var res) && !string.IsNullOrEmpty(res))
|
||||
return res;
|
||||
|
||||
if (!TranslateMaps.ContainsKey(str) && AllStringNames.FindFirst(x => x.ToString() == str, out StringNames stringNames))
|
||||
res = GetString(stringNames);
|
||||
if (langId != SupportedLangs.English)
|
||||
return GetString(str, SupportedLangs.English);
|
||||
}
|
||||
else if (TryGetStringName(str, out var stringName)) return GetString(stringName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -194,14 +205,31 @@ public static class Translator
|
||||
Logger.Error("Here was the error:\n" + ex, "Translator");
|
||||
}
|
||||
|
||||
return res;
|
||||
return $"*{str}";
|
||||
}
|
||||
|
||||
public static string GetString(StringNames stringName)
|
||||
{
|
||||
return TranslationController.Instance.GetString(stringName);
|
||||
}
|
||||
|
||||
public static string GetString(SystemTypes room)
|
||||
{
|
||||
return TranslationController.Instance.GetString(room);
|
||||
}
|
||||
private static bool TryGetStringName(string str, out StringNames result)
|
||||
{
|
||||
for (int i = 0; i < AllStringNames.Length; i++)
|
||||
{
|
||||
var val = AllStringNames[i];
|
||||
if (val.ToString() == str)
|
||||
{
|
||||
result = val;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
public static string GetRoleString(string str, bool forUser = true)
|
||||
{
|
||||
SupportedLangs currentLanguage = TranslationController.Instance.currentLanguage.languageID;
|
||||
@@ -334,5 +362,13 @@ public static class Translator
|
||||
SupportedLangs.SChinese or
|
||||
SupportedLangs.TChinese;
|
||||
}
|
||||
|
||||
}
|
||||
public static bool LangHasSensitiveOutlineText(SupportedLangs lang)
|
||||
{
|
||||
return lang is
|
||||
SupportedLangs.Russian or
|
||||
SupportedLangs.Korean or
|
||||
SupportedLangs.Japanese or
|
||||
SupportedLangs.SChinese or
|
||||
SupportedLangs.TChinese;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user