1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-18 10:38:31 +02:00

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.
This commit is contained in:
Fussmatte 2020-06-03 14:05:09 -04:00 committed by Ethan Lee
parent 3bb4eefaff
commit aaa25c7b47
5 changed files with 38 additions and 6 deletions

View File

@ -2839,6 +2839,7 @@ void Graphics::reloadresources() {
CLEAR_ARRAY(sprites)
CLEAR_ARRAY(flipsprites)
CLEAR_ARRAY(tele)
CLEAR_ARRAY(bfont)
#undef CLEAR_ARRAY

View File

@ -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

View File

@ -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++)

View File

@ -89,6 +89,7 @@ class editorclass{
std::vector<std::string> directoryList;
std::vector<LevelMetaData> ListOfMetaData;
void loadZips();
void getDirectoryData();
bool getLevelMetaData(std::string& filename, LevelMetaData& _data );

View File

@ -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();