Fix a minor bug with Vietnamese "Peashooter"
This commit is contained in:
parent
68b428f9f4
commit
d09efe0008
4 changed files with 100 additions and 46 deletions
|
|
@ -60,22 +60,22 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
|||
TextMeshPro component3 = __instance.plantName.transform.GetChild(0).GetComponent<TextMeshPro>();
|
||||
TextMeshPro component4 = __instance.cost.GetComponent<TextMeshPro>();
|
||||
TextMeshPro component5 = __instance.introduce.GetComponentInChildren<TextMeshPro>();
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
Log.LogWarning($"Introduce text: {component?.text}");
|
||||
Log.LogWarning($"Plant name: {component2?.text}");
|
||||
#endif
|
||||
component.text = Utils.RemoveColorTags(component.text);
|
||||
#endif
|
||||
component.text = component.text ?? string.Empty;
|
||||
|
||||
AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
|
||||
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
||||
{
|
||||
if (plantInfo.seedType == __instance.theSeedType)
|
||||
if (plantInfo.seedType == __instance.theSeedType && !string.IsNullOrEmpty(plantInfo.name))
|
||||
{
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
Log.LogInfo($"Processing plant type: {plantInfo.seedType}");
|
||||
Log.LogInfo($"Plant info: {plantInfo.info}, Name: {plantInfo.name}, Cost: {plantInfo.cost}, Introduce: {plantInfo.introduce}");
|
||||
#endif
|
||||
#endif
|
||||
component.autoSizeTextContainer = false;
|
||||
component.text = plantInfo.info + "\n\n" + plantInfo.introduce;
|
||||
component.overflowMode = TextOverflowModes.Page;
|
||||
|
|
@ -88,7 +88,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
|||
component2.text = plantInfo.name;
|
||||
component2.autoSizeTextContainer = true;
|
||||
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name);
|
||||
#if DEBUG
|
||||
Log.LogInfo($"Processing plant name: '{plantInfo.name}' (null: {plantInfo.name == null})");
|
||||
#endif
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name ?? string.Empty);
|
||||
component3.autoSizeTextContainer = true;
|
||||
|
||||
component4.text = plantInfo.cost;
|
||||
|
|
@ -116,7 +119,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
|||
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in moddedPlantData.plants)
|
||||
{
|
||||
if (plantInfo.seedType == __instance.theSeedType)
|
||||
if (plantInfo.seedType == __instance.theSeedType && !string.IsNullOrEmpty(plantInfo.name))
|
||||
{
|
||||
component.autoSizeTextContainer = false;
|
||||
component.text = plantInfo.info + "\n\n" + plantInfo.introduce;
|
||||
|
|
@ -130,7 +133,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
|||
component2.text = plantInfo.name;
|
||||
component2.autoSizeTextContainer = true;
|
||||
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name);
|
||||
#if DEBUG
|
||||
Log.LogInfo($"Processing plant name: '{plantInfo.name}' (null: {plantInfo.name == null})");
|
||||
#endif
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name ?? string.Empty);
|
||||
component3.autoSizeTextContainer = true;
|
||||
|
||||
component4.text = plantInfo.cost;
|
||||
|
|
@ -189,10 +195,10 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
|||
if (Input.GetKey(KeyCode.LeftControl))
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(__instance.introduce.GetComponent<TextMeshPro>().text);
|
||||
Log.LogInfo($"Info: {__instance.introduce.GetComponent<TextMeshPro>().text}");
|
||||
//Log.LogInfo($"Info: {__instance.introduce.GetComponent<TextMeshPro>().text}");
|
||||
FileLoader.DumpUntranslatedStrings(__instance.plantName.GetComponent<TextMeshPro>().text);
|
||||
Log.LogInfo($"PlantName Name: {__instance.plantName.GetComponent<TextMeshPro>().text}");
|
||||
Log.LogInfo($"PlantShadow Name: {__instance.plantName.transform.GetChild(0).GetComponent<TextMeshPro>().text}");
|
||||
//Log.LogInfo($"PlantName Name: {__instance.plantName.GetComponent<TextMeshPro>().text}");
|
||||
//Log.LogInfo($"PlantShadow Name: {__instance.plantName.transform.GetChild(0).GetComponent<TextMeshPro>().text}");
|
||||
}
|
||||
string currentLanguage = Utils.Language.ToString();
|
||||
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting.FullSerializer;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityEngine.UI;
|
||||
using static PvZ_Fusion_Translator__BepInEx_.FileLoader;
|
||||
|
||||
namespace PvZ_Fusion_Translator__BepInEx_
|
||||
{
|
||||
|
|
@ -79,7 +80,14 @@ namespace PvZ_Fusion_Translator__BepInEx_
|
|||
|
||||
public static string RemoveColorTags(string text)
|
||||
{
|
||||
return Regex.Replace(text, @"<color=[^>]+>", "");
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return text ?? string.Empty;
|
||||
|
||||
// Remove opening color tags like <color=#FF0000>
|
||||
string withoutOpenTags = Regex.Replace(text, @"<color=[^>]+>", string.Empty, RegexOptions.IgnoreCase);
|
||||
// Remove closing color tags like </color>
|
||||
string withoutCloseTags = Regex.Replace(withoutOpenTags, @"</color>", string.Empty, RegexOptions.IgnoreCase);
|
||||
return withoutCloseTags;
|
||||
}
|
||||
|
||||
public static GameObject ConvertToTextMeshProUGUI(GameObject originalText, Transform parent, string name)
|
||||
|
|
@ -112,13 +120,58 @@ namespace PvZ_Fusion_Translator__BepInEx_
|
|||
newGoBackText.color = color;
|
||||
}
|
||||
|
||||
//public static string GetPlantNameFromAlmanac(PlantType thePlantType)
|
||||
//{
|
||||
// string json;
|
||||
// string thePlantName = "";
|
||||
|
||||
// string currentLanguage = Utils.Language.ToString();
|
||||
// string almanacDir = FileLoader.GetAssetDir(FileLoader.AssetType.Almanac, Utils.Language);
|
||||
// string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
|
||||
// string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json");
|
||||
|
||||
// if (!File.Exists(path))
|
||||
// {
|
||||
// Log.LogError($"LawnStringsTranslate.json file not found at path: {path}");
|
||||
// Log.LogError("Plant name could not be found! (Big Garden)");
|
||||
// thePlantName = "";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// json = File.ReadAllText(path);
|
||||
// AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
|
||||
// if (plantData != null && plantData.plants != null)
|
||||
// {
|
||||
// foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
||||
// {
|
||||
// if (plantInfo.seedType == (int)thePlantType)
|
||||
// {
|
||||
// // Remove any ID numbers from the name (e.g., "Peashooter (0)" -> "Peashooter", "Peashooter26" -> "Peashooter")
|
||||
// // thePlantName = System.Text.RegularExpressions.Regex.Replace(plantInfo.name, @"\s*\(\d+\)$|\d+$", "");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (System.Exception ex)
|
||||
// {
|
||||
// Log.LogError($"Error parsing JSON in GetPlantNameFromAlmanac: {ex.Message}");
|
||||
// thePlantName = "";
|
||||
// }
|
||||
// }
|
||||
|
||||
// return thePlantName;
|
||||
//}
|
||||
|
||||
public static string GetPlantNameFromAlmanac(PlantType thePlantType)
|
||||
{
|
||||
string json;
|
||||
string thePlantName = "";
|
||||
|
||||
string currentLanguage = Utils.Language.ToString();
|
||||
string almanacDir = FileLoader.GetAssetDir(FileLoader.AssetType.Almanac, Utils.Language);
|
||||
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
||||
string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
|
||||
string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json");
|
||||
|
||||
|
|
@ -130,28 +183,16 @@ namespace PvZ_Fusion_Translator__BepInEx_
|
|||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
json = File.ReadAllText(path);
|
||||
AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
|
||||
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
||||
{
|
||||
json = File.ReadAllText(path);
|
||||
AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
|
||||
if (plantData != null && plantData.plants != null)
|
||||
if (plantInfo.seedType == (int)thePlantType)
|
||||
{
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
||||
{
|
||||
if (plantInfo.seedType == (int)thePlantType)
|
||||
{
|
||||
// Remove any ID numbers from the name (e.g., "Peashooter (0)" -> "Peashooter", "Peashooter26" -> "Peashooter")
|
||||
thePlantName = System.Text.RegularExpressions.Regex.Replace(plantInfo.name, @"\s*\(\d+\)$|\d+$", "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
thePlantName = plantInfo.name;
|
||||
}
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Log.LogError($"Error parsing JSON in GetPlantNameFromAlmanac: {ex.Message}");
|
||||
thePlantName = "";
|
||||
}
|
||||
}
|
||||
|
||||
return thePlantName;
|
||||
|
|
|
|||
|
|
@ -62,9 +62,9 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
|
||||
AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
|
||||
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
||||
{
|
||||
if (plantInfo.seedType == __instance.theSeedType)
|
||||
if (plantInfo.seedType == __instance.theSeedType && !string.IsNullOrEmpty(plantInfo.name))
|
||||
{
|
||||
component.autoSizeTextContainer = false;
|
||||
component.text = plantInfo.info + "\n\n" + plantInfo.introduce;
|
||||
|
|
@ -80,7 +80,7 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
component2.text = plantInfo.name;
|
||||
component2.autoSizeTextContainer = true;
|
||||
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name);
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name ?? string.Empty);
|
||||
component3.autoSizeTextContainer = true;
|
||||
|
||||
component4.text = plantInfo.cost;
|
||||
|
|
@ -107,9 +107,9 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
|
||||
AlmanacPlantBank.PlantData moddedPlantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(moddedJson);
|
||||
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in moddedPlantData.plants)
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in moddedPlantData.plants)
|
||||
{
|
||||
if (plantInfo.seedType == __instance.theSeedType)
|
||||
if (plantInfo.seedType == __instance.theSeedType && !string.IsNullOrEmpty(plantInfo.name))
|
||||
{
|
||||
component.autoSizeTextContainer = false;
|
||||
component.text = plantInfo.info + "\n\n" + plantInfo.introduce;
|
||||
|
|
@ -125,7 +125,7 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
component2.text = plantInfo.name;
|
||||
component2.autoSizeTextContainer = true;
|
||||
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name);
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name ?? string.Empty);
|
||||
component3.autoSizeTextContainer = true;
|
||||
|
||||
component4.text = plantInfo.cost;
|
||||
|
|
|
|||
|
|
@ -76,10 +76,17 @@ namespace PvZ_Fusion_Translator
|
|||
Process.Start(new ProcessStartInfo(website) { UseShellExecute = true });
|
||||
}
|
||||
|
||||
public static string RemoveColorTags(string text)
|
||||
{
|
||||
return Regex.Replace(text, @"<color=[^>]+>", "");
|
||||
}
|
||||
public static string RemoveColorTags(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return text ?? string.Empty;
|
||||
|
||||
// Remove opening color tags like <color=#FF0000>
|
||||
string withoutOpenTags = Regex.Replace(text, @"<color=[^>]+>", string.Empty, RegexOptions.IgnoreCase);
|
||||
// Remove closing color tags like </color>
|
||||
string withoutCloseTags = Regex.Replace(withoutOpenTags, @"</color>", string.Empty, RegexOptions.IgnoreCase);
|
||||
return withoutCloseTags;
|
||||
}
|
||||
|
||||
public static GameObject ConvertToTextMeshProUGUI(GameObject originalText, Transform parent, string name)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue