2020-04-30 21:52:16 +02:00
|
|
|
#pragma once
|
2020-05-30 15:55:23 +02:00
|
|
|
#include "items.h"
|
2021-07-21 18:12:17 +01:00
|
|
|
#include "room.h"
|
2021-06-16 14:39:43 +01:00
|
|
|
#include "LuaHandler.h"
|
2021-06-29 05:00:15 +02:00
|
|
|
#include "trmath.h"
|
2021-08-06 16:47:24 +01:00
|
|
|
#include <unordered_set>
|
2021-06-29 05:28:17 +02:00
|
|
|
#include "GameScriptColor.h"
|
|
|
|
#include "GameScriptPosition.h"
|
|
|
|
#include "GameScriptRotation.h"
|
|
|
|
#include "GameScriptItemInfo.h"
|
2021-07-21 18:12:17 +01:00
|
|
|
#include "GameScriptMeshInfo.h"
|
2021-07-23 16:02:30 +01:00
|
|
|
#include "GameScriptSinkInfo.h"
|
2021-07-24 12:29:25 +01:00
|
|
|
#include "GameScriptAIObject.h"
|
|
|
|
#include "GameScriptSoundSourceInfo.h"
|
2021-07-23 02:09:52 +01:00
|
|
|
#include "GameScriptCameraInfo.h"
|
2020-04-30 21:52:16 +02:00
|
|
|
|
2021-07-18 15:22:15 +01:00
|
|
|
struct LuaFunction {
|
2020-06-18 15:54:08 +02:00
|
|
|
std::string Name;
|
|
|
|
std::string Code;
|
2020-04-30 21:52:16 +02:00
|
|
|
bool Executed;
|
|
|
|
};
|
|
|
|
|
2021-06-29 05:00:15 +02:00
|
|
|
struct GameScriptVector3 {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
|
|
|
};
|
|
|
|
|
2020-04-30 21:52:16 +02:00
|
|
|
|
|
|
|
class LuaVariables
|
|
|
|
{
|
|
|
|
public:
|
2020-06-20 23:39:08 +02:00
|
|
|
std::map<std::string, sol::object> variables;
|
2020-04-30 21:52:16 +02:00
|
|
|
|
2021-08-05 21:36:18 +01:00
|
|
|
sol::object GetVariable(sol::table tab, std::string key);
|
|
|
|
void SetVariable(sol::table tab, std::string key, sol::object value);
|
2020-04-30 21:52:16 +02:00
|
|
|
};
|
|
|
|
|
2021-07-18 15:22:15 +01:00
|
|
|
struct LuaVariable
|
2020-04-30 21:52:16 +02:00
|
|
|
{
|
|
|
|
bool IsGlobal;
|
2020-06-18 15:54:08 +02:00
|
|
|
std::string Name;
|
2020-04-30 21:52:16 +02:00
|
|
|
int Type;
|
|
|
|
float FloatValue;
|
|
|
|
int IntValue;
|
2020-06-18 15:54:08 +02:00
|
|
|
std::string StringValue;
|
2020-04-30 21:52:16 +02:00
|
|
|
bool BoolValue;
|
|
|
|
};
|
|
|
|
|
2021-08-27 18:21:37 +01:00
|
|
|
using VarMapVal = std::variant< short,
|
|
|
|
std::reference_wrapper<MESH_INFO>,
|
|
|
|
std::reference_wrapper<LEVEL_CAMERA_INFO>,
|
|
|
|
std::reference_wrapper<SINK_INFO>,
|
|
|
|
std::reference_wrapper<SOUND_SOURCE_INFO>,
|
|
|
|
std::reference_wrapper<AI_OBJECT>>;
|
|
|
|
|
2021-06-16 14:39:43 +01:00
|
|
|
class GameScript : public LuaHandler
|
2020-04-30 21:52:16 +02:00
|
|
|
{
|
|
|
|
private:
|
2021-08-27 18:21:37 +01:00
|
|
|
|
2021-08-06 16:47:24 +01:00
|
|
|
LuaVariables m_globals{};
|
|
|
|
LuaVariables m_locals{};
|
2021-08-27 18:21:37 +01:00
|
|
|
std::unordered_map<std::string, VarMapVal> m_nameMap{};
|
2021-08-06 16:47:24 +01:00
|
|
|
std::unordered_map<std::string, short> m_itemsMapName{};
|
|
|
|
std::unordered_set<std::string> m_levelFuncs{};
|
|
|
|
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{};
|
2021-08-23 02:02:47 +01:00
|
|
|
|
|
|
|
void ResetLevelTables();
|
|
|
|
|
2020-04-30 21:52:16 +02:00
|
|
|
public:
|
|
|
|
GameScript(sol::state* lua);
|
|
|
|
|
|
|
|
void FreeLevelScripts();
|
2021-07-24 12:29:25 +01:00
|
|
|
|
|
|
|
|
2021-08-05 21:36:18 +01:00
|
|
|
bool SetLevelFunc(sol::table tab, std::string const& luaName, sol::object obj);
|
2021-08-23 02:02:47 +01:00
|
|
|
sol::protected_function GetLevelFunc(sol::table tab, std::string const& luaName);
|
2021-08-05 21:36:18 +01:00
|
|
|
|
2020-04-30 21:52:16 +02:00
|
|
|
void AssignItemsAndLara();
|
|
|
|
|
2021-06-29 05:00:15 +02:00
|
|
|
|
2021-07-17 22:26:07 +01:00
|
|
|
void ExecuteFunction(std::string const & name);
|
2021-06-29 05:00:15 +02:00
|
|
|
void MakeItemInvisible(short id);
|
2021-07-23 02:09:52 +01:00
|
|
|
|
2021-08-27 18:21:37 +01:00
|
|
|
template <typename R, char const* S>
|
|
|
|
std::unique_ptr<R> GetByName(std::string const& name)
|
|
|
|
{
|
|
|
|
ScriptAssertF(m_nameMap.find(name) != m_nameMap.end(), "{} name not found: {}", S, name);
|
|
|
|
return std::make_unique<R>(std::get<R::IdentifierType>(m_nameMap.at(name)), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Value>
|
|
|
|
bool AddName(std::string const& key, Value&& val)
|
|
|
|
{
|
|
|
|
auto p = std::pair<std::string const&, Value>{ key, val };
|
|
|
|
return m_nameMap.insert(p).second;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RemoveName(std::string const& key)
|
|
|
|
{
|
|
|
|
return m_nameMap.erase(key);
|
|
|
|
}
|
2021-06-29 05:00:15 +02:00
|
|
|
|
|
|
|
// Variables
|
2020-06-09 04:16:51 -03:00
|
|
|
template <typename T>
|
2020-06-20 23:39:08 +02:00
|
|
|
void GetVariables(std::map<std::string, T>& locals, std::map<std::string, T>& globals);
|
2020-06-09 04:16:51 -03:00
|
|
|
template <typename T>
|
2020-06-20 23:39:08 +02:00
|
|
|
void SetVariables(std::map<std::string, T>& locals, std::map<std::string, T>& globals);
|
2021-06-29 05:00:15 +02:00
|
|
|
void ResetVariables();
|
|
|
|
|
2021-07-01 19:31:15 +01:00
|
|
|
|
2021-07-04 14:33:57 +01:00
|
|
|
void InitCallbacks();
|
|
|
|
void OnStart();
|
|
|
|
void OnLoad();
|
2021-08-12 18:20:14 +01:00
|
|
|
void OnControlPhase(float dt);
|
2021-07-04 14:33:57 +01:00
|
|
|
void OnSave();
|
|
|
|
void OnEnd();
|
2021-08-05 21:36:18 +01:00
|
|
|
};
|