2020-09-28 01:10:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
2020-01-03 00:14:26 +00:00
|
|
|
|
{
|
2020-05-17 18:13:45 +00:00
|
|
|
|
public struct BlockColor
|
|
|
|
|
{
|
2021-04-15 23:40:30 +00:00
|
|
|
|
public BlockColors Color => Index == byte.MaxValue
|
|
|
|
|
? BlockColors.Default
|
|
|
|
|
: (BlockColors) (Index % 10);
|
2020-10-02 15:06:06 +00:00
|
|
|
|
|
2021-04-15 23:40:30 +00:00
|
|
|
|
public byte Darkness => (byte) (Index == byte.MaxValue
|
|
|
|
|
? 0
|
|
|
|
|
: Index / 10);
|
|
|
|
|
|
|
|
|
|
public byte Index { get; }
|
2020-05-17 18:13:45 +00:00
|
|
|
|
|
2020-06-04 22:20:35 +00:00
|
|
|
|
public BlockColor(byte index)
|
|
|
|
|
{
|
2021-04-15 23:40:30 +00:00
|
|
|
|
if (index > 99 && index != byte.MaxValue)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index), "Invalid color index. Must be 0-90 or 255.");
|
|
|
|
|
Index = index;
|
2020-06-04 22:20:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 23:40:30 +00:00
|
|
|
|
public BlockColor(BlockColors color, byte darkness = 0)
|
2020-06-04 22:20:35 +00:00
|
|
|
|
{
|
2020-09-28 01:10:59 +00:00
|
|
|
|
if (darkness > 9)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(darkness), "Darkness must be 0-9 where 0 is default.");
|
2021-04-15 23:40:30 +00:00
|
|
|
|
if (color > BlockColors.Red) //Last valid color
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(color), "Invalid color!");
|
|
|
|
|
Index = (byte) (darkness * 10 + (byte) color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static implicit operator BlockColor(BlockColors color)
|
|
|
|
|
{
|
|
|
|
|
return new BlockColor(color);
|
2020-06-04 22:20:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 01:10:59 +00:00
|
|
|
|
public float4 RGBA => Block.BlockEngine.ConvertBlockColor(Index);
|
|
|
|
|
|
2020-05-17 18:13:45 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return $"{nameof(Color)}: {Color}, {nameof(Darkness)}: {Darkness}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-04 00:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Preset block colours
|
|
|
|
|
/// </summary>
|
2021-04-15 23:40:30 +00:00
|
|
|
|
public enum BlockColors : byte
|
2020-01-03 00:14:26 +00:00
|
|
|
|
{
|
|
|
|
|
Default = byte.MaxValue,
|
|
|
|
|
White = 0,
|
|
|
|
|
Pink,
|
|
|
|
|
Purple,
|
|
|
|
|
Blue,
|
|
|
|
|
Aqua,
|
|
|
|
|
Green,
|
|
|
|
|
Lime,
|
|
|
|
|
Yellow,
|
|
|
|
|
Orange,
|
|
|
|
|
Red
|
|
|
|
|
}
|
|
|
|
|
}
|