Some improvements, added cutscene stub
This commit is contained in:
1 parent
72e05cdc28
commit
be05643b70
27 files changed
+3480
-40
No files matched your search
@@ -14,6 +14,7 @@ namespace ZL {
|
||||
sol::state lua;
|
||||
std::unordered_map<std::string, sol::protected_function> triggerEnterCallbacks;
|
||||
std::unordered_map<std::string, sol::protected_function> triggerExitCallbacks;
|
||||
std::unordered_map<std::string, sol::protected_function> cutsceneCompleteCallbacks;
|
||||
};
|
||||
|
||||
ScriptEngine::ScriptEngine() = default;
|
||||
@@ -118,6 +119,21 @@ namespace ZL {
|
||||
}
|
||||
});
|
||||
|
||||
// start_cutscene(cutscene_id)
|
||||
api.set_function("start_cutscene",
|
||||
[game](const std::string& cutsceneId) {
|
||||
if (!game->requestCutsceneStart(cutsceneId))
|
||||
std::cerr << "[script] start_cutscene failed for id: " << cutsceneId << "\n";
|
||||
});
|
||||
|
||||
// set_cutscene_callback(cutscene_id, on_complete)
|
||||
// on_complete() is called with no arguments when the named cutscene finishes.
|
||||
api.set_function("set_cutscene_callback",
|
||||
[this_impl = impl.get()](const std::string& cutsceneId, sol::object onComplete) {
|
||||
if (onComplete.is<sol::protected_function>())
|
||||
this_impl->cutsceneCompleteCallbacks[cutsceneId] = onComplete.as<sol::protected_function>();
|
||||
});
|
||||
|
||||
api.set_function("set_dialogue_flag",
|
||||
[game](const std::string& flag, int value) {
|
||||
game->setDialogueFlag(flag, value);
|
||||
@@ -154,6 +170,17 @@ namespace ZL {
|
||||
this_impl->triggerExitCallbacks[zoneId] = onExit.as<sol::protected_function>();
|
||||
});
|
||||
|
||||
// set_npc_enabled(index, enabled)
|
||||
api.set_function("set_npc_enabled",
|
||||
[game](int index, bool value) {
|
||||
auto& npcs = game->npcs;
|
||||
if (index < 0 || index >= static_cast<int>(npcs.size())) {
|
||||
std::cerr << "[script] set_npc_enabled: index " << index << " out of range\n";
|
||||
return;
|
||||
}
|
||||
npcs[index]->enabled = value;
|
||||
});
|
||||
|
||||
// receive_npc_gift(npc_index)
|
||||
api.set_function("receive_npc_gift", [game, inventory](int npcIndex) {
|
||||
std::cout << "[script] receive_npc_gift: npc index " << npcIndex << std::endl;
|
||||
@@ -297,4 +324,16 @@ namespace ZL {
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::callCutsceneCompleteCallback(const std::string& cutsceneId) {
|
||||
if (!impl) return;
|
||||
auto it = impl->cutsceneCompleteCallbacks.find(cutsceneId);
|
||||
if (it == impl->cutsceneCompleteCallbacks.end()) return;
|
||||
auto result = it->second();
|
||||
if (!result.valid()) {
|
||||
sol::error err = result;
|
||||
std::cerr << "[SCRIPT] cutscene complete callback error for '"
|
||||
<< cutsceneId << "': " << err.what() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ZL
|
||||
Reference in new issue
Block a user