diff --git a/code/foundation/src/debug/debug_ui.c b/code/foundation/src/debug/debug_ui.c index 1d78554..c08d5d7 100644 --- a/code/foundation/src/debug/debug_ui.c +++ b/code/foundation/src/debug/debug_ui.c @@ -41,6 +41,7 @@ static uint8_t is_debug_open = 1; static uint8_t is_handle_ctrl_held; static float debug_xpos = DBG_START_XPOS; static float debug_ypos = DBG_START_YPOS; +static zpl_u16 sel_item_id = 0; typedef enum { L_NONE = 0, @@ -133,17 +134,24 @@ static debug_item items[] = { .list = { .is_collapsed = true, .items = (debug_item[]) { + { + .kind = DITEM_LIST, + .name = "spawn item", + .list = { + .items = (debug_item[]) { + { .kind = DITEM_TEXT, .name = "selected", .proc = DrawSelectedSpawnItem }, + { .kind = DITEM_BUTTON, .name = "Previous", .on_click = ActSpawnItemPrev }, + { .kind = DITEM_BUTTON, .name = "Next", .on_click = ActSpawnItemNext }, + { .kind = DITEM_BUTTON, .name = "Spawn <", .on_click = ActSpawnSelItem }, + { .kind = DITEM_END }, + }, + .is_collapsed = false + } + }, { .kind = DITEM_BUTTON, .name = "spawn car", .on_click = ActSpawnCar }, { .kind = DITEM_BUTTON, .name = "place ice rink", .on_click = ActPlaceIceRink }, { .kind = DITEM_BUTTON, .name = "erase world changes", .on_click = ActEraseWorldChanges }, { .kind = DITEM_BUTTON, .name = "spawn circling driver", .on_click = ActSpawnCirclingDriver }, - { .kind = DITEM_BUTTON, .name = "spawn coal lump", .on_click = ActSpawnCoal }, - { .kind = DITEM_BUTTON, .name = "spawn chest", .on_click = ActSpawnChest }, - { .kind = DITEM_BUTTON, .name = "spawn belt", .on_click = ActSpawnBelt }, - { .kind = DITEM_BUTTON, .name = "spawn furnace", .on_click = ActSpawnFurnace }, - { .kind = DITEM_BUTTON, .name = "spawn demo blueprint", .on_click = ActSpawnDemoHouseItem }, - { .kind = DITEM_BUTTON, .name = "spawn random durability icemaker", .on_click = ActSpawnDurabilityTest }, - { .kind = DITEM_BUTTON, .name = "spawn sprite tall test", .on_click = ActSpawnTallTest }, { .kind = DITEM_LIST, .name = "demo npcs", @@ -354,6 +362,12 @@ void debug_draw(void) { // NOTE(zaklaus): Flush old debug samples debug_draw_flush(); + static zpl_u8 first_run=0; + if (!first_run) { + first_run = 1; + ActSpawnItemNext(); + } + float xpos = debug_xpos; float ypos = debug_ypos; diff --git a/code/foundation/src/debug/debug_ui_actions.c b/code/foundation/src/debug/debug_ui_actions.c index a0b061b..54e937a 100644 --- a/code/foundation/src/debug/debug_ui_actions.c +++ b/code/foundation/src/debug/debug_ui_actions.c @@ -107,6 +107,37 @@ ActSpawnDemoHouseItem(void) { entity_set_position(e, dest->x, dest->y); } +void +ActSpawnItemPrev(void) { + while (true) { + --sel_item_id; + if (sel_item_id > 0 && item_find(sel_item_id) != ASSET_INVALID) { + break; + } + } +} + +void +ActSpawnItemNext(void) { + while (true) { + ++sel_item_id; + if (sel_item_id > 0 && item_find(sel_item_id) != ASSET_INVALID) { + break; + } + } +} + +void +ActSpawnSelItem(void) { + ecs_entity_t e = item_spawn(sel_item_id, 32); + ecs_entity_t plr = camera_get().ent_id; + + Position const* origin = ecs_get(world_ecs(), plr, Position); + Position * dest = ecs_get_mut(world_ecs(), e, Position); + *dest = *origin; + entity_set_position(e, dest->x, dest->y); +} + void ActSpawnCirclingDriver(void) { ecs_entity_t plr = camera_get().ent_id; diff --git a/code/foundation/src/debug/debug_ui_widgets.c b/code/foundation/src/debug/debug_ui_widgets.c index 668b2f1..0569339 100644 --- a/code/foundation/src/debug/debug_ui_widgets.c +++ b/code/foundation/src/debug/debug_ui_widgets.c @@ -119,6 +119,11 @@ DrawDemoNPCCount(debug_item *it, float xpos, float ypos) { return DrawFormattedText(xpos, ypos, TextFormat("%d", demo_npcs ? zpl_array_count(demo_npcs) : 0)); } +static inline debug_draw_result +DrawSelectedSpawnItem(debug_item *it, float xpos, float ypos) { + (void)it; + return DrawFormattedText(xpos, ypos, TextFormat("%s", asset_names[sel_item_id])); +} // NOTE(zaklaus): world simulation static inline debug_draw_result diff --git a/code/foundation/src/lists/assets_ids.h b/code/foundation/src/lists/assets_ids.h index 91d00cc..c0aad36 100644 --- a/code/foundation/src/lists/assets_ids.h +++ b/code/foundation/src/lists/assets_ids.h @@ -2,45 +2,43 @@ #define ASSET_INVALID 0xFF +#define _ASSETS\ + X(ASSET_EMPTY)\ + X(ASSET_BLANK)\ + X(ASSET_BLOCK_FRAME)\ + X(ASSET_BUILDMODE_HIGHLIGHT)\ + X(ASSET_PLAYER)\ + X(ASSET_THING)\ + X(ASSET_CHEST)\ + X(ASSET_FURNACE)\ + X(ASSET_BLUEPRINT)\ + X(ASSET_FENCE)\ + X(ASSET_DEV)\ + X(ASSET_GROUND)\ + X(ASSET_DIRT)\ + X(ASSET_WATER)\ + X(ASSET_LAVA)\ + X(ASSET_WALL)\ + X(ASSET_HILL)\ + X(ASSET_HILL_SNOW)\ + X(ASSET_HOLE)\ + X(ASSET_WOOD)\ + X(ASSET_TREE)\ + X(ASSET_COAL)\ + X(ASSET_IRON_ORE)\ + X(ASSET_IRON_INGOT)\ + X(ASSET_TEST_TALL)\ + X(ASSET_BELT)\ + X(ASSET_BELT_LEFT)\ + X(ASSET_BELT_RIGHT)\ + X(ASSET_BELT_UP)\ + X(ASSET_BELT_DOWN)\ + typedef enum { - // NOTE(zaklaus): Debug - ASSET_EMPTY, - ASSET_BLANK, - ASSET_BLOCK_FRAME, - ASSET_BUILDMODE_HIGHLIGHT, - - // NOTE(zaklaus): entities - ASSET_PLAYER, - ASSET_THING, - ASSET_CHEST, - ASSET_FURNACE, - ASSET_BLUEPRINT, - - // NOTE(zaklaus): items - - // NOTE(zaklaus): blocks - ASSET_FENCE, - ASSET_DEV, - ASSET_GROUND, - ASSET_DIRT, - ASSET_WATER, - ASSET_LAVA, - ASSET_WALL, - ASSET_HILL, - ASSET_HILL_SNOW, - ASSET_HOLE, - ASSET_WOOD, - ASSET_TREE, - ASSET_COAL, - ASSET_IRON_ORE, - ASSET_IRON_INGOT, - ASSET_TEST_TALL, - - ASSET_BELT, - ASSET_BELT_LEFT, - ASSET_BELT_RIGHT, - ASSET_BELT_UP, - ASSET_BELT_DOWN, - + #define X(id) id, + _ASSETS + #undef X MAX_ASSETS = 1024, } asset_id; + +extern const char *asset_names[]; diff --git a/code/foundation/src/models/assets.c b/code/foundation/src/models/assets.c index c17d574..75d4f71 100644 --- a/code/foundation/src/models/assets.c +++ b/code/foundation/src/models/assets.c @@ -109,3 +109,9 @@ void *assets_get_snd(uint16_t id) { void *assets_get_tex(uint16_t id) { return (void*)&assets[id].tex; } + +const char *asset_names[] = { + #define X(id) #id, + _ASSETS + #undef X +};