diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-06-28 15:25:39 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-06-28 15:25:39 +0000 |
| commit | 9102febc37475af113681eaaee02ecc2ea04b4da (patch) | |
| tree | ad08b65668913258d28022f79b202ceaeddfb7c8 /pokemod | |
| parent | 5c3ca621f75587173bab3d946aee81dd2d36f495 (diff) | |
Minor various fixes, Dialog validation started, GUI fixes, String methods added
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@21 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod')
| -rw-r--r-- | pokemod/Badge.cpp | 18 | ||||
| -rw-r--r-- | pokemod/Badge.h | 4 | ||||
| -rw-r--r-- | pokemod/Dialog.cpp | 545 | ||||
| -rw-r--r-- | pokemod/Dialog.h | 5 | ||||
| -rw-r--r-- | pokemod/Ini.cpp | 165 | ||||
| -rw-r--r-- | pokemod/Ini.h | 19 | ||||
| -rw-r--r-- | pokemod/Path.cpp | 2 | ||||
| -rw-r--r-- | pokemod/Pokemod.cpp | 230 | ||||
| -rw-r--r-- | pokemod/Pokemod.h | 49 | ||||
| -rw-r--r-- | pokemod/Pokemon.cpp | 184 | ||||
| -rw-r--r-- | pokemod/Pokemon.h | 14 | ||||
| -rw-r--r-- | pokemod/Ref.h | 8 | ||||
| -rw-r--r-- | pokemod/StatusEffect.h | 1 | ||||
| -rw-r--r-- | pokemod/String.cpp | 113 | ||||
| -rw-r--r-- | pokemod/String.h | 22 | ||||
| -rw-r--r-- | pokemod/TODO | 15 | ||||
| -rw-r--r-- | pokemod/pokemod_inc.h | 2 |
17 files changed, 999 insertions, 397 deletions
diff --git a/pokemod/Badge.cpp b/pokemod/Badge.cpp index 6edef52a..870ab46a 100644 --- a/pokemod/Badge.cpp +++ b/pokemod/Badge.cpp @@ -64,7 +64,7 @@ void PokeGen::PokeMod::Badge::Validate() LogVarNotValid("Badge", id, "face sprite", name);
isValid = false;
}
- if (!Path(pokemod->GetPath() + "badge/badge/" + name + ".png").DoesExist()) + if (!Path(pokemod->GetPath() + "badge/badge/" + name + ".png").DoesExist())
{
LogVarNotValid("Badge", id, "badge sprite", name);
isValid = false;
@@ -84,15 +84,15 @@ void PokeGen::PokeMod::Badge::Validate(const wxListBox &output) output.Append(ConsoleLogVarNotSet("Badge", id, "name"));
isValid = false;
}
- if (!Path(pokemod->GetPath() + "badge/face/" + name + ".png").DoesExist()) - { - LogVarNotValid("Badge", id, "face sprite", name); + if (!Path(pokemod->GetPath() + "badge/face/" + name + ".png").DoesExist())
+ {
+ LogVarNotValid("Badge", id, "face sprite", name);
output.Append(ConsoleLogVarNotValid("Badge", "face sprite", id, name));
isValid = false;
}
- if (!Path(pokemod->GetPath() + "badge/badge/" + name + ".png").DoesExist()) - { - LogVarNotValid("Badge", id, "badge sprite", name); + if (!Path(pokemod->GetPath() + "badge/badge/" + name + ".png").DoesExist())
+ {
+ LogVarNotValid("Badge", id, "badge sprite", name);
output.Append(ConsoleLogVarNotValid("Badge", "badge sprite", id, name));
isValid = false;
}
@@ -150,13 +150,13 @@ void PokeGen::PokeMod::Badge::SetName(const String &n) name = n;
}
-void PokeGen::PokeMod::Badge::SetFace(const Path &f)
+void PokeGen::PokeMod::Badge::SetFace(Path &f)
{
LogSetVar("Badge", id, "face", f, name);
f.CopyTo(pokemod->GetPath() + "badge/face/" + name + ".png");
}
-void PokeGen::PokeMod::Badge::SetBadge(const Path &b)
+void PokeGen::PokeMod::Badge::SetBadge(Path &b)
{
LogSetVar("Badge", id, "badge", b, name);
b.CopyTo(pokemod->GetPath() + "badge/badge/" + name + ".png");
diff --git a/pokemod/Badge.h b/pokemod/Badge.h index afb7f31c..f2e1bd5f 100644 --- a/pokemod/Badge.h +++ b/pokemod/Badge.h @@ -47,8 +47,8 @@ namespace PokeGen void ExportIni(std::ofstream &fout) const;
void SetName(const String &n);
- void SetFace(const Path &f);
- void SetBadge(const Path &b);
+ void SetFace(Path &f);
+ void SetBadge(Path &b);
void SetObey(const unsigned o);
void SetStat(const unsigned s, const unsigned n, const unsigned d);
void SetStatNum(const unsigned s, const unsigned n);
diff --git a/pokemod/Dialog.cpp b/pokemod/Dialog.cpp index 0ff37cef..53e3afc0 100644 --- a/pokemod/Dialog.cpp +++ b/pokemod/Dialog.cpp @@ -51,9 +51,546 @@ void PokeGen::PokeMod::Dialog::Validate(const wxListBox &output) void PokeGen::PokeMod::Dialog::Validate()
#endif
{
- LogValidateStart("Dialog", id);
- // TODO (Validation#1#): Dialog Validation
-# warning "Dialog Validation"
+ LogValidateStart("Dialog", id); + if (dialog == "") + { + LogVarNotSet("Dialog", id, "dialog"); + isValid = false; + } + if (dialog.Count('%') % 2) + { + Log(String("Dialog: Command delimiter mismatch in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + else + { + unsigned curCmd = DC_END; + unsigned numArgs = 0; + for (unsigned i = 0; i < dialog.length(); ++i) + { + switch (dialog[i]) + { + case '%': + switch (curCmd) + { + case DC_FLIP_FLAG ... DC_EXIT: + if (numArgs != DialogCommandNumArgs[curCmd]) + { + Log(String("Dialog: Invalid number of arguments (%u) for %s (%u wanted) in %u", numArgs, DialogCommandStr[curCmd], DialogCommandNumArgs[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_MENU: + if (!(numArgs % 2)) + { + Log(String("Dialog: Argument mismatch for Menu in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_END: + String curCmdStr; + for (; (dialog[i] != '%') && (dialog[i] != '#'); ++i) + curCmdStr.append(1, dialog[i]); + if (((curCmd = FindIn(DC_END, curCmdStr, DialogCommandAbbrStr)) == DC_END)) + { + if (curCmdStr != "") + { + Log(String("Dialog: Invalid command \"%s\" in %u", curCmdStr.c_str(), id), PM_DEBUG_ERROR); + isValid = false; + } + curCmd = DC_END; + } + numArgs = 0; + } + case '#': + if (curCmd != DC_END) + { + String arg; + unsigned tempU; + unsigned long tempUL; + Map *map = NULL; + for (; (dialog[i] != '%') && (dialog[i] != '#'); ++i) + arg.append(1, dialog[i]); + ++numArgs; + // TODO (Ben#1#): Argument parsing checks + switch (curCmd) + { + case DC_FLIP_FLAG: + case DC_SET_FLAG: + case DC_UNSET_FLAG: + case DC_RANDOMIZE_FLAG: + if (numArgs == 1) + { + if (!arg.Convert(tempUL)) + { + Log(String("Dialog: Bad flag in \"%s\" on %u", DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Too many arguments (%u) for \"%s\" in %u", numArgs, DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_TEST_FLAG: + switch (numArgs) + { + case 1: + if ((arg != "Call") || (arg != "Goto") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #1 in \"Test Flag\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 2: + if ((arg != "Unset") || (arg != "Set") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #2 in \"Test Flag\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 3: + if (!arg.Convert(tempUL)) + { + Log(String("Dialog: Bad flag in \"Test Flag\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 4: + case 5: + if (!arg.Convert(tempU) || !pokemod->GetDialog(tempU)) + { + Log(String("Dialog: Invalid argument #%u in \"Test Flag\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + default: + Log(String("Dialog: Too many arguments (%u) for \"Test Flag\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_DIALOG: + switch (numArgs) + { + case 1: + if ((arg != "Call") || (arg != "Goto") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #1 in \"Dialog\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 2: + if (!arg.Convert(tempU) || !pokemod->GetDialog(tempU)) + { + Log(String("Dialog: Invalid argument #%u in \"Dialog\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + default: + Log(String("Dialog: Too many arguments (%u) for \"Dialog\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_YES_NO: + case DC_DELETE_MOVE: + switch (numArgs) + { + case 1: + if ((arg != "Call") || (arg != "Goto") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #1 in \"%s\" in %u", DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 2: + case 3: + if (!arg.Convert(tempU) || !pokemod->GetDialog(tempU)) + { + Log(String("Dialog: Invalid argument #%u in \"%s\" in %u", numArgs, DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + default: + Log(String("Dialog: Too many arguments (%u) for \"%s\" in %u", numArgs, DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_ITEM_SHOP: + if (numArgs == 1) + { + if (!(arg.Convert(tempU) ? pokemod->GetStore(tempU) : pokemod->GetStore(arg))) + { + Log(String("Dialog: Invalid argument #1 in \"Test Flag\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Too many arguments (%u) for \"Test Flag\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_GIVE_ITEM: + case DC_TAKE_ITEM: + case DC_CHECK_ITEM: + switch (numArgs) + { + case 1: + if ((arg != "Call") || (arg != "Goto") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #1 in \"%s\" in %u", DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 2: + if (!(arg.Convert(tempU) ? pokemod->GetItem(tempU) : pokemod->GetItem(arg))) + { + Log(String("Dialog: Invalid argument #2 in \"%s\" in %u", DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 3: + case 4: + if (!arg.Convert(tempU) || !pokemod->GetDialog(tempU)) + { + Log(String("Dialog: Invalid argument #%u in \"%s\" in %u", numArgs, DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + default: + Log(String("Dialog: Too many arguments (%u) for \"%s\" in %u", numArgs, DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_COIN_LIST: + if (numArgs == 1) + { + if (!(arg.Convert(tempU) ? pokemod->GetCoinList(tempU) : pokemod->GetCoinList(arg))) + { + Log(String("Dialog: Invalid argument #1 in \"Coin List\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Too many arguments (%u) for \"Coin List\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_TEACH_MOVE: + switch (numArgs) + { + case 1: + if ((arg != "Call") || (arg != "Goto") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #1 in \"Teach Move\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 2: + if (!(arg.Convert(tempU) ? pokemod->GetMove(tempU) : pokemod->GetMove(arg))) + { + Log(String("Dialog: Invalid argument #2 in \"Teach Move\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 3: + case 4: + case 5: + if (!arg.Convert(tempU) || !pokemod->GetDialog(tempU)) + { + Log(String("Dialog: Invalid argument #%u in \"Teach Move\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + default: + Log(String("Dialog: Too many arguments (%u) for \"Teach Move\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_CHECK_MOVE: + switch (numArgs) + { + case 1: + if ((arg != "Call") || (arg != "Goto") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #1 in \"Check Move\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 2: + if ((arg != "Lead") || (arg != "All") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #2 in \"Check Move\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 3: + if (!(arg.Convert(tempU) ? pokemod->GetMove(tempU) : pokemod->GetMove(arg))) + { + Log(String("Dialog: Invalid argument #3 in \"Check Move\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 4: + case 5: + if (!arg.Convert(tempU) || !pokemod->GetDialog(tempU)) + { + Log(String("Dialog: Invalid argument #%u in \"Check Move\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + default: + Log(String("Dialog: Too many arguments (%u) for \"Check Move\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_GIVE_POKEMON: + break; + case DC_TAKE_POKEMON: + break; + case DC_SHOW_POKEMON: + break; + case DC_VIEW_POKEMON: + break; + case DC_GIVE_MONEY: + if (numArgs == 1) + { + if (arg.Convert(tempUL)) + { + if (pokemod->GetMaxMoney() < tempUL) + { + Log(String("Dialog: More money given than can be held in \"Give Money\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Invalid argument #1 in \"Give Money\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Too many arguments (%u) for \"Give Money\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_TAKE_MONEY: + switch (numArgs) + { + case 1: + if ((arg != "Call") || (arg != "Goto") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #1 in \"Take Money\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 2: + if (arg.Convert(tempUL)) + { + if (pokemod->GetMaxMoney() < tempUL) + { + Log(String("Dialog: More money taken than can be held in \"Take Money\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Invalid argument #2 in \"Take Money\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 3: + case 4: + if (!arg.Convert(tempU) || !pokemod->GetDialog(tempU)) + { + Log(String("Dialog: Invalid argument #%u in \"Take Money\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + default: + Log(String("Dialog: Too many arguments (%u) for \"Take Money\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_MOVE_EFFECT: + break; + case DC_TURN_EFFECT: + break; + case DC_CHECK_DIRECTION: + break; + case DC_CHECK_ROSTER: + break; + case DC_CHECK_LEVELS: + break; + case DC_CHECK_SPECIES: + break; + case DC_CHECK_HELD_ITEMS: + break; + case DC_CHECK_MONEY: + switch (numArgs) + { + case 1: + if ((arg != "Call") || (arg != "Goto") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #1 in \"Check Money\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 2: + if ((arg != "<") || (arg != ">") || (arg != "=")) + { + Log(String("Dialog: Invalid argument #2 in \"Check Money\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 3: + if (arg.Convert(tempUL)) + { + if (pokemod->GetMaxMoney() < tempUL) + { + Log(String("Dialog: More money than can be held in \"Check Money\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Invalid argument #3 in \"Check Money\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case 4: + case 5: + if (!arg.Convert(tempU) || !pokemod->GetDialog(tempU)) + { + Log(String("Dialog: Invalid argument #%u in \"Check Money\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + default: + Log(String("Dialog: Too many arguments (%u) for \"Check Money\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_TRADE: + break; + case DC_DAYCARE: + break; + case DC_BATTLE: + break; + case DC_BADGE: + break; + case DC_WARP: + if (numArgs == 1) + { + if (!(map = (arg.Convert(tempU) ? (Map *)pokemod->GetMap(tempU) : (Map *)pokemod->GetMap(arg))) + { + Log(String("Dialog: Invalid argument #1 in \"Warp\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else if (numArgs == 2) + { + if (map) + { + if (!(arg.Convert(tempU) ? map->GetWarp(tempU) : map->GetWarp(arg))) + { + Log(String("Dialog: Invalid argument #3 in \"Warp\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + Log(String("Dialog: Unable to validate argument #2 in \"Warp\" in %u", id), PM_DEBUG_ERROR); + } + else + Log(String("Dialog: Too many arguments (%u) for \"Warp\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + break; + case DC_NAME: + if (numArgs == 1) + { + if (arg == "") + { + Log(String("Dialog: Invalid argument #1 in \"Name\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Too many arguments (%u) for \"Name\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_MUSIC: + case DC_SOUND_EFFECT: + if (numArgs == 1) + { + if (!Path(pokemod->GetPath() + "sound/" + arg).DoesExist()) + { + Log(String("Dialog: Invalid argument #1 in \"%s\" in %u", DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Too many arguments (%u) for \"%s\" in %u", numArgs, DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + } + break; + case DC_TIMER: + break; + case DC_MAP_SIGN: + break; + case DC_WILD_SCOPE: + break; + case DC_SAFARI: + break; + case DC_HEAL_PARTY: + case DC_REFRESH: + case DC_CLEAR: + case DC_PAUSE: + case DC_NEW_LINE: + case DC_EXIT: + Log(String("Dialog: Too many arguments (%u) for \"%s\" in %u", numArgs, DialogCommandStr[curCmd], id), PM_DEBUG_ERROR); + isValid = false; + break; + case DC_MENU: + if (numArgs == 1) + { + if ((arg != "Call") || (arg != "Goto") || (arg != "0") || (arg != "1")) + { + Log(String("Dialog: Invalid argument #1 in \"Menu\" in %u", id), PM_DEBUG_ERROR); + isValid = false; + } + } + else if (numArgs % 2) + { + if (arg.Convert(tempU)) + { + if (!pokemod->GetDialog(tempU)) + { + Log(String("Dialog: Invalid argument #%u in \"Menu\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + } + else + { + Log(String("Dialog: Invalid argument #%u in \"Menu\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + } + else if (arg == "") + { + Log(String("Dialog: Invalid argument #%u in \"Menu\" in %u", numArgs, id), PM_DEBUG_ERROR); + isValid = false; + } + } + } + } + } + }
LogValidateOver("Dialog", id, isValid);
}
@@ -102,5 +639,5 @@ void PokeGen::PokeMod::Dialog::InsertDialogCommand(const String &cmd, const unsi Log(String("Dialog: Position out-of-range in %u", id), PM_DEBUG_ERROR);
return;
}
- dialog.insert();
+ dialog.insert(pos, cmd);
}
diff --git a/pokemod/Dialog.h b/pokemod/Dialog.h index 8c81cca2..28f879cf 100644 --- a/pokemod/Dialog.h +++ b/pokemod/Dialog.h @@ -23,8 +23,9 @@ #ifndef __POKEMOD_DIALOG__
#define __POKEMOD_DIALOG__
-
-#include "Object.h"
+ +#include "Object.h" +#include "Path.h"
#include "String.h"
#include "Pokemod.h"
diff --git a/pokemod/Ini.cpp b/pokemod/Ini.cpp index 6fd7347f..e78adef6 100644 --- a/pokemod/Ini.cpp +++ b/pokemod/Ini.cpp @@ -47,6 +47,21 @@ void PokeGen::PokeMod::Ini::Export(const String &p) const Export(fout);
}
+void PokeGen::PokeMod::Ini::AddField(const String &n, const bool v) +{ + fields[n] = v ? "true" : "false"; +} + +void PokeGen::PokeMod::Ini::AddField(const String &n, const char v) +{ + fields[n] = String("%c", v); +} + +void PokeGen::PokeMod::Ini::AddField(const String &n, const unsigned char v) +{ + fields[n] = String("%x", v); +} + void PokeGen::PokeMod::Ini::AddField(const String &n, const int v)
{
fields[n] = String("%d", v);
@@ -57,36 +72,54 @@ void PokeGen::PokeMod::Ini::AddField(const String &n, const unsigned v) fields[n] = String("%u", v);
}
-void PokeGen::PokeMod::Ini::AddField(const String &n, const unsigned char v)
-{
- fields[n] = String("%x", v);
-}
-
-void PokeGen::PokeMod::Ini::AddField(const String &n, const char *v)
-{
- fields[n] = v;
-}
-
+void PokeGen::PokeMod::Ini::AddField(const String &n, const double v) +{ + fields[n] = String("%f", v); +} + void PokeGen::PokeMod::Ini::AddField(const String &n, const String &v)
{
fields[n] = v;
}
-void PokeGen::PokeMod::Ini::AddField(const String &n, const bool v)
-{
- fields[n] = v ? "true" : "false";
-}
-
-void PokeGen::PokeMod::Ini::AddField(const String &n, const double v)
-{
- fields[n] = String("%f", v);
-}
-
PokeGen::PokeMod::String PokeGen::PokeMod::Ini::GetName() const
{
return name;
}
+void PokeGen::PokeMod::Ini::GetValue(const String &field, bool &val, const bool def) +{ + if (!fields.count(field)) + { + val = def; + return; + } + if (!fields[field].Convert(val)) + val = def; +} + +void PokeGen::PokeMod::Ini::GetValue(const String &field, char &val, const char def) +{ + if (!fields.count(field)) + { + val = def; + return; + } + if (!fields[field].Convert(val)) + val = def; +} + +void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned char &val, const unsigned char def) +{ + if (!fields.count(field)) + { + val = def; + return; + } + if (!fields[field].Convert(val)) + val = def; +} + void PokeGen::PokeMod::Ini::GetValue(const String &field, int &val, const int def)
{
if (!fields.count(field))
@@ -94,10 +127,8 @@ void PokeGen::PokeMod::Ini::GetValue(const String &field, int &val, const int de val = def;
return;
}
- long temp;
- char *end;
- temp = std::strtol(fields[field], &end, 10);
- val = ((temp < INT_MIN) || (INT_MAX < temp) || *end) ? def : temp;
+ if (!fields[field].Convert(val)) + val = def; }
void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned &val, const unsigned def)
@@ -107,25 +138,43 @@ void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned &val, const u val = def;
return;
}
- unsigned long temp;
- char *end;
- temp = std::strtoul(fields[field], &end, 10);
- val = ((UINT_MAX < temp) || *end) ? def : temp;
-}
-
-void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned char &val, const unsigned char def)
-{
- if (!fields.count(field))
- {
- val = def;
- return;
- }
- unsigned long temp;
- char *end;
- temp = std::strtoul(fields[field], &end, 10);
- val = ((UCHAR_MAX < temp) || *end) ? def : temp;
-}
-
+ if (!fields[field].Convert(val)) + val = def; +}
+
+void PokeGen::PokeMod::Ini::GetValue(const String &field, long &val, const long def) +{ + if (!fields.count(field)) + { + val = def; + return; + } + if (!fields[field].Convert(val)) + val = def; +} + +void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned long &val, const unsigned long def) +{ + if (!fields.count(field)) + { + val = def; + return; + } + if (!fields[field].Convert(val)) + val = def; +} + +void PokeGen::PokeMod::Ini::GetValue(const String &field, double &val, const double def) +{ + if (!fields.count(field)) + { + val = def; + return; + } + if (!fields[field].Convert(val)) + val = def; +} + void PokeGen::PokeMod::Ini::GetValue(const String &field, String &val, const String &def)
{
if (!fields.count(field))
@@ -136,34 +185,6 @@ void PokeGen::PokeMod::Ini::GetValue(const String &field, String &val, const Str val = fields[field];
}
-void PokeGen::PokeMod::Ini::GetValue(const String &field, bool &val, const bool def)
-{
- if (!fields.count(field))
- {
- val = def;
- return;
- }
- if (fields[field] == "true")
- val = true;
- else if (fields[field] == "false")
- val = false;
- else
- val = def;
-}
-
-void PokeGen::PokeMod::Ini::GetValue(const String &field, double &val, const double def)
-{
- if (!fields.count(field))
- {
- val = def;
- return;
- }
- char *end;
- val = std::strtod(fields[field].c_str(), &end);
- if (*end)
- val = def;
-}
-
bool PokeGen::PokeMod::Ini::IsValid() const
{
return isValid;
@@ -175,7 +196,7 @@ bool PokeGen::PokeMod::Ini::Load(std::ifstream &file) std::string field;
std::string value;
fields.clear();
- unsigned pos;
+ size_t pos;
name = "";
isValid = true;
std::getline(file, line);
diff --git a/pokemod/Ini.h b/pokemod/Ini.h index 79b1c07f..685b16cf 100644 --- a/pokemod/Ini.h +++ b/pokemod/Ini.h @@ -41,21 +41,26 @@ namespace PokeGen void Export(std::ofstream &file) const;
void Export(const String &p) const;
+ void AddField(const String &n, const bool v); + void AddField(const String &n, const char v); + void AddField(const String &n, const unsigned char v); void AddField(const String &n, const int v);
void AddField(const String &n, const unsigned v);
- void AddField(const String &n, const unsigned char v);
- void AddField(const String &n, const char *v);
+ void AddField(const String &n, const long v); + void AddField(const String &n, const unsigned long v); + void AddField(const String &n, const double v); void AddField(const String &n, const String &v);
- void AddField(const String &n, const bool v);
- void AddField(const String &n, const double v);
String GetName() const;
+ void GetValue(const String &field, bool &val, const bool def = true); + void GetValue(const String &field, char &val, const char def = CHAR_MAX); + void GetValue(const String &field, unsigned char &val, const unsigned char def = UCHAR_MAX); void GetValue(const String &field, int &val, const int def = INT_MAX);
void GetValue(const String &field, unsigned &val, const unsigned def = UINT_MAX);
- void GetValue(const String &field, unsigned char &val, const unsigned char def = UCHAR_MAX);
+ void GetValue(const String &field, long &val, const long def = LONG_MAX); + void GetValue(const String &field, unsigned long &val, const unsigned long def = ULONG_MAX); + void GetValue(const String &field, double &val, const double def = 0); void GetValue(const String &field, String &val, const String &def = "");
- void GetValue(const String &field, bool &val, const bool def = true);
- void GetValue(const String &field, double &val, const double def = 0);
bool IsValid() const;
protected:
diff --git a/pokemod/Path.cpp b/pokemod/Path.cpp index a8fa5ebb..2e7e8a20 100644 --- a/pokemod/Path.cpp +++ b/pokemod/Path.cpp @@ -59,7 +59,7 @@ bool PokeGen::PokeMod::Path::DoesExist() bool PokeGen::PokeMod::Path::HasExtension(const String &ext)
{
- unsigned pos = rfind('.');
+ size_t pos = rfind('.');
bool ret = true;
String fileExt(substr(pos + 1));
if ((pos == npos) || (pos + 1 == length()) || (fileExt.length() != ext.length()))
diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index 14c1170e..80182f00 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -23,7 +23,7 @@ #include "Pokemod.h"
-PokeGen::PokeMod::Pokemod::Pokemod() :
+PokeGen::PokeMod::Pokemod::Pokemod(const String &f) :
title(""),
version(""),
description(""),
@@ -60,27 +60,16 @@ PokeGen::PokeMod::Pokemod::Pokemod() : startCoordinate(0, 0),
startDirection(UINT_MAX),
startDialog(UINT_MAX),
- walkSkin(""),
- bikeSkin(""),
- surfSkin(""),
- flySkin(""),
- fishSkin(""),
- surfFishSkin(""),
superPCUname(""),
superPCPasswd(""),
struggleMove(UINT_MAX),
confuseMove(UINT_MAX),
- typeChart(1, 1, Frac(1, 1, true))
+ typeChart(1, 1, Frac(1, 1, true)),
+ file(f)
{
LogCtor("Pokemod", 0);
}
-PokeGen::PokeMod::Pokemod::Pokemod(std::ifstream &fin)
-{
- LogCtorIni("Pokemod", 0);
- ImportIni(fin);
-}
-
PokeGen::PokeMod::Pokemod::~Pokemod()
{
LogDtor("Pokemod", 0);
@@ -178,52 +167,34 @@ void PokeGen::PokeMod::Pokemod::Validate() LogVarNotValid("Pokemod", 0, "startDialog");
isValid = false;
}
- if (!walkSkin.DoesExist())
+ if (!Path(GetPath() + "skins/walk.png").DoesExist())
{
- if (walkSkin == "")
- LogVarNotSet("Pokemod", 0, "walkSkin");
- else
- LogVarNotValid("Pokemod", 0, "walkSkin");
+ LogVarNotValid("Pokemod", 0, "walkSkin");
isValid = false;
}
- if (!bikeSkin.DoesExist())
+ if (!Path(GetPath() + "skins/bike.png").DoesExist())
{
- if (bikeSkin == "")
- LogVarNotSet("Pokemod", 0, "bikeSkin");
- else
- LogVarNotValid("Pokemod", 0, "bikeSkin");
+ LogVarNotValid("Pokemod", 0, "bikeSkin");
isValid = false;
}
- if (!surfSkin.DoesExist())
+ if (!Path(GetPath() + "skins/surf.png").DoesExist())
{
- if (surfSkin == "")
- LogVarNotSet("Pokemod", 0, "surfSkin");
- else
- LogVarNotValid("Pokemod", 0, "surfSkin");
+ LogVarNotValid("Pokemod", 0, "surfSkin");
isValid = false;
}
- if (!flySkin.DoesExist())
+ if (!Path(GetPath() + "skins/fly.png").DoesExist())
{
- if (flySkin == "")
- LogVarNotSet("Pokemod", 0, "flySkin");
- else
- LogVarNotValid("Pokemod", 0, "flySkin");
+ LogVarNotValid("Pokemod", 0, "flySkin");
isValid = false;
}
- if (!fishSkin.DoesExist())
+ if (!Path(GetPath() + "skins/fish.png").DoesExist())
{
- if (fishSkin == "")
- LogVarNotSet("Pokemod", 0, "fishSkin");
- else
- LogVarNotValid("Pokemod", 0, "fishSkin");
+ LogVarNotValid("Pokemod", 0, "fishSkin");
isValid = false;
}
- if (!surfFishSkin.DoesExist())
+ if (!Path(GetPath() + "skins/surfFish.png").DoesExist())
{
- if (surfFishSkin == "")
- LogVarNotSet("Pokemod", 0, "surfFishSkin");
- else
- LogVarNotValid("Pokemod", 0, "surfFishSkin");
+ LogVarNotValid("Pokemod", 0, "surfFishSkin");
isValid = false;
}
if (superPCUname == "")
@@ -937,88 +908,40 @@ void PokeGen::PokeMod::Pokemod::Validate(const wxListBox &output) output.Append(ConsoleLogVarNotValid("Pokemod", 0, "startDialog"));
isValid = false;
}
- if (!walkSkin.DoesExist())
+ if (!Path(GetPath() + "skins/walk.png").DoesExist())
{
- if (walkSkin == "")
- {
- LogVarNotSet("Pokemod", 0, "walkSkin");
- output.Append(ConsoleLogVarNotSet("Pokemod", 0, "walkSkin"));
- }
- else
- {
- LogVarNotValid("Pokemod", 0, "walkSkin");
- output.Append(ConsoleLogVarNotValid("Pokemod", 0, "walkSkin"));
- }
+ LogVarNotValid("Pokemod", 0, "walkSkin");
+ output.Append(ConsoleLogVarNotValid("Pokemod", 0, "walkSkin"));
isValid = false;
}
- if (!bikeSkin.DoesExist())
+ if (!Path(GetPath() + "skins/bike.png").DoesExist())
{
- if (bikeSkin == "")
- {
- LogVarNotSet("Pokemod", 0, "bikeSkin");
- output.Append(ConsoleLogVarNotSet("Pokemod", 0, "bikeSkin"));
- }
- else
- {
- LogVarNotValid("Pokemod", 0, "bikeSkin");
- output.Append(ConsoleLogVarNotValid("Pokemod", 0, "bikeSkin"));
- }
+ LogVarNotValid("Pokemod", 0, "bikeSkin");
+ output.Append(ConsoleLogVarNotValid("Pokemod", 0, "bikeSkin"));
isValid = false;
}
- if (!surfSkin.DoesExist())
+ if (!Path(GetPath() + "skins/surf.png").DoesExist())
{
- if (surfSkin == "")
- {
- LogVarNotSet("Pokemod", 0, "surfSkin");
- output.Append(ConsoleLogVarNotSet("Pokemod", 0, "surfSkin"));
- }
- else
- {
- LogVarNotValid("Pokemod", 0, "surfSkin");
- output.Append(ConsoleLogVarNotValid("Pokemod", 0, "surfSkin"));
- }
+ LogVarNotValid("Pokemod", 0, "surfSkin");
+ output.Append(ConsoleLogVarNotValid("Pokemod", 0, "surfSkin"));
isValid = false;
}
- if (!flySkin.DoesExist())
+ if (!Path(GetPath() + "skins/fly.png").DoesExist())
{
- if (flySkin == "")
- {
- LogVarNotSet("Pokemod", 0, "flySkin");
- output.Append(ConsoleLogVarNotSet("Pokemod", 0, "flySkin"));
- }
- else
- {
- LogVarNotValid("Pokemod", 0, "flySkin");
- output.Append(ConsoleLogVarNotValid("Pokemod", 0, "flySkin"));
- }
+ LogVarNotValid("Pokemod", 0, "flySkin");
+ output.Append(ConsoleLogVarNotValid("Pokemod", 0, "flySkin"));
isValid = false;
}
- if (!fishSkin.DoesExist())
+ if (!Path(GetPath() + "skins/fish.png").DoesExist())
{
- if (fishSkin == "")
- {
- LogVarNotSet("Pokemod", 0, "fishSkin");
- output.Append(ConsoleLogVarNotSet("Pokemod", 0, "fishSkin"));
- }
- else
- {
- LogVarNotValid("Pokemod", 0, "fishSkin");
- output.Append(ConsoleLogVarNotValid("Pokemod", 0, "fishSkin"));
- }
+ LogVarNotValid("Pokemod", 0, "fishSkin");
+ output.Append(ConsoleLogVarNotValid("Pokemod", 0, "fishSkin"));
isValid = false;
}
- if (!surfFishSkin.DoesExist())
+ if (!Path(GetPath() + "skins/surfFish.png").DoesExist())
{
- if (surfFishSkin == "")
- {
- LogVarNotSet("Pokemod", 0, "surfFishSkin");
- output.Append(ConsoleLogVarNotSet("Pokemod", 0, "surfFishSkin"));
- }
- else
- {
- LogVarNotValid("Pokemod", 0, "surfFishSkin");
- output.Append(ConsoleLogVarNotValid("Pokemod", 0, "surfFishSkin"));
- }
+ LogVarNotValid("Pokemod", 0, "surfFishSkin");
+ output.Append(ConsoleLogVarNotValid("Pokemod", 0, "surfFishSkin"));
isValid = false;
}
if (superPCUname == "")
@@ -1675,11 +1598,20 @@ void PokeGen::PokeMod::Pokemod::Validate(const wxListBox &output) }
#endif
-void PokeGen::PokeMod::Pokemod::ImportIni(std::ifstream &fin)
+PokeGen::PokeMod::Path PokeGen::PokeMod::Pokemod::GetPath() const
+{
+ Path f = file;
+ f.erase(f.rfind('/') + 1);
+ return f;
+}
+
+void PokeGen::PokeMod::Pokemod::ImportIni(const String &f)
{
LogImportStart("Pokemod");
std::vector<Ini> sections;
Ini meta("unset");
+ std::ifstream fin(f, std::ios::in);
+ file = f;
while (fin.peek() != '\n')
{
Ini curSection(fin);
@@ -1733,12 +1665,6 @@ void PokeGen::PokeMod::Pokemod::ImportIni(std::ifstream &fin) startCoordinate.Set(i, j);
curSection.GetValue("startDirection", startDirection);
curSection.GetValue("startDialog", startDialog);
- curSection.GetValue("walkSkin", walkSkin);
- curSection.GetValue("bikeSkin", bikeSkin);
- curSection.GetValue("surfSkin", surfSkin);
- curSection.GetValue("flySkin", flySkin);
- curSection.GetValue("fishSkin", fishSkin);
- curSection.GetValue("surfFishSkin", surfFishSkin);
curSection.GetValue("superPCUname", superPCUname);
curSection.GetValue("superPCPasswd", superPCPasswd);
curSection.GetValue("struggleMove", struggleMove);
@@ -1926,10 +1852,12 @@ void PokeGen::PokeMod::Pokemod::ImportIni(std::ifstream &fin) LogImportOver("Pokemod", 0, title);
}
-void PokeGen::PokeMod::Pokemod::ExportIni(std::ofstream &fout) const
+void PokeGen::PokeMod::Pokemod::ExportIni(const String &f) const
{
LogExportStart("Pokemod", 0, title);
Ini exPokemod("pokemod");
+ std::ofstream fout(f, std::ios::out);
+ file = f.c_str();
exPokemod.AddField("title", title);
exPokemod.AddField("version", version);
exPokemod.AddField("description", description);
@@ -1968,12 +1896,6 @@ void PokeGen::PokeMod::Pokemod::ExportIni(std::ofstream &fout) const exPokemod.AddField("startCoordinate-y", startCoordinate.GetY());
exPokemod.AddField("startDirection", startDirection);
exPokemod.AddField("startDialog", startDialog);
- exPokemod.AddField("walkSkin", walkSkin);
- exPokemod.AddField("bikeSkin", bikeSkin);
- exPokemod.AddField("surfSkin", surfSkin);
- exPokemod.AddField("flySkin", flySkin);
- exPokemod.AddField("fishSkin", fishSkin);
- exPokemod.AddField("surfFishSkin", surfFishSkin);
exPokemod.AddField("superPCUname", superPCUname);
exPokemod.AddField("superPCPasswd", superPCPasswd);
exPokemod.AddField("struggleMove", struggleMove);
@@ -2326,40 +2248,40 @@ void PokeGen::PokeMod::Pokemod::SetStartDialog(const unsigned s) startDialog = s;
}
-void PokeGen::PokeMod::Pokemod::SetWalkSkin(const Path &w)
+void PokeGen::PokeMod::Pokemod::SetWalkSkin(Path &w)
{
LogSetVar("Pokemod", 0, "walkSkin", w);
- walkSkin = w;
+ w.CopyTo(GetPath() + "skins/walk.png");
}
-void PokeGen::PokeMod::Pokemod::SetBikeSkin(const Path &b)
+void PokeGen::PokeMod::Pokemod::SetBikeSkin(Path &b)
{
LogSetVar("Pokemod", 0, "bikeSkin", b);
- bikeSkin = b;
+ b.CopyTo(GetPath() + "skins/bike.png");
}
-void PokeGen::PokeMod::Pokemod::SetSurfSkin(const Path &s)
+void PokeGen::PokeMod::Pokemod::SetSurfSkin(Path &s)
{
LogSetVar("Pokemod", 0, "surfSkin", s);
- surfSkin = s;
+ s.CopyTo(GetPath() + "skins/surf.png");
}
-void PokeGen::PokeMod::Pokemod::SetFlySkin(const Path &f)
+void PokeGen::PokeMod::Pokemod::SetFlySkin(Path &f)
{
LogSetVar("Pokemod", 0, "flySkin", f);
- flySkin = f;
+ f.CopyTo(GetPath() + "skins/fly.png");
}
-void PokeGen::PokeMod::Pokemod::SetFishSkin(const Path &f)
+void PokeGen::PokeMod::Pokemod::SetFishSkin(Path &f)
{
LogSetVar("Pokemod", 0, "fishSkin", f);
- fishSkin = f;
+ f.CopyTo(GetPath() + "skins/fish.png");
}
-void PokeGen::PokeMod::Pokemod::SetSurfFishSkin(const Path &s)
+void PokeGen::PokeMod::Pokemod::SetSurfFishSkin(Path &s)
{
LogSetVar("Pokemod", 0, "surfFishSkin", s);
- surfFishSkin = s;
+ s.CopyTo(GetPath() + "skins/surfFish.png");
}
void PokeGen::PokeMod::Pokemod::SetSuperPCUname(const String &u)
@@ -2674,40 +2596,40 @@ PokeGen::PokeMod::String PokeGen::PokeMod::Pokemod::GetStartDialogString() const return "";
}
-PokeGen::PokeMod::Path PokeGen::PokeMod::Pokemod::GetWalkSkin() const
+bool PokeGen::PokeMod::Pokemod::GetWalkSkin() const
{
- LogFetchVar("Pokemod", 0, "walkSkin", walkSkin);
- return walkSkin;
+ LogFetchVar("Pokemod", 0, "walkSkin", 0);
+ return Path(GetPath() + "skins/walk.png").DoesExist();
}
-PokeGen::PokeMod::Path PokeGen::PokeMod::Pokemod::GetBikeSkin() const
+bool PokeGen::PokeMod::Pokemod::GetBikeSkin() const
{
- LogFetchVar("Pokemod", 0, "bikeSkin", bikeSkin);
- return bikeSkin;
+ LogFetchVar("Pokemod", 0, "bikeSkin", 0);
+ return Path(GetPath() + "skins/nike.png").DoesExist();
}
-PokeGen::PokeMod::Path PokeGen::PokeMod::Pokemod::GetSurfSkin() const
+bool PokeGen::PokeMod::Pokemod::GetSurfSkin() const
{
- LogFetchVar("Pokemod", 0, "surfSkin", surfSkin);
- return surfSkin;
+ LogFetchVar("Pokemod", 0, "surfSkin", 0);
+ return Path(GetPath() + "skins/surf.png").DoesExist();
}
-PokeGen::PokeMod::Path PokeGen::PokeMod::Pokemod::GetFlySkin() const
+bool PokeGen::PokeMod::Pokemod::GetFlySkin() const
{
- LogFetchVar("Pokemod", 0, "flySkin", flySkin);
- return flySkin;
+ LogFetchVar("Pokemod", 0, "flySkin", 0);
+ return Path(GetPath() + "skins/fly.png").DoesExist();
}
-PokeGen::PokeMod::Path PokeGen::PokeMod::Pokemod::GetFishSkin() const
+bool PokeGen::PokeMod::Pokemod::GetFishSkin() const
{
- LogFetchVar("Pokemod", 0, "fishSkin", fishSkin);
- return fishSkin;
+ LogFetchVar("Pokemod", 0, "fishSkin", 0);
+ return Path(GetPath() + "skins/fish.png").DoesExist();
}
-PokeGen::PokeMod::Path PokeGen::PokeMod::Pokemod::GetSurfFishSkin() const
+bool PokeGen::PokeMod::Pokemod::GetSurfFishSkin() const
{
- LogFetchVar("Pokemod", 0, "surfFishSkin", surfFishSkin);
- return surfFishSkin;
+ LogFetchVar("Pokemod", 0, "surfFishSkin", 0);
+ return Path(GetPath() + "skins/surfFish.png").DoesExist();
}
PokeGen::PokeMod::String PokeGen::PokeMod::Pokemod::GetSuperPCUname() const
diff --git a/pokemod/Pokemod.h b/pokemod/Pokemod.h index a1bbc096..fa0b3ea1 100644 --- a/pokemod/Pokemod.h +++ b/pokemod/Pokemod.h @@ -33,24 +33,26 @@ #include <string>
#include "pokemod_inc.h"
#include "Object.h"
+#include "Frac.h"
+#include "Ini.h"
+#include "Path.h"
+#include "Point.h"
#include "Ref.h"
+#include "String.h"
#include "Ability.h"
#include "Author.h"
#include "Badge.h"
#include "CoinList.h"
#include "Dialog.h"
#include "EggGroup.h"
-#include "Ini.h"
#include "Item.h"
#include "ItemStorage.h"
#include "Map.h"
#include "Move.h"
#include "Nature.h"
-#include "Point.h"
#include "Pokemon.h"
#include "Status.h"
#include "Store.h"
-#include "String.h"
#include "Tile.h"
#include "Time.h"
#include "Type.h"
@@ -62,12 +64,13 @@ namespace PokeGen class Pokemod : public Object
{
public:
- Pokemod();
- Pokemod(std::ifstream &fin);
+ Pokemod(const String &f);
~Pokemod();
- void ImportIni(std::ifstream &fin);
- void ExportIni(std::ofstream &fout) const;
+ void ImportIni(const String &f);
+ void ExportIni(const String &f) const;
+
+ Path GetPath() const;
unsigned MaxCompatability(const Pokemod &p) const;
@@ -116,12 +119,12 @@ namespace PokeGen void SetStartDirection(const unsigned s);
void SetStartDirection(const String &s);
void SetStartDialog(const unsigned s);
- void SetWalkSkin(const Path &w);
- void SetBikeSkin(const Path &b);
- void SetSurfSkin(const Path &s);
- void SetFlySkin(const Path &f);
- void SetFishSkin(const Path &f);
- void SetSurfFishSkin(const Path &s);
+ void SetWalkSkin(Path &w);
+ void SetBikeSkin(Path &b);
+ void SetSurfSkin(Path &s);
+ void SetFlySkin(Path &f);
+ void SetFishSkin(Path &f);
+ void SetSurfFishSkin(Path &s);
void SetSuperPCUname(const String &u);
void SetSuperPCPasswd(const String &p);
void SetStruggleMove(const unsigned s);
@@ -173,12 +176,12 @@ namespace PokeGen String GetStartDirectionString() const;
unsigned GetStartDialog() const;
String GetStartDialogString() const;
- Path GetWalkSkin() const;
- Path GetBikeSkin() const;
- Path GetSurfSkin() const;
- Path GetFlySkin() const;
- Path GetFishSkin() const;
- Path GetSurfFishSkin() const;
+ bool GetWalkSkin() const;
+ bool GetBikeSkin() const;
+ bool GetSurfSkin() const;
+ bool GetFlySkin() const;
+ bool GetFishSkin() const;
+ bool GetSurfFishSkin() const;
String GetSuperPCUname() const;
String GetSuperPCPasswd() const;
unsigned GetStruggleMove() const;
@@ -373,12 +376,6 @@ namespace PokeGen Point startCoordinate;
unsigned startDirection;
unsigned startDialog;
- Path walkSkin;
- Path bikeSkin;
- Path surfSkin;
- Path flySkin;
- Path fishSkin;
- Path surfFishSkin;
String superPCUname;
String superPCPasswd;
unsigned struggleMove;
@@ -403,6 +400,8 @@ namespace PokeGen std::vector<Tile> tiles;
std::vector<Time> times;
std::vector<Type> types;
+
+ String file;
};
}
}
diff --git a/pokemod/Pokemon.cpp b/pokemod/Pokemon.cpp index 31b7ccd3..b699e540 100644 --- a/pokemod/Pokemon.cpp +++ b/pokemod/Pokemon.cpp @@ -102,25 +102,25 @@ void PokeGen::PokeMod::Pokemon::Validate() LogVarNotValid("Pokemon", id, "frontMaleSprite", name);
isValid = false;
}
- if (!Path(pokemod->GetPath() + "images/pokemon/back/" + (pokemod->IsGenderAllowed() ? "male/" : "") + name + ".png").DoesExist()) + if (!Path(pokemod->GetPath() + "images/pokemon/back/" + (pokemod->IsGenderAllowed() ? "male/" : "") + name + ".png").DoesExist())
{
LogVarNotSet("Pokemon", id, "backMaleSprite", name);
isValid = false;
- } - if (pokemod->IsGenderAllowed()) - {
- if (!Path(pokemod->GetPath() + "images/pokemon/front/female/" + name + ".png").DoesExist()) - { - LogVarNotValid("Pokemon", id, "frontFemaleSprite", name); - isValid = false; - } - if (!Path(pokemod->GetPath() + "images/pokemon/back/female/" + name + ".png").DoesExist()) - { - LogVarNotSet("Pokemon", id, "backFemaleSprite", name); - isValid = false; - } - } - if (!Path(pokemod->GetPath() + "images/pokemon/list/" + name + ".png").DoesExist()) + }
+ if (pokemod->IsGenderAllowed())
+ {
+ if (!Path(pokemod->GetPath() + "images/pokemon/front/female/" + name + ".png").DoesExist())
+ {
+ LogVarNotValid("Pokemon", id, "frontFemaleSprite", name);
+ isValid = false;
+ }
+ if (!Path(pokemod->GetPath() + "images/pokemon/back/female/" + name + ".png").DoesExist())
+ {
+ LogVarNotSet("Pokemon", id, "backFemaleSprite", name);
+ isValid = false;
+ }
+ }
+ if (!Path(pokemod->GetPath() + "images/pokemon/list/" + name + ".png").DoesExist())
{
LogVarNotValid("Pokemon", id, "listSprite", name);
isValid = false;
@@ -361,36 +361,36 @@ void PokeGen::PokeMod::Pokemon::Validate(const wxListBox &output) output.Append(ConsoleLogVarNotValid("Pokemon", id, "heightInches", name));
isValid = false;
}
- if (!Path(pokemod->GetPath() + "images/pokemon/front/male/" + name + ".png").DoesExist()) + if (!Path(pokemod->GetPath() + "images/pokemon/front/male/" + name + ".png").DoesExist())
{
LogVarNotValid("Pokemon", id, "frontMaleSprite", name);
output.Append(ConsoleLogVarNotValid("Pokemon", id, "frontMaleSprite", name));
isValid = false;
}
- if (!Path(pokemod->GetPath() + "images/pokemon/back/male/" + name + ".png").DoesExist()) - { - LogVarNotValid("Pokemon", id, "backMaleSprite", name); - output.Append(ConsoleLogVarNotValid("Pokemon", id, "backMaleSprite", name)); - isValid = false; - } - if (!Path(pokemod->GetPath() + "images/pokemon/front/female/" + name + ".png").DoesExist()) - { - LogVarNotValid("Pokemon", id, "frontFemaleSprite", name); - output.Append(ConsoleLogVarNotValid("Pokemon", id, "frontFemaleSprite", name)); - isValid = false; - } - if (!Path(pokemod->GetPath() + "images/pokemon/back/female/" + name + ".png").DoesExist()) - { - LogVarNotValid("Pokemon", id, "backFemaleSprite", name); - output.Append(ConsoleLogVarNotValid("Pokemon", id, "backFemrontMaleSprite", name)); - isValid = false; - } - if (!Path(pokemod->GetPath() + "images/pokemon/list/" + name + ".png").DoesExist()) - { - LogVarNotValid("Pokemon", id, "listSprite", name); - output.Append(ConsoleLogVarNotValid("Pokemon", id, "listSprite", name)); - isValid = false; - } + if (!Path(pokemod->GetPath() + "images/pokemon/back/male/" + name + ".png").DoesExist())
+ {
+ LogVarNotValid("Pokemon", id, "backMaleSprite", name);
+ output.Append(ConsoleLogVarNotValid("Pokemon", id, "backMaleSprite", name));
+ isValid = false;
+ }
+ if (!Path(pokemod->GetPath() + "images/pokemon/front/female/" + name + ".png").DoesExist())
+ {
+ LogVarNotValid("Pokemon", id, "frontFemaleSprite", name);
+ output.Append(ConsoleLogVarNotValid("Pokemon", id, "frontFemaleSprite", name));
+ isValid = false;
+ }
+ if (!Path(pokemod->GetPath() + "images/pokemon/back/female/" + name + ".png").DoesExist())
+ {
+ LogVarNotValid("Pokemon", id, "backFemaleSprite", name);
+ output.Append(ConsoleLogVarNotValid("Pokemon", id, "backFemrontMaleSprite", name));
+ isValid = false;
+ }
+ if (!Path(pokemod->GetPath() + "images/pokemon/list/" + name + ".png").DoesExist())
+ {
+ LogVarNotValid("Pokemon", id, "listSprite", name);
+ output.Append(ConsoleLogVarNotValid("Pokemon", id, "listSprite", name));
+ isValid = false;
+ }
if (!pokemod->GetPokemon(eggSpecies))
{
LogVarNotValid("Pokemon", id, "eggSpecies", name);
@@ -835,40 +835,40 @@ void PokeGen::PokeMod::Pokemon::SetPokedexEntry(const String &p) pokedexEntry = p;
}
-void PokeGen::PokeMod::Pokemon::SetFrontMaleSprite(const Path &f)
+void PokeGen::PokeMod::Pokemon::SetFrontMaleSprite(Path &f)
{
LogSetVar("Pokemon", id, "frontMaleSprite", f, name);
f.CopyTo(pokemod->GetPath() + "pokemon/front/" + (pokemod->IsGenderAllowed() ? "male/" : "") + name + ".png");
}
-void PokeGen::PokeMod::Pokemon::SetBackMaleSprite(const Path &b)
+void PokeGen::PokeMod::Pokemon::SetBackMaleSprite(Path &b)
{
LogSetVar("Pokemon", id, "backMaleSprite", b, name);
- b.CopyTo(pokemod->GetPath() + "pokemon/back/" + (pokemod->IsGenderAllowed() ? "male/" : "") + name + ".png"); -}
-
-void PokeGen::PokeMod::Pokemon::SetFrontFemaleSprite(const Path &f) -{ - if (pokemod->IsGenderAllowed()) - { - LogSetVar("Pokemon", id, "frontFemaleSprite", f, name); - f.CopyTo(pokemod->GetPath() + "pokemon/front/female/" + name + ".png"); - } -} - -void PokeGen::PokeMod::Pokemon::SetBackFemaleSprite(const Path &b) -{ - if (pokemod->IsGenderAllowed()) - { - LogSetVar("Pokemon", id, "backFemaleSprite", b, name); - b.CopyTo(pokemod->GetPath() + "pokemon/back/female/" + name + ".png"); - } -} - -void PokeGen::PokeMod::Pokemon::SetListSprite(const Path &l)
+ b.CopyTo(pokemod->GetPath() + "pokemon/back/" + (pokemod->IsGenderAllowed() ? "male/" : "") + name + ".png");
+}
+
+void PokeGen::PokeMod::Pokemon::SetFrontFemaleSprite(Path &f)
+{
+ if (pokemod->IsGenderAllowed())
+ {
+ LogSetVar("Pokemon", id, "frontFemaleSprite", f, name);
+ f.CopyTo(pokemod->GetPath() + "pokemon/front/female/" + name + ".png");
+ }
+}
+
+void PokeGen::PokeMod::Pokemon::SetBackFemaleSprite(Path &b)
+{
+ if (pokemod->IsGenderAllowed())
+ {
+ LogSetVar("Pokemon", id, "backFemaleSprite", b, name);
+ b.CopyTo(pokemod->GetPath() + "pokemon/back/female/" + name + ".png");
+ }
+}
+
+void PokeGen::PokeMod::Pokemon::SetListSprite(Path &l)
{
LogSetVar("Pokemon", id, "listSprite", l, name);
- l.CopyTo(pokemod->GetPath() + "pokemon/list/" + name + ".png"); + l.CopyTo(pokemod->GetPath() + "pokemon/list/" + name + ".png");
}
void PokeGen::PokeMod::Pokemon::SetGenderFactor(const Frac &g)
@@ -1044,37 +1044,39 @@ PokeGen::PokeMod::String PokeGen::PokeMod::Pokemon::GetPokedexEntry() const bool PokeGen::PokeMod::Pokemon::GetFrontMaleSprite() const
{
LogFetchVar("Pokemon", id, "frontMaleSprite", -1, name);
- return Path(pokemod->GetPath() + "pokemon/front/" + (pokemod->IsGenderAllowed() ? "male/" : "") + name + ".png").DoesExist(); + return Path(pokemod->GetPath() + "pokemon/front/" + (pokemod->IsGenderAllowed() ? "male/" : "") + name + ".png").DoesExist();
}
bool PokeGen::PokeMod::Pokemon::GetBackMaleSprite() const
{
- LogFetchVar("Pokemon", id, "backMaleSprite", -1, name); - return Path(pokemod->GetPath() + "pokemon/back/" + (pokemod->IsGenderAllowed() ? "male/" : "") + name + ".png").DoesExist(); -}
-
-bool PokeGen::PokeMod::Pokemon::GetFrontFemaleSprite() const -{ - if (pokemod->IsGenderAllowed()) - { - LogFetchVar("Pokemon", id, "frontFemaleSprite", -1, name); - return Path(pokemod->GetPath() + "pokemon/front/female/" + name + ".png").DoesExist(); - } -} - -bool PokeGen::PokeMod::Pokemon::GetBackFemaleSprite() const -{ - if (pokemod->IsGenderAllowed()) - { - LogFetchVar("Pokemon", id, "backFemaleSprite", -1, name); - return Path(pokemod->GetPath() + "pokemon/back/female/" + name + ".png").DoesExist(); - } -} - + LogFetchVar("Pokemon", id, "backMaleSprite", -1, name);
+ return Path(pokemod->GetPath() + "pokemon/back/" + (pokemod->IsGenderAllowed() ? "male/" : "") + name + ".png").DoesExist();
+}
+
+bool PokeGen::PokeMod::Pokemon::GetFrontFemaleSprite() const
+{
+ if (pokemod->IsGenderAllowed())
+ {
+ LogFetchVar("Pokemon", id, "frontFemaleSprite", -1, name);
+ return Path(pokemod->GetPath() + "pokemon/front/female/" + name + ".png").DoesExist();
+ }
+ return false;
+}
+
+bool PokeGen::PokeMod::Pokemon::GetBackFemaleSprite() const
+{
+ if (pokemod->IsGenderAllowed())
+ {
+ LogFetchVar("Pokemon", id, "backFemaleSprite", -1, name);
+ return Path(pokemod->GetPath() + "pokemon/back/female/" + name + ".png").DoesExist();
+ }
+ return false;
+}
+
bool PokeGen::PokeMod::Pokemon::GetListSprite() const
{
- LogFetchVar("Pokemon", id, "listSprite", -1, name); - return Path(pokemod->GetPath() + "pokemon/list/" + name + ".png").DoesExist(); + LogFetchVar("Pokemon", id, "listSprite", -1, name);
+ return Path(pokemod->GetPath() + "pokemon/list/" + name + ".png").DoesExist();
}
PokeGen::PokeMod::Frac PokeGen::PokeMod::Pokemon::GetGenderFactor() const
diff --git a/pokemod/Pokemon.h b/pokemod/Pokemon.h index baf545f1..d0544d77 100644 --- a/pokemod/Pokemon.h +++ b/pokemod/Pokemon.h @@ -71,11 +71,11 @@ namespace PokeGen void SetHeightFeet(const unsigned f);
void SetHeightInches(const unsigned char i);
void SetPokedexEntry(const String &p);
- void SetFrontMaleSprite(const Path &f);
- void SetBackMaleSprite(const Path &b);
- void SetFrontFemaleSprite(const Path &f); - void SetBackFemaleSprite(const Path &b); - void SetListSprite(const Path &l);
+ void SetFrontMaleSprite(Path &f);
+ void SetBackMaleSprite(Path &b);
+ void SetFrontFemaleSprite(Path &f);
+ void SetBackFemaleSprite(Path &b);
+ void SetListSprite(Path &l);
void SetGenderFactor(const Frac &g);
void SetGenderFactor(const unsigned n, const unsigned d);
void SetGenderFactorNumerator(const unsigned n);
@@ -106,8 +106,8 @@ namespace PokeGen String GetPokedexEntry() const;
bool GetFrontMaleSprite() const;
bool GetBackMaleSprite() const;
- bool GetFrontFemaleSprite() const; - bool GetBackFemaleSprite() const; + bool GetFrontFemaleSprite() const;
+ bool GetBackFemaleSprite() const;
bool GetListSprite() const;
Frac GetGenderFactor() const;
unsigned GetGenderFactorNumerator() const;
diff --git a/pokemod/Ref.h b/pokemod/Ref.h index 6ad80cc2..0b39c919 100644 --- a/pokemod/Ref.h +++ b/pokemod/Ref.h @@ -243,12 +243,12 @@ namespace PokeGen enum EnumFlagValue
{
- FV_SET = 0,
- FV_UNSET = 1,
+ FV_UNSET = 0,
+ FV_SET = 1,
FV_IGNORE = 2,
FV_END = 3
};
- const char *FlagValueStr[FV_END] = {"Set", "Unset", "Ignore"};
+ const char *FlagValueStr[FV_END] = {"Unset", "Set", "Ignore"};
enum EnumCoinItemType
@@ -456,7 +456,7 @@ namespace PokeGen };
const char *WarpTypeStr[WT_END] = {"Door/Stair", "Warp Pad", "Hole", "Boundary"};
- enum EnumDialogCommands
+ enum EnumDialogCommand
{
DC_FLIP_FLAG = 0,
DC_SET_FLAG = 1,
diff --git a/pokemod/StatusEffect.h b/pokemod/StatusEffect.h index 683b37eb..ec38e4d1 100644 --- a/pokemod/StatusEffect.h +++ b/pokemod/StatusEffect.h @@ -27,7 +27,6 @@ #include "Object.h"
#include "String.h"
#include "Pokemod.h"
-#include "Status.h"
#include "Ref.h"
namespace PokeGen
diff --git a/pokemod/String.cpp b/pokemod/String.cpp index 0d8b8367..61bc7e37 100644 --- a/pokemod/String.cpp +++ b/pokemod/String.cpp @@ -37,7 +37,7 @@ PokeGen::PokeMod::String::String(const char *fmt, ...) va_end(args);
}
-void PokeGen::PokeMod::String::printf(const char *fmt, ...)
+void PokeGen::PokeMod::String::Printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
@@ -45,7 +45,7 @@ void PokeGen::PokeMod::String::printf(const char *fmt, ...) va_end(args);
}
-void PokeGen::PokeMod::String::printf(const char *fmt, va_list &args)
+void PokeGen::PokeMod::String::Printf(const char *fmt, va_list &args)
{
Format unit;
std::stringstream ss;
@@ -130,7 +130,116 @@ void PokeGen::PokeMod::String::printf(const char *fmt, va_list &args) append(1, *p);
++p;
}
+} + +unsigned PokeGen::PokeMod::String::Count(const char c) const +{ + unsigned count = 0; + for (unsigned i = 0; i < length(); ++i) + count += (*this[i] == c); + return count; +} + +unsigned PokeGen::PokeMod::String::Count(const String &s, bool canOverlap) const +{ + unsigned count = 0; + for (unsigned i = 0; i + s.length() < length(); ++i) + { + if (this->substr(i, i + s.length() - 1) == s) + { + ++count; + if (!canOverlap) + i += s.length() - 1; + } + } + return count; }
+ +bool PokeGen::PokeMod::String::Convert(bool &val) const +{ + if (*this == "true") + val = true; + else if (*this == "false") + val = false; + else + return false; + return true; +} + +bool PokeGen::PokeMod::String::Convert(char &val) const +{ + long temp; + char *end; + temp = std::strtol(c_str(), &end, 10); + if ((CHAR_MIN <= temp) && (temp <= CHAR_MAX) && !*end) + val = temp; + else + return false; + return true; +} + +bool PokeGen::PokeMod::String::Convert(unsigned char &val) const +{ + unsigned long temp; + char *end; + temp = std::strtoul(c_str(), &end, 10); + if ((temp <= UCHAR_MAX) && !*end) + val = temp; + else + return false; + return true; +} + +bool PokeGen::PokeMod::String::Convert(int &val) const +{ + long temp; + char *end; + temp = std::strtol(c_str(), &end, 10); + if ((INT_MIN <= temp) && (temp <= INT_MAX) && !*end) + val = temp; + else + return false; + return true; +} + +bool PokeGen::PokeMod::String::Convert(unsigned &val) const +{ + unsigned long temp; + char *end; + temp = std::strtoul(c_str(), &end, 10); + if ((temp <= UINT_MAX) && !*end) + val = temp; + else + return false; + return true; +} + +bool PokeGen::PokeMod::String::Convert(long &val) const +{ + long temp; + char *end; + temp = std::strtol(c_str(), &end, 10); + if (!*end) + val = temp; + return !*end; +} + +bool PokeGen::PokeMod::String::Convert(unsigned long &val) const +{ + unsigned long temp; + char *end; + temp = std::strtoul(c_str(), &end, 10); + if (!*end) + val = temp; + return !*end; +} + +bool PokeGen::PokeMod::String::Convert(double &val) const +{ + char *end; + val = std::strtod(c_str(), &end); + return !*end; +} PokeGen::PokeMod::String::operator const char *() const
{
diff --git a/pokemod/String.h b/pokemod/String.h index 2058ed4b..a2e84301 100644 --- a/pokemod/String.h +++ b/pokemod/String.h @@ -39,9 +39,21 @@ namespace PokeGen public:
String(const std::string &str);
String(const char *fmt = "", ...);
-
- void printf(const char *fmt, ...);
-
+
+ void Printf(const char *fmt, ...); + + unsigned Count(const char c) const; + unsigned Count(const String &s, bool canOverlap = false) const; + + bool Convert(bool &val) const; + bool Convert(char &val) const; + bool Convert(unsigned char &val) const; + bool Convert(int &val) const; + bool Convert(unsigned &val) const; + bool Convert(long &val) const; + bool Convert(unsigned long &val) const; + bool Convert(double &val) const; +
operator const char *() const;
private:
typedef union
@@ -55,8 +67,8 @@ namespace PokeGen long l;
unsigned long ul;
}Format;
-
- void printf(const char *fmt, va_list &args);
+
+ void Printf(const char *fmt, va_list &args);
};
}
}
diff --git a/pokemod/TODO b/pokemod/TODO index 5cdf7c56..83de910a 100644 --- a/pokemod/TODO +++ b/pokemod/TODO @@ -16,10 +16,10 @@ Effect Switches ItemEffect
MoveEffect
----------------
-Enum <-> String
----------------
-Class Template-ize (???)
+----
+Enum
+----
+Class Template-ize (for implicit char * <-> enum <-> int conversions) (???)
=================
Showstopper
@@ -28,16 +28,11 @@ Showstopper ----------
Validation
----------
-StatusEffect
+StatusEffect Dialog
ItemEffect
MoveEffect
--------------
-Miscellaneous
--------------
-Dialog commands
-
=================
Important
=================
diff --git a/pokemod/pokemod_inc.h b/pokemod/pokemod_inc.h index ebcd4348..aae1032a 100644 --- a/pokemod/pokemod_inc.h +++ b/pokemod/pokemod_inc.h @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////
// Name: pokemod/pokemod_inc.h
-// Purpose: Include header for a PokéMod
+// Purpose: Include header for the PokéMod library
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Thu Mar 22 20:53:22 2007
|
