Skip to content

Commit

Permalink
Merge pull request #127 from UmbraSpaceIndustries/DEVELOP
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
BobPalmer authored Mar 11, 2018
2 parents 4ca3618 + 486d205 commit d74c093
Show file tree
Hide file tree
Showing 18 changed files with 669 additions and 330 deletions.
4 changes: 4 additions & 0 deletions FOR_RELEASE/GameData/000_USITools/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.11.1 - 2018.03.11
-----------------
SwapConverter Fixes

0.11.0 - 2018.03.07
------------------
KSP 1.4.0 Compatibility
Expand Down
Binary file modified FOR_RELEASE/GameData/000_USITools/USITools.dll
Binary file not shown.
Binary file modified FOR_RELEASE/GameData/000_USITools/USITools.dll.mdb
Binary file not shown.
Binary file modified FOR_RELEASE/GameData/000_USITools/USITools.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion FOR_RELEASE/GameData/000_USITools/USITools.version
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"VERSION":{
"MAJOR":0,
"MINOR":11,
"PATCH":0,
"PATCH":1,
"BUILD":0
},
"KSP_VERSION":{
Expand Down
3 changes: 1 addition & 2 deletions USITools/USITools/ConverterPart.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using UnityEngine;
using System.Collections.Generic;

namespace USITools
{
Expand Down
4 changes: 2 additions & 2 deletions USITools/USITools/IEfficiencyBonusConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool useEfficiencyBonus
get;
}

void EnableModule();
void DisableModule();
void EnableConsumer();
void DisableConsumer();
}
}
1 change: 1 addition & 0 deletions USITools/USITools/LoadoutInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class LoadoutInfo
{
public int ModuleId { get; set; }
public string LoadoutName { get; set; }
public float BaseEfficiency { get; set; }
public string DecalTexture { get; set; }
}
}
15 changes: 15 additions & 0 deletions USITools/USITools/ModuleResourceConverter_USI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,20 @@ public override string GetModuleDisplayName()
return GetType().Name;
}

public void EnableConsumer()
{
base.EnableModule();
isEnabled = true;
MonoUtilities.RefreshContextWindows(part);
}

public void DisableConsumer()
{
DisableModule();
isEnabled = false;
MonoUtilities.RefreshContextWindows(part);
}


}
}
13 changes: 13 additions & 0 deletions USITools/USITools/ModuleResourceHarvester_USI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,18 @@ public void SetEfficiencyBonus(string bonName, float bonVal)
}

public bool useEfficiencyBonus => UseBonus;
public void EnableConsumer()
{
base.EnableModule();
isEnabled = true;
MonoUtilities.RefreshContextWindows(part);
}

public void DisableConsumer()
{
DisableModule();
isEnabled = false;
MonoUtilities.RefreshContextWindows(part);
}
}
}
142 changes: 0 additions & 142 deletions USITools/USITools/ModuleSwapController.cs

This file was deleted.

113 changes: 113 additions & 0 deletions USITools/USITools/ModuleSwapControllerNew.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

namespace USITools
{
public class ModuleSwapControllerNew : PartModule
{
[KSPField]
public string ResourceCosts = "";

[KSPField]
public string typeName = "Loadout";

public List<ResourceRatio> ResCosts;
public List<ModuleSwapOption> Loadouts;
private List<ModuleResourceHarvester_USI> _harvesters;
private List<ModuleResourceConverter_USI> _converters;

private double lastCheck;
private double checkInterval = 5d;

public override void OnStart(StartState state)
{
Loadouts = part.FindModulesImplementing<ModuleSwapOption>();
_converters = part.FindModulesImplementing<ModuleResourceConverter_USI>();
_harvesters = part.FindModulesImplementing<ModuleResourceHarvester_USI>();
SetupResourceCosts();
}

private void SetupResourceCosts()
{
ResCosts = new List<ResourceRatio>();
if (String.IsNullOrEmpty(ResourceCosts))
return;

var resources = ResourceCosts.Split(',');
for (int i = 0; i < resources.Length; i += 2)
{
ResCosts.Add(new ResourceRatio
{
ResourceName = resources[i],
Ratio = double.Parse(resources[i + 1])
});
}
}

public override string GetInfo()
{
if (String.IsNullOrEmpty(ResourceCosts))
return "";

var output = new StringBuilder("Resource Cost:\n\n");
var resources = ResourceCosts.Split(',');
for (int i = 0; i < resources.Length; i += 2)
{
output.Append(string.Format("{0} {1}\n", double.Parse(resources[i + 1]), resources[i]));
}
return output.ToString();
}

public void ApplyLoadout(int loadIdx, int moduleIdx, bool isConverter)
{
var loadout = Loadouts[loadIdx];
if (isConverter)
{
ApplyConverterChanges(_converters[moduleIdx], loadout);
}
else
{
ApplyHarvesterChanges(_harvesters[moduleIdx], loadout);
}
}

private void ApplyConverterChanges(ModuleResourceConverter_USI converter, ModuleSwapOption loadout)
{
converter.ConverterName = loadout.ConverterName;
converter.StartActionName = loadout.StartActionName;
converter.StopActionName = loadout.StopActionName;
converter.UseSpecialistBonus = loadout.UseSpecialistBonus;
if (converter.UseSpecialistBonus)
converter.ExperienceEffect = loadout.ExperienceEffect;

converter.inputList.Clear();
converter.outputList.Clear();
converter.reqList.Clear();

converter.Recipe.Inputs.Clear();
converter.Recipe.Outputs.Clear();
converter.Recipe.Requirements.Clear();

converter.inputList.AddRange(loadout.inputList);
converter.outputList.AddRange(loadout.outputList);
converter.reqList.AddRange(loadout.reqList);

converter.Recipe.Inputs.AddRange(loadout.inputList);
converter.Recipe.Outputs.AddRange(loadout.outputList);
converter.Recipe.Requirements.AddRange(loadout.reqList);
}

private void ApplyHarvesterChanges(ModuleResourceHarvester_USI harvester, ModuleSwapOption loadout)
{
harvester.Efficiency = loadout.Efficiency;
harvester.ResourceName = loadout.ResourceName;
harvester.ConverterName = loadout.ConverterName;
harvester.StartActionName = loadout.StartActionName;
harvester.StopActionName = loadout.StopActionName;
MonoUtilities.RefreshContextWindows(part);
}
}
}
Loading

0 comments on commit d74c093

Please sign in to comment.