feat: saving/loading resource entries
This commit is contained in:
+20
-1
@@ -52,13 +52,30 @@ void World::updateTimers(float delta) {
|
||||
totalTime += delta;
|
||||
}
|
||||
|
||||
void World::writeResources(const Content* content) {
|
||||
auto root = dynamic::Map();
|
||||
for (size_t typeIndex = 0; typeIndex < RESOURCE_TYPES_COUNT; typeIndex++) {
|
||||
auto typeName = to_string(static_cast<ResourceType>(typeIndex));
|
||||
auto& list = root.putList(typeName);
|
||||
auto& indices = content->resourceIndices[typeIndex];
|
||||
for (size_t i = 0; i < indices.size(); i++) {
|
||||
auto& map = list.putMap();
|
||||
map.put("name", indices.getName(i));
|
||||
if (auto data = indices.getSavedData(i)) {
|
||||
map.put("saved", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
files::write_json(wfile->getResourcesFile(), &root);
|
||||
}
|
||||
|
||||
void World::write(Level* level) {
|
||||
const Content* content = level->content;
|
||||
level->chunks->saveAll();
|
||||
nextEntityId = level->entities->peekNextID();
|
||||
wfile->write(this, content);
|
||||
|
||||
auto playerFile = dynamic::Map();
|
||||
|
||||
auto& players = playerFile.putList("players");
|
||||
for (const auto& object : level->objects) {
|
||||
if (auto player = std::dynamic_pointer_cast<Player>(object)) {
|
||||
@@ -66,6 +83,8 @@ void World::write(Level* level) {
|
||||
}
|
||||
}
|
||||
files::write_json(wfile->getPlayerFile(), &playerFile);
|
||||
|
||||
writeResources(content);
|
||||
}
|
||||
|
||||
std::unique_ptr<Level> World::create(
|
||||
|
||||
Reference in New Issue
Block a user