Skip to content

Commit

Permalink
#5997: Collision model export code is now creating necessary folders …
Browse files Browse the repository at this point in the history
…on its own
  • Loading branch information
codereader committed Aug 19, 2022
1 parent 432f723 commit 8607898
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
7 changes: 5 additions & 2 deletions radiantcore/selection/algorithm/Primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void createCMFromSelection(const cmd::ArgumentList& args)
cm->addBrush(brushes[i]->getBrush());
}

std::string basePath = GlobalGameManager().getModPath();
std::string basePath = game::current::getWriteableGameResourcePath();

std::string modelPath = basePath + model;

Expand All @@ -171,7 +171,10 @@ void createCMFromSelection(const cmd::ArgumentList& args)

try
{
// create the new autosave filename by changing the extension
// Make sure the output folder exists
fs::create_directories(os::getDirectory(modelPath));

// create the new filename by changing the extension
fs::path cmPath = os::replaceExtension(modelPath, newExtension);

// Open the stream to the output file
Expand Down
13 changes: 7 additions & 6 deletions test/ModelExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,22 @@ TEST_F(ModelExportTest, ExportSelectedAsCollisionModelCreatesFolder)
Node_setSelected(entity, true);

auto relativeModelPath = "models/some_folder_not_existing_outside_pk4s/testcube.ase";
auto physicalPath = _context.getTestProjectPath() + relativeModelPath;
auto expectedPhysicalPath = _context.getTestProjectPath() + relativeModelPath;
expectedPhysicalPath = os::replaceExtension(expectedPhysicalPath, "cm");

// Make sure the folder is not there
fs::remove_all(os::getContainingDir(physicalPath));
EXPECT_FALSE(os::fileOrDirExists(os::getContainingDir(physicalPath))) << "Folder should not exist yet";
EXPECT_FALSE(os::fileOrDirExists(physicalPath)) << "Export CM should not exist yet";
fs::remove_all(os::getDirectory(expectedPhysicalPath));
EXPECT_FALSE(os::fileOrDirExists(os::getDirectory(expectedPhysicalPath))) << "Folder should not exist yet";
EXPECT_FALSE(os::fileOrDirExists(expectedPhysicalPath)) << "Export CM should not exist yet";

// Export the selection as collision mesh for the torch model
GlobalCommandSystem().executeCommand("ExportSelectedAsCollisionModel", { relativeModelPath });

// Both file and folder need to exist, just check the file
EXPECT_TRUE(os::fileOrDirExists(physicalPath)) << "Folder should have been created by ExportSelectedAsCollisionModel";
EXPECT_TRUE(os::fileOrDirExists(expectedPhysicalPath)) << "Folder should have been created by ExportSelectedAsCollisionModel";

// Remove the folder after the test is done
fs::remove_all(os::getContainingDir(physicalPath));
fs::remove_all(os::getDirectory(expectedPhysicalPath));
}

}

0 comments on commit 8607898

Please sign in to comment.