implemented network load world call
Dieser Commit ist enthalten in:
Ursprung
5c5f18f5c3
Commit
b9d2b21dad
@ -47,7 +47,7 @@ WorldListDialog::WorldListDialog(const QSharedPointer<Connection>& connection, Q
|
||||
m_buttons->button(QDialogButtonBox::Open)->setEnabled(false);
|
||||
connect(m_buttons->button(QDialogButtonBox::Open), &QPushButton::clicked, [this]()
|
||||
{
|
||||
|
||||
m_uuid = m_tableWidget->getRowObjectId(m_tableWidget->selectionModel()->selectedIndexes().first().row());
|
||||
accept();
|
||||
});
|
||||
m_buttons->button(QDialogButtonBox::Cancel)->setText(Locale::tr("qtapp.world_list_dialog:cancel"));
|
||||
|
||||
@ -303,19 +303,9 @@ void MainWindow::loadWorld()
|
||||
std::unique_ptr<WorldListDialog> d = std::make_unique<WorldListDialog>(m_connection, this);
|
||||
if(d->exec() == QDialog::Accepted)
|
||||
{
|
||||
d->uuid();
|
||||
|
||||
|
||||
/*
|
||||
m_connection = d->connection();
|
||||
connect(m_connection.data(), &Connection::worldChanged,
|
||||
[this]()
|
||||
{
|
||||
worldChanged();
|
||||
updateActions();
|
||||
});
|
||||
worldChanged();
|
||||
clientStateChanged();*/
|
||||
Method* method = m_connection->traintastic()->getMethod("load_world");
|
||||
if(Q_LIKELY(method))
|
||||
method->call(d->uuid());
|
||||
}
|
||||
/*
|
||||
{
|
||||
|
||||
@ -191,6 +191,18 @@ void Connection::callMethod(Method& method)
|
||||
send(event);
|
||||
}
|
||||
|
||||
void Connection::callMethod(Method& method, const QString& arg)
|
||||
{
|
||||
auto event = Message::newEvent(Message::Command::ObjectCallMethod);
|
||||
event->write(method.object().handle());
|
||||
event->write(method.name().toLatin1());
|
||||
event->write(ValueType::Invalid); // no result
|
||||
event->write<uint8_t>(1); // 1 argument
|
||||
event->write(ValueType::String);
|
||||
event->write(arg.toUtf8());
|
||||
send(event);
|
||||
}
|
||||
|
||||
int Connection::callMethod(Method& method, std::function<void(const ObjectPtr&, Message::ErrorCode)> callback)
|
||||
{
|
||||
auto request = Message::newRequest(Message::Command::ObjectCallMethod);
|
||||
|
||||
@ -125,6 +125,7 @@ class Connection : public QObject, public QEnableSharedFromThis<Connection>
|
||||
void setPropertyString(Property& property, const QString& value);
|
||||
|
||||
void callMethod(Method& method);
|
||||
void callMethod(Method& method, const QString& arg);
|
||||
[[nodiscard]] int callMethod(Method& method, std::function<void(const ObjectPtr&, Message::ErrorCode)> callback);
|
||||
[[nodiscard]] int callMethod(Method& method, const QString& arg, std::function<void(const ObjectPtr&, Message::ErrorCode)> callback);
|
||||
|
||||
|
||||
@ -36,6 +36,11 @@ void Method::call()
|
||||
object().connection()->callMethod(*this);
|
||||
}
|
||||
|
||||
void Method::call(const QString& arg)
|
||||
{
|
||||
object().connection()->callMethod(*this, arg);
|
||||
}
|
||||
|
||||
int Method::call(std::function<void(const ObjectPtr&, Message::ErrorCode)> callback)
|
||||
{
|
||||
return object().connection()->callMethod(*this, std::move(callback));
|
||||
|
||||
@ -42,6 +42,7 @@ class Method : public InterfaceItem
|
||||
const QVector<ValueType>& argumentTypes() const { return m_argumentTypes; }
|
||||
|
||||
void call();
|
||||
void call(const QString& arg);
|
||||
[[nodiscard]] int call(std::function<void(const ObjectPtr&, Message::ErrorCode)> callback);
|
||||
[[nodiscard]] int call(const QString& arg, std::function<void(const ObjectPtr&, Message::ErrorCode)> callback);
|
||||
};
|
||||
|
||||
@ -58,6 +58,23 @@ Traintastic::Traintastic(const std::filesystem::path& dataDir) :
|
||||
console->notice(id, "Created new world");
|
||||
world->trackPowerOff();
|
||||
world->edit = true;
|
||||
}},
|
||||
loadWorld{*this, "load_world",
|
||||
[this](const std::string& _uuid)
|
||||
{
|
||||
boost::uuids::uuid uuid;
|
||||
try
|
||||
{
|
||||
uuid = boost::uuids::string_generator()(_uuid);
|
||||
}
|
||||
catch(const std::exception&)
|
||||
{
|
||||
uuid = boost::uuids::nil_generator()();
|
||||
console->error(id, "Invalid default world uuid");
|
||||
}
|
||||
|
||||
if(!uuid.is_nil())
|
||||
load(uuid);
|
||||
}}
|
||||
{
|
||||
if(!std::filesystem::is_directory(m_dataDir))
|
||||
@ -68,6 +85,7 @@ Traintastic::Traintastic(const std::filesystem::path& dataDir) :
|
||||
m_interfaceItems.add(world);
|
||||
m_interfaceItems.add(worldList);
|
||||
m_interfaceItems.add(newWorld);
|
||||
m_interfaceItems.add(loadWorld);
|
||||
}
|
||||
|
||||
Traintastic::~Traintastic()
|
||||
@ -83,21 +101,7 @@ bool Traintastic::run()
|
||||
worldList = std::make_shared<WorldList>(m_dataDir / "world");
|
||||
|
||||
if(!settings->defaultWorld.value().empty())
|
||||
{
|
||||
boost::uuids::uuid uuid;
|
||||
try
|
||||
{
|
||||
uuid = boost::uuids::string_generator()(settings->defaultWorld.value());
|
||||
}
|
||||
catch(const std::exception&)
|
||||
{
|
||||
uuid = boost::uuids::nil_generator()();
|
||||
console->error(id, "Invalid default world uuid");
|
||||
}
|
||||
|
||||
if(!uuid.is_nil())
|
||||
loadWorld(uuid);
|
||||
}
|
||||
loadWorld(settings->defaultWorld.value());
|
||||
|
||||
if(!start())
|
||||
return false;
|
||||
@ -185,20 +189,19 @@ bool Traintastic::stop()
|
||||
return true;
|
||||
}
|
||||
|
||||
void Traintastic::loadWorld(const boost::uuids::uuid& uuid)
|
||||
void Traintastic::load(const boost::uuids::uuid& uuid)
|
||||
{
|
||||
if(const WorldList::WorldInfo* info = worldList->find(uuid))
|
||||
loadWorld(info->path);
|
||||
load(info->path);
|
||||
else
|
||||
console->error(id, "World " + to_string(uuid) + " doesn't exist");
|
||||
}
|
||||
|
||||
void Traintastic::loadWorld(const std::filesystem::path& path)
|
||||
void Traintastic::load(const std::filesystem::path& path)
|
||||
{
|
||||
try
|
||||
{
|
||||
world = WorldLoader(path / "traintastic.json").world();
|
||||
//World::load(path / "traintastic.json");
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
@ -206,12 +209,6 @@ void Traintastic::loadWorld(const std::filesystem::path& path)
|
||||
}
|
||||
}
|
||||
|
||||
void Traintastic::saveWorld()
|
||||
{
|
||||
assert(world);
|
||||
world->save();
|
||||
}
|
||||
|
||||
void Traintastic::clientGone(const std::shared_ptr<Client>& client)
|
||||
{
|
||||
}
|
||||
|
||||
@ -56,9 +56,8 @@ class Traintastic : public Object
|
||||
bool start();
|
||||
bool stop();
|
||||
|
||||
void loadWorld(const boost::uuids::uuid& uuid);
|
||||
void loadWorld(const std::filesystem::path& path);
|
||||
void saveWorld();
|
||||
void load(const boost::uuids::uuid& uuid);
|
||||
void load(const std::filesystem::path& path);
|
||||
|
||||
void doReceive();
|
||||
std::unique_ptr<Message> processMessage(const Message& message);
|
||||
@ -78,6 +77,7 @@ class Traintastic : public Object
|
||||
ObjectProperty<World> world;
|
||||
ObjectProperty<WorldList> worldList;
|
||||
Method<void()> newWorld;
|
||||
Method<void(std::string)> loadWorld;
|
||||
|
||||
Traintastic(const std::filesystem::path& dataDir);
|
||||
~Traintastic() final;
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren