public void RegisterBackgroundConverter(WBIOmniConverter converter) { WBIBackgroundConverter backgroundConverter = new WBIBackgroundConverter(); if (IsRegistered(converter)) { backgroundConverter = GetBackgroundConverter(converter); backgroundConverter.GetConverterData(converter); backgroundConverter.IsActivated = converter.IsActivated; backgroundConverter.isMissingResources = false; backgroundConverter.isContainerFull = false; backgroundConverter.vesselID = converter.part.vessel.id.ToString(); UpdateBackgroundConverter(backgroundConverter); return; } backgroundConverter.vesselID = converter.part.vessel.id.ToString(); backgroundConverter.GetConverterData(converter); backgroundConverters.Add(backgroundConverter.converterID, backgroundConverter); }
public override void OnLoad(ConfigNode node) { backgroundConverters = new Dictionary <string, WBIBackgroundConverter>(); //Housekeeping double.TryParse(node.GetValue("cycleStartTime"), out cycleStartTime); //Converters ConfigNode[] configNodes = node.GetNodes(WBIBackgroundConverter.NodeName); WBIBackgroundConverter converter; for (int index = 0; index < configNodes.Length; index++) { converter = new WBIBackgroundConverter(); converter.Load(configNodes[index]); if (!backgroundConverters.ContainsKey(converter.converterID)) { backgroundConverters.Add(converter.converterID, converter); } } }
protected IEnumerator <YieldInstruction> runConverter(WBIBackgroundConverter converter, double elapsedTime) { //If the vessel is currently loaded, then we're done bool vesselIsLoaded = false; Vessel[] loadedVessels = FlightGlobals.VesselsLoaded.ToArray(); for (int vesselIndex = 0; vesselIndex < loadedVessels.Length; vesselIndex++) { if (loadedVessels[vesselIndex].id.ToString() == converter.vesselID) { vesselIsLoaded = true; break; } } yield return(new WaitForFixedUpdate()); if (!vesselIsLoaded) { //Find the unloaded vessel int count = FlightGlobals.VesselsUnloaded.Count; Vessel[] unloadedVessels = FlightGlobals.VesselsUnloaded.ToArray(); Vessel unloadedVessel = null; ProtoVessel protoVessel; string unloadedVesselID; for (int index = 0; index < count; index++) { unloadedVessel = unloadedVessels[index]; unloadedVesselID = unloadedVessel.id.ToString(); if (unloadedVesselID == converter.vesselID) { break; } else { unloadedVessel = null; } } yield return(new WaitForFixedUpdate()); //Process our resources if we found the vessel. if (unloadedVessel != null) { //Get the proto vessel protoVessel = unloadedVessel.protoVessel; //Get ready to process converter.PrepareToProcess(protoVessel); yield return(new WaitForFixedUpdate()); //Check required converter.CheckRequiredResources(protoVessel, elapsedTime); yield return(new WaitForFixedUpdate()); //Consume inputs converter.ConsumeInputResources(protoVessel, elapsedTime); yield return(new WaitForFixedUpdate()); //Produce outputs converter.ProduceOutputResources(protoVessel, elapsedTime); yield return(new WaitForFixedUpdate()); //Produce yields converter.ProduceYieldResources(protoVessel); yield return(new WaitForFixedUpdate()); //Post process converter.PostProcess(protoVessel); } //We didn't find the vessel. Remove the converter from our list. else { backgroundConverters.Remove(converter.converterID); } } yield return(new WaitForFixedUpdate()); }
internal void Start() { Instance = this; backgroundConverters = WBIBackgroundConverter.GetBackgroundConverters(); }