entity inspector addition

efd/v1
Dominik Madarász 2023-01-15 17:44:48 +01:00
parent 72005402cf
commit 553afd44d0
4 changed files with 74 additions and 10 deletions

View File

@ -268,6 +268,7 @@ static debug_item items[] = {
.list = {
.items = (debug_item[]) {
{ .kind = DITEM_TOOL, .name = "asset inspector", .tool = { .is_open = 0, .on_draw = ToolAssetInspector } },
{ .kind = DITEM_TOOL, .name = "entity inspector", .tool = { .is_open = 0, .on_draw = ToolEntityInspector } },
{ .kind = DITEM_END },
},
.is_collapsed = 0

View File

@ -41,7 +41,7 @@ void ToolAssetInspector(void) {
item_desc it = item_get_desc(it_id);
if (nk_button_label(nk_ctx, "spawn")) {
ecs_entity_t e = item_spawn(i, 1);
ecs_entity_t e = item_spawn(i, it.max_quantity);
ecs_entity_t plr = camera_get().ent_id;
Position const* origin = ecs_get(world_ecs(), plr, Position);
@ -65,3 +65,53 @@ void ToolAssetInspector(void) {
nk_end(nk_ctx);
}
}
void ToolEntityInspector(void) {
if (nk_begin(nk_ctx, "Entity Inspector", nk_rect(660, 100, 240, 800),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| NK_WINDOW_TITLE))
{
static ecs_query_t *q = 0;
if (!q) {
q = ecs_query(world_ecs(), {
.filter.terms = {
{ .id = ecs_id(Position) },
{ .id = ecs_id(Classify), .inout = EcsIn }
}
});
}
ecs_iter_t it = ecs_query_iter(world_ecs(), q);
while (ecs_query_next(&it)) {
Position *p = ecs_field(&it, Position, 1);
const Classify *c = ecs_field(&it, Classify, 2);
for (int i = 0; i < it.count; i++) {
if (nk_tree_push_id(nk_ctx, NK_TREE_NODE, zpl_bprintf("%lld [%s]", it.entities[i], class_names[c[i].id]), NK_MINIMIZED, (int)it.entities[i])) {
{
nk_label(nk_ctx, "position:", NK_TEXT_LEFT);
nk_property_float(nk_ctx, "#x:", ZPL_F32_MIN, &p[i].x, ZPL_F32_MAX, 0.1f, 0.2f);
nk_property_float(nk_ctx, "#y:", ZPL_F32_MIN, &p[i].y, ZPL_F32_MAX, 0.1f, 0.2f);
if (nk_button_label(nk_ctx, "teleport to")) {
ecs_entity_t plr = camera_get().ent_id;
Position const* origin = ecs_get(world_ecs(), it.entities[i], Position);
entity_set_position(plr, origin->x, origin->y);
}
if (nk_button_label(nk_ctx, "teleport here")) {
ecs_entity_t plr = camera_get().ent_id;
Position const* origin = ecs_get(world_ecs(), plr, Position);
entity_set_position(it.entities[i], origin->x, origin->y);
}
}
nk_tree_pop(nk_ctx);
}
}
}
nk_end(nk_ctx);
}
}

View File

@ -2,6 +2,12 @@
#include "pkt/packet_utils.h"
#include "world/blocks.h"
const char *class_names[] = {
#define X(id) #id,
_CLASSES
#undef X
};
ZPL_TABLE_DEFINE(entity_view_tbl, entity_view_tbl_, entity_view);
pkt_desc pkt_entity_view_desc[] = {

View File

@ -8,16 +8,21 @@
#define MAX_CRAFTABLES 32
#define _CLASSES\
X(EKIND_SERVER)\
X(EKIND_PLAYER)\
X(EKIND_ITEM)\
X(EKIND_DEVICE)\
X(EKIND_VEHICLE)\
X(EKIND_DEMO_NPC)\
X(EKIND_MONSTER)\
X(EKIND_MACRO_BOT)\
X(EKIND_CHUNK)
typedef enum {
EKIND_SERVER = 0,
EKIND_PLAYER,
EKIND_ITEM,
EKIND_DEVICE,
EKIND_VEHICLE,
EKIND_DEMO_NPC,
EKIND_MONSTER,
EKIND_MACRO_BOT,
EKIND_CHUNK,
#define X(id) id,
_CLASSES
#undef X
FORCE_EKIND_UINT16 = UINT16_MAX
} entity_kind;
@ -34,6 +39,8 @@ typedef enum {
FORCE_ETRAN_UINT8 = UINT8_MAX
} entity_transition_effect;
extern const char *class_names[];
typedef struct entity_view {
int64_t ent_id;
entity_kind kind;