Content menu, content-pack dependencies

This commit is contained in:
MihailRis
2024-01-27 00:36:18 +03:00
parent abc3e47feb
commit c57b2d0de3
25 changed files with 230 additions and 21 deletions
+18 -1
View File
@@ -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());
}
+2
View File
@@ -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;
};
+4
View 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;
+2 -1
View File
@@ -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);