Brunot
Loading...
Searching...
No Matches
ScriptHolder.h
Go to the documentation of this file.
1
10// ____ __ __ __
11// /\__ _\/\ \ /\ \/\ \
12// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
13// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
14// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
15// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
16// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
17
18#pragma once
19#include "Framework/Component.h"
20
21#include <sol/forward.hpp>
22
23#include <filesystem>
24#include <sol/sol.hpp>
25
27#include "framework/Script.h"
28
29class ScriptHolder : public Component
30{
31public:
32#pragma region static_functions
33 static auto getEnum() -> ComponentTypeEnum
34 {
35 return cScriptHolder;
36 }
37 static auto bindLuaTypes(sol::state& lua) -> void {}
38
39#pragma endregion
40
43 auto operator=(const ScriptHolder&) -> ScriptHolder&;
44 ~ScriptHolder() override = default;
45 ScriptHolder(ScriptHolder&& other) noexcept;
46 auto operator=(ScriptHolder&& other) noexcept -> ScriptHolder& = default;
47
48#pragma region overriden_functions
49
50 auto clone() const -> std::unique_ptr<GameObject> override
51 {
52 return std::make_unique<ScriptHolder>(*this);
53 }
54
55 [[nodiscard("Parenting may fail")]] auto parentTo(GameObject* newParent) -> bool override;
56
57 auto componentShowMenu() -> void override;
58private:
59 auto onUpdate(float dt) -> void override;
60 auto onRender() -> void override;
61public:
62
63 auto endWindow() -> void override
64 {
65 } // for debug ImGUI
66 auto load(const Stream& stream) -> void override;
67 auto save(Stream& stream) const -> void override;
68
69 friend auto to_json(json& j, const ScriptHolder& n) -> void;
70 friend auto from_json(const json& j, ScriptHolder& n) -> void;
71
72 auto onEnterEngine() -> void override;
73
74
75#pragma endregion
76
77#pragma region ScriptHolder_functions
78
84 auto contains(const std::string& script) const -> bool;
85
91 auto getScript(const std::string& script) -> Script&;
92
100 auto addScript(const std::filesystem::path& selectedLuaFilePath, const std::string& selectedLuaFileName) -> void;
101
102#pragma endregion
103
104#pragma region messaging_functions
105
106
107 auto linkMessages() -> void;
108
109#pragma endregion
110
111private:
112#pragma region member_variables
113
117 std::unordered_map<std::string, Script> scripts;
118
119#pragma endregion
120
121#pragma region helper_functions
122
126 auto reloadScripts() -> void;
127
128#pragma endregion
129
130
131#pragma region static_variables
132
133
134#pragma endregion
135
136};
137
138
sys::Json Stream
Definition AudioObject.h:20
The base class for components, holding all of their shared All components should inherit from this.
nlohmann::json json
Definition Json.cpp:19
system for managing lua, and how the lua state interacts with scripts
ComponentTypeEnum
This enum lists out every type of component we have.
Definition Component.h:39
Component(ComponentTypeEnum type, const char *typeName)
Definition Component.cpp:72
the base class for the engine, most things inherit from this.
Definition GameObject.h:83
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
Definition ScriptHolder.h:30
auto addScript(const std::filesystem::path &selectedLuaFilePath, const std::string &selectedLuaFileName) -> void
helper function to add a script exposed as public b/c we build cards programatically,...
Definition ScriptHolder.cpp:305
static auto bindLuaTypes(sol::state &lua) -> void
Definition ScriptHolder.h:37
ScriptHolder()
Definition ScriptHolder.cpp:32
auto onUpdate(float dt) -> void override
called once every frame.
Definition ScriptHolder.cpp:225
std::unordered_map< std::string, Script > scripts
map of scripts, ordered by script name
Definition ScriptHolder.h:117
friend auto from_json(const json &j, ScriptHolder &n) -> void
Definition ScriptHolder.cpp:269
friend auto to_json(json &j, const ScriptHolder &n) -> void
Definition ScriptHolder.cpp:260
auto operator=(ScriptHolder &&other) noexcept -> ScriptHolder &=default
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition ScriptHolder.cpp:252
auto onRender() -> void override
called every frame after update has been called for every object.
Definition ScriptHolder.cpp:234
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition ScriptHolder.h:63
auto getScript(const std::string &script) -> Script &
get a reference to a specific script held
Definition ScriptHolder.cpp:296
static auto getEnum() -> ComponentTypeEnum
Definition ScriptHolder.h:33
auto parentTo(GameObject *newParent) -> bool override
Sets the GameObject as a child of another GameObject.
Definition ScriptHolder.cpp:63
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition ScriptHolder.h:50
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition ScriptHolder.cpp:247
auto linkMessages() -> void
Definition ScriptHolder.cpp:315
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition ScriptHolder.cpp:242
~ScriptHolder() override=default
auto componentShowMenu() -> void override
Definition ScriptHolder.cpp:75
auto reloadScripts() -> void
tell all the scripts to reload themselves
Definition ScriptHolder.cpp:324
auto contains(const std::string &script) const -> bool
checks if this ScriptHolder holds a particular script
Definition ScriptHolder.cpp:291
auto operator=(const ScriptHolder &) -> ScriptHolder &
Definition ScriptHolder.cpp:45
Definition Script.h:32