diff --git a/Marshmallow/Atmosphere/MakeAir.cs b/Marshmallow/Atmosphere/MakeAir.cs index f42f7413..02d09b53 100644 --- a/Marshmallow/Atmosphere/MakeAir.cs +++ b/Marshmallow/Atmosphere/MakeAir.cs @@ -7,53 +7,53 @@ namespace Marshmallow.Atmosphere { public static void Make(GameObject body, float airScale, bool isRaining) { - GameObject air = new GameObject(); - air.layer = 17; - air.SetActive(false); - air.transform.parent = body.transform; + GameObject airGO = new GameObject(); + airGO.SetActive(false); + airGO.layer = 17; + airGO.transform.parent = body.transform; - SphereCollider atmoSC = air.AddComponent(); - atmoSC.isTrigger = true; - atmoSC.radius = airScale; + SphereCollider SC = airGO.AddComponent(); + SC.isTrigger = true; + SC.radius = airScale; - SimpleFluidVolume sfv = air.AddComponent(); - sfv.SetValue("_layer", 5); - sfv.SetValue("_priority", 1); - sfv.SetValue("_density", 1.2f); - sfv.SetValue("_fluidType", FluidVolume.Type.AIR); - sfv.SetValue("_allowShipAutoroll", true); - sfv.SetValue("_disableOnStart", false); + SimpleFluidVolume SFV = airGO.AddComponent(); + SFV.SetValue("_layer", 5); + SFV.SetValue("_priority", 1); + SFV.SetValue("_density", 1.2f); + SFV.SetValue("_fluidType", FluidVolume.Type.AIR); + SFV.SetValue("_allowShipAutoroll", true); + SFV.SetValue("_disableOnStart", false); if (isRaining) { - VisorRainEffectVolume vref = air.AddComponent(); - vref.SetValue("_rainDirection", VisorRainEffectVolume.RainDirection.Radial); - vref.SetValue("_layer", 0); - vref.SetValue("_priority", 0); + VisorRainEffectVolume VREF = airGO.AddComponent(); + VREF.SetValue("_rainDirection", VisorRainEffectVolume.RainDirection.Radial); + VREF.SetValue("_layer", 0); + VREF.SetValue("_priority", 0); - AudioSource auds = air.AddComponent(); - auds.mute = false; - auds.bypassEffects = false; - auds.bypassListenerEffects = false; - auds.bypassReverbZones = false; - auds.playOnAwake = false; - auds.loop = true; - auds.priority = 128; - auds.volume = 0.35f; - auds.pitch = 1f; - auds.panStereo = 0f; - auds.spatialBlend = 0f; - auds.reverbZoneMix = 1f; + AudioSource AS = airGO.AddComponent(); + AS.mute = false; + AS.bypassEffects = false; + AS.bypassListenerEffects = false; + AS.bypassReverbZones = false; + AS.playOnAwake = false; + AS.loop = true; + AS.priority = 128; + AS.volume = 0.35f; + AS.pitch = 1f; + AS.panStereo = 0f; + AS.spatialBlend = 0f; + AS.reverbZoneMix = 1f; - OWAudioSource owas = air.AddComponent(); - owas.SetAudioLibraryClip(AudioType.GD_RainAmbient_LP); - owas.SetClipSelectionType(OWAudioSource.ClipSelectionOnPlay.RANDOM); - owas.SetTrack(OWAudioMixer.TrackName.Environment); + OWAudioSource OWAS = airGO.AddComponent(); + OWAS.SetAudioLibraryClip(AudioType.GD_RainAmbient_LP); + OWAS.SetClipSelectionType(OWAudioSource.ClipSelectionOnPlay.RANDOM); + OWAS.SetTrack(OWAudioMixer.TrackName.Environment); - /*AudioVolume av = */air.AddComponent(); + /*AudioVolume av = */airGO.AddComponent(); } - air.SetActive(true); + airGO.SetActive(true); } } } diff --git a/Marshmallow/Atmosphere/MakeAtmosphere.cs b/Marshmallow/Atmosphere/MakeAtmosphere.cs index bdf43993..c37abcab 100644 --- a/Marshmallow/Atmosphere/MakeAtmosphere.cs +++ b/Marshmallow/Atmosphere/MakeAtmosphere.cs @@ -1,45 +1,47 @@ -using UnityEngine; +using Marshmallow.External; +using UnityEngine; +using Logger = Marshmallow.Utility.Logger; namespace Marshmallow.Atmosphere { static class MakeAtmosphere { - public static void Make(GameObject body, float topCloudScale, bool hasFog, float fogDensity, Color32 fogTint) + public static void Make(GameObject body, IPlanetConfig config) { - topCloudScale /= 2; + GameObject atmoGO = new GameObject(); + atmoGO.SetActive(false); + atmoGO.name = "Atmosphere"; + atmoGO.transform.parent = body.transform; - GameObject atmoM = new GameObject(); - atmoM.SetActive(false); - atmoM.name = "Atmosphere"; - atmoM.transform.parent = body.transform; - - if (hasFog) + if (config.HasFog) { - GameObject fog = new GameObject(); - fog.SetActive(false); - fog.name = "FogSphere"; - fog.transform.parent = atmoM.transform; - fog.transform.localScale = new Vector3(topCloudScale + 10, topCloudScale + 10, topCloudScale + 10); + GameObject fogGO = new GameObject(); + fogGO.SetActive(false); + fogGO.name = "FogSphere"; + fogGO.transform.parent = atmoGO.transform; + fogGO.transform.localScale = new Vector3((config.TopCloudSize / 2) + 10, (config.TopCloudSize / 2) + 10, (config.TopCloudSize / 2) + 10); - MeshFilter mf = fog.AddComponent(); - mf.mesh = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent().mesh; + MeshFilter MF = fogGO.AddComponent(); + MF.mesh = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent().mesh; - MeshRenderer mr = fog.AddComponent(); - mr.materials = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent().materials; - mr.allowOcclusionWhenDynamic = true; + MeshRenderer MR = fogGO.AddComponent(); + MR.materials = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent().materials; + MR.allowOcclusionWhenDynamic = true; - PlanetaryFogController pfc = fog.AddComponent(); - pfc.fogLookupTexture = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent().fogLookupTexture; - pfc.fogRadius = topCloudScale + 10; - pfc.fogDensity = fogDensity; - pfc.fogExponent = 1f; - pfc.fogColorRampTexture = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent().fogColorRampTexture; - pfc.fogColorRampIntensity = 1f; - pfc.fogTint = fogTint; + PlanetaryFogController PFC = fogGO.AddComponent(); + PFC.fogLookupTexture = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent().fogLookupTexture; + PFC.fogRadius = (config.TopCloudSize / 2) + 10; + PFC.fogDensity = config.FogDensity; + PFC.fogExponent = 1f; + PFC.fogColorRampTexture = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent().fogColorRampTexture; + PFC.fogColorRampIntensity = 1f; + PFC.fogTint = config.FogTint.ToColor32(); - fog.SetActive(true); + fogGO.SetActive(true); } + Logger.Log("Re-add LOD atmosphere!", Logger.LogType.Todo); + /* GameObject atmo = new GameObject(); atmo.SetActive(false); @@ -99,7 +101,7 @@ namespace Marshmallow.Atmosphere */ //atmo.SetActive(true); - atmoM.SetActive(true); + atmoGO.SetActive(true); } } } diff --git a/Marshmallow/Atmosphere/MakeBaseEffects.cs b/Marshmallow/Atmosphere/MakeBaseEffects.cs index 8b966c59..e1f2f941 100644 --- a/Marshmallow/Atmosphere/MakeBaseEffects.cs +++ b/Marshmallow/Atmosphere/MakeBaseEffects.cs @@ -6,42 +6,42 @@ namespace Marshmallow.Atmosphere { static class MakeBaseEffects { - public static void Make(GameObject body) + public static void Make(GameObject body, Sector sector) { - GameObject main = new GameObject(); - main.SetActive(false); - main.transform.parent = body.transform; + GameObject effectsGO = new GameObject(); + effectsGO.SetActive(false); + effectsGO.transform.parent = body.transform; - SectorCullGroup maincull = main.AddComponent(); - maincull.SetValue("_sector", Main.SECTOR); - maincull.SetValue("_particleSystemSuspendMode", CullGroup.ParticleSystemSuspendMode.Stop); - maincull.SetValue("_occlusionCulling", false); - maincull.SetValue("_dynamicCullingBounds", false); - maincull.SetValue("_waitForStreaming", false); + SectorCullGroup SCG = effectsGO.AddComponent(); + SCG.SetValue("_sector", sector); + SCG.SetValue("_particleSystemSuspendMode", CullGroup.ParticleSystemSuspendMode.Stop); + SCG.SetValue("_occlusionCulling", false); + SCG.SetValue("_dynamicCullingBounds", false); + SCG.SetValue("_waitForStreaming", false); - GameObject rain = new GameObject(); - rain.SetActive(false); - rain.transform.parent = main.transform; + GameObject rainGO = new GameObject(); + rainGO.SetActive(false); + rainGO.transform.parent = effectsGO.transform; /*ParticleSystem ps = */GameObject.Instantiate(GameObject.Find("Effects_GD_Rain").GetComponent()); - VectionFieldEmitter vfe = rain.AddComponent(); - vfe.fieldRadius = 20f; - vfe.particleCount = 10; - vfe.emitOnLeadingEdge = false; - vfe.emitDirection = VectionFieldEmitter.EmitDirection.Radial; - vfe.reverseDir = true; - vfe.SetValue("_affectingForces", new ForceVolume[0]); - vfe.SetValue("_applyForcePerParticle", false); + VectionFieldEmitter VFE = rainGO.AddComponent(); + VFE.fieldRadius = 20f; + VFE.particleCount = 10; + VFE.emitOnLeadingEdge = false; + VFE.emitDirection = VectionFieldEmitter.EmitDirection.Radial; + VFE.reverseDir = true; + VFE.SetValue("_affectingForces", new ForceVolume[0]); + VFE.SetValue("_applyForcePerParticle", false); - PlanetaryVectionController pvc = rain.AddComponent(); - pvc.SetValue("_followTarget", pvc.GetType().GetNestedType("FollowTarget", BindingFlags.NonPublic).GetField("Player").GetValue(pvc)); - pvc.SetValue("_activeInSector", Main.SECTOR); + PlanetaryVectionController PVC = rainGO.AddComponent(); + PVC.SetValue("_followTarget", PVC.GetType().GetNestedType("FollowTarget", BindingFlags.NonPublic).GetField("Player").GetValue(PVC)); + PVC.SetValue("_activeInSector", sector); - rain.GetComponent().material = GameObject.Find("Effects_GD_Rain").GetComponent().material; + rainGO.GetComponent().material = GameObject.Find("Effects_GD_Rain").GetComponent().material; - main.SetActive(true); - rain.SetActive(true); + effectsGO.SetActive(true); + rainGO.SetActive(true); } } } diff --git a/Marshmallow/Atmosphere/MakeClouds.cs b/Marshmallow/Atmosphere/MakeClouds.cs index 9d7238f2..8ad2608d 100644 --- a/Marshmallow/Atmosphere/MakeClouds.cs +++ b/Marshmallow/Atmosphere/MakeClouds.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json.Linq; +using Marshmallow.External; +using Newtonsoft.Json.Linq; using OWML.ModHelper.Events; using UnityEngine; @@ -6,32 +7,32 @@ namespace Marshmallow.Atmosphere { static class MakeClouds { - public static void Make(GameObject body, float topCloudScale, float bottomCloudScale, Color32 lowerCloudTint, Color32 upperCloudTint) + public static void Make(GameObject body, Sector sector, IPlanetConfig config) { - GameObject cloudsMain = new GameObject(); - cloudsMain.SetActive(false); - cloudsMain.transform.parent = body.transform; + GameObject cloudsMainGO = new GameObject(); + cloudsMainGO.SetActive(false); + cloudsMainGO.transform.parent = body.transform; - GameObject cloudsTop = new GameObject(); - cloudsTop.SetActive(false); - cloudsTop.transform.parent = cloudsMain.transform; - cloudsTop.transform.localScale = new Vector3(topCloudScale / 2, topCloudScale / 2, topCloudScale / 2); + GameObject cloudsTopGO = new GameObject(); + cloudsTopGO.SetActive(false); + cloudsTopGO.transform.parent = cloudsMainGO.transform; + cloudsTopGO.transform.localScale = new Vector3(config.TopCloudSize / 2, config.TopCloudSize / 2, config.TopCloudSize / 2); - MeshFilter MF = cloudsTop.AddComponent(); - MF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; + MeshFilter topMF = cloudsTopGO.AddComponent(); + topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; - MeshRenderer MR = cloudsTop.AddComponent(); - MR.materials = GameObject.Find("CloudsTopLayer_GD").GetComponent().materials; + MeshRenderer topMR = cloudsTopGO.AddComponent(); + topMR.materials = GameObject.Find("CloudsTopLayer_GD").GetComponent().materials; - foreach (var item in MR.materials) + foreach (var material in topMR.materials) { - item.SetColor("_Color", upperCloudTint); + material.SetColor("_Color", config.TopCloudTint.ToColor32()); } - RotateTransform RT = cloudsTop.AddComponent(); - RT.SetValue("_localAxis", Vector3.up); - RT.SetValue("degreesPerSecond", 10); - RT.SetValue("randomizeRotationRate", false); + RotateTransform topRT = cloudsTopGO.AddComponent(); + topRT.SetValue("_localAxis", Vector3.up); + topRT.SetValue("degreesPerSecond", 10); + topRT.SetValue("randomizeRotationRate", false); /* SectorCullGroup scg = cloudsTop.AddComponent(); @@ -42,53 +43,50 @@ namespace Marshmallow.Atmosphere scg.SetValue("_waitForStreaming", false); */ - GameObject cloudsBottom = new GameObject(); - cloudsBottom.SetActive(false); - cloudsBottom.transform.parent = cloudsMain.transform; - cloudsBottom.transform.localScale = new Vector3(bottomCloudScale / 2, bottomCloudScale / 2, bottomCloudScale / 2); + GameObject cloudsBottomGO = new GameObject(); + cloudsBottomGO.SetActive(false); + cloudsBottomGO.transform.parent = cloudsMainGO.transform; + cloudsBottomGO.transform.localScale = new Vector3(config.BottomCloudSize / 2, config.BottomCloudSize / 2, config.BottomCloudSize / 2); - TessellatedSphereRenderer TSR = cloudsBottom.AddComponent(); - TSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent().tessellationMeshGroup; - TSR.sharedMaterials = GameObject.Find("CloudsBottomLayer_GD").GetComponent().sharedMaterials; + TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent(); + bottomTSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent().tessellationMeshGroup; + bottomTSR.sharedMaterials = GameObject.Find("CloudsBottomLayer_GD").GetComponent().sharedMaterials; + bottomTSR.maxLOD = 6; + bottomTSR.LODBias = 0; + bottomTSR.LODRadius = 1f; - foreach (var item in TSR.sharedMaterials) + foreach (Material material in bottomTSR.sharedMaterials) { - item.SetColor("_Color", lowerCloudTint); + material.SetColor("_Color", config.BottomCloudTint.ToColor32()); } - TSR.maxLOD = 6; - TSR.LODBias = 0; - TSR.LODRadius = 1f; + TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent(); + bottomTSST.SetValue("_sector", sector); - TessSphereSectorToggle TSST = cloudsBottom.AddComponent(); - TSST.SetValue("_sector", Main.SECTOR); + GameObject cloudsFluidGO = new GameObject(); + cloudsFluidGO.SetActive(false); + cloudsFluidGO.layer = 17; + cloudsFluidGO.transform.parent = cloudsMainGO.transform; - GameObject cloudsFluid = new GameObject(); - cloudsFluid.layer = 17; - cloudsFluid.SetActive(false); - cloudsFluid.transform.parent = cloudsMain.transform; + SphereCollider fluidSC = cloudsFluidGO.AddComponent(); + fluidSC.isTrigger = true; + fluidSC.radius = config.TopCloudSize / 2; - SphereCollider cloudSC = cloudsFluid.AddComponent(); - cloudSC.isTrigger = true; - cloudSC.radius = topCloudScale / 2; + OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent(); + fluidOWSC.SetValue("_innerRadius", config.BottomCloudSize); - OWShellCollider cloudShell = cloudsFluid.AddComponent(); - cloudShell.SetValue("_innerRadius", bottomCloudScale); + CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent(); + fluidCLFV.SetValue("_layer", 5); + fluidCLFV.SetValue("_priority", 1); + fluidCLFV.SetValue("_density", 1.2f); + fluidCLFV.SetValue("_fluidType", FluidVolume.Type.CLOUD); + fluidCLFV.SetValue("_allowShipAutoroll", true); + fluidCLFV.SetValue("_disableOnStart", false); - CloudLayerFluidVolume cloudLayer = cloudsFluid.AddComponent(); - cloudLayer.SetValue("_layer", 5); - cloudLayer.SetValue("_priority", 1); - cloudLayer.SetValue("_density", 1.2f); - cloudLayer.SetValue("_fluidType", FluidVolume.Type.CLOUD); - cloudLayer.SetValue("_allowShipAutoroll", true); - cloudLayer.SetValue("_disableOnStart", false); - - cloudsTop.SetActive(true); - cloudsBottom.SetActive(true); - cloudsFluid.SetActive(true); - cloudsMain.SetActive(true); - - Main.Log("Clouds - topCloudScale : " + topCloudScale + ", bottomCloudScale : " + bottomCloudScale + ", cloudTint : " + lowerCloudTint); + cloudsTopGO.SetActive(true); + cloudsBottomGO.SetActive(true); + cloudsFluidGO.SetActive(true); + cloudsMainGO.SetActive(true); } } } diff --git a/Marshmallow/Atmosphere/MakeSunOverride.cs b/Marshmallow/Atmosphere/MakeSunOverride.cs index d8eef200..47ac7dff 100644 --- a/Marshmallow/Atmosphere/MakeSunOverride.cs +++ b/Marshmallow/Atmosphere/MakeSunOverride.cs @@ -1,24 +1,25 @@ -using OWML.ModHelper.Events; +using Marshmallow.External; +using OWML.ModHelper.Events; using UnityEngine; namespace Marshmallow.Atmosphere { static class MakeSunOverride { - public static void Make(GameObject body, float topCloudScale, float bottomCloudScale, float waterSize) + public static void Make(GameObject body, Sector sector, IPlanetConfig config) { - GameObject sunov = new GameObject(); - sunov.SetActive(false); - sunov.transform.parent = body.transform; + GameObject overrideGO = new GameObject(); + overrideGO.SetActive(false); + overrideGO.transform.parent = body.transform; - GiantsDeepSunOverrideVolume vol = sunov.AddComponent(); - vol.SetValue("_sector", Main.SECTOR); - vol.SetValue("_cloudsOuterRadius", topCloudScale / 2); - vol.SetValue("_cloudsInnerRadius", bottomCloudScale / 2); - vol.SetValue("_waterOuterRadius", waterSize / 2); - vol.SetValue("_waterInnerRadius", 402.5f); + GiantsDeepSunOverrideVolume GDSOV = overrideGO.AddComponent(); + GDSOV.SetValue("_sector", sector); + GDSOV.SetValue("_cloudsOuterRadius", config.TopCloudSize / 2); + GDSOV.SetValue("_cloudsInnerRadius", config.BottomCloudSize / 2); + GDSOV.SetValue("_waterOuterRadius", config.WaterSize / 2); + GDSOV.SetValue("_waterInnerRadius", 402.5f); - sunov.SetActive(true); + overrideGO.SetActive(true); } } } diff --git a/Marshmallow/Atmosphere/MakeVolumes.cs b/Marshmallow/Atmosphere/MakeVolumes.cs index b5867be7..f162b791 100644 --- a/Marshmallow/Atmosphere/MakeVolumes.cs +++ b/Marshmallow/Atmosphere/MakeVolumes.cs @@ -1,38 +1,39 @@ -using OWML.ModHelper.Events; +using Marshmallow.External; +using OWML.ModHelper.Events; using UnityEngine; namespace Marshmallow.Atmosphere { static class MakeVolumes { - public static void Make(GameObject body, float groundSize, float topCloudSize) + public static void Make(GameObject body, IPlanetConfig config) { - GameObject volumes = new GameObject(); - volumes.SetActive(false); - volumes.transform.parent = body.transform; + GameObject volumesGO = new GameObject(); + volumesGO.SetActive(false); + volumesGO.transform.parent = body.transform; - GameObject ruleset = new GameObject(); - ruleset.transform.parent = volumes.transform; + GameObject rulesetGO = new GameObject(); + rulesetGO.transform.parent = volumesGO.transform; - SphereShape ss = ruleset.AddComponent(); - ss.SetCollisionMode(Shape.CollisionMode.Volume); - ss.SetLayer(Shape.Layer.Sector); - ss.layerMask = -1; - ss.pointChecksOnly = true; - ss.radius = topCloudSize; + SphereShape SS = rulesetGO.AddComponent(); + SS.SetCollisionMode(Shape.CollisionMode.Volume); + SS.SetLayer(Shape.Layer.Sector); + SS.layerMask = -1; + SS.pointChecksOnly = true; + SS.radius = config.TopCloudSize; - /*OWTriggerVolume trigvol = */ruleset.AddComponent(); + /*OWTriggerVolume trigvol = */rulesetGO.AddComponent(); - PlanetoidRuleset prule = ruleset.AddComponent(); - prule.SetValue("_altitudeFloor", groundSize); - prule.SetValue("_altitudeCeiling", topCloudSize); + PlanetoidRuleset PR = rulesetGO.AddComponent(); + PR.SetValue("_altitudeFloor", config.GroundSize); + PR.SetValue("_altitudeCeiling", config.TopCloudSize); - EffectRuleset er = ruleset.AddComponent(); - er.SetValue("_type", EffectRuleset.BubbleType.Underwater); - er.SetValue("_material", GameObject.Find("RulesetVolumes_GD").GetComponent().GetValue("_material")); - er.SetValue("_cloudMaterial", GameObject.Find("RulesetVolumes_GD").GetComponent().GetValue("_cloudMaterial")); + EffectRuleset ER = rulesetGO.AddComponent(); + ER.SetValue("_type", EffectRuleset.BubbleType.Underwater); + ER.SetValue("_material", GameObject.Find("RulesetVolumes_GD").GetComponent().GetValue("_material")); + ER.SetValue("_cloudMaterial", GameObject.Find("RulesetVolumes_GD").GetComponent().GetValue("_cloudMaterial")); - volumes.SetActive(true); + volumesGO.SetActive(true); } } } diff --git a/Marshmallow/Body/MakeGeometry.cs b/Marshmallow/Body/MakeGeometry.cs index d155b941..8c0a2252 100644 --- a/Marshmallow/Body/MakeGeometry.cs +++ b/Marshmallow/Body/MakeGeometry.cs @@ -6,14 +6,12 @@ namespace Marshmallow.Body { public static void Make(GameObject body, float groundScale) { - - - GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); - sphere.transform.parent = body.transform; - sphere.transform.localScale = new Vector3(groundScale / 2, groundScale / 2, groundScale / 2); - sphere.GetComponent().mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; - sphere.GetComponent().radius = 1f; - sphere.SetActive(true); + GameObject groundGO = GameObject.CreatePrimitive(PrimitiveType.Sphere); + groundGO.transform.parent = body.transform; + groundGO.transform.localScale = new Vector3(groundScale / 2, groundScale / 2, groundScale / 2); + groundGO.GetComponent().mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; + groundGO.GetComponent().radius = 1f; + groundGO.SetActive(true); /* GameObject sphere = new GameObject(); diff --git a/Marshmallow/Body/MakeWater.cs b/Marshmallow/Body/MakeWater.cs index 89ed1c60..8095ae23 100644 --- a/Marshmallow/Body/MakeWater.cs +++ b/Marshmallow/Body/MakeWater.cs @@ -1,32 +1,33 @@ -using OWML.ModHelper.Events; +using Marshmallow.External; +using OWML.ModHelper.Events; using UnityEngine; namespace Marshmallow.Body { static class MakeWater { - public static void Make(GameObject body, float waterScale) + public static void Make(GameObject body, Sector sector, IPlanetConfig config) { - GameObject waterBase = new GameObject(); - waterBase.SetActive(false); - waterBase.layer = 15; - waterBase.transform.parent = body.transform; - waterBase.transform.localScale = new Vector3(waterScale / 2, waterScale / 2, waterScale / 2); - waterBase.DestroyAllComponents(); + GameObject waterGO = new GameObject(); + waterGO.SetActive(false); + waterGO.layer = 15; + waterGO.transform.parent = body.transform; + waterGO.transform.localScale = new Vector3(config.WaterSize / 2, config.WaterSize / 2, config.WaterSize / 2); + waterGO.DestroyAllComponents(); - TessellatedSphereRenderer tsr = waterBase.AddComponent(); - tsr.tessellationMeshGroup = GameObject.Find("Ocean_GD").GetComponent().tessellationMeshGroup; - tsr.sharedMaterials = GameObject.Find("Ocean_GD").GetComponent().sharedMaterials; - tsr.maxLOD = 7; - tsr.LODBias = 2; - tsr.LODRadius = 2f; + TessellatedSphereRenderer TSR = waterGO.AddComponent(); + TSR.tessellationMeshGroup = GameObject.Find("Ocean_GD").GetComponent().tessellationMeshGroup; + TSR.sharedMaterials = GameObject.Find("Ocean_GD").GetComponent().sharedMaterials; + TSR.maxLOD = 7; + TSR.LODBias = 2; + TSR.LODRadius = 2f; - TessSphereSectorToggle toggle = waterBase.AddComponent(); - toggle.SetValue("_sector", Main.SECTOR); + TessSphereSectorToggle TSST = waterGO.AddComponent(); + TSST.SetValue("_sector", sector); - OceanEffectController effectC = waterBase.AddComponent(); - effectC.SetValue("_sector", Main.SECTOR); - effectC.SetValue("_ocean", tsr); + OceanEffectController OEC = waterGO.AddComponent(); + OEC.SetValue("_sector", sector); + OEC.SetValue("_ocean", TSR); // Because assetbundles were a bitch... @@ -55,9 +56,9 @@ namespace Marshmallow.Body */ - waterBase.SetActive(true); + waterGO.SetActive(true); - //Main.Log("Water - waterScale : " + waterScale); + //Logger.Log("Water - waterScale : " + waterScale); } } } diff --git a/Marshmallow/External/IPlanetConfig.cs b/Marshmallow/External/IPlanetConfig.cs index 43fc33dd..f79c0605 100644 --- a/Marshmallow/External/IPlanetConfig.cs +++ b/Marshmallow/External/IPlanetConfig.cs @@ -10,25 +10,26 @@ namespace Marshmallow.External { public interface IPlanetConfig { - string name { get; } - MVector3 position { get; } - int orbitAngle { get; } - string primaryBody { get; } - bool hasSpawnPoint { get; } - bool hasClouds { get; } - float topCloudSize { get; } - float bottomCloudSize { get; } - MColor32 topCloudTint { get; } - MColor32 bottomCloudTint { get; } - bool hasWater { get; } - float waterSize { get; } - bool hasRain { get; } - bool hasGravity { get; } - float surfaceAcceleration { get; } - bool hasMapMarker { get; } - bool hasFog { get; } - MColor32 fogTint { get; } - float fogDensity { get; } - float groundSize { get; } + string Name { get; } + MVector3 Position { get; } + int OrbitAngle { get; } + string PrimaryBody { get; } + bool IsMoon { get; } + bool HasSpawnPoint { get; } + bool HasClouds { get; } + float TopCloudSize { get; } + float BottomCloudSize { get; } + MColor32 TopCloudTint { get; } + MColor32 BottomCloudTint { get; } + bool HasWater { get; } + float WaterSize { get; } + bool HasRain { get; } + bool HasGravity { get; } + float SurfaceAcceleration { get; } + bool HasMapMarker { get; } + bool HasFog { get; } + MColor32 FogTint { get; } + float FogDensity { get; } + float GroundSize { get; } } } diff --git a/Marshmallow/External/PlanetConfig.cs b/Marshmallow/External/PlanetConfig.cs index fae4f198..6f44f80e 100644 --- a/Marshmallow/External/PlanetConfig.cs +++ b/Marshmallow/External/PlanetConfig.cs @@ -11,25 +11,26 @@ namespace Marshmallow.External { public class PlanetConfig : IPlanetConfig { - public string name { get; set; } - public MVector3 position { get; set; } - public int orbitAngle { get; set; } - public string primaryBody { get; set; } - public bool hasSpawnPoint { get; set; } - public bool hasClouds { get; set; } - public float topCloudSize { get; set; } - public float bottomCloudSize { get; set; } - public MColor32 topCloudTint { get; set; } - public MColor32 bottomCloudTint { get; set; } - public bool hasWater { get; set; } - public float waterSize { get; set; } - public bool hasRain { get; set; } - public bool hasGravity { get; set; } - public float surfaceAcceleration { get; set; } - public bool hasMapMarker { get; set; } - public bool hasFog { get; set; } - public MColor32 fogTint { get; set; } - public float fogDensity { get; set; } - public float groundSize { get; set; } + public string Name { get; set; } + public MVector3 Position { get; set; } + public int OrbitAngle { get; set; } + public string PrimaryBody { get; set; } + public bool IsMoon { get; set; } + public bool HasSpawnPoint { get; set; } + public bool HasClouds { get; set; } + public float TopCloudSize { get; set; } + public float BottomCloudSize { get; set; } + public MColor32 TopCloudTint { get; set; } + public MColor32 BottomCloudTint { get; set; } + public bool HasWater { get; set; } + public float WaterSize { get; set; } + public bool HasRain { get; set; } + public bool HasGravity { get; set; } + public float SurfaceAcceleration { get; set; } + public bool HasMapMarker { get; set; } + public bool HasFog { get; set; } + public MColor32 FogTint { get; set; } + public float FogDensity { get; set; } + public float GroundSize { get; set; } } } diff --git a/Marshmallow/General/MakeAmbientLight.cs b/Marshmallow/General/MakeAmbientLight.cs index c9f1f37d..9c134270 100644 --- a/Marshmallow/General/MakeAmbientLight.cs +++ b/Marshmallow/General/MakeAmbientLight.cs @@ -4,23 +4,24 @@ namespace Marshmallow.General { static class MakeAmbientLight { - public static void Make(GameObject body) + public static void Make(GameObject body, Sector sector) { - GameObject light = new GameObject(); - light.SetActive(false); - light.transform.parent = body.transform; - Light l = light.AddComponent(); - l.type = LightType.Point; - l.range = 700f; - l.color = Color.red; - l.intensity = 0.8f; - l.shadows = LightShadows.None; - l.cookie = GameObject.Find("AmbientLight_GD").GetComponent().cookie; + GameObject lightGO = new GameObject(); + lightGO.SetActive(false); + lightGO.transform.parent = body.transform; - SectorLightsCullGroup cg = light.AddComponent(); - cg.SetSector(Main.SECTOR); + Light L = lightGO.AddComponent(); + L.type = LightType.Point; + L.range = 700f; + L.color = Color.red; + L.intensity = 0.8f; + L.shadows = LightShadows.None; + L.cookie = GameObject.Find("AmbientLight_GD").GetComponent().cookie; - light.SetActive(true); + SectorLightsCullGroup SLCG = lightGO.AddComponent(); + SLCG.SetSector(sector); + + lightGO.SetActive(true); } } } diff --git a/Marshmallow/General/MakeFieldDetector.cs b/Marshmallow/General/MakeFieldDetector.cs index 51473027..5aab6314 100644 --- a/Marshmallow/General/MakeFieldDetector.cs +++ b/Marshmallow/General/MakeFieldDetector.cs @@ -1,24 +1,26 @@ -using OWML.ModHelper.Events; +using Marshmallow.External; +using OWML.ModHelper.Events; using UnityEngine; namespace Marshmallow.General { static class MakeFieldDetector { - public static void Make(GameObject body) + public static void Make(GameObject body, AstroObject primaryBody, IPlanetConfig config) { - GameObject FieldDetector = new GameObject(); - FieldDetector.SetActive(false); - FieldDetector.name = "FieldDetector"; - FieldDetector.transform.parent = body.transform; - FieldDetector.layer = 20; + GameObject detectorGO = new GameObject(); + detectorGO.SetActive(false); + detectorGO.name = "FieldDetector"; + detectorGO.transform.parent = body.transform; + detectorGO.layer = 20; - ConstantForceDetector CFD = FieldDetector.AddComponent(); + ConstantForceDetector CFD = detectorGO.AddComponent(); ForceVolume[] temp = new ForceVolume[1]; - temp[0] = Locator.GetAstroObject(AstroObject.Name.Sun).GetGravityVolume(); + temp[0] = primaryBody.GetAttachedOWRigidbody().GetAttachedGravityVolume(); CFD.SetValue("_detectableFields", temp); - CFD.SetValue("_inheritElement0", false); - FieldDetector.SetActive(true); + CFD.SetValue("_inheritElement0", config.IsMoon); + + detectorGO.SetActive(true); } } } diff --git a/Marshmallow/General/MakeGravityWell.cs b/Marshmallow/General/MakeGravityWell.cs index 16c1e45f..0e62d9f0 100644 --- a/Marshmallow/General/MakeGravityWell.cs +++ b/Marshmallow/General/MakeGravityWell.cs @@ -8,13 +8,13 @@ namespace Marshmallow.General { public static GravityVolume Make(GameObject body, float surfaceAccel, float upperSurface, float lowerSurface) { - GameObject GravityWell = new GameObject(); - GravityWell.transform.parent = body.transform; - GravityWell.name = "GravityWell"; - GravityWell.layer = 17; - GravityWell.SetActive(false); + GameObject gravityGO = new GameObject(); + gravityGO.transform.parent = body.transform; + gravityGO.name = "GravityWell"; + gravityGO.layer = 17; + gravityGO.SetActive(false); - GravityVolume GV = GravityWell.AddComponent(); + GravityVolume GV = gravityGO.AddComponent(); GV.SetValue("_cutoffAcceleration", 0.1f); GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField("linear").GetValue(GV)); GV.SetValue("_alignmentRadius", 600f); @@ -28,13 +28,15 @@ namespace Marshmallow.General GV.SetValue("_isPlanetGravityVolume", true); GV.SetValue("_cutoffRadius", 55f); - SphereCollider GV_SC = GravityWell.AddComponent(); - GV_SC.isTrigger = true; - GV_SC.radius = 4000; + SphereCollider SC = gravityGO.AddComponent(); + SC.isTrigger = true; + SC.radius = 4000; + + OWCollider OWC = gravityGO.AddComponent(); + OWC.SetLODActivationMask(DynamicOccupant.Player); + + gravityGO.SetActive(true); - OWCollider GV_OWC = GravityWell.AddComponent(); - GV_OWC.SetLODActivationMask(DynamicOccupant.Player); - GravityWell.SetActive(true); return GV; } } diff --git a/Marshmallow/General/MakeMapMarker.cs b/Marshmallow/General/MakeMapMarker.cs index 0942d656..d726198a 100644 --- a/Marshmallow/General/MakeMapMarker.cs +++ b/Marshmallow/General/MakeMapMarker.cs @@ -1,4 +1,5 @@ -using OWML.ModHelper.Events; +using Marshmallow.External; +using OWML.ModHelper.Events; using System.Reflection; using UnityEngine; @@ -6,13 +7,19 @@ namespace Marshmallow.General { static class MakeMapMarker { - public static void Make(GameObject body, string name) + public static void Make(GameObject body, IPlanetConfig config) { - var MM = body.AddComponent(); - MM.SetValue("_labelID", (UITextType)Utility.AddToUITable.Add(name)); - MM.SetValue("_markerType", MM.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField("Planet").GetValue(MM)); + MapMarker MM = body.AddComponent(); + MM.SetValue("_labelID", (UITextType)Utility.AddToUITable.Add(config.Name)); - Main.Log("Map Marker - body : " + body.name + ", labelID : " + name); + if (config.IsMoon) + { + MM.SetValue("_markerType", MM.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField("Moon").GetValue(MM)); + } + else + { + MM.SetValue("_markerType", MM.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField("Planet").GetValue(MM)); + } } } } diff --git a/Marshmallow/General/MakeOrbitLine.cs b/Marshmallow/General/MakeOrbitLine.cs index 1246e2b7..d06efb58 100644 --- a/Marshmallow/General/MakeOrbitLine.cs +++ b/Marshmallow/General/MakeOrbitLine.cs @@ -1,9 +1,11 @@ -using OWML.ModHelper.Events; +using Marshmallow.Utility; +using OWML.ModHelper.Events; using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; +using Logger = Marshmallow.Utility.Logger; namespace Marshmallow.General { @@ -11,6 +13,8 @@ namespace Marshmallow.General { public static void Make(GameObject body, AstroObject astroobject) { + Logger.Log("MakeOrbitLine not finished!", Logger.LogType.Todo); + GameObject orbit = new GameObject(); orbit.transform.parent = body.transform; diff --git a/Marshmallow/General/MakeOrbitingAstroObject.cs b/Marshmallow/General/MakeOrbitingAstroObject.cs index d8e32893..171abfae 100644 --- a/Marshmallow/General/MakeOrbitingAstroObject.cs +++ b/Marshmallow/General/MakeOrbitingAstroObject.cs @@ -1,11 +1,13 @@ -using OWML.ModHelper.Events; +using Marshmallow.External; +using Marshmallow.Utility; +using OWML.ModHelper.Events; using UnityEngine; namespace Marshmallow.General { static class MakeOrbitingAstroObject { - public static AstroObject Make(GameObject body, float angularSpeed, float orbitAngle, bool hasGravity, float surfaceAccel, float groundSize) + public static OWRigidbody Make(GameObject body, AstroObject primaryBody, IPlanetConfig config) { Rigidbody RB = body.AddComponent(); RB.mass = 10000; @@ -16,36 +18,36 @@ namespace Marshmallow.General RB.interpolation = RigidbodyInterpolation.None; RB.collisionDetectionMode = CollisionDetectionMode.Discrete; - Main.OWRB = body.AddComponent(); - Main.OWRB.SetValue("_kinematicSimulation", true); - Main.OWRB.SetValue("_autoGenerateCenterOfMass", true); - Main.OWRB.SetIsTargetable(true); - Main.OWRB.SetValue("_maintainOriginalCenterOfMass", true); - Main.OWRB.SetValue("_rigidbody", RB); + OWRigidbody OWRB = body.AddComponent(); + OWRB.SetValue("_kinematicSimulation", true); + OWRB.SetValue("_autoGenerateCenterOfMass", true); + OWRB.SetIsTargetable(true); + OWRB.SetValue("_maintainOriginalCenterOfMass", true); + OWRB.SetValue("_rigidbody", RB); InitialMotion IM = body.AddComponent(); - IM.SetPrimaryBody(Locator.GetAstroObject(AstroObject.Name.Sun).GetAttachedOWRigidbody()); - IM.SetValue("_orbitAngle", orbitAngle); - Main.Log("Got orbit angle as " + orbitAngle); + IM.SetPrimaryBody(primaryBody.GetAttachedOWRigidbody()); + IM.SetValue("_orbitAngle", config.OrbitAngle); IM.SetValue("_isGlobalAxis", false); - IM.SetValue("_initAngularSpeed", angularSpeed); + IM.SetValue("_initAngularSpeed", 0.02f); IM.SetValue("_initLinearSpeed", 0f); - IM.SetValue("_isGlobalAxis", false); - MakeFieldDetector.Make(body); + MakeFieldDetector.Make(body, primaryBody, config); AstroObject AO = body.AddComponent(); AO.SetValue("_type", AstroObject.Type.Planet); AO.SetValue("_name", AstroObject.Name.None); - AO.SetPrimaryBody(Locator.GetAstroObject(AstroObject.Name.Sun)); - if (hasGravity) + AO.SetPrimaryBody(primaryBody); + if (config.HasGravity) { - GravityVolume GV = MakeGravityWell.Make(body, surfaceAccel, groundSize, groundSize); + GravityVolume GV = MakeGravityWell.Make(body, config.SurfaceAcceleration, config.GroundSize, config.GroundSize); AO.SetValue("_gravityVolume", GV); } + MakeOrbitLine.Make(body, AO); - return AO; - + + //return new Tuple(AO, rigidbody); + return OWRB; } } } diff --git a/Marshmallow/General/MakeRFVolume.cs b/Marshmallow/General/MakeRFVolume.cs index 4a7629d7..2708234d 100644 --- a/Marshmallow/General/MakeRFVolume.cs +++ b/Marshmallow/General/MakeRFVolume.cs @@ -5,34 +5,37 @@ namespace Marshmallow.General { static class MakeRFVolume { - public static void Make(GameObject body) + public static void Make(GameObject body, OWRigidbody rigidbody) { - GameObject RFVolume = new GameObject("RFVolume"); - RFVolume.transform.parent = body.transform; - RFVolume.layer = 19; - RFVolume.SetActive(false); + GameObject rfGO = new GameObject("RFVolume"); + rfGO.transform.parent = body.transform; + rfGO.layer = 19; + rfGO.SetActive(false); - SphereCollider RF_SC = RFVolume.AddComponent(); - RF_SC.isTrigger = true; - RF_SC.radius = 600f; + SphereCollider SC = rfGO.AddComponent(); + SC.isTrigger = true; + SC.radius = 600f; - ReferenceFrameVolume RF_RFV = RFVolume.AddComponent(); - ReferenceFrame test = new ReferenceFrame(Main.OWRB); - test.SetValue("_minSuitTargetDistance", 300); - test.SetValue("_maxTargetDistance", 0); - test.SetValue("_autopilotArrivalDistance", 1000); - test.SetValue("_autoAlignmentDistance", 1000); - test.SetValue("_hideLandingModePrompt", false); - test.SetValue("_matchAngularVelocity", true); - test.SetValue("_minMatchAngularVelocityDistance", 70); - test.SetValue("_maxMatchAngularVelocityDistance", 400); - test.SetValue("_bracketsRadius", 300); - RF_RFV.SetValue("_referenceFrame", test); - RF_RFV.SetValue("_minColliderRadius", 300); - RF_RFV.SetValue("_maxColliderRadius", 2000); - RF_RFV.SetValue("_isPrimaryVolume", true); - RF_RFV.SetValue("_isCloseRangeVolume", false); - RFVolume.SetActive(true); + ReferenceFrameVolume RFV = rfGO.AddComponent(); + + ReferenceFrame RV = new ReferenceFrame(rigidbody); + RV.SetValue("_minSuitTargetDistance", 300); + RV.SetValue("_maxTargetDistance", 0); + RV.SetValue("_autopilotArrivalDistance", 1000); + RV.SetValue("_autoAlignmentDistance", 1000); + RV.SetValue("_hideLandingModePrompt", false); + RV.SetValue("_matchAngularVelocity", true); + RV.SetValue("_minMatchAngularVelocityDistance", 70); + RV.SetValue("_maxMatchAngularVelocityDistance", 400); + RV.SetValue("_bracketsRadius", 300); + + RFV.SetValue("_referenceFrame", RV); + RFV.SetValue("_minColliderRadius", 300); + RFV.SetValue("_maxColliderRadius", 2000); + RFV.SetValue("_isPrimaryVolume", true); + RFV.SetValue("_isCloseRangeVolume", false); + + rfGO.SetActive(true); } } } diff --git a/Marshmallow/General/MakeSector.cs b/Marshmallow/General/MakeSector.cs index b1fab1b6..b5542df8 100644 --- a/Marshmallow/General/MakeSector.cs +++ b/Marshmallow/General/MakeSector.cs @@ -6,30 +6,30 @@ namespace Marshmallow.Body { static class MakeSector { - public static Sector Make(GameObject body, float sectorSize) + public static Sector Make(GameObject body, OWRigidbody rigidbody, float sectorSize) { - GameObject sectorBase = new GameObject(); - sectorBase.SetActive(false); - sectorBase.transform.parent = body.transform; + GameObject sectorGO = new GameObject(); + sectorGO.SetActive(false); + sectorGO.transform.parent = body.transform; - SphereShape sphereshape = sectorBase.AddComponent(); - sphereshape.SetCollisionMode(Shape.CollisionMode.Volume); - sphereshape.SetLayer(Shape.Layer.Sector); - sphereshape.layerMask = -1; - sphereshape.pointChecksOnly = true; - sphereshape.radius = 700f; - sphereshape.center = Vector3.zero; + SphereShape SS = sectorGO.AddComponent(); + SS.SetCollisionMode(Shape.CollisionMode.Volume); + SS.SetLayer(Shape.Layer.Sector); + SS.layerMask = -1; + SS.pointChecksOnly = true; + SS.radius = 700f; + SS.center = Vector3.zero; - /*OWTriggerVolume trigVol = */sectorBase.AddComponent(); + /*OWTriggerVolume trigVol = */sectorGO.AddComponent(); - Sector sector = sectorBase.AddComponent(); - sector.SetValue("_name", Sector.Name.InvisiblePlanet); - sector.SetValue("__attachedOWRigidbody", Main.OWRB); - sector.SetValue("_subsectors", new List()); + Sector S = sectorGO.AddComponent(); + S.SetValue("_name", Sector.Name.InvisiblePlanet); + S.SetValue("__attachedOWRigidbody", rigidbody); + S.SetValue("_subsectors", new List()); - sectorBase.SetActive(true); + sectorGO.SetActive(true); - return sector; + return S; } } } diff --git a/Marshmallow/General/MakeSpawnPoint.cs b/Marshmallow/General/MakeSpawnPoint.cs index 3c0b9763..d07c875a 100644 --- a/Marshmallow/General/MakeSpawnPoint.cs +++ b/Marshmallow/General/MakeSpawnPoint.cs @@ -6,15 +6,17 @@ namespace Marshmallow.General { public static SpawnPoint Make(GameObject body, Vector3 position) { - GameObject spawn = new GameObject(); - spawn.transform.parent = body.transform; - spawn.layer = 8; + GameObject spawnGO = new GameObject(); + spawnGO.transform.parent = body.transform; + spawnGO.layer = 8; - spawn.transform.localPosition = position; + spawnGO.transform.localPosition = position; - //Main.Log("Made spawnpoint on [" + body.name + "] at " + position); + //Logger.Log("Made spawnpoint on [" + body.name + "] at " + position); - return spawn.AddComponent(); + var SS = spawnGO.AddComponent(); + + return SS; } } } diff --git a/Marshmallow/Main.cs b/Marshmallow/Main.cs index 57081334..70526a25 100644 --- a/Marshmallow/Main.cs +++ b/Marshmallow/Main.cs @@ -1,27 +1,22 @@ using Marshmallow.External; using Marshmallow.Utility; -using Newtonsoft.Json.Linq; using OWML.Common; using OWML.ModHelper; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using UnityEngine; +using UnityEngine.SceneManagement; +using Logger = Marshmallow.Utility.Logger; namespace Marshmallow { public class Main : ModBehaviour { - public static OWRigidbody OWRB; - public static Sector SECTOR; - public static SpawnPoint SPAWN; - public static AstroObject ASTROOBJECT; - public static IModHelper helper; - GameObject planet; - - static List planetList = new List(); + public static List planetList = new List(); public override object GetApi() { @@ -30,113 +25,98 @@ namespace Marshmallow void Start() { - base.ModHelper.Events.Subscribe(Events.AfterStart); - IModEvents events = base.ModHelper.Events; - events.OnEvent = (Action)Delegate.Combine(events.OnEvent, new Action(this.OnEvent)); + SceneManager.sceneLoaded += OnSceneLoaded; helper = base.ModHelper; - Main.Log("Begin load of planet config..."); + Logger.Log("Begin load of planet config...", Logger.LogType.Log); try { foreach (var file in Directory.GetFiles(ModHelper.Manifest.ModFolderPath + @"planets\")) { PlanetConfig config = ModHelper.Storage.Load(file.Replace(ModHelper.Manifest.ModFolderPath, "")); - planetList.Add(config); + planetList.Add(new MarshmallowBody(config)); - Main.Log("* " + config.name + " at position " + config.position.ToVector3()); + Logger.Log("* " + config.Name + " at position " + config.Position.ToVector3() + " relative to " + config.PrimaryBody + ". Moon? : " + config.IsMoon, Logger.LogType.Log); } } catch (Exception ex) { - Main.Log("Error! - " + ex.Message); + Logger.Log("Error! - " + ex.Message, Logger.LogType.Error); } if (planetList.Count != 0) { - Main.Log("Loaded [" + planetList.Count + "] planet config files."); + Logger.Log("Loaded [" + planetList.Count + "] planet config files.", Logger.LogType.Log); } else { - Main.Log("ERROR! - No planet config files found!"); + Logger.Log("No planet config files found!", Logger.LogType.Warning); } } - private void OnEvent(MonoBehaviour behaviour, Events ev) + void OnSceneLoaded(Scene scene, LoadSceneMode mode) { - bool flag = behaviour.GetType() == typeof(Flashlight) && ev == Events.AfterStart; - if (flag) + foreach (var planet in planetList) { - foreach (var config in planetList) - { - planet = GenerateBody(config); + var planetObject = GenerateBody(planet.Config); - planet.transform.parent = Locator.GetRootTransform(); - planet.transform.position = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.primaryBody)).gameObject.transform.position + config.position.ToVector3(); - planet.SetActive(true); + var primayBody = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(planet.Config.PrimaryBody)); - try - { - OWRB.SetVelocity(Locator.GetCenterOfTheUniverse().GetOffsetVelocity()); - var primary = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.primaryBody)).GetAttachedOWRigidbody(); - var initialMotion = primary.GetComponent(); - if (initialMotion != null) - { - OWRB.AddVelocityChange(-initialMotion.GetInitVelocity()); - } - OWRB.AddVelocityChange(primary.GetVelocity()); - } - catch { } - } + planetObject.transform.parent = Locator.GetRootTransform(); + planetObject.transform.position = primayBody.gameObject.transform.position + planet.Config.Position.ToVector3(); + planetObject.SetActive(true); + + planet.Object = planetObject; } } public static GameObject GenerateBody(IPlanetConfig config) { - Main.Log("Begin generation sequence of planet [" + config.name + "] ..."); + Logger.Log("Begin generation sequence of planet [" + config.Name + "] ...", Logger.LogType.Log); GameObject body; - body = new GameObject(config.name); + body = new GameObject(config.Name); body.SetActive(false); - Body.MakeGeometry.Make(body, config.groundSize); + Body.MakeGeometry.Make(body, config.GroundSize); - ASTROOBJECT = General.MakeOrbitingAstroObject.Make(body, 0.02f, config.orbitAngle, config.hasGravity, config.surfaceAcceleration, config.groundSize); - General.MakeRFVolume.Make(body); + var owRigidbody = General.MakeOrbitingAstroObject.Make(body, Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.PrimaryBody)), config); + General.MakeRFVolume.Make(body, owRigidbody); - if (config.hasMapMarker) + if (config.HasMapMarker) { - General.MakeMapMarker.Make(body, config.name); + General.MakeMapMarker.Make(body, config); } - SECTOR = Body.MakeSector.Make(body, config.topCloudSize); + var sector = Body.MakeSector.Make(body, owRigidbody, config.TopCloudSize); - if (config.hasClouds) + if (config.HasClouds) { - Atmosphere.MakeClouds.Make(body, config.topCloudSize, config.bottomCloudSize, config.bottomCloudTint.ToColor32(), config.topCloudTint.ToColor32()); - Atmosphere.MakeSunOverride.Make(body, config.topCloudSize, config.bottomCloudSize, config.waterSize); + Atmosphere.MakeClouds.Make(body, sector, config); + Atmosphere.MakeSunOverride.Make(body, sector, config); } - Atmosphere.MakeAir.Make(body, config.topCloudSize / 2, config.hasRain); + Atmosphere.MakeAir.Make(body, config.TopCloudSize / 2, config.HasRain); - if (config.hasWater) + if (config.HasWater) { - Body.MakeWater.Make(body, config.waterSize); + Body.MakeWater.Make(body, sector, config); } - Atmosphere.MakeBaseEffects.Make(body); - Atmosphere.MakeVolumes.Make(body, config.groundSize, config.topCloudSize); - General.MakeAmbientLight.Make(body); - Atmosphere.MakeAtmosphere.Make(body, config.topCloudSize, config.hasFog, config.fogDensity, config.fogTint.ToColor32()); + Atmosphere.MakeBaseEffects.Make(body, sector); + Atmosphere.MakeVolumes.Make(body, config); + General.MakeAmbientLight.Make(body, sector); + Atmosphere.MakeAtmosphere.Make(body, config); - if (config.hasSpawnPoint) + if (config.HasSpawnPoint) { - SPAWN = General.MakeSpawnPoint.Make(body, new Vector3(0, config.groundSize + 10, 0)); + General.MakeSpawnPoint.Make(body, new Vector3(0, config.GroundSize + 10, 0)); } - Main.Log("Generation of planet [" + config.name + "] completed."); + Logger.Log("Generation of planet [" + config.Name + "] completed.", Logger.LogType.Log); return body; } @@ -146,12 +126,12 @@ namespace Marshmallow var planet = Main.GenerateBody(config); planet.transform.parent = Locator.GetRootTransform(); - planet.transform.position = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.primaryBody)).gameObject.transform.position + config.position.ToVector3(); + planet.transform.position = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.PrimaryBody)).gameObject.transform.position + config.Position.ToVector3(); planet.SetActive(true); planet.GetComponent().SetVelocity(Locator.GetCenterOfTheUniverse().GetOffsetVelocity()); - var primary = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.primaryBody)).GetAttachedOWRigidbody(); + var primary = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.PrimaryBody)).GetAttachedOWRigidbody(); var initialMotion = primary.GetComponent(); if (initialMotion != null) { @@ -159,11 +139,6 @@ namespace Marshmallow planet.GetComponent().AddVelocityChange(primary.GetVelocity()); } } - - public static void Log(string text) - { - helper.Console.WriteLine(text); - } } public class MarshmallowApi @@ -172,29 +147,35 @@ namespace Marshmallow { var planetConfig = new PlanetConfig { - name = (string)config["name"], - position = (MVector3)config["position"], - orbitAngle = (int)config["orbitAngle"], - primaryBody = (string)config["primaryBody"], - hasSpawnPoint = (bool)config["hasSpawnPoint"], - hasClouds = (bool)config["hasClouds"], - topCloudSize = (float)config["topCloudSize"], - bottomCloudSize = (float)config["bottomCloudSize"], - topCloudTint = (MColor32)config["topCloudTint"], - bottomCloudTint = (MColor32)config["bottomCloudTint"], - hasWater = (bool)config["hasWater"], - waterSize = (float)config["waterSize"], - hasRain = (bool)config["hasRain"], - hasGravity = (bool)config["hasGravity"], - surfaceAcceleration = (float)config["surfaceAcceleration"], - hasMapMarker = (bool)config["hasMapMarker"], - hasFog = (bool)config["hasFog"], - fogTint = (MColor32)config["fogTint"], - fogDensity = (float)config["fogDensity"], - groundSize = (float)config["groundScale"] + Name = (string)config["name"], + Position = (MVector3)config["position"], + OrbitAngle = (int)config["orbitAngle"], + IsMoon = (bool)config["isMoon"], + PrimaryBody = (string)config["primaryBody"], + HasSpawnPoint = (bool)config["hasSpawnPoint"], + HasClouds = (bool)config["hasClouds"], + TopCloudSize = (float)config["topCloudSize"], + BottomCloudSize = (float)config["bottomCloudSize"], + TopCloudTint = (MColor32)config["topCloudTint"], + BottomCloudTint = (MColor32)config["bottomCloudTint"], + HasWater = (bool)config["hasWater"], + WaterSize = (float)config["waterSize"], + HasRain = (bool)config["hasRain"], + HasGravity = (bool)config["hasGravity"], + SurfaceAcceleration = (float)config["surfaceAcceleration"], + HasMapMarker = (bool)config["hasMapMarker"], + HasFog = (bool)config["hasFog"], + FogTint = (MColor32)config["fogTint"], + FogDensity = (float)config["fogDensity"], + GroundSize = (float)config["groundScale"] }; Main.CreateBody(planetConfig); } + + public GameObject GetPlanet(string name) + { + return Main.planetList.FirstOrDefault(x => x.Config.Name == name).Object; + } } } diff --git a/Marshmallow/Marshmallow.csproj b/Marshmallow/Marshmallow.csproj index 85b5019a..f9cc7ac2 100644 --- a/Marshmallow/Marshmallow.csproj +++ b/Marshmallow/Marshmallow.csproj @@ -106,9 +106,12 @@ + + + diff --git a/Marshmallow/Utility/AddToUITable.cs b/Marshmallow/Utility/AddToUITable.cs index ce60c9fb..a8cc8e83 100644 --- a/Marshmallow/Utility/AddToUITable.cs +++ b/Marshmallow/Utility/AddToUITable.cs @@ -12,7 +12,7 @@ namespace Marshmallow.Utility instance.Insert_UI(instance.theUITable.Keys.Max() + 1, text); - Main.Log($"Added [{text}] to UI table with key [{instance.theUITable.Keys.Max()}]"); + Logger.Log($"Added [{text}] to UI table with key [{instance.theUITable.Keys.Max()}]", Logger.LogType.Log); return instance.theUITable.Keys.Max(); } diff --git a/Marshmallow/Utility/Logger.cs b/Marshmallow/Utility/Logger.cs new file mode 100644 index 00000000..aedb73d5 --- /dev/null +++ b/Marshmallow/Utility/Logger.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Marshmallow.Utility +{ + public class Logger + { + public static void Log(string text, LogType type) + { + Main.helper.Console.WriteLine(Enum.GetName(typeof(LogType), type) + " : " + text); + } + + public enum LogType + { + Log, + Error, + Warning, + Todo + } + } +} diff --git a/Marshmallow/Utility/MarshmallowBody.cs b/Marshmallow/Utility/MarshmallowBody.cs new file mode 100644 index 00000000..43315c59 --- /dev/null +++ b/Marshmallow/Utility/MarshmallowBody.cs @@ -0,0 +1,21 @@ +using Marshmallow.External; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace Marshmallow.Utility +{ + public class MarshmallowBody + { + public MarshmallowBody(IPlanetConfig config) + { + Config = config; + } + + public IPlanetConfig Config; + + public GameObject Object; + } +} diff --git a/Marshmallow/Utility/Tuple.cs b/Marshmallow/Utility/Tuple.cs new file mode 100644 index 00000000..cd86e1af --- /dev/null +++ b/Marshmallow/Utility/Tuple.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Marshmallow.Utility +{ + public class Tuple + { + public Tuple(params object[] _items) + { + Items = _items.ToList(); + } + + public List Items { get; } + } +}