GH-3930 Track duration of previous game sessions
This commit is contained in:
parent
d63ef939be
commit
74f5255eef
@ -37,6 +37,7 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s
|
|||||||
m_settings->registerSetting("notes", "");
|
m_settings->registerSetting("notes", "");
|
||||||
m_settings->registerSetting("lastLaunchTime", 0);
|
m_settings->registerSetting("lastLaunchTime", 0);
|
||||||
m_settings->registerSetting("totalTimePlayed", 0);
|
m_settings->registerSetting("totalTimePlayed", 0);
|
||||||
|
m_settings->registerSetting("lastTimePlayed", 0);
|
||||||
|
|
||||||
// Custom Commands
|
// Custom Commands
|
||||||
auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false);
|
auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false);
|
||||||
@ -146,9 +147,12 @@ void BaseInstance::setRunning(bool running)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qint64 current = settings()->get("totalTimePlayed").toLongLong();
|
|
||||||
QDateTime timeEnded = QDateTime::currentDateTime();
|
QDateTime timeEnded = QDateTime::currentDateTime();
|
||||||
|
|
||||||
|
qint64 current = settings()->get("totalTimePlayed").toLongLong();
|
||||||
settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded));
|
settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded));
|
||||||
|
settings()->set("lastTimePlayed", m_timeStarted.secsTo(timeEnded));
|
||||||
|
|
||||||
emit propertiesChanged(this);
|
emit propertiesChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,9 +170,20 @@ int64_t BaseInstance::totalTimePlayed() const
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t BaseInstance::lastTimePlayed() const
|
||||||
|
{
|
||||||
|
if(m_isRunning)
|
||||||
|
{
|
||||||
|
QDateTime timeNow = QDateTime::currentDateTime();
|
||||||
|
return m_timeStarted.secsTo(timeNow);
|
||||||
|
}
|
||||||
|
return settings()->get("lastTimePlayed").toLongLong();
|
||||||
|
}
|
||||||
|
|
||||||
void BaseInstance::resetTimePlayed()
|
void BaseInstance::resetTimePlayed()
|
||||||
{
|
{
|
||||||
settings()->reset("totalTimePlayed");
|
settings()->reset("totalTimePlayed");
|
||||||
|
settings()->reset("lastTimePlayed");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseInstance::instanceType() const
|
QString BaseInstance::instanceType() const
|
||||||
|
@ -87,6 +87,7 @@ public:
|
|||||||
void setRunning(bool running);
|
void setRunning(bool running);
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
int64_t totalTimePlayed() const;
|
int64_t totalTimePlayed() const;
|
||||||
|
int64_t lastTimePlayed() const;
|
||||||
void resetTimePlayed();
|
void resetTimePlayed();
|
||||||
|
|
||||||
/// get the type of this instance
|
/// get the type of this instance
|
||||||
|
@ -798,9 +798,15 @@ QString MinecraftInstance::getStatusbarDescription()
|
|||||||
|
|
||||||
QString description;
|
QString description;
|
||||||
description.append(tr("Minecraft %1 (%2)").arg(m_components->getComponentVersion("net.minecraft")).arg(typeName()));
|
description.append(tr("Minecraft %1 (%2)").arg(m_components->getComponentVersion("net.minecraft")).arg(typeName()));
|
||||||
if(m_settings->get("ShowGameTime").toBool() && totalTimePlayed() > 0)
|
if(m_settings->get("ShowGameTime").toBool())
|
||||||
{
|
{
|
||||||
description.append(tr(", played for %1").arg(prettifyTimeDuration(totalTimePlayed())));
|
if (lastTimePlayed() > 0) {
|
||||||
|
description.append(tr(", last played for %1").arg(prettifyTimeDuration(lastTimePlayed())));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalTimePlayed() > 0) {
|
||||||
|
description.append(tr(", total played for %1").arg(prettifyTimeDuration(totalTimePlayed())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(hasCrashed())
|
if(hasCrashed())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user