Working on dialog editor, on dialogs, on phone
This commit is contained in:
1 parent
0e27521bea
commit
8f7797789d
63 files changed
+9502
-1459
No files matched your search
@@ -26,6 +26,7 @@ namespace ZL {
|
||||
sol::protected_function darklandsEnterCallback;
|
||||
sol::protected_function darklandsExitCallback;
|
||||
sol::protected_function triggerNightEnterCallback;
|
||||
sol::protected_function chatOpenCallbacks[3];
|
||||
};
|
||||
|
||||
ScriptEngine::ScriptEngine() = default;
|
||||
@@ -65,6 +66,44 @@ namespace ZL {
|
||||
npcs[index]->setTarget(Eigen::Vector3f(x, y, z), std::move(cb));
|
||||
});
|
||||
|
||||
api.set_function("player_walk_to",
|
||||
[game](float x, float y, float z, sol::object on_arrived) {
|
||||
|
||||
std::function<void()> cb;
|
||||
if (on_arrived.is<sol::protected_function>()) {
|
||||
sol::protected_function fn = on_arrived.as<sol::protected_function>();
|
||||
cb = [fn]() mutable {
|
||||
auto result = fn();
|
||||
if (!result.valid()) {
|
||||
sol::error err = result;
|
||||
std::cerr << "[script] on_arrived error: " << err.what() << "\n";
|
||||
}
|
||||
};
|
||||
}
|
||||
game->player->homePosition = Eigen::Vector3f(x, 0.f, z);
|
||||
game->player->setTarget(Eigen::Vector3f(x, y, z), std::move(cb));
|
||||
});
|
||||
|
||||
|
||||
api.set_function("has_item", [inventory](const std::string& itemId) {
|
||||
const Item* item = ItemRegistry::instance().findById(itemId);
|
||||
if (item) {
|
||||
if (inventory->hasItem(itemId)) {
|
||||
std::cout << "[script] has_item: " << item->name << " returns true" << std::endl;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "[script] has_item: " << item->name << " returns false" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
std::cerr << "[script] has_item: item '" << itemId << "' not found in ItemRegistry\n";
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// pickup_item(item_id)
|
||||
api.set_function("pickup_item", [inventory](const std::string& itemId) {
|
||||
const Item* item = ItemRegistry::instance().findById(itemId);
|
||||
@@ -229,6 +268,11 @@ namespace ZL {
|
||||
return game->isNight;
|
||||
});
|
||||
|
||||
api.set_function("is_dawn",
|
||||
[game]() {
|
||||
return game->isDawn;
|
||||
});
|
||||
|
||||
// advance_darklands_hud()
|
||||
// Advances the uni_interior darklands HUD from step12 to step13.
|
||||
// Call when the player enters the ghost trigger zone in darklands.
|
||||
@@ -319,6 +363,19 @@ namespace ZL {
|
||||
this_impl->darklandsExitCallback = onExit.as<sol::protected_function>();
|
||||
});
|
||||
|
||||
api.set_function("close_phone",
|
||||
[game]() {
|
||||
if (game->requestClosePhone)
|
||||
game->requestClosePhone();
|
||||
});
|
||||
|
||||
api.set_function("set_chat_callbacks",
|
||||
[this_impl = impl.get()](sol::object cb0, sol::object cb1, sol::object cb2) {
|
||||
if (cb0.is<sol::protected_function>()) this_impl->chatOpenCallbacks[0] = cb0.as<sol::protected_function>();
|
||||
if (cb1.is<sol::protected_function>()) this_impl->chatOpenCallbacks[1] = cb1.as<sol::protected_function>();
|
||||
if (cb2.is<sol::protected_function>()) this_impl->chatOpenCallbacks[2] = cb2.as<sol::protected_function>();
|
||||
});
|
||||
|
||||
api.set_function("set_enter_night_callback",
|
||||
[this_impl = impl.get()](sol::object onEnter) {
|
||||
if (onEnter.is<sol::protected_function>())
|
||||
@@ -357,6 +414,7 @@ namespace ZL {
|
||||
}
|
||||
Eigen::Vector3f pos(x, y, z);
|
||||
npcs[index]->position = pos;
|
||||
npcs[index]->homePosition = pos;
|
||||
npcs[index]->setTarget(pos);
|
||||
});
|
||||
|
||||
@@ -790,6 +848,18 @@ namespace ZL {
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::callChatOpenCallback(int chatIndex) {
|
||||
if (!impl) return;
|
||||
if (chatIndex < 0 || chatIndex > 2) return;
|
||||
auto& fn = impl->chatOpenCallbacks[chatIndex];
|
||||
if (!fn.valid()) return;
|
||||
auto result = fn();
|
||||
if (!result.valid()) {
|
||||
sol::error err = result;
|
||||
std::cerr << "[SCRIPT] chat open callback error for chat " << chatIndex << ": " << err.what() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::callNpcBumpsPlayerCallback(int npcIndex) {
|
||||
if (!impl) return;
|
||||
auto it = impl->npcBumpsPlayerCallbacks.find(npcIndex);
|
||||
|
||||
Reference in new issue
Block a user