Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
parse_util.hpp
Go to the documentation of this file.
1
8
9
#pragma once
10
11
#include "
value.hpp
"
12
13
#include <glm/glm.hpp>
14
#include <toml++/toml.hpp>
15
16
namespace
input {
17
class
Value
;
18
}
19
20
namespace
input::parse {
21
22
inline
auto
vec2(
const
toml::node_view<const toml::node>& node, glm::vec2 fallback) -> glm::vec2 {
23
if
(
const
auto
* arr = node.as_array()) {
24
glm::vec2 out = fallback;
25
if
(not arr->empty()) {
26
out.x =
static_cast<
float
>
((*arr)[0].value_or(
static_cast<
double
>
(fallback.x)));
27
}
28
if
(arr->size() >= 2) {
29
out.y =
static_cast<
float
>
((*arr)[1].value_or(
static_cast<
double
>
(fallback.y)));
30
}
31
return
out;
32
}
33
if
(
auto
scalar = node.value<
double
>()) {
34
return
glm::vec2 {
static_cast<
float
>
(*scalar)};
35
}
36
return
fallback;
37
}
38
39
inline
auto
number(
const
toml::node_view<const toml::node>& node,
float
fallback) ->
float
{
40
return
static_cast<
float
>
(node.value_or(
static_cast<
double
>
(fallback)));
41
}
42
43
inline
auto
boolean(
const
toml::node_view<const toml::node>& node,
bool
fallback) ->
bool
{
44
return
node.value_or(fallback);
45
}
46
47
inline
auto
value(
const
toml::node_view<const toml::node>& node, ValueType vt) -> Value {
48
switch
(vt) {
49
case
ValueType::axis_0d:
return
Value {boolean(node,
true
), ValueType::axis_0d};
50
case
ValueType::axis_1d:
return
Value {number(node, 1.0f), ValueType::axis_1d};
51
case
ValueType::axis_2d:
return
Value {vec2(node, glm::vec2 {1.0f, 0.0f}), ValueType::axis_2d};
52
}
53
return
Value {};
54
}
55
56
}
input::Value
A tagged value that may represent a bool, a float or a glm::vec2.
Definition
value.hpp:31
value.hpp
Value type shared by triggers, modifiers and actionsg.
engine
src
toast
input
parse_util.hpp
Generated by
1.17.0