From d7018f2c97cd0c0c89c401d999fe6364f8df0744 Mon Sep 17 00:00:00 2001 From: annabunches Date: Fri, 21 Feb 2025 16:52:01 -0500 Subject: [PATCH] Add merge block support to sequencer. --- ActionSequencer/Program.cs | 21 ++++++++++ Mixins/ActionGroups/ActionGroups.projitems | 1 + Mixins/ActionGroups/BlockActionMerge.cs | 45 ++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 Mixins/ActionGroups/BlockActionMerge.cs diff --git a/ActionSequencer/Program.cs b/ActionSequencer/Program.cs index 8801ef9..2b003fb 100644 --- a/ActionSequencer/Program.cs +++ b/ActionSequencer/Program.cs @@ -1,4 +1,5 @@ using Sandbox.ModAPI.Ingame; +using SpaceEngineers.Game.ModAPI.Ingame; using System; using System.Collections.Generic; using VRage.Game.ModAPI.Ingame.Utilities; @@ -169,6 +170,26 @@ namespace IngameScript Ini.Get(key, "velocity").ToSingle(2f) ); } + else if (block is IMyShipMergeBlock) + { + MergeAction action; + string config = Ini.Get(key, "action").ToString("merge").ToLower(); + switch (config) + { + case "merge": + action = MergeAction.Merge; + break; + case "unmerge": + action = MergeAction.Unmerge; + break; + default: + Console.Print($"Unknown action '{config}. Defaulting to merge."); + action = MergeAction.Merge; + break; + } + return new BlockActionMerge(block as IMyShipMergeBlock, action); + } + // TODO: there are several block types added for other scripts that we should support here. Console.Print($"Can't add unsupported block '{block.CustomName}'"); return null; diff --git a/Mixins/ActionGroups/ActionGroups.projitems b/Mixins/ActionGroups/ActionGroups.projitems index c9b57b6..c3625eb 100644 --- a/Mixins/ActionGroups/ActionGroups.projitems +++ b/Mixins/ActionGroups/ActionGroups.projitems @@ -11,6 +11,7 @@ + diff --git a/Mixins/ActionGroups/BlockActionMerge.cs b/Mixins/ActionGroups/BlockActionMerge.cs new file mode 100644 index 0000000..0d442b2 --- /dev/null +++ b/Mixins/ActionGroups/BlockActionMerge.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using Sandbox.ModAPI.Ingame; +using SpaceEngineers.Game.ModAPI.Ingame; + +namespace IngameScript +{ + partial class Program + { + public enum MergeAction + { + Merge, + Unmerge, + } + + public class BlockActionMerge : BlockAction + { + private IMyShipMergeBlock _connector; + private MergeAction _action; + + public BlockActionMerge( + IMyShipMergeBlock connector, + MergeAction action + ) + { + _connector = connector; + _action = action; + } + + protected override IEnumerator onRun() + { + switch (_action) + { + case MergeAction.Merge: + _connector.Enabled = true; + while (!_connector.IsConnected) yield return true; + break; + case MergeAction.Unmerge: + _connector.Enabled = false; + while (_connector.IsConnected) yield return true; + break; + } + } + } + } +} \ No newline at end of file