Switch item definitions to a JSON-driven runtime registry

Replaces the build-time item.json/tools.item.py code generator with a
single item_t ITEM registry populated at runtime by parsing
assets/items.jsonc, so items/types can grow without a rebuild. Adds
itemGetDefById/itemGetTypeById/itemGetIdByName/itemTypeGetOrCreate,
updates inventory/backpack to size off the new *_DEF_COUNT_MAX caps
and look up types dynamically, and reorders engine init so rpgInit
(which loads items) runs before uiInit (which needs the item type
count to size the backpack's tabs).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
2026-09-13 11:36:50 -05:00
co-authored by Claude Sonnet 5
parent 804f8aa1fa
commit 109ddc9e1e
15 changed files with 216 additions and 174 deletions
+30 -2
View File
@@ -7,9 +7,37 @@
#include "dusktest.h"
#include "rpg/item/inventory.h"
#include "util/memory.h"
static itemid_t ITEM_ID_POTION;
static itemid_t ITEM_ID_POTATO;
static itemid_t ITEM_ID_APPLE;
// Registers three test items (POTION as MEDICINE, POTATO/APPLE as FOOD)
// directly into the global ITEM registry -- these tests exercise the
// inventory/backpack layer only, not the JSON-driven itemInit() pipeline.
static int_t itemFixtureSetup(void **state) {
memoryZero(&ITEM, sizeof(ITEM));
ITEM.typeCount = ITEM_TYPE_NULL + 1;
ITEM.defCount = ITEM_ID_NULL + 1;
const itemtype_t medicine = itemTypeGetOrCreate("MEDICINE");
const itemtype_t food = itemTypeGetOrCreate("FOOD");
ITEM_ID_POTION = ITEM.defCount++;
ITEM.defs[ITEM_ID_POTION].type = medicine;
ITEM_ID_POTATO = ITEM.defCount++;
ITEM.defs[ITEM_ID_POTATO].type = food;
ITEM_ID_APPLE = ITEM.defCount++;
ITEM.defs[ITEM_ID_APPLE].type = food;
return 0;
}
static void test_inventoryInit(void **state) {
inventorystack_t storage[5];
inventory_t inventory;
@@ -401,5 +429,5 @@ int main(int argc, char** argv) {
cmocka_unit_test(test_inventorySort),
};
return cmocka_run_group_tests(tests, NULL, NULL);
return cmocka_run_group_tests(tests, itemFixtureSetup, NULL);
}