[world] added booster feature, is automatically enabled when a booster is created, for future booster setting for block
Dieser Commit ist enthalten in:
Ursprung
176522540b
Commit
90cb0704a5
@ -2,7 +2,7 @@
|
||||
* This file is part of Traintastic,
|
||||
* see <https://github.com/traintastic/traintastic>.
|
||||
*
|
||||
* Copyright (C) 2025 Reinder Feenstra
|
||||
* Copyright (C) 2025-2026 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -69,3 +69,19 @@ bool BoosterList::isListedProperty(std::string_view name)
|
||||
{
|
||||
return BoosterListTableModel::isListedProperty(name);
|
||||
}
|
||||
|
||||
void BoosterList::objectAdded(const std::shared_ptr<Booster>& /*object*/)
|
||||
{
|
||||
if(m_items.size() == 1)
|
||||
{
|
||||
getWorld(parent()).enableFeature(WorldFeature::Boosters);
|
||||
}
|
||||
}
|
||||
|
||||
void BoosterList::objectRemoved(const std::shared_ptr<Booster>& /*object*/)
|
||||
{
|
||||
if(m_items.empty())
|
||||
{
|
||||
getWorld(parent()).disableFeature(WorldFeature::Boosters);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
* This file is part of Traintastic,
|
||||
* see <https://github.com/traintastic/traintastic>.
|
||||
*
|
||||
* Copyright (C) 2025 Reinder Feenstra
|
||||
* Copyright (C) 2025-2026 Reinder Feenstra
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@ -30,10 +30,6 @@ class BoosterList final : public ObjectList<Booster>
|
||||
{
|
||||
CLASS_ID("list.booster")
|
||||
|
||||
protected:
|
||||
void worldEvent(WorldState state, WorldEvent event) final;
|
||||
bool isListedProperty(std::string_view name) final;
|
||||
|
||||
public:
|
||||
Method<std::shared_ptr<Booster>()> create;
|
||||
Method<void(const std::shared_ptr<Booster>&)> delete_;
|
||||
@ -42,6 +38,13 @@ public:
|
||||
~BoosterList() final = default;
|
||||
|
||||
TableModelPtr getModel() final;
|
||||
|
||||
protected:
|
||||
void worldEvent(WorldState state, WorldEvent event) final;
|
||||
bool isListedProperty(std::string_view name) final;
|
||||
|
||||
void objectAdded(const std::shared_ptr<Booster>& object) final;
|
||||
void objectRemoved(const std::shared_ptr<Booster>& object) final;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -188,6 +188,18 @@ class World : public Object
|
||||
return m_features;
|
||||
}
|
||||
|
||||
void enableFeature(WorldFeature feature)
|
||||
{
|
||||
assert(isAutomaticFeature(feature));
|
||||
setFeature(feature, true);
|
||||
}
|
||||
|
||||
void disableFeature(WorldFeature feature)
|
||||
{
|
||||
assert(isAutomaticFeature(feature));
|
||||
setFeature(feature, false);
|
||||
}
|
||||
|
||||
std::string getObjectId() const final { return std::string(classId); }
|
||||
|
||||
std::string getUniqueId(std::string_view prefix) const;
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
enum class WorldFeature
|
||||
{
|
||||
Scripting = 0,
|
||||
Boosters = 1,
|
||||
};
|
||||
|
||||
class WorldFeatures
|
||||
@ -81,4 +82,19 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
constexpr bool isAutomaticFeature(WorldFeature feature)
|
||||
{
|
||||
switch(feature)
|
||||
{
|
||||
// features controlled by world properties:
|
||||
case WorldFeature::Scripting:
|
||||
return false;
|
||||
|
||||
// features controlled by other objects:
|
||||
case WorldFeature::Boosters:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren