mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
JSON rewrite beginning
This commit is contained in:
parent
3a8b625f94
commit
a892af13c0
23
Marshmallow/AddToUITable.cs
Normal file
23
Marshmallow/AddToUITable.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using OWML.ModHelper.Events;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Marshmallow.UI
|
||||||
|
{
|
||||||
|
static class AddToUITable
|
||||||
|
{
|
||||||
|
public static int Add(string text)
|
||||||
|
{
|
||||||
|
TextTranslation.TranslationTable instance = GameObject.FindObjectOfType<TextTranslation>().GetValue<TextTranslation.TranslationTable>("m_table");
|
||||||
|
|
||||||
|
instance.Insert_UI(instance.theUITable.Keys.Max() + 1, text);
|
||||||
|
|
||||||
|
Main.Log("Added [" + text + "] to UI table with key [" + instance.theUITable.Keys.Max() + "]");
|
||||||
|
|
||||||
|
return instance.theUITable.Keys.Max();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,9 @@
|
|||||||
using OWML.Common;
|
using Newtonsoft.Json;
|
||||||
|
using OWML.Common;
|
||||||
using OWML.ModHelper;
|
using OWML.ModHelper;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -18,6 +20,8 @@ namespace Marshmallow
|
|||||||
|
|
||||||
public static IModHelper helper;
|
public static IModHelper helper;
|
||||||
|
|
||||||
|
static List<PlanetConfig> planetList = new List<PlanetConfig>();
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
base.ModHelper.Events.Subscribe<Flashlight>(Events.AfterStart);
|
base.ModHelper.Events.Subscribe<Flashlight>(Events.AfterStart);
|
||||||
@ -25,6 +29,13 @@ namespace Marshmallow
|
|||||||
events.OnEvent = (Action<MonoBehaviour, Events>)Delegate.Combine(events.OnEvent, new Action<MonoBehaviour, Events>(this.OnEvent));
|
events.OnEvent = (Action<MonoBehaviour, Events>)Delegate.Combine(events.OnEvent, new Action<MonoBehaviour, Events>(this.OnEvent));
|
||||||
|
|
||||||
helper = base.ModHelper;
|
helper = base.ModHelper;
|
||||||
|
|
||||||
|
foreach (var file in Directory.GetFiles(ModHelper.Manifest.ModFolderPath + @"planets\"))
|
||||||
|
{
|
||||||
|
planetList.Add(ModHelper.Storage.Load<PlanetConfig>(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
Main.Log("Loaded [" + planetList.Count + "] planet config files.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEvent(MonoBehaviour behaviour, Events ev)
|
private void OnEvent(MonoBehaviour behaviour, Events ev)
|
||||||
@ -32,9 +43,14 @@ namespace Marshmallow
|
|||||||
bool flag = behaviour.GetType() == typeof(Flashlight) && ev == Events.AfterStart;
|
bool flag = behaviour.GetType() == typeof(Flashlight) && ev == Events.AfterStart;
|
||||||
if (flag)
|
if (flag)
|
||||||
{
|
{
|
||||||
|
foreach (var config in planetList)
|
||||||
|
{
|
||||||
|
var planet = GenerateBody(config);
|
||||||
|
}
|
||||||
|
|
||||||
PlanetStructure inputStructure = new PlanetStructure
|
PlanetStructure inputStructure = new PlanetStructure
|
||||||
{
|
{
|
||||||
name = "invisibleplanet",
|
name = "Mister_Nebula's Custom Planet!",
|
||||||
|
|
||||||
primaryBody = Locator.GetAstroObject(AstroObject.Name.Sun),
|
primaryBody = Locator.GetAstroObject(AstroObject.Name.Sun),
|
||||||
aoType = AstroObject.Type.Planet,
|
aoType = AstroObject.Type.Planet,
|
||||||
@ -82,8 +98,10 @@ namespace Marshmallow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private GameObject GenerateBody(PlanetStructure planet)
|
private GameObject GenerateBody(PlanetConfig config)
|
||||||
{
|
{
|
||||||
|
Main.Log("Begin generation sequence of planet [" + planet.name + "] ...");
|
||||||
|
|
||||||
float groundScale = 400f;
|
float groundScale = 400f;
|
||||||
|
|
||||||
GameObject body;
|
GameObject body;
|
||||||
@ -99,7 +117,7 @@ namespace Marshmallow
|
|||||||
|
|
||||||
if (planet.hasMapMarker)
|
if (planet.hasMapMarker)
|
||||||
{
|
{
|
||||||
General.MakeMapMarker.Make(body);
|
General.MakeMapMarker.Make(body, planet.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTOR = Body.MakeSector.Make(body, planet.topCloudSize.Value);
|
SECTOR = Body.MakeSector.Make(body, planet.topCloudSize.Value);
|
||||||
@ -127,6 +145,8 @@ namespace Marshmallow
|
|||||||
SPAWN = General.MakeSpawnPoint.Make(body, new Vector3(0, groundScale+10, 0));
|
SPAWN = General.MakeSpawnPoint.Make(body, new Vector3(0, groundScale+10, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Main.Log("Generation of planet [" + planet.name + "] completed.");
|
||||||
|
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,11 +6,13 @@ namespace Marshmallow.General
|
|||||||
{
|
{
|
||||||
static class MakeMapMarker
|
static class MakeMapMarker
|
||||||
{
|
{
|
||||||
public static void Make(GameObject body)
|
public static void Make(GameObject body, string name)
|
||||||
{
|
{
|
||||||
var MM = body.AddComponent<MapMarker>();
|
var MM = body.AddComponent<MapMarker>();
|
||||||
MM.SetValue("_labelID", UITextType.YouAreDeadMessage);
|
MM.SetValue("_labelID", (UITextType)UI.AddToUITable.Add(name));
|
||||||
MM.SetValue("_markerType", MM.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField("Planet").GetValue(MM));
|
MM.SetValue("_markerType", MM.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField("Planet").GetValue(MM));
|
||||||
|
|
||||||
|
Main.Log("Map Marker - body : " + body.name + ", labelID : " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,20 +93,25 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Class1.cs" />
|
<Compile Include="AddToUITable.cs" />
|
||||||
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="MakeAir.cs" />
|
<Compile Include="MakeAir.cs" />
|
||||||
<Compile Include="MakeAmbientLight.cs" />
|
<Compile Include="MakeAmbientLight.cs" />
|
||||||
<Compile Include="MakeAtmosphere.cs" />
|
<Compile Include="MakeAtmosphere.cs" />
|
||||||
<Compile Include="MakeBaseEffects.cs" />
|
<Compile Include="MakeBaseEffects.cs" />
|
||||||
<Compile Include="MakeClouds.cs" />
|
<Compile Include="MakeClouds.cs" />
|
||||||
<Compile Include="MakeFieldDetector.cs" />
|
<Compile Include="MakeFieldDetector.cs" />
|
||||||
|
<Compile Include="MakeGeometry.cs" />
|
||||||
<Compile Include="MakeGravityWell.cs" />
|
<Compile Include="MakeGravityWell.cs" />
|
||||||
<Compile Include="MakeMapMarker.cs" />
|
<Compile Include="MakeMapMarker.cs" />
|
||||||
<Compile Include="MakeOrbitingAstroObject.cs" />
|
<Compile Include="MakeOrbitingAstroObject.cs" />
|
||||||
<Compile Include="MakeRFVolume.cs" />
|
<Compile Include="MakeRFVolume.cs" />
|
||||||
|
<Compile Include="MakeSector.cs" />
|
||||||
<Compile Include="MakeSpawnPoint.cs" />
|
<Compile Include="MakeSpawnPoint.cs" />
|
||||||
<Compile Include="MakeSunOverride.cs" />
|
<Compile Include="MakeSunOverride.cs" />
|
||||||
<Compile Include="MakeVolumes.cs" />
|
<Compile Include="MakeVolumes.cs" />
|
||||||
|
<Compile Include="MakeWater.cs" />
|
||||||
|
<Compile Include="PlanetStructure.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
43
Marshmallow/PlanetConfig.cs
Normal file
43
Marshmallow/PlanetConfig.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Marshmallow
|
||||||
|
{
|
||||||
|
class PlanetConfig
|
||||||
|
{
|
||||||
|
[JsonProperty("settings")]
|
||||||
|
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
public T GetSettingsValue<T>(string key)
|
||||||
|
{
|
||||||
|
bool flag = !this.Settings.ContainsKey(key);
|
||||||
|
T result;
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
Main.Log("Error: setting not found: " + key);
|
||||||
|
result = default(T);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
object obj = this.Settings[key];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JObject jobject;
|
||||||
|
object value = ((jobject = (obj as JObject)) != null) ? jobject["value"] : obj;
|
||||||
|
result = (T)((object)Convert.ChangeType(value, typeof(T)));
|
||||||
|
}
|
||||||
|
catch (InvalidCastException)
|
||||||
|
{
|
||||||
|
Main.Log(string.Format("Error when converting setting {0} of type {1} to type {2}", key, obj.GetType(), typeof(T)));
|
||||||
|
result = default(T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user