Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit a3a8fa0

Browse files
committed
Add option for Reader to read from non-module paths
Associate non-module paths with the Base module so shit doesn't break when dealing with Entities
1 parent 57d4db7 commit a3a8fa0

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

System/Reader.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,28 @@ namespace RTE {
2323
m_OverwriteExisting = false;
2424
m_SkipIncludes = false;
2525
m_CanFail = false;
26+
m_NonMudulePath = false;
2627
}
2728

2829
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2930

3031
int Reader::Create(const std::string &fileName, bool overwrites, const ProgressCallback &progressCallback, bool failOK) {
31-
m_FilePath = g_PresetMan.FullModulePath(std::filesystem::path(fileName).generic_string());
32-
33-
if (m_FilePath.empty()) {
32+
if (fileName.empty()) {
3433
return -1;
3534
}
36-
// Extract the file name and module name from the path
37-
m_FileName = m_FilePath.substr(m_FilePath.find_last_of("/\\") + 1);
38-
m_DataModuleName = g_PresetMan.GetModuleNameFromPath(m_FilePath);
39-
m_DataModuleID = g_PresetMan.GetModuleID(m_DataModuleName);
35+
36+
if (m_NonMudulePath) {
37+
m_FilePath = std::filesystem::path(fileName).generic_string();
38+
m_DataModuleName = "Base.rte";
39+
m_DataModuleID = 0;
40+
} else {
41+
m_FilePath = g_PresetMan.FullModulePath(std::filesystem::path(fileName).generic_string());
42+
43+
// Extract the file name and module name from the path
44+
m_FileName = m_FilePath.substr(m_FilePath.find_last_of("/\\") + 1);
45+
m_DataModuleName = g_PresetMan.GetModuleNameFromPath(m_FilePath);
46+
m_DataModuleID = g_PresetMan.GetModuleID(m_DataModuleName);
47+
}
4048

4149
m_CanFail = failOK;
4250

System/Reader.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ namespace RTE {
2525
/// <param name="overwrites">Whether object definitions read here overwrite existing ones with the same names.</param>
2626
/// <param name="progressCallback">A function pointer to a function that will be called and sent a string with information about the progress of this Reader's reading.</param>
2727
/// <param name="failOK">Whether it's ok for the file to not be there, ie we're only trying to open, and if it's not there, then fail silently.</param>
28-
Reader(const std::string &fileName, bool overwrites = false, const ProgressCallback &progressCallback = nullptr, bool failOK = false) { Clear(); Create(fileName, overwrites, progressCallback, failOK); }
28+
/// <param name="nonModulePath">Whether this Reader is reading from path that is not a DataModule and should just read it as provided.</param>
29+
Reader(const std::string &fileName, bool overwrites = false, const ProgressCallback &progressCallback = nullptr, bool failOK = false, bool nonModulePath = false) { Clear(); m_NonMudulePath = nonModulePath; Create(fileName, overwrites, progressCallback, failOK); }
2930

3031
/// <summary>
3132
/// Makes the Reader object ready for use.
@@ -175,7 +176,7 @@ namespace RTE {
175176
Reader & operator>>(unsigned int &var) { DiscardEmptySpace(); *m_Stream >> var; return *this; }
176177
Reader & operator>>(long &var) { DiscardEmptySpace(); *m_Stream >> var; return *this; }
177178
Reader & operator>>(unsigned long &var) { DiscardEmptySpace(); *m_Stream >> var; return *this; }
178-
// Yeah, this is dumb - read as double and cast.
179+
// Yeah, this is dumb - read as double and cast.
179180
// This is because, for whatever fucking reason, iostream can save out floats at a precision that it's then unable to read...
180181
Reader & operator>>(float &var) { DiscardEmptySpace(); double var2; *m_Stream >> var2; var = static_cast<float>(var2); return *this; }
181182
Reader & operator>>(double &var) { DiscardEmptySpace(); *m_Stream >> var; return *this; }
@@ -220,6 +221,7 @@ namespace RTE {
220221
bool m_OverwriteExisting; //!< Whether object instances read from this should overwrite any already existing ones with the same names.
221222
bool m_SkipIncludes; //!< Indicates whether reader should skip included files.
222223
bool m_CanFail; //!< Whether it's ok for the Reader to fail reading a file and fail silently instead of aborting.
224+
bool m_NonMudulePath; //!< Whether this Reader is reading from path that is not a DataModule and should just read it as provided.
223225

224226
std::stack<int> m_BlockCommentOpenTagLines; //<! Stores lines on which block comment open tags are encountered. Used for error reporting when a file stream ends with an open block comment.
225227

0 commit comments

Comments
 (0)