Rename BUILDINGS to BuildingType, add owner component to entities
This commit is contained in:
@@ -203,6 +203,10 @@
|
||||
"id":13,
|
||||
"type":"animal_farm"
|
||||
},
|
||||
{
|
||||
"id":31,
|
||||
"type":"player_red"
|
||||
},
|
||||
{
|
||||
"id":32,
|
||||
"objectgroup":
|
||||
@@ -324,6 +328,10 @@
|
||||
"id":45,
|
||||
"type":"animal_farm"
|
||||
},
|
||||
{
|
||||
"id":63,
|
||||
"type":"player_blue"
|
||||
},
|
||||
{
|
||||
"id":64,
|
||||
"objectgroup":
|
||||
|
||||
@@ -13,4 +13,8 @@ typedef struct TileSize {
|
||||
BzTile h;
|
||||
} TileSize;
|
||||
|
||||
typedef struct Owner {
|
||||
BuildingType playerID;
|
||||
} Owner;
|
||||
|
||||
#endif //PIXELDEFENSE_COMPONENTS_H
|
||||
|
||||
@@ -49,6 +49,7 @@ ecs_entity_t *entityMap = NULL;
|
||||
bool prepareBuildings(BzTileLayer *layer, BzTile *data, i32 dataCount) {
|
||||
ECS_COMPONENT(ECS, TilePosition);
|
||||
ECS_COMPONENT(ECS, TileSize);
|
||||
ECS_COMPONENT(ECS, Owner);
|
||||
|
||||
entityMap = bzCalloc(sizeof(*entityMap), layer->width * layer->height);
|
||||
|
||||
@@ -74,6 +75,9 @@ bool prepareBuildings(BzTileLayer *layer, BzTile *data, i32 dataCount) {
|
||||
ecs_entity_t e = ecs_new_id(ECS);
|
||||
ecs_set(ECS, e, TilePosition, {.x=x, .y=y});
|
||||
ecs_set(ECS, e, TileSize, {.w=size.w, .h=size.h});
|
||||
ownerTile = bzTilesetGetTile(buildingTileset, ownerTile);
|
||||
ownerTile = getTileBuilding(ownerTile);
|
||||
ecs_set(ECS, e, Owner, {.playerID=ownerTile});
|
||||
|
||||
for (i32 yIdx = y; yIdx < y + size.h; yIdx++) {
|
||||
for (i32 xIdx = x; xIdx < x + size.w; xIdx++) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
typedef enum BUILDINGS {
|
||||
typedef enum BuildingType {
|
||||
BUILDINGS_NONE,
|
||||
BUILDINGS_KEEP,
|
||||
BUILDINGS_GRANARY,
|
||||
@@ -14,7 +14,9 @@ typedef enum BUILDINGS {
|
||||
BUILDINGS_BARACKS,
|
||||
BUILDINGS_ORCHARD,
|
||||
BUILDINGS_ANIMAL_FARM,
|
||||
BUILDINGS_PLAYER_RED,
|
||||
BUILDINGS_FLETCHER,
|
||||
BUILDINGS_PLAYER_BLUE,
|
||||
BUILDINGS_SMITHY,
|
||||
BUILDINGS_WORKSHOP,
|
||||
BUILDINGS_FARM,
|
||||
@@ -24,10 +26,10 @@ typedef enum BUILDINGS {
|
||||
BUILDINGS_TOWER,
|
||||
BUILDINGS_SMALL_TOWER,
|
||||
BUILDINGS_COUNT
|
||||
} BUILDINGS;
|
||||
} BuildingType;
|
||||
|
||||
|
||||
static BUILDINGS getTileBuilding(BzTile tile) {
|
||||
static BuildingType getTileBuilding(BzTile tile) {
|
||||
switch (tile) {
|
||||
case 0:
|
||||
case 1:
|
||||
@@ -65,9 +67,13 @@ static BUILDINGS getTileBuilding(BzTile tile) {
|
||||
case 44:
|
||||
case 45:
|
||||
return BUILDINGS_ANIMAL_FARM;
|
||||
case 31:
|
||||
return BUILDINGS_PLAYER_RED;
|
||||
case 35:
|
||||
case 36:
|
||||
return BUILDINGS_FLETCHER;
|
||||
case 63:
|
||||
return BUILDINGS_PLAYER_BLUE;
|
||||
case 67:
|
||||
case 68:
|
||||
return BUILDINGS_SMITHY;
|
||||
@@ -94,7 +100,7 @@ static BUILDINGS getTileBuilding(BzTile tile) {
|
||||
}
|
||||
}
|
||||
|
||||
static BUILDINGS getBuildingFromStr(const char *str) {
|
||||
static BuildingType getBuildingFromStr(const char *str) {
|
||||
if (strncmp("keep", str, 4) == 0) return BUILDINGS_KEEP;
|
||||
if (strncmp("granary", str, 7) == 0) return BUILDINGS_GRANARY;
|
||||
if (strncmp("armory", str, 6) == 0) return BUILDINGS_ARMORY;
|
||||
@@ -103,7 +109,9 @@ static BUILDINGS getBuildingFromStr(const char *str) {
|
||||
if (strncmp("baracks", str, 7) == 0) return BUILDINGS_BARACKS;
|
||||
if (strncmp("orchard", str, 7) == 0) return BUILDINGS_ORCHARD;
|
||||
if (strncmp("animal_farm", str, 11) == 0) return BUILDINGS_ANIMAL_FARM;
|
||||
if (strncmp("player_red", str, 10) == 0) return BUILDINGS_PLAYER_RED;
|
||||
if (strncmp("fletcher", str, 8) == 0) return BUILDINGS_FLETCHER;
|
||||
if (strncmp("player_blue", str, 11) == 0) return BUILDINGS_PLAYER_BLUE;
|
||||
if (strncmp("smithy", str, 6) == 0) return BUILDINGS_SMITHY;
|
||||
if (strncmp("workshop", str, 8) == 0) return BUILDINGS_WORKSHOP;
|
||||
if (strncmp("farm", str, 4) == 0) return BUILDINGS_FARM;
|
||||
@@ -114,7 +122,7 @@ static BUILDINGS getBuildingFromStr(const char *str) {
|
||||
if (strncmp("small_tower", str, 11) == 0) return BUILDINGS_SMALL_TOWER;
|
||||
else return BUILDINGS_NONE;
|
||||
}
|
||||
static void getBuildingSize(BUILDINGS type, BzTile *outWidth, BzTile *outHeight) {
|
||||
static void getBuildingSize(BuildingType type, BzTile *outWidth, BzTile *outHeight) {
|
||||
switch (type) {
|
||||
case BUILDINGS_KEEP:
|
||||
if (outWidth) *outWidth = 3;
|
||||
@@ -148,10 +156,18 @@ static void getBuildingSize(BUILDINGS type, BzTile *outWidth, BzTile *outHeight)
|
||||
if (outWidth) *outWidth = 2;
|
||||
if (outHeight) *outHeight = 2;
|
||||
break;
|
||||
case BUILDINGS_PLAYER_RED:
|
||||
if (outWidth) *outWidth = 1;
|
||||
if (outHeight) *outHeight = 1;
|
||||
break;
|
||||
case BUILDINGS_FLETCHER:
|
||||
if (outWidth) *outWidth = 2;
|
||||
if (outHeight) *outHeight = 1;
|
||||
break;
|
||||
case BUILDINGS_PLAYER_BLUE:
|
||||
if (outWidth) *outWidth = 1;
|
||||
if (outHeight) *outHeight = 1;
|
||||
break;
|
||||
case BUILDINGS_SMITHY:
|
||||
if (outWidth) *outWidth = 2;
|
||||
if (outHeight) *outHeight = 1;
|
||||
|
||||
@@ -25,6 +25,8 @@ for tile in tiles:
|
||||
|
||||
enum_identifier = os.path.basename(path).split(".")[0].capitalize()
|
||||
enum_name = enum_identifier.upper()
|
||||
if sys.argv[2]:
|
||||
enum_identifier = sys.argv[2]
|
||||
|
||||
indent_level = 0
|
||||
indent_offset = 4
|
||||
@@ -51,21 +53,21 @@ print()
|
||||
enum_none = enum_string("none")
|
||||
enum_count = enum_string("count")
|
||||
|
||||
print(f"{indent()}typedef enum {enum_name} {{")
|
||||
print(f"{indent()}typedef enum {enum_identifier} {{")
|
||||
indent_level += indent_offset
|
||||
print(f"{indent()}{enum_none},")
|
||||
for enum in types:
|
||||
print(f"{indent()}{enum_string(enum)},")
|
||||
print(f"{indent()}{enum_count}")
|
||||
indent_level -= indent_offset
|
||||
print(f"{indent()}}} {enum_name};")
|
||||
print(f"{indent()}}} {enum_identifier};")
|
||||
|
||||
print()
|
||||
print()
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static {enum_name} getTileBuilding(BzTile tile) {{")
|
||||
print(f"{indent()}static {enum_identifier} getTileBuilding(BzTile tile) {{")
|
||||
indent_level += indent_offset
|
||||
print(f"{indent()}switch (tile) {{")
|
||||
for enum, ids in types.items():
|
||||
@@ -93,7 +95,7 @@ print()
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static {enum_name} getBuildingFromStr(const char *str) {{")
|
||||
print(f"{indent()}static {enum_identifier} getBuildingFromStr(const char *str) {{")
|
||||
indent_level += indent_offset
|
||||
|
||||
# trie would be much better
|
||||
@@ -106,7 +108,7 @@ print(f"{indent()}}}")
|
||||
|
||||
# ============================
|
||||
|
||||
print(f"{indent()}static void getBuildingSize({enum_name} type, BzTile *outWidth, BzTile *outHeight) {{")
|
||||
print(f"{indent()}static void getBuildingSize({enum_identifier} type, BzTile *outWidth, BzTile *outHeight) {{")
|
||||
indent_level += indent_offset
|
||||
print(f"{indent()} switch (type) {{")
|
||||
indent_level += indent_offset
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<tile id="11" type="orchard"/>
|
||||
<tile id="12" type="animal_farm"/>
|
||||
<tile id="13" type="animal_farm"/>
|
||||
<tile id="31" type="player_red"/>
|
||||
<tile id="32" type="keep">
|
||||
<objectgroup draworder="index" id="2">
|
||||
<object id="1" x="0" y="0" width="16" height="16"/>
|
||||
@@ -67,6 +68,7 @@
|
||||
<tile id="43" type="orchard"/>
|
||||
<tile id="44" type="animal_farm"/>
|
||||
<tile id="45" type="animal_farm"/>
|
||||
<tile id="63" type="player_blue"/>
|
||||
<tile id="64" type="keep">
|
||||
<objectgroup draworder="index" id="2">
|
||||
<object id="1" x="0" y="0" width="16" height="16"/>
|
||||
|
||||
Reference in New Issue
Block a user