From 1b126b69c0e78015166c42075ab6177c1b2d0217 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 23 Aug 2020 10:31:04 -0400 Subject: [PATCH 1/2] Convert to new GCIPA --- Pixi/PixiPlugin.cs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Pixi/PixiPlugin.cs b/Pixi/PixiPlugin.cs index 15e1e28..f93dfe5 100644 --- a/Pixi/PixiPlugin.cs +++ b/Pixi/PixiPlugin.cs @@ -15,16 +15,16 @@ using Pixi.Robots; namespace Pixi { - public class PixiPlugin : IPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin' + public class PixiPlugin : IEnhancedPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin' { - public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; // Pixi + public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; // Pixi // To change the name, change the project's name - public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); + public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); // To change the version, change #.#.# in Pixi.csproj // called when Gamecraft shuts down - public void OnApplicationQuit() + public override void OnApplicationQuit() { // Shutdown this mod Logging.LogDebug($"{Name} has shutdown"); @@ -34,7 +34,7 @@ namespace Pixi } // called when Gamecraft starts up - public void OnApplicationStart() + public override void OnApplicationStart() { // Initialize the Gamecraft modding API first GamecraftModdingAPI.Main.Init(); @@ -55,15 +55,5 @@ namespace Pixi RobotCommands.CreatePartDumpCommand(); #endif } - - // unused methods - - public void OnFixedUpdate() { } // called once per physics update - - public void OnLevelWasInitialized(int level) { } // called after a level is initialized - - public void OnLevelWasLoaded(int level) { } // called after a level is loaded - - public void OnUpdate() { } // called once per rendered frame (frame update) } } \ No newline at end of file From 4b35647c0b21fe69e907984589fe277ecd510ce5 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Fri, 4 Sep 2020 16:00:12 -0400 Subject: [PATCH 2/2] Use official paint colours for conversion algorithm --- Pixi/Common/ColorSpaceUtility.cs | 68 +++++++++++++++++++++++------- Pixi/Images/ImageCanvasImporter.cs | 5 +++ Pixi/Pixi.csproj | 2 +- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/Pixi/Common/ColorSpaceUtility.cs b/Pixi/Common/ColorSpaceUtility.cs index 554a843..82c7bae 100644 --- a/Pixi/Common/ColorSpaceUtility.cs +++ b/Pixi/Common/ColorSpaceUtility.cs @@ -4,9 +4,16 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine; +using UnityEngine.AddressableAssets; +using UnityEngine.ResourceManagement.AsyncOperations; +using GamecraftModdingAPI.App; using GamecraftModdingAPI.Blocks; +using GamecraftModdingAPI.Tasks; using GamecraftModdingAPI.Utility; +using MiniJSON; +using Svelto.Tasks; +using UnityEngine.ResourceManagement.ResourceLocations; namespace Pixi.Common { @@ -21,7 +28,7 @@ namespace Pixi.Common [MethodImpl(MethodImplOptions.AggressiveInlining)] public static BlockColor QuantizeToBlockColor(Color pixel) { - if (colorMap == null) BuildColorMap(); + //if (colorMap == null) BuildColorMap(); float[] closest = new float[3] { 1, 1, 1 }; BlockColor c = new BlockColor { @@ -79,7 +86,7 @@ namespace Pixi.Common [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float[] UnquantizeToArray(BlockColor c) { - if (colorMap == null) BuildColorMap(); + //if (colorMap == null) BuildColorMap(); return colorMap[c]; } @@ -110,23 +117,16 @@ namespace Pixi.Common }); } + public static void LoadColorMenuEvent(object caller, MenuEventArgs info) + { + Scheduler.Schedule(new AsyncRunner()); + } + private static void BuildColorMap() { + // old manual version for building color map colorMap = new Dictionary(); - // TODO create actual color map - foreach (BlockColors c in Enum.GetValues(typeof(BlockColors))) - { - for (byte d = 0; d < 10; d++) - { - BlockColor colorStruct = new BlockColor - { - Color = c, - Darkness = d, - }; - colorMap[colorStruct] = new float[3] { 1f, 0f, 1f }; - } - } - // this was done manually -- never again + // this was done manually -- never again // White colorMap[new BlockColor { Color = BlockColors.White, Darkness = 0 }] = new float[3] { 1f, 1f, 1f}; colorMap[new BlockColor { Color = BlockColors.White, Darkness = 1 }] = new float[3] { 0.88f, 0.98f, 0.99f }; @@ -281,5 +281,41 @@ namespace Pixi.Common botColorMap[31] = new BlockColor { Color = BlockColors.Pink, Darkness = 4 }; botColorMap[15] = new BlockColor { Color = BlockColors.Red, Darkness = 3 }; } + + private class AsyncRunner : ISchedulable + { + public IEnumerator Run() + { + AsyncOperationHandle asyncHandle = Addressables.LoadAssetAsync("colours"); + yield return asyncHandle.Continue(); + Dictionary colourData = Json.Deserialize(asyncHandle.Result.text) as Dictionary; + if (colourData == null) yield break; + Client.EnterMenu -= LoadColorMenuEvent; + // Logging.MetaLog((List)((colourData["Colours"] as Dictionary)["Data"] as Dictionary)["Slots"]); + // Generate color map + List hexColors = + (((colourData["Colours"] as Dictionary)?["Data"] as Dictionary)? + ["Slots"] as List); + int count = 0; + colorMap = new Dictionary(); + for (byte d = 0; d < 10; d++) + { + foreach (BlockColors c in Enum.GetValues(typeof(BlockColors))) + { + if (c != BlockColors.Default) + { + BlockColor colorStruct = new BlockColor + { + Color = c, + Darkness = d, + }; + Color pixel = Images.PixelUtility.PixelHex((string)hexColors[count]); + colorMap[colorStruct] = new float[] {pixel.r, pixel.g, pixel.b}; + count++; + } + } + } + } + } } } diff --git a/Pixi/Images/ImageCanvasImporter.cs b/Pixi/Images/ImageCanvasImporter.cs index 76bc4a1..23a8fe2 100644 --- a/Pixi/Images/ImageCanvasImporter.cs +++ b/Pixi/Images/ImageCanvasImporter.cs @@ -26,6 +26,11 @@ namespace Pixi.Images public string Name { get; } = "ImageCanvas~Spell"; public BlueprintProvider BlueprintProvider { get; } = null; + + public ImageCanvasImporter() + { + GamecraftModdingAPI.App.Client.EnterMenu += ColorSpaceUtility.LoadColorMenuEvent; + } public bool Qualifies(string name) { diff --git a/Pixi/Pixi.csproj b/Pixi/Pixi.csproj index 0216950..6aaf0ba 100644 --- a/Pixi/Pixi.csproj +++ b/Pixi/Pixi.csproj @@ -3,7 +3,7 @@ net472 true - 1.0.0 + 1.0.1 NGnius MIT https://git.exmods.org/NGnius/Pixi