Skip to content

Commit

Permalink
add 'script' entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Dec 20, 2024
1 parent 1aca495 commit dc93cac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ Engine::Engine(CoreParameters coreParameters)
paths.setResourcesFolder(params.resFolder);
paths.setUserFilesFolder(params.userFolder);
paths.prepare();
if (!params.scriptFile.empty()) {
paths.setScriptFolder(params.scriptFile.parent_path());
}
loadSettings();

auto resdir = paths.getResourcesFolder();
Expand Down
8 changes: 7 additions & 1 deletion src/files/engine_paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ void EnginePaths::setResourcesFolder(std::filesystem::path folder) {
this->resourcesFolder = std::move(folder);
}

void EnginePaths::setScriptFolder(std::filesystem::path folder) {
this->scriptFolder = std::move(folder);
}

void EnginePaths::setCurrentWorldFolder(std::filesystem::path folder) {
this->currentWorldFolder = std::move(folder);
}
Expand Down Expand Up @@ -211,7 +215,9 @@ std::filesystem::path EnginePaths::resolve(
if (prefix == "export") {
return userFilesFolder / EXPORT_FOLDER / fs::u8path(filename);
}

if (prefix == "script" && scriptFolder) {
return scriptFolder.value() / fs::u8path(filename);
}
if (contentPacks) {
for (auto& pack : *contentPacks) {
if (pack.id == prefix) {
Expand Down
4 changes: 4 additions & 0 deletions src/files/engine_paths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <filesystem>
#include <stdexcept>
#include <optional>
#include <string>
#include <vector>
#include <tuple>
Expand All @@ -26,6 +27,8 @@ class EnginePaths {
void setResourcesFolder(std::filesystem::path folder);
std::filesystem::path getResourcesFolder() const;

void setScriptFolder(std::filesystem::path folder);

std::filesystem::path getWorldFolderByName(const std::string& name);
std::filesystem::path getWorldsFolder() const;
std::filesystem::path getConfigFolder() const;
Expand All @@ -51,6 +54,7 @@ class EnginePaths {
std::filesystem::path userFilesFolder {"."};
std::filesystem::path resourcesFolder {"res"};
std::filesystem::path currentWorldFolder;
std::optional<std::filesystem::path> scriptFolder;
std::vector<ContentPack>* contentPacks = nullptr;
};

Expand Down

0 comments on commit dc93cac

Please sign in to comment.