-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFieldOverrides.cs
75 lines (63 loc) · 2.35 KB
/
FieldOverrides.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ModEditor
{
public class FieldOverrides
{
protected Dictionary<string, List<Attribute>> fieldAttributes = new Dictionary<string, List<Attribute>>();
protected System.Type targetType;
public FieldOverrides(System.Type type)
{
targetType = type;
}
public bool HasOverrides()
{
return fieldAttributes.Count > 0;
}
// Add custom field attribute to modify ItemExplorer sheet generation
public void AddAttribute(string fieldName, Attribute attrib)
{
if (!fieldAttributes.ContainsKey(fieldName))
fieldAttributes.Add(fieldName, new List<Attribute>());
fieldAttributes[fieldName].Add(attrib);
}
// Mark field as "string token"
public void OverrideFieldLocString(string fieldName)
{
AddAttribute(fieldName, new LocStringToken());
}
// Mark field as "object reference"
public void OverrideFieldObjectReference(string fieldName, string group, string filter, bool required)
{
AddAttribute(fieldName, new ObjectReference(group, filter, !required));
}
public void OverrideFieldObjectReference(string fieldName, string group, bool required)
{
AddAttribute(fieldName, new ObjectReference(group, "{0}", !required));
}
// Ignore field
public void IgnoreField(string fieldName)
{
AddAttribute(fieldName, new IgnoreByEditor());
}
// Obtain all the attributes within spedified field
public List<Attribute> GetFieldAttribute(System.Reflection.FieldInfo fieldInfo)
{
List<Attribute> result = new List<Attribute>();
// Get attributes from local override list
if (fieldAttributes.ContainsKey(fieldInfo.Name))
{
var list = fieldAttributes[fieldInfo.Name];
result.AddRange(list);
}
// Get attributes from class definition
foreach (Attribute attribute in fieldInfo.GetCustomAttributes(true))
{
result.Add(attribute);
}
return result;
}
}
}