Webclient: Download is no longer a WIP

The temp map file is now properly written to the in-memory filesystem instead of default filesystem, meaning an error is no longer printed to console about a missing file.
This commit is contained in:
UnknownShadow200 2020-11-29 14:36:25 +11:00
parent bfd9c01e89
commit 7d58c5c241

View File

@ -1239,7 +1239,7 @@ static void SaveLevelScreen_UpdateSave(struct SaveLevelScreen* s) {
static void SaveLevelScreen_UpdateAlt(struct SaveLevelScreen* s) { static void SaveLevelScreen_UpdateAlt(struct SaveLevelScreen* s) {
#ifdef CC_BUILD_WEB #ifdef CC_BUILD_WEB
ButtonWidget_SetConst(&s->alt, "Download (WIP)", &s->titleFont); ButtonWidget_SetConst(&s->alt, "Download", &s->titleFont);
#else #else
ButtonWidget_SetConst(&s->alt, ButtonWidget_SetConst(&s->alt,
s->alt.optName ? "&cOverwrite existing?" : "Save schematic", &s->titleFont); s->alt.optName ? "&cOverwrite existing?" : "Save schematic", &s->titleFont);
@ -1267,7 +1267,7 @@ static void DownloadMap(const cc_string* path) {
Platform_ConvertString(strPath, path); Platform_ConvertString(strPath, path);
/* maps/aaa.schematic -> aaa.cw */ /* maps/aaa.schematic -> aaa.cw */
file = String_UNSAFE_SubstringAt(path, 5); file = *path; Utils_UNSAFE_GetFilename(&file);
file.length = String_LastIndexOf(&file, '.'); file.length = String_LastIndexOf(&file, '.');
String_AppendConst(&file, ".cw"); String_AppendConst(&file, ".cw");
Platform_ConvertString(strFile, &file); Platform_ConvertString(strFile, &file);
@ -1339,7 +1339,7 @@ static void SaveLevelScreen_SaveMap(struct SaveLevelScreen* s, const cc_string*
PauseScreen_Show(); PauseScreen_Show();
} }
static void SaveLevelScreen_Save(void* screen, void* widget, const char* ext) { static void SaveLevelScreen_Save(void* screen, void* widget, const char* fmt) {
cc_string path; char pathBuffer[FILENAME_SIZE]; cc_string path; char pathBuffer[FILENAME_SIZE];
struct SaveLevelScreen* s = (struct SaveLevelScreen*)screen; struct SaveLevelScreen* s = (struct SaveLevelScreen*)screen;
@ -1351,7 +1351,7 @@ static void SaveLevelScreen_Save(void* screen, void* widget, const char* ext) {
return; return;
} }
String_InitArray(path, pathBuffer); String_InitArray(path, pathBuffer);
String_Format2(&path, "maps/%s%c", &file, ext); String_Format1(&path, fmt, &file);
if (File_Exists(&path) && !btn->optName) { if (File_Exists(&path) && !btn->optName) {
btn->optName = ""; btn->optName = "";
@ -1362,8 +1362,13 @@ static void SaveLevelScreen_Save(void* screen, void* widget, const char* ext) {
SaveLevelScreen_SaveMap(s, &path); SaveLevelScreen_SaveMap(s, &path);
} }
} }
static void SaveLevelScreen_Main(void* a, void* b) { SaveLevelScreen_Save(a, b, ".cw"); } static void SaveLevelScreen_Main(void* a, void* b) { SaveLevelScreen_Save(a, b, "maps/%s.cw"); }
static void SaveLevelScreen_Alt(void* a, void* b) { SaveLevelScreen_Save(a, b, ".schematic"); } #ifdef CC_BUILD_WEB
/* Use absolute path so data is written to memory filesystem instead of default filesystem */
static void SaveLevelScreen_Alt(void* a, void* b) { SaveLevelScreen_Save(a, b, "/%s.tmpmap"); }
#else
static void SaveLevelScreen_Alt(void* a, void* b) { SaveLevelScreen_Save(a, b, "maps/%s.schematic"); }
#endif
static void SaveLevelScreen_Render(void* screen, double delta) { static void SaveLevelScreen_Render(void* screen, double delta) {
PackedCol grey = PackedCol_Make(150, 150, 150, 255); PackedCol grey = PackedCol_Make(150, 150, 150, 255);