Skip to content

Commit

Permalink
#5108: WIP commit
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 20, 2020
1 parent 57e3a4e commit 018e7fd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions radiantcore/map/Map.cpp
Expand Up @@ -647,6 +647,7 @@ void Map::registerCommands()
{
GlobalCommandSystem().addCommand("NewMap", Map::newMap);
GlobalCommandSystem().addCommand("OpenMap", Map::openMap, { cmd::ARGTYPE_STRING | cmd::ARGTYPE_OPTIONAL });
GlobalCommandSystem().addCommand("OpenMapFromArchive", Map::openMapFromArchive, { cmd::ARGTYPE_STRING, cmd::ARGTYPE_STRING });
GlobalCommandSystem().addCommand("ImportMap", Map::importMap);
GlobalCommandSystem().addCommand(LOAD_PREFAB_AT_CMD, std::bind(&Map::loadPrefabAt, this, std::placeholders::_1),
{ cmd::ARGTYPE_STRING, cmd::ARGTYPE_VECTOR3, cmd::ARGTYPE_INT|cmd::ARGTYPE_OPTIONAL });
Expand Down Expand Up @@ -734,6 +735,49 @@ void Map::openMap(const cmd::ArgumentList& args)
}
}

void Map::openMapFromArchive(const cmd::ArgumentList& args)
{
if (args.size() != 2)
{
rWarning() << "OpenMapFromArchive <absoluteArchivePath> <relativeMapFilePath>" << std::endl;
return;
}

if (!GlobalMap().askForSave(_("Open Map"))) return;

auto archivePath = args[0].getString();
auto relativeMapPath = args[1].getString();

if (!os::fileOrDirExists(archivePath))
{
throw cmd::ExecutionFailure(fmt::format(_("File doesn't exist: {0}"), archivePath));
}

rMessage() << "OpenMapFromArchive: trying to open archive " << archivePath << "..." << std::endl;

auto archive = GlobalFileSystem().openArchiveInAbsolutePath(archivePath);

if (!archive)
{
throw cmd::ExecutionFailure(fmt::format(_("Failed to open this archive: {0}"), archivePath));
}

auto mapFile = archive->openTextFile(relativeMapPath);

if (!mapFile)
{
throw cmd::ExecutionFailure(fmt::format(_("Failed to find the file {0}\nin archive {1}"), mapFile, archivePath));
}

std::istream mapFile->getInputStream();

if (!mapToLoad.empty())
{
GlobalMap().freeMap();
GlobalMap().loadFromStream();
}
}

void Map::importMap(const cmd::ArgumentList& args)
{
MapFileSelection fileInfo =
Expand Down
1 change: 1 addition & 0 deletions radiantcore/map/Map.h
Expand Up @@ -188,6 +188,7 @@ class Map :
static void exportSelection(const cmd::ArgumentList& args);
static void newMap(const cmd::ArgumentList& args);
static void openMap(const cmd::ArgumentList& args);
static void openMapFromArchive(const cmd::ArgumentList& args);
static void importMap(const cmd::ArgumentList& args);
static void saveMap(const cmd::ArgumentList& args);
static void saveMapAs(const cmd::ArgumentList& args);
Expand Down

0 comments on commit 018e7fd

Please sign in to comment.