Inspection for Animation component
This commit is contained in:
@@ -166,11 +166,35 @@ void igTextureRegion(ecs_world_t *ecs,
|
||||
tex->flipY = flipY;
|
||||
}
|
||||
|
||||
static void igEntityType(EntityType *type) {
|
||||
const char *prettyStrings[ENTITY_COUNT];
|
||||
for (int i = 0; i < ENTITY_COUNT; i++) {
|
||||
prettyStrings[i] = getEntityStr(i);
|
||||
}
|
||||
igCombo_Str_arr("EntityType", type, prettyStrings, ENTITY_COUNT, -1);
|
||||
}
|
||||
static void igAnimType(AnimType *type) {
|
||||
const char *prettyStrings[ANIM_COUNT];
|
||||
for (int i = 0; i < ANIM_COUNT; i++) {
|
||||
prettyStrings[i] = getEntityAnimationStr(i);
|
||||
}
|
||||
igCombo_Str_arr("AnimType", type, prettyStrings, ANIM_COUNT, -1);
|
||||
}
|
||||
void igAnimation(ecs_world_t *ecs,
|
||||
ecs_entity_t entity, ecs_entity_t comp) {
|
||||
//Animation *anim = ecs_get_mut_id(ecs, entity, comp);
|
||||
Animation *anim = ecs_get_mut_id(ecs, entity, comp);
|
||||
|
||||
EntityType curEntityType = anim->entityType;
|
||||
igEntityType(&curEntityType);
|
||||
anim->entityType = curEntityType;
|
||||
|
||||
AnimType curAnimType = anim->animType;
|
||||
igAnimType(&curAnimType);
|
||||
anim->animType = curAnimType;
|
||||
|
||||
igText("tileset: %p", anim->tileset);
|
||||
igText("curFrame: %d", anim->curFrame);
|
||||
igText("elapsed: %.2f < %.2F", anim->elapsed, anim->frame.duration);
|
||||
}
|
||||
void igEasing(ecs_world_t *ecs,
|
||||
ecs_entity_t entity, ecs_entity_t comp) {
|
||||
|
||||
@@ -286,11 +286,6 @@ static BzTileID getBuildingTile(BuildingType type) {
|
||||
}
|
||||
}
|
||||
|
||||
static BuildingType getBuildingFromStr(const char *str) {
|
||||
if (strncmp("keep", str, 4) == 0) return BUILDING_KEEP;
|
||||
return BUILDING_COUNT;
|
||||
}
|
||||
|
||||
static const char *getBuildingStr(BuildingType type) {
|
||||
switch (type) {
|
||||
case BUILDING_KEEP: return "keep";
|
||||
@@ -298,7 +293,7 @@ static const char *getBuildingStr(BuildingType type) {
|
||||
}
|
||||
}
|
||||
|
||||
static BuildingType getBuildingSize(BuildingType type, BzTileID *outWidth, BzTileID *outHeight) {
|
||||
static BuildingType getBuildingSize(BuildingType type, i32 *outWidth, i32 *outHeight) {
|
||||
switch (type) {
|
||||
case BUILDING_KEEP:
|
||||
if (outWidth) *outWidth = 3;
|
||||
@@ -344,6 +339,30 @@ static BzTileID getEntityTile(EntityType type) {
|
||||
}
|
||||
}
|
||||
|
||||
static const char *getEntityStr(EntityType type) {
|
||||
switch (type) {
|
||||
case ENTITY_WORKER: return "worker";
|
||||
case ENTITY_WOOD: return "wood";
|
||||
case ENTITY_STONE: return "stone";
|
||||
case ENTITY_APPLE: return "apple";
|
||||
case ENTITY_GOLD: return "gold";
|
||||
case ENTITY_POP: return "pop";
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *getEntityAnimationStr(AnimType type) {
|
||||
switch (type) {
|
||||
case ANIM_IDLE: return "ANIM_IDLE";
|
||||
case ANIM_WALK: return "ANIM_WALK";
|
||||
case ANIM_HURT: return "ANIM_HURT";
|
||||
case ANIM_DIE: return "ANIM_DIE";
|
||||
case ANIM_COUNT: return "ANIM_COUNT";
|
||||
case ANIM_NONE: return "ANIM_NONE";
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool entityHasAnimation(EntityType entity, AnimType type) {
|
||||
switch (entity) {
|
||||
case ENTITY_WORKER:
|
||||
|
||||
67
game/main.c
67
game/main.c
@@ -686,24 +686,29 @@ void render(float dt, void *userData) {
|
||||
|
||||
void igInspectComp(const char *label, ecs_entity_t entity, ecs_entity_t comp, ImGuiCompFn fn) {
|
||||
igPushID_Int(comp);
|
||||
igSeparatorText(label);
|
||||
bool isAttached = ecs_has_id(ECS, entity, comp);
|
||||
igCheckbox("Attached", &isAttached);
|
||||
if (igTreeNode_Str(label)) {
|
||||
bool isAttached = ecs_has_id(ECS, entity, comp);
|
||||
igCheckbox("Attached", &isAttached);
|
||||
|
||||
if (isAttached)
|
||||
fn(ECS, entity, comp);
|
||||
if (isAttached)
|
||||
fn(ECS, entity, comp);
|
||||
|
||||
if (isAttached != ecs_has_id(ECS, entity, comp)) {
|
||||
if (!isAttached) {
|
||||
ecs_remove_id(ECS, entity, comp);
|
||||
} else {
|
||||
ecs_set_id(ECS, entity, comp, 0, NULL);
|
||||
if (isAttached != ecs_has_id(ECS, entity, comp)) {
|
||||
if (!isAttached) {
|
||||
ecs_remove_id(ECS, entity, comp);
|
||||
} else {
|
||||
ecs_set_id(ECS, entity, comp, 0, NULL);
|
||||
}
|
||||
}
|
||||
igTreePop();
|
||||
}
|
||||
|
||||
igPopID();
|
||||
}
|
||||
void igInspectWindow(ecs_entity_t entity, bool *open) {
|
||||
if (!ecs_is_alive(ECS, entity)) {
|
||||
*open = false;
|
||||
return;
|
||||
}
|
||||
igSetNextWindowSize((ImVec2) {300, 440}, ImGuiCond_FirstUseEver);
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "Entity: %ld", entity);
|
||||
@@ -731,25 +736,27 @@ void igInspectWindow(ecs_entity_t entity, bool *open) {
|
||||
else
|
||||
igTextColored((ImVec4) {1, 0, 0, 1}, "NONE");
|
||||
}
|
||||
igInspectComp("Resource", entity, ecs_id(Resource), igResource);
|
||||
igInspectComp("Owner", entity, ecs_id(Owner), igOwner);
|
||||
igInspectComp("SpatialGridID", entity, ecs_id(SpatialGridID), igSpatialGridID);
|
||||
igInspectComp("Position", entity, ecs_id(Position), igVec2Comp);
|
||||
igInspectComp("Size", entity, ecs_id(Size), igVec2Comp);
|
||||
igInspectComp("Velocity", entity, ecs_id(Velocity), igVec2Comp);
|
||||
igInspectComp("TargetPosition", entity, ecs_id(TargetPosition), igVec2Comp);
|
||||
igInspectComp("Steering", entity, ecs_id(Steering), igVec2Comp);
|
||||
igInspectComp("Rotation", entity, ecs_id(Rotation), igFloat);
|
||||
igInspectComp("Path", entity, ecs_id(Path), igPath);
|
||||
igInspectComp("TextureRegion", entity, ecs_id(TextureRegion), igTextureRegion);
|
||||
igInspectComp("Animation", entity, ecs_id(Animation), igAnimation);
|
||||
igInspectComp("Easing", entity, ecs_id(Easing), igEasing);
|
||||
igInspectComp("Arms", entity, ecs_id(Arms), igArms);
|
||||
igInspectComp("Arm", entity, ecs_id(Arm), igArm);
|
||||
igInspectComp("BzBTState", entity, ecs_id(BzBTState), igBzBTState);
|
||||
igInspectComp("AIBlackboard", entity, ecs_id(AIBlackboard), igAIBlackboard);
|
||||
igInspectComp("Worker", entity, ecs_id(Worker), igWorker);
|
||||
igInspectComp("Unit", entity, ecs_id(Unit), igUnit);
|
||||
if (igCollapsingHeader_TreeNodeFlags("Components", 0)) {
|
||||
igInspectComp("Resource", entity, ecs_id(Resource), igResource);
|
||||
igInspectComp("Owner", entity, ecs_id(Owner), igOwner);
|
||||
igInspectComp("SpatialGridID", entity, ecs_id(SpatialGridID), igSpatialGridID);
|
||||
igInspectComp("Position", entity, ecs_id(Position), igVec2Comp);
|
||||
igInspectComp("Size", entity, ecs_id(Size), igVec2Comp);
|
||||
igInspectComp("Velocity", entity, ecs_id(Velocity), igVec2Comp);
|
||||
igInspectComp("TargetPosition", entity, ecs_id(TargetPosition), igVec2Comp);
|
||||
igInspectComp("Steering", entity, ecs_id(Steering), igVec2Comp);
|
||||
igInspectComp("Rotation", entity, ecs_id(Rotation), igFloat);
|
||||
igInspectComp("Path", entity, ecs_id(Path), igPath);
|
||||
igInspectComp("TextureRegion", entity, ecs_id(TextureRegion), igTextureRegion);
|
||||
igInspectComp("Animation", entity, ecs_id(Animation), igAnimation);
|
||||
igInspectComp("Easing", entity, ecs_id(Easing), igEasing);
|
||||
igInspectComp("Arms", entity, ecs_id(Arms), igArms);
|
||||
igInspectComp("Arm", entity, ecs_id(Arm), igArm);
|
||||
igInspectComp("BzBTState", entity, ecs_id(BzBTState), igBzBTState);
|
||||
igInspectComp("AIBlackboard", entity, ecs_id(AIBlackboard), igAIBlackboard);
|
||||
igInspectComp("Worker", entity, ecs_id(Worker), igWorker);
|
||||
igInspectComp("Unit", entity, ecs_id(Unit), igUnit);
|
||||
}
|
||||
}
|
||||
igEnd();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user