Added decoder function types: AlwaysOff, AlwaysOn
Dieser Commit ist enthalten in:
Ursprung
5352179495
Commit
1711108ee0
@ -107,6 +107,8 @@ decoder_function:value=Value
|
|||||||
decoder_function_list:add=Add function
|
decoder_function_list:add=Add function
|
||||||
decoder_function_list:f_hash=F#
|
decoder_function_list:f_hash=F#
|
||||||
|
|
||||||
|
decoder_function_type:always_off=Always off
|
||||||
|
decoder_function_type:always_on=Always on
|
||||||
decoder_function_type:light=Light
|
decoder_function_type:light=Light
|
||||||
decoder_function_type:momentary=Momentary
|
decoder_function_type:momentary=Momentary
|
||||||
decoder_function_type:mute=Mute
|
decoder_function_type:mute=Mute
|
||||||
|
|||||||
@ -26,13 +26,34 @@
|
|||||||
#include <traintastic/enum/decoderfunctiontype.hpp>
|
#include <traintastic/enum/decoderfunctiontype.hpp>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
inline constexpr std::array<DecoderFunctionType, 6> decoderFunctionTypeValues{{
|
inline constexpr std::array<DecoderFunctionType, 8> decoderFunctionTypeValues{{
|
||||||
DecoderFunctionType::OnOff,
|
DecoderFunctionType::OnOff,
|
||||||
DecoderFunctionType::Momentary,
|
DecoderFunctionType::Momentary,
|
||||||
DecoderFunctionType::Light,
|
DecoderFunctionType::Light,
|
||||||
DecoderFunctionType::Sound,
|
DecoderFunctionType::Sound,
|
||||||
DecoderFunctionType::Mute,
|
DecoderFunctionType::Mute,
|
||||||
DecoderFunctionType::Smoke,
|
DecoderFunctionType::Smoke,
|
||||||
|
DecoderFunctionType::AlwaysOff,
|
||||||
|
DecoderFunctionType::AlwaysOn,
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
constexpr bool isAlwaysOffOrOn(DecoderFunctionType type)
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case DecoderFunctionType::AlwaysOff:
|
||||||
|
case DecoderFunctionType::AlwaysOn:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case DecoderFunctionType::OnOff:
|
||||||
|
case DecoderFunctionType::Momentary:
|
||||||
|
case DecoderFunctionType::Light:
|
||||||
|
case DecoderFunctionType::Sound:
|
||||||
|
case DecoderFunctionType::Mute:
|
||||||
|
case DecoderFunctionType::Smoke:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -38,7 +38,11 @@ DecoderFunction::DecoderFunction(Decoder& decoder, std::string_view _id) :
|
|||||||
m_decoder{decoder},
|
m_decoder{decoder},
|
||||||
number{this, "number", 0, PropertyFlags::ReadWrite | PropertyFlags::Store},
|
number{this, "number", 0, PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||||
name{this, "name", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
|
name{this, "name", "", PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||||
type{this, "type", DecoderFunctionType::OnOff, PropertyFlags::ReadWrite | PropertyFlags::Store},
|
type{this, "type", DecoderFunctionType::OnOff, PropertyFlags::ReadWrite | PropertyFlags::Store,
|
||||||
|
[this](DecoderFunctionType)
|
||||||
|
{
|
||||||
|
typeChanged();
|
||||||
|
}},
|
||||||
value{this, "value", false, PropertyFlags::ReadWrite | PropertyFlags::StoreState,
|
value{this, "value", false, PropertyFlags::ReadWrite | PropertyFlags::StoreState,
|
||||||
[this](bool)
|
[this](bool)
|
||||||
{
|
{
|
||||||
@ -56,6 +60,7 @@ DecoderFunction::DecoderFunction(Decoder& decoder, std::string_view _id) :
|
|||||||
Attributes::addEnabled(type, editable);
|
Attributes::addEnabled(type, editable);
|
||||||
Attributes::addValues(type, decoderFunctionTypeValues);
|
Attributes::addValues(type, decoderFunctionTypeValues);
|
||||||
m_interfaceItems.add(type);
|
m_interfaceItems.add(type);
|
||||||
|
Attributes::addEnabled(value, true);
|
||||||
m_interfaceItems.add(value);
|
m_interfaceItems.add(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,6 +71,12 @@ void DecoderFunction::save(WorldSaver& saver, nlohmann::json& data, nlohmann::js
|
|||||||
data["decoder"] = m_decoder.id.toJSON();
|
data["decoder"] = m_decoder.id.toJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DecoderFunction::loaded()
|
||||||
|
{
|
||||||
|
IdObject::loaded();
|
||||||
|
typeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void DecoderFunction::worldEvent(WorldState state, WorldEvent event)
|
void DecoderFunction::worldEvent(WorldState state, WorldEvent event)
|
||||||
{
|
{
|
||||||
IdObject::worldEvent(state, event);
|
IdObject::worldEvent(state, event);
|
||||||
@ -76,3 +87,18 @@ void DecoderFunction::worldEvent(WorldState state, WorldEvent event)
|
|||||||
name.setAttributeEnabled(editable);
|
name.setAttributeEnabled(editable);
|
||||||
type.setAttributeEnabled(editable);
|
type.setAttributeEnabled(editable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DecoderFunction::typeChanged()
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case DecoderFunctionType::AlwaysOff:
|
||||||
|
value = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DecoderFunctionType::AlwaysOn:
|
||||||
|
value = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Attributes::setEnabled(value, !isAlwaysOffOrOn(type));
|
||||||
|
}
|
||||||
|
|||||||
@ -31,10 +31,14 @@ class Decoder;
|
|||||||
|
|
||||||
class DecoderFunction : public IdObject
|
class DecoderFunction : public IdObject
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
void typeChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Decoder& m_decoder;
|
Decoder& m_decoder;
|
||||||
|
|
||||||
void save(WorldSaver& saver, nlohmann::json& data, nlohmann::json& state) const override;
|
void save(WorldSaver& saver, nlohmann::json& data, nlohmann::json& state) const override;
|
||||||
|
void loaded() override;
|
||||||
void worldEvent(WorldState state, WorldEvent event) final;
|
void worldEvent(WorldState state, WorldEvent event) final;
|
||||||
|
|
||||||
// void addToWorld() final { Output::addToWorld(); }
|
// void addToWorld() final { Output::addToWorld(); }
|
||||||
|
|||||||
@ -34,11 +34,13 @@ enum class DecoderFunctionType : uint8_t
|
|||||||
Sound = 3,
|
Sound = 3,
|
||||||
Mute = 4,
|
Mute = 4,
|
||||||
Smoke = 5,
|
Smoke = 5,
|
||||||
|
AlwaysOff = 6,
|
||||||
|
AlwaysOn = 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
ENUM_NAME(DecoderFunctionType, "decoder_function_type")
|
ENUM_NAME(DecoderFunctionType, "decoder_function_type")
|
||||||
|
|
||||||
ENUM_VALUES(DecoderFunctionType, 6,
|
ENUM_VALUES(DecoderFunctionType, 8,
|
||||||
{
|
{
|
||||||
{DecoderFunctionType::OnOff, "on_off"},
|
{DecoderFunctionType::OnOff, "on_off"},
|
||||||
{DecoderFunctionType::Momentary, "momentary"},
|
{DecoderFunctionType::Momentary, "momentary"},
|
||||||
@ -46,6 +48,8 @@ ENUM_VALUES(DecoderFunctionType, 6,
|
|||||||
{DecoderFunctionType::Sound, "sound"},
|
{DecoderFunctionType::Sound, "sound"},
|
||||||
{DecoderFunctionType::Mute, "mute"},
|
{DecoderFunctionType::Mute, "mute"},
|
||||||
{DecoderFunctionType::Smoke, "smoke"},
|
{DecoderFunctionType::Smoke, "smoke"},
|
||||||
|
{DecoderFunctionType::AlwaysOff, "always_off"},
|
||||||
|
{DecoderFunctionType::AlwaysOn, "always_on"},
|
||||||
})
|
})
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren