Merge branch 'master' into preview

This commit is contained in:
NGnius (Graham) 2020-09-23 10:09:15 -04:00
commit d8064db54d
3 changed files with 58 additions and 17 deletions

View file

@ -4,9 +4,16 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using GamecraftModdingAPI.App;
using GamecraftModdingAPI.Blocks; using GamecraftModdingAPI.Blocks;
using GamecraftModdingAPI.Tasks;
using GamecraftModdingAPI.Utility; using GamecraftModdingAPI.Utility;
using MiniJSON;
using Svelto.Tasks;
using UnityEngine.ResourceManagement.ResourceLocations;
namespace Pixi.Common namespace Pixi.Common
{ {
@ -21,7 +28,7 @@ namespace Pixi.Common
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BlockColor QuantizeToBlockColor(Color pixel) public static BlockColor QuantizeToBlockColor(Color pixel)
{ {
if (colorMap == null) BuildColorMap(); //if (colorMap == null) BuildColorMap();
float[] closest = new float[3] { 1, 1, 1 }; float[] closest = new float[3] { 1, 1, 1 };
BlockColor c = new BlockColor BlockColor c = new BlockColor
{ {
@ -79,7 +86,7 @@ namespace Pixi.Common
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float[] UnquantizeToArray(BlockColor c) public static float[] UnquantizeToArray(BlockColor c)
{ {
if (colorMap == null) BuildColorMap(); //if (colorMap == null) BuildColorMap();
return colorMap[c]; return colorMap[c];
} }
@ -110,22 +117,15 @@ namespace Pixi.Common
}); });
} }
public static void LoadColorMenuEvent(object caller, MenuEventArgs info)
{
Scheduler.Schedule(new AsyncRunner());
}
private static void BuildColorMap() private static void BuildColorMap()
{ {
// old manual version for building color map
colorMap = new Dictionary<BlockColor, float[]>(); colorMap = new Dictionary<BlockColor, float[]>();
// 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 // White
colorMap[new BlockColor { Color = BlockColors.White, Darkness = 0 }] = new float[3] { 1f, 1f, 1f}; colorMap[new BlockColor { Color = BlockColors.White, Darkness = 0 }] = new float[3] { 1f, 1f, 1f};
@ -281,5 +281,41 @@ namespace Pixi.Common
botColorMap[31] = new BlockColor { Color = BlockColors.Pink, Darkness = 4 }; botColorMap[31] = new BlockColor { Color = BlockColors.Pink, Darkness = 4 };
botColorMap[15] = new BlockColor { Color = BlockColors.Red, Darkness = 3 }; botColorMap[15] = new BlockColor { Color = BlockColors.Red, Darkness = 3 };
} }
private class AsyncRunner : ISchedulable
{
public IEnumerator<TaskContract> Run()
{
AsyncOperationHandle<TextAsset> asyncHandle = Addressables.LoadAssetAsync<TextAsset>("colours");
yield return asyncHandle.Continue();
Dictionary<string, object> colourData = Json.Deserialize(asyncHandle.Result.text) as Dictionary<string, object>;
if (colourData == null) yield break;
Client.EnterMenu -= LoadColorMenuEvent;
// Logging.MetaLog((List<object>)((colourData["Colours"] as Dictionary<string, object>)["Data"] as Dictionary<string, object>)["Slots"]);
// Generate color map
List<object> hexColors =
(((colourData["Colours"] as Dictionary<string, object>)?["Data"] as Dictionary<string, object>)?
["Slots"] as List<object>);
int count = 0;
colorMap = new Dictionary<BlockColor, float[]>();
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++;
}
}
}
}
}
} }
} }

View file

@ -27,6 +27,11 @@ namespace Pixi.Images
public BlueprintProvider BlueprintProvider { get; } = null; public BlueprintProvider BlueprintProvider { get; } = null;
public ImageCanvasImporter()
{
GamecraftModdingAPI.App.Client.EnterMenu += ColorSpaceUtility.LoadColorMenuEvent;
}
public bool Qualifies(string name) public bool Qualifies(string name)
{ {
//Logging.MetaLog($"Qualifies received name {name}"); //Logging.MetaLog($"Qualifies received name {name}");

View file

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net472</TargetFramework> <TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.0.0</Version> <Version>1.0.1</Version>
<Authors>NGnius</Authors> <Authors>NGnius</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://git.exmods.org/NGnius/Pixi</PackageProjectUrl> <PackageProjectUrl>https://git.exmods.org/NGnius/Pixi</PackageProjectUrl>