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

Update icon context and JSON parsing

jblanked 1 год назад
Родитель
Сommit
fb22ab81fd
4 измененных файлов с 385 добавлено и 195 удалено
  1. 256 64
      game/icon.c
  2. 2 2
      game/icon.h
  3. 127 128
      game/world.c
  4. 0 1
      game/world.h

+ 256 - 64
game/icon.c

@@ -54,262 +54,454 @@ const EntityDescription icon_desc = {
     .context_size = sizeof(IconContext),
 };
 
-const Icon *get_icon(char *name)
+static IconContext _generic_icon = {
+    .icon = &I_icon_earth_15x16,
+    .width = 15,
+    .height = 16,
+};
+
+IconContext *get_icon_context(char *name)
 {
     if (strcmp(name, "earth") == 0)
     {
-        return &I_icon_earth_15x16;
+        _generic_icon.icon = &I_icon_earth_15x16;
+        _generic_icon.width = 15;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "home") == 0)
     {
-        return &I_icon_home_15x16;
+        _generic_icon.icon = &I_icon_home_15x16;
+        _generic_icon.width = 15;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "house") == 0)
     {
-        return &I_icon_house_48x32px;
+        _generic_icon.icon = &I_icon_house_48x32px;
+        _generic_icon.width = 48;
+        _generic_icon.height = 32;
+        return &_generic_icon;
     }
     if (strcmp(name, "house_3d") == 0)
     {
-        return &I_icon_house_3d_34x45px;
+        _generic_icon.icon = &I_icon_house_3d_34x45px;
+        _generic_icon.width = 34;
+        _generic_icon.height = 45;
+        return &_generic_icon;
     }
     if (strcmp(name, "info") == 0)
     {
-        return &I_icon_info_15x16;
+        _generic_icon.icon = &I_icon_info_15x16;
+        _generic_icon.width = 15;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "man") == 0)
     {
-        return &I_icon_man_7x16;
+        _generic_icon.icon = &I_icon_man_7x16;
+        _generic_icon.width = 7;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "plant") == 0)
     {
-        return &I_icon_plant_16x16;
+        _generic_icon.icon = &I_icon_plant_16x16;
+        _generic_icon.width = 16;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "plant_fern") == 0)
     {
-        return &I_icon_plant_fern_18x16px;
+        _generic_icon.icon = &I_icon_plant_fern_18x16px;
+        _generic_icon.width = 18;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "plant_pointy") == 0)
     {
-        return &I_icon_plant_pointy_13x16px;
+        _generic_icon.icon = &I_icon_plant_pointy_13x16px;
+        _generic_icon.width = 13;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "tree") == 0)
     {
-        return &I_icon_tree_16x16;
+        _generic_icon.icon = &I_icon_tree_16x16;
+        _generic_icon.width = 16;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "tree_29x30") == 0)
     {
-        return &I_icon_tree_29x30px;
+        _generic_icon.icon = &I_icon_tree_29x30px;
+        _generic_icon.width = 29;
+        _generic_icon.height = 30;
+        return &_generic_icon;
     }
     if (strcmp(name, "tree_48x48") == 0)
     {
-        return &I_icon_tree_48x48px;
+        _generic_icon.icon = &I_icon_tree_48x48px;
+        _generic_icon.width = 48;
+        _generic_icon.height = 48;
+        return &_generic_icon;
     }
     if (strcmp(name, "woman") == 0)
     {
-        return &I_icon_woman_9x16;
+        _generic_icon.icon = &I_icon_woman_9x16;
+        _generic_icon.width = 9;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "chest_closed") == 0)
     {
-        return &I_icon_chest_closed_16x13px;
+        _generic_icon.icon = &I_icon_chest_closed_16x13px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 13;
+        return &_generic_icon;
     }
     if (strcmp(name, "chest_open") == 0)
     {
-        return &I_icon_chest_open_16x16px;
+        _generic_icon.icon = &I_icon_chest_open_16x16px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "fence") == 0)
     {
-        return &I_icon_fence_16x8px;
+        _generic_icon.icon = &I_icon_fence_16x8px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 8;
+        return &_generic_icon;
     }
     if (strcmp(name, "fence_end") == 0)
     {
-        return &I_icon_fence_end_16x8px;
+        _generic_icon.icon = &I_icon_fence_end_16x8px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 8;
+        return &_generic_icon;
     }
     if (strcmp(name, "fence_vertical_end") == 0)
     {
-        return &I_icon_fence_vertical_end_6x8px;
+        _generic_icon.icon = &I_icon_fence_vertical_end_6x8px;
+        _generic_icon.width = 6;
+        _generic_icon.height = 8;
+        return &_generic_icon;
     }
     if (strcmp(name, "fence_vertical_start") == 0)
     {
-        return &I_icon_fence_vertical_start_6x15px;
+        _generic_icon.icon = &I_icon_fence_vertical_start_6x15px;
+        _generic_icon.width = 6;
+        _generic_icon.height = 15;
+        return &_generic_icon;
     }
     if (strcmp(name, "flower") == 0)
     {
-        return &I_icon_flower_16x16;
+        _generic_icon.icon = &I_icon_flower_16x16;
+        _generic_icon.width = 16;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (strcmp(name, "lake_bottom") == 0)
     {
-        return &I_icon_lake_bottom_31x12px;
+        _generic_icon.icon = &I_icon_lake_bottom_31x12px;
+        _generic_icon.width = 31;
+        _generic_icon.height = 12;
+        return &_generic_icon;
     }
     if (strcmp(name, "lake_bottom_left") == 0)
     {
-        return &I_icon_lake_bottom_left_24x22px;
+        _generic_icon.icon = &I_icon_lake_bottom_left_24x22px;
+        _generic_icon.width = 24;
+        _generic_icon.height = 22;
+        return &_generic_icon;
     }
     if (strcmp(name, "lake_bottom_right") == 0)
     {
-        return &I_icon_lake_bottom_right_24x22px;
+        _generic_icon.icon = &I_icon_lake_bottom_right_24x22px;
+        _generic_icon.width = 24;
+        _generic_icon.height = 22;
+        return &_generic_icon;
     }
     if (strcmp(name, "lake_left") == 0)
     {
-        return &I_icon_lake_left_11x31px;
+        _generic_icon.icon = &I_icon_lake_left_11x31px;
+        _generic_icon.width = 11;
+        _generic_icon.height = 31;
+        return &_generic_icon;
     }
     if (strcmp(name, "lake_right") == 0)
     {
-        return &I_icon_lake_right_11x31;
+        _generic_icon.icon = &I_icon_lake_right_11x31; // Assuming it's 11x31
+        _generic_icon.width = 11;
+        _generic_icon.height = 31;
+        return &_generic_icon;
     }
     if (strcmp(name, "lake_top") == 0)
     {
-        return &I_icon_lake_top_31x12px;
+        _generic_icon.icon = &I_icon_lake_top_31x12px;
+        _generic_icon.width = 31;
+        _generic_icon.height = 12;
+        return &_generic_icon;
     }
     if (strcmp(name, "lake_top_left") == 0)
     {
-        return &I_icon_lake_top_left_24x22px;
+        _generic_icon.icon = &I_icon_lake_top_left_24x22px;
+        _generic_icon.width = 24;
+        _generic_icon.height = 22;
+        return &_generic_icon;
     }
     if (strcmp(name, "lake_top_right") == 0)
     {
-        return &I_icon_lake_top_right_24x22px;
+        _generic_icon.icon = &I_icon_lake_top_right_24x22px;
+        _generic_icon.width = 24;
+        _generic_icon.height = 22;
+        return &_generic_icon;
     }
     if (strcmp(name, "rock_large") == 0)
     {
-        return &I_icon_rock_large_18x19px;
+        _generic_icon.icon = &I_icon_rock_large_18x19px;
+        _generic_icon.width = 18;
+        _generic_icon.height = 19;
+        return &_generic_icon;
     }
     if (strcmp(name, "rock_medium") == 0)
     {
-        return &I_icon_rock_medium_16x14px;
+        _generic_icon.icon = &I_icon_rock_medium_16x14px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 14;
+        return &_generic_icon;
     }
     if (strcmp(name, "rock_small") == 0)
     {
-        return &I_icon_rock_small_10x8px;
+        _generic_icon.icon = &I_icon_rock_small_10x8px;
+        _generic_icon.width = 10;
+        _generic_icon.height = 8;
+        return &_generic_icon;
     }
 
     // If no match is found
     return NULL;
 }
 
-const Icon *get_icon_furi(FuriString *name)
+IconContext *get_icon_context_furi(FuriString *name)
 {
     if (furi_string_cmp(name, "earth") == 0)
     {
-        return &I_icon_earth_15x16;
+        _generic_icon.icon = &I_icon_earth_15x16;
+        _generic_icon.width = 15;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "home") == 0)
     {
-        return &I_icon_home_15x16;
+        _generic_icon.icon = &I_icon_home_15x16;
+        _generic_icon.width = 15;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "house") == 0)
     {
-        return &I_icon_house_48x32px;
+        _generic_icon.icon = &I_icon_house_48x32px;
+        _generic_icon.width = 48;
+        _generic_icon.height = 32;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "house_3d") == 0)
     {
-        return &I_icon_house_3d_34x45px;
+        _generic_icon.icon = &I_icon_house_3d_34x45px;
+        _generic_icon.width = 34;
+        _generic_icon.height = 45;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "info") == 0)
     {
-        return &I_icon_info_15x16;
+        _generic_icon.icon = &I_icon_info_15x16;
+        _generic_icon.width = 15;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "man") == 0)
     {
-        return &I_icon_man_7x16;
+        _generic_icon.icon = &I_icon_man_7x16;
+        _generic_icon.width = 7;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "plant") == 0)
     {
-        return &I_icon_plant_16x16;
+        _generic_icon.icon = &I_icon_plant_16x16;
+        _generic_icon.width = 16;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "plant_fern") == 0)
     {
-        return &I_icon_plant_fern_18x16px;
+        _generic_icon.icon = &I_icon_plant_fern_18x16px;
+        _generic_icon.width = 18;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "plant_pointy") == 0)
     {
-        return &I_icon_plant_pointy_13x16px;
+        _generic_icon.icon = &I_icon_plant_pointy_13x16px;
+        _generic_icon.width = 13;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "tree") == 0)
     {
-        return &I_icon_tree_16x16;
+        _generic_icon.icon = &I_icon_tree_16x16;
+        _generic_icon.width = 16;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "tree_29x30") == 0)
     {
-        return &I_icon_tree_29x30px;
+        _generic_icon.icon = &I_icon_tree_29x30px;
+        _generic_icon.width = 29;
+        _generic_icon.height = 30;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "tree_48x48") == 0)
     {
-        return &I_icon_tree_48x48px;
+        _generic_icon.icon = &I_icon_tree_48x48px;
+        _generic_icon.width = 48;
+        _generic_icon.height = 48;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "woman") == 0)
     {
-        return &I_icon_woman_9x16;
+        _generic_icon.icon = &I_icon_woman_9x16;
+        _generic_icon.width = 9;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "chest_closed") == 0)
     {
-        return &I_icon_chest_closed_16x13px;
+        _generic_icon.icon = &I_icon_chest_closed_16x13px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 13;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "chest_open") == 0)
     {
-        return &I_icon_chest_open_16x16px;
+        _generic_icon.icon = &I_icon_chest_open_16x16px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "fence") == 0)
     {
-        return &I_icon_fence_16x8px;
+        _generic_icon.icon = &I_icon_fence_16x8px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 8;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "fence_end") == 0)
     {
-        return &I_icon_fence_end_16x8px;
+        _generic_icon.icon = &I_icon_fence_end_16x8px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 8;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "fence_vertical_end") == 0)
     {
-        return &I_icon_fence_vertical_end_6x8px;
+        _generic_icon.icon = &I_icon_fence_vertical_end_6x8px;
+        _generic_icon.width = 6;
+        _generic_icon.height = 8;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "fence_vertical_start") == 0)
     {
-        return &I_icon_fence_vertical_start_6x15px;
+        _generic_icon.icon = &I_icon_fence_vertical_start_6x15px;
+        _generic_icon.width = 6;
+        _generic_icon.height = 15;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "flower") == 0)
     {
-        return &I_icon_flower_16x16;
+        _generic_icon.icon = &I_icon_flower_16x16;
+        _generic_icon.width = 16;
+        _generic_icon.height = 16;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "lake_bottom") == 0)
     {
-        return &I_icon_lake_bottom_31x12px;
+        _generic_icon.icon = &I_icon_lake_bottom_31x12px;
+        _generic_icon.width = 31;
+        _generic_icon.height = 12;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "lake_bottom_left") == 0)
     {
-        return &I_icon_lake_bottom_left_24x22px;
+        _generic_icon.icon = &I_icon_lake_bottom_left_24x22px;
+        _generic_icon.width = 24;
+        _generic_icon.height = 22;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "lake_bottom_right") == 0)
     {
-        return &I_icon_lake_bottom_right_24x22px;
+        _generic_icon.icon = &I_icon_lake_bottom_right_24x22px;
+        _generic_icon.width = 24;
+        _generic_icon.height = 22;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "lake_left") == 0)
     {
-        return &I_icon_lake_left_11x31px;
+        _generic_icon.icon = &I_icon_lake_left_11x31px;
+        _generic_icon.width = 11;
+        _generic_icon.height = 31;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "lake_right") == 0)
     {
-        return &I_icon_lake_right_11x31;
+        _generic_icon.icon = &I_icon_lake_right_11x31; // Assuming dimensions
+        _generic_icon.width = 11;
+        _generic_icon.height = 31;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "lake_top") == 0)
     {
-        return &I_icon_lake_top_31x12px;
+        _generic_icon.icon = &I_icon_lake_top_31x12px;
+        _generic_icon.width = 31;
+        _generic_icon.height = 12;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "lake_top_left") == 0)
     {
-        return &I_icon_lake_top_left_24x22px;
+        _generic_icon.icon = &I_icon_lake_top_left_24x22px;
+        _generic_icon.width = 24;
+        _generic_icon.height = 22;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "lake_top_right") == 0)
     {
-        return &I_icon_lake_top_right_24x22px;
+        _generic_icon.icon = &I_icon_lake_top_right_24x22px;
+        _generic_icon.width = 24;
+        _generic_icon.height = 22;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "rock_large") == 0)
     {
-        return &I_icon_rock_large_18x19px;
+        _generic_icon.icon = &I_icon_rock_large_18x19px;
+        _generic_icon.width = 18;
+        _generic_icon.height = 19;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "rock_medium") == 0)
     {
-        return &I_icon_rock_medium_16x14px;
+        _generic_icon.icon = &I_icon_rock_medium_16x14px;
+        _generic_icon.width = 16;
+        _generic_icon.height = 14;
+        return &_generic_icon;
     }
     if (furi_string_cmp(name, "rock_small") == 0)
     {
-        return &I_icon_rock_small_10x8px;
+        _generic_icon.icon = &I_icon_rock_small_10x8px;
+        _generic_icon.width = 10;
+        _generic_icon.height = 8;
+        return &_generic_icon;
     }
 
     // If no match is found

+ 2 - 2
game/icon.h

@@ -12,5 +12,5 @@ typedef struct
 } IconContext;
 
 extern const EntityDescription icon_desc;
-const Icon *get_icon(char *name);
-const Icon *get_icon_furi(FuriString *name);
+IconContext *get_icon_context(char *name);
+IconContext *get_icon_context_furi(FuriString *name);

+ 127 - 128
game/world.c

@@ -19,19 +19,28 @@ bool draw_json_world(Level *level, const char *json_data)
         char *icon = get_json_value("icon", data);
         char *x = get_json_value("x", data);
         char *y = get_json_value("y", data);
-        char *width = get_json_value("width", data);
-        char *height = get_json_value("height", data);
         char *amount = get_json_value("amount", data);
         char *horizontal = get_json_value("horizontal", data);
-        if (icon == NULL || x == NULL || y == NULL || width == NULL || height == NULL || amount == NULL || horizontal == NULL)
+        if (icon == NULL || x == NULL || y == NULL || amount == NULL || horizontal == NULL)
         {
             FURI_LOG_E("Failed Data: ", data);
             free(data);
             free(icon);
             free(x);
             free(y);
-            free(width);
-            free(height);
+            free(amount);
+            free(horizontal);
+            level_clear(level);
+            return false;
+        }
+        IconContext *icon_context = get_icon_context(icon);
+        if (icon_context == NULL)
+        {
+            FURI_LOG_E("Failed Icon: ", icon);
+            free(data);
+            free(icon);
+            free(x);
+            free(y);
             free(amount);
             free(horizontal);
             level_clear(level);
@@ -40,26 +49,24 @@ bool draw_json_world(Level *level, const char *json_data)
         // if amount is less than 2, we spawn a single icon
         if (atoi(amount) < 2)
         {
-            spawn_icon(level, get_icon(icon), atoi(x), atoi(y), atoi(width), atoi(height));
+            spawn_icon(level, icon_context->icon, atoi(x), atoi(y), icon_context->width, icon_context->height);
             free(data);
             free(icon);
             free(x);
             free(y);
-            free(width);
-            free(height);
             free(amount);
             free(horizontal);
+            free(icon_context);
             continue;
         }
-        spawn_icon_line(level, get_icon(icon), atoi(x), atoi(y), atoi(width), atoi(height), atoi(amount), strcmp(horizontal, "true") == 0);
+        spawn_icon_line(level, icon_context->icon, atoi(x), atoi(y), icon_context->width, icon_context->height, atoi(amount), strcmp(horizontal, "true") == 0);
         free(data);
         free(icon);
         free(x);
         free(y);
-        free(width);
-        free(height);
         free(amount);
         free(horizontal);
+        free(icon_context);
     }
     return true;
 }
@@ -75,244 +82,236 @@ bool draw_json_world_furi(Level *level, FuriString *json_data)
         FuriString *icon = get_json_value_furi("icon", data);
         FuriString *x = get_json_value_furi("x", data);
         FuriString *y = get_json_value_furi("y", data);
-        FuriString *width = get_json_value_furi("width", data);
-        FuriString *height = get_json_value_furi("height", data);
         FuriString *amount = get_json_value_furi("amount", data);
         FuriString *horizontal = get_json_value_furi("horizontal", data);
-        if (!icon || !x || !y || !width || !height || !amount || !horizontal)
+        if (!icon || !x || !y || !amount || !horizontal)
         {
             FURI_LOG_E("Failed Data: ", furi_string_get_cstr(data));
             furi_string_free(data);
             furi_string_free(icon);
             furi_string_free(x);
             furi_string_free(y);
-            furi_string_free(width);
-            furi_string_free(height);
             furi_string_free(amount);
             furi_string_free(horizontal);
             level_clear(level);
             return false;
         }
+        IconContext *icon_context = get_icon_context_furi(icon);
+        if (icon_context == NULL)
+        {
+            FURI_LOG_E("Failed Icon: ", furi_string_get_cstr(icon));
+            furi_string_free(data);
+            furi_string_free(icon);
+            furi_string_free(x);
+            furi_string_free(y);
+            furi_string_free(amount);
+            furi_string_free(horizontal);
+            level_clear(level);
+            free(icon_context);
+            return false;
+        }
         // if amount is less than 2, we spawn a single icon
         if (atoi(furi_string_get_cstr(amount)) < 2)
         {
             spawn_icon(
                 level,
-                get_icon_furi(icon),
+                icon_context->icon,
                 atoi(furi_string_get_cstr(x)),
                 atoi(furi_string_get_cstr(y)),
-                atoi(furi_string_get_cstr(width)),
-                atoi(furi_string_get_cstr(height)));
+                icon_context->width,
+                icon_context->height);
             furi_string_free(data);
             furi_string_free(icon);
             furi_string_free(x);
             furi_string_free(y);
-            furi_string_free(width);
-            furi_string_free(height);
             furi_string_free(amount);
             furi_string_free(horizontal);
+            free(icon_context);
             continue;
         }
         spawn_icon_line(
             level,
-            get_icon_furi(icon),
+            icon_context->icon,
             atoi(furi_string_get_cstr(x)),
             atoi(furi_string_get_cstr(y)),
-            atoi(furi_string_get_cstr(width)),
-            atoi(furi_string_get_cstr(height)),
+            icon_context->width,
+            icon_context->height,
             atoi(furi_string_get_cstr(amount)),
             furi_string_cmp(horizontal, "true") == 0);
         furi_string_free(data);
         furi_string_free(icon);
         furi_string_free(x);
         furi_string_free(y);
-        furi_string_free(width);
-        furi_string_free(height);
         furi_string_free(amount);
         furi_string_free(horizontal);
+        free(icon_context);
     }
     return true;
 }
 
-void draw_example_world(Level *level)
-{
-    spawn_icon(level, get_icon("earth"), 112, 56, 15, 16);
-    spawn_icon(level, get_icon("home"), 128, 24, 15, 16);
-    spawn_icon(level, get_icon("info"), 144, 24, 15, 16);
-    spawn_icon(level, get_icon("man"), 160, 56, 7, 16);
-    spawn_icon(level, get_icon("woman"), 168, 56, 9, 16);
-    spawn_icon(level, get_icon("plant"), 168, 32, 16, 16);
-}
-
 void draw_tree_world(Level *level)
 {
+    IconContext *tree_icon = get_icon_context("tree");
+    if (!tree_icon)
+    {
+        FURI_LOG_E("Game", "Failed to get tree icon context");
+        return;
+    }
     // Spawn two full left/up tree lines
     for (int i = 0; i < 2; i++)
     {
         // Horizontal line of 22 icons
-        spawn_icon_line(level, get_icon("tree"), 5, 2 + i * 17, 16, 16, 22, true);
+        spawn_icon_line(level, tree_icon->icon, 5, 2 + i * 17, tree_icon->width, tree_icon->height, 22, true);
         // Vertical line of 11 icons
-        spawn_icon_line(level, get_icon("tree"), 5 + i * 17, 2, 16, 16, 11, false);
+        spawn_icon_line(level, tree_icon->icon, 5 + i * 17, 2, tree_icon->width, tree_icon->height, 11, false);
     }
 
     // Spawn two full down tree lines
     for (int i = 9; i < 11; i++)
     {
         // Horizontal line of 22 icons
-        spawn_icon_line(level, get_icon("tree"), 5, 2 + i * 17, 16, 16, 22, true);
+        spawn_icon_line(level, tree_icon->icon, 5, 2 + i * 17, tree_icon->width, tree_icon->height, 22, true);
     }
 
     // Spawn two full right tree lines
     for (int i = 20; i < 22; i++)
     {
         // Vertical line of 8 icons starting further down (y=50)
-        spawn_icon_line(level, get_icon("tree"), 5 + i * 17, 50, 16, 16, 8, false);
+        spawn_icon_line(level, tree_icon->icon, 5 + i * 17, 50, tree_icon->width, tree_icon->height, 8, false);
     }
 
     // Labyrinth lines
     // Third line (14 left, then a gap, then 3 middle)
-    spawn_icon_line(level, get_icon("tree"), 5, 2 + 2 * 17, 16, 16, 14, true);
-    spawn_icon_line(level, get_icon("tree"), 5 + 16 * 17, 2 + 2 * 17, 16, 16, 3, true);
+    spawn_icon_line(level, tree_icon->icon, 5, 2 + 2 * 17, tree_icon->width, tree_icon->height, 14, true);
+    spawn_icon_line(level, tree_icon->icon, 5 + 16 * 17, 2 + 2 * 17, tree_icon->width, tree_icon->height, 3, true);
 
     // Fourth line (3 left, 6 middle, 4 right)
-    spawn_icon_line(level, get_icon("tree"), 5, 2 + 3 * 17, 16, 16, 3, true);           // 3 left
-    spawn_icon_line(level, get_icon("tree"), 5 + 7 * 17, 2 + 3 * 17, 16, 16, 6, true);  // 6 middle
-    spawn_icon_line(level, get_icon("tree"), 5 + 15 * 17, 2 + 3 * 17, 16, 16, 4, true); // 4 right
+    spawn_icon_line(level, tree_icon->icon, 5, 2 + 3 * 17, tree_icon->width, tree_icon->height, 3, true);           // 3 left
+    spawn_icon_line(level, tree_icon->icon, 5 + 7 * 17, 2 + 3 * 17, tree_icon->width, tree_icon->height, 6, true);  // 6 middle
+    spawn_icon_line(level, tree_icon->icon, 5 + 15 * 17, 2 + 3 * 17, tree_icon->width, tree_icon->height, 4, true); // 4 right
 
     // Fifth line (6 left, 7 middle)
-    spawn_icon_line(level, get_icon("tree"), 5, 2 + 4 * 17, 16, 16, 6, true);
-    spawn_icon_line(level, get_icon("tree"), 5 + 7 * 17, 2 + 4 * 17, 16, 16, 7, true);
+    spawn_icon_line(level, tree_icon->icon, 5, 2 + 4 * 17, tree_icon->width, tree_icon->height, 6, true);
+    spawn_icon_line(level, tree_icon->icon, 5 + 7 * 17, 2 + 4 * 17, tree_icon->width, tree_icon->height, 7, true);
 
     // Sixth line (5 left, 3 middle, 7 right)
-    spawn_icon_line(level, get_icon("tree"), 5, 2 + 5 * 17, 16, 16, 5, true);           // 5 left
-    spawn_icon_line(level, get_icon("tree"), 5 + 7 * 17, 2 + 5 * 17, 16, 16, 3, true);  // 3 middle
-    spawn_icon_line(level, get_icon("tree"), 5 + 15 * 17, 2 + 5 * 17, 16, 16, 7, true); // 7 right
+    spawn_icon_line(level, tree_icon->icon, 5, 2 + 5 * 17, tree_icon->width, tree_icon->height, 5, true);           // 5 left
+    spawn_icon_line(level, tree_icon->icon, 5 + 7 * 17, 2 + 5 * 17, tree_icon->width, tree_icon->height, 3, true);  // 3 middle
+    spawn_icon_line(level, tree_icon->icon, 5 + 15 * 17, 2 + 5 * 17, tree_icon->width, tree_icon->height, 7, true); // 7 right
 
     // Seventh line (0 left, 7 middle, 4 right)
-    spawn_icon_line(level, get_icon("tree"), 5 + 6 * 17, 2 + 6 * 17, 16, 16, 7, true);  // 7 middle
-    spawn_icon_line(level, get_icon("tree"), 5 + 14 * 17, 2 + 6 * 17, 16, 16, 4, true); // 4 right
+    spawn_icon_line(level, tree_icon->icon, 5 + 6 * 17, 2 + 6 * 17, tree_icon->width, tree_icon->height, 7, true);  // 7 middle
+    spawn_icon_line(level, tree_icon->icon, 5 + 14 * 17, 2 + 6 * 17, tree_icon->width, tree_icon->height, 4, true); // 4 right
 
     // Eighth line (4 left, 3 middle, 4 right)
-    spawn_icon_line(level, get_icon("tree"), 5, 2 + 7 * 17, 16, 16, 4, true);           // 4 left
-    spawn_icon_line(level, get_icon("tree"), 5 + 7 * 17, 2 + 7 * 17, 16, 16, 3, true);  // 3 middle
-    spawn_icon_line(level, get_icon("tree"), 5 + 15 * 17, 2 + 7 * 17, 16, 16, 4, true); // 4 right
+    spawn_icon_line(level, tree_icon->icon, 5, 2 + 7 * 17, tree_icon->width, tree_icon->height, 4, true);           // 4 left
+    spawn_icon_line(level, tree_icon->icon, 5 + 7 * 17, 2 + 7 * 17, tree_icon->width, tree_icon->height, 3, true);  // 3 middle
+    spawn_icon_line(level, tree_icon->icon, 5 + 15 * 17, 2 + 7 * 17, tree_icon->width, tree_icon->height, 4, true); // 4 right
 
     // Ninth line (3 left, 1 middle, 3 right)
-    spawn_icon_line(level, get_icon("tree"), 5, 2 + 8 * 17, 16, 16, 3, true);           // 3 left
-    spawn_icon_line(level, get_icon("tree"), 5 + 5 * 17, 2 + 8 * 17, 16, 16, 1, true);  // 1 middle
-    spawn_icon_line(level, get_icon("tree"), 5 + 11 * 17, 2 + 8 * 17, 16, 16, 3, true); // 3 right
+    spawn_icon_line(level, tree_icon->icon, 5, 2 + 8 * 17, tree_icon->width, tree_icon->height, 3, true);           // 3 left
+    spawn_icon_line(level, tree_icon->icon, 5 + 5 * 17, 2 + 8 * 17, tree_icon->width, tree_icon->height, 1, true);  // 1 middle
+    spawn_icon_line(level, tree_icon->icon, 5 + 11 * 17, 2 + 8 * 17, tree_icon->width, tree_icon->height, 3, true); // 3 right
+
+    free(tree_icon);
 }
 
 void draw_town_world(Level *level)
 {
+    // define all the icons
+    IconContext *house_icon = get_icon_context("house");
+    IconContext *fence_icon = get_icon_context("fence");
+    IconContext *fence_end_icon = get_icon_context("fence_end");
+    IconContext *plant_icon = get_icon_context("plant");
+    IconContext *flower_icon = get_icon_context("flower");
+    IconContext *man_icon = get_icon_context("man");
+    IconContext *woman_icon = get_icon_context("woman");
+    IconContext *lake_top_left_icon = get_icon_context("lake_top_left");
+    IconContext *lake_top_icon = get_icon_context("lake_top");
+    IconContext *lake_top_right_icon = get_icon_context("lake_top_right");
+    IconContext *lake_left_icon = get_icon_context("lake_left");
+    IconContext *lake_right_icon = get_icon_context("lake_right");
+    IconContext *lake_bottom_left_icon = get_icon_context("lake_bottom_left");
+    IconContext *lake_bottom_icon = get_icon_context("lake_bottom");
+    IconContext *lake_bottom_right_icon = get_icon_context("lake_bottom_right");
+    IconContext *tree_icon = get_icon_context("tree");
+
+    // check if any of the icons are NULL
+    if (!house_icon || !fence_icon || !fence_end_icon || !plant_icon || !flower_icon ||
+        !man_icon || !woman_icon || !lake_top_left_icon || !lake_top_icon || !lake_top_right_icon ||
+        !lake_left_icon || !lake_right_icon || !lake_bottom_left_icon || !lake_bottom_icon || !lake_bottom_right_icon || !tree_icon)
+    {
+        FURI_LOG_E("Game", "Failed to get icon context");
+        return;
+    }
+
     // house-fence group 1
-    spawn_icon(level, get_icon("house"), 148, 36, 48, 32);
-    spawn_icon(level, get_icon("fence"), 148, 72, 16, 8);
-    spawn_icon(level, get_icon("fence"), 164, 72, 16, 8);
-    spawn_icon(level, get_icon("fence_end"), 180, 72, 16, 8);
+    spawn_icon(level, house_icon->icon, 148, 36, house_icon->width, house_icon->height);
+    spawn_icon(level, fence_icon->icon, 148, 72, fence_icon->width, fence_icon->height);
+    spawn_icon(level, fence_icon->icon, 164, 72, fence_icon->width, fence_icon->height);
+    spawn_icon(level, fence_end_icon->icon, 180, 72, fence_end_icon->width, fence_end_icon->height);
 
     // house-fence group 4 (the left of group 1)
-    spawn_icon(level, get_icon("house"), 96, 36, 48, 32);
-    spawn_icon(level, get_icon("fence"), 96, 72, 16, 8);
-    spawn_icon(level, get_icon("fence"), 110, 72, 16, 8);
-    spawn_icon(level, get_icon("fence_end"), 126, 72, 16, 8);
+    spawn_icon(level, house_icon->icon, 96, 36, house_icon->width, house_icon->height);
+    spawn_icon(level, fence_icon->icon, 96, 72, fence_icon->width, fence_icon->height);
+    spawn_icon(level, fence_icon->icon, 110, 72, fence_icon->width, fence_icon->height);
+    spawn_icon(level, fence_end_icon->icon, 126, 72, fence_end_icon->width, fence_end_icon->height);
 
     // house-fence group 5 (the left of group 4)
-    spawn_icon(level, get_icon("house"), 40, 36, 48, 32);
-    spawn_icon(level, get_icon("fence"), 40, 72, 16, 8);
-    spawn_icon(level, get_icon("fence"), 56, 72, 16, 8);
-    spawn_icon(level, get_icon("fence_end"), 72, 72, 16, 8);
+    spawn_icon(level, house_icon->icon, 40, 36, house_icon->width, house_icon->height);
+    spawn_icon(level, fence_icon->icon, 40, 72, fence_icon->width, fence_icon->height);
+    spawn_icon(level, fence_icon->icon, 56, 72, fence_icon->width, fence_icon->height);
+    spawn_icon(level, fence_end_icon->icon, 72, 72, fence_end_icon->width, fence_end_icon->height);
 
     // line of fences on the 8th row (using spawn_icon_line)
-    spawn_icon_line(level, get_icon("fence"), 8, 100, 16, 8, 10, true);
+    spawn_icon_line(level, fence_icon->icon, 8, 100, fence_icon->width, fence_icon->height, 10, true);
 
     // plants spaced out underneath the fences
-    spawn_icon_line(level, get_icon("plant"), 40, 110, 16, 16, 6, true);
-    spawn_icon_line(level, get_icon("flower"), 40, 140, 16, 16, 6, true);
+    spawn_icon_line(level, plant_icon->icon, 40, 110, plant_icon->width, plant_icon->height, 6, true);
+    spawn_icon_line(level, flower_icon->icon, 40, 140, flower_icon->width, flower_icon->height, 6, true);
 
     // man and woman
-    spawn_icon(level, get_icon("man"), 156, 110, 7, 16);
-    spawn_icon(level, get_icon("woman"), 164, 110, 9, 16);
+    spawn_icon(level, man_icon->icon, 156, 110, man_icon->width, man_icon->height);
+    spawn_icon(level, woman_icon->icon, 164, 110, woman_icon->width, woman_icon->height);
 
     // lake
     // Top row
-    spawn_icon(level, get_icon("lake_top_left"), 240, 52, 24, 22);
-    spawn_icon(level, get_icon("lake_top"), 264, 52, 31, 22);
-    spawn_icon(level, get_icon("lake_top_right"), 295, 52, 24, 22);
+    spawn_icon(level, lake_top_left_icon->icon, 240, 52, lake_top_left_icon->width, lake_top_left_icon->height);
+    spawn_icon(level, lake_top_icon->icon, 264, 52, lake_top_icon->width, lake_top_icon->height);
+    spawn_icon(level, lake_top_right_icon->icon, 295, 52, lake_top_right_icon->width, lake_top_right_icon->height);
 
     // Middle row
-    spawn_icon(level, get_icon("lake_left"), 231, 74, 11, 31);
-    spawn_icon(level, get_icon("lake_right"), 317, 74, 11, 31);
+    spawn_icon(level, lake_left_icon->icon, 231, 74, lake_left_icon->width, lake_left_icon->height);
+    spawn_icon(level, lake_right_icon->icon, 317, 74, lake_right_icon->width, lake_right_icon->height);
 
     // Bottom row
-    spawn_icon(level, get_icon("lake_bottom_left"), 240, 105, 24, 22);
-    spawn_icon(level, get_icon("lake_bottom"), 264, 124, 31, 12);
-    spawn_icon(level, get_icon("lake_bottom_right"), 295, 105, 24, 22);
+    spawn_icon(level, lake_bottom_left_icon->icon, 240, 105, lake_bottom_left_icon->width, lake_bottom_left_icon->height);
+    spawn_icon(level, lake_bottom_icon->icon, 264, 124, lake_bottom_icon->width, lake_bottom_icon->height);
+    spawn_icon(level, lake_bottom_right_icon->icon, 295, 105, lake_bottom_right_icon->width, lake_bottom_right_icon->height);
 
     // Spawn two full left/up tree lines
     for (int i = 0; i < 2; i++)
     {
         // Horizontal line of 22 icons
-        spawn_icon_line(level, get_icon("tree"), 5, 2 + i * 17, 16, 16, 22, true);
+        spawn_icon_line(level, tree_icon->icon, 5, 2 + i * 17, tree_icon->width, tree_icon->height, 22, true);
         // Vertical line of 11 icons
-        spawn_icon_line(level, get_icon("tree"), 5 + i * 17, 2, 16, 16, 11, false);
+        spawn_icon_line(level, tree_icon->icon, 5 + i * 17, 2, tree_icon->width, tree_icon->height, 11, false);
     }
 
     // Spawn two full down tree lines
     for (int i = 9; i < 11; i++)
     {
         // Horizontal line of 22 icons
-        spawn_icon_line(level, get_icon("tree"), 5, 2 + i * 17, 16, 16, 22, true);
+        spawn_icon_line(level, tree_icon->icon, 5, 2 + i * 17, tree_icon->width, tree_icon->height, 22, true);
     }
 
     // Spawn two full right tree lines
     for (int i = 20; i < 22; i++)
     {
         // Vertical line of 8 icons starting further down (y=50)
-        spawn_icon_line(level, get_icon("tree"), 5 + i * 17, 50, 16, 16, 8, false);
+        spawn_icon_line(level, tree_icon->icon, 5 + i * 17, 50, tree_icon->width, tree_icon->height, 8, false);
     }
 }
-/*
-{
-    "name": "town_world",
-    "author": "JBlanked",
-    "json_data": [
-        { "icon": "house",     "x": 148, "y": 36, "width": 48, "height": 32, "amount": 1, "horizontal": true },
-        { "icon": "fence",     "x": 148, "y": 72, "width": 16, "height": 8,  "amount": 1, "horizontal": true },
-        { "icon": "fence",     "x": 164, "y": 72, "width": 16, "height": 8,  "amount": 1, "horizontal": true },
-        { "icon": "fence_end", "x": 180, "y": 72, "width": 16, "height": 8,  "amount": 1, "horizontal": true },
-        { "icon": "house",     "x": 96,  "y": 36, "width": 48, "height": 32, "amount": 1, "horizontal": true },
-        { "icon": "fence",     "x": 96,  "y": 72, "width": 16, "height": 8,  "amount": 1, "horizontal": true },
-        { "icon": "fence",     "x": 110, "y": 72, "width": 16, "height": 8,  "amount": 1, "horizontal": true },
-        { "icon": "fence_end", "x": 126, "y": 72, "width": 16, "height": 8,  "amount": 1, "horizontal": true },
-        { "icon": "house",     "x": 40,  "y": 36, "width": 48, "height": 32, "amount": 1, "horizontal": true },
-        { "icon": "fence",     "x": 40,  "y": 72, "width": 16, "height": 8,  "amount": 1, "horizontal": true },
-        { "icon": "fence",     "x": 56,  "y": 72, "width": 16, "height": 8,  "amount": 1, "horizontal": true },
-        { "icon": "fence_end", "x": 72,  "y": 72, "width": 16, "height": 8,  "amount": 1, "horizontal": true },
-        { "icon": "fence",  "x": 8,  "y": 100, "width": 16, "height": 8,  "amount": 10, "horizontal": true },
-        { "icon": "plant",  "x": 40, "y": 110, "width": 16, "height": 16, "amount": 6, "horizontal": true },
-        { "icon": "flower", "x": 40, "y": 140, "width": 16, "height": 16, "amount": 6, "horizontal": true },
-        { "icon": "man",    "x": 156, "y": 110, "width": 7,  "height": 16, "amount": 1, "horizontal": true },
-        { "icon": "woman",  "x": 164, "y": 110, "width": 9,  "height": 16, "amount": 1, "horizontal": true },
-        { "icon": "lake_top_left",     "x": 240, "y": 52,  "width": 24, "height": 22, "amount": 1, "horizontal": true },
-        { "icon": "lake_top",          "x": 264, "y": 52,  "width": 31, "height": 22, "amount": 1, "horizontal": true },
-        { "icon": "lake_top_right",    "x": 295, "y": 52,  "width": 24, "height": 22, "amount": 1, "horizontal": true },
-        { "icon": "lake_left",         "x": 231, "y": 74,  "width": 11, "height": 31, "amount": 1, "horizontal": true },
-        { "icon": "lake_right",        "x": 317, "y": 74,  "width": 11, "height": 31, "amount": 1, "horizontal": true },
-        { "icon": "lake_bottom_left",  "x": 240, "y": 105, "width": 24, "height": 22, "amount": 1, "horizontal": true },
-        { "icon": "lake_bottom",       "x": 264, "y": 124, "width": 31, "height": 12, "amount": 1, "horizontal": true },
-        { "icon": "lake_bottom_right", "x": 295, "y": 105, "width": 24, "height": 22, "amount": 1, "horizontal": true },
-        { "icon": "tree", "x": 5,   "y": 2,   "width": 16, "height": 16, "amount": 22, "horizontal": true },
-        { "icon": "tree", "x": 5,   "y": 2,   "width": 16, "height": 16, "amount": 11, "horizontal": false },
-        { "icon": "tree", "x": 22,  "y": 2,   "width": 16, "height": 16, "amount": 22, "horizontal": true },
-        { "icon": "tree", "x": 22,  "y": 2,   "width": 16, "height": 16, "amount": 11, "horizontal": false },
-        { "icon": "tree", "x": 5,   "y": 155, "width": 16, "height": 16, "amount": 22, "horizontal": true },
-        { "icon": "tree", "x": 5,   "y": 172, "width": 16, "height": 16, "amount": 22, "horizontal": true },
-        { "icon": "tree", "x": 345, "y": 50,  "width": 16, "height": 16, "amount": 8,  "horizontal": false },
-        { "icon": "tree", "x": 362, "y": 50,  "width": 16, "height": 16, "amount": 8,  "horizontal": false }
-    ]
-}
-*/
 
 FuriString *fetch_world(char *name, void *app)
 {

+ 0 - 1
game/world.h

@@ -12,7 +12,6 @@
 #define MAX_WORLD_OBJECTS 100
 
 void draw_bounds(Canvas *canvas);
-void draw_example_world(Level *level);
 void draw_tree_world(Level *level);
 void draw_town_world(Level *level);
 bool draw_json_world(Level *level, const char *json_data);