mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-11-10 13:09:43 +01: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:
parent
3bb4eefaff
commit
aaa25c7b47
5 changed files with 38 additions and 6 deletions
|
@ -2839,6 +2839,7 @@ void Graphics::reloadresources() {
|
||||||
CLEAR_ARRAY(sprites)
|
CLEAR_ARRAY(sprites)
|
||||||
CLEAR_ARRAY(flipsprites)
|
CLEAR_ARRAY(flipsprites)
|
||||||
CLEAR_ARRAY(tele)
|
CLEAR_ARRAY(tele)
|
||||||
|
CLEAR_ARRAY(bfont)
|
||||||
|
|
||||||
#undef CLEAR_ARRAY
|
#undef CLEAR_ARRAY
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include "KeyPoll.h"
|
#include "KeyPoll.h"
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
|
|
||||||
|
#include "FileSystemUtils.h"
|
||||||
|
|
||||||
scriptclass::scriptclass()
|
scriptclass::scriptclass()
|
||||||
{
|
{
|
||||||
//Start SDL
|
//Start SDL
|
||||||
|
@ -2506,6 +2508,7 @@ void scriptclass::resetgametomenu()
|
||||||
|
|
||||||
void scriptclass::startgamemode( int t )
|
void scriptclass::startgamemode( int t )
|
||||||
{
|
{
|
||||||
|
FILESYSTEM_unmountassets();
|
||||||
switch(t)
|
switch(t)
|
||||||
{
|
{
|
||||||
case 0: //Normal new game
|
case 0: //Normal new game
|
||||||
|
|
|
@ -92,6 +92,26 @@ static bool endsWith(const std::string& str, const std::string& suffix)
|
||||||
) == 0;
|
) == 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)
|
void replace_all(std::string& str, const std::string& from, const std::string& to)
|
||||||
{
|
{
|
||||||
if (from.empty())
|
if (from.empty())
|
||||||
|
@ -182,6 +202,8 @@ void editorclass::getDirectoryData()
|
||||||
ListOfMetaData.clear();
|
ListOfMetaData.clear();
|
||||||
directoryList.clear();
|
directoryList.clear();
|
||||||
|
|
||||||
|
loadZips();
|
||||||
|
|
||||||
directoryList = FILESYSTEM_getLevelDirFileNames();
|
directoryList = FILESYSTEM_getLevelDirFileNames();
|
||||||
|
|
||||||
for(size_t i = 0; i < directoryList.size(); i++)
|
for(size_t i = 0; i < directoryList.size(); i++)
|
||||||
|
|
|
@ -89,6 +89,7 @@ class editorclass{
|
||||||
std::vector<std::string> directoryList;
|
std::vector<std::string> directoryList;
|
||||||
std::vector<LevelMetaData> ListOfMetaData;
|
std::vector<LevelMetaData> ListOfMetaData;
|
||||||
|
|
||||||
|
void loadZips();
|
||||||
void getDirectoryData();
|
void getDirectoryData();
|
||||||
bool getLevelMetaData(std::string& filename, LevelMetaData& _data );
|
bool getLevelMetaData(std::string& filename, LevelMetaData& _data );
|
||||||
|
|
||||||
|
|
|
@ -260,16 +260,21 @@ int main(int argc, char *argv[])
|
||||||
game.levelpage = 0;
|
game.levelpage = 0;
|
||||||
game.playcustomlevel = 0;
|
game.playcustomlevel = 0;
|
||||||
|
|
||||||
ed.directoryList.clear();
|
ed.directoryList = { playtestname };
|
||||||
ed.directoryList.push_back(playtestname);
|
|
||||||
|
|
||||||
LevelMetaData meta;
|
LevelMetaData meta;
|
||||||
if (ed.getLevelMetaData(playtestname, meta)) {
|
if (ed.getLevelMetaData(playtestname, meta)) {
|
||||||
ed.ListOfMetaData.clear();
|
ed.ListOfMetaData = { meta };
|
||||||
ed.ListOfMetaData.push_back(meta);
|
|
||||||
} else {
|
} else {
|
||||||
printf("Level not found\n");
|
ed.loadZips();
|
||||||
return 1;
|
|
||||||
|
ed.directoryList = { playtestname };
|
||||||
|
if (ed.getLevelMetaData(playtestname, meta)) {
|
||||||
|
ed.ListOfMetaData = { meta };
|
||||||
|
} else {
|
||||||
|
printf("Level not found\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
game.loadcustomlevelstats();
|
game.loadcustomlevelstats();
|
||||||
|
|
Loading…
Reference in a new issue