Skip to content

Commit

Permalink
3.3 release.
Browse files Browse the repository at this point in the history
Adds dust colour definitions for each body.
  • Loading branch information
pizzaoverhead committed Nov 6, 2015
1 parent a7e9406 commit 694908f
Show file tree
Hide file tree
Showing 7 changed files with 830 additions and 245 deletions.
604 changes: 370 additions & 234 deletions CollisionFX/CollisionFX.cs

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions CollisionFX/CollisionFX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\3rd party binaries\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\Squad binaries\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -42,17 +42,20 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\3rd party binaries\UnityEngine.dll</HintPath>
<HintPath>..\..\Squad binaries\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CollisionFX.cs" />
<Compile Include="ColourManager.cs" />
<Compile Include="EvaWatcher.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /y "$(TargetPath)" "C:\Games\Kerbal Space Program\GameData\CollisionFX\Plugins\"
<PostBuildEvent>xcopy /y "$(TargetPath)" "C:\Games\Kerbal Space Program\GameData\$(ProjectName)\Plugins\"
xcopy /y "$(TargetDir)$(TargetName).pdb" "C:\Games\Kerbal Space Program\GameData\$(ProjectName)\Plugins\"
call "C:\Games\Kerbal Space Program\GameData\$(ProjectName)\Plugins\GenerateMonoDebug.bat" C:\Games\Kerbal~1\GameData\$(ProjectName)\Plugins\
taskkill /IM tail.exe /F 2&gt;&amp;1 | exit /B 0</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
196 changes: 196 additions & 0 deletions CollisionFX/ColourManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;

namespace CollisionFX
{
public static class ColourManager
{
public class DustBody
{
public string Name;
public List<DustBiome> Biomes;
public override string ToString() { return Name; }
}

public class DustBiome
{
public string Name;
public Color DustColour;
public override string ToString() { return Name; }
}

private static List<DustBody> _dustBodies;

public static void LoadDustColours()
{
_dustBodies = new List<DustBody>();
ConfigNode config = ConfigNode.Load(CollisionFX.ConfigPath);
if (config == null)
{
Debug.LogError("CollisionFX: Configuration file not found at " + CollisionFX.ConfigPath);
return;
}
foreach (ConfigNode node in config.nodes)
{
if (!node.name.Equals("DustBody"))
continue;

DustBody body;
if (node.HasValue("name"))
{
body = new DustBody
{
Name = node.GetValue("name"),
Biomes = new List<DustBiome>()
};
Debug.Log("#Body " + body.Name);
}
else
{
Debug.LogWarning("CollisionFX: Invalid DustBody definition: \"name\" field is missing.");
continue;
}

if (!node.HasNode("Biomes"))
continue;
ConfigNode biomeNode = node.GetNode("Biomes");
foreach (ConfigNode.Value biomeDefinition in biomeNode.values)
{
string colourString = biomeDefinition.value;
string[] colourValues = colourString.Split(' ');
if (colourValues.Length > 4)
{
Debug.LogWarning("CollisionFX: Invalid Biome colour definition in body \"" +
body.Name + "\": Too many parameters.");
continue;
}
float r, g, b, a;
NumberStyles flags = NumberStyles.AllowDecimalPoint;
if (!float.TryParse(colourValues[0], flags, CultureInfo.InvariantCulture, out r))
{
Debug.LogWarning("CollisionFX: Invalid Biome colour definition in body \"" +
body.Name + "\": \"\" is not a valid integer.");
continue;
}
if (!float.TryParse(colourValues[1], flags, CultureInfo.InvariantCulture, out g))
{
Debug.LogWarning("CollisionFX: Invalid Biome colour definition in body \"" +
body.Name + "\": \"\" is not a valid integer.");
continue;
}
if (!float.TryParse(colourValues[2], flags, CultureInfo.InvariantCulture, out b))
{
Debug.LogWarning("CollisionFX: Invalid Biome colour definition in body \"" +
body.Name + "\": \"\" is not a valid integer.");
continue;
}

Color c;
if (colourValues.Length == 4)
{
if (!float.TryParse(colourValues[3], flags, CultureInfo.InvariantCulture, out a))
{
Debug.LogWarning("CollisionFX: Invalid Biome colour definition in body \"" +
body.Name + "\": \"\" is not a valid integer.");
continue;
}
c = new Color(r, g, b, a);
}
else
c = new Color(r, g, b);

DustBiome biome = new DustBiome
{
Name = biomeDefinition.name,
DustColour = c
};
body.Biomes.Add(biome);
}
_dustBodies.Add(body);
}
}

public static string GetCurrentBiomeName(Vessel vessel)
{
CBAttributeMapSO biomeMap = FlightGlobals.currentMainBody.BiomeMap;
CBAttributeMapSO.MapAttribute mapAttribute = biomeMap.GetAtt(vessel.latitude * Mathf.Deg2Rad, vessel.longitude * Mathf.Deg2Rad);
return mapAttribute.name;
}

static Color genericDustColour = new Color(0.8f, 0.8f, 0.8f, 0.007f); // Grey 210 210 210
static Color dirtColour = new Color(0.65f, 0.48f, 0.34f, 0.05f); // Brown 165, 122, 88
static Color lightDirtColour = new Color(0.65f, 0.52f, 0.34f, 0.05f); // Brown 165, 132, 88
static Color sandColour = new Color(0.80f, 0.68f, 0.47f, 0.05f); // Light brown 203, 173, 119
static Color snowColour = new Color(0.90f, 0.94f, 1f, 0.05f); // Blue-white 230, 250, 255
private static DustBody _previousDustBody;
private static DustBiome _previousDustBiome;

public static Color GetBiomeColour(Collider c)
{
if (_dustBodies == null)
LoadDustColours();

string currentBody = FlightGlobals.ActiveVessel.mainBody.name;
DustBody body = null;
if (_previousDustBody != null &&
_previousDustBody.Name.Equals(currentBody, StringComparison.InvariantCultureIgnoreCase))
body = _previousDustBody;
else
{
_previousDustBiome = null;
foreach (DustBody db in _dustBodies)
{
if (db.Name.Equals(currentBody, StringComparison.InvariantCultureIgnoreCase))
{
body = db;
_previousDustBody = db;
break;
}
}
}

if (body == null)
{
Debug.LogWarning("CollisionFX: Unable to find dust definition for body \"" + currentBody + "\"; using default.");
return genericDustColour;
}

string currentBiome = IsPQS(c) ? GetCurrentBiomeName(FlightGlobals.ActiveVessel) : "Structure";
DustBiome biome = null;
if (_previousDustBiome != null &&
_previousDustBiome.Name.Equals(currentBiome, StringComparison.InvariantCultureIgnoreCase))
biome = _previousDustBiome;
else
{
foreach (DustBiome b in body.Biomes)
{
if (b.Name.Equals(currentBiome, StringComparison.InvariantCultureIgnoreCase))
{
biome = b;
_previousDustBiome = b;
break;
}
}
}

if (biome == null)
{
Debug.LogWarning("CollisionFX: Unable to find dust definition for biome \"" + currentBiome +
"\" on body \"" + currentBody + "\"; using default.");
return genericDustColour;
}

return biome.DustColour;
}

public static bool IsPQS(Collider c)
{
if (c == null) return false;
// Test for PQS: Name in the form "Ab0123456789".
Int64 n;
return c.name.Length == 12 && Int64.TryParse(c.name.Substring(2, 10), out n);
}
}
}
8 changes: 4 additions & 4 deletions CollisionFX/EvaWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace CollisionFX
[KSPAddon(KSPAddon.Startup.Flight, false)]
class EvaWatcher : MonoBehaviour
{
private string _configPath = "GameData/CollisionFX/settings.cfg";
//private string _configPath = "GameData/CollisionFX/settings.cfg";

bool _scrapeSparks;
string _collisionSound;
Expand All @@ -16,10 +16,10 @@ class EvaWatcher : MonoBehaviour
public void Start()
{
GameEvents.onCrewOnEva.Add(OnCrewEVA);
ConfigNode config = ConfigNode.Load(_configPath);
ConfigNode config = ConfigNode.Load(CollisionFX.ConfigPath);
if (config == null)
{
Debug.LogError("CollisionFX: Configuration file not found at " + _configPath);
Debug.LogError("CollisionFX: Configuration file not found at " + CollisionFX.ConfigPath);
return;
}
foreach (ConfigNode node in config.nodes)
Expand All @@ -32,7 +32,7 @@ public void Start()
_collisionSound = node.GetValue("collisionSound");
if (node.HasValue("scrapeSound"))
_scrapeSound = node.GetValue("scrapeSound");
if (node.HasValue("collisionSound"))
if (node.HasValue("sparkSound"))
_sparkSound = node.GetValue("sparkSound");
}
}
Expand Down
4 changes: 2 additions & 2 deletions CollisionFX/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.1.0.0")]
[assembly: AssemblyFileVersion("3.1.0.0")]
[assembly: AssemblyVersion("3.3.0.0")]
[assembly: AssemblyFileVersion("3.3.0.0")]
32 changes: 30 additions & 2 deletions ModuleManager_CollisionFX.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
@PART[*]:HAS[@MODULE[ModuleLandingGear*]]
// CollisionFX fields:
// volume - How loud the scraping sounds are. Default: 0.5f
// scrapeSparks - Whether this part should produce sparks as well as dust. Default: true
// collisionSound - The path (starting in GameData) to the sound file to be used for collisions, including the filename but not the extension.
// wheelImpactSound - The path (starting in GameData) to the sound file to be used for wheel collisions, including the filename but not the extension.
// scrapeSound - The path (starting in GameData) to the sound file to be used for dust scraping, including the filename but not the extension.
// sparkSound - The path (starting in GameData) to the sound file to be used for spark scraping, including the filename but not the extension.
// sparkLightIntensity - How bright the light produced by sparks should be. Default: 0.05
// minScrapeSpeed - The minimum velocity at which scraping sounds are produced, in m/s. Default: 1

@PART[*]:HAS[@MODULE[ModuleLandingGear]]
{
MODULE
{
name = CollisionFX
scrapeSparks = false
wheelImpactSound = CollisionFX/Sounds/TyreSqueal
}
}
@PART[*]:HAS[@MODULE[ModuleLandingGearFixed]]
{
MODULE
{
Expand All @@ -16,7 +35,16 @@
wheelImpactSound = CollisionFX/Sounds/TyreSqueal
}
}
@PART[*]:HAS[!MODULE[ModuleLandingGear],!MODULE[ModuleWheel],!MODULE[KerbalEVA],!MODULE[CollisionFX],!MODULE[FSwheel],!MODULE[FSwheelAlignment],!MODULE[TTModularWheel],!MODULE[*Repulsor*],!MODULE[ModuleTrack],!MODULE[TrackWheel]]
@PART[*]:HAS[@MODULE[BDAdjustableLandingGear]]
{
MODULE
{
name = CollisionFX
scrapeSparks = false
wheelImpactSound = CollisionFX/Sounds/TyreSqueal
}
}
@PART[*]:HAS[!MODULE[ModuleLandingGear],!MODULE[ModuleWheel],!MODULE[KerbalEVA],!MODULE[CollisionFX],!MODULE[FSwheel],!MODULE[FSwheelAlignment],!MODULE[BDAdjustableLandingGear],!MODULE[TTModularWheel],!MODULE[*Repulsor*],!MODULE[ModuleTrack],!MODULE[TrackWheel],!MODULE[KFModuleWheel],!MODULE[KFWheel],!MODULE[KFTrackSurface]]
{
MODULE
{
Expand Down

0 comments on commit 694908f

Please sign in to comment.