mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Remove module & config base classes
This commit is contained in:
parent
e1e630aaef
commit
06588c2645
@ -25,7 +25,7 @@ namespace NewHorizons.Builder.Body
|
||||
{
|
||||
var size = Random.Range(minSize, maxSize);
|
||||
|
||||
var config = new PlanetConfig(null);
|
||||
var config = new PlanetConfig();
|
||||
config.Name = $"{bodyName} Asteroid {i}";
|
||||
config.StarSystem = parentConfig.StarSystem;
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ namespace NewHorizons.Builder.Body
|
||||
if (starModule.Curve != null)
|
||||
{
|
||||
var controller = sunAtmosphere.AddComponent<StarAtmosphereSizeController>();
|
||||
controller.scaleCurve = starModule.ToAnimationCurve();
|
||||
controller.scaleCurve = starModule.GetAnimationCurve();
|
||||
controller.initialSize = starModule.Size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ namespace NewHorizons.Builder.Orbital
|
||||
var gravitationalMass = GetGravitationalMass(primary.Config) + GetGravitationalMass(secondary.Config);
|
||||
|
||||
// Copying it because I don't want to modify the actual config
|
||||
var fakeMassConfig = new PlanetConfig(null);
|
||||
var fakeMassConfig = new PlanetConfig();
|
||||
|
||||
// Now need to fake the 3 values to make it return this mass
|
||||
fakeMassConfig.Base.SurfaceSize = 1;
|
||||
|
||||
@ -7,8 +7,7 @@ namespace NewHorizons.Components
|
||||
{
|
||||
public void Awake()
|
||||
{
|
||||
// TODO: eventually all bodies should have configs
|
||||
var config = new PlanetConfig(null);
|
||||
var config = new PlanetConfig();
|
||||
config.Base.SurfaceSize = 10f;
|
||||
|
||||
var detector = base.transform.GetComponentInChildren<DynamicForceDetector>();
|
||||
|
||||
40
NewHorizons/External/Configs/Config.cs
vendored
40
NewHorizons/External/Configs/Config.cs
vendored
@ -1,40 +0,0 @@
|
||||
using NewHorizons.External.Modules;
|
||||
using NewHorizons.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace NewHorizons.External.Configs
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public Config(Dictionary<string, object> dict)
|
||||
{
|
||||
if (dict == null) return;
|
||||
|
||||
foreach (var item in dict)
|
||||
{
|
||||
var property = GetType().GetProperty(item.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
|
||||
if (property == null) property = GetType().GetProperty(item.Key.ToCamelCase(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
if (property == null) property = GetType().GetProperty(item.Key.ToTitleCase(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
|
||||
if (property != null)
|
||||
{
|
||||
if (property.PropertyType.BaseType == typeof(Module))
|
||||
{
|
||||
if (property.GetValue(this) == null)
|
||||
{
|
||||
var module = Activator.CreateInstance(property.PropertyType);
|
||||
property.SetValue(this, module);
|
||||
}
|
||||
((Module)property.GetValue(this)).Build(item.Value as Dictionary<string, object>);
|
||||
}
|
||||
else
|
||||
{
|
||||
property.SetValue(this, Convert.ChangeType(item.Value, property.PropertyType));
|
||||
}
|
||||
}
|
||||
else Logger.LogError($"{item.Key} {item.Value} is not valid. Is your config formatted correctly?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
5
NewHorizons/External/Configs/PlanetConfig.cs
vendored
5
NewHorizons/External/Configs/PlanetConfig.cs
vendored
@ -1,10 +1,9 @@
|
||||
using NewHorizons.External.Modules;
|
||||
using NewHorizons.External.Modules.VariableSize;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NewHorizons.External.Configs
|
||||
{
|
||||
public class PlanetConfig : Config
|
||||
public class PlanetConfig
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Version { get; set; }
|
||||
@ -33,7 +32,7 @@ namespace NewHorizons.External.Configs
|
||||
public SandModule Sand { get; set; }
|
||||
public FunnelModule Funnel { get; set; }
|
||||
|
||||
public PlanetConfig(Dictionary<string, object> dict) : base(dict)
|
||||
public PlanetConfig()
|
||||
{
|
||||
// Always have to have a base module
|
||||
if (Base == null) Base = new BaseModule();
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
namespace NewHorizons.External.Configs
|
||||
namespace NewHorizons.External.Configs
|
||||
{
|
||||
public class StarSystemConfig : Config
|
||||
public class StarSystemConfig
|
||||
{
|
||||
public bool canEnterViaWarpDrive = true;
|
||||
public bool startHere = false;
|
||||
@ -24,8 +23,5 @@ namespace NewHorizons.External.Configs
|
||||
public string path = null;
|
||||
public bool destroyStarField = false;
|
||||
}
|
||||
|
||||
public StarSystemConfig(Dictionary<string, object> dict) : base(dict) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class AsteroidBeltModule : Module
|
||||
public class AsteroidBeltModule
|
||||
{
|
||||
public float InnerRadius { get; set; }
|
||||
public float OuterRadius { get; set; }
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using NewHorizons.Utility;
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class AtmosphereModule : Module
|
||||
public class AtmosphereModule
|
||||
{
|
||||
public float Size { get; set; }
|
||||
public MColor CloudTint { get; set; }
|
||||
|
||||
2
NewHorizons/External/Modules/BaseModule.cs
vendored
2
NewHorizons/External/Modules/BaseModule.cs
vendored
@ -1,7 +1,7 @@
|
||||
using NewHorizons.Utility;
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class BaseModule : Module
|
||||
public class BaseModule
|
||||
{
|
||||
public bool HasMapMarker { get; set; }
|
||||
public bool HasAmbientLight { get; set; }
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using NewHorizons.Utility;
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class HeightMapModule : Module
|
||||
public class HeightMapModule
|
||||
{
|
||||
public string HeightMap { get; set; }
|
||||
public string TextureMap { get; set; }
|
||||
|
||||
20
NewHorizons/External/Modules/Module.cs
vendored
20
NewHorizons/External/Modules/Module.cs
vendored
@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public abstract class Module
|
||||
{
|
||||
public void Build(Dictionary<string, object> dict)
|
||||
{
|
||||
if (dict == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var item in dict)
|
||||
{
|
||||
var property = GetType().GetProperty(item.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
property.SetValue(this, Convert.ChangeType(item.Value, property.PropertyType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
NewHorizons/External/Modules/OrbitModule.cs
vendored
2
NewHorizons/External/Modules/OrbitModule.cs
vendored
@ -2,7 +2,7 @@
|
||||
using NewHorizons.Utility;
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class OrbitModule : Module, IOrbitalParameters
|
||||
public class OrbitModule : IOrbitalParameters
|
||||
{
|
||||
public float SemiMajorAxis { get; set; }
|
||||
public float Inclination { get; set; }
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
using NewHorizons.Utility;
|
||||
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class ProcGenModule : Module
|
||||
public class ProcGenModule
|
||||
{
|
||||
public float Scale { get; set; }
|
||||
public MColor Color { get; set; }
|
||||
|
||||
2
NewHorizons/External/Modules/PropModule.cs
vendored
2
NewHorizons/External/Modules/PropModule.cs
vendored
@ -1,7 +1,7 @@
|
||||
using NewHorizons.Utility;
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class PropModule : Module
|
||||
public class PropModule
|
||||
{
|
||||
public ScatterInfo[] Scatter;
|
||||
public DetailInfo[] Details;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using NewHorizons.Utility;
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class ShipLogModule : Module
|
||||
public class ShipLogModule
|
||||
{
|
||||
public string xmlFile;
|
||||
public string spriteFolder;
|
||||
|
||||
2
NewHorizons/External/Modules/SignalModule.cs
vendored
2
NewHorizons/External/Modules/SignalModule.cs
vendored
@ -1,7 +1,7 @@
|
||||
using NewHorizons.Utility;
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class SignalModule : Module
|
||||
public class SignalModule
|
||||
{
|
||||
public SignalInfo[] Signals;
|
||||
|
||||
|
||||
2
NewHorizons/External/Modules/SpawnModule.cs
vendored
2
NewHorizons/External/Modules/SpawnModule.cs
vendored
@ -1,7 +1,7 @@
|
||||
using NewHorizons.Utility;
|
||||
namespace NewHorizons.External.Modules
|
||||
{
|
||||
public class SpawnModule : Module
|
||||
public class SpawnModule
|
||||
{
|
||||
public MVector3 PlayerSpawnPoint { get; set; }
|
||||
public MVector3 ShipSpawnPoint { get; set; }
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
namespace NewHorizons.External.Modules.VariableSize
|
||||
{
|
||||
public class VariableSizeModule : Module
|
||||
public class VariableSizeModule
|
||||
{
|
||||
public TimeValuePair[] Curve { get; set; }
|
||||
|
||||
@ -11,7 +11,7 @@ namespace NewHorizons.External.Modules.VariableSize
|
||||
public float Value { get; set; }
|
||||
}
|
||||
|
||||
public AnimationCurve ToAnimationCurve(float size = 1f)
|
||||
public AnimationCurve GetAnimationCurve(float size = 1f)
|
||||
{
|
||||
var curve = new AnimationCurve();
|
||||
foreach (var pair in this.Curve)
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Logger = NewHorizons.Utility.Logger;
|
||||
namespace NewHorizons.External.Modules
|
||||
|
||||
namespace NewHorizons.External
|
||||
{
|
||||
public static class NewHorizonsData
|
||||
{
|
||||
@ -12,7 +12,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Logger = NewHorizons.Utility.Logger;
|
||||
using NewHorizons.External.Modules.VariableSize;
|
||||
|
||||
namespace NewHorizons.Handlers
|
||||
{
|
||||
|
||||
@ -36,11 +36,9 @@ namespace NewHorizons.Handlers
|
||||
{
|
||||
if (centers.Length == 0 && Main.Instance.CurrentStarSystem == "SolarSystem")
|
||||
{
|
||||
var SunConfig = new Dictionary<string, object>
|
||||
{
|
||||
{"name", "Sun"}
|
||||
};
|
||||
_rootNode = ConstructGraph(new NewHorizonsBody(new PlanetConfig(SunConfig), Main.Instance), bodies);
|
||||
var SunConfig = new PlanetConfig();
|
||||
SunConfig.Name = "Sun";
|
||||
_rootNode = ConstructGraph(new NewHorizonsBody(SunConfig, Main.Instance), bodies);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
using NewHorizons.Builder.Props;
|
||||
using NewHorizons.Components;
|
||||
using NewHorizons.External.Configs;
|
||||
using NewHorizons.External.Modules;
|
||||
using NewHorizons.External;
|
||||
using NewHorizons.Handlers;
|
||||
using NewHorizons.Utility;
|
||||
using OWML.Common;
|
||||
@ -95,7 +95,7 @@ namespace NewHorizons
|
||||
|
||||
BodyDict["SolarSystem"] = new List<NewHorizonsBody>();
|
||||
BodyDict["EyeOfTheUniverse"] = new List<NewHorizonsBody>(); // Keep this empty tho fr
|
||||
SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig(null), Instance)
|
||||
SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig(), Instance)
|
||||
{
|
||||
Config =
|
||||
{
|
||||
@ -387,7 +387,7 @@ namespace NewHorizons
|
||||
{
|
||||
// Since we didn't load it earlier there shouldn't be a star system config
|
||||
var starSystemConfig = mod.ModHelper.Storage.Load<StarSystemConfig>($"systems/{config.StarSystem}.json");
|
||||
if (starSystemConfig == null) starSystemConfig = new StarSystemConfig(null);
|
||||
if (starSystemConfig == null) starSystemConfig = new StarSystemConfig();
|
||||
else Logger.LogWarning($"Loaded system config for {config.StarSystem}. Why wasn't this loaded earlier?");
|
||||
|
||||
var system = new NewHorizonsSystem(config.StarSystem, starSystemConfig, mod);
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
using NewHorizons.Builder.Props;
|
||||
using NewHorizons.External.Configs;
|
||||
using NewHorizons.Utility;
|
||||
using OWML.Common;
|
||||
using OWML.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@ -12,21 +13,43 @@ namespace NewHorizons
|
||||
{
|
||||
public class NewHorizonsApi
|
||||
{
|
||||
[Obsolete("Create(Dictionary<string, object> config) is deprecated, please use Create(Dictionary<string, object> config, IModBehaviour mod) instead")]
|
||||
[Obsolete("Create(Dictionary<string, object> config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")]
|
||||
public void Create(Dictionary<string, object> config)
|
||||
{
|
||||
Create(config, null);
|
||||
}
|
||||
|
||||
[Obsolete("Create(Dictionary<string, object> config) is deprecated, please use LoadConfigs(IModBehaviour mod) instead")]
|
||||
public void Create(Dictionary<string, object> config, IModBehaviour mod)
|
||||
{
|
||||
Logger.Log("Recieved API request to create planet " + (string)config["Name"], Logger.LogType.Log);
|
||||
var planetConfig = new PlanetConfig(config);
|
||||
try
|
||||
{
|
||||
var name = (string)config["Name"];
|
||||
|
||||
var body = new NewHorizonsBody(planetConfig, mod ?? Main.Instance);
|
||||
Logger.LogWarning($"Recieved API request to create planet [{name}]");
|
||||
|
||||
if (!Main.BodyDict.ContainsKey(body.Config.StarSystem)) Main.BodyDict.Add(body.Config.StarSystem, new List<NewHorizonsBody>());
|
||||
Main.BodyDict[body.Config.StarSystem].Add(body);
|
||||
if (name == null) return;
|
||||
|
||||
var relativePath = $"temp/{name}.json";
|
||||
var fullPath = Main.Instance.ModHelper.Manifest.ModFolderPath + relativePath;
|
||||
if (!Directory.Exists(Main.Instance.ModHelper.Manifest.ModFolderPath + "temp"))
|
||||
{
|
||||
Directory.CreateDirectory(Main.Instance.ModHelper.Manifest.ModFolderPath + "temp");
|
||||
}
|
||||
JsonHelper.SaveJsonObject(fullPath, config);
|
||||
var body = Main.Instance.LoadConfig(Main.Instance, relativePath);
|
||||
File.Delete(fullPath);
|
||||
|
||||
// Update it to point to their mod for textures and stuff
|
||||
body.Mod = mod ?? Main.Instance;
|
||||
|
||||
if (!Main.BodyDict.ContainsKey(body.Config.StarSystem)) Main.BodyDict.Add(body.Config.StarSystem, new List<NewHorizonsBody>());
|
||||
Main.BodyDict[body.Config.StarSystem].Add(body);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Logger.LogError($"Error in Create API: {ex.Message} {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadConfigs(IModBehaviour mod)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using HarmonyLib;
|
||||
using NewHorizons.Builder.Props;
|
||||
using NewHorizons.Components;
|
||||
using NewHorizons.External.Modules;
|
||||
using NewHorizons.External;
|
||||
using NewHorizons.Handlers;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using NewHorizons.Builder.Props;
|
||||
using NewHorizons.External.Modules;
|
||||
using NewHorizons.External;
|
||||
using NewHorizons.Handlers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user