Cleanup modules

This commit is contained in:
2026-05-05 19:29:29 -05:00
parent bb29c0edef
commit 368d370f49
2 changed files with 5 additions and 21 deletions
+5 -17
View File
@@ -10,7 +10,6 @@
#include "script/scriptproto.h"
#include "item/inventory.h"
#include "item/backpack.h"
#include "item/item.h"
typedef struct {
inventory_t *inventory;
@@ -27,7 +26,6 @@ static inline inventory_t * moduleInventoryGet(
return h ? h->inventory : NULL;
}
// inventory.add(itemId, quantity)
moduleBaseFunction(moduleInventoryAdd) {
if(argc < 2) return moduleBaseThrow("Expected (itemId, quantity)");
moduleBaseRequireNumber(0);
@@ -42,7 +40,6 @@ moduleBaseFunction(moduleInventoryAdd) {
return jerry_undefined();
}
// inventory.remove(itemId)
moduleBaseFunction(moduleInventoryRemove) {
if(argc < 1) return moduleBaseThrow("Expected itemId");
moduleBaseRequireNumber(0);
@@ -52,7 +49,6 @@ moduleBaseFunction(moduleInventoryRemove) {
return jerry_undefined();
}
// inventory.set(itemId, quantity)
moduleBaseFunction(moduleInventorySet) {
if(argc < 2) return moduleBaseThrow("Expected (itemId, quantity)");
moduleBaseRequireNumber(0);
@@ -67,7 +63,6 @@ moduleBaseFunction(moduleInventorySet) {
return jerry_undefined();
}
// inventory.count(itemId) → number
moduleBaseFunction(moduleInventoryCount) {
if(argc < 1) return moduleBaseThrow("Expected itemId");
moduleBaseRequireNumber(0);
@@ -78,7 +73,6 @@ moduleBaseFunction(moduleInventoryCount) {
);
}
// inventory.has(itemId) → boolean
moduleBaseFunction(moduleInventoryHas) {
if(argc < 1) return moduleBaseThrow("Expected itemId");
moduleBaseRequireNumber(0);
@@ -89,7 +83,6 @@ moduleBaseFunction(moduleInventoryHas) {
);
}
// inventory.isItemFull(itemId) → boolean
moduleBaseFunction(moduleInventoryIsItemFull) {
if(argc < 1) return moduleBaseThrow("Expected itemId");
moduleBaseRequireNumber(0);
@@ -100,19 +93,19 @@ moduleBaseFunction(moduleInventoryIsItemFull) {
);
}
// inventory.sort(sortBy, reverse?)
moduleBaseFunction(moduleInventorySort) {
if(argc < 1) return moduleBaseThrow("Expected sortBy");
moduleBaseRequireNumber(0);
inventory_t *inv = moduleInventoryGet(callInfo);
if(!inv) return jerry_undefined();
inventorysort_t sortBy = (inventorysort_t)jerry_value_as_number(args[0]);
bool_t reverse = (argc >= 2 && jerry_value_is_true(args[1]));
inventorySort(inv, sortBy, reverse);
inventorySort(
inv,
(inventorysort_t)jerry_value_as_number(args[0]),
(argc >= 2 && jerry_value_is_true(args[1]))
);
return jerry_undefined();
}
// inventory.full → boolean (read-only property)
moduleBaseFunction(moduleInventoryGetFull) {
inventory_t *inv = moduleInventoryGet(callInfo);
if(!inv) return jerry_undefined();
@@ -120,14 +113,10 @@ moduleBaseFunction(moduleInventoryGetFull) {
}
static void moduleItem(void) {
// ITEM_ID_* and ITEM_TYPE_* numeric constants
moduleBaseEval(ITEM_SCRIPT);
// Sort constants
moduleBaseSetInt("INVENTORY_SORT_BY_ID", INVENTORY_SORT_BY_ID);
moduleBaseSetInt("INVENTORY_SORT_BY_TYPE", INVENTORY_SORT_BY_TYPE);
// Inventory prototype — not a public constructor, only used via singletons
scriptProtoInit(
&MODULE_INVENTORY_PROTO, NULL,
sizeof(inventoryscript_t), NULL
@@ -144,7 +133,6 @@ static void moduleItem(void) {
scriptProtoDefineFunc(&MODULE_INVENTORY_PROTO, "isItemFull", moduleInventoryIsItemFull);
scriptProtoDefineFunc(&MODULE_INVENTORY_PROTO, "sort", moduleInventorySort);
// Backpack — global singleton Inventory wrapping the engine BACKPACK
inventoryscript_t h = { .inventory = &BACKPACK };
jerry_value_t backpackObj = scriptProtoCreateValue(&MODULE_INVENTORY_PROTO, &h);
moduleBaseSetValue("Backpack", backpackObj);
@@ -12,7 +12,6 @@
static scriptproto_t MODULE_STORY_FLAG_PROTO;
// StoryFlag.get(flagId) → number
moduleBaseFunction(moduleStoryFlagGet) {
if(argc < 1) return moduleBaseThrow("Expected flagId");
moduleBaseRequireNumber(0);
@@ -23,7 +22,6 @@ moduleBaseFunction(moduleStoryFlagGet) {
return jerry_number((double)storyFlagGet(flag));
}
// StoryFlag.set(flagId, value)
moduleBaseFunction(moduleStoryFlagSet) {
if(argc < 2) return moduleBaseThrow("Expected (flagId, value)");
moduleBaseRequireNumber(0);
@@ -37,10 +35,8 @@ moduleBaseFunction(moduleStoryFlagSet) {
}
static void moduleStory(void) {
// STORY_FLAG_* numeric constants
moduleBaseEval(STORY_FLAG_SCRIPT);
// StoryFlag — global static namespace, no instances
scriptProtoInit(
&MODULE_STORY_FLAG_PROTO, "StoryFlag",
sizeof(uint8_t), NULL