-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItemBase.cs
81 lines (63 loc) · 2.01 KB
/
ItemBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using PoE.SortStash.Items;
using System;
namespace PoE.SortStash
{
public abstract class ItemBase:IComparable<ItemBase>
{
private static readonly ItemTryParseDelegate[] parsers = new ItemTryParseDelegate[]
{
Gem.TryParse
};
public static ItemBase Parse(string value)
{
if (!string.IsNullOrEmpty(value))
{
foreach (var parser in parsers)
{
if (parser(value, out ItemBase item))
return item;
}
}
return null;
}
protected const string PARTSPLITTER = "--------\r\n";
protected const string CORRUPTED = "Corrupted";
protected readonly static char[] NEWLINE = new char[] { '\r', '\n' };
public readonly ItemType Type;
public readonly Rarity Rarity;
public readonly string Name;
public readonly int Width;
public readonly int Height;
protected ItemBase(ItemType type, Rarity rarity, string name,int width,int height)
{
Name = name;
Rarity = rarity;
Type = type;
Width = width;
Height = height;
}
protected abstract int Compare(ItemBase other);
public int CompareTo(ItemBase other)
{
int result = Type.CompareTo(other.Type);
if (result == 0)
result = Name.CompareTo(other.Name);
if (result == 0)
result = Rarity.CompareTo(other.Rarity);
if (result == 0)
result = Compare(other);
return result;
}
public static int Comparison(ItemBase x,ItemBase y)
{
if (x == null && y == null)
return 0;
else if (x == null)
return 1;
else if (y == null)
return -1;
else
return x.CompareTo(y);
}
}
}