Просмотр исходного кода

switch to SpriteID enum and lower filename size

jblanked 9 месяцев назад
Родитель
Сommit
1d877f8805
2 измененных файлов с 31 добавлено и 19 удалено
  1. 16 16
      game/player.c
  2. 15 3
      game/player.h

+ 16 - 16
game/player.c

@@ -599,7 +599,7 @@ const EntityDescription player_desc = {
     .context_size = sizeof(PlayerContext), // size of entity context, will be automatically allocated and freed
     .context_size = sizeof(PlayerContext), // size of entity context, will be automatically allocated and freed
 };
 };
 
 
-static SpriteContext *sprite_generic_alloc(const char *id, const char *type, uint8_t width, uint8_t height)
+static SpriteContext *sprite_generic_alloc(SpriteID id, const char *char_id, const char *type, uint8_t width, uint8_t height)
 {
 {
     SpriteContext *ctx = malloc(sizeof(SpriteContext));
     SpriteContext *ctx = malloc(sizeof(SpriteContext));
     if (!ctx)
     if (!ctx)
@@ -607,23 +607,23 @@ static SpriteContext *sprite_generic_alloc(const char *id, const char *type, uin
         FURI_LOG_E("Game", "Failed to allocate SpriteContext");
         FURI_LOG_E("Game", "Failed to allocate SpriteContext");
         return NULL;
         return NULL;
     }
     }
-    snprintf(ctx->id, sizeof(ctx->id), "%s", id);
+    ctx->id = id;
     ctx->width = width;
     ctx->width = width;
     ctx->height = height;
     ctx->height = height;
     if (is_str(type, "player"))
     if (is_str(type, "player"))
     {
     {
-        snprintf(ctx->right_file_name, sizeof(ctx->right_file_name), "player_right_%s_%dx%dpx.fxbm", id, width, height);
-        snprintf(ctx->left_file_name, sizeof(ctx->left_file_name), "player_left_%s_%dx%dpx.fxbm", id, width, height);
+        snprintf(ctx->right_file_name, sizeof(ctx->right_file_name), "player_right_%s_%dx%dpx.fxbm", char_id, width, height);
+        snprintf(ctx->left_file_name, sizeof(ctx->left_file_name), "player_left_%s_%dx%dpx.fxbm", char_id, width, height);
     }
     }
     else if (is_str(type, "enemy"))
     else if (is_str(type, "enemy"))
     {
     {
-        snprintf(ctx->right_file_name, sizeof(ctx->right_file_name), "enemy_right_%s_%dx%dpx.fxbm", id, width, height);
-        snprintf(ctx->left_file_name, sizeof(ctx->left_file_name), "enemy_left_%s_%dx%dpx.fxbm", id, width, height);
+        snprintf(ctx->right_file_name, sizeof(ctx->right_file_name), "enemy_right_%s_%dx%dpx.fxbm", char_id, width, height);
+        snprintf(ctx->left_file_name, sizeof(ctx->left_file_name), "enemy_left_%s_%dx%dpx.fxbm", char_id, width, height);
     }
     }
     else if (is_str(type, "npc"))
     else if (is_str(type, "npc"))
     {
     {
-        snprintf(ctx->right_file_name, sizeof(ctx->right_file_name), "npc_right_%s_%dx%dpx.fxbm", id, width, height);
-        snprintf(ctx->left_file_name, sizeof(ctx->left_file_name), "npc_left_%s_%dx%dpx.fxbm", id, width, height);
+        snprintf(ctx->right_file_name, sizeof(ctx->right_file_name), "npc_right_%s_%dx%dpx.fxbm", char_id, width, height);
+        snprintf(ctx->left_file_name, sizeof(ctx->left_file_name), "npc_left_%s_%dx%dpx.fxbm", char_id, width, height);
     }
     }
     return ctx;
     return ctx;
 }
 }
@@ -631,23 +631,23 @@ static SpriteContext *sprite_generic_alloc(const char *id, const char *type, uin
 SpriteContext *get_sprite_context(const char *name)
 SpriteContext *get_sprite_context(const char *name)
 {
 {
     if (is_str(name, "axe"))
     if (is_str(name, "axe"))
-        return sprite_generic_alloc("axe", "player", 15, 11);
+        return sprite_generic_alloc(SPRITE_ID_AXE, "axe", "player", 15, 11);
     else if (is_str(name, "bow"))
     else if (is_str(name, "bow"))
-        return sprite_generic_alloc("bow", "player", 13, 11);
+        return sprite_generic_alloc(SPRITE_ID_BOW, "bow", "player", 13, 11);
     else if (is_str(name, "naked"))
     else if (is_str(name, "naked"))
-        return sprite_generic_alloc("naked", "player", 10, 10);
+        return sprite_generic_alloc(SPRITE_ID_NAKED, "naked", "player", 10, 10);
     else if (is_str(name, "sword"))
     else if (is_str(name, "sword"))
-        return sprite_generic_alloc("sword", "player", 15, 11);
+        return sprite_generic_alloc(SPRITE_ID_SWORD, "sword", "player", 15, 11);
     //
     //
     else if (is_str(name, "cyclops"))
     else if (is_str(name, "cyclops"))
-        return sprite_generic_alloc("cyclops", "enemy", 10, 11);
+        return sprite_generic_alloc(SPRITE_ID_CYCLOPS, "cyclops", "enemy", 10, 11);
     else if (is_str(name, "ghost"))
     else if (is_str(name, "ghost"))
-        return sprite_generic_alloc("ghost", "enemy", 15, 15);
+        return sprite_generic_alloc(SPRITE_ID_GHOST, "ghost", "enemy", 15, 15);
     else if (is_str(name, "ogre"))
     else if (is_str(name, "ogre"))
-        return sprite_generic_alloc("ogre", "enemy", 10, 13);
+        return sprite_generic_alloc(SPRITE_ID_OGRE, "ogre", "enemy", 10, 13);
     //
     //
     else if (is_str(name, "funny"))
     else if (is_str(name, "funny"))
-        return sprite_generic_alloc("funny", "npc", 15, 21);
+        return sprite_generic_alloc(SPRITE_ID_FUNNY, "funny", "npc", 15, 21);
 
 
     // If no match is found
     // If no match is found
     FURI_LOG_E("Game", "Sprite not found: %s", name);
     FURI_LOG_E("Game", "Sprite not found: %s", name);

+ 15 - 3
game/player.h

@@ -109,11 +109,23 @@ typedef struct
     FlipperHTTP *fhttp;
     FlipperHTTP *fhttp;
 } GameContext;
 } GameContext;
 
 
+typedef enum
+{
+    SPRITE_ID_AXE,
+    SPRITE_ID_BOW,
+    SPRITE_ID_NAKED,
+    SPRITE_ID_SWORD,
+    SPRITE_ID_CYCLOPS,
+    SPRITE_ID_GHOST,
+    SPRITE_ID_OGRE,
+    SPRITE_ID_FUNNY
+} SpriteID;
+
 typedef struct
 typedef struct
 {
 {
-    char id[16];
-    char left_file_name[64];
-    char right_file_name[64];
+    SpriteID id;
+    char left_file_name[33];
+    char right_file_name[33];
     uint8_t width;
     uint8_t width;
     uint8_t height;
     uint8_t height;
 } SpriteContext;
 } SpriteContext;