24 #include "wadseeker/entities/checksum.h" 25 #include "wadseeker/entities/hash.h" 26 #include "wadseeker/entities/modfile.h" 31 static QString coerceInternalName(
const QString &
name)
33 return name.toLower().remove(QRegExp(
"[^a-z0-9]"));
44 void setInternalName(
const QString &name)
46 internalName = coerceInternalName(name);
57 DMFlag::DMFlag(
const QString &internalName,
unsigned value)
60 d->setInternalName(internalName);
64 DMFlag::DMFlag(
const QString &internalName,
unsigned value,
const QString &name)
67 d->setInternalName(internalName);
71 DMFlag::DMFlag(
const DMFlag &other)
89 return d->internalName;
109 DClass<DMFlagsSection>
114 QVector<DMFlag> flags;
116 void setInternalName(
const QString &name)
118 internalName = coerceInternalName(name);
124 DMFlagsSection::DMFlagsSection()
128 DMFlagsSection::DMFlagsSection(
const QString &internalName)
131 d->setInternalName(internalName);
134 DMFlagsSection::DMFlagsSection(
const QString &internalName,
const QString &name)
137 d->setInternalName(internalName);
145 DMFlagsSection::~DMFlagsSection()
164 for (
const DMFlag &flag : d->flags)
166 result |= flag.
value();
174 copy.d->flags.clear();
180 return d->flags.count();
185 return d->internalName;
200 return d->flags[index];
205 return d->flags[index];
209 const QList<DMFlagsSection> &original,
210 const QList<DMFlagsSection> &removals)
212 QList<DMFlagsSection> copy;
215 bool removed =
false;
218 if (section.internalName() == removal.internalName())
220 copy << section.removed(removal);
236 for (
const DMFlag &removal : removals.d->flags)
238 QMutableVectorIterator<DMFlag> i(copy.d->flags);
268 GameCVar::GameCVar(
const QString &name,
const QString &command)
271 d->command = command;
274 GameCVar::GameCVar(
const QString &name,
const QString &command,
const QVariant &value)
277 d->command = command;
281 GameCVar::GameCVar(
const GameCVar &other)
286 GameCVar::~GameCVar()
304 return value().isValid();
309 return !command().isEmpty();
329 DClass<GameCVarProvider>
335 GameCVarProvider::GameCVarProvider()
339 GameCVarProvider::~GameCVarProvider()
346 return QList<GameCVar>();
363 d->index = SGM_Unknown;
379 GameMode::~GameMode()
393 result.setTeamGame(
false);
404 return ffaGame(SGM_Cooperative, QObject::tr(
"Cooperative"));
409 return ffaGame(SGM_Deathmatch, QObject::tr(
"Deathmatch"));
412 GameMode GameMode::mkTeamDeathmatch()
414 return teamGame(SGM_TeamDeathmatch, QObject::tr(
"Team DM"));
417 GameMode GameMode::mkCaptureTheFlag()
419 return teamGame(SGM_CTF, QObject::tr(
"CTF"));
424 return ffaGame(SGM_Unknown, QObject::tr(
"Unknown"));
439 return !d->name.isEmpty();
442 void GameMode::setTeamGame(
bool b)
450 result.setTeamGame(
true);
461 QList<Checksum> checksums;
466 PWad::PWad(
const QString &name,
bool optional,
const QList<Checksum> &checksums)
469 d->optional = optional;
470 d->checksums = checksums;
473 PWad::PWad(
const QString &name,
bool optional)
476 d->optional = optional;
479 PWad::PWad(
const ModFile &modFile)
481 d->name = modFile.fileName();
483 d->checksums = modFile.checksums();
486 PWad::PWad(
const PWad &other)
495 PWad &PWad::operator=(
const PWad &other)
502 PWad::operator ModFile()
504 ModFile modFile(d->name);
505 modFile.setChecksums(d->checksums);
526 d->checksums.append(Checksum(hash, algorithm));
531 for (
const Checksum checksum : d->checksums)
533 if (Hash::hashFile(path, checksum.algorithm()) != checksum.hash())
void add(const DMFlag &flag)
Append a new DMFlag to this section.
const QString & name() const
Nice name to display to user in Create Game dialog and in other widgets.
const QString & name() const
User-friendly name to display for game mode.
const QString & internalName() const
static GameMode ffaGame(int index, const QString &name)
Construct a custom FFA game where players don't belong to any teams.
GameMode()
Constructs an invalid GameMode object.
void setValue(const QVariant &value)
Assign value() to this GameCVar.
bool isValid() const
'Null' objects are invalid.
A group of DMFlag objects that can be safely OR'ed together to form a meaningful value.
A game setting that is a part of a group of settings that can be OR'ed logically as a single integer...
const QVariant & value() const
Passed as the second argument, following command().
int count() const
Number of DMFlag objects inside the collection.
virtual QList< GameCVar > get(const QVariant &context)
Default implementation creates empty set.
bool isTeamGame() const
Is this GameMode based on rivaling teams?
const QList< Checksum > checksums() const
List of checksums of the WAD.
bool hasValue() const
Is any value assigned to this GameCVar.
const QString & internalName() const
Uniquely identifiable name within its DMFlagsSection, ex. "Jump is allowed" or "jumpisallowed".
bool isValid() const
'Null' objects are invalid.
const DMFlag & operator[](int index) const
Access DMFlag at specific index with '[]' operator.
const QString & name() const
Server's name.
Game mode representation.
DMFlagsSection removed(const DMFlagsSection &removals) const
Returns a copy of this list with specified DMFlags removed.
unsigned combineValues() const
Logical OR of all DMFlag::value() results in this collection.
unsigned value() const
Bits that represent this flag (usually just a single '1' bit).
int gamemode_id
Unique identifier of a GameMode within the plugin.
const QString & name() const
User-displayable name of this section, ex. "Compatibility flags".
bool isValid() const
Valid objects have value() greater than zero.
bool isOptional() const
Is this WAD required to join the server?
bool validFile(const QString &path) const
Verifies if a file has the same checksums as the PWad.
static GameMode teamGame(int index, const QString &name)
Game mode based on rivaling teams.
gamemode_id index() const
Index, either a StandardGameMode or custom defined by plugin.
DMFlagsSection copyEmpty() const
Copies section maintaining its properties but removing all flags.
const QString & name() const
User-displayable, translateable name of the DMFlag, ex. "Jump is allowed".
bool isEmpty() const
Does this section contain any dmflag?
void addChecksum(const QByteArray &hash, const QCryptographicHash::Algorithm &algorithm)
Adds a checksum to the WAD.
A general game setting or variable (like fraglimit).
const QString & command() const
Command-line argument that sets this GameCVar.
static QList< DMFlagsSection > removedBySection(const QList< DMFlagsSection > &original, const QList< DMFlagsSection > &removals)
Matches sections by internalName() and calls removed() on them.
const QString & name() const
File name of the WAD.