diff --git a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/Communication/DefinitionAPI.cs b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/Communication/DefinitionAPI.cs index 543c9d0e7..d65731723 100644 --- a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/Communication/DefinitionAPI.cs +++ b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/Communication/DefinitionAPI.cs @@ -19,7 +19,7 @@ public class ModularDefinitionApi /// /// The expected API version. Don't touch this unless you're developing for the Modular Assemblies Framework. /// - public const int ApiVersion = 2; + public const int ApiVersion = 3; /// /// Triggered whenever the API is ready - added to by the constructor or manually. @@ -163,18 +163,18 @@ public IMyCubeGrid GetAssemblyGrid(int assemblyId) /// Registers an Action triggered on assembly removal. /// /// - public void AddOnAssemblyClose(Action action) + public void RegisterOnAssemblyClose(string definitionName, Action action) { - _addOnAssemblyClose?.Invoke(action); + _registerOnAssemblyClose?.Invoke(definitionName, action); } /// /// De-registers an Action(AssemblyId) triggered on assembly removal. /// /// - public void RemoveOnAssemblyClose(Action action) + public void UnregisterOnAssemblyClose(string definitionName, Action action) { - _removeOnAssemblyClose?.Invoke(action); + _unregisterOnAssemblyClose?.Invoke(definitionName, action); } /// @@ -194,9 +194,9 @@ public void RecreateAssembly(int assemblyId) /// public T GetAssemblyProperty(int assemblyId, string propertyName) { - var value = _getAssemblyProperty(assemblyId, propertyName); + object value = _getAssemblyProperty(assemblyId, propertyName); - return value == null ? default(T) : (T)value; + return value == null ? default(T) : (T) value; } /// @@ -283,6 +283,7 @@ public string[] RegisterDefinitions(DefinitionDefs.ModularDefinitionContainer mo RegisterOnPartAdd(definition.Name, definition.OnPartAdd); RegisterOnPartRemove(definition.Name, definition.OnPartRemove); RegisterOnPartDestroy(definition.Name, definition.OnPartDestroy); + RegisterOnAssemblyClose(definition.Name, definition.OnAssemblyClose); if (validDefinitions.Contains(definition.Name)) definition.OnInit?.Invoke(); @@ -440,8 +441,8 @@ public void RemoveChatCommand(string command) private Func _getMemberParts; private Func _getBasePart; private Func _getAssemblyGrid; - private Action> _addOnAssemblyClose; - private Action> _removeOnAssemblyClose; + private Action> _registerOnAssemblyClose; + private Action> _unregisterOnAssemblyClose; private Action _recreateAssembly; private Func _getAssemblyProperty; private Action _setAssemblyProperty; @@ -498,8 +499,8 @@ public bool ApiAssign() SetApiMethod("GetMemberParts", ref _getMemberParts); SetApiMethod("GetBasePart", ref _getBasePart); SetApiMethod("GetAssemblyGrid", ref _getAssemblyGrid); - SetApiMethod("AddOnAssemblyClose", ref _addOnAssemblyClose); - SetApiMethod("RemoveOnAssemblyClose", ref _removeOnAssemblyClose); + SetApiMethod("RegisterOnAssemblyClose", ref _registerOnAssemblyClose); + SetApiMethod("UnregisterOnAssemblyClose", ref _unregisterOnAssemblyClose); SetApiMethod("RecreateAssembly", ref _recreateAssembly); SetApiMethod("GetAssemblyProperty", ref _getAssemblyProperty); SetApiMethod("SetAssemblyProperty", ref _setAssemblyProperty); @@ -662,6 +663,14 @@ public class ModularPhysicalDefinition /// public Action OnPartDestroy { get; set; } + /// + /// Called when an assembly is closed. Note - OnPartRemove will not be called. + /// + /// Arg1 is PhysicalAssemblyId + /// + /// + public Action OnAssemblyClose { get; set; } + /// /// All allowed SubtypeIds. The mod will likely misbehave if two mods allow the same blocks, so please be cautious. /// diff --git a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/FusionParts.cs b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/FusionParts.cs index 137f07be5..00f82c1c0 100644 --- a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/FusionParts.cs +++ b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/FusionParts.cs @@ -29,6 +29,11 @@ internal partial class ModularDefinition // You can remove this function, and any others if need be. }, + OnAssemblyClose = assemblyId => + { + SFusionManager.I.FusionSystems.Remove(assemblyId); + }, + // The most important block in an assembly. Connection checking starts here. BaseBlockSubtype = null, diff --git a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/FusionParts/S_FusionManager.cs b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/FusionParts/S_FusionManager.cs index dc44c7d6c..69eaae41d 100644 --- a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/FusionParts/S_FusionManager.cs +++ b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/FusionParts/S_FusionManager.cs @@ -9,8 +9,6 @@ internal class SFusionManager { public static SFusionManager I = new SFusionManager(); - private bool _didRegisterAssemblyClose; - private int _ticks; public ModularDefinition FusionDefinition; public Dictionary FusionSystems = new Dictionary(); @@ -29,12 +27,6 @@ public void Unload() public void UpdateTick() { - if (!_didRegisterAssemblyClose && (ModularApi?.IsReady ?? false)) - { - ModularApi.AddOnAssemblyClose(assemblyId => FusionSystems.Remove(assemblyId)); - _didRegisterAssemblyClose = true; - } - foreach (var fusionSystem in FusionSystems.Values) fusionSystem.UpdateTick(); diff --git a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts.cs b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts.cs index 0aece114e..5490a45a9 100644 --- a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts.cs +++ b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts.cs @@ -28,6 +28,11 @@ internal partial class ModularDefinition // Triggers whenever a part is destroyed, simultaneously with OnPartRemove OnPartDestroy = null, + OnAssemblyClose = assemblyId => + { + HeatManager.I.RemoveAssembly(assemblyId); + }, + // The most important block in an assembly. Connection checking starts here. BaseBlockSubtype = null, diff --git a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts/GridHeatManager.cs b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts/GridHeatManager.cs index e2384241e..34e874fc3 100644 --- a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts/GridHeatManager.cs +++ b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts/GridHeatManager.cs @@ -58,6 +58,11 @@ public void UpdateTick() HeatRatio = HeatStored / (HeatCapacity + BaseHeatCapacity); } + public void RemoveAssembly(int assemblyId) + { + _heatSystems.Remove(assemblyId); + } + private void Update15Tick() { var gridSize = (Grid.Max - Grid.Min + Vector3I.One) * Grid.GridSize; diff --git a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts/HeatManager.cs b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts/HeatManager.cs index 8749312f5..d770a90f5 100644 --- a/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts/HeatManager.cs +++ b/Utility Mods/Stable/Modular Assembly Mods/MoA Fusion Systems/Data/Scripts/ModularAssemblies/HeatParts/HeatManager.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Sandbox.ModAPI; using VRage.Game.ModAPI; using VRage.ModAPI; @@ -34,6 +35,12 @@ public void UpdateTick() system.UpdateTick(); } + public void RemoveAssembly(int assemblyId) + { + foreach (var system in _heatSystems.Values) + system.RemoveAssembly(assemblyId); + } + public float GetGridHeatLevel(IMyCubeGrid grid) { return _heatSystems.GetValueOrDefault(grid, null)?.HeatRatio ?? -1;