comparison genesis.c @ 2438:bed4d3db8a3f

More flexible loading of Pico storyware assets
author Michael Pavone <pavone@retrodev.com>
date Sun, 11 Feb 2024 11:04:39 -0800
parents 79a8cccb6ac1
children cb62730d5c99
comparison
equal deleted inserted replaced
2437:79a8cccb6ac1 2438:bed4d3db8a3f
3153 set_audio_config(gen); 3153 set_audio_config(gen);
3154 bindings_set_mouse_mode(MOUSE_ABSOLUTE); 3154 bindings_set_mouse_mode(MOUSE_ABSOLUTE);
3155 memset(gen->pico_story_pages, 0xFF, sizeof(gen->pico_story_pages)); 3155 memset(gen->pico_story_pages, 0xFF, sizeof(gen->pico_story_pages));
3156 #ifndef IS_LIB 3156 #ifndef IS_LIB
3157 gen->pico_story_window = render_create_window("Pico Storybook & Pad", 640, 640, NULL); 3157 gen->pico_story_window = render_create_window("Pico Storybook & Pad", 640, 640, NULL);
3158 const char *parts[] = {current_media()->dir, PATH_SEP, current_media()->name, ".manifest"}; 3158 char *manifest_name = alloc_concat(current_media()->name, ".manifest");
3159 char *manifest_path = alloc_concat_m(sizeof(parts)/sizeof(*parts), parts); 3159 char *manifest_str = load_media_subfile(current_media(), manifest_name, NULL);
3160 tern_node *manifest = parse_config_file(manifest_path); 3160 tern_node *manifest = NULL;
3161 if (!manifest) { 3161 if (manifest_str) {
3162 printf("Manifest not found at %s\n", manifest_path); 3162 manifest = parse_config(manifest_str);
3163 } 3163 if (!manifest) {
3164 if (manifest) { 3164 printf("Failed to parse manifest %s\n", manifest_name);
3165 tern_node *pages = tern_find_node(manifest, "pages"); 3165 }
3166 } else {
3167 printf("Manifest file %s not found\n", manifest_name);
3168 }
3169
3170 tern_node *pages = tern_find_node(manifest, "pages");
3171 if (!pages && manifest) {
3172 printf("No pages key in %s\n", manifest_name);
3173 }
3174 char numkey[18];
3175 for (int i = 0; i < 7; i++) {
3176 uint8_t *img_data;
3177 uint32_t img_size;
3166 if (pages) { 3178 if (pages) {
3167 char numkey[13]; 3179 sprintf(numkey, "%d", i);
3168 for (int i = 0; i < 7; i++) { 3180 char *page_path = tern_find_ptr(pages, numkey);
3169 sprintf(numkey, "%d", i); 3181 if (page_path) {
3170 char *page_path = tern_find_ptr(pages, numkey); 3182 printf("page %d: %s\n", i, page_path);
3171 if (page_path) { 3183 } else {
3172 printf("page %d: %s\n", i, page_path); 3184 continue;
3173 } else { 3185 }
3186 img_data = load_media_subfile(current_media(), page_path, &img_size);
3187 if (!img_data) {
3188 printf("Failed to load image file for page %d from %s\n", i, page_path);
3189 continue;
3190 }
3191 } else {
3192 sprintf(numkey, "_%d.png", i);
3193 char *img_path = alloc_concat(current_media()->name, numkey);
3194 img_data = load_media_subfile(current_media(), img_path, &img_size);
3195 if (!img_data) {
3196 sprintf(numkey, "_%d.PNG", i);
3197 char *img_path_loud = alloc_concat(current_media()->name, numkey);
3198 img_data = load_media_subfile(current_media(), img_path_loud, &img_size);
3199 if (!img_data) {
3200 printf("Failed to load image file for page %d from %s or %s\n", i, img_path, img_path_loud);
3201 free(img_path);
3202 free(img_path_loud);
3174 continue; 3203 continue;
3175 } 3204 }
3176 char *img_path; 3205 free(img_path_loud);
3177 if (is_absolute_path(current_media()->dir)) { 3206 }
3178 const char *img_parts[] = {current_media()->dir, PATH_SEP, page_path}; 3207 free(img_path);
3179 img_path = alloc_concat_m(sizeof(img_parts)/sizeof(*img_parts), img_parts); 3208 }
3180 } else { 3209
3181 const char *img_parts[] = {path_current_dir(), PATH_SEP, current_media()->dir, PATH_SEP, page_path}; 3210 gen->pico_story_pages[i] = render_static_image(gen->pico_story_window, img_data, img_size);
3182 img_path = alloc_concat_m(sizeof(img_parts)/sizeof(*img_parts), img_parts); 3211 if (gen->pico_story_pages[i] == 0xFF) {
3183 } 3212 printf("Failed to decode image for page %d\n", i);
3184 gen->pico_story_pages[i] = render_static_image(gen->pico_story_window, img_path); 3213 }
3185 if (gen->pico_story_pages[i] == 0xFF) { 3214 free(img_data);
3186 printf("Failed to load page %d from %s\n", i, img_path); 3215 }
3187 } 3216
3188 free(img_path); 3217 free(manifest_name);
3189 } 3218 tern_free(manifest);
3190 } else {
3191 printf("No pages key in %s\n", manifest_path);
3192 }
3193 tern_free(manifest);
3194 }
3195 free(manifest_path);
3196 pico_update_page(gen); 3219 pico_update_page(gen);
3197 #endif 3220 #endif
3198 return gen; 3221 return gen;
3199 } 3222 }