1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-15 08:26:37 +00:00

Use Context::initializeOnce

This commit is contained in:
Evil Eye 2025-07-17 16:42:24 +02:00
parent 183652e51d
commit b61d8fb585

View file

@ -299,35 +299,33 @@ namespace MWLua
};
}
if (view["openmw_cellbindings"] != sol::nil)
return; // Only add the usertype once
auto pathGridT = view.new_usertype<ESM::Pathgrid>("ESM3_PathGrid");
pathGridT[sol::meta_function::to_string] = [](const ESM::Pathgrid& rec) -> std::string {
return "ESM3_PathGrid[" + rec.mCell.toDebugString() + "]";
};
pathGridT["getPoints"] = [](sol::this_state lua, const ESM::Pathgrid& rec) -> sol::table {
sol::table points(lua, sol::create);
for (const ESM::Pathgrid::Point& point : rec.mPoints)
{
sol::table table(lua, sol::create);
table["autoGenerated"] = point.mAutogenerated == 0;
table["relativePosition"] = osg::Vec3f(point.mX, point.mY, point.mZ);
sol::table edges(lua, sol::create);
table["connections"] = edges;
points.add(table);
}
for (const ESM::Pathgrid::Edge& edge : rec.mEdges)
{
sol::table p1 = points[edge.mV0 + 1];
sol::table p2 = points[edge.mV1 + 1];
p1.get<sol::table>("connections").add(p2);
p2.get<sol::table>("connections").add(p1);
}
return points;
};
view["openmw_cellbindings"] = true;
if (context.initializeOnce("openmw_cellbindings"))
{
auto pathGridT = view.new_usertype<ESM::Pathgrid>("ESM3_PathGrid");
pathGridT[sol::meta_function::to_string] = [](const ESM::Pathgrid& rec) -> std::string {
return "ESM3_PathGrid[" + rec.mCell.toDebugString() + "]";
};
pathGridT["getPoints"] = [](sol::this_state lua, const ESM::Pathgrid& rec) -> sol::table {
sol::table points(lua, sol::create);
for (const ESM::Pathgrid::Point& point : rec.mPoints)
{
sol::table table(lua, sol::create);
table["autoGenerated"] = point.mAutogenerated == 0;
table["relativePosition"] = osg::Vec3f(point.mX, point.mY, point.mZ);
sol::table edges(lua, sol::create);
table["connections"] = edges;
points.add(table);
}
for (const ESM::Pathgrid::Edge& edge : rec.mEdges)
{
sol::table p1 = points[edge.mV0 + 1];
sol::table p2 = points[edge.mV1 + 1];
p1.get<sol::table>("connections").add(p2);
p2.get<sol::table>("connections").add(p1);
}
return points;
};
}
}
void initCellBindingsForLocalScripts(const Context& context)