Working on doors and scripting
This commit is contained in:
1 parent
774397f690
commit
0f2b2e55af
11 files changed
+322
-9
No files matched your search
@@ -185,6 +185,88 @@ namespace ZL {
|
||||
npcs[index]->enabled = value;
|
||||
});
|
||||
|
||||
// move_object(name, x, y, z, duration_sec [, on_complete])
|
||||
api.set_function("move_object",
|
||||
[game](const std::string& name, float x, float y, float z,
|
||||
float durationSec, sol::object onComplete) {
|
||||
for (auto& intObj : game->interactiveObjects) {
|
||||
if (intObj.loadedObject.name != name) continue;
|
||||
if (intObj.isAnimating) {
|
||||
std::cerr << "[script] move_object: '" << name << "' is already animating\n";
|
||||
return;
|
||||
}
|
||||
std::function<void()> cb;
|
||||
if (onComplete.is<sol::protected_function>()) {
|
||||
sol::protected_function fn = onComplete.as<sol::protected_function>();
|
||||
cb = [fn]() mutable {
|
||||
auto res = fn();
|
||||
if (!res.valid()) {
|
||||
sol::error err = res;
|
||||
std::cerr << "[script] move_object on_complete error: " << err.what() << "\n";
|
||||
}
|
||||
};
|
||||
}
|
||||
intObj.moveTo(Eigen::Vector3f(x, y, z), durationSec, std::move(cb));
|
||||
return;
|
||||
}
|
||||
std::cerr << "[script] move_object: object '" << name << "' not found\n";
|
||||
});
|
||||
|
||||
// rotate_object(name, angle_deg, duration_sec [, on_complete])
|
||||
api.set_function("rotate_object",
|
||||
[game](const std::string& name, float angleDeg,
|
||||
float durationSec, sol::object onComplete) {
|
||||
for (auto& intObj : game->interactiveObjects) {
|
||||
if (intObj.loadedObject.name != name) continue;
|
||||
if (intObj.isAnimating) {
|
||||
std::cerr << "[script] rotate_object: '" << name << "' is already animating\n";
|
||||
return;
|
||||
}
|
||||
std::function<void()> cb;
|
||||
if (onComplete.is<sol::protected_function>()) {
|
||||
sol::protected_function fn = onComplete.as<sol::protected_function>();
|
||||
cb = [fn]() mutable {
|
||||
auto res = fn();
|
||||
if (!res.valid()) {
|
||||
sol::error err = res;
|
||||
std::cerr << "[script] rotate_object on_complete error: " << err.what() << "\n";
|
||||
}
|
||||
};
|
||||
}
|
||||
const float angleRad = angleDeg * static_cast<float>(M_PI) / 180.f;
|
||||
intObj.rotateTo(intObj.rotationY + angleRad, durationSec, std::move(cb));
|
||||
return;
|
||||
}
|
||||
std::cerr << "[script] rotate_object: object '" << name << "' not found\n";
|
||||
});
|
||||
|
||||
// scale_object(name, target_scale, duration_sec [, on_complete])
|
||||
api.set_function("scale_object",
|
||||
[game](const std::string& name, float targetScale,
|
||||
float durationSec, sol::object onComplete) {
|
||||
for (auto& intObj : game->interactiveObjects) {
|
||||
if (intObj.loadedObject.name != name) continue;
|
||||
if (intObj.isAnimating) {
|
||||
std::cerr << "[script] scale_object: '" << name << "' is already animating\n";
|
||||
return;
|
||||
}
|
||||
std::function<void()> cb;
|
||||
if (onComplete.is<sol::protected_function>()) {
|
||||
sol::protected_function fn = onComplete.as<sol::protected_function>();
|
||||
cb = [fn]() mutable {
|
||||
auto res = fn();
|
||||
if (!res.valid()) {
|
||||
sol::error err = res;
|
||||
std::cerr << "[script] scale_object on_complete error: " << err.what() << "\n";
|
||||
}
|
||||
};
|
||||
}
|
||||
intObj.scaleTo(targetScale, durationSec, std::move(cb));
|
||||
return;
|
||||
}
|
||||
std::cerr << "[script] scale_object: object '" << name << "' not found\n";
|
||||
});
|
||||
|
||||
lua.script_file(scriptPath);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user