1- {$I WaspLib/osrs.simba}
2-
31const
42 ENDPOINT = 'https://oldschool.runescape.wiki/api.php?';
5- SILENT: Boolean = False ;
3+ SILENT: Boolean = True ;
64 TEST_ITEM: String = '';
75
6+ SLOT_NAMES: TStringArray = [
7+ 'head', 'cape', 'neck', 'ammo', 'weapon', 'body', 'shield', 'legs', 'hands',
8+ 'feet', 'ring', 'spec_weapons', '2h'
9+ ];
10+
811function GetEndPoint(name: String): String;
912begin
1013 Result := ENDPOINT + 'action=parse&page=' +
@@ -32,11 +35,9 @@ function TSlotArray.GetStr(): String;
3235var
3336 i: Integer;
3437begin
35- for i := 0 to 10 do
36- Result += ' "' + ToStr(ERSEquipment(i)).After('ERSEquipment.').ToLower() + '": ' + Self[i].Unique().Sorted().GetStr() + ',' + LINE_SEP;
37-
38- Result += ' "spec_weapons": ' + Self[11].Unique().Sorted().GetStr() + ',' + LINE_SEP;
39- Result += ' "2h": ' + Self[12].Unique().Sorted().GetStr();
38+ for i := 0 to 11 do
39+ Result += ' "' + SLOT_NAMES[i] + '": ' + Self[i].Unique().Sorted().GetStr() + ',' + LINE_SEP;
40+ Result += ' "' + SLOT_NAMES[12] + '": ' + Self[12].Unique().Sorted().GetStr();
4041end;
4142
4243procedure FillSlot(item, txt: String);
4849
4950 if txt.Contains('slot = weapon') then
5051 begin
51- Slots[ERSEquipment.WEAPON ] += item;
52+ Slots[4 ] += item;
5253 if txt.Contains('Category:Weapons with Special attacks') then
5354 Slots[11] += item;
5455 Exit;
@@ -64,60 +65,60 @@ begin
6465
6566 if txt.Contains('slot = head') then
6667 begin
67- Slots[ERSEquipment.HEAD ] += item;
68+ Slots[0 ] += item;
6869 Exit;
6970 end;
7071
7172 if txt.Contains('slot = cape') then
7273 begin
73- Slots[ERSEquipment.CAPE ] += item;
74+ Slots[1 ] += item;
7475 Exit;
7576 end;
7677
7778 if txt.Contains('slot = neck') then
7879 begin
79- Slots[ERSEquipment.NECK ] += item;
80+ Slots[2 ] += item;
8081 Exit;
8182 end;
8283
8384 if txt.Contains('slot = ammo') then
8485 begin
85- Slots[ERSEquipment.AMMO ] += item;
86+ Slots[3 ] += item;
8687 Exit;
8788 end;
8889
8990 if txt.Contains('slot = body') then
9091 begin
91- Slots[ERSEquipment.BODY ] += item;
92+ Slots[5 ] += item;
9293 Exit;
9394 end;
9495
9596 if txt.Contains('slot = shield') then
9697 begin
97- Slots[ERSEquipment.SHIELD ] += item;
98+ Slots[6 ] += item;
9899 Exit;
99100 end;
100101
101102 if txt.Contains('slot = legs') then
102103 begin
103- Slots[ERSEquipment.LEGS ] += item;
104+ Slots[7 ] += item;
104105 Exit;
105106 end;
106107
107108 if txt.Contains('slot = hands') then
108109 begin
109- Slots[ERSEquipment.HANDS ] += item;
110+ Slots[8 ] += item;
110111 Exit;
111112 end;
112113
113114 if txt.Contains('slot = feet') then
114115 begin
115- Slots[ERSEquipment.FEET ] += item;
116+ Slots[9 ] += item;
116117 Exit;
117118 end;
118119
119120 if txt.Contains('slot = ring') then
120- Slots[ERSEquipment.RING ] += item;
121+ Slots[10 ] += item;
121122end;
122123
123124procedure TStringArray.Filter();
@@ -148,17 +149,16 @@ begin
148149 end;
149150end;
150151
151-
152152var
153153 items: TStringArray;
154154 i: Integer;
155155 url: String;
156- json, tmp: TJSONItem ;
156+ json, tmp: TJSONParser ;
157157 text: String;
158158begin
159159 ClearSimbaOutput();
160160
161- items := FileReadLines(ItemFinder.Database.DataDir + ' item').Unique();
161+ items := FileReadLines({$MACRO DIR} + '..' + PATH_SEP + 'finders' + PATH_SEP + 'items' + PATH_SEP + 'data' + PATH_SEP + ' item.txt ').Unique();
162162 items.Filter();
163163
164164 for i := 0 to High(items) do
@@ -176,13 +176,14 @@ begin
176176 WriteLn url;
177177
178178 try
179- json := HTTPClient.GetJson(url);
179+ json := new TJSONParser();
180+ json.Parse(HTTPClient.Get(url));
180181 except
181182 WriteLn('Failed to fetch: ', items[i]);
182183 end;
183184
184185 if TEST_ITEM <> '' then
185- WriteLn json.ToJSON ();
186+ WriteLn json.Format ();
186187
187188 if json = nil then
188189 begin
@@ -194,28 +195,25 @@ begin
194195 tmp := json.Item['parse'];
195196 except
196197 WriteLn('Failed to find parse: ', items[i]);
197- json.Free();
198198 Continue;
199199 end;
200200
201201 try
202- text := tmp.Item['wikitext'].ToJSON( );
202+ text := tmp.Item['wikitext'].Format([EJSONFormatOption.SINGLE_LINE_ARR] );
203203 except
204204 if not SILENT then
205205 WriteLn('Failed to find wikitext: ', items[i]);
206- json.Free();
207206 Continue;
208207 end;
209208
210209 if TEST_ITEM <> '' then
211210 FillSlot(TEST_ITEM, text)
212211 else
213212 FillSlot(items[i], text);
214- json.Free();
215213 end;
216214
217215 text := '{' + LINE_SEP + Slots.GetStr() + LINE_SEP + '}';
218216 WriteLn text;
219217 if TEST_ITEM = '' then
220- FileWrite(GearData.PATH , text);
218+ FileWrite({$MACRO DIR} + '..' + PATH_SEP + 'jsons' + PATH_SEP + 'gear.json' , text);
221219end;
0 commit comments