diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-12-29 10:54:11 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-12-29 10:54:11 -0500 |
| commit | 3fa8f8764bae2e2fa4d558f6282f1237444147d9 (patch) | |
| tree | f006e662eb27ac480b3164850759784985769d95 | |
| parent | 471658adb0a2df73eef065cce4e7550d6dd14b1e (diff) | |
| download | sigen-3fa8f8764bae2e2fa4d558f6282f1237444147d9.tar.gz sigen-3fa8f8764bae2e2fa4d558f6282f1237444147d9.tar.xz sigen-3fa8f8764bae2e2fa4d558f6282f1237444147d9.zip | |
Fixed up Sigmod and it now uses check macros
| -rw-r--r-- | sigmod/Macros.h | 13 | ||||
| -rw-r--r-- | sigmod/Sigmod.cpp | 117 | ||||
| -rw-r--r-- | sigmod/Sigmod.h | 8 | ||||
| -rw-r--r-- | sigmodr/SpeciesUI.cpp | 5 | ||||
| -rw-r--r-- | sigmodr/gui/species.ui | 8 |
5 files changed, 68 insertions, 83 deletions
diff --git a/sigmod/Macros.h b/sigmod/Macros.h index 34a31af4..06c258cc 100644 --- a/sigmod/Macros.h +++ b/sigmod/Macros.h @@ -35,7 +35,6 @@ #define LOAD_ARRAY(variable) loadArray(xml.firstChildElement(#variable), &m_##variable) #define LOAD_LIST(variable) loadList(xml.firstChildElement(#variable), &m_##variable) #define LOAD_MATRIX(variable) loadMatrix(xml.firstChildElement(#variable), &m_##variable) -// #define LOAD_Rules() m_rules->load(xml.firstChildElement("Rules")) #define LOAD_SUB(setter, class) \ QDomElement xml_##class = xml.firstChildElement(#class); \ while (!xml_##class.isNull()) \ @@ -112,6 +111,12 @@ m_##variable[index - offset] = value; \ emit(changed()); \ } +#define TS_MATRIX(variable, row, column, value) \ + if (variable##Check(value) && (m_##variable(row, column) != value)) \ + { \ + m_##variable(row, column) = value; \ + emit(changed()); \ + } #define TS_LIST_BEGIN(variable) \ if (variable##Check(variable) && state && !m_##variable.contains(variable)) \ { @@ -175,6 +180,11 @@ void Sigmod::class::set##capital(const indexType indexName, const type valueName { \ TS_ARRAY(variable, indexName, offset, valueName); \ } +#define SETTER_MATRIX(class, type, capital, variable, valueName) \ +void Sigmod::class::set##capital(const int row, const int column, const type valueName) \ +{ \ + TS_MATRIX(variable, row, column, valueName); \ +} #define SETTER_LIST(class, capital, variable) \ void Sigmod::class::set##capital(const int variable, const bool state) \ { \ @@ -209,7 +219,6 @@ QList<int> Sigmod::class::variable() const \ return m_##variable; \ } - #define CHECK_BEGIN(class, type, variable) \ bool Sigmod::class::variable##Check(const type variable) const \ { diff --git a/sigmod/Sigmod.cpp b/sigmod/Sigmod.cpp index 576eec0b..a916e39c 100644 --- a/sigmod/Sigmod.cpp +++ b/sigmod/Sigmod.cpp @@ -285,7 +285,7 @@ void Sigmod::Sigmod::load(const QDomElement& xml) LOAD(singlePlayer); LOAD(startMap); LOAD(startWarp); - LOAD_Rules(); + m_rules->load(xml.firstChildElement("Rules")); LOAD_SUB(newAbility, Ability); LOAD_SUB(newAuthor, Author); LOAD_SUB(newBadge, Badge); @@ -348,53 +348,13 @@ QDomElement Sigmod::Sigmod::save() const return xml; } -void Sigmod::Sigmod::setTitle(const QString& title) -{ - CHECK(title); -} - -void Sigmod::Sigmod::setVersion(const QString& version) -{ - CHECK(version); -} - -void Sigmod::Sigmod::setDescription(const QString& description) -{ - CHECK(description); -} - -void Sigmod::Sigmod::setSinglePlayer(const bool singlePlayer) -{ - CHECK(singlePlayer); -} - -void Sigmod::Sigmod::setStartMap(const int startMap) -{ - if (!m_singlePlayer) - emit(error(unused("startMap"))); - if (!mapById(startMap)) - emit(error(bounds("startMap", startMap))); - else - CHECK(startMap); -} - -void Sigmod::Sigmod::setStartWarp(const int startWarp) -{ - if (!m_singlePlayer) - emit(error(unused("startWarp"))); - const Map* map = mapById(m_startMap); - if (!map) - emit(error(bounds("startMap", m_startMap))); - else if (!map->warpById(startWarp)) - emit(error(bounds("startWarp", startWarp))); - else - CHECK(startWarp); -} - -void Sigmod::Sigmod::setTypechart(const int attack, const int defense, const Sigcore::Fraction& multiplier) -{ - CHECK_ARRAY(typechart(attack, defense), multiplier); -} +SETTER(Sigmod, QString&, Title, title) +SETTER(Sigmod, QString&, Version, version) +SETTER(Sigmod, QString&, Description, description) +SETTER(Sigmod, bool, SinglePlayer, singlePlayer) +SETTER(Sigmod, int, StartMap, startMap) +SETTER(Sigmod, int, StartWarp, startWarp) +SETTER_MATRIX(Sigmod, Sigcore::Fraction&, Typechart, typechart, multiplier) void Sigmod::Sigmod::setRules(const Rules& rules) { @@ -406,35 +366,12 @@ void Sigmod::Sigmod::setRules(const QDomElement& xml) m_rules->load(xml); } -QString Sigmod::Sigmod::title() const -{ - return m_title; -} - -QString Sigmod::Sigmod::version() const -{ - return m_version; -} - -QString Sigmod::Sigmod::description() const -{ - return m_description; -} - -bool Sigmod::Sigmod::singlePlayer() const -{ - return m_singlePlayer; -} - -int Sigmod::Sigmod::startMap() const -{ - return m_startMap; -} - -int Sigmod::Sigmod::startWarp() const -{ - return m_startWarp; -} +GETTER(Sigmod, QString, title) +GETTER(Sigmod, QString, version) +GETTER(Sigmod, QString, description) +GETTER(Sigmod, bool, singlePlayer) +GETTER(Sigmod, int, startMap) +GETTER(Sigmod, int, startWarp) const Sigcore::Matrix<Sigcore::Fraction>* Sigmod::Sigmod::typechart() const { @@ -461,6 +398,32 @@ Sigmod::Rules* Sigmod::Sigmod::rules() return m_rules; } +CHECK(Sigmod, QString&, title) +CHECK(Sigmod, QString&, version) +CHECK(Sigmod, QString&, description) +CHECK(Sigmod, bool, singlePlayer) +CHECK_BEGIN(Sigmod, int, startMap) + if (!m_singlePlayer) + { + emit(error(unused("startMap"))); + return false; + } + if (!mapById(startMap)) + EBOUNDS_IDX(startMap); +CHECK_END() +CHECK_BEGIN(Sigmod, int, startWarp) + if (!m_singlePlayer) + { + emit(error(unused("startWarp"))); + return false; + } + const Map* map = mapById(m_startMap); + if (!map) + EBOUNDS_IDX(m_startMap); + IBOUNDS(startWarp, map, warp); +CHECK_END() +CHECK_BOUNDS(Sigmod, Sigcore::Fraction&, typechart, 0, INT_MAX) + const Sigmod::Ability* Sigmod::Sigmod::ability(const int index) const { if (index < abilityCount()) diff --git a/sigmod/Sigmod.h b/sigmod/Sigmod.h index 043c4df1..0ccad22d 100644 --- a/sigmod/Sigmod.h +++ b/sigmod/Sigmod.h @@ -134,6 +134,14 @@ class SIGMOD_EXPORT Sigmod : public Object const Rules* rules() const; Rules* rules(); + bool titleCheck(const QString& title) const; + bool versionCheck(const QString& version) const; + bool descriptionCheck(const QString& description) const; + bool singlePlayerCheck(const bool singlePlayer) const; + bool startMapCheck(const int startMap) const; + bool startWarpCheck(const int startWarp) const; + bool typechartCheck(const Sigcore::Fraction& multiplier) const; + const Ability* ability(const int index) const; Ability* ability(const int index); const Ability* abilityById(const int id) const; diff --git a/sigmodr/SpeciesUI.cpp b/sigmodr/SpeciesUI.cpp index a77ae536..a020c2d8 100644 --- a/sigmodr/SpeciesUI.cpp +++ b/sigmodr/SpeciesUI.cpp @@ -48,6 +48,7 @@ void Sigmodr::SpeciesUI::initGui() varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Normal], QVariant::fromValue(Sigmod::Species::Normal)); varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Fast], QVariant::fromValue(Sigmod::Species::Fast)); varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Erratic], QVariant::fromValue(Sigmod::Species::Erratic)); + varEffortValue->setMaximum(sigmod()->rules()->maxEVPerStat() ? sigmod()->rules()->maxEVPerStat() : INT_MAX); } void Sigmodr::SpeciesUI::refreshGui() @@ -192,7 +193,7 @@ void Sigmodr::SpeciesUI::setGui() varFemaleBack->setCurrentIndex(varFemaleBack->findData(qobject_cast<Sigmod::Species*>(modified())->backFemaleSprite())); } varSkin->setCurrentIndex(varSkin->findData(qobject_cast<Sigmod::Species*>(modified())->skin())); - boxGenderChance->setChecked((qobject_cast<Sigmod::Species*>(modified())->genderFactor().denominator() < qobject_cast<Sigmod::Species*>(modified())->genderFactor().numerator()) ? Qt::Checked : Qt::Unchecked); + boxGenderChance->setChecked((qobject_cast<Sigmod::Species*>(modified())->genderFactor() < 0) ? Qt::Checked : Qt::Unchecked); varGenderChance->setValue(qobject_cast<Sigmod::Species*>(modified())->genderFactor()); varEggSpecies->setCurrentIndex(varEggSpecies->findData(qobject_cast<Sigmod::Species*>(modified())->eggSpecies())); varEggSteps->setValue(qobject_cast<Sigmod::Species*>(modified())->eggSteps()); @@ -316,7 +317,7 @@ void Sigmodr::SpeciesUI::on_varSkin_currentIndexChanged(const int skin) void Sigmodr::SpeciesUI::on_boxGenderChance_clicked(const bool genderChance) { - qobject_cast<Sigmod::Species*>(modified())->setGenderFactor(Sigcore::Fraction((genderChance ? 1 : 2), 1)); + qobject_cast<Sigmod::Species*>(modified())->setGenderFactor(Sigcore::Fraction((genderChance ? 1 : -1), 1)); } void Sigmodr::SpeciesUI::on_varGenderChance_valueChanged(const Sigcore::Fraction& genderChance) diff --git a/sigmodr/gui/species.ui b/sigmodr/gui/species.ui index 0f60f13a..9d988e82 100644 --- a/sigmodr/gui/species.ui +++ b/sigmodr/gui/species.ui @@ -385,7 +385,7 @@ <string>The Encyclopedia number of the species</string> </property> <property name="minimum" > - <number>0</number> + <number>-1</number> </property> </widget> </item> @@ -506,7 +506,11 @@ </property> <layout class="QVBoxLayout" > <item> - <widget class="Sigmodr::FractionWidget" name="varGenderChance" /> + <widget class="Sigmodr::FractionWidget" name="varGenderChance" > + <property name="behavior" > + <enum>Sigmodr::FractionWidget::Proper</enum> + </property> + </widget> </item> </layout> </widget> |
