Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
BaseCard.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using Newtonsoft.Json;
3
4public class BaseCard : EClass
5{
6 [JsonProperty(PropertyName = "X")]
7 public Dictionary<int, object> mapObj = new Dictionary<int, object>();
8
9 [JsonProperty(PropertyName = "Y")]
10 public Dictionary<int, int> mapInt = new Dictionary<int, int>();
11
12 [JsonProperty(PropertyName = "Z")]
13 public Dictionary<int, string> mapStr = new Dictionary<int, string>();
14
15 public bool GetBool(int id)
16 {
17 return GetInt(id) != 0;
18 }
19
20 public void SetBool(int id, bool enable)
21 {
22 SetInt(id, enable ? 1 : 0);
23 }
24
25 public int GetInt(int id, int? defaultInt = null)
26 {
27 if (mapInt.TryGetValue(id, out var value))
28 {
29 return value;
30 }
31 return defaultInt.GetValueOrDefault();
32 }
33
34 public void AddInt(int id, int value)
35 {
36 SetInt(id, GetInt(id) + value);
37 }
38
39 public void SetInt(int id, int value = 0)
40 {
41 if (value == 0)
42 {
43 if (mapInt.ContainsKey(id))
44 {
45 mapInt.Remove(id);
46 }
47 }
48 else
49 {
50 mapInt[id] = value;
51 }
52 }
53
54 public string GetStr(int id, string defaultStr = null)
55 {
56 if (mapStr.TryGetValue(id, out var value))
57 {
58 return value;
59 }
60 return defaultStr;
61 }
62
63 public void SetStr(int id, string value = null)
64 {
65 if (value.IsEmpty())
66 {
67 if (mapStr.ContainsKey(id))
68 {
69 mapStr.Remove(id);
70 }
71 }
72 else
73 {
74 mapStr[id] = value;
75 }
76 }
77
78 public T GetObj<T>(int id)
79 {
80 if (mapObj == null)
81 {
82 return default(T);
83 }
84 if (mapObj.TryGetValue(id, out var value) && value is T)
85 {
86 return (T)value;
87 }
88 return default(T);
89 }
90
91 public void SetObj(int id, object o)
92 {
93 if (mapObj == null)
94 {
95 mapObj = new Dictionary<int, object>();
96 }
97 if (o == null)
98 {
99 if (mapObj.ContainsKey(id))
100 {
101 mapObj.Remove(id);
102 }
103 }
104 else
105 {
106 mapObj[id] = o;
107 }
108 }
109
110 public T SetObj<T>(int id, object o)
111 {
112 if (mapObj == null)
113 {
114 mapObj = new Dictionary<int, object>();
115 }
116 if (o == null)
117 {
118 if (mapStr.ContainsKey(id))
119 {
120 mapObj.Remove(id);
121 }
122 return default(T);
123 }
124 mapObj[id] = o;
125 return (T)o;
126 }
127}
Dictionary< int, int > mapInt
Definition: BaseCard.cs:10
void SetStr(int id, string value=null)
Definition: BaseCard.cs:63
void SetObj(int id, object o)
Definition: BaseCard.cs:91
string GetStr(int id, string defaultStr=null)
Definition: BaseCard.cs:54
void AddInt(int id, int value)
Definition: BaseCard.cs:34
Dictionary< int, object > mapObj
Definition: BaseCard.cs:7
T GetObj< T >(int id)
Definition: BaseCard.cs:78
T SetObj< T >(int id, object o)
Definition: BaseCard.cs:110
void SetBool(int id, bool enable)
Definition: BaseCard.cs:20
int GetInt(int id, int? defaultInt=null)
Definition: BaseCard.cs:25
void SetInt(int id, int value=0)
Definition: BaseCard.cs:39
Dictionary< int, string > mapStr
Definition: BaseCard.cs:13
bool GetBool(int id)
Definition: BaseCard.cs:15
Definition: EClass.cs:5