[train] converted hasThrottle and throttleName to properties
Dieser Commit ist enthalten in:
Ursprung
181d6ca4bc
Commit
31ef2b206c
@ -102,8 +102,8 @@ bool Throttle::acquired() const
|
||||
std::error_code Throttle::acquire(const std::shared_ptr<Train>& 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)
|
||||
{
|
||||
|
||||
@ -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<Throttle>();
|
||||
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
|
||||
|
||||
@ -102,6 +102,8 @@ class Train : public IdObject
|
||||
Property<bool> powered;
|
||||
Property<bool> active;
|
||||
Property<TrainMode> mode;
|
||||
Property<bool> hasThrottle;
|
||||
Property<std::string> 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);
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren