GH-2374 fix missing alternating backgrounds in worlds, add gametype column
This commit is contained in:
parent
de568b32b8
commit
13b293dd65
@ -30,6 +30,26 @@
|
||||
#include <quazipfile.h>
|
||||
#include <quazipdir.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
QString gameTypeToString(GameType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GameType::Survival:
|
||||
return QCoreApplication::translate("GameType", "Survival");
|
||||
case GameType::Creative:
|
||||
return QCoreApplication::translate("GameType", "Creative");
|
||||
case GameType::Adventure:
|
||||
return QCoreApplication::translate("GameType", "Adventure");
|
||||
case GameType::Spectator:
|
||||
return QCoreApplication::translate("GameType", "Spectator");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QObject::tr("Unknown");
|
||||
}
|
||||
|
||||
std::unique_ptr <nbt::tag_compound> parseLevelDat(QByteArray data)
|
||||
{
|
||||
QByteArray output;
|
||||
@ -303,6 +323,32 @@ static int64_t read_long (nbt::value& parent, const char * name, const int64_t &
|
||||
}
|
||||
}
|
||||
|
||||
static int read_int (nbt::value& parent, const char * name, const int & fallback = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto &namedValue = parent.at(name);
|
||||
if(namedValue.get_type() != nbt::tag_type::Int)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
auto & tag_str = namedValue.as<nbt::tag_int>();
|
||||
return tag_str.get();
|
||||
}
|
||||
catch (const std::out_of_range &e)
|
||||
{
|
||||
// fallback for old world formats
|
||||
qWarning() << "Int NBT tag" << name << "could not be found. Defaulting to" << fallback;
|
||||
return fallback;
|
||||
}
|
||||
catch (const std::bad_cast &e)
|
||||
{
|
||||
// type mismatch
|
||||
qWarning() << "NBT tag" << name << "could not be converted to int. Defaulting to" << fallback;
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
void World::loadFromLevelDat(QByteArray data)
|
||||
{
|
||||
try
|
||||
@ -332,11 +378,14 @@ void World::loadFromLevelDat(QByteArray data)
|
||||
m_lastPlayed = QDateTime::fromMSecsSinceEpoch(temp);
|
||||
}
|
||||
|
||||
m_gameType = (GameType) read_int(val, "GameType", 0);
|
||||
|
||||
m_randomSeed = read_long(val, "RandomSeed", 0);
|
||||
|
||||
qDebug() << "World Name:" << m_actualName;
|
||||
qDebug() << "Last Played:" << m_lastPlayed.toString();
|
||||
qDebug() << "Seed:" << m_randomSeed;
|
||||
qDebug() << "GameMode:" << m_randomSeed;
|
||||
}
|
||||
catch (const nbt::io::input_error &e)
|
||||
{
|
||||
|
@ -19,6 +19,15 @@
|
||||
|
||||
#include "multimc_logic_export.h"
|
||||
|
||||
enum class GameType
|
||||
{
|
||||
Survival,
|
||||
Creative,
|
||||
Adventure,
|
||||
Spectator
|
||||
};
|
||||
QString MULTIMC_LOGIC_EXPORT gameTypeToString(GameType type);
|
||||
|
||||
class MULTIMC_LOGIC_EXPORT World
|
||||
{
|
||||
public:
|
||||
@ -35,6 +44,10 @@ public:
|
||||
{
|
||||
return m_lastPlayed;
|
||||
}
|
||||
GameType gameType() const
|
||||
{
|
||||
return m_gameType;
|
||||
}
|
||||
int64_t seed() const
|
||||
{
|
||||
return m_randomSeed;
|
||||
@ -79,5 +92,6 @@ protected:
|
||||
QDateTime levelDatTime;
|
||||
QDateTime m_lastPlayed;
|
||||
int64_t m_randomSeed = 0;
|
||||
GameType m_gameType = GameType::Survival;
|
||||
bool is_valid = false;
|
||||
};
|
||||
|
@ -138,7 +138,7 @@ bool WorldList::deleteWorlds(int first, int last)
|
||||
|
||||
int WorldList::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
QVariant WorldList::data(const QModelIndex &index, int role) const
|
||||
@ -161,6 +161,9 @@ QVariant WorldList::data(const QModelIndex &index, int role) const
|
||||
case NameColumn:
|
||||
return world.name();
|
||||
|
||||
case GameModeColumn:
|
||||
return gameTypeToString(world.gameType());
|
||||
|
||||
case LastPlayedColumn:
|
||||
return world.lastPlayed();
|
||||
|
||||
@ -206,6 +209,8 @@ QVariant WorldList::headerData(int section, Qt::Orientation orientation, int rol
|
||||
{
|
||||
case NameColumn:
|
||||
return tr("Name");
|
||||
case GameModeColumn:
|
||||
return tr("Game Mode");
|
||||
case LastPlayedColumn:
|
||||
return tr("Last Played");
|
||||
default:
|
||||
@ -217,6 +222,8 @@ QVariant WorldList::headerData(int section, Qt::Orientation orientation, int rol
|
||||
{
|
||||
case NameColumn:
|
||||
return tr("The name of the world.");
|
||||
case GameModeColumn:
|
||||
return tr("Game mode of the world.");
|
||||
case LastPlayedColumn:
|
||||
return tr("Date and time the world was last played.");
|
||||
default:
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
enum Columns
|
||||
{
|
||||
NameColumn,
|
||||
GameModeColumn,
|
||||
LastPlayedColumn
|
||||
};
|
||||
|
||||
@ -42,6 +43,7 @@ public:
|
||||
FolderRole,
|
||||
SeedRole,
|
||||
NameRole,
|
||||
GameModeRole,
|
||||
LastPlayedRole
|
||||
};
|
||||
|
||||
|
@ -126,6 +126,9 @@
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::DragDrop</enum>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
|
Loading…
Reference in New Issue
Block a user