world: replaced m_uuid by uuid property, to make it available in the clients
Dieser Commit ist enthalten in:
Ursprung
17147e48d0
Commit
dc24fa017b
@ -65,7 +65,7 @@ void World::init(const std::shared_ptr<World>& world)
|
||||
|
||||
World::World(Private) :
|
||||
Object(),
|
||||
m_uuid{boost::uuids::random_generator()()},
|
||||
uuid{this, "uuid", to_string(boost::uuids::random_generator()()), PropertyFlags::ReadOnly | PropertyFlags::NoStore},
|
||||
name{this, "name", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||
scale{this, "scale", WorldScale::H0, PropertyFlags::ReadWrite | PropertyFlags::Store, [this](WorldScale value){ updateScaleRatio(); }},
|
||||
scaleRatio{this, "scale_ratio", 87, PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||
@ -182,7 +182,6 @@ World::World(Private) :
|
||||
// backup world:
|
||||
const std::filesystem::path worldDir = Traintastic::instance->worldDir();
|
||||
const std::filesystem::path worldBackupDir = Traintastic::instance->worldBackupDir();
|
||||
const std::string uuid{to_string(m_uuid)};
|
||||
auto dateTimeStr =
|
||||
[]()
|
||||
{
|
||||
@ -200,24 +199,24 @@ World::World(Private) :
|
||||
Log::log(*this, LogMessage::C1007_CREATING_WORLD_BACKUP_DIRECTORY_FAILED_X, ec);
|
||||
}
|
||||
|
||||
if(std::filesystem::is_directory(worldDir / uuid))
|
||||
if(std::filesystem::is_directory(worldDir / uuid.value()))
|
||||
{
|
||||
std::error_code ec;
|
||||
std::filesystem::rename(worldDir / uuid, worldBackupDir / uuid += dateTimeStr(), ec);
|
||||
std::filesystem::rename(worldDir / uuid.value(), worldBackupDir / uuid.value() += dateTimeStr(), ec);
|
||||
if(ec)
|
||||
Log::log(*this, LogMessage::C1006_CREATING_WORLD_BACKUP_FAILED_X, ec);
|
||||
}
|
||||
|
||||
if(std::filesystem::is_regular_file(worldDir / uuid += dotCTW))
|
||||
if(std::filesystem::is_regular_file(worldDir / uuid.value() += dotCTW))
|
||||
{
|
||||
std::error_code ec;
|
||||
std::filesystem::rename(worldDir / uuid += dotCTW, worldBackupDir / uuid += dateTimeStr() += dotCTW, ec);
|
||||
std::filesystem::rename(worldDir / uuid.value() += dotCTW, worldBackupDir / uuid.value() += dateTimeStr() += dotCTW, ec);
|
||||
if(ec)
|
||||
Log::log(*this, LogMessage::C1006_CREATING_WORLD_BACKUP_FAILED_X, ec);
|
||||
}
|
||||
|
||||
// save world:
|
||||
std::filesystem::path savePath = worldDir / uuid;
|
||||
std::filesystem::path savePath = worldDir / uuid.value();
|
||||
if(!Traintastic::instance->settings->saveWorldUncompressed)
|
||||
savePath += dotCTW;
|
||||
|
||||
@ -231,6 +230,7 @@ World::World(Private) :
|
||||
}
|
||||
}}
|
||||
{
|
||||
m_interfaceItems.add(uuid);
|
||||
Attributes::addDisplayName(name, DisplayName::Object::name);
|
||||
m_interfaceItems.add(name);
|
||||
Attributes::addEnabled(scale, false);
|
||||
|
||||
@ -64,7 +64,6 @@ class World : public Object
|
||||
protected:
|
||||
static void init(const std::shared_ptr<World>& world);
|
||||
|
||||
boost::uuids::uuid m_uuid;
|
||||
std::unordered_map<std::string, std::weak_ptr<Object>> m_objects;
|
||||
|
||||
void loaded() final;
|
||||
@ -81,6 +80,7 @@ class World : public Object
|
||||
|
||||
static std::shared_ptr<World> create();
|
||||
|
||||
Property<std::string> uuid;
|
||||
Property<std::string> name;
|
||||
Property<WorldScale> scale;
|
||||
Property<double> scaleRatio;
|
||||
@ -117,7 +117,7 @@ class World : public Object
|
||||
|
||||
std::string getObjectId() const final { return std::string(classId); }
|
||||
|
||||
const boost::uuids::uuid& uuid() const { return m_uuid; }
|
||||
//const boost::uuids::uuid& uuid() const { return m_uuid; }
|
||||
|
||||
std::string getUniqueId(std::string_view prefix) const;
|
||||
bool isObject(const std::string&_id) const;
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include <fstream>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/uuid/string_generator.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include "world.hpp"
|
||||
#include "../utils/string.hpp"
|
||||
#include "ctwreader.hpp"
|
||||
@ -82,7 +83,8 @@ WorldLoader::WorldLoader(std::filesystem::path path) :
|
||||
}
|
||||
}
|
||||
|
||||
m_world->m_uuid = boost::uuids::string_generator()(std::string(data["uuid"]));
|
||||
// check if UUID is valid:
|
||||
m_world->uuid.setValueInternal(to_string(boost::uuids::string_generator()(std::string(data["uuid"]))));
|
||||
|
||||
// create a list of all objects
|
||||
m_objects.insert({m_world->getObjectId(), {data, m_world, false}});
|
||||
|
||||
@ -44,7 +44,7 @@ WorldSaver::WorldSaver(const World& world, std::filesystem::path path) :
|
||||
data.erase("class_id");
|
||||
}
|
||||
|
||||
data["uuid"] = state["uuid"] = to_string(world.m_uuid);
|
||||
data["uuid"] = state["uuid"] = world.uuid.value();
|
||||
|
||||
{
|
||||
json objects = json::array();
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren