TombEngine/TombEngine/Scripting/Internal/ScriptInterfaceState.cpp
TrainWrack d19d56acee
Collision Class (#1579)
* First Commit

* Make ScriptCollision class

* Fix typo

* Return correct types

* Use NO_HEIGHT

* Implement GetSurfaceMaterial

* Add enums

* Added death, climbable wall, monkeybar

* FIx angle

* Revise things

* Make "Collision" script module; add IsOutOfBounds() method

* Rename IsOutOfBounds()

* Allow getting floor or ceiling material type

* Don't need IsWall()

* Update Collision.cpp

* Restore IsWall()

* Rename class to "Probe"; start docs; make steepness inquirers return an optional

* Update Probe.cpp

* Update class name in doc

* Update Probe.cpp

* add GetRoomName

* UpdateEnums

* Update MaterialType enum; make room name getting more local

* Revise constructors; update doc

* Update Probe.cpp

* Generate html docs

* Slightly clearer doc comments

* Convert spaces to tabs

* Update Probe.cpp

* Update Probe.cpp

* Rename parameters

* Update Probe.cpp

* ScriptProbe -> Probe

* ExposeGetRoom

* Register Collision.MaterialType table; Enable ClimbWall again.

* Cleanup

* Docs revision

* Update CHANGELOG.md

* Moved names to script reserved names

* Fixed incorrect namespace for probe

* Use consistent names; cleanup

* Make argument optional; fix doc

* Update Probe.cpp

* Add missing includes

* Add Preview() method; update docs

* Add constant

---------

Co-authored-by: Sezz <sezzary@outlook.com>
Co-authored-by: Lwmte <3331699+Lwmte@users.noreply.github.com>
2025-03-05 10:13:48 +02:00

65 lines
2.3 KiB
C++

#include "framework.h"
#include "Scripting/Include/ScriptInterfaceState.h"
#include "Scripting/Internal/ReservedScriptNames.h"
#include "Scripting/Internal/TEN/Collision/Probe.h"
#include "Scripting/Internal/TEN/Effects/EffectsFunctions.h"
#include "Scripting/Internal/TEN/Flow/FlowHandler.h"
#include "Scripting/Internal/TEN/Input/InputHandler.h"
#include "Scripting/Internal/TEN/Inventory/InventoryHandler.h"
#include "Scripting/Internal/TEN/Logic/LogicHandler.h"
#include "Scripting/Internal/TEN/Objects/ObjectsHandler.h"
#include "Scripting/Internal/TEN/Strings/StringsHandler.h"
#include "Scripting/Internal/TEN/Sound/SoundHandler.h"
#include "Scripting/Internal/TEN/Util/Util.h"
#include "Scripting/Internal/TEN/View/ViewHandler.h"
static sol::state SolState;
static sol::table RootTable;
int lua_exception_handler(lua_State* luaStatePtr, sol::optional<const std::exception&> exception, sol::string_view description)
{
return luaL_error(luaStatePtr, description.data());
}
ScriptInterfaceGame* ScriptInterfaceState::CreateGame()
{
return new LogicHandler(&SolState, RootTable);
}
ScriptInterfaceFlowHandler* ScriptInterfaceState::CreateFlow()
{
return new FlowHandler(&SolState, RootTable);
}
ScriptInterfaceObjectsHandler* ScriptInterfaceState::CreateObjectsHandler()
{
return new ObjectsHandler(&SolState, RootTable);
}
ScriptInterfaceStringsHandler* ScriptInterfaceState::CreateStringsHandler()
{
return new StringsHandler(&SolState, RootTable);
}
void ScriptInterfaceState::Init(const std::string& assetsDir)
{
SolState.open_libraries(
sol::lib::base, sol::lib::math, sol::lib::package, sol::lib::coroutine,
sol::lib::table, sol::lib::string, sol::lib::debug);
SolState.script("package.path=\"" + assetsDir + "Scripts/?.lua\"");
SolState.set_exception_handler(lua_exception_handler);
RootTable = sol::table(SolState.lua_state(), sol::create);
SolState.set(ScriptReserved_TEN, RootTable);
// Misc. handlers not assigned above.
TEN::Scripting::InventoryHandler::Register(&SolState, RootTable);
TEN::Scripting::Collision::Register(&SolState, RootTable);
TEN::Scripting::Effects::Register(&SolState, RootTable);
TEN::Scripting::Input::Register(&SolState, RootTable);
TEN::Scripting::Sound::Register(&SolState, RootTable);
TEN::Scripting::Util::Register(&SolState, RootTable);
TEN::Scripting::View::Register(&SolState, RootTable);
}