Merge pull request #373 from Scrumplex/feat-world-size

This commit is contained in:
Sefa Eyeoglu 2022-04-02 00:59:15 +02:00 committed by GitHub
commit 333f7cc320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 2 deletions

View File

@ -17,6 +17,7 @@
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QSaveFile> #include <QSaveFile>
#include <QDirIterator>
#include "World.h" #include "World.h"
#include "GZip.h" #include "GZip.h"
@ -187,6 +188,26 @@ bool putLevelDatDataToFS(const QFileInfo &file, QByteArray & data)
return f.commit(); return f.commit();
} }
int64_t calculateWorldSize(const QFileInfo &file)
{
if (file.isFile() && file.suffix() == "zip")
{
return file.size();
}
else if(file.isDir())
{
QDirIterator it(file.absolutePath(), QDirIterator::Subdirectories);
int64_t total = 0;
while (it.hasNext())
{
total += it.fileInfo().size();
it.next();
}
return total;
}
return -1;
}
World::World(const QFileInfo &file) World::World(const QFileInfo &file)
{ {
repath(file); repath(file);
@ -196,6 +217,7 @@ void World::repath(const QFileInfo &file)
{ {
m_containerFile = file; m_containerFile = file;
m_folderName = file.fileName(); m_folderName = file.fileName();
m_size = calculateWorldSize(file);
if(file.isFile() && file.suffix() == "zip") if(file.isFile() && file.suffix() == "zip")
{ {
m_iconFile = QString(); m_iconFile = QString();
@ -482,6 +504,7 @@ void World::loadFromLevelDat(QByteArray data)
if(randomSeed) { if(randomSeed) {
qDebug() << "Seed:" << *randomSeed; qDebug() << "Seed:" << *randomSeed;
} }
qDebug() << "Size:" << m_size;
qDebug() << "GameType:" << m_gameType.toLogString(); qDebug() << "GameType:" << m_gameType.toLogString();
} }

View File

@ -52,6 +52,10 @@ public:
{ {
return m_iconFile; return m_iconFile;
} }
int64_t bytes() const
{
return m_size;
}
QDateTime lastPlayed() const QDateTime lastPlayed() const
{ {
return m_lastPlayed; return m_lastPlayed;
@ -105,6 +109,7 @@ protected:
QString m_iconFile; QString m_iconFile;
QDateTime levelDatTime; QDateTime levelDatTime;
QDateTime m_lastPlayed; QDateTime m_lastPlayed;
int64_t m_size;
int64_t m_randomSeed = 0; int64_t m_randomSeed = 0;
GameType m_gameType; GameType m_gameType;
bool is_valid = false; bool is_valid = false;

View File

@ -14,6 +14,8 @@
*/ */
#include "WorldList.h" #include "WorldList.h"
#include "Application.h"
#include <FileSystem.h> #include <FileSystem.h>
#include <QMimeData> #include <QMimeData>
#include <QUrl> #include <QUrl>
@ -150,7 +152,7 @@ bool WorldList::resetIcon(int row)
int WorldList::columnCount(const QModelIndex &parent) const int WorldList::columnCount(const QModelIndex &parent) const
{ {
return 3; return 4;
} }
QVariant WorldList::data(const QModelIndex &index, int role) const QVariant WorldList::data(const QModelIndex &index, int role) const
@ -164,6 +166,8 @@ QVariant WorldList::data(const QModelIndex &index, int role) const
if (row < 0 || row >= worlds.size()) if (row < 0 || row >= worlds.size())
return QVariant(); return QVariant();
QLocale locale;
auto & world = worlds[row]; auto & world = worlds[row];
switch (role) switch (role)
{ {
@ -179,6 +183,9 @@ QVariant WorldList::data(const QModelIndex &index, int role) const
case LastPlayedColumn: case LastPlayedColumn:
return world.lastPlayed(); return world.lastPlayed();
case SizeColumn:
return locale.formattedDataSize(world.bytes());
default: default:
return QVariant(); return QVariant();
} }
@ -207,6 +214,10 @@ QVariant WorldList::data(const QModelIndex &index, int role) const
{ {
return world.lastPlayed(); return world.lastPlayed();
} }
case SizeRole:
{
return locale.formattedDataSize(world.bytes());
}
case IconFileRole: case IconFileRole:
{ {
return world.iconFile(); return world.iconFile();
@ -229,6 +240,9 @@ QVariant WorldList::headerData(int section, Qt::Orientation orientation, int rol
return tr("Game Mode"); return tr("Game Mode");
case LastPlayedColumn: case LastPlayedColumn:
return tr("Last Played"); return tr("Last Played");
case SizeColumn:
//: World size on disk
return tr("Size");
default: default:
return QVariant(); return QVariant();
} }
@ -242,6 +256,8 @@ QVariant WorldList::headerData(int section, Qt::Orientation orientation, int rol
return tr("Game mode of the world."); return tr("Game mode of the world.");
case LastPlayedColumn: case LastPlayedColumn:
return tr("Date and time the world was last played."); return tr("Date and time the world was last played.");
case SizeColumn:
return tr("Size of the world on disk.");
default: default:
return QVariant(); return QVariant();
} }

View File

@ -32,7 +32,8 @@ public:
{ {
NameColumn, NameColumn,
GameModeColumn, GameModeColumn,
LastPlayedColumn LastPlayedColumn,
SizeColumn
}; };
enum Roles enum Roles
@ -43,6 +44,7 @@ public:
NameRole, NameRole,
GameModeRole, GameModeRole,
LastPlayedRole, LastPlayedRole,
SizeRole,
IconFileRole IconFileRole
}; };