Skip to content

Commit

Permalink
Merge pull request #11 from MaxFleur/dev_1.9.2
Browse files Browse the repository at this point in the history
Merge 1.9.2 changes
  • Loading branch information
MaxFleur committed Mar 11, 2023
2 parents 446e556 + 33cca9d commit d361697
Show file tree
Hide file tree
Showing 22 changed files with 179 additions and 180 deletions.
50 changes: 25 additions & 25 deletions src/handler/CharacterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <QCryptographicHash>

// Stores a new character in the vector
// Stores a new character
void
CharacterHandler::storeCharacter(
QString name,
Expand All @@ -16,7 +16,7 @@ CharacterHandler::storeCharacter(
}


// Sort all created characters
// Sort all created characters, depending on the used rulset
void
CharacterHandler::sortCharacters(const RuleSettings::Ruleset& ruleset, bool rollAutomatically)
{
Expand All @@ -38,29 +38,29 @@ CharacterHandler::sortCharacters(const RuleSettings::Ruleset& ruleset, bool roll
return c1.initiative > c2.initiative;
}
switch (ruleset) {
// PF 1E/D&D 3.5/Starfinder rules: Sort for higher INI mod
// If that's equal, sort automatically or let the party decide
case RuleSettings::Ruleset::PATHFINDER_1E_DND_35E:
case RuleSettings::Ruleset::STARFINDER:
// D&D 3.0 uses the dex value for ties, but this is essentially another variant
// of the mod value, so no additional changes are necessary
case RuleSettings::Ruleset::DND_30E:
if (c1.modifier != c2.modifier) {
return c1.modifier > c2.modifier;
}
return sortUsingHashes(c1, c2);
// PF 2E rules: If there is a tie between player and foe, foe goes first
// Otherwise sort automatically or let the party decide
case RuleSettings::Ruleset::PATHFINDER_2E:
if (c1.isEnemy != c2.isEnemy) {
return c1.isEnemy > c2.isEnemy;
}
return sortUsingHashes(c1, c2);
// D&D 5E rules: Just sort automatically or let the party decide
case RuleSettings::Ruleset::DND_5E:
return sortUsingHashes(c1, c2);
default:
return false;
// PF 1E/D&D 3.5/Starfinder rules: Sort for higher INI mod
// If that's equal, sort automatically or let the party decide
case RuleSettings::Ruleset::PATHFINDER_1E_DND_35E:
case RuleSettings::Ruleset::STARFINDER:
// D&D 3.0 uses the dex value for ties, but this is essentially another variant
// of the mod value, so no additional changes are necessary
case RuleSettings::Ruleset::DND_30E:
if (c1.modifier != c2.modifier) {
return c1.modifier > c2.modifier;
}
return sortUsingHashes(c1, c2);
// PF 2E rules: If there is a tie between player and foe, foe goes first
// Otherwise sort automatically or let the party decide
case RuleSettings::Ruleset::PATHFINDER_2E:
if (c1.isEnemy != c2.isEnemy) {
return c1.isEnemy > c2.isEnemy;
}
return sortUsingHashes(c1, c2);
// D&D 5E rules: Just sort automatically or let the party decide
case RuleSettings::Ruleset::DND_5E:
return sortUsingHashes(c1, c2);
default:
return false;
}
});
}
Expand Down
7 changes: 3 additions & 4 deletions src/handler/CharacterHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class CharacterHandler {
int initiative = 0;
// Modifiers only
int modifier = 0;
// The hp for this character. Optional.
// The hp for this character
int hp = 0;
// Is the character an enemy or not
bool isEnemy = false;
// Additional information (e.g. status effects). Optional.
// Additional information (e.g. status effects)
QString additionalInf = QString();
};

public:
// Store a new character

void
storeCharacter(QString name,
int initiative = 0,
Expand All @@ -36,7 +36,6 @@ class CharacterHandler {
bool isEnemy = false,
QString additionalInf = QString());

// Sort the stored characters, depending on the ruleset
void
sortCharacters(const RuleSettings::Ruleset& ruleset,
bool rollAutomatically);
Expand Down
23 changes: 11 additions & 12 deletions src/handler/FileHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QFile>
#include <QStringList>

// Stores a table as a csv
// Stores table data as csv
bool
FileHandler::saveTable(
const QVector<QVector<QVariant> >& tableData,
Expand All @@ -14,21 +14,22 @@ FileHandler::saveTable(
const RuleSettings::Ruleset& ruleset,
bool rollAutomatically) const
{
// Create a file
// Create file
QFile file(filename);

// Check if device is open for writing
// Check if the device is open for writing
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream data(&file);
data.setCodec("UTF-8");
data.setGenerateByteOrderMark(false);

QStringList strList;

// Store the header of the table, used for checking the correct table format if the table is reloaded
// Store the table data header
strList << "Name" << "Initiative" << "INI modifier" << "HP" << "Is Enemy" << "Additional information";
data << strList.join(";") + "\n";

// Store main table data
auto firstRow = true;
for (const auto& row : tableData) {
// Clear the list at the beginning of every row iteration
Expand All @@ -43,7 +44,7 @@ FileHandler::saveTable(
<< QString::number(ruleset) << QString::number(rollAutomatically);
}

// The "\n" guarantees that the rows are set correctly in the csv table
// Line break
data << strList.join(";") + "\n";
}

Expand All @@ -54,7 +55,7 @@ FileHandler::saveTable(
}


// Open an existing csv table and stream it's data
// Open an existing csv table and stream its data
int
FileHandler::getCSVData(const QString& filename)
{
Expand All @@ -67,14 +68,14 @@ FileHandler::getCSVData(const QString& filename)
in.setGenerateByteOrderMark(false);
m_data = QString();

// Import file line by line
// Import file
while (!in.atEnd()) {
m_data.append(in.readLine() + "\n");
}
importedCSV.close();

if (checkTableFormat(m_data)) {
// Successfully checked table
// Success
return 0;
}
// Table in false format
Expand All @@ -85,19 +86,18 @@ FileHandler::getCSVData(const QString& filename)
}


// Checks if a table is in the correct format before using
// Checks if a table is in the correct format
bool
FileHandler::checkTableFormat(const QString& data) const
{
if (data.isEmpty()) {
return false;
}

// Get the stored table row data information
const auto rowDataHeader = data.split("\n").at(0).split(";");
const auto rowDataFirstRow = data.split("\n").at(1).split(";");

// Test if the table has the correct header columns
// Test if the stored data has the correct header columns
if (rowDataHeader.size() == 6
&& rowDataHeader[0] == "Name"
&& rowDataHeader[1] == "Initiative"
Expand All @@ -106,7 +106,6 @@ FileHandler::checkTableFormat(const QString& data) const
&& rowDataHeader[4] == "Is Enemy"
&& rowDataHeader[5] == "Additional information"

// The second row is checked
// 7th entry should contain the player on the move, 8th the round counter,
// 9th the ruleset and 10th the roll automatically option
&& rowDataFirstRow.size() == 10) {
Expand Down
8 changes: 4 additions & 4 deletions src/handler/FileHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include "RuleSettings.hpp"

// This class handles the saving and reopening of tables as csv data
// This class handles the saving and opening of csv table data
class FileHandler {
public:
// Save a table of characters
// Save the characters
[[nodiscard]] bool
saveTable(const QVector<QVector<QVariant> >& tableData,
const QString& filename,
Expand All @@ -19,7 +19,7 @@ class FileHandler {
const RuleSettings::Ruleset& ruleset,
bool rollAutomatically) const;

// Reopen a saved table
// Open a saved table
[[nodiscard]] int
getCSVData(const QString& filename);

Expand All @@ -30,7 +30,7 @@ class FileHandler {
}

private:
// Checks if a table is in the right format
// Checks if data is in the right format
bool
checkTableFormat(const QString& data) const;

Expand Down
28 changes: 12 additions & 16 deletions src/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ MainWindow::MainWindow()
auto *const aboutQtAction = new QAction(style()->standardIcon(QStyle::SP_TitleBarMenuButton), tr("About &Qt"), this);
connect(aboutQtAction, &QAction::triggered, qApp, &QApplication::aboutQt);

// Add actions
auto *const fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(newCombatAction);
fileMenu->addAction(openTableAction);
Expand Down Expand Up @@ -132,7 +133,7 @@ MainWindow::saveTable()
} else {
fileName = m_dirSettings->openDir;
}

// Save the table
const auto tableDataWidget = Utils::Table::tableDataFromWidget(m_combatWidget->getTableWidget());
if (m_file->saveTable(tableDataWidget, fileName, m_combatWidget->getRowEntered(),
m_combatWidget->getRoundCounter(), m_ruleSettings->ruleset, m_ruleSettings->rollAutomatical)) {
Expand All @@ -149,14 +150,15 @@ MainWindow::saveTable()
}


// Reopen the file dialog, even if the table has been saved already
void
MainWindow::saveAs()
{
// Save state
const auto saveChangeOccured = isWindowModified();
const auto saveTableInFile = m_tableInFile;

// Change variables so saveTable calls the file dialog
// Change variables to call the file dialog
setWindowModified(true);
m_tableInFile = false;
// Restore old state if the save fails
Expand All @@ -178,10 +180,8 @@ MainWindow::openTable()
return;
}
}
const auto fileName =
QFileDialog::getOpenFileName(this, "Open Table", m_dirSettings->openDir, ("csv File(*.csv)"));
const auto fileName = QFileDialog::getOpenFileName(this, "Open Table", m_dirSettings->openDir, ("csv File(*.csv)"));
const auto code = m_file->getCSVData(fileName);

auto rulesModified = false;

switch (code) {
Expand Down Expand Up @@ -238,9 +238,9 @@ void
MainWindow::about()
{
QMessageBox::about(this, tr("About Light Combat Manager"),
tr("<p>Light Combat Manager. A small and simple Combat Manager for D&D-like games.<br>"
tr("<p>Light Combat Manager. A small, lightweight Combat Manager for d20-based role playing games.<br>"
"<a href='https://github.com/MaxFleur/LightCombatManager'>Code available on Github.</a></p>"
"<p>Version 1.9.1.<br>"
"<p>Version 1.9.2.<br>"
"<a href='https://github.com/MaxFleur/LightCombatManager/releases'>Changelog</a></p>"));
}

Expand Down Expand Up @@ -305,8 +305,6 @@ MainWindow::setTableWidget(bool isDataStored, bool newCombatStarted, const QStri
m_combatWidget->openAddCharacterDialog();
} else {
m_combatWidget->generateTable();
// Setting the table emits changeOccured because the cells are altered, so reset
setCombatTitle(false);
const auto height = m_combatWidget->getHeight();
setFixedHeight(height > START_HEIGHT ? height : START_HEIGHT);
}
Expand Down Expand Up @@ -336,10 +334,9 @@ MainWindow::createSaveMessageBox(const QString& tableMessage, bool isClosing)
{
auto *const msgBox = new QMessageBox(this);
msgBox->setIcon(QMessageBox::Question);
msgBox->setStandardButtons(
isWindowModified() ?
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel :
QMessageBox::Yes | QMessageBox::No);
msgBox->setStandardButtons(isWindowModified() ?
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel :
QMessageBox::Yes | QMessageBox::No);
msgBox->setText(tableMessage);
if (isClosing) {
isWindowModified() ? msgBox->setWindowTitle(tr("Save and exit?")) : msgBox->setWindowTitle(tr("Exit application?"));
Expand Down Expand Up @@ -371,7 +368,7 @@ MainWindow::createSaveMessageBox(const QString& tableMessage, bool isClosing)
}


QMessageBox *
QMessageBox*
MainWindow::createRuleChangeMessageBox()
{
const auto message = tr("The Table you are trying to load uses another ruleset than you have stored in your rule settings! <br><br>"
Expand Down Expand Up @@ -406,10 +403,9 @@ MainWindow::closeEvent(QCloseEvent *event)
break;
}
case QMessageBox::Discard:
case QMessageBox::Yes:
event->accept();
break;
case QMessageBox::Yes:
return;
case QMessageBox::Cancel:
case QMessageBox::No:
event->ignore();
Expand Down
3 changes: 1 addition & 2 deletions src/ui/MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class RuleSettings;
class WelcomeWidget;

// This class handles the creation and managing of the main GUI window. It also serves
// as "main anchor point", switching between the different widgets the Combat Manager can have.
// The widgets are created in other classes and given to this class.
// as "main anchor point", switching between LCM's widgets, which are created in other classes.
class MainWindow : public QMainWindow
{
Q_OBJECT
Expand Down
6 changes: 3 additions & 3 deletions src/ui/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ SettingsDialog::SettingsDialog(std::shared_ptr<RuleSettings> RuleSettings,
m_rollTieBox = new QCheckBox;
m_rollTieBox->setChecked(m_ruleSettings->rollAutomatical);
auto *const rollTieLabel = new QLabel(tr("Roll automatically for tie"));
rollTieLabel->setToolTip(tr("If a tie occurs while Characters are generated for a Combat, the app will "
"automatically decide the turn order."));
rollTieLabel->setToolTip(tr("If a tie occurs while Characters are generated for a Combat,\n"
"the app will automatically decide the turn order."));

auto *const rollTieLayout = new QHBoxLayout;
rollTieLayout->setAlignment(Qt::AlignLeft);
Expand Down Expand Up @@ -73,7 +73,7 @@ bool
SettingsDialog::applyClicked()
{
if (m_rulesetBox->currentIndex() != m_ruleSettings->ruleset || m_rollTieBox->isChecked() != m_ruleSettings->rollAutomatical) {
// It could be dangerous to change the combat rules while a combat is active, so abort instead
// It could be dangerous to change the combat rules while a combat is active, so abort
if (m_isTableActive) {
auto const reply = QMessageBox::critical(this, tr("Combat active!"),
tr("You changed the ruleset while a Combat is active. Please save and exit "
Expand Down
4 changes: 2 additions & 2 deletions src/ui/SettingsDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class RuleSettings;
class QCheckBox;
class QComboBox;

// Dialog for the main program settings
// Dialog for the main application settings
class SettingsDialog : public QDialog {
Q_OBJECT

Expand All @@ -30,5 +30,5 @@ private slots:
QPointer<QCheckBox> m_rollTieBox;

std::shared_ptr<RuleSettings> m_ruleSettings;
bool m_isTableActive;
const bool m_isTableActive;
};
2 changes: 1 addition & 1 deletion src/ui/settings/DirSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "BaseSettings.hpp"

// Store data used for the opening and saving directories
// Store data used for handling the opening and saving directories
class DirSettings : public BaseSettings {
public:
DirSettings();
Expand Down
Loading

0 comments on commit d361697

Please sign in to comment.