#pragma once #include #include #include struct World; struct ClientRpcCalls; struct PlayerEnterWorldEvent; namespace Resources { struct ResourceCollection; } struct ScriptService { ScriptService(World& aWorld, entt::dispatcher& aDispatcher); ~ScriptService(); TP_NOCOPYMOVE(ScriptService); void Initialize(Resources::ResourceCollection& aCollection) noexcept; bool LoadScript(const std::filesystem::path& aPath); std::tuple HandlePlayerJoin(const ConnectionId_t aEntity) noexcept; std::tuple HandleCharacterMove(const entt::entity aNpc) noexcept; std::tuple HandleCharacterSpawn(const entt::entity aPlayer) noexcept; std::tuple HandleCharacterDestoy(const entt::entity aPlayer) noexcept; std::tuple HandleChatMessage(const entt::entity aSender, const String& aMessage) noexcept; void HandlePlayerQuit(ConnectionId_t aConnectionId, Server::EDisconnectReason aReason) noexcept; std::tuple HandleSetTime(int aHours, int aMinutes, float aTimeScale) noexcept; protected: // void RegisterExtensions(ScriptContext& aContext) override; void OnUpdate(const UpdateEvent& acEvent) noexcept; void OnPlayerEnterWorld(const PlayerEnterWorldEvent& acEvent) noexcept; // void BindStaticFunctions(ScriptContext& aContext) noexcept; // void BindTypes(ScriptContext& aContext) noexcept; void AddEventHandler(std::string acName, sol::function acFunction) noexcept; void CancelEvent(std::string aReason) noexcept; template std::tuple CallCancelableEvent(const String& acName, Args&&... args) noexcept; template void CallEvent(const String& acName, Args&&... args) noexcept; private: void BindInbuiltFunctions(); private: using TCallbacks = Vector; World& m_world; bool m_eventCanceled{}; String m_cancelReason; entt::scoped_connection m_updateConnection; entt::scoped_connection m_rpcCallsRequest; entt::scoped_connection m_playerEnterWorldConnection; // NOTE(Vince): keep in mind that cxx specifies construction and deconstruction order, // so do not touch this order of member variables TiltedPhoques::Lockable m_lua; Map m_callbacks; TiltedPhoques::Vector m_sandboxes; sol::table m_globals{}; }; #include "ScriptService.inl"