private void onLaunchedFromHangar(BaseEventDetails data) { if (!Valid) { return; } if (!data.GetBool("fromFairings")) { return; } var pm = data.Get <PartModule>("hangar"); if (pm == null || pm.vessel == null) { return; } var tca = AvailableTCA(pm.vessel); if (tca == null) { return; } reset(); CFG = tca.CloneConfig(); init(); }
public void OnChangeTextureScale(BaseEventDetails data) { if (ApplyLegacyTextures()) { legacyTextureHandler.ChangeTextureScale(data.Get <string>("meshName"), data.Get <Vector2>("targetScale")); } }
public void OnPartVolumeChanged(BaseEventDetails eventData) { Log("OnPartVolumeChanged called"); if (!started) { Log("Not yet started, returning"); cachedEventData = eventData; return; } try { float volume = (float)eventData.Get <double>("newTotalVolume"); Log("volume changed to ", volume); if (volume * FloatTolerance < cachedMinVolume && cachedMinVolume != float.MaxValue) { Log("volume of ", volume, " is less than expected min volume of ", cachedMinVolume, " expecting another update"); RefreshPartWindow(); //assuming the part will be resized return; } Log("setting cachedVolume to ", volume); cachedVolume = volume; SendRemainingVolume(); UpdateControllableMassSlider(); RefreshDisplays(); } catch (Exception ex) { Log("error getting changed volume: ", ex); } }
/// <summary> /// takes a volume in m^3 and sets up amounts for RF/MFT /// </summary> public void FuelSetResources() { if (!(CanBeFueled && HighLogic.LoadedSceneIsEditor)) { return; } if (!UseStockFuel) { // send public event OnPartVolumeChanged, like ProceduralParts does var data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <string>("volName", "Tankage"); data.Set("newTotalVolume", aeroStatVolume); //aeroStatVolume should be in m3 part.SendEvent("OnPartVolumeChanged", data, 0); } else { part.Resources.Clear(); PartResource[] partResources = part.GetComponents <PartResource>(); foreach (KeyValuePair <string, WingTankResource> kvp in StaticWingGlobals.wingTankConfigurations[fuelSelectedTankSetup].resources) { var newResourceNode = new ConfigNode("RESOURCE"); newResourceNode.AddValue("name", kvp.Value.resource.name); newResourceNode.AddValue("amount", kvp.Value.unitsPerVolume * aeroStatVolume); newResourceNode.AddValue("maxAmount", kvp.Value.unitsPerVolume * aeroStatVolume); part.AddResource(newResourceNode); } } }
private void UpdateMftModule() { try { if (_prefabPart.Modules.Contains("ModuleFuelTanks")) { scaleMass = false; PartModule m = _prefabPart.Modules["ModuleFuelTanks"]; FieldInfo fieldInfo = m.GetType().GetField("totalVolume", BindingFlags.Public | BindingFlags.Instance); if (fieldInfo != null) { double oldVol = (double)fieldInfo.GetValue(m) * 0.001d; BaseEventDetails data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <string>("volName", "Tankage"); data.Set <double>("newTotalVolume", oldVol * ScalingFactor.absolute.cubic); part.SendEvent("OnPartVolumeChanged", data, 0); } else { Log.warn("MFT interaction failed (fieldinfo=null)"); } } } catch (Exception e) { Log.warn("Exception during MFT interaction" + e.ToString()); } }
public void OnPartResourceInitialAmountChanged(BaseEventDetails data) { if (!GameSceneFilter.AnyEditor.IsLoaded()) { return; } if (selectedTankType == null) { return; } PartResource resource = data.Get <PartResource> ("resource"); TankResource tankResource = selectedTankType.resources.Find(r => r.name == name); if (tankResource == null || !tankResource.forceEmpty) { return; } if (resource != null && resource.amount > 0) { resource.amount = 0; InitialAmountChanged(part, resource, resource.amount); } }
public void OnPartVolumeChanged(BaseEventDetails data) { string volumeName = data.Get <string> ("volName"); double volume = data.Get <double> ("newTotalVolume"); if (volumeName != tankVolumeName) { return; } if (volume <= 0f) { throw new ArgumentOutOfRangeException("volume"); } tankVolume = (float)volume; //Debug.Log ((float)volume); volumeDisplay = volume.ToStringSI(4, 3, "L"); UpdateMassAndResources(false); if (HighLogic.LoadedSceneIsEditor) { GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } }
public void OnPartVolumeChanged(BaseEventDetails eventData) { Log("OnPartVolumeChanged called"); if (!started) { Log("Not yet started, returning"); cachedEventData = eventData; return; } try { float volume = (float)eventData.Get <double>("newTotalVolume"); Log("volume changed to ", volume); if (volume * FLOAT_ERROR_ALLOWANCE < cachedMinVolue && cachedMinVolue != float.MaxValue) { Log("volume of ", volume, " is less than expected min volume of ", cachedMinVolue, " expecting another update"); RefreshPartWindow(); //assuming the part will be resized return; } Log("setting cachedVolume to ", volume); cachedVolume = volume; //Log("cached total volume set from eventData: ", cachedVolume); AvionicsConfigChanged(); } catch (Exception ex) { Log("error getting changed volume: ", ex); } }
public void OnResourceInitialChanged(BaseEventDetails eventData) { if (_ecTank is FuelTank && eventData.Get <PartResource>("resource")?.part == _rfPM.part) { RefreshDisplays(); } }
public void OnPartVolumeChanged(BaseEventDetails data) { string volumeName = data.Get <string>("volName"); double volume = data.Get <double>("newTotalVolume"); if (volumeName != tankVolumeName) { Debug.LogWarning($"{ModTag} OnPartVolumeChanged for {this}, volumeName {volumeName} vs tankVolumeName {tankVolumeName}"); return; } if (volume <= 0f) { throw new ArgumentOutOfRangeException("volume"); } tankVolume = Convert.ToSingle(volume); volumeDisplay = tankVolume.ToStringSI(4, 3, "L"); UpdateTankMass(); UpdateResourceAmounts(); UpdateMassDisplay(); if (HighLogic.LoadedSceneIsEditor) { GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } }
public void OnResourceMaxChanged(BaseEventDetails data) { if (HighLogic.LoadedSceneIsEditor) { UpdateMaxThrust(true); } }
public void scaleNode(AttachNode node, float scale, bool setSize) { if (node == null) { return; } node.position = node.originalPosition * scale; if (!justLoaded) { PFUtils.updateAttachedPartPos(node, part); } if (setSize) { node.size = Mathf.RoundToInt(scale / diameterStepLarge); } if (node.attachedPart != null) { var baseEventDatum = new BaseEventDetails(0); baseEventDatum.Set <Vector3>("location", node.position); baseEventDatum.Set <Vector3>("orientation", node.orientation); baseEventDatum.Set <Vector3>("secondaryAxis", node.secondaryAxis); baseEventDatum.Set <AttachNode>("node", node); node.attachedPart.SendEvent("OnPartAttachNodePositionChanged", baseEventDatum); } }
private void CallUpdaters() { // two passes, to depend less on the order of this list int len = _updaters.Length; for (int i = 0; i < len; i++) { // first apply the exponents IRescalable updater = _updaters[i]; if (updater is TSGenericUpdater) { try { float oldMass = part.mass; updater.OnRescale(ScalingFactor); part.mass = oldMass; // make sure we leave this in a clean state } catch (Exception e) { Log.error("Exception on rescale: {0}", e); } } } if (_prefabPart.CrewCapacity > 0) { UpdateCrewManifest(); } if (part.Modules.Contains("ModuleDataTransmitter")) { UpdateAntennaPowerDisplay(); } // MFT support UpdateMftModule(); // TF support updateTestFlight(); // send scaling part message BaseEventDetails data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <float>("factorAbsolute", ScalingFactor.absolute.linear); data.Set <float>("factorRelative", ScalingFactor.relative.linear); part.SendEvent("OnPartScaleChanged", data, 0); len = _updaters.Length; for (int i = 0; i < len; i++) { IRescalable updater = _updaters[i]; // then call other updaters (emitters, other mods) if (updater is TSGenericUpdater) { continue; } updater.OnRescale(ScalingFactor); } }
//[PartMessageEvent] //public event PartMassChanged MassChanged; public void MassChanged(float mass) { var data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <float> ("mass", mass); part.SendEvent("OnPartMassChanged", data, 0); }
public void OnPartVolumeChanged(BaseEventDetails data) { if (HighLogic.LoadedSceneIsEditor && density > 0 && data.Get <double>("newTotalVolume") is double volume) { mass = Convert.ToSingle(density * volume); GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } }
// Events. These will get bound up automatically //[PartMessageEvent] //public event PartVolumeChanged ChangeVolume; public void ChangeVolume(string volName, double newVolume) { var data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <string> ("volName", volName); data.Set <double> ("newTotalVolume", newVolume); part.SendEvent("OnPartVolumeChanged", data, 0); }
public void RaiseResourceMaxChanged(PartResource resource, double amount) { var data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <PartResource> ("resource", resource); data.Set <double> ("amount", amount); part.SendEvent("OnResourceMaxChanged", data, 0); }
private void NotifyPartResourcesChanged() { BaseEventDetails data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <int>("InstanceID", this.part.GetInstanceID()); data.Set <Type>("issuer", this.GetType()); this.part.SendEvent("OnPartResourcesChanged", data, 0); }
public void OnPartNodeMoved(BaseEventDetails data) { if (data.Get <AttachNode>("node") is AttachNode node && node == bottomAttachNode) { MoveBellAndBottomNode(); SetBellRotation(thrustDeflection); } }
public void SendVolumeChangedEvent(float newVol) { var data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <string>("volName", "Tankage"); data.Set <double>("newTotalVolume", newVol); part.SendEvent("OnPartVolumeChanged", data, 0); }
void ExDiscoverWorkshops(BaseEventDetails data) { // Recyclers are not actual work-sinks, but the master is needed // to check the vessel producitivity if (sm != null) { sm.SetMaster(data.Get <ExWorkshop> ("master")); } }
//[PartMessageListener(typeof(PartAttachNodeSizeChanged), scenes: GameSceneFilter.AnyEditor)] //public void ChangeAttachNodeSize(AttachNode node, float minDia, float area) public void ChangeAttachNodeSize(AttachNode node, float minDia, float area) { var data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set("node", node); data.Set <float> ("minDia", minDia); data.Set <float> ("area", area); part.SendEvent("OnPartAttachNodeSizeChanged", data, 0); }
private void NotifyPartSurfaceAttachmentChanged() { BaseEventDetails data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <int>("InstanceID", this.part.GetInstanceID()); data.Set <Type>("issuer", this.GetType()); data.Set <AttachNode>("srfAttachNode", this.part.srfAttachNode); this.part.SendEvent("OnPartSurfaceAttachmentChanged", data, 0); }
public void OnResourceInitialChanged(BaseEventDetails eventData) { if (_ecTank == null || eventData.Get <PartResource>("resource")?.part != _rfPM.part) { return; } StartCoroutine(DeferredRFTankChangeHandler()); }
void OnPartVolumeChanged(BaseEventDetails data) { string volName = data.Get <string> ("volName"); double newTotalVolume = data.Get <double> ("newTotalVolume") * tankVolumeConversion; if (volName == "Tankage") { ChangeTotalVolume(newTotalVolume); } }
public void PartAttachNodeSizeChanged(BaseEventDetails data) { AttachNode node = data.Get <AttachNode> ("node"); if (node.id != topNodeId) { return; } CopyNodeSizeAndStrength(); }
void OnPartVolumeChanged(BaseEventDetails data) { var volName = data.Get <string>("volName"); var newTotalVolume = (float)data.Get <double>("newTotalVolume"); if (volName == "Tankage") { Rescale(newTotalVolume / Volume, HighLogic.LoadedSceneIsEditor); } }
void OnPartScaleChanged(BaseEventDetails data) { if (managed) { return; } var scale = data.Get <float>("factorRelative"); SetVolume(Volume * scale * scale * scale); }
internal void OnPartScaleChanged(BaseEventDetails data) { float factorAbsolute = data.Get <float>("factorAbsolute"); float factorRelative = data.Get <float>("factorRelative"); Log.dbg("PartMessage: OnPartScaleChanged:" + "\npart=" + part.name + "\nfactorRelative=" + factorRelative.ToString() + "\nfactorAbsolute=" + factorAbsolute.ToString()); }
private void NotifyPartScaleChanged() { BaseEventDetails data = new BaseEventDetails(BaseEventDetails.Sender.USER); data.Set <int>("InstanceID", this.part.GetInstanceID()); data.Set <Type>("issuer", this.GetType()); data.Set <float>("factorAbsolute", ScalingFactor.absolute.linear); data.Set <float>("factorRelative", ScalingFactor.relative.linear); this.part.SendEvent("OnPartScaleChanged", data, 0); }