Content menu, content-pack dependencies
This commit is contained in:
@@ -453,13 +453,18 @@ void WorldFiles::write(const World* world, const Content* content) {
|
||||
}
|
||||
|
||||
void WorldFiles::writePacks(const World* world) {
|
||||
auto packsFile = getPacksFile();
|
||||
if (fs::is_regular_file(packsFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& packs = world->getPacks();
|
||||
std::stringstream ss;
|
||||
ss << "# autogenerated; do not modify\n";
|
||||
for (const auto& pack : packs) {
|
||||
ss << pack.id << "\n";
|
||||
}
|
||||
files::write_string(getPacksFile(), ss.str());
|
||||
files::write_string(packsFile, ss.str());
|
||||
}
|
||||
|
||||
void WorldFiles::writeIndices(const ContentIndices* indices) {
|
||||
@@ -574,3 +579,15 @@ bool WorldFiles::readPlayer(Player* player) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WorldFiles::addPack(const std::string& id) {
|
||||
auto packs = files::read_list(getPacksFile());
|
||||
packs.push_back(id);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "# autogenerated; do not modify\n";
|
||||
for (const auto& pack : packs) {
|
||||
ss << pack << "\n";
|
||||
}
|
||||
files::write_string(getPacksFile(), ss.str());
|
||||
}
|
||||
|
||||
@@ -146,6 +146,8 @@ public:
|
||||
void write(const World* world, const Content* content);
|
||||
void writePacks(const World* world);
|
||||
void writeIndices(const ContentIndices* indices);
|
||||
/* Append pack to packs.list without duplicate check */
|
||||
void addPack(const std::string& id);
|
||||
|
||||
static const char* WORLD_FILE;
|
||||
};
|
||||
|
||||
@@ -43,6 +43,10 @@ fs::path EnginePaths::getWorldsFolder() {
|
||||
return userfiles/fs::path("worlds");
|
||||
}
|
||||
|
||||
fs::path EnginePaths::getWorldFolder() {
|
||||
return worldFolder;
|
||||
}
|
||||
|
||||
std::vector<fs::path> EnginePaths::scanForWorlds() {
|
||||
std::vector<fs::path> folders;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace fs = std::filesystem;
|
||||
class EnginePaths {
|
||||
fs::path userfiles {"."};
|
||||
fs::path resources {"res"};
|
||||
fs::path worldFolder {""};
|
||||
fs::path worldFolder;
|
||||
std::vector<ContentPack>* contentPacks = nullptr;
|
||||
public:
|
||||
fs::path getUserfiles() const;
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
|
||||
fs::path getScreenshotFile(std::string ext);
|
||||
fs::path getWorldsFolder();
|
||||
fs::path getWorldFolder();
|
||||
bool isWorldNameUsed(std::string name);
|
||||
|
||||
void setUserfiles(fs::path folder);
|
||||
|
||||
Reference in New Issue
Block a user