Skip to content

Commit

Permalink
recovered lost code
Browse files Browse the repository at this point in the history
  • Loading branch information
snjo committed May 30, 2014
1 parent 6a7508e commit 364fe2b
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 56 deletions.
4 changes: 3 additions & 1 deletion Firespitter.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2012 for Windows Desktop
# Visual Studio Express 2013 for Windows Desktop
VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Firespitter", "Firespitter\Firespitter.csproj", "{BFE97E64-BF01-48AF-81EE-6B2610076542}"
EndProject
Global
Expand Down
1 change: 1 addition & 0 deletions Firespitter/Firespitter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<Compile Include="cockpit\FSpitchIndicator.cs" />
<Compile Include="cockpit\FStachometer.cs" />
<Compile Include="customization\FSfuelSwitch.cs" />
<Compile Include="customization\FSmodularTank.cs" />
<Compile Include="engine\FS engine modules\FSengineBladed.cs" />
<Compile Include="engine\FSresource.cs" />
<Compile Include="info\FSpartDirectionGuide.cs" />
Expand Down
67 changes: 34 additions & 33 deletions Firespitter/customization/FSfuelSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,32 @@ public class FSfuelSwitch : PartModule
[KSPField]
public string resourceAmounts = "100;75,25;200";
[KSPField]
public float basePartMass = 0.25f;
[KSPField]
public string tankMass = "0;0;0;0";
[KSPField]
public bool hasGUI = true;
[KSPField]
public bool availableInFlight = false;
[KSPField]
public bool availableInEditor = true;

[KSPField (isPersistant = true)]
[KSPField(isPersistant = true)]
public Vector4 currentAmounts = Vector4.zero;
[KSPField(isPersistant = true)]
public int selectedTankSetup = 0;
[KSPField(isPersistant = true)]
public bool hasLaunched = false;

[KSPField(guiActive = false, guiActiveEditor=false, guiName = "Structural")]
public string info = "";

private List<FSmodularTank> tankList = new List<FSmodularTank>();
[KSPField(guiActive = false, guiActiveEditor = false, guiName = "Structural")]
public string structuralInfo = "";
[KSPField(guiActive = false, guiActiveEditor = true, guiName = "Dry mass")]
public float dryMassInfo = 0f;
private List<FSmodularTank> tankList = new List<FSmodularTank>();
private List<float> weightList = new List<float>();

public override void OnStart(PartModule.StartState state)
{
setupTankList();

this.weightList = Tools.parseFloats(this.tankMass);
assignResourcesToPart();
if (HighLogic.LoadedSceneIsFlight) hasLaunched = true;
if (hasGUI)
Expand Down Expand Up @@ -66,15 +70,8 @@ public void nextTankSetupEvent()

public void selectTankSetup(int i)
{
//if (i < tankList.Count)
//{
selectedTankSetup = i;
assignResourcesToPart();
//}
//else
//{
// Debug.Log("FSfuelSwitch: invalid tank setup, " + i);
//}
selectedTankSetup = i;
assignResourcesToPart();
}

private void assignResourcesToPart()
Expand Down Expand Up @@ -116,17 +113,26 @@ private void setupTankInPart(Part currentPart)
Debug.Log("add node to part");
currentPart.AddResource(newResourceNode);
//part.Resources[tankList[i].resources[j].name].enabled = true;
Fields["info"].guiActiveEditor = false;
Fields["structuralInfo"].guiActiveEditor = false;
}
else
{
Fields["info"].guiActiveEditor = true;
Fields["structuralInfo"].guiActiveEditor = true;
Debug.Log("Skipping structural fuel type");
}
}
}
}
currentPart.Resources.UpdateList();
updateWeight(currentPart, selectedTankSetup);
}

private void updateWeight(Part currentPart, int newTankSetup)
{
if (newTankSetup < weightList.Count)
{
currentPart.mass = basePartMass + weightList[newTankSetup];
}
}

public override void OnUpdate()
Expand All @@ -153,15 +159,15 @@ public override void OnUpdate()
}
}
}
}
}

//public void Update()
//{
// if (Input.GetKeyDown(KeyCode.F3))
// {
// nextTankSetupEvent();
// }
//}
public void Update()
{
if (HighLogic.LoadedSceneIsEditor)
{
dryMassInfo = part.mass;
}
}

private float getResource(int number)
{
Expand Down Expand Up @@ -250,10 +256,5 @@ private void setupTankList()
}
}
}
}

public class FSmodularTank
{
public List<engine.FSresource> resources = new List<engine.FSresource>();
}
}
}
32 changes: 24 additions & 8 deletions Firespitter/customization/FSmeshSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class FSmeshSwitch : PartModule
[KSPField]
public string previousButtonName = "Prev part variant";
[KSPField]
public string objectDisplayNames = "Default";
[KSPField]
public bool showPreviousButton = true;
[KSPField]
public bool useFuelSwitchModule = false;
Expand All @@ -22,23 +24,27 @@ public class FSmeshSwitch : PartModule
[KSPField]
public string objects = string.Empty;

// in case of multiple instances of this module, on will be the master, the rest slaves.
[KSPField]
public bool isController = true;
//// in case of multiple instances of this module, on will be the master, the rest slaves.
//[KSPField]
//public bool isController = true;

// in case of multiple sets of master/slaves, only affect ones on the same channel.
[KSPField]
public int channel = 0;
//// in case of multiple sets of master/slaves, only affect ones on the same channel.
//[KSPField]
//public int channel = 0;

[KSPField(isPersistant = true)]
public int selectedObject = 0;

private string[] objectNames;
private List<Transform> objectTransforms = new List<Transform>();
private List<int> fuelTankSetupList = new List<int>();
private List<string> objectDisplayList = new List<string>();

private FSfuelSwitch fuelSwitch;

[KSPField(guiActiveEditor = true, guiName = "Current Variant")]
public string currentObjectName = string.Empty;

[KSPEvent(guiActive = false, guiActiveEditor = true, guiActiveUnfocused = false, guiName = "Next part variant")]
public void nextObjectEvent()
{
Expand Down Expand Up @@ -102,7 +108,7 @@ private void switchToObject(int objectNumber)

private void setObject(int objectNumber)
{
if (objectNumber >= objectTransforms.Count) return;
//if (objectNumber >= objectTransforms.Count) return;

for (int i = 0; i < objectTransforms.Count; i++)
{
Expand All @@ -114,18 +120,28 @@ private void setObject(int objectNumber)

if (useFuelSwitchModule)
{
Debug.Log("FStextureSwitch2 calling on FSfuelSwitch tank setup " + objectNumber);
//Debug.Log("FStextureSwitch2 calling on FSfuelSwitch tank setup " + objectNumber);
if (objectNumber < fuelTankSetupList.Count)
fuelSwitch.selectTankSetup(fuelTankSetupList[objectNumber]);
else
Debug.Log("FStextureSwitch2: no such fuel tank setup");
}

if (selectedObject > objectDisplayList.Count - 1)
{
currentObjectName = objectNames[selectedObject];
}
else
{
currentObjectName = objectDisplayList[selectedObject];
}
}

public override void OnStart(PartModule.StartState state)
{
parseObjectNames();
fuelTankSetupList = Tools.parseIntegers(fuelTankSetups);
objectDisplayList = Tools.parseNames(objectDisplayNames);

if (useFuelSwitchModule)
{
Expand Down
12 changes: 12 additions & 0 deletions Firespitter/customization/FSmodularTank.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Firespitter.customization
{
public class FSmodularTank
{
public List<engine.FSresource> resources = new List<engine.FSresource>();
}
}
23 changes: 9 additions & 14 deletions Firespitter/customization/FStextureSwitch2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using UnityEngine;
using Firespitter.info;

namespace Firespitter.customization
{
Expand All @@ -17,7 +18,7 @@ public class FStextureSwitch2 : PartModule
[KSPField]
public string mapNames = string.Empty;
[KSPField]
public string textureDisplayNames = string.Empty;
public string textureDisplayNames = "Default";

[KSPField(isPersistant = true)]
public int selectedTexture = 0;
Expand Down Expand Up @@ -57,7 +58,7 @@ public class FStextureSwitch2 : PartModule

private FSfuelSwitch fuelSwitch;

Firespitter.info.FSdebugMessages debug = new Firespitter.info.FSdebugMessages(false, Firespitter.info.FSdebugMessages.OutputMode.both, 2f); //set to true for debug
FSdebugMessages debug = new FSdebugMessages(false, FSdebugMessages.OutputMode.both, 2f); //set to true for debug

[KSPField(guiActiveEditor = true, guiName = "Current Texture")]
public string currentTextureName = string.Empty;
Expand Down Expand Up @@ -176,8 +177,8 @@ public void useTexture(Material targetMat)

public override string GetInfo()
{
texList = parseNames(textureNames);
textureDisplayList = parseNames(textureDisplayNames);
texList = Tools.parseNames(textureNames);
textureDisplayList = Tools.parseNames(textureDisplayNames);
StringBuilder info = new StringBuilder();
info.AppendLine("Alternate textures available:");
if (texList.Count == 0)
Expand All @@ -202,20 +203,14 @@ private string getTextureDisplayName(string longName)
return splitString[splitString.Length - 1];
}

public List<string> parseNames(string names)
{
string[] nameArray = names.Split(';');
return nameArray.ToList();
}

public override void OnStart(PartModule.StartState state)
{
debug.debugMode = debugMode;

objectList = parseNames(objectNames);
texList = parseNames(textureNames);
mapList = parseNames(mapNames);
textureDisplayList = parseNames(textureDisplayNames);
objectList = Tools.parseNames(objectNames);
texList = Tools.parseNames(textureNames);
mapList = Tools.parseNames(mapNames);
textureDisplayList = Tools.parseNames(textureDisplayNames);
fuelTankSetupList = Tools.parseIntegers(fuelTankSetups);

debug.debugMessage("FStextureSwitch2 found " + texList.Count + " textures, using number " + selectedTexture + ", found " + objectList.Count + " objects, " + mapList.Count + " maps");
Expand Down
26 changes: 26 additions & 0 deletions Firespitter/tools/FStools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ public static List<int> parseIntegers(string stringOfInts)
}
return newIntList;
}


public static List<float> parseFloats(string stringOfFloats)
{
System.Collections.Generic.List<float> list = new System.Collections.Generic.List<float>();
string[] array = stringOfFloats.Split(';');
for (int i = 0; i < array.Length; i++)
{
float item = 0f;
if (float.TryParse(array[i], out item))
{
list.Add(item);
}
else
{
Debug.Log("invalid float: " + array[i]);
}
}
return list;
}

public static List<string> parseNames(string names)
{
string[] source = names.Split(';');
return source.ToList<string>();
}
}

public class MouseEventHandler : MonoBehaviour
Expand Down

0 comments on commit 364fe2b

Please sign in to comment.