diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bcbcf97 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,39 @@ +# Rules in this file were initially inferred by Visual Studio IntelliCode from the D:\YandexDisk\SRC\SpaceEngineers\wContainerSorter codebase based on best match to current usage at 24.01.2023 +# You can modify the rules from these initially generated values to suit your own policies +# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference +[*.cs] + + +#Core editorconfig formatting - indentation + +#use soft tabs (spaces) for indentation +indent_style = space + +#Formatting - spacing options + +#do not place space characters after the opening parenthesis and before the closing parenthesis of a method call +csharp_space_between_method_call_parameter_list_parentheses = false +#place a space character after the opening parenthesis and before the closing parenthesis of a method declaration parameter list. +csharp_space_between_method_declaration_parameter_list_parentheses = false + +#Style - expression bodied member options + +#prefer block bodies for constructors +csharp_style_expression_bodied_constructors = false:suggestion + +#Style - implicit and explicit types + +#prefer var over explicit type in all cases, unless overridden by another code style rule +csharp_style_var_elsewhere = true:suggestion + +#Style - modifier options + +#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods. +dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion + +#Style - Modifier preferences + +#when this rule is set to a list of modifiers, prefer the specified ordering. +csharp_preferred_modifier_order = static,public:suggestion +insert_final_newline=true +csharp_new_line_before_open_brace=all diff --git a/wContainerSorter.sln b/wContainerSorter.sln new file mode 100644 index 0000000..8771936 --- /dev/null +++ b/wContainerSorter.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33214.272 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wContainerSorter", "wContainerSorter\wContainerSorter.csproj", "{1EDEB5E2-21FC-4571-999C-DC4CEDE78067}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E471A6FA-5174-4D81-AA71-CEF6C130194A}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1EDEB5E2-21FC-4571-999C-DC4CEDE78067}.Debug|x64.ActiveCfg = Debug|x64 + {1EDEB5E2-21FC-4571-999C-DC4CEDE78067}.Debug|x64.Build.0 = Debug|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9CACD287-2581-4CD8-9010-F1A2DBACB58B} + EndGlobalSection +EndGlobal diff --git a/wContainerSorter/Instructions.readme b/wContainerSorter/Instructions.readme new file mode 100644 index 0000000..ed30ab7 --- /dev/null +++ b/wContainerSorter/Instructions.readme @@ -0,0 +1,5 @@ +R e a d m e +----------- + +In this file you can include any instructions or other comments you want to have injected onto the +top of your final script. You can safely delete this file if you do not want any such comments. diff --git a/wContainerSorter/MDK/Bootstrapper.cs b/wContainerSorter/MDK/Bootstrapper.cs new file mode 100644 index 0000000..dd86886 --- /dev/null +++ b/wContainerSorter/MDK/Bootstrapper.cs @@ -0,0 +1,27 @@ +using Malware.MDKUtilities; + +namespace IngameScript.MDK +{ + public class TestBootstrapper + { + // All the files in this folder, as well as all files containing the file ".debug.", will be excluded + // from the build process. You can use this to create utilites for testing your scripts directly in + // Visual Studio. + + static TestBootstrapper() + { + // Initialize the MDK utility framework + MDKUtilityFramework.Load(); + } + + public static void Main() + { + // In order for your program to actually run, you will need to provide a mockup of all the facilities + // your script uses from the game, since they're not available outside of the game. + + // Create and configure the desired program. + var program = MDKFactory.CreateProgram(); + MDKFactory.Run(program); + } + } +} \ No newline at end of file diff --git a/wContainerSorter/MDK/MDK.options.props b/wContainerSorter/MDK/MDK.options.props new file mode 100644 index 0000000..0c01f05 --- /dev/null +++ b/wContainerSorter/MDK/MDK.options.props @@ -0,0 +1,18 @@ + + + + + 1.4.12 + + no + + + None + + + mdk + + + \ No newline at end of file diff --git a/wContainerSorter/MDK/MDK.paths.props b/wContainerSorter/MDK/MDK.paths.props new file mode 100644 index 0000000..180c851 --- /dev/null +++ b/wContainerSorter/MDK/MDK.paths.props @@ -0,0 +1,81 @@ + + + + + 1.4.12 + no + V:\Steam\SteamApps\common\SpaceEngineers\Bin64 + c:\users\w0lf\appdata\local\microsoft\visualstudio\16.0_4163267d\extensions\3itxx5kv.f04 + C:\Users\W0LF\AppData\Roaming\SpaceEngineers\IngameScripts\local + + + + $(MDKGameBinPath)\System.Collections.Immutable.dll + false + + + $(MDKGameBinPath)\Sandbox.Common.dll + False + + + $(MDKGameBinPath)\Sandbox.Game.dll + False + + + $(MDKGameBinPath)\Sandbox.Graphics.dll + False + + + $(MDKGameBinPath)\SpaceEngineers.Game.dll + False + + + $(MDKGameBinPath)\SpaceEngineers.ObjectBuilders.dll + False + + + $(MDKGameBinPath)\VRage.dll + False + + + $(MDKGameBinPath)\VRage.Audio.dll + False + + + $(MDKGameBinPath)\VRage.Game.dll + False + + + $(MDKGameBinPath)\VRage.Input.dll + False + + + $(MDKGameBinPath)\VRage.Library.dll + False + + + $(MDKGameBinPath)\VRage.Math.dll + False + + + $(MDKGameBinPath)\VRage.Render.dll + False + + + $(MDKGameBinPath)\VRage.Render11.dll + False + + + $(MDKGameBinPath)\VRage.Scripting.dll + False + + + $(MDKInstallPath)\MDKUtilities.dll + True + + + + \ No newline at end of file diff --git a/wContainerSorter/Program.cs b/wContainerSorter/Program.cs new file mode 100644 index 0000000..4d9d30b --- /dev/null +++ b/wContainerSorter/Program.cs @@ -0,0 +1,88 @@ +using Sandbox.Game.EntityComponents; +using Sandbox.ModAPI.Ingame; +using Sandbox.ModAPI.Interfaces; + +using SpaceEngineers.Game.ModAPI.Ingame; + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; + +using VRage; +using VRage.Collections; +using VRage.Game; +using VRage.Game.Components; +using VRage.Game.GUI.TextPanel; +using VRage.Game.ModAPI.Ingame; +using VRage.Game.ModAPI.Ingame.Utilities; +using VRage.Game.ObjectBuilders.Definitions; + +using VRageMath; + +namespace IngameScript +{ + partial class Program : MyGridProgram + { + + // ---------- + // wContainerSorter, v0.2 + // Copyright (c) 2023 by W0LF aka 'dreamforce' + // + // This script sorts the content of the containers. + + // Type of sorting. + // By default (empty string) - sort by item's Type (MyObjectBuilder_Component/Computer, MyObjectBuilder_Ore/Stone, etc). + // It can be a "Name" string - sort by SubtypeId (Computer, Stone). + static readonly string sortType = ""; + + // NO CHANGES BELOW // + static List containers = new List(); + static List containerItems = new List(); + + public Program() + { + Runtime.UpdateFrequency = UpdateFrequency.Update100; + } + + public void Main(string argument, UpdateType updateSource) + { + IMyTextPanel lcd = GridTerminalSystem.GetBlockWithName("LCD") as IMyTextPanel; + lcd.ContentType = ContentType.TEXT_AND_IMAGE; + lcd.WriteText(""); + + containers.Clear(); + + GridTerminalSystem.GetBlocksOfType(containers); + + foreach (var container in containers) + { + containerItems.Clear(); + IMyInventory containerInventory = container.GetInventory(); + containerInventory.GetItems(containerItems); + + if (sortType.ToUpper() == "NAME") containerItems.Sort((MyInventoryItem x, MyInventoryItem y) => x.Type.SubtypeId.ToString().CompareTo(y.Type.SubtypeId.ToString())); + else containerItems.Sort((MyInventoryItem x, MyInventoryItem y) => x.Type.ToString().CompareTo(y.Type.ToString())); + + foreach (MyInventoryItem item in containerItems) + { + for (int i = 0; i < containerInventory.ItemCount; i++) + { + MyInventoryItem item2 = (MyInventoryItem)containerInventory.GetItemAt(i); + if (item.Equals(item2)) containerInventory.TransferItemTo(containerInventory, i, i + containerInventory.ItemCount, true); + } + } + + lcd.WriteText($"{container.CustomName}:\n", true); + foreach (MyInventoryItem item in containerItems) lcd.WriteText($"{item.Type} - {item.Amount}\n", true); + lcd.WriteText("\n", true); + } + } + // ---------- + + + + } +} diff --git a/wContainerSorter/thumb.png b/wContainerSorter/thumb.png new file mode 100644 index 0000000..5f05800 Binary files /dev/null and b/wContainerSorter/thumb.png differ diff --git a/wContainerSorter/wContainerSorter.csproj b/wContainerSorter/wContainerSorter.csproj new file mode 100644 index 0000000..fe8471c --- /dev/null +++ b/wContainerSorter/wContainerSorter.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {1EDEB5E2-21FC-4571-999C-DC4CEDE78067} + Exe + IngameScript + wContainerSorter + v4.6.1 + 512 + true + + + + true + bin\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + 6 + + + + + + + + + + + + + + + + + + Always + + + Always + + + + + + + + + + + + \ No newline at end of file