mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-08-03 15:27:13 -04:00
Expose path grids to Lua
This commit is contained in:
parent
6dadf5de75
commit
183652e51d
@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
|
|||||||
set(OPENMW_VERSION_MAJOR 0)
|
set(OPENMW_VERSION_MAJOR 0)
|
||||||
set(OPENMW_VERSION_MINOR 50)
|
set(OPENMW_VERSION_MINOR 50)
|
||||||
set(OPENMW_VERSION_RELEASE 0)
|
set(OPENMW_VERSION_RELEASE 0)
|
||||||
set(OPENMW_LUA_API_REVISION 81)
|
set(OPENMW_LUA_API_REVISION 82)
|
||||||
set(OPENMW_POSTPROCESSING_API_REVISION 3)
|
set(OPENMW_POSTPROCESSING_API_REVISION 3)
|
||||||
|
|
||||||
set(OPENMW_VERSION_COMMITHASH "")
|
set(OPENMW_VERSION_COMMITHASH "")
|
||||||
|
@ -61,6 +61,10 @@ namespace sol
|
|||||||
struct is_automagical<MWLua::GCell> : std::false_type
|
struct is_automagical<MWLua::GCell> : std::false_type
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
template <>
|
||||||
|
struct is_automagical<ESM::Pathgrid> : std::false_type
|
||||||
|
{
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWLua
|
namespace MWLua
|
||||||
@ -126,6 +130,14 @@ namespace MWLua
|
|||||||
return sol::nullopt;
|
return sol::nullopt;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cellT["pathGrid"] = sol::readonly_property([](const CellT& c) -> const ESM::Pathgrid* {
|
||||||
|
const ESM::Pathgrid* grid
|
||||||
|
= MWBase::Environment::get().getESMStore()->get<ESM::Pathgrid>().search(*c.mStore->getCell());
|
||||||
|
if (grid && grid->mPoints.empty())
|
||||||
|
return nullptr;
|
||||||
|
return grid;
|
||||||
|
});
|
||||||
|
|
||||||
if constexpr (std::is_same_v<CellT, GCell>)
|
if constexpr (std::is_same_v<CellT, GCell>)
|
||||||
{ // only for global scripts
|
{ // only for global scripts
|
||||||
cellT["getAll"] = [ids = getPackageToTypeTable(view)](const CellT& cell, sol::optional<sol::table> type) {
|
cellT["getAll"] = [ids = getPackageToTypeTable(view)](const CellT& cell, sol::optional<sol::table> type) {
|
||||||
@ -286,6 +298,36 @@ namespace MWLua
|
|||||||
return GObjectList{ std::move(res) };
|
return GObjectList{ std::move(res) };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initCellBindingsForLocalScripts(const Context& context)
|
void initCellBindingsForLocalScripts(const Context& context)
|
||||||
|
@ -295,13 +295,14 @@
|
|||||||
-- @field #string id Unique record ID of the cell, based on cell name for interiors and the worldspace for exteriors, or the formID of the cell for ESM4 cells.
|
-- @field #string id Unique record ID of the cell, based on cell name for interiors and the worldspace for exteriors, or the formID of the cell for ESM4 cells.
|
||||||
-- @field #string region Region of the cell.
|
-- @field #string region Region of the cell.
|
||||||
-- @field #boolean isExterior Whether the cell is an exterior cell. "Exterior" means grid of cells where the player can seamless walk from one cell to another without teleports. QuasiExterior (interior with sky) is not an exterior.
|
-- @field #boolean isExterior Whether the cell is an exterior cell. "Exterior" means grid of cells where the player can seamless walk from one cell to another without teleports. QuasiExterior (interior with sky) is not an exterior.
|
||||||
-- @field #boolean isQuasiExterior (DEPRECATED, use `hasTag("QuasiExterior")`) Whether the cell is a quasi exterior (like interior but with the sky and the wheather).
|
-- @field #boolean isQuasiExterior (DEPRECATED, use `hasTag("QuasiExterior")`) Whether the cell is a quasi exterior (like interior but with the sky and the weather).
|
||||||
-- @field #number gridX Index of the cell by X (only for exteriors).
|
-- @field #number gridX Index of the cell by X (only for exteriors).
|
||||||
-- @field #number gridY Index of the cell by Y (only for exteriors).
|
-- @field #number gridY Index of the cell by Y (only for exteriors).
|
||||||
-- @field #string worldSpaceId Id of the world space.
|
-- @field #string worldSpaceId Id of the world space.
|
||||||
-- @field #boolean hasWater True if the cell contains water.
|
-- @field #boolean hasWater True if the cell contains water.
|
||||||
-- @field #number waterLevel The water level of the cell. (nil if cell has no water).
|
-- @field #number waterLevel The water level of the cell. (nil if cell has no water).
|
||||||
-- @field #boolean hasSky True if in this cell sky should be rendered.
|
-- @field #boolean hasSky True if in this cell sky should be rendered.
|
||||||
|
-- @field #PathGrid pathGrid The cell's @{#PathGrid} if it has one.
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Returns true if the cell has given tag.
|
-- Returns true if the cell has given tag.
|
||||||
@ -334,6 +335,23 @@
|
|||||||
-- local all = cell:getAll()
|
-- local all = cell:getAll()
|
||||||
-- local weapons = cell:getAll(types.Weapon)
|
-- local weapons = cell:getAll(types.Weapon)
|
||||||
|
|
||||||
|
---
|
||||||
|
-- A cell's path grid marking traversable paths.
|
||||||
|
-- @type PathGrid
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Get all points in this path grid.
|
||||||
|
-- @function [parent=#PathGrid] getPoints
|
||||||
|
-- @param self
|
||||||
|
-- @return #list<#PathGridPoint> A list of @{#PathGridPoint}s.
|
||||||
|
|
||||||
|
---
|
||||||
|
-- A point in a cell's path grid.
|
||||||
|
-- @type PathGridPoint
|
||||||
|
-- @field #boolean autoGenerated True if this node was automatically generated in the editor.
|
||||||
|
-- @field openmw.util#Vector3 relativePosition The point's position relative to the cell's origin. An exterior cell's origin is its southwest corner.
|
||||||
|
-- @field #list<#PathGridPoint> connections A list of points connected to this point.
|
||||||
|
|
||||||
---
|
---
|
||||||
-- @type ActiveSpell
|
-- @type ActiveSpell
|
||||||
-- @field #string name The spell or item display name
|
-- @field #string name The spell or item display name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user