324template <
typename Gobj = GameObject>
342 explicit Path(std::string pathString)
345 switch (pathString[0])
350 pathString = pathString.substr(1);
356 pathString = pathString.substr(1);
361 path = std::make_shared<PathRoot>();
367 assert(
false &&
"Cannot create a path that starts with . without passing a gameObject as base");
392 assert(pathString[0] ==
'.');
393 path = std::make_shared<PathBase>(rootObject);
396 pathString = pathString.substr(1);
421 operator const Gobj&()
434 std::shared_ptr<PathNode>
path;
471 auto result =
dynamic_cast<Gobj*
>(
itr.get());
474 throw PathException(
"Path iterator called get() on GameObject that isn't same type as iterator");
510 return itr == other.itr;
518 auto operator*() const -> std::add_lvalue_reference_t<Gobj>
520 auto result =
dynamic_cast<Gobj*
>(
itr.get());
523 throw PathException(
"Path iterator dereferenced GameObject that isn't same type as iterator");
544 static_assert(std::input_iterator<iterator>);
545 static_assert(std::sentinel_for<iterator, iterator>);
575 return begin().get();
595 static auto splitString(
const std::string& fullString,
const std::string& delimiter) -> std::vector<std::string>
598 auto end = delimiter.length();
599 auto delimiterLength = delimiter.length();
601 std::vector<std::string>
result;
603 while ((
end = fullString.find(delimiter, start)) != std::string::npos)
605 token = fullString.substr(start,
end - start);
606 start =
end + delimiterLength;
610 result.push_back(fullString.substr(start));
617 if (std::is_same_v<Gobj, Component>)
619 path->appendPathNode(std::make_shared<PathFilter>(
627 else if (std::is_same_v<Gobj, Entity>)
629 path->appendPathNode(std::make_shared<PathFilter>(
637 else if (std::is_same_v<Gobj, System>)
639 path->appendPathNode(std::make_shared<PathFilter>(
649 else if (!std::is_same_v<Gobj, GameObject> && !std::is_same_v<Gobj, System>)
651 path->appendPathNode(std::make_shared<PathFilter>(
655 return !!(
dynamic_cast<const Gobj*
>(&g));
668 std::string dir =
"/";
672 for (
auto itr = nodes.begin(); itr != nodes.end(); ++itr)
675 if (itr != nodes.begin() && *itr !=
"..")
677 path->appendPathNode(std::make_shared<PathDir>());
682 path->appendPathNode(std::make_shared<PathUp>());
689 path->appendPathNode(std::make_shared<PathName>(*itr));
695 if (nodes.back().empty())
712template<std::derived_from<GameObject> Gobj,
typename ... Args>
715 return Path<Gobj>(std::format(fmt_path, std::forward<Args>(args)...));
729template<std::derived_from<GameObject> Gobj,
typename ... Args>
732 return Path<Gobj>(std::format(fmt_path, std::forward<Args>(args)...), rootObject);
static FMOD_RESULT result
Definition AudioObject.cpp:27
The class that holds the top node, and manages the main game loop, as well as startup and shutdown.
the base class for the engine, most things inherit from this.
One of the beginnings of a Path, where the Path starts at an arbitrary GameObject.
Given a range of GameObjects, generates a range of all of those GameObjects children.
excption emittited by Path s and their associated classes
Internal PathNode that takes a range of GameObjects on the left, and filters the range to only GameOb...
Internal PathNode that takes a range of GameObjects on the left, and filters the range to only GameOb...
Base class for a linked list of Path sections, which altogether represent the logic of a Path,...
Path Node that represents the Root object in the Engine, and provides a starting point for a Path.
Internal Path Node that takes a range of GameObjects on the left, and transforms the range into the p...
static auto getSystem() -> system *
A function to get a system.
Definition Engine.h:50
the base class for the engine, most things inherit from this.
Definition GameObject.h:83
auto isType(gobj::Type otherType) const -> bool
check whether the GameObject is the same as a given type.
Definition GameObject.cpp:271
Definition PathException.h:24
iterator type, refers to a GameObject, and holds onto a reference to a PathNode to determine its rang...
Definition PathNode.h:45
iterator member class for Path.
Definition Path.h:442
PathNode::path_iterator itr
Internal iterator type that is used by PathNode, and only refers to GameObjects as GameObjects.
Definition Path.h:539
auto operator*() const -> std::add_lvalue_reference_t< Gobj >
Gets a reference to the GameObject the iterator refers to, and casts it to Gobj as well.
Definition Path.h:518
iterator(PathNode::path_iterator itr)
constructs a Path::iterator from a PathNode::path_iterator, which is an internal type used for logic
Definition Path.h:448
auto get() const -> Gobj *
Definition Path.h:469
iterator()=default
defaults initializes iterator as a sentinel "Past the End" iterator
friend Path
Definition Path.h:454
auto operator++(int) -> iterator
post-increments the iterator, getting the next GameObject in the range
Definition Path.h:496
Gobj value_type
Definition Path.h:458
auto operator==(iterator other) const -> bool
compares if two iterators point to the same object.
Definition Path.h:508
std::ptrdiff_t difference_type
Definition Path.h:457
auto operator->() const -> Gobj *
allows for calling functions on the objects an iterator refers to.
Definition Path.h:532
auto operator++() -> iterator &
pre-increments the iterator, getting the next GameObject in the range.
Definition Path.h:485
An object that represents where a GameObject or a range of GameObjects exists in the Engine.
Definition Path.h:326
void addFilterBasedOnType()
Definition Path.h:614
Path(std::string pathString)
constructs a Path by parsing a string
Definition Path.h:342
Gobj value_type
Definition Path.h:332
auto begin() const -> iterator
Definition Path.h:553
auto end() const -> iterator
Definition Path.h:563
std::shared_ptr< PathNode > path
a pointer to the linked list of PathNodes that handles the logic for Path deduction
Definition Path.h:434
static auto bindLuaTypes(sol::state &lua) -> void
Definition Path.h:328
auto parsePath(const std::string &pathString) -> void
parses a Path, constructing the linked list of PathNodes, which calculate the range that a Path refer...
Definition Path.h:665
static auto splitString(const std::string &fullString, const std::string &delimiter) -> std::vector< std::string >
splits a string into many smaller strings.
Definition Path.h:595
Path(std::string pathString, GameObject &rootObject)
constructs a Path by parsing a string
Definition Path.h:390
auto operator->() const -> Gobj *
Definition Path.h:582
auto get() const -> Gobj *
Definition Path.h:573
namespace for things relating to GameObject, other than GameObject itself
Definition Entity.h:440
constexpr auto FormatPath(const std::format_string< Args... > &&fmt_path, Args &&... args) -> Path< Gobj >
Constructs a Path by parsing a string, and uses string formatting.
Definition Path.h:713
@ Entity
Definition GameObject.h:58
@ Component
Definition GameObject.h:59
@ System
Definition GameObject.h:57
Path Node that represents the Root object in the Engine, and provides a starting point for a Path.
Definition PathRoot.h:28