mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 04:51:49 +00:00
World content packs list
This commit is contained in:
parent
7f8935a93c
commit
082599e78c
8 changed files with 82 additions and 26 deletions
|
|
@ -1,9 +1,11 @@
|
|||
#include "ContentPack.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "../files/files.h"
|
||||
#include "../coders/json.h"
|
||||
#include "../files/files.h"
|
||||
#include "../files/engine_paths.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
|
|
@ -44,3 +46,21 @@ void ContentPack::scan(fs::path rootfolder,
|
|||
packs.push_back(read(folder));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> ContentPack::worldPacksList(fs::path folder) {
|
||||
fs::path listfile = folder / fs::path("packs.list");
|
||||
if (!fs::is_regular_file(listfile)) {
|
||||
std::cerr << "warning: packs.list not found (will be created)";
|
||||
std::cerr << std::endl;
|
||||
files::write_string(listfile, "# autogenerated, do not modify\nbase\n");
|
||||
}
|
||||
return files::read_list(listfile);
|
||||
}
|
||||
|
||||
fs::path ContentPack::findPack(const EnginePaths* paths, std::string name) {
|
||||
auto folder = paths->getResources() / fs::path("content") / fs::path(name);
|
||||
if (!fs::is_directory(folder)) {
|
||||
throw std::runtime_error("could not to find pack '"+name+"'");
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
class EnginePaths;
|
||||
|
||||
struct ContentPack {
|
||||
std::string id = "none";
|
||||
std::string title = "untitled";
|
||||
|
|
@ -19,6 +21,8 @@ struct ContentPack {
|
|||
static ContentPack read(std::filesystem::path folder);
|
||||
static void scan(std::filesystem::path folder,
|
||||
std::vector<ContentPack>& packs);
|
||||
static std::vector<std::string> worldPacksList(std::filesystem::path folder);
|
||||
static std::filesystem::path findPack(const EnginePaths* paths, std::string name);
|
||||
};
|
||||
|
||||
#endif // CONTENT_CONTENT_PACK_H_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue