this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

save options as json to .local folder (#2597)

authored by

Vadim Grigoruk and committed by
GitHub
9a92615c 7e40e849

+145 -53
+2 -2
CMakeLists.txt
··· 23 23 set(BUILD_PLAYER_DEFAULT OFF) 24 24 set(BUILD_LIBRETRO_DEFAULT OFF) 25 25 set(BUILD_TOUCH_INPUT_DEFAULT ${ANDROID}) 26 - set(BUILD_TOOLS OFF) 27 26 set(BUILD_WITH_ALL_DEFAULT OFF) 28 27 29 28 option(BUILD_STATIC "Static runtime" ${BUILD_STATIC_DEFAULT}) ··· 32 31 option(BUILD_SDLGPU "SDL GPU Enabled" OFF) 33 32 option(BUILD_SOKOL "Sokol Enabled" OFF) 34 33 option(BUILD_LIBRETRO "libretro Enabled" ${BUILD_LIBRETRO_DEFAULT}) 35 - option(BUILD_TOOLS "bin2txt prj2cart" ${BUILD_TOOLS}) 34 + option(BUILD_TOOLS "bin2txt prj2cart" OFF) 35 + option(BUILD_EDITORS "Build cart editors" ON) 36 36 option(BUILD_PRO "Build PRO version" FALSE) 37 37 option(BUILD_PLAYER "Build standalone players" ${BUILD_PLAYER_DEFAULT}) 38 38 option(BUILD_TOUCH_INPUT "Build with touch input support" ${BUILD_TOUCH_INPUT_DEFAULT})
+23 -15
cmake/studio.cmake
··· 4 4 5 5 set(TIC80LIB_DIR ${CMAKE_SOURCE_DIR}/src) 6 6 set(TIC80STUDIO_SRC 7 - ${TIC80LIB_DIR}/studio/screens/console.c 8 7 ${TIC80LIB_DIR}/studio/screens/run.c 9 8 ${TIC80LIB_DIR}/studio/screens/menu.c 10 9 ${TIC80LIB_DIR}/studio/screens/mainmenu.c 11 - ${TIC80LIB_DIR}/studio/screens/surf.c 12 10 ${TIC80LIB_DIR}/studio/screens/start.c 13 - ${TIC80LIB_DIR}/studio/editors/code.c 14 - ${TIC80LIB_DIR}/studio/editors/sprite.c 15 - ${TIC80LIB_DIR}/studio/editors/map.c 16 - ${TIC80LIB_DIR}/studio/editors/world.c 17 - ${TIC80LIB_DIR}/studio/editors/sfx.c 18 - ${TIC80LIB_DIR}/studio/editors/music.c 19 11 ${TIC80LIB_DIR}/studio/studio.c 20 12 ${TIC80LIB_DIR}/studio/config.c 21 13 ${TIC80LIB_DIR}/studio/fs.c 22 - ${TIC80LIB_DIR}/studio/net.c 23 14 ${TIC80LIB_DIR}/ext/md5.c 24 - ${TIC80LIB_DIR}/ext/history.c 25 - ${TIC80LIB_DIR}/ext/gif.c 26 - ${TIC80LIB_DIR}/ext/png.c 27 15 ${TIC80LIB_DIR}/ext/json.c 28 16 ) 29 17 30 - if(${BUILD_PRO}) 31 - set(TIC80STUDIO_SRC ${TIC80STUDIO_SRC} ${TIC80LIB_DIR}/studio/project.c) 18 + if(BUILD_EDITORS) 19 + set(TIC80STUDIO_SRC ${TIC80STUDIO_SRC} 20 + ${TIC80LIB_DIR}/studio/screens/console.c 21 + ${TIC80LIB_DIR}/studio/screens/surf.c 22 + ${TIC80LIB_DIR}/studio/editors/code.c 23 + ${TIC80LIB_DIR}/studio/editors/sprite.c 24 + ${TIC80LIB_DIR}/studio/editors/map.c 25 + ${TIC80LIB_DIR}/studio/editors/world.c 26 + ${TIC80LIB_DIR}/studio/editors/sfx.c 27 + ${TIC80LIB_DIR}/studio/editors/music.c 28 + ${TIC80LIB_DIR}/studio/net.c 29 + ${TIC80LIB_DIR}/ext/history.c 30 + ${TIC80LIB_DIR}/ext/gif.c 31 + ${TIC80LIB_DIR}/ext/png.c 32 + ) 33 + endif() 34 + 35 + if(BUILD_PRO) 36 + set(TIC80STUDIO_SRC ${TIC80STUDIO_SRC} 37 + ${TIC80LIB_DIR}/studio/project.c) 32 38 endif() 33 39 34 40 set(TIC80_OUTPUT tic80) ··· 57 63 target_compile_definitions(tic80studio PUBLIC CRT_SHADER_SUPPORT) 58 64 endif() 59 65 60 - target_compile_definitions(tic80studio PUBLIC BUILD_EDITORS) 66 + if(BUILD_EDITORS) 67 + target_compile_definitions(tic80studio PUBLIC BUILD_EDITORS) 68 + endif()
+101 -8
src/studio/config.c
··· 37 37 #define INTEGER_SCALE_DEFAULT true 38 38 #endif 39 39 40 + #define JSON(...) #__VA_ARGS__ 41 + 40 42 static void readConfig(Config* config) 41 43 { 42 44 const char* json = config->cart->code.data; ··· 150 152 studioConfigChanged(config->studio); 151 153 } 152 154 153 - static const char OptionsDatPath[] = TIC_LOCAL_VERSION "options.dat"; 155 + static const char OptionsJsonPath[] = TIC_LOCAL "options.json"; 154 156 155 - static void loadConfigData(tic_fs* fs, const char* path, void* dst, s32 size) 157 + typedef struct 156 158 { 157 - s32 dataSize = 0; 158 - u8* data = (u8*)tic_fs_loadroot(fs, path, &dataSize); 159 + char data[1024]; 160 + } string; 161 + 162 + static void loadOptions(Config* config) 163 + { 164 + s32 size; 165 + u8* data = (u8*)tic_fs_loadroot(config->fs, OptionsJsonPath, &size); 159 166 160 167 if(data) SCOPE(free(data)) 161 - if(dataSize == size) 162 - memcpy(dst, data, size); 168 + { 169 + string json; 170 + snprintf(json.data, sizeof json, "%.*s", size, data); 171 + 172 + if(json_parse(json.data, strlen(json.data))) 173 + { 174 + struct StudioOptions* options = &config->data.options; 175 + 176 + #if defined(CRT_SHADER_SUPPORT) 177 + options->crt = json_bool("crt", 0); 178 + #endif 179 + options->fullscreen = json_bool("fullscreen", 0); 180 + options->vsync = json_bool("vsync", 0); 181 + options->integerScale = json_bool("integerScale", 0); 182 + options->volume = json_int("volume", 0); 183 + options->autosave = json_bool("autosave", 0); 184 + 185 + string mapping; 186 + json_string("mapping", 0, mapping.data, sizeof mapping); 187 + tic_tool_str2buf(mapping.data, strlen(mapping.data), &options->mapping, false); 188 + 189 + #if defined(BUILD_EDITORS) 190 + options->keybindMode = json_int("keybindMode", 0); 191 + options->tabMode = json_int("tabMode", 0); 192 + options->devmode = json_bool("devmode", 0); 193 + options->tabSize = json_int("tabSize", 0); 194 + #endif 195 + } 196 + } 163 197 } 164 198 165 199 void initConfig(Config* config, Studio* studio, tic_fs* fs) ··· 190 224 else saveConfig(config, false); 191 225 } 192 226 193 - loadConfigData(fs, OptionsDatPath, &config->data.options, sizeof config->data.options); 227 + loadOptions(config); 194 228 195 229 #if defined(__TIC_LINUX__) 196 230 // do not load fullscreen option on Linux ··· 200 234 tic_api_reset(config->tic); 201 235 } 202 236 237 + static string data2str(const void* data, s32 size) 238 + { 239 + string res; 240 + tic_tool_buf2str(data, size, res.data, false); 241 + return res; 242 + } 243 + 244 + static const char* bool2str(bool value) 245 + { 246 + return value ? "true" : "false"; 247 + } 248 + 249 + static void saveOptions(Config* config) 250 + { 251 + const struct StudioOptions* options = &config->data.options; 252 + 253 + string buf; 254 + sprintf(buf.data, JSON( 255 + { 256 + #if defined(CRT_SHADER_SUPPORT) 257 + "crt":%s, 258 + #endif 259 + "fullscreen":%s, 260 + "vsync":%s, 261 + "integerScale":%s, 262 + "volume":%i, 263 + "autosave":%s, 264 + "mapping":"%s" 265 + #if defined(BUILD_EDITORS) 266 + , 267 + "keybindMode":%i, 268 + "tabMode":%i, 269 + "devmode":%s, 270 + "tabSize":%i 271 + #endif 272 + }) 273 + , 274 + #if defined(CRT_SHADER_SUPPORT) 275 + bool2str(options->crt), 276 + #endif 277 + bool2str(options->fullscreen), 278 + bool2str(options->vsync), 279 + bool2str(options->integerScale), 280 + options->volume, 281 + bool2str(options->autosave), 282 + data2str(&options->mapping, sizeof options->mapping).data 283 + 284 + #if defined(BUILD_EDITORS) 285 + , 286 + options->keybindMode, 287 + options->tabMode, 288 + bool2str(options->devmode), 289 + options->tabSize 290 + #endif 291 + ); 292 + 293 + tic_fs_saveroot(config->fs, OptionsJsonPath, buf.data, strlen(buf.data), true); 294 + } 295 + 203 296 void freeConfig(Config* config) 204 297 { 205 - tic_fs_saveroot(config->fs, OptionsDatPath, &config->data.options, sizeof config->data.options, true); 298 + saveOptions(config); 206 299 207 300 free(config->cart); 208 301 free(config);
+1 -12
src/studio/project.c
··· 51 51 else strcpy(out, tag); 52 52 } 53 53 54 - static void buf2str(const void* data, s32 size, char* ptr, bool flip) 55 - { 56 - enum {Len = 2}; 57 - 58 - for(s32 i = 0; i < size; i++, ptr+=Len) 59 - { 60 - sprintf(ptr, "%02x", ((u8*)data)[i]); 61 - if(flip) SWAP(ptr[0], ptr[1], char); 62 - } 63 - } 64 - 65 54 static bool bufferEmpty(const u8* data, s32 size) 66 55 { 67 56 for(s32 i = 0; i < size; i++) ··· 90 79 sprintf(ptr, "%s %03i:", comment, row); 91 80 ptr += strlen(ptr); 92 81 93 - buf2str(data, size, ptr, flip); 82 + tic_tool_buf2str(data, size, ptr, flip); 94 83 ptr += strlen(ptr); 95 84 96 85 sprintf(ptr, "\n");
+2 -4
src/studio/screens/run.c
··· 68 68 } 69 69 70 70 { 71 - enum{Size = 16}; 72 - u8 digest[Size]; 71 + u8 digest[16]; 73 72 MD5_Final(digest, &c); 74 73 75 - for (s32 n = 0; n < Size; ++n) 76 - snprintf(out + n*2, sizeof("ff"), "%02x", digest[n]); 74 + tic_tool_buf2str(digest, sizeof digest, out, false); 77 75 } 78 76 79 77 return out;
+5 -12
src/studio/studio.c
··· 563 563 { 564 564 char* ptr = clipboard; 565 565 566 - for(s32 i = 0; i < size; i++, ptr+=Len) 567 - { 568 - sprintf(ptr, "%02x", ((u8*)data)[i]); 569 - 570 - if(flip) 571 - { 572 - char tmp = ptr[0]; 573 - ptr[0] = ptr[1]; 574 - ptr[1] = tmp; 575 - } 576 - } 577 - 566 + tic_tool_buf2str(data, size, clipboard, flip); 578 567 tic_sys_clipboard_set(clipboard); 579 568 free(clipboard); 580 569 } ··· 1745 1734 keyWasPressedOnce(studio, tic_key_numpadenter); 1746 1735 } 1747 1736 1737 + #if defined(BUILD_EDITORS) 1738 + 1748 1739 static bool isDevMode(Studio* studio) 1749 1740 { 1750 1741 tic_mem* tic = studio->tic; ··· 1758 1749 1759 1750 return getConfig(studio)->options.devmode; 1760 1751 } 1752 + 1753 + #endif 1761 1754 1762 1755 static void processShortcuts(Studio* studio) 1763 1756 {
+9
src/tools.c
··· 171 171 return FLAT4(wave->data) && *wave->data % 0xff == 0; 172 172 } 173 173 174 + void tic_tool_buf2str(const void* data, s32 size, char* str, bool flip) 175 + { 176 + for(s32 i = 0; i < size; i++, str += 2) 177 + { 178 + sprintf(str, "%02x", ((u8*)data)[i]); 179 + if(flip) SWAP(str[0], str[1], char); 180 + } 181 + } 182 + 174 183 void tic_tool_str2buf(const char* str, s32 size, void* buf, bool flip) 175 184 { 176 185 char val[] = "0x00";
+2
src/tools.h
··· 94 94 bool tic_tool_has_ext(const char* name, const char* ext); 95 95 s32 tic_tool_get_track_row_sfx(const tic_track_row* row); 96 96 void tic_tool_set_track_row_sfx(tic_track_row* row, s32 sfx); 97 + 98 + void tic_tool_buf2str(const void* data, s32 size, char* str, bool flip); 97 99 void tic_tool_str2buf(const char* str, s32 size, void* buf, bool flip); 98 100 99 101 u32 tic_tool_zip(void* dest, s32 destSize, const void* source, s32 size);