Added block sensor states to board
Dieser Commit ist enthalten in:
Ursprung
336eb667d5
Commit
27d87a66be
@ -30,6 +30,7 @@
|
||||
#include "tilepainter.hpp"
|
||||
#include "../network/board.hpp"
|
||||
#include "../network/abstractproperty.hpp"
|
||||
#include "../network/abstractvectorproperty.hpp"
|
||||
#include "../utils/rectf.hpp"
|
||||
|
||||
QRect rectToViewport(const QRect& r, const int gridSize)
|
||||
@ -179,6 +180,20 @@ BlockState BoardAreaWidget::getBlockState(const TileLocation& l) const
|
||||
return BlockState::Unknown;
|
||||
}
|
||||
|
||||
std::vector<SensorState> BoardAreaWidget::getBlockSensorStates(const TileLocation& l) const
|
||||
{
|
||||
if(ObjectPtr object = m_board.board().getTileObject(l))
|
||||
if(const auto* p = object->getVectorProperty("sensor_states"))
|
||||
{
|
||||
const int size = p->size();
|
||||
std::vector<SensorState> sensorStates(static_cast<size_t>(size));
|
||||
for(int i = 0; i < size; i++)
|
||||
sensorStates[i] = p->getEnum<SensorState>(i);
|
||||
return sensorStates;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
SensorState BoardAreaWidget::getSensorState(const TileLocation& l) const
|
||||
{
|
||||
if(ObjectPtr object = m_board.board().getTileObject(l))
|
||||
@ -382,7 +397,7 @@ void BoardAreaWidget::paintEvent(QPaintEvent* event)
|
||||
break;
|
||||
|
||||
case TileId::RailBlock:
|
||||
tilePainter.drawBlock(id, r, a, getBlockState(it.first));
|
||||
tilePainter.drawBlock(id, r, a, getBlockState(it.first), getBlockSensorStates(it.first));
|
||||
break;
|
||||
|
||||
case TileId::None:
|
||||
|
||||
@ -77,6 +77,7 @@ class BoardAreaWidget : public QWidget
|
||||
int getTileSize() const { return 25 + m_zoomLevel * 5; }
|
||||
TurnoutPosition getTurnoutPosition(const TileLocation& l) const;
|
||||
BlockState getBlockState(const TileLocation& l) const;
|
||||
std::vector<SensorState> getBlockSensorStates(const TileLocation& l) const;
|
||||
SensorState getSensorState(const TileLocation& l) const;
|
||||
SignalAspect getSignalAspect(const TileLocation& l) const;
|
||||
TileLocation pointToTileLocation(const QPoint& p);
|
||||
|
||||
@ -28,7 +28,8 @@ BlockRailTile::BlockRailTile(const std::weak_ptr<World>& world, std::string_view
|
||||
RailTile(world, _id, TileId::RailBlock),
|
||||
name{this, "name", id, PropertyFlags::ReadWrite | PropertyFlags::Store},
|
||||
inputMap{this, "input_map", nullptr, PropertyFlags::ReadOnly | PropertyFlags::Store | PropertyFlags::SubObject},
|
||||
state{this, "state", BlockState::Unknown, PropertyFlags::ReadOnly | PropertyFlags::StoreState}
|
||||
state{this, "state", BlockState::Unknown, PropertyFlags::ReadOnly | PropertyFlags::StoreState},
|
||||
sensorStates{*this, "sensor_states", {}, PropertyFlags::ReadOnly | PropertyFlags::StoreState}
|
||||
{
|
||||
inputMap.setValueInternal(std::make_shared<BlockInputMap>(*this, inputMap.name()));
|
||||
|
||||
@ -43,6 +44,24 @@ BlockRailTile::BlockRailTile(const std::weak_ptr<World>& world, std::string_view
|
||||
m_interfaceItems.add(inputMap);
|
||||
Attributes::addValues(state, blockStateValues);
|
||||
m_interfaceItems.add(state);
|
||||
Attributes::addValues(sensorStates, sensorStateValues);
|
||||
m_interfaceItems.add(sensorStates);
|
||||
}
|
||||
|
||||
void BlockRailTile::inputItemValueChanged(BlockInputMapItem& item)
|
||||
{
|
||||
if(inputMap->items.size() != sensorStates.size())
|
||||
{
|
||||
std::vector<SensorState> values;
|
||||
values.reserve(inputMap->items.size());
|
||||
for(const auto& item : inputMap->items)
|
||||
values.emplace_back(item->value());
|
||||
sensorStates.setValuesInternal(values);
|
||||
}
|
||||
else
|
||||
sensorStates.setValueInternal(inputMap->items.indexOf(item), item.value());
|
||||
|
||||
updateState();
|
||||
}
|
||||
|
||||
void BlockRailTile::updateState()
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
#include "railtile.hpp"
|
||||
#include "../../../core/objectproperty.hpp"
|
||||
#include "../../../core/vectorproperty.hpp"
|
||||
#include "../../../enum/blockstate.hpp"
|
||||
#include "../../../hardware/input/map/blockinputmap.hpp"
|
||||
|
||||
@ -40,14 +41,17 @@ class BlockRailTile : public RailTile
|
||||
void worldEvent(WorldState state, WorldEvent event) final;
|
||||
void setRotate(TileRotate value) final;
|
||||
|
||||
void updateState();
|
||||
|
||||
public:
|
||||
Property<std::string> name;
|
||||
ObjectProperty<BlockInputMap> inputMap;
|
||||
Property<BlockState> state;
|
||||
VectorProperty<SensorState> sensorStates;
|
||||
|
||||
BlockRailTile(const std::weak_ptr<World>& world, std::string_view _id);
|
||||
|
||||
void updateState();
|
||||
void inputItemValueChanged(BlockInputMapItem& item);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
#include "blockinputmap.hpp"
|
||||
#include "../../../world/getworld.hpp"
|
||||
#include "../../../core/attributes.hpp"
|
||||
#include "../../../board/tile/rail/blockrailtile.hpp"
|
||||
|
||||
BlockInputMap::BlockInputMap(Object& _parent, const std::string& parentPropertyName) :
|
||||
InputMap(_parent, parentPropertyName),
|
||||
@ -69,11 +68,6 @@ BlockInputMap::BlockInputMap(Object& _parent, const std::string& parentPropertyN
|
||||
m_interfaceItems.add(moveDown);
|
||||
}
|
||||
|
||||
void BlockInputMap::itemValueChanged(BlockInputMapItem& item)
|
||||
{
|
||||
static_cast<BlockRailTile&>(parent()).updateState();
|
||||
}
|
||||
|
||||
void BlockInputMap::load(WorldLoader& loader, const nlohmann::json& data)
|
||||
{
|
||||
nlohmann::json objects = data.value("items", nlohmann::json::array());
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include "../../../world/getworld.hpp"
|
||||
#include "../../../utils/displayname.hpp"
|
||||
#include "../../../utils/sensor.hpp"
|
||||
#include "../../../board/tile/rail/blockrailtile.hpp"
|
||||
|
||||
BlockInputMapItem::BlockInputMapItem(BlockInputMap& parent, uint32_t itemId) :
|
||||
InputMapItem(),
|
||||
@ -119,6 +120,6 @@ void BlockInputMapItem::setValue(SensorState value)
|
||||
if(m_value != value)
|
||||
{
|
||||
m_value = value;
|
||||
m_parent.itemValueChanged(*this);
|
||||
static_cast<BlockRailTile&>(m_parent.parent()).inputItemValueChanged(*this);
|
||||
}
|
||||
}
|
||||
|
||||
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren