#pragma once #include "items.h" #include "room.h" #include "LuaHandler.h" #include "trmath.h" #include #include "GameScriptColor.h" #include "GameScriptPosition.h" #include "GameScriptRotation.h" #include "GameScriptItemInfo.h" #include "GameScriptMeshInfo.h" #include "GameScriptSinkInfo.h" #include "GameScriptAIObject.h" #include "GameScriptSoundSourceInfo.h" #include "GameScriptCameraInfo.h" struct LuaFunction { std::string Name; std::string Code; bool Executed; }; struct GameScriptVector3 { float x; float y; float z; }; class LuaVariables { public: std::map variables; sol::object GetVariable(sol::table tab, std::string key); void SetVariable(sol::table tab, std::string key, sol::object value); }; struct LuaVariable { bool IsGlobal; std::string Name; int Type; float FloatValue; int IntValue; std::string StringValue; bool BoolValue; }; class GameScript : public LuaHandler { private: LuaVariables m_globals{}; LuaVariables m_locals{}; std::unordered_map m_itemsMapName{}; std::unordered_map m_meshesMapName{}; std::unordered_map m_camerasMapName{}; std::unordered_map m_sinksMapName{}; std::unordered_map m_soundSourcesMapName{}; std::unordered_map m_aiObjectsMapName{}; std::unordered_set m_levelFuncs{}; std::vector m_triggers{}; sol::protected_function m_onStart{}; sol::protected_function m_onLoad{}; sol::protected_function m_onControlPhase{}; sol::protected_function m_onSave{}; sol::protected_function m_onEnd{}; public: GameScript(sol::state* lua); void FreeLevelScripts(); void AddTrigger(LuaFunction* function); bool AddLuaNameItem(std::string const & luaName, short itemNumber); bool RemoveLuaNameItem(std::string const& luaName); bool AddLuaNameMesh(std::string const & luaName, MESH_INFO &); bool RemoveLuaNameMesh(std::string const& luaName); bool AddLuaNameCamera(std::string const & luaName, LEVEL_CAMERA_INFO &); bool RemoveLuaNameCamera(std::string const& luaName); bool AddLuaNameSink(std::string const & luaName, SINK_INFO &); bool RemoveLuaNameSink(std::string const& luaName); bool AddLuaNameSoundSource(std::string const& luaName, SOUND_SOURCE_INFO&); bool RemoveLuaNameSoundSource(std::string const& luaName); bool AddLuaNameAIObject(std::string const & luaName, AI_OBJECT &); bool RemoveLuaNameAIObject(std::string const& luaName); bool SetLevelFunc(sol::table tab, std::string const& luaName, sol::object obj); void AssignItemsAndLara(); bool ExecuteTrigger(short index); void ExecuteFunction(std::string const & name); void MakeItemInvisible(short id); std::unique_ptr GetItemByName(std::string const & name); std::unique_ptr GetMeshByName(std::string const & name); std::unique_ptr GetCameraByName(std::string const & name); std::unique_ptr GetSinkByName(std::string const & name); std::unique_ptr GetSoundSourceByName(std::string const & name); std::unique_ptr GetAIObjectByName(std::string const & name); // Variables template void GetVariables(std::map& locals, std::map& globals); template void SetVariables(std::map& locals, std::map& globals); void ResetVariables(); void InitCallbacks(); void OnStart(); void OnLoad(); void OnControlPhase(float dt); void OnSave(); void OnEnd(); };