mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 13:59:19 +02:00
poprawka ładowania mmd
This commit is contained in:
@@ -4969,8 +4969,7 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co
|
|||||||
+ " " + ReplacableSkin // (p3)
|
+ " " + ReplacableSkin // (p3)
|
||||||
+ " end",
|
+ " end",
|
||||||
cParser::buffer_TEXT,
|
cParser::buffer_TEXT,
|
||||||
asBaseDir );
|
asBaseDir, true, std::vector<std::string>(), true );
|
||||||
parser.allowRandomIncludes = true;
|
|
||||||
std::string token;
|
std::string token;
|
||||||
do {
|
do {
|
||||||
token = "";
|
token = "";
|
||||||
|
|||||||
@@ -8573,7 +8573,7 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
|||||||
m_radiosound.owner( DynamicObject );
|
m_radiosound.owner( DynamicObject );
|
||||||
CabSoundLocations.clear();
|
CabSoundLocations.clear();
|
||||||
|
|
||||||
cParser parser( asFileName, cParser::buffer_FILE, DynamicObject->asBaseDir );
|
cParser parser( asFileName, cParser::buffer_FILE, DynamicObject->asBaseDir, true, std::vector<std::string>(), true );
|
||||||
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
||||||
// parser.addCommentStyle( "#", "\n" );
|
// parser.addCommentStyle( "#", "\n" );
|
||||||
std::string token;
|
std::string token;
|
||||||
@@ -8700,8 +8700,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
|
|||||||
|
|
||||||
std::string cabstr("cab" + std::to_string(cabindex) + "definition:");
|
std::string cabstr("cab" + std::to_string(cabindex) + "definition:");
|
||||||
|
|
||||||
cParser parser( asFileName, cParser::buffer_FILE, DynamicObject->asBaseDir );
|
cParser parser( asFileName, cParser::buffer_FILE, DynamicObject->asBaseDir, true, std::vector<std::string>(), true );
|
||||||
parser.allowRandomIncludes = true;
|
|
||||||
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
||||||
// parser.addCommentStyle( "#", "\n" );
|
// parser.addCommentStyle( "#", "\n" );
|
||||||
std::string token;
|
std::string token;
|
||||||
|
|||||||
15
parser.cpp
15
parser.cpp
@@ -24,9 +24,10 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
// cParser -- generic class for parsing text data.
|
// cParser -- generic class for parsing text data.
|
||||||
|
|
||||||
// constructors
|
// constructors
|
||||||
cParser::cParser( std::string const &Stream, buffertype const Type, std::string Path, bool const Loadtraction, std::vector<std::string> Parameters ) :
|
cParser::cParser( std::string const &Stream, buffertype const Type, std::string Path, bool const Loadtraction, std::vector<std::string> Parameters, bool allowRandom ) :
|
||||||
mPath(Path),
|
mPath(Path),
|
||||||
LoadTraction( Loadtraction ) {
|
LoadTraction( Loadtraction ),
|
||||||
|
allowRandomIncludes(allowRandom) {
|
||||||
// store to calculate sub-sequent includes from relative path
|
// store to calculate sub-sequent includes from relative path
|
||||||
if( Type == buffertype::buffer_FILE ) {
|
if( Type == buffertype::buffer_FILE ) {
|
||||||
mFile = Stream;
|
mFile = Stream;
|
||||||
@@ -252,8 +253,7 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
|||||||
&& ( false == contains( includefile, "tra/" ) ) ) ) {
|
&& ( false == contains( includefile, "tra/" ) ) ) ) {
|
||||||
if (Global.ParserLogIncludes)
|
if (Global.ParserLogIncludes)
|
||||||
WriteLog("including: " + includefile);
|
WriteLog("including: " + includefile);
|
||||||
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ) );
|
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ), allowRandomIncludes );
|
||||||
mIncludeParser->allowRandomIncludes = allowRandomIncludes;
|
|
||||||
mIncludeParser->autoclear( m_autoclear );
|
mIncludeParser->autoclear( m_autoclear );
|
||||||
if( mIncludeParser->mSize <= 0 ) {
|
if( mIncludeParser->mSize <= 0 ) {
|
||||||
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
||||||
@@ -269,7 +269,6 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
|||||||
else if( ( std::strcmp( Break, "\n\r" ) == 0 ) && ( token.compare( 0, 7, "include" ) == 0 ) ) {
|
else if( ( std::strcmp( Break, "\n\r" ) == 0 ) && ( token.compare( 0, 7, "include" ) == 0 ) ) {
|
||||||
// HACK: if the parser reads full lines we expect this line to contain entire include directive, to make parsing easier
|
// HACK: if the parser reads full lines we expect this line to contain entire include directive, to make parsing easier
|
||||||
cParser includeparser( token.substr( 7 ) );
|
cParser includeparser( token.substr( 7 ) );
|
||||||
includeparser.allowRandomIncludes = allowRandomIncludes;
|
|
||||||
std::string includefile = allowRandomIncludes ? deserialize_random_set( includeparser ) : includeparser.readToken( ToLower ); // nazwa pliku
|
std::string includefile = allowRandomIncludes ? deserialize_random_set( includeparser ) : includeparser.readToken( ToLower ); // nazwa pliku
|
||||||
replace_slashes(includefile);
|
replace_slashes(includefile);
|
||||||
if( ( true == LoadTraction )
|
if( ( true == LoadTraction )
|
||||||
@@ -277,8 +276,7 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
|
|||||||
&& ( false == contains( includefile, "tra/" ) ) ) ) {
|
&& ( false == contains( includefile, "tra/" ) ) ) ) {
|
||||||
if (Global.ParserLogIncludes)
|
if (Global.ParserLogIncludes)
|
||||||
WriteLog("including: " + includefile);
|
WriteLog("including: " + includefile);
|
||||||
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ) );
|
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ), allowRandomIncludes );
|
||||||
mIncludeParser->allowRandomIncludes = allowRandomIncludes;
|
|
||||||
mIncludeParser->autoclear( m_autoclear );
|
mIncludeParser->autoclear( m_autoclear );
|
||||||
if( mIncludeParser->mSize <= 0 ) {
|
if( mIncludeParser->mSize <= 0 ) {
|
||||||
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
|
||||||
@@ -384,8 +382,7 @@ void cParser::injectString(const std::string &str)
|
|||||||
mIncludeParser->injectString(str);
|
mIncludeParser->injectString(str);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mIncludeParser = std::make_shared<cParser>( str, buffer_TEXT, "", LoadTraction );
|
mIncludeParser = std::make_shared<cParser>( str, buffer_TEXT, "", LoadTraction, std::vector<std::string>(), allowRandomIncludes );
|
||||||
mIncludeParser->allowRandomIncludes = allowRandomIncludes;
|
|
||||||
mIncludeParser->autoclear( m_autoclear );
|
mIncludeParser->autoclear( m_autoclear );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
parser.h
4
parser.h
@@ -28,7 +28,7 @@ class cParser //: public std::stringstream
|
|||||||
buffer_TEXT
|
buffer_TEXT
|
||||||
};
|
};
|
||||||
// constructors:
|
// constructors:
|
||||||
cParser(std::string const &Stream, buffertype const Type = buffer_TEXT, std::string Path = "", bool const Loadtraction = true, std::vector<std::string> Parameters = std::vector<std::string>() );
|
cParser(std::string const &Stream, buffertype const Type = buffer_TEXT, std::string Path = "", bool const Loadtraction = true, std::vector<std::string> Parameters = std::vector<std::string>(), bool allowRandom = false );
|
||||||
// destructor:
|
// destructor:
|
||||||
virtual ~cParser();
|
virtual ~cParser();
|
||||||
// methods:
|
// methods:
|
||||||
@@ -91,7 +91,6 @@ class cParser //: public std::stringstream
|
|||||||
// returns number of currently processed line in main file, -1 if inside include
|
// returns number of currently processed line in main file, -1 if inside include
|
||||||
int LineMain() const;
|
int LineMain() const;
|
||||||
bool expandIncludes = true;
|
bool expandIncludes = true;
|
||||||
bool allowRandomIncludes = false;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// methods:
|
// methods:
|
||||||
@@ -119,6 +118,7 @@ class cParser //: public std::stringstream
|
|||||||
std::shared_ptr<cParser> mIncludeParser; // child class to handle include directives.
|
std::shared_ptr<cParser> mIncludeParser; // child class to handle include directives.
|
||||||
std::vector<std::string> parameters; // parameter list for included file.
|
std::vector<std::string> parameters; // parameter list for included file.
|
||||||
std::deque<std::string> tokens;
|
std::deque<std::string> tokens;
|
||||||
|
bool allowRandomIncludes = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user