mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 01:35:45 +08:00
Ref T259, Ref T243 utility functions parts/engine list
This commit is contained in:
@@ -34,15 +34,29 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CAircraftEngine CAircraftEngineList::getEngine(int engineNumber) const
|
CAircraftEngine CAircraftEngineList::getEngine(int engineNumber) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(engineNumber >= 0);
|
Q_ASSERT(engineNumber > 0);
|
||||||
return this->findBy(&CAircraftEngine::getNumber, engineNumber).frontOrDefault();
|
return this->findBy(&CAircraftEngine::getNumber, engineNumber).frontOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CAircraftEngineList::isEngineOn(int engineNumber) const
|
bool CAircraftEngineList::isEngineOn(int engineNumber) const
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(engineNumber > 0);
|
||||||
return this->getEngine(engineNumber).isOn();
|
return this->getEngine(engineNumber).isOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAircraftEngineList::setEngineOn(int engineNumber, bool on)
|
||||||
|
{
|
||||||
|
Q_ASSERT(engineNumber > 0);
|
||||||
|
for (CAircraftEngine &engine : *this)
|
||||||
|
{
|
||||||
|
if (engine.getNumber() == engineNumber)
|
||||||
|
{
|
||||||
|
engine.setOn(on);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CAircraftEngineList::initEngines(int engineNumber, bool on)
|
void CAircraftEngineList::initEngines(int engineNumber, bool on)
|
||||||
{
|
{
|
||||||
this->clear();
|
this->clear();
|
||||||
@@ -64,7 +78,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
for (const auto &e : *this)
|
for (const auto &e : *this)
|
||||||
{
|
{
|
||||||
QJsonObject value = e.toJson();
|
const QJsonObject value = e.toJson();
|
||||||
map.insert(QString::number(e.getNumber()), value);
|
map.insert(QString::number(e.getNumber()), value);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
@@ -72,11 +86,11 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CAircraftEngineList::convertFromJson(const QJsonObject &json)
|
void CAircraftEngineList::convertFromJson(const QJsonObject &json)
|
||||||
{
|
{
|
||||||
clear();
|
this->clear();
|
||||||
for (const auto &e : json.keys())
|
for (const auto &e : json.keys())
|
||||||
{
|
{
|
||||||
CAircraftEngine engine;
|
CAircraftEngine engine;
|
||||||
int number = e.toInt();
|
const int number = e.toInt();
|
||||||
CJsonScope scope(e);
|
CJsonScope scope(e);
|
||||||
Q_UNUSED(scope);
|
Q_UNUSED(scope);
|
||||||
engine.convertFromJson(json.value(e).toObject());
|
engine.convertFromJson(json.value(e).toObject());
|
||||||
|
|||||||
@@ -48,11 +48,17 @@ namespace BlackMisc
|
|||||||
CAircraftEngineList(const CSequence<CAircraftEngine> &other);
|
CAircraftEngineList(const CSequence<CAircraftEngine> &other);
|
||||||
|
|
||||||
//! Get engine 1..n
|
//! Get engine 1..n
|
||||||
|
//! \remark 1 based, not 0 based
|
||||||
CAircraftEngine getEngine(int engineNumber) const;
|
CAircraftEngine getEngine(int engineNumber) const;
|
||||||
|
|
||||||
//! Engine number 1..x on?
|
//! Engine number 1..x on?
|
||||||
|
//! \remark 1 based, not 0 based
|
||||||
bool isEngineOn(int engineNumber) const;
|
bool isEngineOn(int engineNumber) const;
|
||||||
|
|
||||||
|
//! Set engine on/off
|
||||||
|
//! \remark 1 based, not 0 based
|
||||||
|
void setEngineOn(int engineNumber, bool on);
|
||||||
|
|
||||||
//! Init some engines
|
//! Init some engines
|
||||||
void initEngines(int engineNumber, bool on);
|
void initEngines(int engineNumber, bool on);
|
||||||
|
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ namespace BlackMisc
|
|||||||
QString CAircraftParts::convertToQString(bool i18n) const
|
QString CAircraftParts::convertToQString(bool i18n) const
|
||||||
{
|
{
|
||||||
return QStringLiteral("ts: ") % this->getFormattedTimestampAndOffset(true) %
|
return QStringLiteral("ts: ") % this->getFormattedTimestampAndOffset(true) %
|
||||||
QStringLiteral(" lights: ") % m_lights.toQString(i18n) %
|
QStringLiteral(" on ground: ") % BlackMisc::boolToYesNo(m_isOnGround) %
|
||||||
QStringLiteral(" gear down: ") % BlackMisc::boolToYesNo(m_gearDown) %
|
QStringLiteral(" | lights: ") % m_lights.toQString(i18n) %
|
||||||
QStringLiteral(" flaps pct: ") % QString::number(m_flapsPercentage) %
|
QStringLiteral(" | gear down: ") % BlackMisc::boolToYesNo(m_gearDown) %
|
||||||
QStringLiteral(" spoilers out: ") % BlackMisc::boolToYesNo(m_spoilersOut) %
|
QStringLiteral(" | flaps pct: ") % QString::number(m_flapsPercentage) %
|
||||||
QStringLiteral(" engines on: ") % m_engines.toQString(i18n) %
|
QStringLiteral(" | spoilers out: ") % BlackMisc::boolToYesNo(m_spoilersOut) %
|
||||||
QStringLiteral(" on ground: ") % BlackMisc::boolToYesNo(m_isOnGround);
|
QStringLiteral(" | engines on: ") % m_engines.toQString(i18n);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject CAircraftParts::toIncrementalJson() const
|
QJsonObject CAircraftParts::toIncrementalJson() const
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ namespace BlackMisc
|
|||||||
//! Get aircraft lights
|
//! Get aircraft lights
|
||||||
CAircraftLights getLights() const { return m_lights; }
|
CAircraftLights getLights() const { return m_lights; }
|
||||||
|
|
||||||
|
//! Reference to lights, meant wor easy direct changes of the values
|
||||||
|
CAircraftLights &lights() { return m_lights; }
|
||||||
|
|
||||||
//! Set aircraft lights
|
//! Set aircraft lights
|
||||||
void setLights(const CAircraftLights &lights) { m_lights = lights; }
|
void setLights(const CAircraftLights &lights) { m_lights = lights; }
|
||||||
|
|
||||||
@@ -98,6 +101,9 @@ namespace BlackMisc
|
|||||||
//! Get engines
|
//! Get engines
|
||||||
CAircraftEngineList getEngines() const { return m_engines; }
|
CAircraftEngineList getEngines() const { return m_engines; }
|
||||||
|
|
||||||
|
//! Direct access to engines, meant for simple value modifications
|
||||||
|
CAircraftEngineList &engines() { return m_engines; }
|
||||||
|
|
||||||
//! Engine with number
|
//! Engine with number
|
||||||
CAircraftEngine getEngine(int number) const;
|
CAircraftEngine getEngine(int number) const;
|
||||||
|
|
||||||
@@ -120,9 +126,11 @@ namespace BlackMisc
|
|||||||
void setOnGround(bool onGround) { m_isOnGround = onGround; }
|
void setOnGround(bool onGround) { m_isOnGround = onGround; }
|
||||||
|
|
||||||
//! Is aircraft on ground? (Smoothly interpolated between 0 and 1.)
|
//! Is aircraft on ground? (Smoothly interpolated between 0 and 1.)
|
||||||
|
//! \remark 1..on ground 0..not on ground
|
||||||
double isOnGroundInterpolated() const;
|
double isOnGroundInterpolated() const;
|
||||||
|
|
||||||
//! Set aircraft on ground. (Smoothly interpolated between 0 and 1.)
|
//! Set aircraft on ground. (Smoothly interpolated between 0 and 1.)
|
||||||
|
//! \remark 1..on ground 0..not on ground
|
||||||
void setOnGroundInterpolated(double onGround) { m_isOnGroundInterpolated = onGround; }
|
void setOnGroundInterpolated(double onGround) { m_isOnGroundInterpolated = onGround; }
|
||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
|
|||||||
Reference in New Issue
Block a user