208 lines
6.0 KiB
C
208 lines
6.0 KiB
C
#include "components.h"
|
|
|
|
#include "unit_ai.h"
|
|
#include "unit_actions.h"
|
|
|
|
ECS_TAG_DECLARE(GameEntity);
|
|
|
|
ECS_COMPONENT_DECLARE(Resource);
|
|
|
|
ECS_COMPONENT_DECLARE(Owner);
|
|
|
|
ECS_COMPONENT_DECLARE(SpatialGridID);
|
|
ECS_COMPONENT_DECLARE(Position);
|
|
ECS_COMPONENT_DECLARE(Size);
|
|
ECS_COMPONENT_DECLARE(Velocity);
|
|
ECS_COMPONENT_DECLARE(Rotation);
|
|
ECS_COMPONENT_DECLARE(Orientation);
|
|
ECS_COMPONENT_DECLARE(Steering);
|
|
ECS_COMPONENT_DECLARE(TargetPosition);
|
|
ECS_COMPONENT_DECLARE(Path);
|
|
|
|
ECS_COMPONENT_DECLARE(TextureRegion);
|
|
|
|
ECS_COMPONENT_DECLARE(Animation);
|
|
ECS_COMPONENT_DECLARE(Easing);
|
|
|
|
ECS_COMPONENT_DECLARE(Arms);
|
|
ECS_COMPONENT_DECLARE(Arm);
|
|
ECS_COMPONENT_DECLARE(UnitAI);
|
|
ECS_COMPONENT_DECLARE(UnitAction);
|
|
|
|
ECS_TAG_DECLARE(Selectable);
|
|
ECS_TAG_DECLARE(Selected);
|
|
|
|
ECS_COMPONENT_DECLARE(Worker);
|
|
ECS_COMPONENT_DECLARE(Unit);
|
|
ECS_TAG_DECLARE(Storage);
|
|
ECS_TAG_DECLARE(Harvestable);
|
|
ECS_TAG_DECLARE(Buildable);
|
|
ECS_TAG_DECLARE(Workable);
|
|
ECS_TAG_DECLARE(Attackable);
|
|
|
|
void initComponentIDs(ecs_world_t *ecs) {
|
|
ECS_TAG_DEFINE(ecs, GameEntity);
|
|
|
|
ECS_COMPONENT_DEFINE(ecs, Resource);
|
|
|
|
ECS_COMPONENT_DEFINE(ecs, Owner);
|
|
|
|
ECS_COMPONENT_DEFINE(ecs, SpatialGridID);
|
|
ECS_COMPONENT_DEFINE(ecs, Position);
|
|
ECS_COMPONENT_DEFINE(ecs, Size);
|
|
ECS_COMPONENT_DEFINE(ecs, Velocity);
|
|
ECS_COMPONENT_DEFINE(ecs, Rotation);
|
|
ECS_COMPONENT_DEFINE(ecs, Orientation);
|
|
ECS_COMPONENT_DEFINE(ecs, Steering);
|
|
ECS_COMPONENT_DEFINE(ecs, TargetPosition);
|
|
ECS_COMPONENT_DEFINE(ecs, Path);
|
|
|
|
ECS_COMPONENT_DEFINE(ecs, TextureRegion);
|
|
|
|
ECS_COMPONENT_DEFINE(ecs, Animation);
|
|
ECS_COMPONENT_DEFINE(ecs, Easing);
|
|
|
|
ECS_COMPONENT_DEFINE(ecs, Arms);
|
|
ECS_COMPONENT_DEFINE(ecs, Arm);
|
|
ECS_COMPONENT_DEFINE(ecs, UnitAI);
|
|
ECS_COMPONENT_DEFINE(ecs, UnitAction);
|
|
|
|
ECS_TAG_DEFINE(ecs, Selectable);
|
|
ECS_TAG_DEFINE(ecs, Selected);
|
|
|
|
ECS_COMPONENT_DEFINE(ecs, Worker);
|
|
ECS_COMPONENT_DEFINE(ecs, Unit);
|
|
ECS_TAG_DEFINE(ecs, Storage);
|
|
ECS_TAG_DEFINE(ecs, Harvestable);
|
|
ECS_TAG_DEFINE(ecs, Buildable);
|
|
ECS_TAG_DEFINE(ecs, Workable);
|
|
ECS_TAG_DEFINE(ecs, Attackable);
|
|
|
|
}
|
|
|
|
#include <rlImGui.h>
|
|
void igTagCheckbox(const char *label, ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t tag) {
|
|
bool hasTag = ecs_has_id(ecs, entity, tag);
|
|
igCheckbox(label, &hasTag);
|
|
if (hasTag)
|
|
ecs_add_id(ecs, entity, tag);
|
|
else
|
|
ecs_remove_id(ecs, entity, tag);
|
|
}
|
|
void igResource(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
Resource *res = ecs_get_mut_id(ecs, entity, comp);
|
|
const char *resStrings[RES_COUNT];
|
|
for (i32 i = 0; i < RES_COUNT; i++) {
|
|
resStrings[i] = getResourceTypePrettyName(i);
|
|
}
|
|
int curType = res->type;
|
|
igCombo_Str_arr("Type", &curType, resStrings, RES_COUNT, -1);
|
|
res->type = curType;
|
|
igInputInt("Amount", &res->amount, 1, 10, 0);
|
|
}
|
|
void igOwner(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
Owner *owner = ecs_get_mut_id(ecs, entity, comp);
|
|
igInputInt("PlayerID", &owner->playerID, 0, 0, 0);
|
|
}
|
|
|
|
void igSpatialGridID(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
SpatialGridID *id = ecs_get_mut_id(ecs, entity, comp);
|
|
igText("SpatialID", *id);
|
|
}
|
|
void igVec2(Vector2 *vec) {
|
|
igInputFloat("X", &vec->x, 1.0f, 10.0f, "%.2f", 0);
|
|
igInputFloat("Y", &vec->y, 1.0f, 10.0f, "%.2f", 0);
|
|
}
|
|
void igVec2Comp(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
Vector2 *vec = ecs_get_mut_id(ecs, entity, comp);
|
|
igVec2(vec);
|
|
}
|
|
void igFloat(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
f32 *f = ecs_get_mut_id(ecs, entity, comp);
|
|
igInputFloat("", f, 0.1f, 1.0f, "%.2f", 0);
|
|
}
|
|
|
|
void igPath(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
Path path = *(Path *) ecs_get_mut_id(ecs, entity, comp);
|
|
i32 idx = 0;
|
|
while (path.paths) {
|
|
for (int32_t i = path.curWaypoint; i < path.paths->numWaypoints; i++) {
|
|
igPushID_Int(idx);
|
|
igText("Waypoint %d:", idx);
|
|
igInputFloat("X", &path.paths->waypoints[i].x, 1, 16, "%.2f", 0);
|
|
igInputFloat("Y", &path.paths->waypoints[i].y, 1, 16, "%.2f", 0);
|
|
igPopID();
|
|
idx++;
|
|
}
|
|
path.paths = path.paths->next;
|
|
path.curWaypoint = 0;
|
|
}
|
|
}
|
|
|
|
void igRect(Rectangle *rect) {
|
|
igInputFloat("X", &rect->x, 1, 16, "%.2f", 0);
|
|
igInputFloat("Y", &rect->y, 1, 16, "%.2f", 0);
|
|
igInputFloat("Width", &rect->width, 1, 16, "%.2f", 0);
|
|
igInputFloat("Height", &rect->height, 1, 16, "%.2f", 0);
|
|
}
|
|
void igTextureRegion(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
TextureRegion *tex = ecs_get_mut_id(ecs, entity, comp);
|
|
igText("Texture: %d", tex->texture.id);
|
|
igRect(&tex->rec);
|
|
bool flipX = tex->flipX;
|
|
bool flipY = tex->flipY;
|
|
igCheckbox("flipX", &flipX);
|
|
igCheckbox("flipY", &flipY);
|
|
tex->flipX = flipX;
|
|
tex->flipY = flipY;
|
|
}
|
|
|
|
void igAnimation(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
//Animation *anim = ecs_get_mut_id(ecs, entity, comp);
|
|
|
|
|
|
}
|
|
void igEasing(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
Easing *easing = ecs_get_mut_id(ecs, entity, comp);
|
|
igText("Component: %d, offset: %d", easing->compID, easing->offset);
|
|
igText("x = %.2f + %.2f * (%.2f + (%.2f * %.2f) + %.2f) + %.2f",
|
|
easing->start, easing->target, easing->easeStart, easing->easeTarget,
|
|
easing->x, easing->easeOffset, easing->offset);
|
|
}
|
|
|
|
void igArms(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
|
|
}
|
|
void igArm(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
|
|
}
|
|
|
|
void igUnitAction(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
|
|
}
|
|
void igUnitAI(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
|
|
}
|
|
void igWorker(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
|
|
}
|
|
void igUnit(ecs_world_t *ecs,
|
|
ecs_entity_t entity, ecs_entity_t comp) {
|
|
|
|
}
|