#pragma once #include #include #include "external/nlohmann/json.hpp" #include "ISaveable.h" #include "AudioPlayerAsync.h" namespace FRG { class Location; class ScriptEngine { public: ScriptEngine(); ~ScriptEngine(); // Must be called once, after the Game's NPCs are ready. void init(Location* game, AudioPlayerAsync* audioPlayer, const std::string& scriptPath); // Execute a Lua script file. Logs errors to stderr. //void runScript(const std::string& path); void callItemPickupCallback(const std::string& objectName); void callFunction(const std::string& functionName); void callActivateFunction(const std::string& functionName); void callNpcInteractCallback(const std::string& npcId); void callTriggerEnterCallback(const std::string& zoneId); void callTriggerExitCallback(const std::string& zoneId); // Fired when the player (moving) physically bumps into a standing NPC. void callNpcBumpedByPlayerCallback(const std::string& npcId); // Fired when a moving NPC physically bumps into the standing player. void callNpcBumpsPlayerCallback(const std::string& npcId); void callLocationInitCallback(); void callLocationEnterCallback(); void callLocationExitCallback(); void callDarklandsEnterCallback(); void callDarklandsExitCallback(); void callTriggerNightEnterCallback(); void callCutsceneCompleteCallback(const std::string& cutsceneId); void callChatOpenCallback(int chatIndex); void callCallTaxiCallback(); // Serialise all Lua global scalars (numbers, strings, booleans) to JSON. // Complex types (functions, tables, userdata) are skipped — they are recreated // by re-running the script on load. void saveScriptGlobals(nlohmann::json& out) const; // Restore previously saved scalar globals. Call after init() so the script // has already run and registered all callbacks. void loadScriptGlobals(const nlohmann::json& in); void save(nlohmann::json& out) const { saveScriptGlobals(out); } void load(const nlohmann::json& in) { loadScriptGlobals(in); } private: struct Impl; std::unique_ptr impl; }; } // namespace FRG