mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Add api method to make ship logs
This commit is contained in:
parent
212e16b5f0
commit
0f187f6aca
@ -55,15 +55,20 @@ namespace NewHorizons.Builder.ShipLog
|
|||||||
{
|
{
|
||||||
string systemName = body.Config.starSystem;
|
string systemName = body.Config.starSystem;
|
||||||
XElement astroBodyFile = XElement.Load(Path.Combine(body.Mod.ModHelper.Manifest.ModFolderPath, body.Config.ShipLog.xmlFile));
|
XElement astroBodyFile = XElement.Load(Path.Combine(body.Mod.ModHelper.Manifest.ModFolderPath, body.Config.ShipLog.xmlFile));
|
||||||
XElement astroBodyId = astroBodyFile.Element("ID");
|
AddShipLogXML(manager, astroBodyFile, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddShipLogXML(ShipLogManager manager, XElement xml, NewHorizonsBody body)
|
||||||
|
{
|
||||||
|
XElement astroBodyId = xml.Element("ID");
|
||||||
if (astroBodyId == null)
|
if (astroBodyId == null)
|
||||||
{
|
{
|
||||||
NHLogger.LogError("Failed to load ship logs for " + systemName + "!");
|
NHLogger.LogError("Failed to load ship logs for " + body.Config.name + "!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var entryIDs = new List<string>();
|
var entryIDs = new List<string>();
|
||||||
foreach (XElement entryElement in astroBodyFile.DescendantsAndSelf("Entry"))
|
foreach (XElement entryElement in xml.DescendantsAndSelf("Entry"))
|
||||||
{
|
{
|
||||||
XElement curiosityName = entryElement.Element("Curiosity");
|
XElement curiosityName = entryElement.Element("Curiosity");
|
||||||
XElement id = entryElement.Element("ID");
|
XElement id = entryElement.Element("ID");
|
||||||
@ -98,8 +103,8 @@ namespace NewHorizons.Builder.ShipLog
|
|||||||
}
|
}
|
||||||
AddTranslation(entryElement);
|
AddTranslation(entryElement);
|
||||||
}
|
}
|
||||||
TextAsset newAsset = new TextAsset(astroBodyFile.ToString());
|
var newAsset = new TextAsset(xml.ToString());
|
||||||
List<TextAsset> newBodies = new List<TextAsset>(manager._shipLogXmlAssets) { newAsset };
|
var newBodies = new List<TextAsset>(manager._shipLogXmlAssets) { newAsset };
|
||||||
manager._shipLogXmlAssets = newBodies.ToArray();
|
manager._shipLogXmlAssets = newBodies.ToArray();
|
||||||
ShipLogHandler.AddConfig(astroBodyId.Value, entryIDs, body);
|
ShipLogHandler.AddConfig(astroBodyId.Value, entryIDs, body);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using OWML.Common;
|
using OWML.Common;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Xml.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
@ -14,6 +15,15 @@ namespace NewHorizons
|
|||||||
[Obsolete("Create(Dictionary<string, object> config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")]
|
[Obsolete("Create(Dictionary<string, object> config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")]
|
||||||
void Create(Dictionary<string, object> config, IModBehaviour mod);
|
void Create(Dictionary<string, object> config, IModBehaviour mod);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Directly add ship logs from XML. Call this method right before ShipLogManager awake.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mod"></param>
|
||||||
|
/// <param name="manager"></param>
|
||||||
|
/// <param name="xml"></param>
|
||||||
|
/// <param name="planetName"></param>
|
||||||
|
void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will load all configs in the regular folders (planets, systems, translations, etc) for this mod.
|
/// Will load all configs in the regular folders (planets, systems, translations, etc) for this mod.
|
||||||
/// The NH addon config template is just a single call to this API method.
|
/// The NH addon config template is just a single call to this API method.
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
using NewHorizons.Builder.Props;
|
using NewHorizons.Builder.Props;
|
||||||
using NewHorizons.Builder.Props.Audio;
|
using NewHorizons.Builder.Props.Audio;
|
||||||
|
using NewHorizons.Builder.ShipLog;
|
||||||
using NewHorizons.External;
|
using NewHorizons.External;
|
||||||
|
using NewHorizons.External.Configs;
|
||||||
using NewHorizons.External.Modules;
|
using NewHorizons.External.Modules;
|
||||||
using NewHorizons.External.Modules.Props;
|
using NewHorizons.External.Modules.Props;
|
||||||
using NewHorizons.External.Modules.Props.Audio;
|
using NewHorizons.External.Modules.Props.Audio;
|
||||||
@ -15,6 +17,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Xml.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
|
||||||
@ -62,6 +65,31 @@ namespace NewHorizons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddShipLogXML(IModBehaviour mod, ShipLogManager manager, XElement xml, string planetName)
|
||||||
|
{
|
||||||
|
var body = new NewHorizonsBody(new PlanetConfig() { name = planetName, starSystem = Main.Instance.CurrentStarSystem }, mod);
|
||||||
|
|
||||||
|
if (!Main.BodyDict.ContainsKey(Main.Instance.CurrentStarSystem))
|
||||||
|
{
|
||||||
|
Main.BodyDict.Add(Main.Instance.CurrentStarSystem, new List<NewHorizonsBody>());
|
||||||
|
Main.BodyDict[Main.Instance.CurrentStarSystem].Add(body);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var existingBody = Main.BodyDict[Main.Instance.CurrentStarSystem].FirstOrDefault(x => x.Config.name == planetName);
|
||||||
|
if (existingBody != null)
|
||||||
|
{
|
||||||
|
body = existingBody;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Main.BodyDict[Main.Instance.CurrentStarSystem].Add(body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RumorModeBuilder.AddShipLogXML(manager, xml, body);
|
||||||
|
}
|
||||||
|
|
||||||
public void LoadConfigs(IModBehaviour mod)
|
public void LoadConfigs(IModBehaviour mod)
|
||||||
{
|
{
|
||||||
Main.Instance.LoadConfigs(mod);
|
Main.Instance.LoadConfigs(mod);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user