Gravity cannon computer will write the planet the Shuttle starts on

This commit is contained in:
Nick 2023-08-04 23:48:11 -04:00
parent 76705a5b37
commit d284380f9e
6 changed files with 77 additions and 19 deletions

View File

@ -22,7 +22,8 @@
"DEBUG_PLACE_TEXT": "Place Nomai Text",
"DEBUG_UNDO": "Undo",
"DEBUG_REDO": "Redo",
"Vessel": "Vessel"
"Vessel": "Vessel",
"NOMAI_SHUTTLE_COMPUTER": "The <![CDATA[<color=orange>shuttle</color>]]> is currently resting at <![CDATA[<color=lightblue>{0}</color>]]>."
},
"AchievementTranslations": {
"NH_EATEN_OUTSIDE_BRAMBLE": {

View File

@ -1,10 +1,14 @@
using NewHorizons.Builder.Props.TranslatorText;
using NewHorizons.Components.Orbital;
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.Props.Shuttle;
using NewHorizons.External.Modules.TranslatorText;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using NewHorizons.Utility.OuterWilds;
using NewHorizons.Utility.OWML;
using Newtonsoft.Json;
using OWML.Common;
using UnityEngine;
@ -76,7 +80,8 @@ namespace NewHorizons.Builder.Props
gravityCannonObject.SetActive(false);
var gravityCannonController = gravityCannonObject.GetComponent<GravityCannonController>();
gravityCannonController._shuttleID = ShuttleHandler.GetShuttleID(info.shuttleID);
var id = ShuttleHandler.GetShuttleID(info.shuttleID);
gravityCannonController._shuttleID = id;
// Gravity controller checks string length instead of isnullorempty
gravityCannonController._retrieveShipLogFact = info.retrieveReveal ?? string.Empty;
@ -86,7 +91,11 @@ namespace NewHorizons.Builder.Props
if (info.computer != null)
{
gravityCannonController._nomaiComputer = CreateComputer(planetGO, sector, info.computer);
// Do it next update so that the shuttle has been made
Delay.FireOnNextUpdate(() =>
{
gravityCannonController._nomaiComputer = CreateComputer(planetGO, sector, info.computer, id);
});
}
else
{
@ -140,14 +149,23 @@ namespace NewHorizons.Builder.Props
}, () => Main.IsSystemReady, 10);
}
private static NomaiComputer CreateComputer(GameObject planetGO, Sector sector, GeneralPropInfo computerInfo)
private static NomaiComputer CreateComputer(GameObject planetGO, Sector sector, GeneralPropInfo computerInfo, NomaiShuttleController.ShuttleID id)
{
var computerObject = DetailBuilder.Make(planetGO, sector, TranslatorTextBuilder.ComputerPrefab, new DetailInfo(computerInfo));
// Load the position info from the GeneralPropInfo
var translatorTextInfo = new TranslatorTextInfo();
JsonConvert.PopulateObject(JsonConvert.SerializeObject(computerInfo), translatorTextInfo);
translatorTextInfo.type = NomaiTextType.Computer;
var shuttle = ShuttleBuilder.Shuttles[id];
var planet = AstroObjectLocator.GetPlanetName(shuttle.GetComponentInParent<AstroObject>());
var displayText = TranslationHandler.GetTranslation("NOMAI_SHUTTLE_COMPUTER", TranslationHandler.TextType.UI).Replace("{0}", planet);
NHLogger.Log(displayText);
var xmlContent = $"<NomaiObject>\r\n <TextBlock>\r\n <ID>1</ID>\r\n <Text>{displayText}</Text>\r\n </TextBlock>\r\n</NomaiObject>";
var computerObject = TranslatorTextBuilder.Make(planetGO, sector, translatorTextInfo, null, xmlContent);
var computer = computerObject.GetComponentInChildren<NomaiComputer>();
computer.SetSector(sector);
Delay.FireOnNextUpdate(computer.ClearAllEntries);
computerObject.SetActive(true);

View File

@ -3,6 +3,7 @@ using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.Props.Shuttle;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using System.Collections.Generic;
using UnityEngine;
namespace NewHorizons.Builder.Props
@ -13,6 +14,8 @@ namespace NewHorizons.Builder.Props
private static GameObject _orbPrefab;
private static GameObject _bodyPrefab;
public static Dictionary<NomaiShuttleController.ShuttleID, NomaiShuttleController> Shuttles { get; } = new();
internal static void InitPrefab()
{
if (_prefab == null)
@ -108,6 +111,8 @@ namespace NewHorizons.Builder.Props
orbObject.SetActive(true);
shuttleController._orb.RemoveAllLocks();
Shuttles[id] = shuttleController;
return shuttleObject;
}
}

View File

@ -1,7 +1,7 @@
using NewHorizons.External;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.SerializableData;
using NewHorizons.External.Modules.TranslatorText;
using NewHorizons.External.SerializableData;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using NewHorizons.Utility.Geometry;
@ -14,7 +14,6 @@ using System.IO;
using System.Linq;
using System.Xml;
using UnityEngine;
using Random = UnityEngine.Random;
namespace NewHorizons.Builder.Props.TranslatorText
@ -137,6 +136,11 @@ namespace NewHorizons.Builder.Props.TranslatorText
return null;
}
return Make(planetGO, sector, info, nhBody, xmlContent);
}
public static GameObject Make(GameObject planetGO, Sector sector, TranslatorTextInfo info, NewHorizonsBody nhBody, string xmlContent)
{
switch (info.type)
{
case NomaiTextType.Wall:
@ -401,7 +405,7 @@ namespace NewHorizons.Builder.Props.TranslatorText
}
}
private static NomaiWallText MakeWallText(GameObject go, Sector sector, TranslatorTextInfo info, string xmlPath, NewHorizonsBody nhBody)
private static NomaiWallText MakeWallText(GameObject go, Sector sector, TranslatorTextInfo info, string xmlContent, NewHorizonsBody nhBody)
{
GameObject nomaiWallTextObj = new GameObject("NomaiWallText");
nomaiWallTextObj.SetActive(false);
@ -418,13 +422,13 @@ namespace NewHorizons.Builder.Props.TranslatorText
nomaiWallText._location = EnumUtils.Parse<NomaiText.Location>(info.location.ToString());
var text = new TextAsset(xmlPath);
var text = new TextAsset(xmlContent);
// Text assets need a name to be used with VoiceMod
text.name = Path.GetFileNameWithoutExtension(info.xmlFile);
BuildArcs(xmlPath, nomaiWallText, nomaiWallTextObj, info, nhBody);
AddTranslation(xmlPath);
BuildArcs(xmlContent, nomaiWallText, nomaiWallTextObj, info, nhBody);
AddTranslation(xmlContent);
nomaiWallText._nomaiTextAsset = text;
nomaiWallText.SetTextAsset(text);

View File

@ -8,9 +8,9 @@ namespace NewHorizons.Handlers
{
public static class TranslationHandler
{
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _shipLogTranslationDictionary = new Dictionary<TextTranslation.Language, Dictionary<string, string>>();
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _dialogueTranslationDictionary = new Dictionary<TextTranslation.Language, Dictionary<string, string>>();
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _uiTranslationDictionary = new Dictionary<TextTranslation.Language, Dictionary<string, string>>();
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _shipLogTranslationDictionary = new();
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _dialogueTranslationDictionary = new();
private static Dictionary<TextTranslation.Language, Dictionary<string, string>> _uiTranslationDictionary = new();
public enum TextType
{
@ -93,8 +93,9 @@ namespace NewHorizons.Handlers
if (!_uiTranslationDictionary.ContainsKey(language)) _uiTranslationDictionary.Add(language, new Dictionary<string, string>());
foreach (var originalKey in config.UIDictionary.Keys)
{
var key = originalKey.Replace("&lt;", "<").Replace("&gt;", ">").Replace("<![CDATA[", "").Replace("]]>", "");
var value = config.UIDictionary[originalKey].Replace("&lt;", "<").Replace("&gt;", ">").Replace("<![CDATA[", "").Replace("]]>", "");
// Don't remove CDATA from UI
var key = originalKey.Replace("&lt;", "<").Replace("&gt;", ">");
var value = config.UIDictionary[originalKey].Replace("&lt;", "<").Replace("&gt;", ">");
if (!_uiTranslationDictionary[language].ContainsKey(key)) _uiTranslationDictionary[language].Add(key, value);
else _uiTranslationDictionary[language][key] = value;

View File

@ -1,5 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using NewHorizons.Components.Orbital;
using NewHorizons.Handlers;
using NewHorizons.Utility.OWML;
using UnityEngine;
@ -177,5 +179,32 @@ namespace NewHorizons.Utility.OuterWilds
return otherChildren.ToArray();
}
public static string GetPlanetName(AstroObject astroObject)
{
if (astroObject != null)
{
if (astroObject is NHAstroObject nhAstroObject)
{
var customName = nhAstroObject.GetCustomName();
if (!string.IsNullOrWhiteSpace(customName))
{
return TranslationHandler.GetTranslation(customName, TranslationHandler.TextType.UI, false);
}
}
else
{
AstroObject.Name astroObjectName = astroObject.GetAstroObjectName();
if (astroObjectName - AstroObject.Name.Sun <= 7 || astroObjectName - AstroObject.Name.TimberMoon <= 1)
{
return AstroObject.AstroObjectNameToString(astroObject.GetAstroObjectName());
}
}
}
return "???";
}
}
}