Skip to content

Commit

Permalink
1.3.3
Browse files Browse the repository at this point in the history
Fix for KSP 1.3
Search for IScienceDataContainer instead of ModuleScienceContainer for
higher mod compatibility
  • Loading branch information
Xarun committed Jun 4, 2017
1 parent 547b4aa commit c766665
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 32 deletions.
24 changes: 17 additions & 7 deletions source/AutomatedScienceSampler/AutomatedScienceSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AutomatedScienceSampler : KerboKatzBase<Settings>, IToolbar
private static List<GameScenes> _activeScences = new List<GameScenes>() { GameScenes.FLIGHT };
private Sprite _icon = AssetLoader.GetAsset<Sprite>("icon56", "Icons/AutomatedScienceSampler", "AutomatedScienceSampler/AutomatedScienceSampler");
private List<ModuleScienceExperiment> experiments;
private List<ModuleScienceContainer> scienceContainers;
private List<IScienceDataContainer> scienceContainers;
private Dropdown transferScienceUIElement;
private bool uiElementsReady;
private string settingsUIName;
Expand Down Expand Up @@ -185,7 +185,7 @@ private void OnTransferScienceChange(int arg0)
Log("OnTransferScienceChange ");
if (craftSettings.currentContainer != 0 && scienceContainers.Count >= craftSettings.currentContainer)
{
StartCoroutine(DisableHighlight(0.25f, scienceContainers[craftSettings.currentContainer - 1].part));
StartCoroutine(DisableHighlight(0.25f, ((PartModule)scienceContainers[craftSettings.currentContainer - 1]).part));
}
SaveSettings();
}
Expand Down Expand Up @@ -407,7 +407,7 @@ private void CheckExperimentOptions(ModuleScienceExperiment experiment, IScience
}
else if (CanTransferExperiment(experiment, activator))
{

activator.Transfer(experiment, scienceContainers[craftSettings.currentContainer - 1]);
}
else if (CanResetExperiment(experiment, activator))
Expand Down Expand Up @@ -477,7 +477,7 @@ private bool BasicTransferCheck()
return false;
if (craftSettings.currentContainer > scienceContainers.Count)
return false;
if (scienceContainers[craftSettings.currentContainer - 1].vessel != FlightGlobals.ActiveVessel)
if (((PartModule)scienceContainers[craftSettings.currentContainer - 1]).vessel != FlightGlobals.ActiveVessel)
return false;
return true;
}
Expand Down Expand Up @@ -509,11 +509,20 @@ private void UpdateShipInformation()
transferScienceUIElement.options.RemoveAt(transferScienceUIElement.options.Count - 1);
}
experiments = FlightGlobals.ActiveVessel.FindPartModulesImplementing<ModuleScienceExperiment>();
scienceContainers = FlightGlobals.ActiveVessel.FindPartModulesImplementing<ModuleScienceContainer>();
//scienceContainers = FlightGlobals.ActiveVessel.FindPartModulesImplementing<ModuleScienceContainer>();
scienceContainers = FlightGlobals.ActiveVessel.FindPartModulesImplementing<IScienceDataContainer>();
for(var i = scienceContainers.Count-1; i >= 0; i--)
{
if (scienceContainers[i].GetType().IsTypeOf(typeof(ModuleScienceExperiment)))//dont want stock ModuleScienceExperiment as a transfer target as these can only contain the experiments results
{
Log("Removing ", (scienceContainers[i] as PartModule).moduleName, " as transfer target");
scienceContainers.RemoveAt(i);
}
}
shipCotainsExperiments.Clear();
foreach (ModuleScienceContainer currentContainer in scienceContainers)
foreach (var currentContainer in scienceContainers)
{
AddOptionToDropdown(transferScienceUIElement, currentContainer.part.partInfo.title);
AddOptionToDropdown(transferScienceUIElement, (currentContainer as PartModule).part.partInfo.title);
foreach (var data in currentContainer.GetData())
{
AddToContainer(data.subjectID);
Expand All @@ -537,6 +546,7 @@ private void AddToContainer(string subjectID, int add = 0)
}
}


#region IToolbar

public List<GameScenes> activeScences
Expand Down
18 changes: 12 additions & 6 deletions source/AutomatedScienceSampler/DefaultActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool CanRunExperiment(ModuleScienceExperiment baseExperiment, float curre
_AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Science value is less than cutoff threshold: ", currentScienceValue, "<", _AutomatedScienceSamplerInstance.craftSettings.threshold);
return false;
}
if(baseExperiment.GetData().Length > 0)
if (baseExperiment.GetData().Length > 0)
{
_AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Experiment already contains results!");
return false;
Expand Down Expand Up @@ -74,8 +74,8 @@ public void DeployExperiment(ModuleScienceExperiment baseExperiment)

public ScienceSubject GetScienceSubject(ModuleScienceExperiment baseExperiment)
{
//experiment.BiomeIsRelevantWhile
return ResearchAndDevelopment.GetExperimentSubject(baseExperiment.experiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, CurrentBiome(baseExperiment.experiment));
string currentBiome = CurrentBiome(baseExperiment.experiment);
return ResearchAndDevelopment.GetExperimentSubject(baseExperiment.experiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, currentBiome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, currentBiome));
}

public float GetScienceValue(ModuleScienceExperiment baseExperiment, Dictionary<string, int> shipCotainsExperiments, ScienceSubject currentScienceSubject)
Expand Down Expand Up @@ -131,9 +131,15 @@ public void Reset(ModuleScienceExperiment baseExperiment)
baseExperiment.ResetExperiment();
}

public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
public bool CanTransfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer)
{
_AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": CanTransfer");

if (moduleScienceContainer == baseExperiment as IScienceDataContainer)
{//no point in transfering to the same container
_AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Experiment is same as Container ", baseExperiment.GetScienceCount());
return false;
}
if (baseExperiment.GetScienceCount() == 0)
{
_AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Experiment has no data skiping transfer ", baseExperiment.GetScienceCount());
Expand Down Expand Up @@ -162,10 +168,10 @@ public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceCon
return true;
}

public void Transfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
public void Transfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer)
{
_AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": transfering");
moduleScienceContainer.StoreData(new List<IScienceDataContainer>() { baseExperiment }, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates);
moduleScienceContainer.StoreData(baseExperiment, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates);
}

private string CurrentBiome(ScienceExperiment baseExperiment)
Expand Down
4 changes: 2 additions & 2 deletions source/AutomatedScienceSampler/IScienceActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public interface IScienceActivator

void Reset(ModuleScienceExperiment baseExperimentModule);

bool CanTransfer(ModuleScienceExperiment baseExperimentModule, ModuleScienceContainer moduleScienceContainer);
bool CanTransfer(ModuleScienceExperiment baseExperimentModule, IScienceDataContainer moduleScienceContainer);

void Transfer(ModuleScienceExperiment baseExperimentModule, ModuleScienceContainer moduleScienceContainer);
void Transfer(ModuleScienceExperiment baseExperimentModule, IScienceDataContainer moduleScienceContainer);
}
}
2 changes: 1 addition & 1 deletion source/AutomatedScienceSampler/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,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("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
//[assembly: AssemblyFileVersion("0.26.1.0")]
10 changes: 5 additions & 5 deletions source/Plugins/DMModuleScienceAnimateGeneric/Activator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public ScienceSubject GetScienceSubject(ModuleScienceExperiment baseExperiment)
{
ExperimentSituations situation = ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel);
var biome = currentExperiment.getBiome(situation);
_AutomatedScienceSamplerInstance.Log(biome, "_", situation, "_", ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome) == null);
return ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome);
_AutomatedScienceSamplerInstance.Log(biome, "_", situation, "_", ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, biome)) == null);
return ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, biome));
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ public void Reset(ModuleScienceExperiment baseExperiment)
currentExperiment.ResetExperiment();
}

public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
public bool CanTransfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer)
{
var currentExperiment = baseExperiment as DMModuleScienceAnimateGeneric.DMModuleScienceAnimateGeneric;
if ((currentExperiment as IScienceDataContainer).GetScienceCount() == 0)
Expand Down Expand Up @@ -152,11 +152,11 @@ public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceCon
return true;
}

public void Transfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
public void Transfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer)
{
var currentExperiment = baseExperiment as DMModuleScienceAnimateGeneric.DMModuleScienceAnimateGeneric;
_AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": transfering");
moduleScienceContainer.StoreData(new List<IScienceDataContainer>() { currentExperiment as DMModuleScienceAnimateGeneric.DMModuleScienceAnimateGeneric }, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates);
moduleScienceContainer.StoreData(currentExperiment as DMModuleScienceAnimateGeneric.DMModuleScienceAnimateGeneric, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates);
}

public List<Type> GetValidTypes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,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("1.3.1")]
[assembly: AssemblyVersion("1.3.3")]
//[assembly: AssemblyFileVersion("0.26.1.0")]
8 changes: 4 additions & 4 deletions source/Plugins/DMagic Orbital Science/Activator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ScienceSubject GetScienceSubject(ModuleScienceExperiment baseExperiment)
return null;
}
//_AutomatedScienceSamplerInstance.Log(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID) == null, FlightGlobals.currentMainBody == null, biome == null);
var scienceSubject = ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome);
var scienceSubject = ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, biome));
_AutomatedScienceSamplerInstance.Log(biome, "_", situation, "_", scienceSubject == null);
return scienceSubject;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public void Reset(ModuleScienceExperiment baseExperiment)
currentExperiment.ResetExperiment();
}

public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
public bool CanTransfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer)
{
var currentExperiment = baseExperiment as DMModuleScienceAnimate;
if ((currentExperiment as IScienceDataContainer).GetScienceCount() == 0)
Expand Down Expand Up @@ -177,11 +177,11 @@ public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceCon
return true;
}

public void Transfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
public void Transfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer)
{
var currentExperiment = baseExperiment as DMModuleScienceAnimate;
_AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": transfering");
moduleScienceContainer.StoreData(new List<IScienceDataContainer>() { currentExperiment as DMModuleScienceAnimate }, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates);
moduleScienceContainer.StoreData(currentExperiment as DMModuleScienceAnimate , _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates);
}

public List<Type> GetValidTypes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,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("1.3.2")]
[assembly: AssemblyVersion("1.3.3")]
//[assembly: AssemblyFileVersion("0.26.1.0")]
9 changes: 5 additions & 4 deletions source/Plugins/Station Science/Activator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public void DeployExperiment(ModuleScienceExperiment baseExperiment)
public ScienceSubject GetScienceSubject(ModuleScienceExperiment baseExperiment)
{
//experiment.BiomeIsRelevantWhile
return ResearchAndDevelopment.GetExperimentSubject(baseExperiment.experiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, CurrentBiome(baseExperiment.experiment));
string biome = CurrentBiome(baseExperiment.experiment);
return ResearchAndDevelopment.GetExperimentSubject(baseExperiment.experiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, biome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, biome));
}

public float GetScienceValue(ModuleScienceExperiment baseExperiment, Dictionary<string, int> shipCotainsExperiments, ScienceSubject currentScienceSubject)
Expand Down Expand Up @@ -141,7 +142,7 @@ public void Reset(ModuleScienceExperiment baseExperiment)
baseExperiment.ResetExperiment();
}

public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
public bool CanTransfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer)
{
if (baseExperiment.GetScienceCount() == 0)
{
Expand Down Expand Up @@ -171,10 +172,10 @@ public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceCon
return true;
}

public void Transfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
public void Transfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer)
{
_AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": transfering");
moduleScienceContainer.StoreData(new List<IScienceDataContainer>() { baseExperiment }, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates);
moduleScienceContainer.StoreData(baseExperiment , _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates);
}

private string CurrentBiome(ScienceExperiment baseExperiment)
Expand Down
2 changes: 1 addition & 1 deletion source/Plugins/Station Science/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,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("1.3.1")]
[assembly: AssemblyVersion("1.3.3")]
//[assembly: AssemblyFileVersion("0.26.1.0")]

0 comments on commit c766665

Please sign in to comment.