Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Kopernicus/Kopernicus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0f07ee18d31d
Choose a base ref
...
head repository: Kopernicus/Kopernicus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2b16c6a70c6a
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on May 6, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e8c0dcd View commit details
  2. Working PQSCity parsers

    StollD committed May 6, 2018
    Copy the full SHA
    2b16c6a View commit details
238 changes: 207 additions & 31 deletions src/Kopernicus/Configuration/ModLoader/City.cs
Original file line number Diff line number Diff line change
@@ -23,10 +23,11 @@
* https://kerbalspaceprogram.com
*/

/*using CommNet;
using CommNet;
using System;
using System.Collections.Generic;
using System.Linq;
using Kopernicus.Constants;
using Kopernicus.UI;
using UnityEngine;

namespace Kopernicus
@@ -36,8 +37,133 @@ namespace Configuration
namespace ModLoader
{
[RequireConfigType(ConfigType.Node)]
public class City : ModLoader<PQSCity>, IParserEventSubscriber
public class City : ModLoader<PQSCity>
{
// LODRange loader
[RequireConfigType(ConfigType.Node)]
public class LODRangeLoader : IPatchable, ITypeParser<PQSCity.LODRange>
{
// LOD object
public PQSCity.LODRange Value { get; set; }

// Fake property to allow patching by index
public String name
{
get { return null; }
set {}
}

// Delete the lod range
[ParserTarget("delete")]
public NumericParser<Boolean> delete = false;

// visibleRange
[ParserTarget("visibleRange")]
public NumericParser<Single> visibleRange
{
get { return Value.visibleRange; }
set { Value.visibleRange = value; }
}

// The mesh for the mod
[ParserTarget("model")]
public MuParser model
{
get
{
GameObject obj = null;
if (Value.objects.Length > 1)
{
obj = new GameObject();
obj.transform.parent = Utility.Deactivator;
foreach (GameObject subobj in Value.objects)
{
UnityEngine.Object.Instantiate(subobj).transform.parent = obj.transform;
}
}
else
{
obj = Value.objects[0];
}
return new MuParser(obj);
}
set
{
Value.objects = new[] {value.Value};
Value.renderers = value.Value.GetComponentsInChildren<Renderer>().Select(r => r.gameObject)
.ToArray();
}
}

// scale
[ParserTarget("scale")]
public Vector3Parser scale
{
get
{
Single x = 0;
Single y = 0;
Single z = 0;
Single count = Value.objects.Length > 0 ? Value.objects.Length : 1;
foreach (GameObject obj in Value.objects)
{
x += obj.transform.localScale.x;
y += obj.transform.localScale.y;
z += obj.transform.localScale.z;
}

return new Vector3(x / count, y / count, z / count);
}
set
{
foreach (GameObject obj in Value.objects)
{
obj.transform.localScale = value;
}
}
}

[KittopiaConstructor(KittopiaConstructor.Parameter.Empty, purpose = KittopiaConstructor.Purpose.Create)]
public LODRangeLoader ()
{
// Initialize the LOD range
Value = new PQSCity.LODRange();
Value.objects = new GameObject[0];
Value.renderers = new GameObject[0];
}

[KittopiaConstructor(KittopiaConstructor.Parameter.Element, purpose = KittopiaConstructor.Purpose.Edit)]
public LODRangeLoader(PQSCity.LODRange c)
{
Value = c;
if (Value.objects == null)
{
Value.objects = new GameObject[0];
}

if (Value.renderers == null)
{
Value.renderers = new GameObject[0];
}
}

/// <summary>
/// Convert Parser to Value
/// </summary>
public static implicit operator PQSCity.LODRange(LODRangeLoader parser)
{
return parser.Value;
}

/// <summary>
/// Convert Value to Parser
/// </summary>
public static implicit operator LODRangeLoader(PQSCity.LODRange value)
{
return new LODRangeLoader(value);
}
}

// debugOrientated
[ParserTarget("debugOrientated")]
public NumericParser<Boolean> debugOrientated
@@ -94,6 +220,13 @@ public Vector3Parser repositionRadial
set { mod.repositionRadial = value; }
}

// repositionRadial - Position
[ParserTarget("RepositionRadial")]
private PositionParser repositionRadialPosition
{
set { mod.repositionRadial = value; }
}

// repositionRadiusOffset
[ParserTarget("repositionRadiusOffset")]
public NumericParser<Double> repositionRadiusOffset
@@ -126,53 +259,96 @@ public NumericParser<Boolean> repositionToSphereSurfaceAddHeight
set { mod.repositionToSphereSurfaceAddHeight = value; }
}

// The mesh for the mod
[ParserTarget("model")]
public MuParser model
// Commnet Station
[ParserTarget("commnetStation")]
public NumericParser<Boolean> commnetStation
{
get { return mod.gameObject.GetComponentInChildren<CommNetHome>() != null; }
set
{
value.Value.transform.parent = mod.transform;
Transform[] gameObjectList = mod.gameObject.GetComponentsInChildren<Transform>();
List<GameObject> rendererList = gameObjectList.Where(t => t.gameObject.GetComponent<Renderer>() != null).Select(t => t.gameObject).ToList();
mod.lod[0].objects = new GameObject[0];
mod.lod[0].renderers = rendererList.ToArray();
if (!value) return;
CommNetHome station = mod.gameObject.AddComponent<CommNetHome>();
station.isKSC = false;
}
}

// visibility Range
[ParserTarget("visibilityRange")]
public NumericParser<Single> visibilityRange
{
get { return mod.lod[0].visibleRange; }
set { mod.lod[0].visibleRange = value; }
}
// Commnet Station
[ParserTarget("commnetStation")]
public NumericParser<Boolean> commnetStation
[ParserTarget("isKSC")]
public NumericParser<Boolean> isKSC
{
get { return mod.gameObject.GetComponentInChildren<CommNetHome>() != null; }
get
{
CommNetHome home = mod.gameObject.GetComponentInChildren<CommNetHome>();
return home != null && home.isKSC;
}
set
{
if (value)
CommNetHome home = mod.gameObject.GetComponentInChildren<CommNetHome>();
if (home != null)
{
CommNetHome station = mod.gameObject.AddComponent<CommNetHome>();
station.isKSC = false;
home.isKSC = value;
}
}
}

// Apply event
void IParserEventSubscriber.Apply(ConfigNode node)
// The land classes
[ParserTargetCollection("LOD", AllowMerge = true)]
public CallbackList<LODRangeLoader> lodRanges { get; set; }

// Creates the a PQSMod of type T with given PQS
public override void Create(PQS pqsVersion)
{
mod.lod = new [] { new PQSCity.LODRange() };
base.Create(pqsVersion);

// Create the callback list
lodRanges = new CallbackList<LODRangeLoader> ((e) =>
{
mod.lod = lodRanges.Where(lodRange => !lodRange.delete)
.Select(lodRange => lodRange.Value).ToArray();
foreach (GameObject obj in e.Value.objects)
{
obj.transform.parent = mod.transform;
obj.transform.localPosition = Vector3.zero;
}
mod.gameObject.SetLayerRecursive(GameLayers.LocalSpace);
});
mod.lod = new PQSCity.LODRange[0];
}

// Apply event
void IParserEventSubscriber.PostApply(ConfigNode node) { }
// Grabs a PQSMod of type T from a parameter with a given PQS
public override void Create(PQSCity _mod, PQS pqsVersion)
{
base.Create(_mod, pqsVersion);

// Create the callback list
lodRanges = new CallbackList<LODRangeLoader> (e =>
{
mod.lod = lodRanges.Where(lodRange => !lodRange.delete)
.Select(lodRange => lodRange.Value).ToArray();
foreach (GameObject obj in e.Value.objects)
{
obj.transform.parent = mod.transform;
obj.transform.localPosition = Vector3.zero;
}
mod.gameObject.SetLayerRecursive(GameLayers.LocalSpace);
});

// Load LandClasses
if (mod.lod != null)
{
for (Int32 i = 0; i < mod.lod.Length; i++)
{
// Only activate the callback if we are adding the last loader
lodRanges.Add(new LODRangeLoader(mod.lod[i]), i == mod.lod.Length - 1);
}
}
else
{
mod.lod = new PQSCity.LODRange[0];
}
}
}
}
}
}*/
}

Loading