Converted Tile::tileId() to a property, so it can be used by the client.

Dieser Commit ist enthalten in:
Reinder Feenstra 2024-07-08 23:09:15 +02:00
Ursprung e6cc388aa9
Commit 4d76dc8891
22 geänderte Dateien mit 55 neuen und 50 gelöschten Zeilen

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020-2023 Reinder Feenstra
* Copyright (C) 2020-2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -53,7 +53,7 @@ Board::Board(World& world, std::string_view _id) :
{
const TileRotate tileRotate = it->second->rotate;
if(it->second->tileId() == TileId::RailStraight && tileClassId == StraightRailTile::classId) // merge to bridge
if(it->second->tileId == TileId::RailStraight && tileClassId == StraightRailTile::classId) // merge to bridge
{
if((tileRotate == rotate + TileRotate::Deg90 || tileRotate == rotate - TileRotate::Deg90) && deleteTile(x, y))
{
@ -73,7 +73,7 @@ Board::Board(World& world, std::string_view _id) :
else
return false;
}
else if(it->second->tileId() == TileId::RailStraight && // replace straight by a straight with something extra
else if(it->second->tileId == TileId::RailStraight && // replace straight by a straight with something extra
Tiles::canUpgradeStraightRail(tileClassId) &&
(tileRotate == rotate || (tileRotate + TileRotate::Deg180) == rotate) &&
deleteTile(x, y))

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2022-2023 Reinder Feenstra
* Copyright (C) 2022-2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -238,7 +238,7 @@ std::unique_ptr<const AbstractSignalPath::Item> AbstractSignalPath::findBlocks(c
if(nextNode.getLink(0).get() == &link)
return findBlocks(nextNode, *nextLink, blocksAhead);
}
else if(isRailBridge(tile->tileId()) || isRailCross(tile->tileId()))
else if(isRailBridge(tile->tileId) || isRailCross(tile->tileId))
{
// 2 1 2 2 3
// | \| |/
@ -257,7 +257,7 @@ std::unique_ptr<const AbstractSignalPath::Item> AbstractSignalPath::findBlocks(c
if(auto linkNode = linkTile->link->node())
return findBlocks(linkNode->get(), linkNode->get().getLink(0), blocksAhead);
}
else if(tile->tileId() != TileId::RailBufferStop)
else if(tile->tileId != TileId::RailBufferStop)
{
if(const auto& nextLink = otherLink(nextNode, link))
{

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2023 Reinder Feenstra
* Copyright (C) 2023-2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -101,11 +101,11 @@ std::vector<std::shared_ptr<BlockPath>> BlockPath::find(BlockRailTile& startBloc
const auto& nextNode = current.link->getNext(*current.node);
auto& tile = nextNode.tile();
switch(tile.tileId())
switch(tile.tileId.value())
{
case TileId::RailBlock:
{
if(current.node->tile().tileId() == TileId::RailNXButton)
if(current.node->tile().tileId == TileId::RailNXButton)
{
current.path->m_nxButtonTo = current.node->tile().shared_ptr<NXButtonRailTile>();
}

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2023 Reinder Feenstra
* Copyright (C) 2023-2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -45,7 +45,7 @@ tcb::span<const Path::TurnoutPositionLink> Path::getTurnoutLinks(TurnoutRailTile
const auto& node = turnout.node()->get();
switch(turnout.tileId())
switch(turnout.tileId.value())
{
case TileId::RailTurnoutLeft45:
case TileId::RailTurnoutLeft90:

Datei anzeigen

@ -38,9 +38,9 @@ static std::shared_ptr<BlockRailTile> findBlock(Node& node, uint8_t linkIndex)
return {};
}
auto* tile = &link->getNext(node).tile();
while(tile->tileId() != TileId::RailBlock)
while(tile->tileId != TileId::RailBlock)
{
if(isRailBridge(tile->tileId()))
if(isRailBridge(tile->tileId))
{
auto& bridgeNode = (*tile->node()).get();
size_t index = bridgeNode.getIndex(*link);

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020,2023 Reinder Feenstra
* Copyright (C) 2020,2023-2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -23,8 +23,8 @@
#include "railtile.hpp"
#include "../../board.hpp"
RailTile::RailTile(World& world, std::string_view _id, TileId tileId) :
Tile(world, _id, tileId)
RailTile::RailTile(World& world, std::string_view _id, TileId tileId_) :
Tile(world, _id, tileId_)
{
}

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020,2023 Reinder Feenstra
* Copyright (C) 2020,2023-2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -31,7 +31,7 @@ class RailTile : public Tile
uint8_t m_reservedState = 0;
protected:
RailTile(World& world, std::string_view _id, TileId tileId);
RailTile(World& world, std::string_view _id, TileId tileId_);
uint8_t reservedState() const final
{

Datei anzeigen

@ -76,8 +76,8 @@ std::optional<OutputActionValue> SignalRailTile::getDefaultActionValue(SignalAsp
return {};
}
SignalRailTile::SignalRailTile(World& world, std::string_view _id, TileId tileId) :
StraightRailTile(world, _id, tileId),
SignalRailTile::SignalRailTile(World& world, std::string_view _id, TileId tileId_) :
StraightRailTile(world, _id, tileId_),
m_node{*this, 2},
name{this, "name", std::string(_id), PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::ScriptReadOnly},
requireReservation{this, "require_reservation", AutoYesNo::Auto, PropertyFlags::ReadWrite | PropertyFlags::Store},

Datei anzeigen

@ -44,7 +44,7 @@ class SignalRailTile : public StraightRailTile
std::unique_ptr<AbstractSignalPath> m_signalPath;
std::weak_ptr<BlockPath> m_blockPath;
SignalRailTile(World& world, std::string_view _id, TileId tileId);
SignalRailTile(World& world, std::string_view _id, TileId tileId_);
void worldEvent(WorldState state, WorldEvent event) override;

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020,2022 Reinder Feenstra
* Copyright (C) 2020,2022,2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -22,8 +22,8 @@
#include "straightrailtile.hpp"
StraightRailTile::StraightRailTile(World& world, std::string_view _id, TileId tileId) :
RailTile(world, _id, tileId)
StraightRailTile::StraightRailTile(World& world, std::string_view _id, TileId tileId_) :
RailTile(world, _id, tileId_)
{
}

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020,2022 Reinder Feenstra
* Copyright (C) 2020,2022,2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -31,7 +31,7 @@ class StraightRailTile : public RailTile
CREATE(StraightRailTile)
public:
StraightRailTile(World& world, std::string_view _id, TileId tileId = TileId::RailStraight);
StraightRailTile(World& world, std::string_view _id, TileId tileId_ = TileId::RailStraight);
void getConnectors(std::vector<Connector>& connectors) const final;
};

Datei anzeigen

@ -63,8 +63,8 @@ static std::optional<OutputActionValue> getDefaultActionValue(TurnoutPosition tu
return {};
}
TurnoutLeftRailTile::TurnoutLeftRailTile(World& world, std::string_view _id, TileId tileId)
: TurnoutRailTile(world, _id, tileId, 3)
TurnoutLeftRailTile::TurnoutLeftRailTile(World& world, std::string_view _id, TileId tileId_)
: TurnoutRailTile(world, _id, tileId_, 3)
{
// Skip Unknown position
tcb::span<const TurnoutPosition, 2> setPositionValues = tcb::make_span(positionValues).subspan<1>();

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020-2022 Reinder Feenstra
* Copyright (C) 2020-2022,2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -28,7 +28,7 @@
class TurnoutLeftRailTile : public TurnoutRailTile
{
protected:
TurnoutLeftRailTile(World& world, std::string_view _id, TileId tileId);
TurnoutLeftRailTile(World& world, std::string_view _id, TileId tileId_);
};
#endif

Datei anzeigen

@ -27,15 +27,15 @@
#include "../../../../world/world.hpp"
#include "../../../../utils/displayname.hpp"
TurnoutRailTile::TurnoutRailTile(World& world, std::string_view _id, TileId tileId, size_t connectors) :
RailTile(world, _id, tileId),
TurnoutRailTile::TurnoutRailTile(World& world, std::string_view _id, TileId tileId_, size_t connectors) :
RailTile(world, _id, tileId_),
m_node{*this, connectors},
name{this, "name", std::string(_id), PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::ScriptReadOnly},
position{this, "position", TurnoutPosition::Unknown, PropertyFlags::ReadWrite | PropertyFlags::StoreState | PropertyFlags::ScriptReadOnly},
outputMap{this, "output_map", nullptr, PropertyFlags::ReadOnly | PropertyFlags::Store | PropertyFlags::SubObject | PropertyFlags::NoScript},
setPosition{*this, "set_position", MethodFlags::ScriptCallable, [this](TurnoutPosition value) { return doSetPosition(value); }}
{
assert(isRailTurnout(tileId));
assert(isRailTurnout(tileId_));
const bool editable = contains(m_world.state.value(), WorldState::Edit);

Datei anzeigen

@ -38,7 +38,7 @@ class TurnoutRailTile : public RailTile
Node m_node;
protected:
TurnoutRailTile(World& world, std::string_view _id, TileId tileId, size_t connectors);
TurnoutRailTile(World& world, std::string_view _id, TileId tileId_, size_t connectors);
void worldEvent(WorldState state, WorldEvent event) override;

Datei anzeigen

@ -63,8 +63,8 @@ static std::optional<OutputActionValue> getDefaultActionValue(TurnoutPosition tu
return {};
}
TurnoutRightRailTile::TurnoutRightRailTile(World& world, std::string_view _id, TileId tileId)
: TurnoutRailTile(world, _id, tileId, 3)
TurnoutRightRailTile::TurnoutRightRailTile(World& world, std::string_view _id, TileId tileId_)
: TurnoutRailTile(world, _id, tileId_, 3)
{
// Skip Unknown position
tcb::span<const TurnoutPosition, 2> setPositionValues = tcb::make_span(positionValues).subspan<1>();

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020-2022 Reinder Feenstra
* Copyright (C) 2020-2022,2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -28,7 +28,7 @@
class TurnoutRightRailTile : public TurnoutRailTile
{
protected:
TurnoutRightRailTile(World& world, std::string_view _id, TileId tileId);
TurnoutRightRailTile(World& world, std::string_view _id, TileId tileId_);
};
#endif

Datei anzeigen

@ -23,8 +23,8 @@
#include "turnoutsliprailtile.hpp"
#include "../../../../core/attributes.hpp"
TurnoutSlipRailTile::TurnoutSlipRailTile(World& world, std::string_view _id, TileId tileId)
: TurnoutRailTile(world, _id, tileId, 4)
TurnoutSlipRailTile::TurnoutSlipRailTile(World& world, std::string_view _id, TileId tileId_)
: TurnoutRailTile(world, _id, tileId_, 4)
, dualMotor{this, "dual_motor", false, PropertyFlags::ReadWrite | PropertyFlags::Store | PropertyFlags::ScriptReadOnly,
[this](bool /*value*/)
{

Datei anzeigen

@ -28,7 +28,7 @@
class TurnoutSlipRailTile : public TurnoutRailTile
{
protected:
TurnoutSlipRailTile(World& world, std::string_view _id, TileId tileId);
TurnoutSlipRailTile(World& world, std::string_view _id, TileId tileId_);
virtual void loaded() override;

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020-2021,2023 Reinder Feenstra
* Copyright (C) 2020-2021,2023-2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -27,15 +27,19 @@
#include "../boardlist.hpp"
#include "../../world/world.hpp"
Tile::Tile(World& world, std::string_view _id, TileId tileId)
Tile::Tile(World& world, std::string_view _id, TileId tileId_)
: IdObject(world, _id)
, m_tileId{tileId}
, tileId{this, "tile_id", tileId_, PropertyFlags::Constant | PropertyFlags::NoStore | PropertyFlags::NoScript}
, x{this, "x", 0, PropertyFlags::ReadOnly | PropertyFlags::Store}
, y{this, "y", 0, PropertyFlags::ReadOnly | PropertyFlags::Store}
, rotate{this, "rotate", TileRotate::Deg0, PropertyFlags::ReadOnly | PropertyFlags::Store}
, height{this, "height", 1, PropertyFlags::ReadOnly | PropertyFlags::Store}
, width{this, "width", 1, PropertyFlags::ReadOnly | PropertyFlags::Store}
{
Attributes::addObjectEditor(tileId, false);
Attributes::addValues(tileId, tcb::span<const TileId, 0>{});
m_interfaceItems.add(tileId);
Attributes::addObjectEditor(x, false);
m_interfaceItems.add(x);

Datei anzeigen

@ -3,7 +3,7 @@
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2020-2023 Reinder Feenstra
* Copyright (C) 2020-2024 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -39,9 +39,7 @@ class Tile : public IdObject
friend class WorldLoader;
protected:
const TileId m_tileId;
Tile(World& world, std::string_view _id, TileId tileId);
Tile(World& world, std::string_view _id, TileId tileId_);
Board& getBoard();
@ -57,15 +55,15 @@ class Tile : public IdObject
public:
static constexpr std::string_view defaultId = "tile";
Property<TileId> tileId;
Property<int16_t> x;
Property<int16_t> y;
Property<TileRotate> rotate;
Property<uint8_t> height;
Property<uint8_t> width;
TileId tileId() const { return m_tileId; }
inline TileLocation location() const { return {x.value(), y.value()}; }
inline TileData data() const { return TileData{m_tileId, rotate, width, height, reservedState()}; }
inline TileData data() const { return TileData{tileId.value(), rotate, width, height, reservedState()}; }
virtual std::optional<std::reference_wrapper<const Node>> node() const { return {}; }
virtual std::optional<std::reference_wrapper<Node>> node() { return {}; }

Datei anzeigen

@ -24,6 +24,7 @@
#define TRAINTASTIC_SHARED_TRAINTASTIC_BOARD_TILEID_HPP
#include <cstdint>
#include "../enum/enum.hpp"
enum class TileId : uint16_t // 10 bit
{
@ -203,4 +204,6 @@ constexpr bool isActive(TileId id)
return false;
}
TRAINTASTIC_ENUM(TileId, "tile_id", 0, {}); // no values defined as we don't need them (at the moment).
#endif