From aaa25c7b4750eeb33e256facbd5e78159d6e0e49 Mon Sep 17 00:00:00 2001 From: Fussmatte Date: Wed, 3 Jun 2020 14:05:09 -0400 Subject: [PATCH] Fixed some custom asset bugs, added .zip level loading Main game would retain custom level assets, now fixed. Also, custom fonts load properly. Finally, levels can be stored as a zip and placed in the levels folder, with the .vvvvvv file at the root of the zip and custom asset folders (graphics, sounds etc) also at the root. --- desktop_version/src/Graphics.cpp | 1 + desktop_version/src/Script.cpp | 3 +++ desktop_version/src/editor.cpp | 22 ++++++++++++++++++++++ desktop_version/src/editor.h | 1 + desktop_version/src/main.cpp | 17 +++++++++++------ 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 9f875a7f..b5d67d97 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -2839,6 +2839,7 @@ void Graphics::reloadresources() { CLEAR_ARRAY(sprites) CLEAR_ARRAY(flipsprites) CLEAR_ARRAY(tele) + CLEAR_ARRAY(bfont) #undef CLEAR_ARRAY diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 873265e4..9594b6f7 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -6,6 +6,8 @@ #include "KeyPoll.h" #include "Map.h" +#include "FileSystemUtils.h" + scriptclass::scriptclass() { //Start SDL @@ -2506,6 +2508,7 @@ void scriptclass::resetgametomenu() void scriptclass::startgamemode( int t ) { + FILESYSTEM_unmountassets(); switch(t) { case 0: //Normal new game diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index cbfd81de..ff5662db 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -92,6 +92,26 @@ static bool endsWith(const std::string& str, const std::string& suffix) ) == 0; } +void editorclass::loadZips() +{ + directoryList = FILESYSTEM_getLevelDirFileNames(); + bool needsReload = false; + + for(size_t i = 0; i < directoryList.size(); i++) + { + if (endsWith(directoryList[i], ".zip")) { + PHYSFS_File* zip = PHYSFS_openRead(directoryList[i].c_str()); + if (!PHYSFS_mountHandle(zip, directoryList[i].c_str(), "levels", 1)) { + printf("%s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + } else { + needsReload = true; + } + } + } + + if (needsReload) directoryList = FILESYSTEM_getLevelDirFileNames(); +} + void replace_all(std::string& str, const std::string& from, const std::string& to) { if (from.empty()) @@ -182,6 +202,8 @@ void editorclass::getDirectoryData() ListOfMetaData.clear(); directoryList.clear(); + loadZips(); + directoryList = FILESYSTEM_getLevelDirFileNames(); for(size_t i = 0; i < directoryList.size(); i++) diff --git a/desktop_version/src/editor.h b/desktop_version/src/editor.h index 4d5942ce..c5ea3e6c 100644 --- a/desktop_version/src/editor.h +++ b/desktop_version/src/editor.h @@ -89,6 +89,7 @@ class editorclass{ std::vector directoryList; std::vector ListOfMetaData; + void loadZips(); void getDirectoryData(); bool getLevelMetaData(std::string& filename, LevelMetaData& _data ); diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 05897ac1..e27f71fa 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -260,16 +260,21 @@ int main(int argc, char *argv[]) game.levelpage = 0; game.playcustomlevel = 0; - ed.directoryList.clear(); - ed.directoryList.push_back(playtestname); + ed.directoryList = { playtestname }; LevelMetaData meta; if (ed.getLevelMetaData(playtestname, meta)) { - ed.ListOfMetaData.clear(); - ed.ListOfMetaData.push_back(meta); + ed.ListOfMetaData = { meta }; } else { - printf("Level not found\n"); - return 1; + ed.loadZips(); + + ed.directoryList = { playtestname }; + if (ed.getLevelMetaData(playtestname, meta)) { + ed.ListOfMetaData = { meta }; + } else { + printf("Level not found\n"); + return 1; + } } game.loadcustomlevelstats();