[sensorrailtile] Added onStateChanged event
Dieser Commit ist enthalten in:
Ursprung
9875a399f6
Commit
bc2fd8a254
@ -1 +1,13 @@
|
||||
{}
|
||||
{
|
||||
"on_state_changed": {
|
||||
"parameters": [
|
||||
{
|
||||
"name": "state"
|
||||
},
|
||||
{
|
||||
"name": "sensor"
|
||||
}
|
||||
],
|
||||
"since": "0.3"
|
||||
}
|
||||
}
|
||||
@ -58,6 +58,7 @@ SensorRailTile::SensorRailTile(World& world, std::string_view _id) :
|
||||
input()->interface->inputSimulateChange(input()->channel, input()->address, SimulateInputAction::Toggle);
|
||||
}
|
||||
}}
|
||||
, onStateChanged{*this, "on_state_changed", EventFlags::Scriptable}
|
||||
{
|
||||
const bool editable = contains(m_world.state.value(), WorldState::Edit);
|
||||
|
||||
@ -81,6 +82,8 @@ SensorRailTile::SensorRailTile(World& world, std::string_view _id) :
|
||||
Attributes::addEnabled(simulateTrigger, false);
|
||||
Attributes::addObjectEditor(simulateTrigger, false);
|
||||
m_interfaceItems.add(simulateTrigger);
|
||||
|
||||
m_interfaceItems.add(onStateChanged);
|
||||
}
|
||||
|
||||
//! \todo Remove in v0.4
|
||||
@ -125,7 +128,12 @@ void SensorRailTile::worldEvent(WorldState worldState, WorldEvent worldEvent)
|
||||
|
||||
void SensorRailTile::inputValueChanged(bool value, const std::shared_ptr<Input>& /*input*/)
|
||||
{
|
||||
state.setValueInternal(toSensorState(type, toTriState(value != invert.value())));
|
||||
const auto newState = toSensorState(type, toTriState(value != invert.value()));
|
||||
if(state != newState)
|
||||
{
|
||||
state.setValueInternal(newState);
|
||||
fireEvent(onStateChanged, newState, shared_ptr<SensorRailTile>());
|
||||
}
|
||||
}
|
||||
|
||||
void SensorRailTile::updateSimulateTriggerEnabled()
|
||||
|
||||
@ -52,6 +52,7 @@ class SensorRailTile : public StraightRailTile, public InputConsumer
|
||||
Property<bool> invert;
|
||||
Property<SensorState> state;
|
||||
Method<void()> simulateTrigger;
|
||||
Event<SensorState, const std::shared_ptr<SensorRailTile>&> onStateChanged;
|
||||
|
||||
SensorRailTile(World& world, std::string_view _id);
|
||||
};
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren