Also reload map list if file not found error

This commit is contained in:
UnknownShadow200 2021-12-01 21:07:25 +11:00
parent 2e4098c07b
commit c942d507d1
3 changed files with 22 additions and 11 deletions

View File

@ -54,28 +54,29 @@ IMapImporter Map_FindImporter(const cc_string* path) {
return NULL;
}
void Map_LoadFrom(const cc_string* path) {
cc_result Map_LoadFrom(const cc_string* path) {
IMapImporter importer;
struct Stream stream;
cc_result res;
Game_Reset();
res = Stream_OpenFile(&stream, path);
if (res) { Logger_SysWarn2(res, "opening", path); return; }
if (res) { Logger_SysWarn2(res, "opening", path); return res; }
importer = Map_FindImporter(path);
if (!importer) {
Logger_SysWarn2(ERR_NOT_SUPPORTED, "decoding", path);
res = ERR_NOT_SUPPORTED;
} else if ((res = importer(&stream))) {
World_Reset();
Logger_SysWarn2(res, "decoding", path);
}
/* No point logging error for closing readonly file */
stream.Close(&stream);
if (res) Logger_SysWarn2(res, "decoding", path);
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
LocalPlayer_MoveToSpawn();
return res;
}

View File

@ -13,7 +13,7 @@ typedef cc_result (*IMapImporter)(struct Stream* stream);
CC_API IMapImporter Map_FindImporter(const cc_string* path);
/* Attempts to import the map from the given file. */
/* NOTE: Uses Map_FindImporter to import based on filename. */
CC_API void Map_LoadFrom(const cc_string* path);
CC_API cc_result Map_LoadFrom(const cc_string* path);
/* Imports a world from a .lvl MCSharp server map file. */
/* Used by MCSharp/MCLawl/MCForge/MCDzienny/MCGalaxy. */

View File

@ -413,6 +413,12 @@ static void ListScreen_ContextRecreated(void* screen) {
ButtonWidget_SetConst(&s->upload, "Upload", &s->font);
}
static void ListScreen_Reload(struct ListScreen* s) {
ListScreen_Free(s);
s->LoadEntries(s);
ListScreen_SetCurrentIndex(s, s->currentIndex);
}
static const struct ScreenVTABLE ListScreen_VTABLE = {
ListScreen_Init, Screen_NullUpdate, ListScreen_Free,
ListScreen_Render, Screen_BuildMesh,
@ -1553,13 +1559,11 @@ static void TexturePackScreen_EntryClick(void* screen, void* widget) {
TexturePack_SetDefault(&file);
TexturePack_Url.length = 0;
res = TexturePack_ExtractCurrent(true);
if (res != ReturnCode_FileNotFound) return;
/* FileNotFound error may be because user deleted .zips from disc */
if (res != ReturnCode_FileNotFound) return;
Chat_AddRaw("&eReloading texture pack list as it may be out of date");
ListScreen_Free(s);
s->LoadEntries(s);
ListScreen_SetCurrentIndex(s, s->currentIndex);
ListScreen_Reload(s);
}
static void TexturePackScreen_FilterFiles(const cc_string* path, void* obj) {
@ -1745,11 +1749,17 @@ void HotkeyListScreen_Show(void) {
static void LoadLevelScreen_EntryClick(void* screen, void* widget) {
cc_string path; char pathBuffer[FILENAME_SIZE];
struct ListScreen* s = (struct ListScreen*)screen;
cc_result res;
cc_string relPath = ListScreen_UNSAFE_GetCur(s, widget);
String_InitArray(path, pathBuffer);
String_Format1(&path, "maps/%s", &relPath);
Map_LoadFrom(&path);
res = Map_LoadFrom(&path);
/* FileNotFound error may be because user deleted maps from disc */
if (res != ReturnCode_FileNotFound) return;
Chat_AddRaw("&eReloading level list as it may be out of date");
ListScreen_Reload(s);
}
static void LoadLevelScreen_FilterFiles(const cc_string* path, void* obj) {