Brunot
Loading...
Searching...
No Matches
Script Struct Referencefinal

#include <Script.h>

Inheritance diagram for Script:
[legend]
Collaboration diagram for Script:
[legend]

Public Member Functions

 Script (const std::filesystem::path &path)
 Script ()
 Constructs a NULL script, which represents a script that does not exist Once constructed as a NULL script, scripts cannot be turned into a real script.
 Script (const Script &other)
 Script (Script &&other) noexcept
auto operator= (const Script &other) -> Script &
auto operator= (Script &&other) noexcept -> Script &
 operator bool () const
auto showMenu () -> void override
 Called before update each frame, for calling ImGui editor code relevant to the gameObject.
auto clone () const -> std::unique_ptr< GameObject > override
 makes a copy a GameObject even if it's held polymorphically
auto endWindow () -> void override
 currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
auto onEnterEngine () -> void override
 hook that is called when a GameObject enters the Engine tree.
auto onSceneStart (const std::string &sceneName) -> void override
 Hook that is called before the first frame a scene is run, but after the entire scene is loaded into the engine To receive the hook, simply override the function in your class.
auto onSceneExit (const std::string &sceneName) -> void override
 Hook that is called right before a scene is unloaded To receive the hook, simply override the function in your class.
auto load (const Stream &stream) -> void override
 Implementations will load the state of a GameObject from a th::Json Object.
auto save (Stream &stream) const -> void override
 Implementations will load the state of a GameObject to a th::Json object.
auto parentTo (GameObject *newParent) -> bool override
 override of parentTo because a ScriptHolder parent is the Entity above it, not the ScriptHolder component
template<typename... Args>
auto callIfFunction (const std::string &functionName, Args &&... args) -> sol::optional< sol::protected_function_result >
 checks if a member function of the script exists, and then calls it if it does, otherwise returns an empty optional
template<typename... Args>
auto callFunction (const std::string &functionName, Args &&... args) -> sol::protected_function_result
 calls a lua function that is a member of the Script
__forceinline auto getVariable (const std::string &name) -> sol::table_proxy< sol::basic_table_core< false, sol::basic_reference<> > &, std::tuple< const char(&)[5], const std::string & > >
 Gets a reference to public variable from the script.
__forceinline auto operator[] (const std::string &name) -> sol::table_proxy< sol::basic_table_core< false, sol::basic_reference<> > &, std::tuple< const char(&)[5], const std::string & > >
 Gets a reference to public variable from the script.
auto loadDataFromJson (const nlohmann::json &j) -> void
 helper to de-serialize a json into a script
auto getDataAsJson () const -> nlohmann::json
 helper to serialize a script into a json
auto reloadScript () -> void
 loads a script from the file it is constructed from
Public Member Functions inherited from GameObject
 GameObject (std::string typeName, gobj::Type parentType, gobj::Type type)
 constructor for gameobject.
virtual ~GameObject ()
 destructor for GameObject.
 GameObject (const GameObject &other)
 Copy Constructor.
auto operator= (const GameObject &other) -> GameObject &
 copy assignment operator
 GameObject (GameObject &&other) noexcept
 Move constructor.
auto operator= (GameObject &&other) noexcept -> GameObject &
 Move assignment operator.
virtual auto update (float dt) -> void
 called once every frame.
virtual auto render () -> void
 called every frame after update has been called for every object.
virtual auto destroy () -> void
 Marks an GameObject to be destroyed.
virtual auto for_each (std::function< void(GameObject &)> func) -> void
 applies a function to every child.
virtual auto for_each (std::function< void(const GameObject &)> func) const -> void
 applies a const function to every child.
virtual auto getParent () const -> GameObject *
 Gets the parent of a GameObject.
auto getInternalParent () const -> GameObject *
 returns the actual owning parent of the GameObject
virtual auto addChild (std::unique_ptr< GameObject > newChild) -> bool
 Adds a child to a GameObject.
auto addChildLua (std::unique_ptr< GameObject > &newChild) -> bool
 for lua
virtual auto getKey () const -> Key
 Generates a unique Key that corresponds to the GameObject.
auto destroyed () const -> bool
auto getUUID () const -> gobj::UUID
auto coolerGetUUID () const -> unsigned int
auto isUUID (gobj::UUID compareUUID) const -> bool
auto getName () const -> const std::string &
 Gets the type of the object as a string.
auto getNickname () const -> const std::string &
 Gets the nickname (custom, writable name) of a GameObject.
auto getFormattedName () const -> const std::string &
 combines a GameObjects Type, Nickname, and UUID into one string, for use with logging.
auto nameEquals (const std::string &compareString) const -> bool
 check whether a GameObjects typeName is equivilent to a given string.
auto isType (gobj::Type otherType) const -> bool
 check whether the GameObject is the same as a given type.
auto getObjectType () const -> gobj::Type
 gets the internal type of the GameObject, as an enum
auto setNickname (const std::string &newNickname) -> void
 sets the GameObjects nickname.
auto updates () const -> bool
auto renders () const -> bool
auto receivesMessages () const -> bool
auto isActive () const -> bool
virtual auto setShouldUpdate (bool _shouldUpdate) -> void
 set whether the GameObject should update every frame, and whether all of it's children should update every frame
virtual auto setShouldRender (bool _shouldRender) -> void
 set whether the GameObject should render every frame, and whether all of it's children should render every frame
virtual auto setShouldReceiveMessages (bool _shouldReceiveMessages) -> void
 set whether the GameObject should Receive Messags, and whether all of it's children should receive messages
auto setActive (bool shouldBeActive) -> void
 set the GameObject should update, render, and receive messages
auto getGameObjectJson () const -> json
 Used for serializing GameObjects.
auto setGameObjectJson (const json &stream) -> void
 used for deserializing GameObjects

Public Attributes

friend ScriptHolder
std::filesystem::path scriptPath
 the path of the script
std::string scriptName
 the name of the script
sol::table luaObject
 the data for the script in lua
const bool isNull = false
 whether the script is null (not constructed with a script path)
Public Attributes inherited from GameObject
friend Entity
friend Node
friend Engine

Private Member Functions

auto onUpdate (float dt) -> void override
 called once every frame.
auto onRender () -> void override
 called every frame after update has been called for every object.
auto updateOtherComponentBindings () -> void
 Helper function that may be used later should link other components on the entity to the script object as table fields.
auto receiveComponentAdded (const Message *) -> Message
 message recieving function that is currently unused, but might be used later
auto setParentInLua (GameObject *newParent) -> void
 helper function to set a pointer to entity parent of the script in lua
void deepCopyTable (sol::table table, const sol::table &otherTable)

Static Private Member Functions

static auto tableToJson (const sol::table &table) -> nlohmann::json
 helper function that serializes a lua table to a json this works on: numbers (convert to double), string, bool, and table
static auto jsonToTable (const nlohmann::json &j, sol::table table) -> void
 helper function that de-serializes a json into a lua table
static auto tableShowMenu (sol::table table) -> void
 for all the values in a lua table, create editor fields for them in imgui

Additional Inherited Members

Protected Member Functions inherited from GameObject
auto setInternalParent (GameObject *parent) -> bool
 sets the internal parent of a GameObject directly, avoiding abstractions provided by ParentTo().
virtual auto getChildren () const -> std::shared_ptr< std::vector< GameObject * > >
 gets a vector of a GameObjects public (i.e.
auto checkAddToSceneHook () -> void
 Determine if the GameObject was recently added to the engine, and if it was, call onEngineEnter.

Constructor & Destructor Documentation

◆ Script() [1/4]

Script::Script ( const std::filesystem::path & path)
explicit
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Script() [2/4]

Script::Script ( )

Constructs a NULL script, which represents a script that does not exist Once constructed as a NULL script, scripts cannot be turned into a real script.

Here is the call graph for this function:

◆ Script() [3/4]

Script::Script ( const Script & other)
Here is the call graph for this function:

◆ Script() [4/4]

Script::Script ( Script && other)
noexcept
Here is the call graph for this function:

Member Function Documentation

◆ callFunction()

template<typename... Args>
auto Script::callFunction ( const std::string & functionName,
Args &&... args )->sol::protected_function_result
inline

calls a lua function that is a member of the Script

Template Parameters
ArgsArguments for lua function
Parameters
functionNamename of lua function
argsArguments for lua function
Returns
the result of the function, which can be automatically converted to the correct type, or will be null, if the function doesn't exist. There is no
Here is the call graph for this function:

◆ callIfFunction()

template<typename... Args>
auto Script::callIfFunction ( const std::string & functionName,
Args &&... args )->sol::optional< sol::protected_function_result >
inline

checks if a member function of the script exists, and then calls it if it does, otherwise returns an empty optional

Template Parameters
Argsargs to be passed into the lua function
Parameters
functionNamethe name of the function to call
argsargs to be passed into the lua function
Returns
an optional filled with the result if the function exists, and is empty otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clone()

auto Script::clone ( ) const->std::unique_ptr< GameObject >
overridevirtual

makes a copy a GameObject even if it's held polymorphically

Warning
When overriding this function, make sure to set the parents object to this
Returns
a unique_ptr to a new stack allocated object that is a copy of the object

Implements GameObject.

Here is the call graph for this function:

◆ deepCopyTable()

void Script::deepCopyTable ( sol::table table,
const sol::table & otherTable )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ endWindow()

auto Script::endWindow ( ) ->void
overridevirtual

currently unused, but intended to but was assumed to be necessary for a proper ImGui editor

Implements GameObject.

◆ getDataAsJson()

auto Script::getDataAsJson ( ) const->nlohmann::json

helper to serialize a script into a json

Returns
a json with the data from the script
Here is the call graph for this function:

◆ getVariable()

__forceinline auto Script::getVariable ( const std::string & name) ->sol::table_proxy< sol::basic_table_core< false, sol::basic_reference<> > &, std::tuple< constchar(&)[5], conststd::string & > >
inline

Gets a reference to public variable from the script.

Parameters
namethe name of the variable to get
Returns
something awful that you should store as auto, or it will automatically convert to the type that you want
Here is the caller graph for this function:

◆ jsonToTable()

auto Script::jsonToTable ( const nlohmann::json & j,
sol::table table )->void
staticprivate

helper function that de-serializes a json into a lua table

Parameters
jjson to de-serialize
tablethe lua table to load the json into
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load()

auto Script::load ( const Stream & stream) ->void
overridevirtual

Implementations will load the state of a GameObject from a th::Json Object.

Unimplemented in GameObject

Parameters
streamth::Json Object

Implements GameObject.

◆ loadDataFromJson()

auto Script::loadDataFromJson ( const nlohmann::json & j) ->void

helper to de-serialize a json into a script

Parameters
jjson
Here is the call graph for this function:

◆ onEnterEngine()

auto Script::onEnterEngine ( ) ->void
overridevirtual

hook that is called when a GameObject enters the Engine tree.

The hook is called immediately after a GameObject's parent is called. Functionality may not be correct if an object was removed from the engine then re-added. To receive the hook, simply override the function in your class

Reimplemented from GameObject.

Here is the call graph for this function:

◆ onRender()

auto Script::onRender ( ) ->void
overrideprivatevirtual

called every frame after update has been called for every object.

Generally used for rendering an object to the screen, when applicable. Unimplemented in GameObject

Implements GameObject.

Here is the call graph for this function:

◆ onSceneExit()

auto Script::onSceneExit ( const std::string & sceneName) ->void
overridevirtual

Hook that is called right before a scene is unloaded To receive the hook, simply override the function in your class.

Parameters
sceneNamethe name of the root node of the old scene

Reimplemented from GameObject.

Here is the call graph for this function:

◆ onSceneStart()

auto Script::onSceneStart ( const std::string & sceneName) ->void
overridevirtual

Hook that is called before the first frame a scene is run, but after the entire scene is loaded into the engine To receive the hook, simply override the function in your class.

Parameters
sceneNamethe name of the root node of the new scene

Reimplemented from GameObject.

Here is the call graph for this function:

◆ onUpdate()

auto Script::onUpdate ( float dt) ->void
overrideprivatevirtual

called once every frame.

Generally used for timers, movement, condition checks, etc. Unimplemented in GameObject

Parameters
dtthe time in seconds that has elapsed

Implements GameObject.

Here is the call graph for this function:

◆ operator bool()

Script::operator bool ( ) const
inlineexplicit

◆ operator=() [1/2]

auto Script::operator= ( const Script & other) ->Script &
Here is the call graph for this function:

◆ operator=() [2/2]

auto Script::operator= ( Script && other) ->Script &
noexcept
Here is the call graph for this function:

◆ operator[]()

__forceinline auto Script::operator[] ( const std::string & name) ->sol::table_proxy< sol::basic_table_core< false, sol::basic_reference<> > &, std::tuple< constchar(&)[5], conststd::string & > >
inline

Gets a reference to public variable from the script.

Parameters
namethe name of the variable to get
Returns
something awful that you should store as auto, or it will automatically convert to the type that you want
Here is the call graph for this function:

◆ parentTo()

auto Script::parentTo ( GameObject * newParent) ->bool
nodiscardoverridevirtual

override of parentTo because a ScriptHolder parent is the Entity above it, not the ScriptHolder component

Parameters
newParentthe parent entity
Returns
whether the parenting succeeded

Reimplemented from GameObject.

Here is the call graph for this function:

◆ receiveComponentAdded()

auto Script::receiveComponentAdded ( const Message * ) ->Message
private

message recieving function that is currently unused, but might be used later

Returns
empty message
Here is the caller graph for this function:

◆ reloadScript()

auto Script::reloadScript ( ) ->void

loads a script from the file it is constructed from

TODO: don't use getstate here

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save()

auto Script::save ( Stream & stream) const->void
overridevirtual

Implementations will load the state of a GameObject to a th::Json object.

Unimplemented in GameObject

Parameters
streamth::Json Object

Implements GameObject.

◆ setParentInLua()

auto Script::setParentInLua ( GameObject * newParent) ->void
private

helper function to set a pointer to entity parent of the script in lua

Parameters
newParentpointer to entity parent
Here is the call graph for this function:
Here is the caller graph for this function:

◆ showMenu()

auto Script::showMenu ( ) ->void
overridevirtual

Called before update each frame, for calling ImGui editor code relevant to the gameObject.

virtual because we might need to destroy other things too, like parent node for entity Has a empty definition in GameObject, so it may be overriden, but doesn't have to be.

Reimplemented from GameObject.

Here is the call graph for this function:

◆ tableShowMenu()

auto Script::tableShowMenu ( sol::table table) ->void
staticprivate

for all the values in a lua table, create editor fields for them in imgui

Parameters
tablethe table to show in imgui
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tableToJson()

auto Script::tableToJson ( const sol::table & table) ->nlohmann::json
staticprivate

helper function that serializes a lua table to a json this works on: numbers (convert to double), string, bool, and table

Parameters
tablereference to the table to serialize
Returns
a new json
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateOtherComponentBindings()

auto Script::updateOtherComponentBindings ( ) ->void
private

Helper function that may be used later should link other components on the entity to the script object as table fields.

Member Data Documentation

◆ isNull

const bool Script::isNull = false

whether the script is null (not constructed with a script path)

◆ luaObject

sol::table Script::luaObject

the data for the script in lua

◆ ScriptHolder

friend Script::ScriptHolder

◆ scriptName

std::string Script::scriptName

the name of the script

◆ scriptPath

std::filesystem::path Script::scriptPath

the path of the script


The documentation for this struct was generated from the following files:
  • /home/egrazil/sites/Brunot/The House/source/Framework/Script.h
  • /home/egrazil/sites/Brunot/The House/source/Framework/Script.cpp