diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-03 10:45:40 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-03 10:45:40 +0000 |
| commit | 8714e1d409f46b05980b3e1e9f3a10910294b429 (patch) | |
| tree | 5d4931ed73a4947df329c6825474ddb902c465b8 /pokemod/Dialog.cpp | |
| parent | 822b5fcaa34b78b9668a58680f9e0d89aa3fd7bd (diff) | |
| download | sigen-8714e1d409f46b05980b3e1e9f3a10910294b429.tar.gz sigen-8714e1d409f46b05980b3e1e9f3a10910294b429.tar.xz sigen-8714e1d409f46b05980b3e1e9f3a10910294b429.zip | |
[FIX] pokemod now uses signals/slots for errors and warnings
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@120 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Dialog.cpp')
| -rw-r--r-- | pokemod/Dialog.cpp | 1173 |
1 files changed, 565 insertions, 608 deletions
diff --git a/pokemod/Dialog.cpp b/pokemod/Dialog.cpp index 5c0ea887..de1e87f7 100644 --- a/pokemod/Dialog.cpp +++ b/pokemod/Dialog.cpp @@ -39,631 +39,588 @@ Dialog::Dialog(const Dialog& dialog) : *this = dialog; } -Dialog::Dialog(const Object* parent, const int id) : +Dialog::Dialog(const Pokemod* parent, const int id) : Object("Dialog", parent, id), m_dialog("") { } -Dialog::Dialog(const Dialog& dialog, const Object* parent, const int id) : +Dialog::Dialog(const Dialog& dialog, const Pokemod* parent, const int id) : Object("Dialog", parent, id) { *this = dialog; } -Dialog::Dialog(const QDomElement& xml, const Object* parent, const int id) : +Dialog::Dialog(const QDomElement& xml, const Pokemod* parent, const int id) : Object("Dialog", parent, id) { load(xml, id); } -void Dialog::validate(QTextStream& stream) +void Dialog::validate() { - // TODO: validate -// bool valid = true; -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("---Dialog with id %1---").arg(id()), Pokemod::V_Msg); -// if (m_dialog == "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Dialog is empty"); -// setValid(false); -// } -// if (m_dialog.count('%') & 1) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Command delimiter mismatch"); -// setValid(false); -// } -// else -// { -// int curCmd = End; -// int numArgs = 0; -// for (int i = 0; i < m_dialog.length(); ++i) -// { -// switch (m_dialog.at(i).toAscii()) -// { -// case '%': -// switch (curCmd) -// { -// case FlipFlag ... Exit: -// if (numArgs != CommandNumArgs[curCmd]) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Invalid number of arguments for \"%1\". %2 given when %3 needed").arg(CommandStr[curCmd]).arg(numArgs).arg(CommandNumArgs[curCmd])); -// setValid(false); -// } -// break; -// case Menu: -// if (!(numArgs & 1)) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Invalid number of arguments for Menu"); -// setValid(false); -// } -// break; -// case End: -// QString curCmdStr; -// for (; (m_dialog.at(i) != '%') && (m_dialog.at(i) != '#'); ++i) -// curCmdStr += m_dialog.at(i); -// if (((curCmd = CommandAbbrStr.indexOf(curCmdStr))) == INT_MAX) -// { -// if (curCmdStr != "") -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Invalid command \"%1\"").arg(curCmdStr)); -// setValid(false); -// } -// curCmd = End; -// } -// numArgs = 0; -// break; -// } -// break; -// case '#': -// if (curCmd != End) -// { -// QString arg; -// for (; (m_dialog.at(i) != '%') && (m_dialog.at(i) != '#'); ++i) -// arg += m_dialog.at(i); -// bool ok; -// int temp = arg.toInt(&ok); -// int invError = 0; -// const Map* map = NULL; -// ++numArgs; -// switch (curCmd) -// { -// case FlipFlag: -// case SetFlag: -// case UnsetFlag: -// case RandomizeFlag: -// if (numArgs == 1) -// { -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Bad flag in \"%1\"").arg(CommandStr[curCmd])); -// setValid(false); -// } -// } -// break; -// case TestFlag: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if (!ok) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Bad flag in \"Test Flag\""); -// setValid(false); -// } -// break; -// case 3: -// case 4: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// } -// break; -// case DialogC: -// if (numArgs == 1) -// { -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// } -// else if (numArgs == 2) -// { -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = 2; -// } -// break; -// case YesNo: -// case DeleteMove: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// case 3: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// } -// break; -// case ItemShop: -// if (numArgs == 1) -// { -// if (!ok || (static_cast<const Pokemod*>(pokemod())->storeIndex(temp) == INT_MAX)) -// invError = 1; -// } -// break; -// case GiveItem: -// case TakeItem: -// case CheckItem: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->itemIndex(temp) == INT_MAX)) -// invError = 2; -// break; -// case 3: -// case 4: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// break; -// } -// break; -// case CoinList: -// if (numArgs == 1) -// { -// if (!ok || (static_cast<const Pokemod*>(pokemod())->coinListIndex(temp) == INT_MAX)) -// invError = 1; -// } -// break; -// case TeachMove: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->moveIndex(temp) == INT_MAX)) -// invError = 2; -// break; -// case 3: -// case 4: -// case 5: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// break; -// } -// break; -// case CheckMove: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if ((arg != "Lead") && (arg != "All") && (arg != "0") && (arg != "1")) -// invError = 2; -// break; -// case 3: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->moveIndex(temp) == INT_MAX)) -// invError = 3; -// break; -// case 4: -// case 5: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// break; -// } -// break; -// case GivePokemon: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) ==INT_MAX)) -// invError = 2; -// break; -// case 3: -// if ((arg != "false") && (arg != "true") && (arg != "0") && (arg != "1")) -// invError = 3; -// break; -// case 4: -// if (ok) -// { -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < temp) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Higher level than allowed in \"Give Pokémon\""); -// setValid(false); -// } -// } -// else -// invError = 4; -// break; -// case 5: -// if (!ok) -// invError = 5; -// break; -// case 6: -// case 7: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// break; -// } -// break; -// case TakePokemon: -// case ViewPokemon: -// case CheckSpecies: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) == INT_MAX)) -// invError = 2; -// break; -// case 3: -// case 4: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// break; -// } -// break; -// case ShowPokemon: -// if (numArgs == 1) -// { -// if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) == INT_MAX)) -// invError = 1; -// } -// break; -// case GiveMoney: -// if (numArgs == 1) -// { -// if (ok) -// { -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < temp) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("More money given than can be held in \"Give Money\"", Pokemod::V_Warn); -// setValid(false); -// } -// } -// else -// invError = 1; -// } -// break; -// case TakeMoney: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if (ok) -// { -// if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < temp) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("More money taken than can be held in \"Take Money\""); -// setValid(false); -// } -// } -// else -// invError = 2; -// break; -// case 3: -// case 4: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// break; -// } -// break; -// case MoveEffect: -// case CheckDirection: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) -// invError = 2; -// else -// map = static_cast<const Pokemod*>(pokemod())->mapById(temp); -// break; -// case 3: -// if (map) -// { -// if (!ok || (map->effectIndex(temp) == INT_MAX)) -// invError = 3; -// } -// else if ((arg != "Player") && (arg != "INT_MAX")) -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Unable to validate argument #3 in \"%1\"").arg(CommandStr[curCmd])); -// break; -// case 4: -// if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && ((arg != "Random") || (curCmd == CheckDirection)) && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && ((arg != "4") || (curCmd == CheckDirection))) -// invError = 4; -// break; -// case 5: -// case 6: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// break; -// } -// break; -// case TurnEffect: -// switch (numArgs) -// { -// case 1: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) -// invError = 1; -// else -// map = static_cast<const Pokemod*>(pokemod())->mapById(temp); -// break; -// case 2: -// if (map) -// { -// if (!ok || (map->effectIndex(temp) == INT_MAX)) -// invError = 2; -// } -// else if ((arg != "Player") && (arg != "INT_MAX")) -// static_cast<const Pokemod*>(pokemod())->validationMsg("Unable to validate argument #2 in \"Turn Effect\""); -// map = NULL; -// break; -// case 3: -// if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && (arg != "Random") && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && (arg != "4")) -// invError = 3; -// break; -// } -// break; -// case CheckRoster: -// case CheckLevels: -// case CheckMoney: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if ((arg != "<") && (arg != ">") && (arg != "=")) -// invError = 2; -// break; -// case 3: -// if (ok) -// { -// if (((curCmd == CheckRoster) ? static_cast<const Pokemod*>(pokemod())->rules()->maxParty() : ((curCmd == CheckLevels) ? static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() : static_cast<const Pokemod*>(pokemod())->rules()->maxMoney())) < temp) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("More %1 than can be carried in \"%2\"").arg((curCmd == CheckRoster) ? "party members" : ((curCmd == CheckLevels) ? "level" : "money")).arg(CommandStr[curCmd])); -// setValid(false); -// } -// } -// else -// invError = 3; -// break; -// case 4: -// case 5: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// break; -// } -// break; -// case CheckHeldItems: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// case 3: -// case 4: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// } -// break; -// case Trade: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// case 3: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) == INT_MAX)) -// invError = numArgs; -// case 4: -// if (!ok) -// invError = 4; -// break; -// case 5: -// case 6: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = numArgs; -// break; -// } -// break; -// case Daycare: -// if (numArgs == 1) -// { -// if (!ok) -// invError = 1; -// } -// break; -// case Battle: -// if (numArgs == 1) -// { -// if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) -// invError = 1; -// else -// map = static_cast<const Pokemod*>(pokemod())->mapById(temp); -// } -// else if (numArgs == 2) -// { -// if (map) -// { -// if (!ok || (map->trainerIndex(temp) == INT_MAX)) -// invError = 2; -// } -// else -// static_cast<const Pokemod*>(pokemod())->validationMsg("Unable to validate argument #2 in \"Battle\""); -// map = NULL; -// } -// break; -// case Badge: -// if (numArgs == 1) -// { -// if (!ok || (static_cast<const Pokemod*>(pokemod())->badgeIndex(temp) == INT_MAX)) -// invError = 1; -// } -// break; -// case Warp: -// if (numArgs == 1) -// { -// if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) -// invError = 1; -// else -// map = static_cast<const Pokemod*>(pokemod())->mapById(temp); -// } -// else if (numArgs == 2) -// { -// if (map) -// { -// if (!ok || (map->warpIndex(temp) == INT_MAX)) -// invError = 2; -// } -// else -// static_cast<const Pokemod*>(pokemod())->validationMsg("Unable to validate argument #2 in \"Warp\""); -// map = NULL; -// } -// break; -// case Name: -// case MapSign: -// if (numArgs == 1) -// { -// if (arg == "") -// invError = 1; -// } -// break; -// case Music: -// if (numArgs == 1) -// { -// // FIXME: find sound files -// // if (!QFile(QString("%1/music/%2").arg(static_cast<const Pokemod*>(pokemod())->path()).arg(arg)).exists()) -// // invError = 1; -// } -// break; -// case SoundEffect: -// if (numArgs == 1) -// { -// // FIXME: find sound files -// // if (!QFile(QString("%1/sound/%2").arg(static_cast<const Pokemod*>(pokemod())->path()).arg(arg)).exists()) -// // invError = 1; -// } -// else if (numArgs == 2) -// { -// if (!ok) -// invError = 2; -// } -// break; -// case Timer: -// switch (numArgs) -// { -// case 1: -// if ((arg != "Time") && (arg != "Step") && (arg != "0") && (arg != "1")) -// invError = 1; -// break; -// case 2: -// if (!ok) -// invError = 2; -// break; -// case 3: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) -// invError = 3; -// break; -// } -// break; -// case WildScope: -// if (numArgs == 1) -// { -// if (!ok) + if (m_dialog.isEmpty()) + emit(error("Dialog is empty")); + if (m_dialog.count('%') & 1) + emit(error("Command delimiter mismatch")); + else + { + int curCmd = End; + int numArgs = 0; + for (int i = 0; i < m_dialog.length(); ++i) + { + switch (m_dialog.at(i).toAscii()) + { + case '%': + switch (curCmd) + { + case FlipFlag ... Exit: + if (numArgs != CommandNumArgs[curCmd]) + emit(error(QString("Invalid number of arguments for \"%1\". %2 given when %3 needed"))); + break; + case Menu: + if (!(numArgs & 1)) + emit(error("Invalid number of arguments for Menu")); + break; + case End: + QString curCmdStr; + for (; (m_dialog.at(i) != '%') && (m_dialog.at(i) != '#'); ++i) + curCmdStr += m_dialog.at(i); + if (((curCmd = CommandAbbrStr.indexOf(curCmdStr))) == INT_MAX) + { + if (!curCmdStr.isEmpty()) + emit(error(QString("Invalid command \"%1\"").arg(curCmdStr))); + curCmd = End; + } + numArgs = 0; + break; + } + break; + case '#': + if (curCmd != End) + { + QString arg; + for (; (m_dialog.at(i) != '%') && (m_dialog.at(i) != '#'); ++i) + arg += m_dialog.at(i); + bool ok; + int temp = arg.toInt(&ok); + int invError = 0; + const Map* map = NULL; + ++numArgs; + switch (curCmd) + { + case FlipFlag: + case SetFlag: + case UnsetFlag: + case RandomizeFlag: + if (numArgs == 1) + { + if (!ok) + emit(error(QString("Bad flag in \"%1\"").arg(CommandStr[curCmd]))); + } + break; + case TestFlag: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!ok) + emit(error("Bad flag in \"Test Flag\"")); + break; + case 3: + case 4: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + } + break; + case DialogC: + if (numArgs == 1) + { + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + } + else if (numArgs == 2) + { + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = 2; + } + break; + case YesNo: + case DeleteMove: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + case 3: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + } + break; + case ItemShop: + if (numArgs == 1) + { + if (!ok || (static_cast<const Pokemod*>(pokemod())->storeIndex(temp) == INT_MAX)) + invError = 1; + } + break; + case GiveItem: + case TakeItem: + case CheckItem: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!ok || (static_cast<const Pokemod*>(pokemod())->itemIndex(temp) == INT_MAX)) + invError = 2; + break; + case 3: + case 4: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + break; + } + break; + case CoinList: + if (numArgs == 1) + { + if (!ok || (static_cast<const Pokemod*>(pokemod())->coinListIndex(temp) == INT_MAX)) + invError = 1; + } + break; + case TeachMove: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!ok || (static_cast<const Pokemod*>(pokemod())->moveIndex(temp) == INT_MAX)) + invError = 2; + break; + case 3: + case 4: + case 5: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + break; + } + break; + case CheckMove: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if ((arg != "Lead") && (arg != "All") && (arg != "0") && (arg != "1")) + invError = 2; + break; + case 3: + if (!ok || (static_cast<const Pokemod*>(pokemod())->moveIndex(temp) == INT_MAX)) + invError = 3; + break; + case 4: + case 5: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + break; + } + break; + case GivePokemon: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) ==INT_MAX)) + invError = 2; + break; + case 3: + if ((arg != "false") && (arg != "true") && (arg != "0") && (arg != "1")) + invError = 3; + break; + case 4: + if (ok) + { + if (static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < temp) + emit(error("Higher level than allowed in \"Give Pokémon\"")); + } + else + invError = 4; + break; + case 5: + if (!ok) + invError = 5; + break; + case 6: + case 7: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + break; + } + break; + case TakePokemon: + case ViewPokemon: + case CheckSpecies: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) == INT_MAX)) + invError = 2; + break; + case 3: + case 4: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + break; + } + break; + case ShowPokemon: + if (numArgs == 1) + { + if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) == INT_MAX)) + invError = 1; + } + break; + case GiveMoney: + if (numArgs == 1) + { + if (ok) + { + if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < temp) + emit(warning("More money given than can be held in \"Give Money\"")); + } + else + invError = 1; + } + break; + case TakeMoney: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (ok) + { + if (static_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < temp) + emit(error("More money taken than can be held in \"Take Money\"")); + } + else + invError = 2; + break; + case 3: + case 4: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + break; + } + break; + case MoveEffect: + case CheckDirection: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) + invError = 2; + else + map = static_cast<const Pokemod*>(pokemod())->mapById(temp); + break; + case 3: + if (map) + { + if (!ok || (map->effectIndex(temp) == INT_MAX)) + invError = 3; + } + else if ((arg != "Player") && (arg != "INT_MAX")) + emit(error(QString("Unable to validate argument #3 in \"%1\"").arg(CommandStr[curCmd]))); + break; + case 4: + if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && ((arg != "Random") || (curCmd == CheckDirection)) && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && ((arg != "4") || (curCmd == CheckDirection))) + invError = 4; + break; + case 5: + case 6: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + break; + } + break; + case TurnEffect: + switch (numArgs) + { + case 1: + if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) + invError = 1; + else + map = static_cast<const Pokemod*>(pokemod())->mapById(temp); + break; + case 2: + if (map) + { + if (!ok || (map->effectIndex(temp) == INT_MAX)) + invError = 2; + } + else if ((arg != "Player") && (arg != "INT_MAX")) + emit(error("Unable to validate argument #2 in \"Turn Effect\"")); + map = NULL; + break; + case 3: + if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && (arg != "Random") && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && (arg != "4")) + invError = 3; + break; + } + break; + case CheckRoster: + case CheckLevels: + case CheckMoney: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if ((arg != "<") && (arg != ">") && (arg != "=")) + invError = 2; + break; + case 3: + if (ok) + { + if (((curCmd == CheckRoster) ? static_cast<const Pokemod*>(pokemod())->rules()->maxParty() : ((curCmd == CheckLevels) ? static_cast<const Pokemod*>(pokemod())->rules()->maxLevel() : static_cast<const Pokemod*>(pokemod())->rules()->maxMoney())) < temp) + emit(error(QString("More %1 than can be carried in \"%2\"").arg((curCmd == CheckRoster) ? "party members" : ((curCmd == CheckLevels) ? "level" : "money")).arg(CommandStr[curCmd]))); + } + else + invError = 3; + break; + case 4: + case 5: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + break; + } + break; + case CheckHeldItems: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + case 3: + case 4: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + } + break; + case Trade: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + case 3: + if (!ok || (static_cast<const Pokemod*>(pokemod())->speciesIndex(temp) == INT_MAX)) + invError = numArgs; + case 4: + if (!ok) + invError = 4; + break; + case 5: + case 6: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = numArgs; + break; + } + break; + case Daycare: + if (numArgs == 1) + { + if (!ok) + invError = 1; + } + break; + case Battle: + if (numArgs == 1) + { + if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) + invError = 1; + else + map = static_cast<const Pokemod*>(pokemod())->mapById(temp); + } + else if (numArgs == 2) + { + if (map) + { + if (!ok || (map->trainerIndex(temp) == INT_MAX)) + invError = 2; + } + else + emit(error("Unable to validate argument #2 in \"Battle\"")); + map = NULL; + } + break; + case Badge: + if (numArgs == 1) + { + if (!ok || (static_cast<const Pokemod*>(pokemod())->badgeIndex(temp) == INT_MAX)) + invError = 1; + } + break; + case Warp: + if (numArgs == 1) + { + if (!ok || (static_cast<const Pokemod*>(pokemod())->mapIndex(temp) == INT_MAX)) + invError = 1; + else + map = static_cast<const Pokemod*>(pokemod())->mapById(temp); + } + else if (numArgs == 2) + { + if (map) + { + if (!ok || (map->warpIndex(temp) == INT_MAX)) + invError = 2; + } + else + emit(error("Unable to validate argument #2 in \"Warp\"")); + map = NULL; + } + break; + case Name: + case MapSign: + if (numArgs == 1) + { + if (arg == "") + invError = 1; + } + break; + case Music: + if (numArgs == 1) + { + // FIXME: find sound files +// if (!QFile(QString("%1/music/%2").arg(static_cast<const Pokemod*>(pokemod())->path()).arg(arg)).exists()) // invError = 1; -// } -// break; -// case Safari: -// switch (numArgs) -// { -// case 1: -// if (ok && (static_cast<const Pokemod*>(pokemod())->itemIndex(temp) != INT_MAX)) -// { -// const Item* item = static_cast<const Pokemod*>(pokemod())->itemById(temp); -// bool temp = false; -// for (int i = 0; (i < item->effectCount()) || !temp; ++i) -// { -// if (item->effect(i)->effect() == ItemEffect::E_Ball) -// temp = true; -// } -// if (!temp) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg("Item in argument #1 in \"Safari\" isn\'t a PokéBall"); -// setValid(false); -// } -// } -// else -// invError = 1; -// break; -// case 2: -// if (!ok) -// invError = 2; -// break; -// case 3: -// if (!ok || (static_cast<const Pokemod*>(pokemod())->rules()->maxParty() < temp)) -// invError = 3; -// break; -// } -// break; -// case Menu: -// if (numArgs == 1) -// { -// if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + } + break; + case SoundEffect: + if (numArgs == 1) + { + // FIXME: find sound files +// if (!QFile(QString("%1/sound/%2").arg(static_cast<const Pokemod*>(pokemod())->path()).arg(arg)).exists()) // invError = 1; -// } -// else if (numArgs & 1) -// { -// if (ok) -// { -// if (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX) -// invError = numArgs; -// } -// else -// invError = numArgs; -// } -// else if (arg == "") -// invError = numArgs; -// break; -// } -// if (invError) -// { -// static_cast<const Pokemod*>(pokemod())->validationMsg(QString("Invalid argument #%1 in \"%2\"").arg(invError).arg(CommandStr[curCmd])); -// setValid(false); -// } -// } -// break; -// } -// } -// } -// return valid; + } + else if (numArgs == 2) + { + if (!ok) + invError = 2; + } + break; + case Timer: + switch (numArgs) + { + case 1: + if ((arg != "Time") && (arg != "Step") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!ok) + invError = 2; + break; + case 3: + if (!ok || (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX)) + invError = 3; + break; + } + break; + case WildScope: + if (numArgs == 1) + { + if (!ok) + invError = 1; + } + break; + case Safari: + switch (numArgs) + { + case 1: + if (ok && (static_cast<const Pokemod*>(pokemod())->itemIndex(temp) != INT_MAX)) + { + const Item* item = static_cast<const Pokemod*>(pokemod())->itemById(temp); + bool temp = false; + for (int i = 0; (i < item->effectCount()) || !temp; ++i) + { + if (item->effect(i)->effect() == ItemEffect::E_Ball) + temp = true; + } + if (!temp) + emit(error("Item in argument #1 in \"Safari\" isn\'t a PokéBall")); + } + else + invError = 1; + break; + case 2: + if (!ok) + invError = 2; + break; + case 3: + if (!ok || (static_cast<const Pokemod*>(pokemod())->rules()->maxParty() < temp)) + invError = 3; + break; + } + break; + case Menu: + if (numArgs == 1) + { + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + } + else if (numArgs & 1) + { + if (ok) + { + if (static_cast<const Pokemod*>(pokemod())->dialogIndex(temp) == INT_MAX) + invError = numArgs; + } + else + invError = numArgs; + } + else if (arg == "") + invError = numArgs; + break; + } + if (invError) + emit(error(QString("Invalid argument #%1 in \"%2\"").arg(invError).arg(CommandStr[curCmd]))); + } + break; + } + } + } } void Dialog::load(const QDomElement& xml, int id) @@ -693,7 +650,7 @@ void Dialog::insertCommand(const int position, const QString& command) { if (m_dialog.length() < position) { - boundsError("command"); + emit(error(bounds("command"))); return; } m_dialog.insert(position, command); |
