mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-07-01 01:22:07 +00:00
SkinBOX - Change class to record & make member properties getter only
This commit is contained in:
@@ -44,14 +44,28 @@ namespace PckStudio.Extensions
|
||||
{
|
||||
if (!skinBox.IsValidType())
|
||||
return "";
|
||||
if (skinBox.IsOverlayPart())
|
||||
return skinBox.Type;
|
||||
int index = Array.IndexOf(SkinBOX.BaseTypes, skinBox.Type);
|
||||
return SkinBOX.OverlayTypes.IndexInRange(index) ? SkinBOX.OverlayTypes[index] : "";
|
||||
}
|
||||
|
||||
public static string GetOverlayType(string type)
|
||||
{
|
||||
if (!SkinBOX.IsValidType(type))
|
||||
return "";
|
||||
if (SkinBOX.IsOverlayPart(type))
|
||||
return type;
|
||||
int index = Array.IndexOf(SkinBOX.BaseTypes, type);
|
||||
return SkinBOX.OverlayTypes.IndexInRange(index) ? SkinBOX.OverlayTypes[index] : "";
|
||||
}
|
||||
|
||||
public static string GetBaseType(this SkinBOX skinBox)
|
||||
{
|
||||
if (!skinBox.IsValidType())
|
||||
return "";
|
||||
if (skinBox.IsBasePart())
|
||||
return skinBox.Type;
|
||||
int index = Array.IndexOf(SkinBOX.OverlayTypes, skinBox.Type);
|
||||
return SkinBOX.BaseTypes.IndexInRange(index) ? SkinBOX.BaseTypes[index] : "";
|
||||
}
|
||||
@@ -60,6 +74,8 @@ namespace PckStudio.Extensions
|
||||
{
|
||||
if (!SkinBOX.IsValidType(type))
|
||||
return "";
|
||||
if (SkinBOX.IsBasePart(type))
|
||||
return type;
|
||||
int index = Array.IndexOf(SkinBOX.OverlayTypes, type);
|
||||
return SkinBOX.BaseTypes.IndexInRange(index) ? SkinBOX.BaseTypes[index] : "";
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace PckStudio.Forms.Editor
|
||||
|
||||
private void createToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var boxEditor = new BoxEditor(SkinBOX.Empty, _allowInflate);
|
||||
var boxEditor = new BoxEditor(SkinBOX.DefaultHead, _allowInflate);
|
||||
if (boxEditor.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
SkinBOX newBox = boxEditor.Result;
|
||||
@@ -225,7 +225,7 @@ namespace PckStudio.Forms.Editor
|
||||
{
|
||||
if (skinPartListBox.SelectedItem is SkinBOX box)
|
||||
{
|
||||
var clone = (SkinBOX)box.Clone();
|
||||
SkinBOX clone = box;
|
||||
renderer3D1.ModelData.Add(clone);
|
||||
_skin.Model.AdditionalBoxes.Add(clone);
|
||||
skinPartListBindingSource.ResetBindings(false);
|
||||
|
||||
@@ -20,12 +20,13 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using PckStudio.Extensions;
|
||||
|
||||
namespace PckStudio.Internal.Skin
|
||||
{
|
||||
public class SkinBOX : ICloneable, IEquatable<SkinBOX>
|
||||
public record SkinBOX : IEquatable<SkinBOX>
|
||||
{
|
||||
public static readonly SkinBOX Empty = new SkinBOX("HEAD", new Vector3(-4, -8, -4), new Vector3(8), Vector2.Zero);
|
||||
public static readonly SkinBOX DefaultHead = new SkinBOX("HEAD", new Vector3(-4, -8, -4), new Vector3(8), Vector2.Zero);
|
||||
|
||||
public static readonly string[] BaseTypes = new string[]
|
||||
{
|
||||
@@ -85,13 +86,13 @@ namespace PckStudio.Internal.Skin
|
||||
|
||||
public static readonly string[] ValidBoxTypes = BaseTypes.Concat(OverlayTypes).ToArray();
|
||||
|
||||
public string Type { get; set; }
|
||||
public Vector3 Pos;
|
||||
public Vector3 Size;
|
||||
public Vector2 UV;
|
||||
public bool HideWithArmor;
|
||||
public bool Mirror;
|
||||
public float Scale;
|
||||
public string Type { get; }
|
||||
public Vector3 Pos { get; }
|
||||
public Vector3 Size { get; }
|
||||
public Vector2 UV { get; }
|
||||
public bool HideWithArmor { get; }
|
||||
public bool Mirror { get; }
|
||||
public float Scale { get; }
|
||||
|
||||
public SkinBOX(string type, Vector3 pos, Vector3 size, Vector2 uv,
|
||||
bool hideWithArmor = false, bool mirror = false, float scale = 0.0f)
|
||||
@@ -116,14 +117,13 @@ namespace PckStudio.Internal.Skin
|
||||
Vector3 pos = TryGetVector3(arguments, 1);
|
||||
Vector3 size = TryGetVector3(arguments, 4);
|
||||
Vector2 uv = TryGetVector2(arguments, 7);
|
||||
var skinBox = new SkinBOX(type, pos, size, uv);
|
||||
if (arguments.Length >= 10)
|
||||
skinBox.HideWithArmor = arguments[9] == "1";
|
||||
if (arguments.Length >= 11)
|
||||
skinBox.Mirror = arguments[10] == "1";
|
||||
if (arguments.Length >= 12)
|
||||
float.TryParse(arguments[11], out skinBox.Scale);
|
||||
return skinBox;
|
||||
|
||||
bool hideWithArmor = arguments.IndexInRange(9) && arguments[9] == "1";
|
||||
bool mirror = arguments.IndexInRange(10) && arguments[10] == "1";
|
||||
float scale = default;
|
||||
if (arguments.IndexInRange(11))
|
||||
float.TryParse(arguments[11], out scale);
|
||||
return new SkinBOX(type, pos, size, uv, hideWithArmor, mirror, scale);
|
||||
}
|
||||
|
||||
public bool IsValidType() => IsValidType(Type);
|
||||
@@ -176,23 +176,5 @@ namespace PckStudio.Internal.Skin
|
||||
hashCode = hashCode * -1521134295 + Scale.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is SkinBOX box && Equals(box);
|
||||
}
|
||||
|
||||
public bool Equals(SkinBOX other)
|
||||
{
|
||||
return Type.Equals(other.Type) &&
|
||||
Pos.Equals(other.Pos) &&
|
||||
Size.Equals(other.Size) &&
|
||||
UV.Equals(other.UV);
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return new SkinBOX((string)Type.Clone(), Pos, Size, UV, HideWithArmor, Mirror, Scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,8 +166,8 @@ namespace PckStudio.Internal
|
||||
pos = TranslateToInternalPosition(outlineName, pos, size, new Vector3(1, 1, 0));
|
||||
|
||||
var box = new SkinBOX(outlineName, pos, size, uv, mirror: element.MirrorUv);
|
||||
if (box.IsBasePart() && ((outlineName == "HEAD" && element.Inflate == 0.5f) || (element.Inflate >= 0.25f && element.Inflate <= 0.5f)))
|
||||
box.Type = box.GetOverlayType();
|
||||
if (SkinBOX.IsBasePart(outlineName) && ((outlineName == "HEAD" && element.Inflate == 0.5f) || (element.Inflate >= 0.25f && element.Inflate <= 0.5f)))
|
||||
box = new SkinBOX(SkinBOXExtensions.GetOverlayType(outlineName), pos, size, uv, mirror: element.MirrorUv);
|
||||
return box;
|
||||
}
|
||||
|
||||
@@ -307,8 +307,8 @@ namespace PckStudio.Internal
|
||||
{
|
||||
Vector3 pos = TranslateToInternalPosition(boxType, cube.Origin, cube.Size, Vector3.UnitY);
|
||||
var skinBox = new SkinBOX(boxType, pos, cube.Size, cube.Uv, hideWithArmor: bone.Name == "helmet", mirror: cube.Mirror);
|
||||
if (skinBox.IsBasePart() && ((boxType == "HEAD" && cube.Inflate == 0.5f) || (cube.Inflate >= 0.25f && cube.Inflate <= 0.5f)))
|
||||
skinBox.Type = skinBox.GetOverlayType();
|
||||
if (SkinBOX.IsBasePart(boxType) && ((boxType == "HEAD" && cube.Inflate == 0.5f) || (cube.Inflate >= 0.25f && cube.Inflate <= 0.5f)))
|
||||
skinBox = new SkinBOX(SkinBOXExtensions.GetOverlayType(boxType), pos, cube.Size, cube.Uv, hideWithArmor: bone.Name == "helmet", mirror: cube.Mirror);
|
||||
boxes.Add(skinBox);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2329,7 +2329,7 @@ namespace PckStudio
|
||||
{
|
||||
if (treeViewMain.SelectedNode is TreeNode t && t.Tag is PckAsset asset)
|
||||
{
|
||||
using BoxEditor diag = new BoxEditor(SkinBOX.Empty, false);
|
||||
using BoxEditor diag = new BoxEditor(SkinBOX.DefaultHead, false);
|
||||
if (diag.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
asset.AddProperty("BOX", diag.Result);
|
||||
|
||||
Reference in New Issue
Block a user