Files
PCK-Studio/MinecraftUSkinEditor/Classes/Utils/SkinANIM.cs
MattNL 7461fbae9c ANIM editor and small changes
-Moved and renamed the LCESkin class to the SkinANIM class in preperation of the ANIM Editor
-Added the ANIM editor, which is more or less a port of my ANIM tool on my website. Double click an ANIM tag to open it. If the value is invalid, it will go to the normal meta tag prompt to allow you to fix it.
- Added two template skins in the resources so the ANIM editor can utilize them for creating proper templates.
-Added a resolution combobox for creating Texture Packs.
-Increased the limit from 3 to 5 for the MipMapLevel option in the Animation Editor.
-Fixed some bugs with the Play Overworld Songs in Creative feature in the Music Editor
2022-08-02 16:22:45 -04:00

134 lines
3.2 KiB
C#

using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace PckStudio.Classes.Utils
{
[Flags]
public enum eANIM_EFFECTS : int
{
STATIC_ARMS = 1 << 0,
ZOMBIE_ARMS = 1 << 1,
STATIC_LEGS = 1 << 2,
BAD_SANTA = 1 << 3,
unk_BIT4 = 1 << 4, // Whatever effect this is should be a simple one as it's existed for a while
SYNCED_LEGS = 1 << 5,
SYNCED_ARMS = 1 << 6,
STATUE_OF_LIBERTY = 1 << 7,
ALL_ARMOR_DISABLED = 1 << 8,
HEAD_BOBBING_DISABLED = 1 << 9,
HEAD_DISABLED = 1 << 10,
RIGHT_ARM_DISABLED = 1 << 11,
LEFT_ARM_DISABLED = 1 << 12,
BODY_DISABLED = 1 << 13,
RIGHT_LEG_DISABLED = 1 << 14,
LEFT_LEG_DISABLED = 1 << 15,
HEAD_OVERLAY_DISABLED = 1 << 16,
DO_BACKWARDS_CROUCH = 1 << 17,
RESOLUTION_64x64 = 1 << 18,
SLIM_MODEL = 1 << 19,
LEFT_ARM_OVERLAY_DISABLED = 1 << 20,
RIGHT_ARM_OVERLAY_DISABLED = 1 << 21,
LEFT_LEG_OVERLAY_DISABLED = 1 << 22,
RIGHT_LEG_OVERLAY_DISABLED = 1 << 23,
BODY_OVERLAY_DISABLED = 1 << 24,
FORCE_HEAD_ARMOR = 1 << 25,
FORCE_RIGHT_ARM_ARMOR = 1 << 26,
FORCE_LEFT_ARM_ARMOR = 1 << 27,
FORCE_BODY_ARMOR = 1 << 28,
FORCE_RIGHT_LEG_ARMOR = 1 << 29,
FORCE_LEFT_LEG_ARMOR = 1 << 30,
DINNERBONE = 1 << 31,
}
internal class SkinANIM
{
eANIM_EFFECTS _ANIM;
public bool isValid;
public SkinANIM()
{
_ANIM = 0;
}
public SkinANIM(string anim)
{
// Port of my ANIM Generator found at https://mattnl.com/lce/anim-generator - MattNL
if (anim.StartsWith("0x")) anim = anim.Substring(2);
isValid = anim.Length <= 8 && Regex.IsMatch(anim, @"\A\b[0-9a-fA-F]+\b\Z");
if (isValid)
{
anim = anim.PadLeft(8, '0');
string bits = String.Join("", anim.Select(
b => Convert.ToString(Convert.ToInt32(b.ToString(), 16), 2).PadLeft(4, '0')
)
);
int current_bit = 31;
foreach (char bit in bits)
{
SetANIMFlag((eANIM_EFFECTS)(1 << current_bit), bit == '1');
current_bit--;
}
}
}
public SkinANIM(eANIM_EFFECTS anim)
{
_ANIM = anim;
}
public string ToString(bool getBits = false)
{
string bits = "";
foreach (eANIM_EFFECTS effect in Enum.GetValues(typeof(eANIM_EFFECTS)))
{
bits += GetANIMFlag(effect) ? "1" : "0";
}
char[] bitArray = bits.ToCharArray();
Array.Reverse(bitArray);
bits = new string(bitArray).PadLeft(32, '0');
if(getBits) return bits;
string new_anim = Convert.ToInt32(bits, 2).ToString("X");
return "0x" + new_anim.PadLeft(8, '0').ToLower();
}
public override string ToString()
{
return ToString(false);
}
/// <summary>
/// Sets the desired flag in the bitfield
/// </summary>
/// <param name="flag">ANIM Flag to be set</param>
/// <param name="state">wether to enable the flag</param>
public void SetANIMFlag(eANIM_EFFECTS flag, bool state)
{
if (state) _ANIM |= flag;
else _ANIM &= ~flag;
}
/// <summary>
/// Returns true if the desired flag is set in the bitfield, otherwise false
/// </summary>
/// <param name="flag">ANIM Flag to check</param>
/// <returns>Bool wether its set or not</returns>
public bool GetANIMFlag(eANIM_EFFECTS flag)
{
return ((int)_ANIM & (int)flag) != 0;
}
}
}