载入中...
搜索中...
未找到
LocationProfileBindings.cpp
浏览该文件的文档.
2
5
6#include <simplesquirrel/simplesquirrel.hpp>
7
8namespace eve::scene {
9namespace {
10eve::Value poseValue(const LocationPose& p) {
11 return eve::Value::Object{{"x", p.x}, {"y", p.y}, {"z", p.z}, {"qx", p.qx}, {"qy", p.qy},
12 {"qz", p.qz}, {"qw", p.qw}};
13}
14eve::Value snapshotValue(const LocationSnapshot& s) {
15 eve::Value::Object value{{"camera", poseValue(s.camera)}, {"hasPlayer", bool(s.player)}};
16 value["player"] = s.player ? poseValue(*s.player) : eve::Value();
17 return value;
18}
19}
20
21void exposeLocationProfileBindings(ssq::Table& table) {
22 auto pose = table.addClass("LocationPose", ssq::Class::Ctor<LocationPose()>());
23 pose.addVar("x", &LocationPose::x); pose.addVar("y", &LocationPose::y); pose.addVar("z", &LocationPose::z);
24 pose.addVar("qx", &LocationPose::qx); pose.addVar("qy", &LocationPose::qy); pose.addVar("qz", &LocationPose::qz);
25 pose.addVar("qw", &LocationPose::qw);
26 auto bookmark = table.addClass("LocationBookmark", ssq::Class::Ctor<LocationBookmark()>());
27 bookmark.addVar("name", &LocationBookmark::name);
28 bookmark.addVar("controller", &LocationBookmark::controller);
29 bookmark.addVar("scene", &LocationBookmark::scene);
30 bookmark.addFunc("setCamera", [](LocationBookmark* b, const LocationPose* p) { if (b && p) b->camera = *p; });
31 bookmark.addFunc("setPlayer", [](LocationBookmark* b, const LocationPose* p) { if (b && p) b->player = *p; });
32 bookmark.addFunc("clearPlayer", [](LocationBookmark* b) { if (b) b->player.reset(); });
33
34 auto profile = table.addClass("LocationProfile", ssq::Class::Ctor<LocationProfile()>());
35 profile.addFunc("hasSavedLocation", [](const LocationProfile* p) { return p && p->hasSavedLocation(); });
36 profile.addFunc("getBookmarkCount", [](const LocationProfile* p) { return p ? p->getBookmarkCount() : 0; });
37 profile.addFunc("clearBookmarks", [](LocationProfile* p) { if (p) p->clearBookmarks(); });
38 profile.addFunc("serializeJson", [vm=table.getHandle()](const LocationProfile* p) {
39 auto r=p?p->serializeJson():Result<std::string>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile required"));
40 return eve::script::projectResult(vm,std::move(r),[](const std::string& v){return eve::Value(v);});
41 });
42 profile.addFunc("restoreJson", [vm=table.getHandle()](LocationProfile* p,const std::string& json) {
43 auto r=p?p->restoreJson(json):Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile required"));
44 return eve::script::projectResult(vm,std::move(r));
45 });
46 profile.addFunc("saveLocation", [vm=table.getHandle()](LocationProfile* p, const LocationPose* camera) {
47 return eve::script::projectResult(vm, p && camera ? p->saveLocation(*camera)
48 : Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"location profile and camera required")));
49 });
50 profile.addFunc("saveLocationWithPlayer", [vm=table.getHandle()](LocationProfile* p, const LocationPose* camera,
51 const LocationPose* player) {
52 return eve::script::projectResult(vm, p && camera && player ? p->saveLocation(*camera,*player)
53 : Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile, camera and player required")));
54 });
55 profile.addFunc("loadLocation", [vm=table.getHandle()](LocationProfile* p) {
57 return eve::script::projectResult(vm,std::move(r),[](const LocationSnapshot& s){return snapshotValue(s);});
58 });
59 profile.addFunc("addBookmark", [vm=table.getHandle()](LocationProfile* p, const LocationBookmark* b) {
60 auto r=p&&b?p->addBookmark(*b):Result<int>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile and bookmark required"));
61 return eve::script::projectResult(vm,std::move(r),[](int v){return eve::Value(v);});
62 });
63 profile.addFunc("loadBookmark", [vm=table.getHandle()](const LocationProfile* p,int i) {
65 return eve::script::projectResult(vm,std::move(r),[](const LocationSnapshot& s){return snapshotValue(s);});
66 });
67 profile.addFunc("removeBookmark", [vm=table.getHandle()](LocationProfile* p,int i,int selected) {
68 auto r=p?p->removeBookmark(i,selected):Result<int>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile required"));
69 return eve::script::projectResult(vm,std::move(r),[](int v){return eve::Value(v);});
70 });
71 profile.addFunc("getBookmarkName", [vm=table.getHandle()](const LocationProfile* p,int i) {
72 auto r=p?p->getBookmarkName(i):Result<std::string>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile required"));
73 return eve::script::projectResult(vm,std::move(r),[](const std::string& v){return eve::Value(v);});
74 });
75 profile.addFunc("getBookmarkController", [vm=table.getHandle()](const LocationProfile* p,int i) {
76 auto r=p?p->getBookmarkController(i):Result<std::string>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile required"));
77 return eve::script::projectResult(vm,std::move(r),[](const std::string& v){return eve::Value(v);});
78 });
79 profile.addFunc("getBookmarkScene", [vm=table.getHandle()](const LocationProfile* p,int i) {
80 auto r=p?p->getBookmarkScene(i):Result<std::string>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile required"));
81 return eve::script::projectResult(vm,std::move(r),[](const std::string& v){return eve::Value(v);});
82 });
83 profile.addFunc("overrideBookmark", [vm=table.getHandle()](LocationProfile* p,int i,const LocationBookmark* b) {
84 auto r=p&&b?p->overrideBookmark(i,LocationSnapshot{b->camera,b->player},b->controller,b->scene)
86 return eve::script::projectResult(vm,std::move(r));
87 });
88 profile.addFunc("previousBookmark", [vm=table.getHandle()](const LocationProfile* p,int i) {
89 auto r=p?p->previousBookmark(i):Result<int>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile required"));
90 return eve::script::projectResult(vm,std::move(r),[](int v){return eve::Value(v);});
91 });
92 profile.addFunc("nextBookmark", [vm=table.getHandle()](const LocationProfile* p,int i) {
93 auto r=p?p->nextBookmark(i):Result<int>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"profile required"));
94 return eve::script::projectResult(vm,std::move(r),[](int v){return eve::Value(v);});
95 });
96}
97} // namespace eve::scene
double value
eve::EntitySpatialPose pose
const std::string & s
glm::vec4 p[6]
HSQUIRRELVM vm
Definition ECS.cpp:20
float camera[2]
double r
float v
MeleePoint3 b
Definition MeleeHit.cpp:41
The single Squirrel projection for common Result, Status and Value.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
Caller-owned Pcg location and bookmark state. Mutable operations validate complete candidate data bef...
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:26
void exposeLocationProfileBindings(ssq::Table &table)
Register Pcg location profile value types and operations.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
One named Pcg location bookmark with optional player transform metadata.
Provider-neutral position and quaternion stored by Pcg's location profile.
Loaded camera/player transform pair.