[world] added booster feature, is automatically enabled when a booster is created, for future booster setting for block

Dieser Commit ist enthalten in:
Reinder Feenstra 2026-01-17 09:19:30 +01:00
Ursprung 176522540b
Commit 90cb0704a5
4 geänderte Dateien mit 53 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -2,7 +2,7 @@
* This file is part of Traintastic, * This file is part of Traintastic,
* see <https://github.com/traintastic/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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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); 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);
}
}

Datei anzeigen

@ -2,7 +2,7 @@
* This file is part of Traintastic, * This file is part of Traintastic,
* see <https://github.com/traintastic/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 * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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") CLASS_ID("list.booster")
protected:
void worldEvent(WorldState state, WorldEvent event) final;
bool isListedProperty(std::string_view name) final;
public: public:
Method<std::shared_ptr<Booster>()> create; Method<std::shared_ptr<Booster>()> create;
Method<void(const std::shared_ptr<Booster>&)> delete_; Method<void(const std::shared_ptr<Booster>&)> delete_;
@ -42,6 +38,13 @@ public:
~BoosterList() final = default; ~BoosterList() final = default;
TableModelPtr getModel() final; 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 #endif

Datei anzeigen

@ -188,6 +188,18 @@ class World : public Object
return m_features; 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 getObjectId() const final { return std::string(classId); }
std::string getUniqueId(std::string_view prefix) const; std::string getUniqueId(std::string_view prefix) const;

Datei anzeigen

@ -28,6 +28,7 @@
enum class WorldFeature enum class WorldFeature
{ {
Scripting = 0, Scripting = 0,
Boosters = 1,
}; };
class WorldFeatures 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 #endif