mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-11 16:45:48 -04:00
Also reload map list if file not found error
This commit is contained in:
parent
2e4098c07b
commit
c942d507d1
@ -54,28 +54,29 @@ IMapImporter Map_FindImporter(const cc_string* path) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map_LoadFrom(const cc_string* path) {
|
cc_result Map_LoadFrom(const cc_string* path) {
|
||||||
IMapImporter importer;
|
IMapImporter importer;
|
||||||
struct Stream stream;
|
struct Stream stream;
|
||||||
cc_result res;
|
cc_result res;
|
||||||
Game_Reset();
|
Game_Reset();
|
||||||
|
|
||||||
res = Stream_OpenFile(&stream, path);
|
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);
|
importer = Map_FindImporter(path);
|
||||||
if (!importer) {
|
if (!importer) {
|
||||||
Logger_SysWarn2(ERR_NOT_SUPPORTED, "decoding", path);
|
res = ERR_NOT_SUPPORTED;
|
||||||
} else if ((res = importer(&stream))) {
|
} else if ((res = importer(&stream))) {
|
||||||
World_Reset();
|
World_Reset();
|
||||||
Logger_SysWarn2(res, "decoding", path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No point logging error for closing readonly file */
|
/* No point logging error for closing readonly file */
|
||||||
stream.Close(&stream);
|
stream.Close(&stream);
|
||||||
|
if (res) Logger_SysWarn2(res, "decoding", path);
|
||||||
|
|
||||||
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
|
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
|
||||||
LocalPlayer_MoveToSpawn();
|
LocalPlayer_MoveToSpawn();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ typedef cc_result (*IMapImporter)(struct Stream* stream);
|
|||||||
CC_API IMapImporter Map_FindImporter(const cc_string* path);
|
CC_API IMapImporter Map_FindImporter(const cc_string* path);
|
||||||
/* Attempts to import the map from the given file. */
|
/* Attempts to import the map from the given file. */
|
||||||
/* NOTE: Uses Map_FindImporter to import based on filename. */
|
/* 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. */
|
/* Imports a world from a .lvl MCSharp server map file. */
|
||||||
/* Used by MCSharp/MCLawl/MCForge/MCDzienny/MCGalaxy. */
|
/* Used by MCSharp/MCLawl/MCForge/MCDzienny/MCGalaxy. */
|
||||||
|
22
src/Menus.c
22
src/Menus.c
@ -413,6 +413,12 @@ static void ListScreen_ContextRecreated(void* screen) {
|
|||||||
ButtonWidget_SetConst(&s->upload, "Upload", &s->font);
|
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 = {
|
static const struct ScreenVTABLE ListScreen_VTABLE = {
|
||||||
ListScreen_Init, Screen_NullUpdate, ListScreen_Free,
|
ListScreen_Init, Screen_NullUpdate, ListScreen_Free,
|
||||||
ListScreen_Render, Screen_BuildMesh,
|
ListScreen_Render, Screen_BuildMesh,
|
||||||
@ -1553,13 +1559,11 @@ static void TexturePackScreen_EntryClick(void* screen, void* widget) {
|
|||||||
TexturePack_SetDefault(&file);
|
TexturePack_SetDefault(&file);
|
||||||
TexturePack_Url.length = 0;
|
TexturePack_Url.length = 0;
|
||||||
res = TexturePack_ExtractCurrent(true);
|
res = TexturePack_ExtractCurrent(true);
|
||||||
if (res != ReturnCode_FileNotFound) return;
|
|
||||||
|
|
||||||
/* FileNotFound error may be because user deleted.zips from disc */
|
/* 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");
|
Chat_AddRaw("&eReloading texture pack list as it may be out of date");
|
||||||
ListScreen_Free(s);
|
ListScreen_Reload(s);
|
||||||
s->LoadEntries(s);
|
|
||||||
ListScreen_SetCurrentIndex(s, s->currentIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TexturePackScreen_FilterFiles(const cc_string* path, void* obj) {
|
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) {
|
static void LoadLevelScreen_EntryClick(void* screen, void* widget) {
|
||||||
cc_string path; char pathBuffer[FILENAME_SIZE];
|
cc_string path; char pathBuffer[FILENAME_SIZE];
|
||||||
struct ListScreen* s = (struct ListScreen*)screen;
|
struct ListScreen* s = (struct ListScreen*)screen;
|
||||||
|
cc_result res;
|
||||||
|
|
||||||
cc_string relPath = ListScreen_UNSAFE_GetCur(s, widget);
|
cc_string relPath = ListScreen_UNSAFE_GetCur(s, widget);
|
||||||
String_InitArray(path, pathBuffer);
|
String_InitArray(path, pathBuffer);
|
||||||
String_Format1(&path, "maps/%s", &relPath);
|
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) {
|
static void LoadLevelScreen_FilterFiles(const cc_string* path, void* obj) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user