fix(cleanup): Consolidate the duplicate code in Properties, PropsGump, and PropsConfig (#540)

This commit is contained in:
Kamron Batman 2021-04-14 22:58:56 -07:00 • committed by GitHub
parent 98ce65083a
commit dd2933a9ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 335 additions and 761 deletions

View file

@ -6,39 +6,15 @@ using System.Text;
using Server.Items;
using CPA = Server.CommandPropertyAttribute;
using static Server.Attributes;
using static Server.Types;
namespace Server.Commands
{
public static class Add
{
private static readonly Type m_EntityType = typeof(IEntity);
private static readonly Type m_ConstructibleType = typeof(ConstructibleAttribute);
private static readonly Type m_EnumType = typeof(Enum);
private static readonly Type m_TypeType = typeof(Type);
private static readonly Type m_ParsableType = typeof(ParsableAttribute);
private static readonly Type[] m_ParseTypes = { typeof(string) };
private static readonly object[] m_ParseArgs = new object[1];
private static readonly Type[] m_SignedNumerics =
{
typeof(long),
typeof(int),
typeof(short),
typeof(sbyte)
};
private static readonly Type[] m_UnsignedNumerics =
{
typeof(ulong),
typeof(uint),
typeof(ushort),
typeof(byte)
};
public static void Initialize()
{
CommandSystem.Register("Tile", AccessLevel.GameMaster, Tile_OnCommand);
@ -193,7 +169,7 @@ namespace Server.Commands
}
else
{
var attr = Properties.GetCPA(thisProp);
var attr = GetCPA(thisProp);
if (attr == null)
{
@ -759,56 +735,21 @@ namespace Server.Commands
InternalAvg_OnCommand(e, true);
}
public static bool IsEntity(Type t) => m_EntityType.IsAssignableFrom(t);
public static bool IsEnum(Type type) => type.IsSubclassOf(OfEnum);
public static bool IsConstructible(ConstructorInfo ctor, AccessLevel accessLevel)
{
var attrs = ctor.GetCustomAttributes(m_ConstructibleType, false);
public static bool IsType(Type type) => type == OfType || type.IsSubclassOf(OfType);
return attrs.Length != 0 && accessLevel >= ((ConstructibleAttribute)attrs[0]).AccessLevel;
}
public static bool IsEnum(Type type) => type.IsSubclassOf(m_EnumType);
public static bool IsType(Type type) => type == m_TypeType || type.IsSubclassOf(m_TypeType);
public static bool IsParsable(Type type) => type.IsDefined(m_ParsableType, false);
public static bool IsParsable(Type type) => type.IsDefined(OfParsable, false);
public static object ParseParsable(Type type, string value)
{
var method = type.GetMethod("Parse", m_ParseTypes);
var method = type.GetMethod("Parse", ParseTypes);
m_ParseArgs[0] = value;
return method?.Invoke(null, m_ParseArgs);
}
public static bool IsSignedNumeric(Type type)
{
for (var i = 0; i < m_SignedNumerics.Length; ++i)
{
if (type == m_SignedNumerics[i])
{
return true;
}
}
return false;
}
public static bool IsUnsignedNumeric(Type type)
{
for (var i = 0; i < m_UnsignedNumerics.Length; ++i)
{
if (type == m_UnsignedNumerics[i])
{
return true;
}
}
return false;
}
private enum TileZType
{
Start,

View file

@ -2,55 +2,19 @@ using System;
using Server.Commands;
using Server.Network;
using static Server.Gumps.PropsConfig;
namespace Server.Gumps
{
public class CategorizedAddGump : Gump
{
public static bool OldStyle = PropsConfig.OldStyle;
private static readonly int EntryHeight = PropsConfig.EntryHeight + 4;
public static readonly int EntryHeight = 24; // PropsConfig.EntryHeight;
private static readonly int SetOffsetY = PropsConfig.SetOffsetY + (EntryHeight - 20) / 2 / 2;
public static readonly int OffsetSize = PropsConfig.OffsetSize;
public static readonly int BorderSize = PropsConfig.BorderSize;
private static readonly int PrevOffsetY = PropsConfig.PrevOffsetY + (EntryHeight - 20) / 2 / 2;
public static readonly int GumpOffsetX = PropsConfig.GumpOffsetX;
public static readonly int GumpOffsetY = PropsConfig.GumpOffsetY;
public static readonly int TextHue = PropsConfig.TextHue;
public static readonly int TextOffsetX = PropsConfig.TextOffsetX;
public static readonly int OffsetGumpID = PropsConfig.OffsetGumpID;
public static readonly int HeaderGumpID = PropsConfig.HeaderGumpID;
public static readonly int EntryGumpID = PropsConfig.EntryGumpID;
public static readonly int BackGumpID = PropsConfig.BackGumpID;
public static readonly int SetGumpID = PropsConfig.SetGumpID;
public static readonly int SetWidth = PropsConfig.SetWidth;
public static readonly int SetOffsetX = PropsConfig.SetOffsetX,
SetOffsetY = PropsConfig.SetOffsetY + (EntryHeight - 20) / 2 / 2;
public static readonly int SetButtonID1 = PropsConfig.SetButtonID1;
public static readonly int SetButtonID2 = PropsConfig.SetButtonID2;
public static readonly int PrevWidth = PropsConfig.PrevWidth;
public static readonly int PrevOffsetX = PropsConfig.PrevOffsetX,
PrevOffsetY = PropsConfig.PrevOffsetY + (EntryHeight - 20) / 2 / 2;
public static readonly int PrevButtonID1 = PropsConfig.PrevButtonID1;
public static readonly int PrevButtonID2 = PropsConfig.PrevButtonID2;
public static readonly int NextWidth = PropsConfig.NextWidth;
public static readonly int NextOffsetX = PropsConfig.NextOffsetX,
NextOffsetY = PropsConfig.NextOffsetY + (EntryHeight - 20) / 2 / 2;
public static readonly int NextButtonID1 = PropsConfig.NextButtonID1;
public static readonly int NextButtonID2 = PropsConfig.NextButtonID2;
private static readonly bool PrevLabel = false;
private static readonly bool NextLabel = false;
private static readonly int NextOffsetY = PropsConfig.NextOffsetY + (EntryHeight - 20) / 2 / 2;
private static readonly int PrevLabelOffsetX = PrevWidth + 1;
private static readonly int PrevLabelOffsetY = 0;
@ -62,10 +26,9 @@ namespace Server.Gumps
private static readonly int EntryCount = 15;
private static readonly int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize;
private static readonly int TotalHeight = OffsetSize + (EntryHeight + OffsetSize) * (EntryCount + 1);
private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize;
private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize;
private readonly CAGCategory m_Category;
private readonly Mobile m_Owner;