-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user configuration of workshop effects & more refactoring
Store the custom user settings inside the submission json file used for disabled_files Another mega commit, wheee
- Loading branch information
Showing
26 changed files
with
664 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include <stdafx.h> | ||
|
||
#include "Workshop.h" | ||
|
||
void Workshop::OnModPauseCleanup() | ||
{ | ||
m_CachedSubmissionSettings.clear(); | ||
} | ||
|
||
nlohmann::json Workshop::GetSubmissionSettingJson(const std::string &submissionPath) | ||
{ | ||
if (m_CachedSubmissionSettings.contains(submissionPath)) | ||
{ | ||
return m_CachedSubmissionSettings.at(submissionPath); | ||
} | ||
|
||
auto submissionSettingsFile = submissionPath + ".json"; | ||
if (!DoesFileExist(submissionSettingsFile)) | ||
{ | ||
return {}; | ||
} | ||
|
||
std::ifstream file(submissionSettingsFile); | ||
std::stringstream buffer; | ||
buffer << file.rdbuf(); | ||
|
||
try | ||
{ | ||
m_CachedSubmissionSettings[submissionPath] = nlohmann::json::parse(buffer.str()); | ||
} | ||
catch (nlohmann::json::exception) | ||
{ | ||
m_CachedSubmissionSettings[submissionPath] = {}; | ||
} | ||
|
||
return m_CachedSubmissionSettings.at(submissionPath); | ||
} | ||
|
||
std::vector<std::string> Workshop::GetSubmissionBlacklistedFiles(const std::string &submissionPath) | ||
{ | ||
std::vector<std::string> blacklistedFiles; | ||
|
||
auto json = GetSubmissionSettingJson(submissionPath); | ||
try | ||
{ | ||
for (const std::string &file : json["disabled_files"]) | ||
{ | ||
blacklistedFiles.push_back(file); | ||
} | ||
} | ||
catch (nlohmann::json::exception) | ||
{ | ||
} | ||
|
||
return blacklistedFiles; | ||
} | ||
|
||
std::vector<std::filesystem::directory_entry> Workshop::GetSubmissionFiles(const std::string &submissionPath, | ||
FileType fileType, std::string subPath) | ||
{ | ||
const auto &blacklistedFiles = GetSubmissionBlacklistedFiles(submissionPath); | ||
|
||
std::vector<std::filesystem::directory_entry> entries; | ||
switch (fileType) | ||
{ | ||
case FileType::Script: | ||
entries = GetFiles(submissionPath + "\\" + subPath, ".lua", true, blacklistedFiles); | ||
break; | ||
case FileType::Audio: | ||
entries = GetFiles(submissionPath + "\\" + subPath, ".mp3", true, blacklistedFiles); | ||
break; | ||
default: | ||
return {}; | ||
} | ||
|
||
return entries; | ||
} | ||
|
||
std::unordered_map<std::string, nlohmann::json> Workshop::GetSubmissionScriptSettings(const std::string &submissionPath, | ||
const std::string &scriptPath) | ||
{ | ||
std::unordered_map<std::string, nlohmann::json> scriptSettings; | ||
|
||
auto json = GetSubmissionSettingJson(submissionPath); | ||
try | ||
{ | ||
for (const auto &[key, value] : json["effect_settings"][scriptPath].items()) | ||
{ | ||
LOG(key << " " << value); | ||
scriptSettings[key] = value; | ||
} | ||
} | ||
catch (nlohmann::json::exception) | ||
{ | ||
} | ||
|
||
return scriptSettings; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "Util/File.h" | ||
|
||
#include <filesystem> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include <json.hpp> | ||
|
||
class Workshop : public Component | ||
{ | ||
private: | ||
std::unordered_map<std::string, nlohmann::json> m_CachedSubmissionSettings; | ||
|
||
private: | ||
nlohmann::json GetSubmissionSettingJson(const std::string &submissionPath); | ||
|
||
public: | ||
void OnModPauseCleanup() override; | ||
|
||
std::vector<std::string> GetSubmissionBlacklistedFiles(const std::string &submissionPath); | ||
enum class FileType | ||
{ | ||
Script, | ||
Audio | ||
}; | ||
std::vector<std::filesystem::directory_entry> GetSubmissionFiles(const std::string &submissionPath, | ||
FileType fileType, std::string subPath = ""); | ||
|
||
std::unordered_map<std::string, nlohmann::json> GetSubmissionScriptSettings(const std::string &submissionPath, | ||
const std::string &scriptPath); | ||
|
||
template <class T> | ||
requires std::is_base_of_v<Component, T> | ||
friend struct ComponentHolder; | ||
}; |
Oops, something went wrong.