XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.SpaceEngineers.ScriptingHelper

【DLL】太空工程师SpaceEngineer脚本依赖辅助

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension.SpaceEngineers.ScriptingHelper

完善部分内容

d468d59
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

5 个文件 +92 -44
Deleted XFEExtension.SpaceEngineers.ScriptingHelper/IProgramBase.cs +0 -27
@@ -1,27 +0,0 @@
1 using Sandbox.ModAPI;
2 using Sandbox.ModAPI.Ingame;
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8
9 namespace XFEExtension.SpaceEngineers.ScriptingHelper;
10
11 /// <summary>
12 /// Provides a base class for programmable scripts in a grid-based environment, enabling custom logic execution in
13 /// response to system events.
14 /// </summary>
15 /// <remarks>Inherit from ProgramBase to implement script behavior for grid systems. Override the Main method to
16 /// define how your script responds to arguments and update events. This class is intended for use in environments where
17 /// scripts are triggered by various update sources, such as timers or user actions.</remarks>
18 public abstract class ProgramBase : MyGridProgram
19 {
20 /// <summary>
21 /// Executes the main entry point for the program, processing the specified argument based on the provided update
22 /// source.
23 /// </summary>
24 /// <param name="argument">The input string to be processed. Cannot be null; represents the command or data to handle.</param>
25 /// <param name="updateSource">The source of the update triggering the execution. Determines how the argument is interpreted and processed.</param>
26 public abstract void Main(string argument, UpdateType updateSource);
27 }
Deleted XFEExtension.SpaceEngineers.ScriptingHelper/Program.cs +0 -15
@@ -1,15 +0,0 @@
1 using Sandbox.ModAPI.Ingame;
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Threading.Tasks;
7
8 namespace XFEExtension.SpaceEngineers.ScriptingHelper;
9
10 public class Program : ProgramBase
11 {
12 public override void Main(string argument, UpdateType updateSource)
13 {
14 }
15 }
Added XFEExtension.SpaceEngineers.ScriptingHelper/ProgramBase.cs +68 -0
@@ -0,0 +1,68 @@
1 using System;
2 using System.Collections.Generic;
3 using Sandbox.ModAPI.Ingame;
4
5 namespace XFEExtension.SpaceEngineers.ScriptingHelper;
6
7 /// <summary>
8 /// 提供一个基类,用于在基于网格的环境中编写可编程脚本,使其能够响应系统事件执行自定义逻辑。<br/>
9 /// Provides a base class for programmable scripts in a grid-based environment, enabling custom logic execution in
10 /// response to system events.
11 /// </summary>
12 /// <remarks>Inherit from ProgramBase to implement script behavior for grid systems. Override the Main method to
13 /// define how your script responds to arguments and update events. This class is intended for use in environments where
14 /// scripts are triggered by various update sources, such as timers or user actions.</remarks>
15 public abstract class ProgramBase : MyGridProgram
16 {
17 /// <summary>
18 /// Retrieves a block of the specified type with the given name.
19 /// </summary>
20 /// <typeparam name="T">The type of block to retrieve.</typeparam>
21 /// <param name="name">The name of the block.</param>
22 /// <returns>The block instance if found; otherwise, null.</returns>
23 public T GetBlock<T>(string name) where T : class, IMyTerminalBlock
24 {
25 return GridTerminalSystem.GetBlockWithName(name) as T;
26 }
27
28 /// <summary>
29 /// Retrieves the first block of the specified type that matches the optional filter.
30 /// </summary>
31 /// <typeparam name="T">The type of block to retrieve.</typeparam>
32 /// <param name="collect">An optional filter function.</param>
33 /// <returns>The block instance if found; otherwise, null.</returns>
34 public T GetBlock<T>(Func<T, bool> collect = null) where T : class, IMyTerminalBlock
35 {
36 var list = new List<T>();
37 GridTerminalSystem.GetBlocksOfType(list, collect);
38 return list.Count > 0 ? list[0] : null;
39 }
40
41 /// <summary>
42 /// Retrieves a list of blocks of the specified type, optionally filtered.
43 /// </summary>
44 /// <typeparam name="T">The type of blocks to retrieve.</typeparam>
45 /// <param name="collect">An optional filter function.</param>
46 /// <returns>A list of blocks matching the criteria.</returns>
47 public List<T> GetBlocks<T>(Func<T, bool> collect = null) where T : class, IMyTerminalBlock
48 {
49 var list = new List<T>();
50 GridTerminalSystem.GetBlocksOfType(list, collect);
51 return list;
52 }
53
54 /// <summary>
55 /// 当游戏内脚本执行时调用。根据传入的参数和更新源执行相应的逻辑。<br/>
56 /// Executes the main entry point for the program, processing the specified argument based on the provided update
57 /// source.
58 /// </summary>
59 /// <param name="argument">需要处理的输入字符串。不能为空;表示要处理的命令或数据。<br/>The input string to be processed. Cannot be null; represents the command or data to handle.</param>
60 /// <param name="updateSource">触发执行的更新源。决定如何解释和处理参数。<br/>The source of the update triggering the execution. Determines how the argument is interpreted and processed.</param>
61 public abstract void Main(string argument, UpdateType updateSource);
62
63 /// <summary>
64 /// 当游戏内脚本需要保存其状态时调用。可以在此方法中实现任何必要的逻辑来持久化数据,以便在脚本重新加载时恢复状态。<br/>
65 /// Called when the program needs to save its state.
66 /// </summary>
67 public abstract void Save();
68 }
Modified XFEExtension.SpaceEngineers.ScriptingHelper/XFEExtension.SpaceEngineers.ScriptingHelper.csproj +5 -2
@@ -23,6 +23,7 @@
23 23 <ErrorReport>prompt</ErrorReport>
24 24 <WarningLevel>4</WarningLevel>
25 25 <DocumentationFile>bin\Debug\XFEExtension.SpaceEngineers.ScriptingHelper.xml</DocumentationFile>
26 <GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
26 27 </PropertyGroup>
27 28 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28 29 <DebugType>pdbonly</DebugType>
@@ -94,9 +95,11 @@
94 95 </Reference>
95 96 </ItemGroup>
96 97 <ItemGroup>
97 <Compile Include="IProgramBase.cs" />
98 <Compile Include="Program.cs" />
98 <Compile Include="ProgramBase.cs" />
99 99 <Compile Include="Properties\AssemblyInfo.cs" />
100 100 </ItemGroup>
101 <ItemGroup>
102 <None Include="XFEExtension.SpaceEngineers.ScriptingHelper.nuspec" />
103 </ItemGroup>
101 104 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
102 105 </Project>
Added XFEExtension.SpaceEngineers.ScriptingHelper/XFEExtension.SpaceEngineers.ScriptingHelper.nuspec +19 -0
@@ -0,0 +1,19 @@
1 <?xml version="1.0" encoding="utf-8"?>
2 <package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3 <metadata>
4 <id>XFEExtension.SpaceEngineers.ScriptingHelper</id>
5 <version>1.0.0</version>
6 <authors>XFEStudio</authors>
7 <description>Provides a base class for Space Engineers scripts. Adds ProgramBase directly to your project for easy copy-pasting into the game.</description>
8 <dependencies>
9 <group targetFramework=".NETFramework4.8" />
10 </dependencies>
11 <contentFiles>
12 <files include="cs/any/ProgramBase.cs" buildAction="Compile" />
13 </contentFiles>
14 </metadata>
15 <files>
16 <file src="ProgramBase.cs" target="content/ProgramBase.cs" />
17 <file src="ProgramBase.cs" target="contentFiles/cs/any/ProgramBase.cs" />
18 </files>
19 </package>