Finished JSON implementation

This commit is contained in:
Mister_Nebula 2020-04-12 15:31:58 +01:00
parent 6188af8d89
commit 7cec7c3fbb
16 changed files with 83 additions and 152 deletions

View File

@ -1,8 +1,5 @@
using OWML.ModHelper.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Marshmallow.UI

View File

@ -1,13 +1,9 @@
using Newtonsoft.Json;
using OWML.Common;
using OWML.Common;
using OWML.ModHelper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Marshmallow
{
@ -31,8 +27,12 @@ namespace Marshmallow
foreach (var file in Directory.GetFiles(ModHelper.Manifest.ModFolderPath + @"planets\"))
{
var config = ModHelper.Storage.Load<PlanetConfig>(file);
PlanetConfig config = ModHelper.Storage.Load<PlanetConfig>(file.Replace(ModHelper.Manifest.ModFolderPath, ""));
planetList.Add(config);
Log(config.GetSettingsValue<Vector3>("position").ToString());
Log(config.GetSettingsValue<Color32>("fogTint").ToString());
}
if (planetList.Count != 0)
@ -54,52 +54,11 @@ namespace Marshmallow
{
var planet = GenerateBody(config);
if (config.GetSettingsValue<AstroObject>("primaryBody") == Locator.GetAstroObject(AstroObject.Name.Sun))
{
planet.transform.parent = Locator.GetRootTransform();
}
else
{
planet.transform.parent = config.GetSettingsValue<AstroObject>("primaryBody").transform;
}
planet.transform.parent = Locator.GetRootTransform();
planet.transform.position = config.GetSettingsValue<Vector3>("position");
planet.SetActive(true);
}
PlanetStructure inputStructure = new PlanetStructure
{
name = "Mister_Nebula's Custom Planet!",
primaryBody = Locator.GetAstroObject(AstroObject.Name.Sun),
aoType = AstroObject.Type.Planet,
aoName = AstroObject.Name.InvisiblePlanet,
position = new Vector3(0, 0, 30000),
makeSpawnPoint = true,
hasClouds = true,
topCloudSize = 650f,
bottomCloudSize = 600f,
cloudTint = new Color32(0, 75, 15, 128),
hasWater = true,
waterSize = 401f,
hasRain = true,
hasGravity = true,
surfaceAccel = 12f,
hasMapMarker = true,
hasFog = true,
fogTint = new Color32(0, 75, 15, 128),
fogDensity = 0.75f,
hasOrbit = true
};
}
}
@ -111,7 +70,7 @@ namespace Marshmallow
var name = config.GetSettingsValue<string>("name");
var topCloudSize = config.GetSettingsValue<float>("topCloudSize");
var bottomCloudSize = config.GetSettingsValue<float>("topCloudSize");
var bottomCloudSize = config.GetSettingsValue<float>("bottomCloudSize");
GameObject body;
@ -120,7 +79,7 @@ namespace Marshmallow
Body.MakeGeometry.Make(body, groundScale);
General.MakeOrbitingAstroObject.Make(body, config.GetSettingsValue<AstroObject>("primaryBody"), 0.02f, config.GetSettingsValue<bool>("hasGravity"), config.GetSettingsValue<float>("surfaceAcceleration"), groundScale);
General.MakeOrbitingAstroObject.Make(body, 0.02f, config.GetSettingsValue<float>("orbitAngle"), config.GetSettingsValue<bool>("hasGravity"), config.GetSettingsValue<float>("surfaceAcceleration"), groundScale);
General.MakeRFVolume.Make(body);
if (config.GetSettingsValue<bool>("hasMapMarker"))
@ -132,7 +91,7 @@ namespace Marshmallow
if (config.GetSettingsValue<bool>("hasClouds"))
{
Atmosphere.MakeClouds.Make(body, topCloudSize, bottomCloudSize, config.GetSettingsValue<Color>("cloudTint"));
Atmosphere.MakeClouds.Make(body, topCloudSize, bottomCloudSize, config.GetSettingsValue<Color32>("cloudTint"));
Atmosphere.MakeSunOverride.Make(body, topCloudSize, bottomCloudSize, config.GetSettingsValue<float>("waterSize"));
}
@ -146,11 +105,11 @@ namespace Marshmallow
Atmosphere.MakeBaseEffects.Make(body);
Atmosphere.MakeVolumes.Make(body, groundScale, topCloudSize);
General.MakeAmbientLight.Make(body);
Atmosphere.MakeAtmosphere.Make(body, topCloudSize, config.GetSettingsValue<bool>("hasFog"), config.GetSettingsValue<float>("fogDensity"), config.GetSettingsValue<Color>("fogTint"));
Atmosphere.MakeAtmosphere.Make(body, topCloudSize, config.GetSettingsValue<bool>("hasFog"), config.GetSettingsValue<float>("fogDensity"), config.GetSettingsValue<Color32>("fogTint"));
if (config.GetSettingsValue<bool>("makeSpawnPoint"))
{
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 [" + name + "] completed.");

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine;
namespace Marshmallow.General
{

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine;
namespace Marshmallow.Atmosphere
{
@ -101,7 +97,7 @@ namespace Marshmallow.Atmosphere
lodg.SetLODs(lodlist);
lodg.fadeMode = LODFadeMode.None;
*/
//atmo.SetActive(true);
atmoM.SetActive(true);
}

View File

@ -1,9 +1,5 @@
using OWML.ModHelper.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using UnityEngine;
namespace Marshmallow.Atmosphere

View File

@ -14,7 +14,7 @@ namespace Marshmallow.Atmosphere
GameObject cloudsTop = new GameObject();
cloudsTop.SetActive(false);
cloudsTop.transform.parent = cloudsMain.transform;
cloudsTop.transform.localScale = new Vector3(topCloudScale/2, topCloudScale/2, topCloudScale/2);
cloudsTop.transform.localScale = new Vector3(topCloudScale / 2, topCloudScale / 2, topCloudScale / 2);
MeshFilter MF = cloudsTop.AddComponent<MeshFilter>();
MF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
@ -22,6 +22,11 @@ namespace Marshmallow.Atmosphere
MeshRenderer MR = cloudsTop.AddComponent<MeshRenderer>();
MR.materials = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().materials;
foreach (var item in MR.materials)
{
item.SetColor("_Color", cloudTint.Value);
}
RotateTransform RT = cloudsTop.AddComponent<RotateTransform>();
RT.SetValue("_localAxis", Vector3.up);
RT.SetValue("degreesPerSecond", 10);
@ -39,7 +44,7 @@ namespace Marshmallow.Atmosphere
GameObject cloudsBottom = new GameObject();
cloudsBottom.SetActive(false);
cloudsBottom.transform.parent = cloudsMain.transform;
cloudsBottom.transform.localScale = new Vector3(bottomCloudScale/2, bottomCloudScale/2, bottomCloudScale/2);
cloudsBottom.transform.localScale = new Vector3(bottomCloudScale / 2, bottomCloudScale / 2, bottomCloudScale / 2);
TessellatedSphereRenderer TSR = cloudsBottom.AddComponent<TessellatedSphereRenderer>();
TSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup;
@ -64,7 +69,7 @@ namespace Marshmallow.Atmosphere
SphereCollider cloudSC = cloudsFluid.AddComponent<SphereCollider>();
cloudSC.isTrigger = true;
cloudSC.radius = topCloudScale/2;
cloudSC.radius = topCloudScale / 2;
OWShellCollider cloudShell = cloudsFluid.AddComponent<OWShellCollider>();
cloudShell.SetValue("_innerRadius", bottomCloudScale);
@ -82,7 +87,7 @@ namespace Marshmallow.Atmosphere
cloudsFluid.SetActive(true);
cloudsMain.SetActive(true);
Main.Log("Clouds - topCloudScale : " + topCloudScale + ", bottomCloudScale : " + bottomCloudScale + ", cloudTint : " + cloudTint);
//Main.Log("Clouds - topCloudScale : " + topCloudScale + ", bottomCloudScale : " + bottomCloudScale + ", cloudTint : " + cloudTint);
}
}
}

View File

@ -1,9 +1,4 @@
using OWML.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine;
namespace Marshmallow.Body
{

View File

@ -5,7 +5,7 @@ namespace Marshmallow.General
{
static class MakeOrbitingAstroObject
{
public static void Make(GameObject body, AstroObject primaryBody, float angularSpeed, bool hasGravity, float surfaceAccel, float groundSize)
public static void Make(GameObject body, float angularSpeed, float orbitAngle, bool hasGravity, float surfaceAccel, float groundSize)
{
Rigidbody RB = body.AddComponent<Rigidbody>();
RB.mass = 10000;
@ -23,8 +23,8 @@ namespace Marshmallow.General
Main.OWRB.SetValue("_maintainOriginalCenterOfMass", true);
InitialMotion IM = body.AddComponent<InitialMotion>();
IM.SetPrimaryBody(primaryBody.GetAttachedOWRigidbody());
IM.SetValue("_orbitAngle", 0f);
IM.SetPrimaryBody(Locator.GetAstroObject(AstroObject.Name.Sun).GetAttachedOWRigidbody());
IM.SetValue("_orbitAngle", orbitAngle);
IM.SetValue("_isGlobalAxis", false);
IM.SetValue("_initAngularSpeed", angularSpeed);
IM.SetValue("_initLinearSpeed", 0f);
@ -40,8 +40,8 @@ namespace Marshmallow.General
AstroObject AO = body.AddComponent<AstroObject>();
AO.SetValue("_type", AstroObject.Type.Planet);
AO.SetValue("_name", AstroObject.Name.InvisiblePlanet);
AO.SetPrimaryBody(primaryBody);
AO.SetValue("_name", AstroObject.Name.None);
AO.SetPrimaryBody(Locator.GetAstroObject(AstroObject.Name.Sun));
if (hasGravity)
{
GravityVolume GV = MakeGravityWell.Make(body, surfaceAccel, groundSize, groundSize);

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine;
namespace Marshmallow.General
{
@ -16,7 +12,7 @@ namespace Marshmallow.General
spawn.transform.localPosition = position;
Main.Log("Made spawnpoint on [" + body.name + "] at " + position);
//Main.Log("Made spawnpoint on [" + body.name + "] at " + position);
return spawn.AddComponent<SpawnPoint>();
}

View File

@ -13,9 +13,9 @@ namespace Marshmallow.Atmosphere
GiantsDeepSunOverrideVolume vol = sunov.AddComponent<GiantsDeepSunOverrideVolume>();
vol.SetValue("_sector", Main.SECTOR);
vol.SetValue("_cloudsOuterRadius", topCloudScale/2);
vol.SetValue("_cloudsInnerRadius", bottomCloudScale/2);
vol.SetValue("_waterOuterRadius", waterSize/2);
vol.SetValue("_cloudsOuterRadius", topCloudScale / 2);
vol.SetValue("_cloudsInnerRadius", bottomCloudScale / 2);
vol.SetValue("_waterOuterRadius", waterSize / 2);
vol.SetValue("_waterInnerRadius", 402.5f);
sunov.SetActive(true);

View File

@ -1,8 +1,4 @@
using OWML.ModHelper.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Marshmallow.Atmosphere

View File

@ -32,7 +32,7 @@ namespace Marshmallow.Body
GameObject fog1 = new GameObject();
fog1.transform.parent = waterBase.transform;
fog1.transform.localScale = new Vector3(1,1,1);
fog1.transform.localScale = new Vector3(1, 1, 1);
fog1.AddComponent<MeshFilter>().mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
fog1.AddComponent<MeshRenderer>().material = new Material(Shader.Find("Sprites/Default"));
fog1.GetComponent<MeshRenderer>().material.color = new Color32(0, 75, 50, 5);
@ -53,7 +53,7 @@ namespace Marshmallow.Body
waterBase.SetActive(true);
Main.Log("Water - waterScale : " + waterScale);
//Main.Log("Water - waterScale : " + waterScale);
}
}
}

View File

@ -112,7 +112,6 @@
<Compile Include="MakeVolumes.cs" />
<Compile Include="MakeWater.cs" />
<Compile Include="PlanetConfig.cs" />
<Compile Include="PlanetStructure.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -3,18 +3,17 @@ using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Marshmallow
{
class PlanetConfig
{
[JsonProperty("settings")]
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>();
class PlanetConfig
{
[JsonProperty("settings")]
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>();
public T GetSettingsValue<T>(string key)
{
Main.Log("start");
bool flag = !this.Settings.ContainsKey(key);
T result;
if (flag)
@ -29,7 +28,47 @@ namespace Marshmallow
{
JObject jobject;
object value = ((jobject = (obj as JObject)) != null) ? jobject["value"] : obj;
result = (T)((object)Convert.ChangeType(value, typeof(T)));
if (obj.GetType() == typeof(JArray))
{
if (typeof(T) == typeof(Vector2))
{
JArray array = (JArray)obj;
float[] items = array.Select(jv => (float)jv).ToArray();
Vector2 output = new Vector2(items[0], items[1]);
return (T)Convert.ChangeType(output, typeof(T));
}
if (typeof(T) == typeof(Vector3))
{
JArray array = (JArray)obj;
float[] items = array.Select(jv => (float)jv).ToArray();
Vector3 output = new Vector3(items[0], items[1], items[2]);
return (T)Convert.ChangeType(output, typeof(T));
}
if (typeof(T) == typeof(Vector4) || typeof(T) == typeof(Color))
{
JArray array = (JArray)obj;
float[] items = array.Select(jv => (float)jv).ToArray();
Vector4 output = new Vector4(items[0], items[1], items[2], items[3]);
return (T)Convert.ChangeType(output, typeof(T));
}
if (typeof(T) == typeof(Color32))
{
JArray array = (JArray)obj;
byte[] items = array.Select(jv => (byte)jv).ToArray();
Color32 output = new Color32(items[0], items[1], items[2], items[3]);
return (T)Convert.ChangeType(output, typeof(T));
}
}
result = (T)Convert.ChangeType(value, typeof(T));
}
catch (InvalidCastException)
{

View File

@ -1,42 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Marshmallow
{
public class PlanetStructure
{
public string name;
public AstroObject primaryBody;
public AstroObject.Type aoType;
public AstroObject.Name aoName;
public Vector3 position;
public bool makeSpawnPoint = false;
public bool hasClouds = false;
public float? topCloudSize = null;
public float? bottomCloudSize = null;
public Color? cloudTint = null;
public bool hasWater = false;
public float? waterSize = null;
public bool hasRain = false;
public bool hasGravity = false;
public float surfaceAccel = 1f;
public bool hasMapMarker = false;
public bool hasFog = false;
public Color fogTint = Color.white;
public float fogDensity = 0.3f;
public bool hasOrbit = false;
}
}

View File

@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following