@@ -18,6 +18,8 @@ these do not have a rotation field.
1818{$INCLUDE_ONCE WaspLib/osrs.simba}
1919
2020type
21+ ENPCData = enum(ID, NAME, LEVEL, CATEGORY, MINIMAPDOT, ACTIONS, SIZE, COORDINATES, COLORS);
22+
2123(*
2224## TRSEntity
2325Main type to handle {ref}`RSEntity`.
@@ -44,7 +46,7 @@ Array of {ref}`TRSEntity`.
4446## RSEntity.Create
4547```pascal
4648function TRSEntity.Create(walker: PRSWalker; size: TVector3; coordinates: TPointArray; uptext: TStringArray = []; dots: ERSMinimapDots = []): TRSEntity; static;
47- function TRSEntity.Create(json: TJSONItem ): TRSEntity; static; overload;
49+ function TRSEntity.Create(json: TJSONObject ): TRSEntity; static; overload;
4850```
4951Createors to create your {ref}`TRSEntity`.
5052
9597 Result.Filter += TRSDotFilter.Create([], TCircle.Create(pt.X, pt.Y, radius), True);
9698end;
9799
98- function TRSEntity.Create(json: TJSONItem ): TRSEntity; static; overload;
100+ function TRSEntity.Create(json: TJSONObject ): TRSEntity; static; overload;
99101var
100102 i: Integer;
101103 colors: TColorArray;
@@ -105,29 +107,34 @@ begin
105107 if json.Typ <> EJSONType.OBJ then
106108 raise GetDebugLn('TRSEntity', 'JSON Object expected, got ' + ToStr(json.Typ) + '.');
107109
108- if json.Item[1].AsString <> 'null' then
109- Result.UpText := [json.Item[1].AsString];
110- if json.Item[4].AsBool then //4 is minimapdot key in TRSMap jsons
110+ with json.Item[Ord(ENPCData.NAME)] do
111+ if AsString <> 'null' then
112+ Result.UpText := [AsString];
113+
114+ if json.Item[Ord(ENPCData.MINIMAPDOT)].AsBool then
111115 Result.MinimapDots := [ERSMinimapDot.NPC];
112116
113- //6 is size key in TRSMap jsons
114- Result.Size.X := Round(json.Item[6].Item[0].AsInt * 0.8, 2);
115- Result.Size.Y := Round(json.Item[6].Item[1].AsInt * 0.8, 2);
116- Result.Size.Z := Round(json.Item[6].Item[2].AsInt / 40, 2);
117+ with json.Item[Ord(ENPCData.SIZE)] do
118+ begin
119+ Result.Size.X := Item[0].AsInt * 0.8;
120+ Result.Size.Y := Item[1].AsInt * 0.8;
121+ Result.Size.Z := Item[2].AsInt / 40;
122+ end;
117123
118- if Result.Size.Z = 0.0 then
124+ if Abs( Result.Size.Z) < 0.05 then
119125 Result.Size.Z := 3.0;
120126
121- //7 is coordinates key in TRSMap jsons
122- for i := 0 to json.Item[7].Count-1 do
123- begin
124- coord := json.Item[7].Item[i];
125- Result.Coordinates += [coord.Item[0].AsInt, coord.Item[1].AsInt];
126- Result.Filter += TRSDotFilter.Create([], TCircle.Create(coord.Item[0].AsInt, coord.Item[1].AsInt, 40), True);
127- end;
128- //8 is colors key in TRSMap jsons
129- for i := 0 to json.Item[8].Count-1 do
130- colors += json.Item[8].Item[i].AsInt;
127+ with json.Item[Ord(ENPCData.COORDINATES)] do
128+ for i := 0 to Count-1 do
129+ begin
130+ coord := Item[i];
131+ Result.Coordinates += [coord.Item[0].AsInt, coord.Item[1].AsInt];
132+ Result.Filter += TRSDotFilter.Create([], TCircle.Create(coord.Item[0].AsInt, coord.Item[1].AsInt, 40), True);
133+ end;
134+
135+ with json.Item[Ord(ENPCData.COLORS)] do
136+ for i := 0 to Count-1 do
137+ colors += Item[i].AsInt;
131138
132139 if colors <> [] then
133140 begin
@@ -138,7 +145,29 @@ begin
138145 Result.Walker := @Map.Walker;
139146end;
140147
141- function TRSEntityArray.Create(json: TJSONItem): TRSEntityArray; static;
148+ (*
149+ ## RSEntityArray.Create
150+ ```pascal
151+ function TRSEntityArray.Create(json: TJSONArray): TRSEntityArray; static;
152+ ```
153+ Create function to build your {ref}`TRSObjectArray`.
154+
155+ This only accepts a `json` array and it expects a specific json structure which is
156+ the one that {ref}`Map JSONs` provide.
157+
158+ Example:
159+ ```pascal
160+ {$I WaspLib/osrs.simba}
161+
162+ var
163+ objs: TRSObjectArray;
164+ begin
165+ Map.Setup([ERSChunk.VARROCK]);
166+ objs := TRSObject.Create(ObjectsJSON.GetByName('bank'));
167+ end;
168+ ```
169+ *)
170+ function TRSEntityArray.Create(json: TJSONArray): TRSEntityArray; static;
142171var
143172 i: Integer;
144173begin
0 commit comments