PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
asset_path_serialization.h
1#pragma once
2
3#include "pixelbullet/filesystem/asset_path.h"
4#include "pixelbullet/serialization/node.h"
5#include "pixelbullet/serialization/node_reader.h"
6
7namespace pixelbullet
8{
9inline const Node& operator>>(const Node& node, AssetPath& path)
10{
11 path = AssetPath(node.value());
12 return node;
13}
14
15inline Node& operator<<(Node& node, const AssetPath& path)
16{
17 return node << path.logical_path();
18}
19
20[[nodiscard]] inline bool TryReadNode(const Node& node, AssetPath& path, serialization::NodeReader& reader)
21{
22 std::string logical_path;
23 if (!serialization::TryReadNode(node, logical_path, reader))
24 {
25 return false;
26 }
27
28 const auto parsed_path = AssetPath::TryCreate(logical_path);
29 if (!parsed_path)
30 {
31 return reader.Fail("Expected empty path or aliased asset path rooted at @assets or @shared, got '" + logical_path + "'.");
32 }
33
34 path = *parsed_path;
35 return true;
36}
37} // namespace pixelbullet
Definition asset_path.h:28
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:49
Definition node_reader.h:48