Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
jsonobject.c
Go to the documentation of this file.
2{
3 ref map<string, string> m_Strings;
4 ref map<string, int> m_Ints;
5 ref map<string, float> m_Floats;
6 ref map<string, bool> m_Bools;
7 ref map<string, ref Vector2> m_Vectors2;
8
9 void JsonObject()
10 {
11 m_Strings = new map<string, string>;
12 m_Ints = new map<string, int>;
14 m_Bools = new map<string, bool>;
15 m_Vectors2 = new map<string, ref Vector2>;
16 }
17
18 void ~JsonObject()
19 {
20 Clear();
21 }
22
23 void Clear()
24 {
25 m_Strings.Clear();
26 m_Ints.Clear();
27 m_Floats.Clear();
28 m_Bools.Clear();
29 m_Vectors2.Clear();
30 }
31
32 void AddString(string name, string value)
33 {
34 array<string> strgs = new array<string>;
35 value.Split("\"", strgs);
36
37 if ( strgs.Count() > 1 )
38 {
39 value = "";
40 int str_count = strgs.Count();
41
42 for ( int i = 0; i < str_count; ++i )
43 {
44 string s = strgs[i];
45
46 int length = s.Length();
47
48 if ( s[length - 1] != "\\" )
49 {
50 value += s;
51
52 if (i < str_count - 1 )
53 {
54 value += "\\";
55 value += "\"";
56 }
57 }
58 }
59 }
60
61 m_Strings.Insert(name, value);
62 }
63
64 void AddInt(string name, int value)
65 {
66 m_Ints.Insert(name, value);
67 }
68
69 void AddFloat(string name, float value)
70 {
71 m_Floats.Insert(name, value);
72 }
73
74 void AddBool(string name, bool value)
75 {
76 m_Bools.Insert(name, value);
77 }
78
79 void AddVector2(string name, float x, float y)
80 {
81 Vector2 v = new Vector2(x, y);
82 m_Vectors2.Insert(name, v);
83 }
84
85 string GetJson()
86 {
87 string name;
88 int i;
89
90 string jsn = "";
91 jsn += "{";
92
93 // Parse Strings
94 for ( i = 0; i < m_Strings.Count(); ++i )
95 {
96 if ( jsn.Length() > 1 )
97 {
98 jsn += ",";
99 }
100
101 name = m_Strings.GetKey(i);
102 string value_str = m_Strings.GetElement(i);
103
104 jsn += "\""+name+"\":\""+value_str+"\"";
105 }
106
107 // Parse Ints
108 for ( i = 0; i < m_Ints.Count(); ++i )
109 {
110 if ( jsn.Length() > 1 )
111 {
112 jsn += ",";
113 }
114
115 name = m_Ints.GetKey(i);
116 int value_int = m_Ints.GetElement(i);
117
118 jsn += "\""+name+"\":"+value_int;
119 }
120
121 // Parse Floats
122 for ( i = 0; i < m_Floats.Count(); ++i )
123 {
124 if ( jsn.Length() > 1 )
125 {
126 jsn += ",";
127 }
128
129 name = m_Floats.GetKey(i);
130 float value_flt = m_Floats.GetElement(i);
131
132 jsn += "\""+name+"\":"+value_flt;
133 }
134
135 // Parse Bools
136 for ( i = 0; i < m_Bools.Count(); ++i )
137 {
138 if ( jsn.Length() > 1 )
139 {
140 jsn += ",";
141 }
142
143 name = m_Bools.GetKey(i);
144
145 if ( m_Bools.GetElement(i) )
146 {
147 jsn += "\""+name+"\":true";
148 }
149 else
150 {
151 jsn += "\""+name+"\":false";
152 }
153 }
154
155 // Parse Vectors2
156 for ( i = 0; i < m_Vectors2.Count(); ++i )
157 {
158 if ( jsn.Length() > 1 )
159 {
160 jsn += ",";
161 }
162
163 name = m_Vectors2.GetKey(i);
164 Vector2 value_vct = m_Vectors2.GetElement(i);
165
166 jsn += "\""+name+"\":{\"x\":"+value_vct.x+",\"y\":"+value_vct.y+"}";
167 }
168
169 jsn += "}";
170
171 return jsn;
172 }
173};
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Icon x
Icon y
ref map< string, float > m_Floats