Inspection for Animation component
This commit is contained in:
@@ -166,11 +166,35 @@ void igTextureRegion(ecs_world_t *ecs,
|
|||||||
tex->flipY = flipY;
|
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,
|
void igAnimation(ecs_world_t *ecs,
|
||||||
ecs_entity_t entity, ecs_entity_t comp) {
|
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,
|
void igEasing(ecs_world_t *ecs,
|
||||||
ecs_entity_t entity, ecs_entity_t comp) {
|
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) {
|
static const char *getBuildingStr(BuildingType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BUILDING_KEEP: return "keep";
|
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) {
|
switch (type) {
|
||||||
case BUILDING_KEEP:
|
case BUILDING_KEEP:
|
||||||
if (outWidth) *outWidth = 3;
|
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) {
|
static bool entityHasAnimation(EntityType entity, AnimType type) {
|
||||||
switch (entity) {
|
switch (entity) {
|
||||||
case ENTITY_WORKER:
|
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) {
|
void igInspectComp(const char *label, ecs_entity_t entity, ecs_entity_t comp, ImGuiCompFn fn) {
|
||||||
igPushID_Int(comp);
|
igPushID_Int(comp);
|
||||||
igSeparatorText(label);
|
if (igTreeNode_Str(label)) {
|
||||||
bool isAttached = ecs_has_id(ECS, entity, comp);
|
bool isAttached = ecs_has_id(ECS, entity, comp);
|
||||||
igCheckbox("Attached", &isAttached);
|
igCheckbox("Attached", &isAttached);
|
||||||
|
|
||||||
if (isAttached)
|
if (isAttached)
|
||||||
fn(ECS, entity, comp);
|
fn(ECS, entity, comp);
|
||||||
|
|
||||||
if (isAttached != ecs_has_id(ECS, entity, comp)) {
|
if (isAttached != ecs_has_id(ECS, entity, comp)) {
|
||||||
if (!isAttached) {
|
if (!isAttached) {
|
||||||
ecs_remove_id(ECS, entity, comp);
|
ecs_remove_id(ECS, entity, comp);
|
||||||
} else {
|
} else {
|
||||||
ecs_set_id(ECS, entity, comp, 0, NULL);
|
ecs_set_id(ECS, entity, comp, 0, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
igTreePop();
|
||||||
}
|
}
|
||||||
|
|
||||||
igPopID();
|
igPopID();
|
||||||
}
|
}
|
||||||
void igInspectWindow(ecs_entity_t entity, bool *open) {
|
void igInspectWindow(ecs_entity_t entity, bool *open) {
|
||||||
|
if (!ecs_is_alive(ECS, entity)) {
|
||||||
|
*open = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
igSetNextWindowSize((ImVec2) {300, 440}, ImGuiCond_FirstUseEver);
|
igSetNextWindowSize((ImVec2) {300, 440}, ImGuiCond_FirstUseEver);
|
||||||
char buf[64];
|
char buf[64];
|
||||||
snprintf(buf, sizeof(buf), "Entity: %ld", entity);
|
snprintf(buf, sizeof(buf), "Entity: %ld", entity);
|
||||||
@@ -731,25 +736,27 @@ void igInspectWindow(ecs_entity_t entity, bool *open) {
|
|||||||
else
|
else
|
||||||
igTextColored((ImVec4) {1, 0, 0, 1}, "NONE");
|
igTextColored((ImVec4) {1, 0, 0, 1}, "NONE");
|
||||||
}
|
}
|
||||||
igInspectComp("Resource", entity, ecs_id(Resource), igResource);
|
if (igCollapsingHeader_TreeNodeFlags("Components", 0)) {
|
||||||
igInspectComp("Owner", entity, ecs_id(Owner), igOwner);
|
igInspectComp("Resource", entity, ecs_id(Resource), igResource);
|
||||||
igInspectComp("SpatialGridID", entity, ecs_id(SpatialGridID), igSpatialGridID);
|
igInspectComp("Owner", entity, ecs_id(Owner), igOwner);
|
||||||
igInspectComp("Position", entity, ecs_id(Position), igVec2Comp);
|
igInspectComp("SpatialGridID", entity, ecs_id(SpatialGridID), igSpatialGridID);
|
||||||
igInspectComp("Size", entity, ecs_id(Size), igVec2Comp);
|
igInspectComp("Position", entity, ecs_id(Position), igVec2Comp);
|
||||||
igInspectComp("Velocity", entity, ecs_id(Velocity), igVec2Comp);
|
igInspectComp("Size", entity, ecs_id(Size), igVec2Comp);
|
||||||
igInspectComp("TargetPosition", entity, ecs_id(TargetPosition), igVec2Comp);
|
igInspectComp("Velocity", entity, ecs_id(Velocity), igVec2Comp);
|
||||||
igInspectComp("Steering", entity, ecs_id(Steering), igVec2Comp);
|
igInspectComp("TargetPosition", entity, ecs_id(TargetPosition), igVec2Comp);
|
||||||
igInspectComp("Rotation", entity, ecs_id(Rotation), igFloat);
|
igInspectComp("Steering", entity, ecs_id(Steering), igVec2Comp);
|
||||||
igInspectComp("Path", entity, ecs_id(Path), igPath);
|
igInspectComp("Rotation", entity, ecs_id(Rotation), igFloat);
|
||||||
igInspectComp("TextureRegion", entity, ecs_id(TextureRegion), igTextureRegion);
|
igInspectComp("Path", entity, ecs_id(Path), igPath);
|
||||||
igInspectComp("Animation", entity, ecs_id(Animation), igAnimation);
|
igInspectComp("TextureRegion", entity, ecs_id(TextureRegion), igTextureRegion);
|
||||||
igInspectComp("Easing", entity, ecs_id(Easing), igEasing);
|
igInspectComp("Animation", entity, ecs_id(Animation), igAnimation);
|
||||||
igInspectComp("Arms", entity, ecs_id(Arms), igArms);
|
igInspectComp("Easing", entity, ecs_id(Easing), igEasing);
|
||||||
igInspectComp("Arm", entity, ecs_id(Arm), igArm);
|
igInspectComp("Arms", entity, ecs_id(Arms), igArms);
|
||||||
igInspectComp("BzBTState", entity, ecs_id(BzBTState), igBzBTState);
|
igInspectComp("Arm", entity, ecs_id(Arm), igArm);
|
||||||
igInspectComp("AIBlackboard", entity, ecs_id(AIBlackboard), igAIBlackboard);
|
igInspectComp("BzBTState", entity, ecs_id(BzBTState), igBzBTState);
|
||||||
igInspectComp("Worker", entity, ecs_id(Worker), igWorker);
|
igInspectComp("AIBlackboard", entity, ecs_id(AIBlackboard), igAIBlackboard);
|
||||||
igInspectComp("Unit", entity, ecs_id(Unit), igUnit);
|
igInspectComp("Worker", entity, ecs_id(Worker), igWorker);
|
||||||
|
igInspectComp("Unit", entity, ecs_id(Unit), igUnit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
igEnd();
|
igEnd();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ class EnumWriter:
|
|||||||
def output_enum_tile_size(self, func_name):
|
def output_enum_tile_size(self, func_name):
|
||||||
writer = self.writer
|
writer = self.writer
|
||||||
writer.output(
|
writer.output(
|
||||||
f"static {self.enum_type} {func_name}({self.enum_type} type, BzTileID *outWidth, BzTileID *outHeight) ")
|
f"static {self.enum_type} {func_name}({self.enum_type} type, i32 *outWidth, i32 *outHeight) ")
|
||||||
writer.block_start()
|
writer.block_start()
|
||||||
|
|
||||||
writer.output("switch (type) ")
|
writer.output("switch (type) ")
|
||||||
@@ -330,7 +330,22 @@ class EnumWriter:
|
|||||||
def output_anim_enum(self):
|
def output_anim_enum(self):
|
||||||
writer = self.writer
|
writer = self.writer
|
||||||
writer.enum_list(self.anim_type, self.animations)
|
writer.enum_list(self.anim_type, self.animations)
|
||||||
pass
|
|
||||||
|
def output_anim_enum_to_str(self, func_name):
|
||||||
|
writer = self.writer
|
||||||
|
writer.output(f"static const char *{func_name}({self.anim_type} type) ")
|
||||||
|
writer.block_start()
|
||||||
|
|
||||||
|
writer.output("switch (type) ")
|
||||||
|
writer.block_start()
|
||||||
|
|
||||||
|
for name in self.animations:
|
||||||
|
writer.output(f"case {name}: return \"{name}\";\n")
|
||||||
|
writer.output(f"default: return NULL;\n")
|
||||||
|
|
||||||
|
writer.block_end()
|
||||||
|
writer.block_end()
|
||||||
|
writer.empty_line()
|
||||||
|
|
||||||
def output_has_anim(self, func_name):
|
def output_has_anim(self, func_name):
|
||||||
writer = self.writer
|
writer = self.writer
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ writer.empty_line()
|
|||||||
building_writer.output_enum()
|
building_writer.output_enum()
|
||||||
building_writer.output_tile_to_enum("getTileBuilding")
|
building_writer.output_tile_to_enum("getTileBuilding")
|
||||||
building_writer.output_enum_to_tile("getBuildingTile")
|
building_writer.output_enum_to_tile("getBuildingTile")
|
||||||
building_writer.output_str_to_enum("getBuildingFromStr")
|
|
||||||
building_writer.output_enum_to_str("getBuildingStr")
|
building_writer.output_enum_to_str("getBuildingStr")
|
||||||
building_writer.output_enum_tile_size("getBuildingSize")
|
building_writer.output_enum_tile_size("getBuildingSize")
|
||||||
writer.empty_line()
|
writer.empty_line()
|
||||||
@@ -75,11 +74,13 @@ anim_writer.output_enum()
|
|||||||
anim_writer.output_anim_enum()
|
anim_writer.output_anim_enum()
|
||||||
|
|
||||||
anim_writer.output_enum_to_tile("getEntityTile")
|
anim_writer.output_enum_to_tile("getEntityTile")
|
||||||
|
anim_writer.output_enum_to_str("getEntityStr")
|
||||||
|
anim_writer.output_anim_enum_to_str("getEntityAnimationStr")
|
||||||
anim_writer.output_has_anim("entityHasAnimation")
|
anim_writer.output_has_anim("entityHasAnimation")
|
||||||
anim_writer.output_anim_sequence("entityGetAnimationSequence")
|
anim_writer.output_anim_sequence("entityGetAnimationSequence")
|
||||||
anim_writer.output_anim_frame("entityGetAnimationFrame")
|
anim_writer.output_anim_frame("entityGetAnimationFrame")
|
||||||
|
|
||||||
print(item_tiles)
|
#print(item_tiles)
|
||||||
item_writer = EnumWriter(writer, item_tiles, "item", "item_anim")
|
item_writer = EnumWriter(writer, item_tiles, "item", "item_anim")
|
||||||
item_writer.output_enum()
|
item_writer.output_enum()
|
||||||
#item_writer.output_anim_enum()
|
#item_writer.output_anim_enum()
|
||||||
|
|||||||
Reference in New Issue
Block a user