Item Loader¶
Builds the item database WaspLib looks items up in: every named item, the ids it goes by, and the hash of each icon it can be drawn with.
TItemLoader.DecodeName¶
function TItemLoader.DecodeName(const name: String): String; static;
Turns a name as the cache stores it, one byte per character, into lowercase UTF-8.
TItemLoader._CollectGear¶
procedure TItemLoader._CollectGear(constref itemDef: TItemDefinition; name: String);
Files name under the TItemLoader.Gear slot of each of the up to 3 wear positions itemDef
has, so a hat that also covers the hair is filed once under head while a cape that occupies the
ammo position too is filed under both. Anything that takes up the weapon and the shield position
at once is two handed and is filed only under 2h. Items that can’t be equipped are ignored.
TItemLoader.Load calls this for every named item as it decodes it, so the gear lists cost nothing beyond the pass that names the items. Duplicates are left in and weeded out by TItemLoader.WriteGearJSON.
TItemLoader.Load¶
procedure TItemLoader.Load();
Caches the config index and works out the database name of every item id, filling
TItemLoader.Names, and files every equippable item into TItemLoader.Gear as it goes. Does
nothing once loaded.
TItemLoader.Names is indexed by item id and holds '' for ids that aren’t items. Noted items
are named noted followed by the name of the item they are a note of, and the ids an item
switches to as its stack grows share that item’s name unless they have one of their own.
TItemLoader.WriteGearJSON¶
function TItemLoader.WriteGearJSON(path: String): Integer;
Writes TItemLoader.Gear into path as gear.json: the name of every equippable item, sorted
and without repeats, grouped under the head, cape, neck, ammo, weapon, body,
shield, legs, hands, feet, ring and 2h keys, in that order. Loads the items first
with TItemLoader.Load if they aren’t yet, and creates path if it doesn’t exist.
Returns how many names were written.
Example:
CacheReader := TCacheReader.Create();
ItemLoader.WriteGearJSON('C:/items-db/');
TItemLoader.WriteDatabase¶
function TItemLoader.WriteDatabase(path: String): Integer;
Renders every item in TItemLoader.Names and writes the database into path as four column
files, item.txt, id.txt, hash.txt and border.txt, where line N of each file belongs to
row N. gear.json is written next to them with TItemLoader.WriteGearJSON.
Loads the items first with TItemLoader.Load if they aren’t yet, and creates path if it
doesn’t exist. Returns how many rows were written.
Every animation frame of an item is hashed with TItemSprite.GetCRC and TItemSprite.GetBorderCRC, and each distinct icon an item has gets its own row. An id whose icon looks exactly like a lower id of the same name adds nothing and is left out. Items that can’t be rendered are left out too.
Example:
CacheReader := TCacheReader.Create();
ItemLoader.WriteDatabase('C:/items-db/');