jblanked 1 год назад
Родитель
Сommit
6a61e4ef7c

+ 0 - 0
assets/chest_closed_16x13px.png → assets/icon_chest_closed_16x13px.png


+ 0 - 0
assets/chest_open_16x16px.png → assets/icon_chest_open_16x16px.png


+ 0 - 0
assets/fence_16x8px.png → assets/icon_fence_16x8px.png


+ 0 - 0
assets/fence_end_16x8px.png → assets/icon_fence_end_16x8px.png


+ 0 - 0
assets/house_3d_34x45px.png → assets/icon_house_3d_34x45px.png


+ 0 - 0
assets/house_48x48px.png → assets/icon_house_48x48px.png


+ 0 - 0
assets/lake_bottom_31x31px.png → assets/icon_lake_bottom_31x31px.png


+ 0 - 0
assets/lake_bottom_left_31x31px.png → assets/icon_lake_bottom_left_31x31px.png


+ 0 - 0
assets/lake_bottom_right_31x31px.png → assets/icon_lake_bottom_right_31x31px.png


+ 0 - 0
assets/lake_left_31x31.png → assets/icon_lake_left_31x31.png


+ 0 - 0
assets/lake_right_31x31px.png → assets/icon_lake_right_31x31px.png


+ 0 - 0
assets/lake_top_31x31px.png → assets/icon_lake_top_31x31px.png


+ 0 - 0
assets/lake_top_left_31x31px.png → assets/icon_lake_top_left_31x31px.png


+ 0 - 0
assets/lake_top_right_31x31px.png → assets/icon_lake_top_right_31x31px.png


+ 0 - 0
assets/plant_fern_18x16px.png → assets/icon_plant_fern_18x16px.png


+ 0 - 0
assets/plant_pointy_13x16px.png → assets/icon_plant_pointy_13x16px.png


+ 0 - 0
assets/rock_large_18x19px.png → assets/icon_rock_large_18x19px.png


+ 0 - 0
assets/rock_medium_16x14px.png → assets/icon_rock_medium_16x14px.png


+ 0 - 0
assets/rock_small_10x8px.png → assets/icon_rock_small_10x8px.png


+ 0 - 0
assets/tree_29x30px.png → assets/icon_tree_29x30px.png


+ 0 - 0
assets/tree_48x48px.png → assets/icon_tree_48x48px.png


+ 2 - 2
callback/callback.c

@@ -783,13 +783,13 @@ static char *flip_world_parse_worlds(DataLoaderModel *model)
     // we used 10 since we passed 10 in the request
     for (int i = 0; i < 10; i++)
     {
-        char *json = get_json_array_value("worlds", i, furi_string_get_cstr(world_data), 1024);
+        char *json = get_json_array_value("worlds", i, furi_string_get_cstr(world_data));
         if (!json)
         {
             FURI_LOG_E(TAG, "Failed to get worlds. Data likely empty");
             break;
         }
-        char *world_name = get_json_value("name", json, 1024);
+        char *world_name = get_json_value("name", json);
         if (!world_name)
         {
             FURI_LOG_E(TAG, "Failed to get world name");

+ 7 - 7
game/icon.c

@@ -3,31 +3,31 @@ const Icon *get_icon(char *name)
 {
     if (strcmp(name, "earth") == 0)
     {
-        return &I_icon_earth;
+        return &I_icon_earth_15x16;
     }
     if (strcmp(name, "home") == 0)
     {
-        return &I_icon_home;
+        return &I_icon_home_15x16;
     }
     if (strcmp(name, "info") == 0)
     {
-        return &I_icon_info;
+        return &I_icon_info_15x16;
     }
     if (strcmp(name, "man") == 0)
     {
-        return &I_icon_man;
+        return &I_icon_man_7x16;
     }
     if (strcmp(name, "plant") == 0)
     {
-        return &I_icon_plant;
+        return &I_icon_plant_16x16;
     }
     if (strcmp(name, "tree") == 0)
     {
-        return &I_icon_tree;
+        return &I_icon_tree_16x16;
     }
     if (strcmp(name, "woman") == 0)
     {
-        return &I_icon_woman;
+        return &I_icon_woman_9x16;
     }
     return NULL;
 }

+ 2 - 2
game/level.c

@@ -102,14 +102,14 @@ bool level_load_all()
 
     for (int i = 0; i < 10; i++)
     {
-        char *json = get_json_array_value("worlds", i, json_data, 1024);
+        char *json = get_json_array_value("worlds", i, json_data);
         if (!json)
         {
             FURI_LOG_E(TAG, "Failed to get worlds. Data likely empty");
             break;
         }
 
-        char *world_id = get_json_value("name", json, 1024);
+        char *world_id = get_json_value("name", json);
         if (!world_id)
         {
             FURI_LOG_E(TAG, "Failed to get world id");

+ 44 - 44
game/world.c

@@ -11,18 +11,18 @@ bool draw_json_world(Level *level, const char *json_data)
 {
     for (int i = 0; i < MAX_WORLD_OBJECTS; i++)
     {
-        char *data = get_json_array_value("json_data", i, json_data, MAX_WORLD_TOKENS);
+        char *data = get_json_array_value("json_data", i, json_data);
         if (data == NULL)
         {
             break;
         }
-        char *icon = get_json_value("icon", data, 64);
-        char *x = get_json_value("x", data, 64);
-        char *y = get_json_value("y", data, 64);
-        char *width = get_json_value("width", data, 64);
-        char *height = get_json_value("height", data, 64);
-        char *amount = get_json_value("amount", data, 64);
-        char *horizontal = get_json_value("horizontal", data, 64);
+        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)
         {
             return false;
@@ -57,18 +57,18 @@ bool draw_json_world_furi(Level *level, FuriString *json_data)
 {
     for (int i = 0; i < MAX_WORLD_OBJECTS; i++)
     {
-        char *data = get_json_array_value("json_data", i, furi_string_get_cstr(json_data), MAX_WORLD_TOKENS);
+        char *data = get_json_array_value("json_data", i, furi_string_get_cstr(json_data));
         if (data == NULL)
         {
             break;
         }
-        char *icon = get_json_value("icon", data, 64);
-        char *x = get_json_value("x", data, 64);
-        char *y = get_json_value("y", data, 64);
-        char *width = get_json_value("width", data, 64);
-        char *height = get_json_value("height", data, 64);
-        char *amount = get_json_value("amount", data, 64);
-        char *horizontal = get_json_value("horizontal", data, 64);
+        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)
         {
             return false;
@@ -102,12 +102,12 @@ bool draw_json_world_furi(Level *level, FuriString *json_data)
 
 void draw_example_world(Level *level)
 {
-    spawn_icon(level, &I_icon_earth, 112, 56, 15, 16);
-    spawn_icon(level, &I_icon_home, 128, 24, 15, 16);
-    spawn_icon(level, &I_icon_info, 144, 24, 15, 16);
-    spawn_icon(level, &I_icon_man, 160, 56, 7, 16);
-    spawn_icon(level, &I_icon_woman, 168, 56, 9, 16);
-    spawn_icon(level, &I_icon_plant, 168, 32, 16, 16);
+    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)
@@ -116,55 +116,55 @@ void draw_tree_world(Level *level)
     for (int i = 0; i < 2; i++)
     {
         // Horizontal line of 22 icons
-        spawn_icon_line(level, &I_icon_tree, 5, 2 + i * 17, 16, 16, 22, true);
+        spawn_icon_line(level, get_icon("tree"), 5, 2 + i * 17, 16, 16, 22, true);
         // Vertical line of 11 icons
-        spawn_icon_line(level, &I_icon_tree, 5 + i * 17, 2, 16, 16, 11, false);
+        spawn_icon_line(level, get_icon("tree"), 5 + i * 17, 2, 16, 16, 11, false);
     }
 
     // Spawn two full down tree lines
     for (int i = 9; i < 11; i++)
     {
         // Horizontal line of 22 icons
-        spawn_icon_line(level, &I_icon_tree, 5, 2 + i * 17, 16, 16, 22, true);
+        spawn_icon_line(level, get_icon("tree"), 5, 2 + i * 17, 16, 16, 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, &I_icon_tree, 5 + i * 17, 50, 16, 16, 8, false);
+        spawn_icon_line(level, get_icon("tree"), 5 + i * 17, 50, 16, 16, 8, false);
     }
 
     // Labyrinth lines
     // Third line (14 left, then a gap, then 3 middle)
-    spawn_icon_line(level, &I_icon_tree, 5, 2 + 2 * 17, 16, 16, 14, true);
-    spawn_icon_line(level, &I_icon_tree, 5 + 16 * 17, 2 + 2 * 17, 16, 16, 3, true);
+    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);
 
     // Fourth line (3 left, 6 middle, 4 right)
-    spawn_icon_line(level, &I_icon_tree, 5, 2 + 3 * 17, 16, 16, 3, true);           // 3 left
-    spawn_icon_line(level, &I_icon_tree, 5 + 7 * 17, 2 + 3 * 17, 16, 16, 6, true);  // 6 middle
-    spawn_icon_line(level, &I_icon_tree, 5 + 15 * 17, 2 + 3 * 17, 16, 16, 4, true); // 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
 
     // Fifth line (6 left, 7 middle)
-    spawn_icon_line(level, &I_icon_tree, 5, 2 + 4 * 17, 16, 16, 6, true);
-    spawn_icon_line(level, &I_icon_tree, 5 + 7 * 17, 2 + 4 * 17, 16, 16, 7, true);
+    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);
 
     // Sixth line (5 left, 3 middle, 7 right)
-    spawn_icon_line(level, &I_icon_tree, 5, 2 + 5 * 17, 16, 16, 5, true);           // 5 left
-    spawn_icon_line(level, &I_icon_tree, 5 + 7 * 17, 2 + 5 * 17, 16, 16, 3, true);  // 3 middle
-    spawn_icon_line(level, &I_icon_tree, 5 + 15 * 17, 2 + 5 * 17, 16, 16, 7, true); // 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
 
     // Seventh line (0 left, 7 middle, 4 right)
-    spawn_icon_line(level, &I_icon_tree, 5 + 6 * 17, 2 + 6 * 17, 16, 16, 7, true);  // 7 middle
-    spawn_icon_line(level, &I_icon_tree, 5 + 14 * 17, 2 + 6 * 17, 16, 16, 4, true); // 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
 
     // Eighth line (4 left, 3 middle, 4 right)
-    spawn_icon_line(level, &I_icon_tree, 5, 2 + 7 * 17, 16, 16, 4, true);           // 4 left
-    spawn_icon_line(level, &I_icon_tree, 5 + 7 * 17, 2 + 7 * 17, 16, 16, 3, true);  // 3 middle
-    spawn_icon_line(level, &I_icon_tree, 5 + 15 * 17, 2 + 7 * 17, 16, 16, 4, true); // 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
 
     // Ninth line (3 left, 1 middle, 3 right)
-    spawn_icon_line(level, &I_icon_tree, 5, 2 + 8 * 17, 16, 16, 3, true);           // 3 left
-    spawn_icon_line(level, &I_icon_tree, 5 + 5 * 17, 2 + 8 * 17, 16, 16, 1, true);  // 1 middle
-    spawn_icon_line(level, &I_icon_tree, 5 + 11 * 17, 2 + 8 * 17, 16, 16, 3, true); // 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
 }

+ 8 - 8
jsmn/jsmn.c

@@ -446,14 +446,14 @@ int jsoneq(const char *json, jsmntok_t *tok, const char *s)
 }
 
 // Return the value of the key in the JSON data
-char *get_json_value(char *key, const char *json_data, uint32_t max_tokens)
+char *get_json_value(char *key, const char *json_data)
 {
     // Parse the JSON feed
     if (json_data != NULL)
     {
         jsmn_parser parser;
         jsmn_init(&parser);
-
+        uint32_t max_tokens = json_token_count(json_data);
         // Allocate tokens array on the heap
         jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
         if (tokens == NULL)
@@ -560,19 +560,19 @@ static int skip_token(const jsmntok_t *tokens, int start, int total)
 }
 
 // Revised get_json_array_value
-char *get_json_array_value(char *key, uint32_t index, const char *json_data, uint32_t max_tokens)
+char *get_json_array_value(char *key, uint32_t index, const char *json_data)
 {
     // Always extract the full array each time from the original json_data
-    char *array_str = get_json_value(key, json_data, max_tokens);
+    char *array_str = get_json_value(key, json_data);
     if (array_str == NULL)
     {
         FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
         return NULL;
     }
+    uint32_t max_tokens = json_token_count(array_str);
 
     jsmn_parser parser;
     jsmn_init(&parser);
-
     jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
     if (tokens == NULL)
     {
@@ -642,16 +642,16 @@ char *get_json_array_value(char *key, uint32_t index, const char *json_data, uin
 }
 
 // Revised get_json_array_values function with correct token skipping
-char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values)
+char **get_json_array_values(char *key, char *json_data, int *num_values)
 {
     // Retrieve the array string for the given key
-    char *array_str = get_json_value(key, json_data, max_tokens);
+    char *array_str = get_json_value(key, json_data);
     if (array_str == NULL)
     {
         FURI_LOG_E("JSMM.H", "Failed to get array for key: %s", key);
         return NULL;
     }
-
+    uint32_t max_tokens = json_token_count(array_str);
     // Initialize the JSON parser
     jsmn_parser parser;
     jsmn_init(&parser);

+ 3 - 3
jsmn/jsmn.h

@@ -68,13 +68,13 @@ char *jsmn(const char *key, const char *value);
 int jsoneq(const char *json, jsmntok_t *tok, const char *s);
 
 // Return the value of the key in the JSON data
-char *get_json_value(char *key, const char *json_data, uint32_t max_tokens);
+char *get_json_value(char *key, const char *json_data);
 
 // Revised get_json_array_value function
-char *get_json_array_value(char *key, uint32_t index, const char *json_data, uint32_t max_tokens);
+char *get_json_array_value(char *key, uint32_t index, const char *json_data);
 
 // Revised get_json_array_values function with correct token skipping
-char **get_json_array_values(char *key, char *json_data, uint32_t max_tokens, int *num_values);
+char **get_json_array_values(char *key, char *json_data, int *num_values);
 
 int json_token_count(const char *json);
 #endif /* JB_JSMN_EDIT */

+ 9 - 10
jsmn/jsmn_furi.c

@@ -476,14 +476,14 @@ static int skip_token(const jsmntok_t *tokens, int start, int total)
 /**
  * Parse JSON and return the value associated with a given char* key.
  */
-FuriString *get_json_value_furi(const char *key, const FuriString *json_data, uint32_t max_tokens)
+FuriString *get_json_value_furi(const char *key, const FuriString *json_data)
 {
     if (json_data == NULL)
     {
         FURI_LOG_E("JSMM.H", "JSON data is NULL");
         return NULL;
     }
-
+    uint32_t max_tokens = json_token_count_furi(json_data);
     // Create a temporary FuriString from key
     FuriString *key_str = furi_string_alloc();
     furi_string_cat_str(key_str, key);
@@ -538,16 +538,15 @@ FuriString *get_json_value_furi(const char *key, const FuriString *json_data, ui
 /**
  * Return the value at a given index in a JSON array for a given char* key.
  */
-FuriString *get_json_array_value_furi(const char *key, uint32_t index, const FuriString *json_data, uint32_t max_tokens)
+FuriString *get_json_array_value_furi(const char *key, uint32_t index, const FuriString *json_data)
 {
-    // Convert key to FuriString and call get_json_value_furi
-    FuriString *array_str = get_json_value_furi(key, json_data, max_tokens);
+    FuriString *array_str = get_json_value_furi(key, json_data);
     if (array_str == NULL)
     {
         FURI_LOG_E("JSMM.H", "Failed to get array for key");
         return NULL;
     }
-
+    uint32_t max_tokens = json_token_count_furi(array_str);
     jsmn_parser parser;
     jsmn_init_furi(&parser);
 
@@ -612,18 +611,18 @@ FuriString *get_json_array_value_furi(const char *key, uint32_t index, const Fur
 /**
  * Extract all object values from a JSON array associated with a given char* key.
  */
-FuriString **get_json_array_values_furi(const char *key, const FuriString *json_data, uint32_t max_tokens, int *num_values)
+FuriString **get_json_array_values_furi(const char *key, const FuriString *json_data, int *num_values)
 {
     *num_values = 0;
-
     // Convert key to FuriString and call get_json_value_furi
-    FuriString *array_str = get_json_value_furi(key, json_data, max_tokens);
+    FuriString *array_str = get_json_value_furi(key, json_data);
     if (array_str == NULL)
     {
         FURI_LOG_E("JSMM.H", "Failed to get array for key");
         return NULL;
     }
 
+    uint32_t max_tokens = json_token_count_furi(array_str);
     jsmn_parser parser;
     jsmn_init_furi(&parser);
 
@@ -705,7 +704,7 @@ FuriString **get_json_array_values_furi(const char *key, const FuriString *json_
     return values;
 }
 
-int json_token_count_furi(const FuriString *json)
+uint32_t json_token_count_furi(const FuriString *json)
 {
     if (json == NULL)
     {

+ 4 - 4
jsmn/jsmn_furi.h

@@ -50,11 +50,11 @@ extern "C"
 FuriString *jsmn_create_object(const FuriString *key, const FuriString *value);
 
 // Updated signatures to accept const char* key
-FuriString *get_json_value_furi(const char *key, const FuriString *json_data, uint32_t max_tokens);
-FuriString *get_json_array_value_furi(const char *key, uint32_t index, const FuriString *json_data, uint32_t max_tokens);
-FuriString **get_json_array_values_furi(const char *key, const FuriString *json_data, uint32_t max_tokens, int *num_values);
+FuriString *get_json_value_furi(const char *key, const FuriString *json_data);
+FuriString *get_json_array_value_furi(const char *key, uint32_t index, const FuriString *json_data);
+FuriString **get_json_array_values_furi(const char *key, const FuriString *json_data, int *num_values);
 
-int json_token_count_furi(const FuriString *json);
+uint32_t json_token_count_furi(const FuriString *json);
 /* Example usage:
 char *json = "{\"key1\":\"value1\",\"key2\":\"value2\"}";
 FuriString *json_data = char_to_furi_string(json);