diff --git a/server/src/throttle/throttle.cpp b/server/src/throttle/throttle.cpp index 4c695da5..d1aa67c4 100644 --- a/server/src/throttle/throttle.cpp +++ b/server/src/throttle/throttle.cpp @@ -102,8 +102,8 @@ bool Throttle::acquired() const std::error_code Throttle::acquire(const std::shared_ptr& acquireTrain, bool steal) { assert(acquireTrain); - const auto stole = steal && acquireTrain->hasThrottle(); - const std::string stoleFrom = stole ? acquireTrain->throttleName() : std::string{}; + const auto stole = steal && acquireTrain->hasThrottle.value(); + const std::string stoleFrom = stole ? acquireTrain->throttleName.value() : std::string{}; const auto ec = acquireTrain->acquire(*this, steal); if(ec) { diff --git a/server/src/train/train.cpp b/server/src/train/train.cpp index 15edd5db..c3ba719a 100644 --- a/server/src/train/train.cpp +++ b/server/src/train/train.cpp @@ -150,6 +150,8 @@ Train::Train(World& world, std::string_view _id) : }, std::bind(&Train::setTrainActive, this, std::placeholders::_1)}, mode{this, "mode", TrainMode::ManualUnprotected, PropertyFlags::ReadWrite | PropertyFlags::StoreState | PropertyFlags::ScriptReadOnly}, + hasThrottle{this, "has_throttle", false, PropertyFlags::ReadOnly | PropertyFlags::NoStore | PropertyFlags::ScriptReadOnly}, + throttleName{this, "throttle_name", "", PropertyFlags::ReadOnly | PropertyFlags::NoStore | PropertyFlags::ScriptReadOnly}, blocks{*this, "blocks", {}, PropertyFlags::ReadOnly | PropertyFlags::StoreState | PropertyFlags::ScriptReadOnly}, notes{this, "notes", "", PropertyFlags::ReadWrite | PropertyFlags::Store} , onBlockAssigned{*this, "on_block_assigned", EventFlags::Scriptable} @@ -202,6 +204,12 @@ Train::Train(World& world, std::string_view _id) : Attributes::addValues(mode, trainModeValues); m_interfaceItems.add(mode); + Attributes::addObjectEditor(hasThrottle, false); + m_interfaceItems.add(hasThrottle); + + Attributes::addObjectEditor(throttleName, false); + m_interfaceItems.add(throttleName); + Attributes::addObjectEditor(blocks, false); m_interfaceItems.add(blocks); @@ -455,15 +463,6 @@ bool Train::setTrainActive(bool val) return true; } -std::string Train::throttleName() const -{ - if(m_throttle) - { - return m_throttle->name; - } - return {}; -} - std::error_code Train::acquire(Throttle& throttle, bool steal) { if(m_throttle) @@ -490,6 +489,8 @@ std::error_code Train::acquire(Throttle& throttle, bool steal) } assert(!m_throttle); m_throttle = throttle.shared_ptr(); + hasThrottle.setValueInternal(true); + throttleName.setValueInternal(m_throttle->name); return {}; } @@ -500,6 +501,8 @@ std::error_code Train::release(Throttle& throttle) return make_error_code(ErrorCode::InvalidThrottle); } m_throttle.reset(); + hasThrottle.setValueInternal(false); + throttleName.setValueInternal(""); if(isStopped && blocks.empty()) { active = false; // deactive train if it is stopped and not assigned to a block diff --git a/server/src/train/train.hpp b/server/src/train/train.hpp index a2c6e8d4..100ca0df 100644 --- a/server/src/train/train.hpp +++ b/server/src/train/train.hpp @@ -102,6 +102,8 @@ class Train : public IdObject Property powered; Property active; Property mode; + Property hasThrottle; + Property throttleName; //! \brief List of block status the train is in //! Index 0 is the block where the head of the train is. @@ -116,12 +118,6 @@ class Train : public IdObject Train(World& world, std::string_view _id); - bool hasThrottle() const - { - return m_throttle.operator bool(); - } - - std::string throttleName() const; std::error_code acquire(Throttle& throttle, bool steal = false); std::error_code release(Throttle& throttle); std::error_code setSpeed(Throttle& throttle, double value);