Add support for getting the RGB of block colors
Only works if the constructors are used
This commit is contained in:
parent
4dfa7b0f4e
commit
c9e71d84b4
3 changed files with 24 additions and 16 deletions
|
@ -36,16 +36,11 @@ namespace GamecraftModdingAPI
|
|||
/// Place a new block at the given position. If scaled, position means the center of the block. The default block size is 0.2 in terms of position.
|
||||
/// Place blocks next to each other to connect them.
|
||||
/// The placed block will be a complete block with a placement grid and collision which will be saved along with the game.
|
||||
/// <para></para>
|
||||
/// <para>When placing multiple blocks, do not access properties immediately after creation as this
|
||||
/// triggers a sync each time which can affect performance and may cause issues with the game.
|
||||
/// You may either use AsyncUtils.WaitForSubmission() after placing all of the blocks
|
||||
/// or simply access the block properties which will trigger the synchronization the first time a property is used.</para>
|
||||
/// </summary>
|
||||
/// <param name="block">The block's type</param>
|
||||
/// <param name="color">The block's color</param>
|
||||
/// <param name="darkness">The block color's darkness (0-9) - 0 is default color</param>
|
||||
/// <param name="position">The block's position in the grid - default block size is 0.2</param>
|
||||
/// <param name="position">The block's position - default block size is 0.2</param>
|
||||
/// <param name="rotation">The block's rotation in degrees</param>
|
||||
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
|
||||
/// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
|
||||
|
@ -66,7 +61,7 @@ namespace GamecraftModdingAPI
|
|||
/// <param name="block">The block's type</param>
|
||||
/// <param name="color">The block's color</param>
|
||||
/// <param name="darkness">The block color's darkness (0-9) - 0 is default color</param>
|
||||
/// <param name="position">The block's position in the grid - default block size is 0.2</param>
|
||||
/// <param name="position">The block's position - default block size is 0.2</param>
|
||||
/// <param name="rotation">The block's rotation in degrees</param>
|
||||
/// <param name="uscale">The block's uniform scale - default scale is 1 (with 0.2 width)</param>
|
||||
/// <param name="scale">The block's non-uniform scale - 0 means <paramref name="uscale"/> is used</param>
|
||||
|
@ -192,7 +187,7 @@ namespace GamecraftModdingAPI
|
|||
type);
|
||||
ILGenerator il = dynamic.GetILGenerator();
|
||||
|
||||
il.DeclareLocal(type);
|
||||
//il.DeclareLocal(type);
|
||||
il.Emit(OpCodes.Ldarg_0); //Load EGID and pass to constructor
|
||||
il.Emit(OpCodes.Newobj, ctor); //Call constructor
|
||||
//il.Emit(OpCodes.Stloc_0); - doesn't seem like we need these
|
||||
|
@ -317,7 +312,7 @@ namespace GamecraftModdingAPI
|
|||
color.indexInPalette = (byte) (val.Color + val.Darkness * 10);
|
||||
color.overridePaletteColour = false;
|
||||
color.needsUpdate = true;
|
||||
BlockEngine.SetBlockColorFromPalette(ref color);
|
||||
color.paletteColour = BlockEngine.ConvertBlockColor(color.indexInPalette);
|
||||
}, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
namespace GamecraftModdingAPI.Blocks
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace GamecraftModdingAPI.Blocks
|
||||
{
|
||||
public struct BlockColor
|
||||
{
|
||||
public BlockColors Color;
|
||||
public byte Darkness;
|
||||
public byte Index;
|
||||
|
||||
public BlockColor(byte index)
|
||||
{
|
||||
|
@ -14,17 +18,27 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
if (index > 99)
|
||||
throw new ArgumentOutOfRangeException(nameof(index), "Invalid color index. Must be 0-90 or 255.");
|
||||
Color = (BlockColors) (index % 10);
|
||||
Darkness = (byte) (index / 10);
|
||||
}
|
||||
|
||||
Index = index;
|
||||
}
|
||||
|
||||
public BlockColor(BlockColors color, byte darkness)
|
||||
{
|
||||
if (darkness > 9)
|
||||
throw new ArgumentOutOfRangeException(nameof(darkness), "Darkness must be 0-9 where 0 is default.");
|
||||
Color = color;
|
||||
Darkness = darkness;
|
||||
if (color == BlockColors.Default) Index = byte.MaxValue;
|
||||
else Index = (byte) (darkness * 10 + color);
|
||||
}
|
||||
|
||||
public float4 RGBA => Block.BlockEngine.ConvertBlockColor(Index);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{nameof(Color)}: {Color}, {nameof(Darkness)}: {Darkness}";
|
||||
|
|
|
@ -13,6 +13,7 @@ using Svelto.ECS;
|
|||
using Svelto.ECS.Hybrid;
|
||||
|
||||
using GamecraftModdingAPI.Engines;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace GamecraftModdingAPI.Blocks
|
||||
{
|
||||
|
@ -54,12 +55,10 @@ namespace GamecraftModdingAPI.Blocks
|
|||
return ret;
|
||||
}
|
||||
|
||||
public void SetBlockColorFromPalette(ref ColourParameterEntityStruct color)
|
||||
{
|
||||
ref var paletteEntry = ref entitiesDB.QueryEntity<PaletteEntryEntityStruct>(color.indexInPalette,
|
||||
CommonExclusiveGroups.COLOUR_PALETTE_GROUP);
|
||||
color.paletteColour = paletteEntry.Colour;
|
||||
}
|
||||
public float4 ConvertBlockColor(byte index) => index == byte.MaxValue
|
||||
? new float4(-1f, -1f, -1f, -1f)
|
||||
: entitiesDB.QueryEntity<PaletteEntryEntityStruct>(index,
|
||||
CommonExclusiveGroups.COLOUR_PALETTE_GROUP).Colour;
|
||||
|
||||
public ref T GetBlockInfo<T>(EGID blockID) where T : unmanaged, IEntityComponent
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue