mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-28 13:27:30 +01:00
Add vehicle graph core: .vhg loader, logic and cab blocks, -graph-run and -graph-catalog
This commit is contained in:
49
vehicle/graph/graph_block.cpp
Normal file
49
vehicle/graph/graph_block.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "vehicle/graph/graph_block.h"
|
||||
#include "vehicle/graph/graph_catalog.h"
|
||||
|
||||
namespace vgraph
|
||||
{
|
||||
|
||||
block::block(block_setup const &Setup) : m_type(Setup.type), m_slots(Setup.slots) {}
|
||||
|
||||
double block::number(block_setup const &Setup, std::size_t const Param)
|
||||
{
|
||||
return Setup.params[Param].number;
|
||||
}
|
||||
|
||||
bool block::boolean(block_setup const &Setup, std::size_t const Param)
|
||||
{
|
||||
return Setup.params[Param].boolean;
|
||||
}
|
||||
|
||||
std::string const &block::text(block_setup const &Setup, std::size_t const Param)
|
||||
{
|
||||
return Setup.params[Param].text;
|
||||
}
|
||||
|
||||
int block::choice(block_setup const &Setup, std::size_t const Param)
|
||||
{
|
||||
auto const &choices{Setup.type.params[Param].choices};
|
||||
auto const &value{Setup.params[Param].text};
|
||||
for (std::size_t idx = 0; idx < choices.size(); ++idx)
|
||||
{
|
||||
if (choices[idx] == value)
|
||||
{
|
||||
return static_cast<int>(idx);
|
||||
}
|
||||
}
|
||||
// the loader rejects values outside of the list, so this only happens with a broken catalog
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace vgraph
|
||||
Reference in New Issue
Block a user