mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-30 14:15:35 +08:00
Simplify XPlane CSL model strings
Before this change, the model strings were assembled via some relatives pathes - long and very hard to read. Now it is assembled via the pattern <package root dir> <dir> ... <objectname> <texturename> <package root dir> = the parent directory of xsb_aircrafts.txt <dir> ... = directory hierarchy down to the object file refs #574
This commit is contained in:
@@ -123,6 +123,16 @@ namespace BlackMisc
|
|||||||
emit loadingFinished(true);
|
emit loadingFinished(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CAircraftModelLoaderXPlane::CSLPlane::getModelName() const
|
||||||
|
{
|
||||||
|
QString modelName = dirNames.join(' ');
|
||||||
|
modelName += " ";
|
||||||
|
modelName += objectName;
|
||||||
|
modelName += " ";
|
||||||
|
modelName += textureName;
|
||||||
|
return modelName;
|
||||||
|
}
|
||||||
|
|
||||||
CAircraftModelList CAircraftModelLoaderXPlane::performParsing(const QString &rootDirectory, const QStringList &excludeDirectories)
|
CAircraftModelList CAircraftModelLoaderXPlane::performParsing(const QString &rootDirectory, const QStringList &excludeDirectories)
|
||||||
{
|
{
|
||||||
CAircraftModelList allModels;
|
CAircraftModelList allModels;
|
||||||
@@ -202,19 +212,18 @@ namespace BlackMisc
|
|||||||
CAircraftModelList CAircraftModelLoaderXPlane::parseCslPackages(const QString &rootDirectory, const QStringList &excludeDirectories)
|
CAircraftModelList CAircraftModelLoaderXPlane::parseCslPackages(const QString &rootDirectory, const QStringList &excludeDirectories)
|
||||||
{
|
{
|
||||||
Q_UNUSED(excludeDirectories);
|
Q_UNUSED(excludeDirectories);
|
||||||
QStringList packages;
|
if (rootDirectory.isEmpty()) { return {}; }
|
||||||
QDirIterator it(rootDirectory, QDirIterator::Subdirectories);
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
it.next();
|
|
||||||
if (it.fileName() == "xsb_aircraft.txt") { packages << it.fileInfo().absolutePath(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
m_cslPackages.clear();
|
m_cslPackages.clear();
|
||||||
for (const auto &packageFilePath : packages)
|
|
||||||
|
|
||||||
|
QDir searchPath(rootDirectory, "xsb_aircraft.txt");
|
||||||
|
QDirIterator it(searchPath, QDirIterator::Subdirectories);
|
||||||
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
QString packageFile(packageFilePath);
|
QString packageFile = it.next();
|
||||||
packageFile += "/xsb_aircraft.txt";
|
|
||||||
|
QString packageFilePath = it.fileInfo().absolutePath();
|
||||||
QFile file(packageFile);
|
QFile file(packageFile);
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
QString content;
|
QString content;
|
||||||
@@ -228,6 +237,7 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
CAircraftModelList installedModels;
|
CAircraftModelList installedModels;
|
||||||
|
|
||||||
// Now we do a full run
|
// Now we do a full run
|
||||||
for (auto &package : m_cslPackages)
|
for (auto &package : m_cslPackages)
|
||||||
{
|
{
|
||||||
@@ -244,7 +254,13 @@ namespace BlackMisc
|
|||||||
|
|
||||||
for (const auto &plane : package.planes)
|
for (const auto &plane : package.planes)
|
||||||
{
|
{
|
||||||
CAircraftModel model(plane.modelName, CAircraftModel::TypeOwnSimulatorModel);
|
if (installedModels.containsModelString(plane.getModelName()))
|
||||||
|
{
|
||||||
|
CLogMessage(this).warning("Model %1 exists already! Potential model string conflict! Ignoring it.") << plane.getModelName();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CAircraftModel model(plane.getModelName(), CAircraftModel::TypeOwnSimulatorModel);
|
||||||
model.setFileName(plane.filePath);
|
model.setFileName(plane.filePath);
|
||||||
|
|
||||||
CAircraftIcaoCode icao(plane.icao);
|
CAircraftIcaoCode icao(plane.icao);
|
||||||
@@ -252,8 +268,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CLivery livery;
|
CLivery livery;
|
||||||
livery.setCombinedCode(plane.livery);
|
livery.setCombinedCode(plane.livery);
|
||||||
CAirlineIcaoCode airline;
|
CAirlineIcaoCode airline(plane.airline);
|
||||||
airline.setName(plane.airline);
|
|
||||||
livery.setAirlineIcaoCode(airline);
|
livery.setAirlineIcaoCode(airline);
|
||||||
model.setLivery(livery);
|
model.setLivery(livery);
|
||||||
|
|
||||||
@@ -329,6 +344,19 @@ namespace BlackMisc
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Reads the next line from stream ignoring empty ones.
|
||||||
|
//! Returns a null QString if stream is at the end.
|
||||||
|
QString readLineFrom(QTextStream &stream)
|
||||||
|
{
|
||||||
|
QString line;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
line = stream.readLine();
|
||||||
|
}
|
||||||
|
while(line.isEmpty() && !stream.atEnd());
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
bool CAircraftModelLoaderXPlane::parseObjectCommand(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum)
|
bool CAircraftModelLoaderXPlane::parseObjectCommand(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum)
|
||||||
{
|
{
|
||||||
if (tokens.size() != 2)
|
if (tokens.size() != 2)
|
||||||
@@ -336,17 +364,57 @@ namespace BlackMisc
|
|||||||
CLogMessage(this).warning("%1 - %2: OBJECT command requires 1 argument.") << path << lineNum;
|
CLogMessage(this).warning("%1 - %2: OBJECT command requires 1 argument.") << path << lineNum;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString relativePath(tokens[1]);
|
QString relativePath(tokens[1]);
|
||||||
normalizePath(relativePath);
|
normalizePath(relativePath);
|
||||||
QString fullPath(relativePath);
|
QString fullPath(relativePath);
|
||||||
if (!doPackageSub(fullPath))
|
if (!doPackageSub(fullPath))
|
||||||
{
|
{
|
||||||
CLogMessage(this).warning("%1 - %2: package not found..") << path << lineNum;
|
CLogMessage(this).warning("%1 - %2: package not found.") << path << lineNum;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get obj header
|
||||||
|
QFile objFile(fullPath);
|
||||||
|
if(!objFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
|
{
|
||||||
|
CLogMessage(this).warning("Object %1 does not exist.") << fullPath;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QTextStream ts(&objFile);
|
||||||
|
|
||||||
|
// First line is about line endings. We don't need it.
|
||||||
|
readLineFrom(ts);
|
||||||
|
|
||||||
|
// Version number.
|
||||||
|
QString versionLine = readLineFrom(ts);
|
||||||
|
if (versionLine.isNull()) { return false; }
|
||||||
|
QString version = versionLine.split(QRegularExpression("\\s"), QString::SkipEmptyParts).at(0);
|
||||||
|
|
||||||
|
// For version 7, there is another line 'obj'
|
||||||
|
if (version == "700") { readLineFrom(ts); }
|
||||||
|
|
||||||
|
// Texture
|
||||||
|
QString textureLine = readLineFrom(ts);
|
||||||
|
if (textureLine.isNull()) { return false; }
|
||||||
|
QString texture = textureLine.split(QRegularExpression("\\s"), QString::SkipEmptyParts).at(0);
|
||||||
|
|
||||||
|
objFile.close();
|
||||||
|
|
||||||
package.planes.push_back(CSLPlane());
|
package.planes.push_back(CSLPlane());
|
||||||
package.planes.back().modelName = relativePath;
|
QFileInfo fileInfo(fullPath);
|
||||||
|
|
||||||
|
QStringList dirNames;
|
||||||
|
dirNames.append(relativePath.split('/', QString::SkipEmptyParts));
|
||||||
|
// Replace the first one being the package name with the package root dir
|
||||||
|
QString packageRootDir = package.path.mid(package.path.lastIndexOf('/') + 1);
|
||||||
|
dirNames.replace(0, packageRootDir);
|
||||||
|
// Remove the last one being the obj itself
|
||||||
|
dirNames.removeLast();
|
||||||
|
|
||||||
|
package.planes.back().dirNames = dirNames;
|
||||||
|
package.planes.back().objectName = fileInfo.completeBaseName();
|
||||||
|
package.planes.back().textureName = texture;
|
||||||
package.planes.back().filePath = fullPath;
|
package.planes.back().filePath = fullPath;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -366,34 +434,33 @@ namespace BlackMisc
|
|||||||
|
|
||||||
if (!doPackageSub(absoluteTexPath))
|
if (!doPackageSub(absoluteTexPath))
|
||||||
{
|
{
|
||||||
CLogMessage(this).warning("%1 - %2: package not found..") << path << lineNum;
|
CLogMessage(this).warning("%1 - %2: package not found.") << path << lineNum;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
package.planes.back().modelName += " ";
|
QFileInfo fileInfo(absoluteTexPath);
|
||||||
package.planes.back().modelName += relativeTexPath;
|
if (!fileInfo.exists())
|
||||||
|
{
|
||||||
|
CLogMessage(this).warning("Texture %1 does not exist.") << absoluteTexPath;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
package.planes.back().textureName = fileInfo.completeBaseName();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CAircraftModelLoaderXPlane::parseAircraftCommand(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum)
|
bool CAircraftModelLoaderXPlane::parseAircraftCommand(const QStringList &tokens, CSLPackage &package, const QString &path, int lineNum)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(package)
|
||||||
// AIRCAFT <min> <max> <path>
|
// AIRCAFT <min> <max> <path>
|
||||||
if (tokens.size() != 4)
|
if (tokens.size() != 4)
|
||||||
{
|
{
|
||||||
CLogMessage(this).warning("%1 - %2: AIRCRAFT command requires 3 arguments.") << path << lineNum;
|
CLogMessage(this).warning("%1 - %2: AIRCRAFT command requires 3 arguments.") << path << lineNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString relativePath = tokens[3];
|
// Flyable aircrafts are parsed by a different method. We don't know any aircraft files in CSL packages.
|
||||||
normalizePath(relativePath);
|
// If there is one, implement this method here.
|
||||||
QString absolutePath(relativePath);
|
qFatal("Not implemented yet.");
|
||||||
if (!doPackageSub(absolutePath))
|
|
||||||
{
|
|
||||||
CLogMessage(this).warning("%1 - %2: package not found..") << path << lineNum;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
package.planes.push_back(CSLPlane());
|
|
||||||
package.planes.back().modelName = relativePath;
|
|
||||||
package.planes.back().filePath = absolutePath;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,6 +612,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
QString localCopy(content);
|
QString localCopy(content);
|
||||||
QTextStream in(&localCopy);
|
QTextStream in(&localCopy);
|
||||||
|
|
||||||
while (!in.atEnd())
|
while (!in.atEnd())
|
||||||
{
|
{
|
||||||
++lineNum;
|
++lineNum;
|
||||||
|
|||||||
@@ -69,7 +69,13 @@ namespace BlackMisc
|
|||||||
private:
|
private:
|
||||||
struct CSLPlane
|
struct CSLPlane
|
||||||
{
|
{
|
||||||
QString modelName; //!< Unique model name
|
QString getModelName() const;
|
||||||
|
|
||||||
|
// Model name parts
|
||||||
|
QStringList dirNames; //!< List dir names starting from xsb_aircrafts.txt parent down to obj folder
|
||||||
|
QString objectName; //!< Complete basename of the object file
|
||||||
|
QString textureName; //!< Complete basename of the texture file
|
||||||
|
|
||||||
QString filePath; //!< object filePath
|
QString filePath; //!< object filePath
|
||||||
QString icao; //!< Icao type of this model
|
QString icao; //!< Icao type of this model
|
||||||
QString airline; //!< Airline identifier. Can be empty.
|
QString airline; //!< Airline identifier. Can be empty.
|
||||||
|
|||||||
Submodule src/xbus/libxplanemp updated: 5c4e6df0e4...e50ccf5726
Reference in New Issue
Block a user