mirror of
https://github.com/OpenMW/openmw.git
synced 2026-01-24 19:30:54 +00:00
Add Lua API for map overwrite flag and existing map IDs
This commit is contained in:
parent
e8d844e7e5
commit
a89bd0e40e
4 changed files with 91 additions and 1 deletions
|
|
@ -613,6 +613,9 @@ namespace MWBase
|
|||
virtual std::string getLocalMapOutputPath() const = 0;
|
||||
///< Get the local map output path from options or default
|
||||
|
||||
virtual bool getOverwriteMaps() const = 0;
|
||||
///< Get the overwrite maps flag
|
||||
|
||||
virtual void extractWorldMap() = 0;
|
||||
///< Extract world map using path from options or default
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "worldbindings.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <components/esm3/loadacti.hpp>
|
||||
#include <components/esm3/loadalch.hpp>
|
||||
#include <components/esm3/loadarmo.hpp>
|
||||
|
|
@ -301,6 +303,49 @@ namespace MWLua
|
|||
return MWBase::Environment::get().getWorld()->isMapExtractionActive();
|
||||
};
|
||||
|
||||
api["getOverwriteFlag"] = [lua = context.mLua]() -> bool {
|
||||
checkGameInitialized(lua);
|
||||
return MWBase::Environment::get().getWorld()->getOverwriteMaps();
|
||||
};
|
||||
|
||||
api["getExistingLocalMapIds"] = [lua = context.mLua](sol::this_state luaState) -> sol::table {
|
||||
checkGameInitialized(lua);
|
||||
sol::state_view state(luaState);
|
||||
sol::table result = state.create_table();
|
||||
|
||||
std::string localMapPath = MWBase::Environment::get().getWorld()->getLocalMapOutputPath();
|
||||
std::filesystem::path dir(localMapPath);
|
||||
|
||||
if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir))
|
||||
return result;
|
||||
|
||||
// Use set to store unique filenames (without extension)
|
||||
std::set<std::string> uniqueNames;
|
||||
|
||||
for (const auto& entry : std::filesystem::directory_iterator(dir))
|
||||
{
|
||||
if (entry.is_regular_file())
|
||||
{
|
||||
std::string ext = entry.path().extension().string();
|
||||
// Check for .yaml, .png, or .tga extensions
|
||||
if (ext == ".yaml" || ext == ".png" || ext == ".tga")
|
||||
{
|
||||
std::string filename = entry.path().stem().string();
|
||||
uniqueNames.insert(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert set to lua table
|
||||
int index = 1;
|
||||
for (const auto& name : uniqueNames)
|
||||
{
|
||||
result[index++] = name;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
return LuaUtil::makeReadOnly(api);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -689,7 +689,7 @@ namespace MWWorld
|
|||
|
||||
std::string getWorldMapOutputPath() const override { return mWorldMapOutputPath; }
|
||||
std::string getLocalMapOutputPath() const override { return mLocalMapOutputPath; }
|
||||
bool getOverwriteMaps() const { return mOverwriteMaps; }
|
||||
bool getOverwriteMaps() const override { return mOverwriteMaps; }
|
||||
|
||||
void extractWorldMap() override;
|
||||
void extractLocalMaps() override;
|
||||
|
|
|
|||
|
|
@ -265,5 +265,47 @@
|
|||
-- print("Map extraction already in progress")
|
||||
-- end
|
||||
|
||||
---
|
||||
-- Get the overwrite maps flag from command line options.
|
||||
-- Returns true if the --overwrite-maps option was specified, false otherwise.
|
||||
-- This flag determines whether existing map files should be overwritten during extraction.
|
||||
-- @function [parent=#world] getOverwriteFlag
|
||||
-- @return #boolean true if overwrite is enabled, false otherwise
|
||||
-- @usage
|
||||
-- if world.getOverwriteFlag() then
|
||||
-- print("Will overwrite existing maps")
|
||||
-- else
|
||||
-- print("Will skip existing maps")
|
||||
-- end
|
||||
|
||||
---
|
||||
-- Get list of existing local map IDs (filenames without extension).
|
||||
-- Returns a table containing unique names of all files in the local map output directory
|
||||
-- with .yaml, .png, or .tga extensions, without the extension itself.
|
||||
-- Each filename corresponds to a cell ID that has been extracted.
|
||||
-- This can be used to check which maps have already been generated.
|
||||
-- The list contains unique names - if a cell has multiple file types (e.g., both .yaml and .png),
|
||||
-- the name will appear only once in the list.
|
||||
-- @function [parent=#world] getExistingLocalMapIds
|
||||
-- @return #table Array of strings containing unique local map IDs (cell names without extension)
|
||||
-- @usage
|
||||
-- local existingMaps = world.getExistingLocalMapIds()
|
||||
-- for _, mapId in ipairs(existingMaps) do
|
||||
-- print("Found existing map: " .. mapId)
|
||||
-- end
|
||||
--
|
||||
-- -- Check if a specific map exists
|
||||
-- local targetCell = "Balmora"
|
||||
-- local exists = false
|
||||
-- for _, mapId in ipairs(existingMaps) do
|
||||
-- if mapId == targetCell then
|
||||
-- exists = true
|
||||
-- break
|
||||
-- end
|
||||
-- end
|
||||
-- if not exists then
|
||||
-- print("Map for " .. targetCell .. " not found, need to extract")
|
||||
-- end
|
||||
|
||||
return nil
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue