world loader: added loading of legacy command stations and controllers

Dieser Commit ist enthalten in:
Reinder Feenstra 2022-01-03 00:05:29 +01:00
Ursprung 35ea514d61
Commit b8867e1378
3 geänderte Dateien mit 126 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,33 @@
/**
* server/src/utils/endswith.hpp
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2022 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TRAINTASTIC_SERVER_UTILS_ENDSWITH_HPP
#define TRAINTASTIC_SERVER_UTILS_ENDSWITH_HPP
#include <string_view>
constexpr bool endsWith(std::string_view sv, std::string_view suffix)
{
return sv.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), sv.rbegin());
}
#endif

Datei anzeigen

@ -0,0 +1,37 @@
/**
* server/src/utils/stripsuffix.hpp
*
* This file is part of the traintastic source code.
*
* Copyright (C) 2022 Reinder Feenstra
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef TRAINTASTIC_SERVER_UTILS_STRIPSUFFIX_HPP
#define TRAINTASTIC_SERVER_UTILS_STRIPSUFFIX_HPP
#include <string_view>
#include <algorithm>
#include "endswith.hpp"
constexpr std::string_view stripSuffix(std::string_view sv, std::string_view suffix)
{
if(endsWith(sv, suffix))
sv.remove_suffix(suffix.size());
return sv;
}
#endif

Datei anzeigen

@ -27,6 +27,7 @@
#include <boost/uuid/uuid_io.hpp>
#include "world.hpp"
#include "../utils/startswith.hpp"
#include "../utils/stripsuffix.hpp"
#include "ctwreader.hpp"
#include "../board/board.hpp"
@ -199,6 +200,61 @@ void WorldLoader::createObject(ObjectData& objectData)
else if(classId == Lua::Script::classId)
objectData.object = Lua::Script::create(m_world, id);
#endif
// backwards compatibility < 0.1
else if(classId == "command_station.dccplusplus_serial")
{
objectData.object = DCCPlusPlusInterface::create(m_world, id);
objectData.json["device"] = objectData.json["port"];
objectData.json.erase("port");
}
else if(classId == "command_station.loconet_serial")
{
auto object = LocoNetInterface::create(m_world, id);
object->type = LocoNetInterfaceType::Serial;
objectData.object = object;
objectData.json["device"] = objectData.json["port"];
objectData.json.erase("port");
}
else if(classId == "command_station.loconet_tcp_binary")
{
auto object = LocoNetInterface::create(m_world, id);
object->type = LocoNetInterfaceType::TCPBinary;
objectData.object = object;
}
else if(classId == "command_station.xpressnet_serial")
{
auto object = XpressNetInterface::create(m_world, id);
object->type = XpressNetInterfaceType::Serial;
objectData.object = object;
objectData.json["device"] = objectData.json["port"];
objectData.json.erase("port");
}
else if(classId == "command_station.z21")
{
objectData.object = Z21Interface::create(m_world, id);
}
else if(classId == "controller.wlanmaus")
{
objectData.object = WlanMausInterface::create(m_world, id);
}
else if(classId == "input.loconet")
{
objectData.object = Input::create(m_world, id);
objectData.json["interface"] = stripSuffix(objectData.json["loconet"], ".loconet");
objectData.json.erase("loconet");
}
else if(classId == "output.loconet")
{
objectData.object = Output::create(m_world, id);
objectData.json["interface"] = stripSuffix(objectData.json["loconet"], ".loconet");
objectData.json.erase("loconet");
}
else if(classId == "input.xpressnet")
{
objectData.object = Input::create(m_world, id);
objectData.json["interface"] = stripSuffix(objectData.json["xpressnet"], ".xpressnet");
objectData.json.erase("xpressnet");
}
else
assert(false);