diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-05-11 01:33:42 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-05-11 01:33:42 +0000 |
| commit | fafbdab97afb5ec6498ea0ab66b693b9e335f6f1 (patch) | |
| tree | 2f8ad1e735f3b15b123ea2353fedec8affd22790 | |
| parent | 0d2d8121cbb6a45180d88021fe2e5ac86b3532e3 (diff) | |
Starting INI migration
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@9 6ecfd1a5-f3ed-3746-8530-beee90d26b22
| -rw-r--r-- | Changelog | 10 | ||||
| -rw-r--r-- | pokegen.depend | 19 | ||||
| -rw-r--r-- | pokegen.layout | 90 | ||||
| -rw-r--r-- | pokemod/Ability.cpp | 44 | ||||
| -rw-r--r-- | pokemod/Ability.h | 8 | ||||
| -rw-r--r-- | pokemod/Author.cpp | 42 | ||||
| -rw-r--r-- | pokemod/Author.h | 6 | ||||
| -rw-r--r-- | pokemod/Badge.cpp | 132 | ||||
| -rw-r--r-- | pokemod/Badge.h | 6 | ||||
| -rw-r--r-- | pokemod/Debug.h | 46 | ||||
| -rw-r--r-- | pokemod/Flag.cpp | 30 | ||||
| -rw-r--r-- | pokemod/Flag.h | 11 | ||||
| -rw-r--r-- | pokemod/Frac.cpp | 35 | ||||
| -rw-r--r-- | pokemod/Frac.h | 6 | ||||
| -rw-r--r-- | pokemod/Ini.cpp | 36 | ||||
| -rw-r--r-- | pokemod/Ini.h | 7 | ||||
| -rw-r--r-- | pokemod/Matrix.cpp | 171 | ||||
| -rw-r--r-- | pokemod/Matrix.h | 39 | ||||
| -rw-r--r-- | pokemod/Nature.cpp | 43 | ||||
| -rw-r--r-- | pokemod/Nature.h | 8 | ||||
| -rw-r--r-- | pokemod/Object.h | 4 | ||||
| -rw-r--r-- | pokemod/Path.cpp | 2 | ||||
| -rw-r--r-- | pokemod/Path.h | 2 | ||||
| -rw-r--r-- | pokemod/Point.cpp | 13 | ||||
| -rw-r--r-- | pokemod/Point.h | 2 |
25 files changed, 371 insertions, 441 deletions
@@ -1,6 +1,14 @@ -----------------
+Rev: 9
+Date: 10 May 2007
+User: MathStuf
+-----------------
+[FIX] Migration to INI format started
+[FIX] Rev. 8 date
+
+-----------------
Rev: 8
-Date: 4 May 2007
+Date: 5 May 2007
User: MathStuf
-----------------
[ADD] STANDARDS file
diff --git a/pokegen.depend b/pokegen.depend deleted file mode 100644 index 7d1bf52e..00000000 --- a/pokegen.depend +++ /dev/null @@ -1,19 +0,0 @@ -# depslib dependency file v1.0
-1178323226 source:h:\ben\programming\pc\pokegen\src\ai\net.cpp
- "Net.h"
-
-1178324449 h:\ben\programming\pc\pokegen\src\ai\net.h
- "Layer.h"
-
-1178324610 h:\ben\programming\pc\pokegen\src\ai\layer.h
- <vector>
- <cstdlib>
- "Node.h"
-
-1178324663 h:\ben\programming\pc\pokegen\src\ai\node.h
- <string>
- <vector>
- <cstdlib>
- <cmath>
- "Layer.h"
-
diff --git a/pokegen.layout b/pokegen.layout index 24e09e80..9447677a 100644 --- a/pokegen.layout +++ b/pokegen.layout @@ -2,7 +2,7 @@ <CodeBlocks_layout_file> <ActiveTarget name="pokemodr" /> <File name="Changelog" open="1" top="0" tabpos="1"> - <Cursor position="485" topLine="0" /> + <Cursor position="473" topLine="0" /> </File> <File name="STANDARDS" open="0" top="0" tabpos="0"> <Cursor position="2" topLine="0" /> @@ -14,7 +14,7 @@ <Cursor position="1287" topLine="0" /> </File> <File name="ai\Net.cpp" open="0" top="0" tabpos="0"> - <Cursor position="1801" topLine="17" /> + <Cursor position="1949" topLine="17" /> </File> <File name="ai\Net.h" open="0" top="0" tabpos="0"> <Cursor position="1255" topLine="0" /> @@ -25,77 +25,77 @@ <File name="ai\Node.h" open="0" top="0" tabpos="0"> <Cursor position="1408" topLine="0" /> </File> - <File name="pokemod\Ability.cpp" open="1" top="0" tabpos="2"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Ability.cpp" open="0" top="0" tabpos="2"> + <Cursor position="335" topLine="105" /> </File> - <File name="pokemod\Ability.h" open="1" top="0" tabpos="3"> - <Cursor position="2147" topLine="8" /> + <File name="pokemod\Ability.h" open="1" top="0" tabpos="2"> + <Cursor position="1372" topLine="14" /> </File> - <File name="pokemod\Author.cpp" open="1" top="0" tabpos="4"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Author.cpp" open="0" top="0" tabpos="4"> + <Cursor position="3801" topLine="111" /> </File> - <File name="pokemod\Author.h" open="1" top="0" tabpos="5"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Author.h" open="0" top="0" tabpos="5"> + <Cursor position="1622" topLine="15" /> </File> <File name="pokemod\Badge.cpp" open="1" top="0" tabpos="6"> - <Cursor position="103" topLine="0" /> + <Cursor position="6614" topLine="211" /> </File> <File name="pokemod\Badge.h" open="1" top="0" tabpos="7"> - <Cursor position="103" topLine="0" /> + <Cursor position="1402" topLine="15" /> </File> <File name="pokemod\Debug.cpp" open="0" top="0" tabpos="0"> - <Cursor position="103" topLine="0" /> + <Cursor position="1583" topLine="9" /> </File> - <File name="pokemod\Debug.h" open="0" top="0" tabpos="0"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Debug.h" open="1" top="0" tabpos="8"> + <Cursor position="7621" topLine="164" /> </File> - <File name="pokemod\Flag.cpp" open="1" top="0" tabpos="8"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Flag.cpp" open="0" top="0" tabpos="8"> + <Cursor position="2576" topLine="53" /> </File> - <File name="pokemod\Flag.h" open="1" top="0" tabpos="9"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Flag.h" open="0" top="0" tabpos="9"> + <Cursor position="1259" topLine="3" /> </File> - <File name="pokemod\Frac.cpp" open="1" top="0" tabpos="10"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Frac.cpp" open="0" top="0" tabpos="10"> + <Cursor position="2291" topLine="58" /> </File> - <File name="pokemod\Frac.h" open="1" top="0" tabpos="11"> - <Cursor position="1243" topLine="10" /> + <File name="pokemod\Frac.h" open="0" top="0" tabpos="11"> + <Cursor position="2000" topLine="31" /> </File> - <File name="pokemod\Ini.cpp" open="0" top="0" tabpos="3"> - <Cursor position="3208" topLine="122" /> + <File name="pokemod\Ini.cpp" open="1" top="0" tabpos="3"> + <Cursor position="3866" topLine="136" /> </File> - <File name="pokemod\Ini.h" open="1" top="0" tabpos="12"> - <Cursor position="1577" topLine="11" /> + <File name="pokemod\Ini.h" open="0" top="0" tabpos="12"> + <Cursor position="2169" topLine="32" /> </File> - <File name="pokemod\Matrix.cpp" open="1" top="0" tabpos="13"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Matrix.cpp" open="0" top="0" tabpos="5"> + <Cursor position="4826" topLine="120" /> </File> - <File name="pokemod\Matrix.h" open="1" top="0" tabpos="14"> - <Cursor position="2162" topLine="15" /> + <File name="pokemod\Matrix.h" open="0" top="0" tabpos="4"> + <Cursor position="2015" topLine="46" /> </File> - <File name="pokemod\Nature.cpp" open="1" top="0" tabpos="15"> - <Cursor position="49" topLine="0" /> + <File name="pokemod\Nature.cpp" open="1" top="0" tabpos="5"> + <Cursor position="3336" topLine="99" /> </File> - <File name="pokemod\Nature.h" open="1" top="0" tabpos="16"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Nature.h" open="1" top="1" tabpos="4"> + <Cursor position="1332" topLine="22" /> </File> <File name="pokemod\Object.cpp" open="0" top="0" tabpos="0"> - <Cursor position="103" topLine="11" /> + <Cursor position="1290" topLine="10" /> </File> <File name="pokemod\Object.h" open="0" top="0" tabpos="0"> - <Cursor position="1556" topLine="24" /> + <Cursor position="1239" topLine="25" /> </File> - <File name="pokemod\Path.cpp" open="1" top="0" tabpos="17"> - <Cursor position="42" topLine="0" /> + <File name="pokemod\Path.cpp" open="0" top="0" tabpos="17"> + <Cursor position="2673" topLine="57" /> </File> - <File name="pokemod\Path.h" open="1" top="0" tabpos="18"> - <Cursor position="103" topLine="0" /> + <File name="pokemod\Path.h" open="0" top="0" tabpos="18"> + <Cursor position="1747" topLine="18" /> </File> - <File name="pokemod\Point.cpp" open="1" top="1" tabpos="19"> - <Cursor position="1556" topLine="13" /> + <File name="pokemod\Point.cpp" open="0" top="0" tabpos="19"> + <Cursor position="1463" topLine="10" /> </File> - <File name="pokemod\Point.h" open="1" top="0" tabpos="20"> - <Cursor position="1575" topLine="26" /> + <File name="pokemod\Point.h" open="0" top="0" tabpos="20"> + <Cursor position="1549" topLine="38" /> </File> <File name="pokemod\Ref.cpp" open="0" top="0" tabpos="0"> <Cursor position="103" topLine="0" /> diff --git a/pokemod/Ability.cpp b/pokemod/Ability.cpp index 3c88b39a..6f2ddadc 100644 --- a/pokemod/Ability.cpp +++ b/pokemod/Ability.cpp @@ -32,17 +32,17 @@ PokeGen::PokeMod::Ability::Ability(unsigned _id) id = _id;
}
-PokeGen::PokeMod::Ability::Ability(XmlElement &xml, unsigned _id)
+PokeGen::PokeMod::Ability::Ability(Ini &ini, unsigned _id)
{
- LogCtorXml("Ability", id);
- ImportXml(xml, _id);
+ LogCtorIni("Ability", id);
+ ImportIni(ini, _id);
if (id == UINT_MAX)
LogIdError("Ability");
}
PokeGen::PokeMod::Ability::~Ability()
{
- LogDtor("Ability", id, name));
+ LogDtor("Ability", id, name);
}
void PokeGen::PokeMod::Ability::Validate()
@@ -109,45 +109,33 @@ void PokeGen::PokeMod::Ability::Validate(wxListBox &output) }
#endif
-void PokeGen::PokeMod::Ability::ImportXml(XmlElement &xml, unsigned _id)
+void PokeGen::PokeMod::Ability::ImportIni(Ini &ini, unsigned _id)
{
LogImportStart("Ability");
- String curName;
if (_id == UINT_MAX)
{
- xml.GetValue(id);
+ ini.GetValue("id", id, UINT_MAX);
// Was there an id associated with the element?
if (id == UINT_MAX)
LogIdNotFound("Ability");
}
else
id = _id;
- name = "";
- effects.clear();
- xml.ClearCounter();
- for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
- {
- curName = child->GetName();
- if (curName == "name")
- child->GetValue(name);
- else if (curName == "effect")
- effects.push_back(AbilityEffect(*child));
- else
- LogUnknownXml("Ability", curName);
- }
+ ini.GetValue("name", name, "");
LogImportOver("Ability", id, name);
}
-XmlElement PokeGen::PokeMod::Ability::ExportXml()
+void PokeGen::PokeMod::Ability::ExportIni(std::ofstream &fout)
{
LogExportStart("Ability", id, name);
// Make elements
- XmlElement exAbility("ability");
- exAbility.AddElement("name", name);
+ Ini exAbility("ability");
+ exAbility.AddField("id", id);
+ exAbility.AddField("name", name);
+ exAbility.Export(fout);
for (std::vector<AbilityEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
- exAbility.AddElement(i->ExportXml());
+ i->ExportIni(fout, name);
LogExportOver("Ability", id, name);
- return exAbility;
}
void PokeGen::PokeMod::Ability::SetName(const String &n)
@@ -180,7 +168,7 @@ unsigned PokeGen::PokeMod::Ability::GetAbilityEffectCount() return effects.size();
}
-void PokeGen::PokeMod::Ability::NewAbilityEffect(XmlElement *xml)
+void PokeGen::PokeMod::Ability::NewAbilityEffect(Ini *ini)
{
unsigned i = 0;
// Find the first unused ID in the vector
@@ -190,8 +178,8 @@ void PokeGen::PokeMod::Ability::NewAbilityEffect(XmlElement *xml) break;
}
AbilityEffect newAbilityEffect(i);
- if (xml)
- newAbilityEffect.ImportXml(*xml);
+ if (ini)
+ newAbilityEffect.ImportXml(*ini);
LogSubmoduleNew("Ability", "effect", i, id, name);
effects.push_back(newAbilityEffect);
}
diff --git a/pokemod/Ability.h b/pokemod/Ability.h index aec3bee1..6f4e43c9 100644 --- a/pokemod/Ability.h +++ b/pokemod/Ability.h @@ -39,11 +39,11 @@ namespace PokeGen {
public:
Ability(unsigned _id);
- Ability(XmlElement &xml, unsigned _id = UINT_MAX);
+ Ability(Ini &ini, unsigned _id = UINT_MAX);
~Ability();
- void ImportXml(XmlElement &xml, unsigned _id = UINT_MAX);
- XmlElement ExportXml();
+ void ImportIni(Ini &ini, unsigned _id = UINT_MAX);
+ void ExportIni(std::ofstream &fout);
void SetName(const String &n);
@@ -51,7 +51,7 @@ namespace PokeGen AbilityEffect *GetAbilityEffect(unsigned _id);
unsigned GetAbilityEffectCount();
- void NewAbilityEffect(XmlElement *xml = NULL);
+ void NewAbilityEffect(Ini *ini = NULL);
void DeleteAbilityEffect(unsigned _id);
private:
void Validate();
diff --git a/pokemod/Author.cpp b/pokemod/Author.cpp index cd033ccf..c67f25bb 100644 --- a/pokemod/Author.cpp +++ b/pokemod/Author.cpp @@ -32,10 +32,10 @@ PokeGen::PokeMod::Author::Author(unsigned _id) id = _id;
}
-PokeGen::PokeMod::Author::Author(XmlElement &xml, unsigned _id)
+PokeGen::PokeMod::Author::Author(Ini &ini, unsigned _id)
{
- LogCtorXml("Author", id);
- ImportXml(xml, _id);
+ LogCtorIni("Author", id);
+ ImportIni(ini, _id);
// Big problems
if (id == UINT_MAX)
LogIdError("Author");
@@ -104,47 +104,35 @@ void PokeGen::PokeMod::Author::Validate(wxListBox &output) }
#endif
-void PokeGen::PokeMod::Author::ImportXml(XmlElement &xml, unsigned _id)
+void PokeGen::PokeMod::Author::ImportIni(Ini &ini, unsigned _id)
{
LogImportStart("Author");
String curName;
if (_id == UINT_MAX)
{
- xml.GetValue(id);
+ ini.GetValue("id", id, UINT_MAX);
if (id == UINT_MAX)
LogIdNotFound("Author");
}
else
id = _id;
- name = "";
- email = "";
- role = "";
- xml.ClearCounter();
- for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
- {
- curName = child->GetName();
- if (curName == "name")
- child->GetValue(name);
- else if (curName == "email")
- child->GetValue(email);
- else if (curName == "role")
- child->GetValue(role);
- else
- LogUnknownXml("Author", curName);
- }
+ ini.GetValue("name", name, "");
+ ini.GetValue("email", email, "");
+ ini.GetValue("role", role, "");
LogImportOver("Author", id, name);
}
-PokeGen::PokeMod::XmlElement PokeGen::PokeMod::Author::ExportXml()
+void PokeGen::PokeMod::Author::ExportIni(const std::ofstream &fout)
{
LogExportStart("Author", id, name);
// Declare the elements
- XmlElement exAuthor("author", id, true);
- exAuthor.AddElement("name", name);
- exAuthor.AddElement("email", email);
- exAuthor.AddElement("role", role);
+ Ini exAuthor("author");
+ exAuthor.AddField("id", id);
+ exAuthor.AddField("name", name);
+ exAuthor.AddField("email", email);
+ exAuthor.AddField("role", role);
+ exAuthor.Export(fout);
LogExportOver("Author", id, name);
- return exAuthor;
}
void PokeGen::PokeMod::Author::SetName(const String &n)
diff --git a/pokemod/Author.h b/pokemod/Author.h index cb35e0a8..dd9826ae 100644 --- a/pokemod/Author.h +++ b/pokemod/Author.h @@ -35,11 +35,11 @@ namespace PokeGen {
public:
Author(unsigned _id);
- Author(XmlElement &xml, unsigned _id = UINT_MAX);
+ Author(Ini &ini, unsigned _id = UINT_MAX);
~Author();
- void ImportXml(XmlElement &xml, unsigned _id = UINT_MAX);
- XmlElement ExportXml();
+ void ImportIni(Ini &ini, unsigned _id = UINT_MAX);
+ void ExportIni(const std::ofstream &fout);
void SetName(const String &n);
void SetEmail(const String &e);
diff --git a/pokemod/Badge.cpp b/pokemod/Badge.cpp index 257ca152..62a35274 100644 --- a/pokemod/Badge.cpp +++ b/pokemod/Badge.cpp @@ -40,10 +40,10 @@ PokeGen::PokeMod::Badge::Badge(unsigned _id) id = _id;
}
-PokeGen::PokeMod::Badge::Badge(XmlElement &xml, unsigned _id)
+PokeGen::PokeMod::Badge::Badge(Ini &ini, unsigned _id)
{
- LogCtorXml("Badge", _id);
- ImportXml(xml);
+ LogCtorIni("Badge", _id);
+ ImportIni(ini, _id);
if (id == UINT_MAX)
LogIdError("Badge");
}
@@ -78,7 +78,7 @@ void PokeGen::PokeMod::Badge::Validate() LogVarNotValid("Badge", "badge sprite", id, name);
isValid = false;
}
- LogValidationOver("Badge", isValid, is, name);
+ LogValidationOver("Badge", isValid, id, name);
}
#ifdef PG_DEBUG_WINDOW
@@ -124,112 +124,76 @@ void PokeGen::PokeMod::Badge::Validate(wxListBox &output) }
#endif
-void PokeGen::PokeMod::Badge::ImportXml(XmlElement &xml, unsigned _id)
+void PokeGen::PokeMod::Badge::ImportIni(Ini &ini, unsigned _id)
{
- LogImport("Badge");
- String curName;
+ LogImportStart("Badge");
if (_id == UINT_MAX)
{
- xml.GetValue(id);
+ ini.GetValue("id", id, UINT_MAX);
// Was there an id associated with the element?
if (id == UINT_MAX)
LogIdNotFound("Badge");
}
else
id = _id;
- name = "";
- face = "";
- badge = "";
- obey = 0;
- for (unsigned i = 0; i < STH_END_GSC; ++i)
- stats[i].Set(1, 1);
- for (unsigned i = 0; i < HM_END; ++i)
- hm[i] = false;
- xml.ClearCounter();
- for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ ini.GetValue("name", name, "");
+ ini.GetValue("face", face, "");
+ ini.GetValue("badge", badge, "");
+ ini.GetValue("obey", obey, 0);
+ for (int i = 0; i < STH_END_GSC; ++i)
{
- curName = child->Value();
- if (curName == "name")
- name = child->GetTextOrDefault("");
- else if (curName == "face")
- face = child->GetTextOrDefault("");
- else if (curName == "badge")
- badge = child->GetTextOrDefault("");
- else if (curName == "obey")
- child->GetTextOrDefault(&obey, 0);
- else if (curName == "stats")
- {
- for (ticpp::Element *subChild = child->FirstChildElement(); subChild; subChild = subChild->NextSiblingElement())
- {
- curName = subChild->Value();
- int i = FindIn(STH_END_GSC, curName, StatHPGSCStr);
- if (i < STH_END_GSC)
- stats[i].ImportXml(*subChild);
- else if (curName == "Special")
- stats[STH_SPECIAL].ImportXml(*subChild);
- else
- PMLog(PMString("Badge Import: Unknown Stat XML Element \"%s\"", curName.c_str()), PM_DEBUG_ERROR);
- }
- }
- else if (curName == "hms")
- {
- for (ticpp::Element *subChild = child->FirstChildElement(); subChild; subChild = subChild->NextSiblingElement())
- {
- curName = subChild->Value();
- int i = FindIn(PokeGen::PokeMod::HM_END, curName, HMStr);
- if (i < HM_END)
- subChild->GetTextOrDefault(&hm[i], false);
- else
- PMLog(PMString("Badge Import: Unknown HM XML Element \"%s\"", curName.c_str()), PM_DEBUG_ERROR);
- }
- }
- else
- PMLog(PMString("Badge Import: Unknown XML element \"%s\"", curName.c_str()), PM_DEBUG_ERROR);
+ unsigned j;
+ unsigned k;
+ ini.GetValue(String("stats-%d-n", i), j, 1);
+ ini.GetValue(String("stats-%d-d", i), k, 1);
+ stats[i].Set(j, k);
}
+ for (int i = 0; i < HM_END; ++i)
+ ini.GetValue(String("hm-%d", i), hm[i], false);
LogImportOver("Badge", id, name);
}
-PokeGen::PokeMod::XmlElement PokeGen::PokeMod::Badge::ExportXml()
+void PokeGen::PokeMod::Badge::ExportIni(std::ofstream &fout)
{
LogExportStart("Badge", id, name);
- XmlElement exBadge("badge", id, true);
- XmlElement exStats("stats", 0, true);
- XmlElement exHm("hm", 0, true);
- exBadge.AddElement("name", name);
- exBadge.AddElement("face", face);
- exBadge.AddElement("badge", badge);
- exBadge.AddElement("obey", obey);
- for (unsigned i = 0; i < (curPokeMod.IsSpecialSplit() ? STH_END_GSC : STH_END_RBY); ++i)
- exStats.AddElement(stats[i].ExportXml((curPokeMod.IsSpecialSplit() ? StatHPGSCStr : StatHPRBYStr)[i]));
- exBadge.AddElement(exStats);
- for (unsigned i = 0; i < HM_END; ++i)
- exHm.AddElement(HMStr[i], hm[i]);
- exBadge.AddElement(exHm);
+ Ini exBadge("badge");
+ exBadge.AddField("id", id);
+ exBadge.AddField("name", name);
+ exBadge.AddField("face", face);
+ exBadge.AddField("badge", badge);
+ exBadge.AddField("obey", obey);
+ for (int i = 0; i < STH_END_GSC; ++i)
+ {
+ exBadge.AddField(String("stats-%d-n", i), stats[i].GetNum());
+ exBadge.AddField(String("stats-%d-d", i), stats[i].GetDenom());
+ }
+ for (int i = 0; i < HM_END; ++i)
+ exBadge.AddField(String("hm-%d", i), hm[i]);
+ exBadge.Export(fout);
LogExportOver("Badge", id, name);
- return exBadge;
}
void PokeGen::PokeMod::Badge::SetName(const String &n)
{
- LogSetVar("Badge", "name", id, INT_MIN, n);
+ LogSetVar("Badge", "name", id, LONG_MAX, n);
name = n;
}
void PokeGen::PokeMod::Badge::SetFace(const Path &f)
{
- LogSetVar("Badge", "face", id, INT_MIN, f);
+ LogSetVar("Badge", "face", id, LONG_MAX, f);
face = f;
}
void PokeGen::PokeMod::Badge::SetBadge(const Path &b)
{
- LogSetVar("Badge", "badge", id, INT_MIN, b);
+ LogSetVar("Badge", "badge", id, LONG_MAX, b);
badge = b;
}
void PokeGen::PokeMod::Badge::SetObey(unsigned o)
{
- LogSetVar("Badge", "obey", id, INT_MIN, o);
+ LogSetVar("Badge", "obey", id, o);
obey = o;
}
@@ -241,46 +205,46 @@ void PokeGen::PokeMod::Badge::SetStat(unsigned s, unsigned n, unsigned d) void PokeGen::PokeMod::Badge::SetStatNum(unsigned s, unsigned n)
{
- LogSetVar("Badge", String("stat[%u] numerator", s), id, INT_MIN, n);
+ LogSetVar("Badge", String("stat[%u] numerator", s), id, n);
stats[s].SetNum(n);
}
void PokeGen::PokeMod::Badge::SetStatDenom(unsigned s, unsigned d)
{
- LogSetVar("Badge", String("stat[%u] denominator", s), id, INT_MIN, d);
+ LogSetVar("Badge", String("stat[%u] denominator", s), id, d);
stats[s].SetDenom(d);
}
void PokeGen::PokeMod::Badge::SetHm(unsigned h, bool hb)
{
- LogSetVar("Badge", String("hm[%u]", s), id, INT_MIN, hb);
+ LogSetVar("Badge", String("hm[%u]", h), id, hb);
if (HM_END <= h)
- PMLog(PMString("Badge: Index of hm out-of-bounds (%d)", h), PM_DEBUG_ERROR);
+ Log(String("Badge: Index of hm out-of-bounds (%d)", h), PM_DEBUG_ERROR);
else
hm[h] = hb;
}
PokeGen::PokeMod::String PokeGen::PokeMod::Badge::GetName()
{
- LogFetchVar("Badge", "name", id, INT_MIN, name);
+ LogFetchVar("Badge", "name", id, LONG_MAX, name);
return name;
}
PokeGen::PokeMod::Path PokeGen::PokeMod::Badge::GetFace()
{
- LogFetchVar("Badge", "face", id, INT_MIN, face);
+ LogFetchVar("Badge", "face", id, LONG_MAX, face);
return face;
}
PokeGen::PokeMod::Path PokeGen::PokeMod::Badge::GetBadge()
{
- LogFetchVar("Badge", "badge", id, INT_MIN, badge);
+ LogFetchVar("Badge", "badge", id, LONG_MAX, badge);
return badge;
}
unsigned PokeGen::PokeMod::Badge::GetObey()
{
- LogFetchVar("Badge", "obey", id, INT_MIN, obey);
+ LogFetchVar("Badge", "obey", id, obey);
return obey;
}
@@ -288,7 +252,7 @@ PokeGen::PokeMod::Frac PokeGen::PokeMod::Badge::GetStat(unsigned s) {
LogFetchVar("Badge", String("stats[%u]", s), id, INT_MIN, stats[s]);
if ((curPokeMod.IsSpecialSplit() ? STH_END_RBY : STH_END_GSC) <= s)
- PMLog(PMString("Badge: Index of stats out-of-bounds (%d)", s), PM_DEBUG_ERROR);
+ Log(String("Badge: Index of stats out-of-bounds (%d)", s), PM_DEBUG_ERROR);
return stats[s];
}
@@ -296,6 +260,6 @@ bool PokeGen::PokeMod::Badge::GetHm(unsigned h) {
LogFetchVar("Badge", String("hm[%u]", h), id, INT_MIN, hm[h]);
if (HM_END <= h)
- PMLog(PMString("Badge: Index of hm out-of-bounds (%d)", h), PM_DEBUG_ERROR);
+ Log(String("Badge: Index of hm out-of-bounds (%d)", h), PM_DEBUG_ERROR);
return hm[h];
}
diff --git a/pokemod/Badge.h b/pokemod/Badge.h index a20988df..2aba138e 100644 --- a/pokemod/Badge.h +++ b/pokemod/Badge.h @@ -40,11 +40,11 @@ namespace PokeGen {
public:
Badge(unsigned _id);
- Badge(XmlElement &xml, unsigned _id = UINT_MAX);
+ Badge(Ini &ini, unsigned _id = UINT_MAX);
~Badge();
- void ImportXml(XmlElement &xml);
- XmlElement ExportXml();
+ void ImportIni(Ini &ini, unsigned _id = UINT_MAX);
+ void ExportIni(std::ofstream &fout);
void SetName(const String &n);
void SetFace(const Path &f);
diff --git a/pokemod/Debug.h b/pokemod/Debug.h index edf8a285..cdb27588 100644 --- a/pokemod/Debug.h +++ b/pokemod/Debug.h @@ -73,9 +73,9 @@ namespace PokeGen Log(String("%s: Initializing %u", module, id), PM_DEBUG_DEBUG);
}
- inline void LogCtorXml(const char *module, unsigned id)
+ inline void LogCtorIni(const char *module, unsigned id)
{
- Log(String("%s: Initializing by XML (%u)", module, id), PM_DEBUG_DEBUG);
+ Log(String("%s: Initializing by INI (%u)", module, id), PM_DEBUG_DEBUG);
}
inline void LogIdError(const char *module)
@@ -147,7 +147,7 @@ namespace PokeGen }
// Importing
- inline void LogImport(const char *module)
+ inline void LogImportStart(const char *module)
{
Log(String("%s Import: Starting", module), PM_DEBUG_INFO);
}
@@ -157,14 +157,14 @@ namespace PokeGen Log(String("%s Import: id not found", module), PM_DEBUG_ALERT);
}
- inline void LogUnknownXml(const char *module, const char *element)
+ inline void LogImportOver(const char *module, unsigned id, const char *name = NULL)
{
- Log(String("%s Import: Unknown XML element (%s)", module, element), PM_DEBUG_NOTICE);
+ Log(String("%s Import: Imported %u%s", module, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_INFO);
}
- inline void LogImportOver(const char *module, unsigned id, const char *name = NULL)
+ inline void LogImportOver(const char *module)
{
- Log(String("%s Import: Imported %u%s", module, id, name ? String(" (%s)", name).c_str() : ""), PM_DEBUG_INFO);
+ Log(String("%s Import: Imported", module), PM_DEBUG_INFO);
}
// Exporting
@@ -179,14 +179,9 @@ namespace PokeGen }
// Setting Variable Values
- inline void LogSetVar(const char *module, const char *var, unsigned id, int valInt = INT_MIN, const char *valStr = NULL, const char *name = NULL)
+ inline void LogSetVar(const char *module, const char *var, unsigned id, long valInt = LONG_MAX, const char *valStr = NULL, const char *name = NULL)
{
- Log(String("%s: Setting %s of %u%s to %s", module, var, id, name ? String(" (%s)", name).c_str() : "", (valInt == INT_MIN) ? String("%d%s", valInt, valStr ? String(" (%s)", valStr).c_str() : "").c_str() : (valStr ? valStr : String("%d", valInt).c_str())), PM_DEBUG_DEBUG);
- }
-
- inline void LogSetVar(const char *module, const char *var, unsigned id, unsigned valInt = UINT_MAX, const char *valStr = NULL, const char *name = NULL)
- {
- Log(String("%s: Setting %s of %u%s to %s", module, var, id, name ? String(" (%s)", name).c_str() : "", (valInt == UINT_MAX) ? String("%u%s", valInt, valStr ? String(" (%s)", valStr).c_str() : "").c_str() : (valStr ? valStr : String("%u", valInt).c_str())), PM_DEBUG_DEBUG);
+ Log(String("%s: Setting %s of %u%s to %s", module, var, id, name ? String(" (%s)", name).c_str() : "", (valInt == LONG_MAX) ? (valStr ? valStr : String("%d", valInt).c_str()) : String("%d%s", valInt, valStr ? String(" (%s)", valStr).c_str() : "").c_str()), PM_DEBUG_DEBUG);
}
inline void LogSetVar(const char *module, const char *var, Frac &val, unsigned id, const char *name = NULL)
@@ -209,24 +204,14 @@ namespace PokeGen Log(String("%s: Attempting to set %s to %d of %u%s out-of-range (%s)", module, var, valInt, id, name ? String(" (%s)", name).c_str() : "", regVal), PM_DEBUG_DEBUG);
}
- inline void LogNotSet(const char *module, const char *var, const char *reg, unsigned id, int valInt = INT_MIN, const char *valStr = NULL, const char *name = NULL)
- {
- Log(String("%s: Attempting to set %s to %s of %u%s without %s being set", module, var, (valInt == INT_MIN) ? String("%d%s", valInt, valStr ? String(" (%s)", valStr).c_str() : "").c_str() : (valStr ? valStr : String("%d", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg), PM_DEBUG_ERROR);
- }
-
- inline void LogNotSet(const char *module, const char *var, const char *reg, unsigned id, unsigned valInt = UINT_MAX, const char *valStr = NULL, const char *name = NULL)
- {
- Log(String("%s: Attempting to set %s to %s of %u%s without %s being set", module, var, (valInt == UINT_MAX) ? String("%u%s", valInt, valStr ? String(" (%s)", valStr).c_str() : "").c_str() : (valStr ? valStr : String("%u", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg), PM_DEBUG_ERROR);
- }
-
- inline void LogNoUse(const char *module, const char *var, const char *reg, const char *regVal, unsigned id, int valInt = INT_MIN, const char *valStr = NULL, const char *name = NULL)
+ inline void LogNotSet(const char *module, const char *var, const char *reg, unsigned id, long valInt = LONG_MAX, const char *valStr = NULL, const char *name = NULL)
{
- Log(String("%s: Attempting to set %s to %s of %u%s without %s needing it (%s)", module, var, (valInt == INT_MIN) ? String("%d%s", valInt, valStr ? String(" (%s)", valStr).c_str() : "").c_str() : (valStr ? valStr : String("%d", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg, regVal), PM_DEBUG_ERROR);
+ Log(String("%s: Attempting to set %s to %s of %u%s without %s being set", module, var, (valInt == LONG_MAX) ? String("%d%s", valInt, valStr ? String(" (%s)", valStr).c_str() : "").c_str() : (valStr ? valStr : String("%d", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg), PM_DEBUG_ERROR);
}
- inline void LogNoUse(const char *module, const char *var, const char *reg, const char *regVal, unsigned id, unsigned valInt = UINT_MAX, const char *valStr = NULL, const char *name = NULL)
+ inline void LogNoUse(const char *module, const char *var, const char *reg, const char *regVal, unsigned id, long valInt = LONG_MAX, const char *valStr = NULL, const char *name = NULL)
{
- Log(String("%s: Attempting to set %s to %s of %u%s without %s needing it (%s)", module, var, (valInt == UINT_MAX) ? String("%u%s", valInt, valStr ? String(" (%s)", valStr).c_str() : "").c_str() : (valStr ? valStr : String("%u", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg, regVal), PM_DEBUG_ERROR);
+ Log(String("%s: Attempting to set %s to %s of %u%s without %s needing it (%s)", module, var, (valInt == LONG_MAX) ? String("%d%s", valInt, valStr ? String(" (%s)", valStr).c_str() : "").c_str() : (valStr ? valStr : String("%d", valInt).c_str()), id, name ? String(" (%s)", name).c_str() : "", reg, regVal), PM_DEBUG_ERROR);
}
// Fetching variable values
@@ -240,6 +225,11 @@ namespace PokeGen Log(String("%s: Fetching %s from %u%s (%s%s)", module, var, id, name ? String(" (%s)", name).c_str() : "", valStr, regVal ? String(", %s", regVal).c_str() : ""), PM_DEBUG_DEBUG);
}
+ inline void LogFetchVar(const char *module, const char *var, unsigned valInt)
+ {
+ Log(String("%s: Fetching %s (%u)", module, var, valInt), PM_DEBUG_DEBUG);
+ }
+
// Submodule logging
inline void LogSubmoduleFetch(const char *module, const char *subName, unsigned subId, unsigned id, const char *name = NULL)
{
diff --git a/pokemod/Flag.cpp b/pokemod/Flag.cpp index caf0e414..6c317770 100644 --- a/pokemod/Flag.cpp +++ b/pokemod/Flag.cpp @@ -30,33 +30,23 @@ PokeGen::PokeMod::Flag::Flag(unsigned f, int s) SetStatus(s);
}
-void PokeGen::PokeMod::Flag::ImportXml(XmlElement &xml)
+void PokeGen::PokeMod::Flag::ImportIni(Ini &ini)
{
LogImportStart("Flag");
- String curName;
- xml.ClearCounter();
- for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
- {
- curName = child->GetName();
- if (curName == "flag")
- child->GetValue(flag);
- else if (curName == "state")
- child->GetValue(status);
- else
- LogUnknownXml("Flag", curName);
- }
- LogImportOver("Flag", id, name);
+ ini.GetValue("flag", flag, 0);
+ ini.GetValue("status", status, 0);
+ LogImportOver("Flag");
}
-PokeGen::PokeMod::XmlElement PokeGen::PokeMod::Flag::ExportXml(const String &val)
+void PokeGen::PokeMod::Flag::ExportIni(std::ofstream &fout, const String &val)
{
Log(String("Flag Export: Starting %s", val.c_str()), PM_DEBUG_INFO);
// Declare the elements
- XmlElement exFlag(val, 0, true);
- exFlag.AddElement("flag", flag);
- exFlag.AddElement("state", status);
+ Ini exFlag(val);
+ exFlag.AddField("flag", flag);
+ exFlag.AddField("status", status);
+ exFlag.Export(fout);
Log(String("Flag Export: Finished %s", val.c_str()), PM_DEBUG_INFO);
- return exFlag;
}
void PokeGen::PokeMod::Flag::SetFlag(unsigned f)
@@ -84,7 +74,7 @@ unsigned PokeGen::PokeMod::Flag::GetFlag() return flag;
}
-FlagValue PokeGen::PokeMod::Flag::GetStatus()
+int PokeGen::PokeMod::Flag::GetStatus()
{
Log(String("Flag: Fetching the status (%d, %s)", status, FlagValueStr[status]), PM_DEBUG_DEBUG);
return status;
diff --git a/pokemod/Flag.h b/pokemod/Flag.h index e527f38c..6bbd9c77 100644 --- a/pokemod/Flag.h +++ b/pokemod/Flag.h @@ -25,7 +25,8 @@ #define __POKEMOD_FLAG__
#include "Debug.h"
-#include "Xml.h"
+#include "Ini.h"
+#include "Ref.h"
namespace PokeGen
{
@@ -35,19 +36,19 @@ namespace PokeGen {
public:
Flag(unsigned f, int s);
- void ImportXml(XmlElement &xml);
- XmlElement ExportXml(const String &val);
+ void ImportIni(Ini &ini);
+ void ExportIni(std::ofstream &fout, const String &val);
void SetFlag(unsigned f);
void SetStatus(int s);
void SetStatus(const String &s);
unsigned GetFlag();
- FlagValue GetStatus();
+ int GetStatus();
String GetStatusString();
private:
unsigned flag;
- FlagValue status;
+ int status;
};
}
}
diff --git a/pokemod/Frac.cpp b/pokemod/Frac.cpp index 3fc651eb..3262c67a 100644 --- a/pokemod/Frac.cpp +++ b/pokemod/Frac.cpp @@ -37,42 +37,27 @@ PokeGen::PokeMod::Frac::Frac(unsigned n, unsigned d, bool i) Set(n, d, i);
}
-void PokeGen::PokeMod::Frac::ImportXml(XmlElement &xml)
+void PokeGen::PokeMod::Frac::ImportIni(Ini &ini)
{
LogImportStart("Frac");
- String curName;
- num = 1;
- denom = 1;
- improper = false;
- Reduce();
- xml.ClearCounter();
- for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
- {
- curName = child->GetName();
- if (curName == "num")
- child->GetValue(num, 1);
- else if (curName == "denom")
- child->GetValue(denom, 1);
- else if (curName == "improper")
- child->GetValue(improper, false);
- else
- LogUnknownXml("Frac", curName);
- }
+ ini.GetValue("improper", improper, false);
+ ini.GetValue("num", num, 1);
+ ini.GetValue("denom", denom, 1);
Log(String("Frac Import: Imported %u/%u", num, denom), PM_DEBUG_INFO);
}
-PokeGen::PokeMod::XmlElement PokeGen::PokeMod::Frac::ExportXml(const String &val)
+void PokeGen::PokeMod::Frac::ExportIni(const std::ofstream &fout, const String &val)
{
Log(String("Frac Export: Starting %u/%u as %s", num, denom, val.c_str()), PM_DEBUG_INFO);
// Reduce fraction before storing
Reduce();
// Declare the elements
- XmlElement exFrac(val, 0, true);
- exFrac.AddElement("num", num);
- exFrac.AddElement("denom", denom);
- exFrac.AddElement("improper", improper);
+ Ini exFrac(val);
+ exFrac.AddField("num", num);
+ exFrac.AddField("denom", denom);
+ exFrac.AddField("improper", improper);
+ exFrac.Export(fout);
Log(String("Frac Export: Finished %u/%u as %s", num, denom, val.c_str()), PM_DEBUG_INFO);
- return exFrac;
}
void PokeGen::PokeMod::Frac::Set(unsigned n, unsigned d)
diff --git a/pokemod/Frac.h b/pokemod/Frac.h index a7f903c3..31797c8e 100644 --- a/pokemod/Frac.h +++ b/pokemod/Frac.h @@ -25,7 +25,7 @@ #define __POKEMOD_FRAC__
#include "Debug.h"
-#include "Xml.h"
+#include "Ini.h"
namespace PokeGen
{
@@ -37,8 +37,8 @@ namespace PokeGen Frac(bool i = false);
Frac(unsigned n, unsigned d, bool i = false);
- void ImportXml(XmlElement &xml);
- XmlElement ExportXml(const String &val);
+ void ImportIni(Ini &ini);
+ void ExportIni(const std::ofstream &fout, const String &val);
void Set(unsigned n, unsigned d);
void Set(unsigned n, unsigned d, bool i);
diff --git a/pokemod/Ini.cpp b/pokemod/Ini.cpp index 4c108564..6b8448d8 100644 --- a/pokemod/Ini.cpp +++ b/pokemod/Ini.cpp @@ -47,20 +47,14 @@ void PokeGen::PokeMod::Ini::Export(const String &p) Export(fout);
}
-template<typename T>
-void PokeGen::PokeMod::Ini::AddField<T>(const String &n, const T v)
+void PokeGen::PokeMod::Ini::AddField(const String &n, const int v)
{
- std::stringstream ss;
- std::string s;
- ss << v;
- ss >> s;
- fields[n] = s;
+ fields[n] = String("%d", v);
}
-template<>
-void PokeGen::PokeMod::Ini::AddField<bool>(const String &n, const bool v)
+void PokeGen::PokeMod::Ini::AddField(const String &n, const unsigned v)
{
- fields[n] = v ? "true" : "false";
+ fields[n] = String("%u", v);
}
void PokeGen::PokeMod::Ini::AddField(const String &n, const String &v)
@@ -68,6 +62,16 @@ 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()
{
return name;
@@ -99,7 +103,7 @@ void PokeGen::PokeMod::Ini::GetValue(const String &field, unsigned &val, unsigne val = ((UINT_MAX < temp) || *end) ? def : temp;
}
-void PokeGen::PokeMod::Ini::GetValue(const String &field, String &val)
+void PokeGen::PokeMod::Ini::GetValue(const String &field, String &val, const String &def)
{
if (!fields.count(field))
{
@@ -147,20 +151,20 @@ bool PokeGen::PokeMod::Ini::Load(std::ifstream &file) String line;
String field;
String value;
- int pos;
fields.clear();
+ unsigned pos;
name = "";
isValid = true;
std::getline(file, line);
- if (line[0] != '[')
+ if (line.at(0) != '[')
return (isValid = false);
- if ((pos = line.find(']')) != line.length() - 1)
+ if (line.at(line.length() - 1) != ']')
return (isValid = false);
- name.assign(line, 1, pos - 1);
+ name.assign(line, 1, line.length() - 2);
std::getline(file, line);
while (!line.empty())
{
- if (line[0] == '[')
+ if (line.at(0) == '[')
return (isValid = false);
pos = line.find('=');
if (pos == std::string::npos)
diff --git a/pokemod/Ini.h b/pokemod/Ini.h index b3fb2fd2..265e7764 100644 --- a/pokemod/Ini.h +++ b/pokemod/Ini.h @@ -42,13 +42,16 @@ namespace PokeGen void Export(std::ofstream &file);
void Export(const String &p);
- template<typename T> void AddField<T>(const String &n, const T v);
+ void AddField(const String &n, const int v);
+ void AddField(const String &n, const unsigned 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();
void GetValue(const String &field, int &val, int def = -1);
void GetValue(const String &field, unsigned &val, unsigned def = UINT_MAX);
- void GetValue(const String &field, String &val);
+ void GetValue(const String &field, String &val, const String &def = "");
void GetValue(const String &field, bool &val, bool def = true);
void GetValue(const String &field, double &val, double def = 0);
diff --git a/pokemod/Matrix.cpp b/pokemod/Matrix.cpp index d2c917c0..9fb32398 100644 --- a/pokemod/Matrix.cpp +++ b/pokemod/Matrix.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////
-// Name: pokemod/Matrix.cpp
+// Name: pokemod/Map.cpp
// Purpose: A 2D vector class
// Author: Ben Boeckel
// Modified by: Ben Boeckel
@@ -24,7 +24,7 @@ #include "Matrix.h"
template<class T>
-PokeGen::PokeMod::Matrix<T>::Matrix(unsigned w, unsigned h, T &d)
+PokeGen::PokeMod::Matrix<T>::Matrix(unsigned w, unsigned h, const T &d)
{
matrix.resize(w, std::vector<T>(h, d));
width = w;
@@ -32,112 +32,135 @@ PokeGen::PokeMod::Matrix<T>::Matrix(unsigned w, unsigned h, T &d) }
template<class T>
-PokeGen::PokeMod::Matrix<T>::Matrix(XmlElement &x)
+PokeGen::PokeMod::Matrix<T>::Matrix(Ini &ini)
{
- ImportXml(xml);
+ width = 0;
+ height = 0;
+ matrix.clear();
}
-template<class T>
-void PokeGen::PokeMod::Matrix<T>::AddRow(T &d)
+template<>
+PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Point>::Matrix(Ini &ini)
{
- for (std::vector<T> *i = matrix.begin(); i != matrix.end(); ++i)
- i->push_back(d);
- ++height;
+ ImportIni(ini);
+}
+
+template<>
+PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Frac>::Matrix(Ini &ini)
+{
+ ImportIni(ini);
}
template<class T>
-void PokeGen::PokeMod::Matrix<T>::ImportXml(XmlElement &xml)
+void PokeGen::PokeMod::Matrix<T>::ImportIni(Ini &ini)
+{
+}
+
+template<>
+void PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Point>::ImportIni(Ini &ini)
{
LogImportStart("Matrix");
- String curName;
- width = 0;
- height = 0;
- bool haveHeight = false;
- bool haveWidth = false;
- xml.ClearCounter();
- for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
+ ini.GetValue("width", width, 0);
+ ini.GetValue("height", height, 0);
+ if (!(width && height))
+ return;
+ matrix.resize(width, std::vector<Point>(height, Point(0, 0)));
+ for (unsigned i = 0; i < width; ++i)
{
- curName = child->GetName();
- if (curName == "height")
+ for (unsigned j = 0; j < height; ++j)
{
- child->GetValue(height);
- if (height)
- haveHeight = true;
+ int k;
+ int l;
+ ini.GetValue(String("Element-%d-%d-x", i, j), k, 0);
+ ini.GetValue(String("Element-%d-%d-y", i, j), l, 0);
+ matrix[i][j].Set(k, l);
}
- else if (curName == "width")
+ }
+ LogImportOver("Matrix");
+}
+
+template<>
+void PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Frac>::ImportIni(Ini &ini)
+{
+ LogImportStart("Matrix");
+ ini.GetValue("width", width, 0);
+ ini.GetValue("height", height, 0);
+ if (!(width && height))
+ return;
+ matrix.resize(width, std::vector<Frac>(height, Frac(1, 1)));
+ for (unsigned i = 0; i < width; ++i)
+ {
+ for (unsigned j = 0; j < height; ++j)
{
- if (haveHeight)
- {
- child->GetValue(width);
- if (width)
- haveWidth = true;
- matrix.resize(w, std::vector<T>(h, T()));
- }
- else
- Log("Matrix Import: Elements out of order", PM_DEBUG_ERROR);
+ unsigned k;
+ unsigned l;
+ bool m;
+ ini.GetValue(String("Element-%d-%d-n", i, j), k, 0);
+ ini.GetValue(String("Element-%d-%d-d", i, j), l, 0);
+ ini.GetValue(String("Element-%d-%d-i", i, j), m, 0);
+ matrix[i][j].Set(k, l, m);
}
- else if (curName == "col")
+ }
+ LogImportOver("Matrix");
+}
+
+template<>
+void PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Point>::ExportIni(const String &val)
+{
+ Log(String("Matrix Export: Starting %s", val.c_str()), PM_DEBUG_INFO);
+ // Declare the elements
+ Ini exMatrix(val);
+ exMatrix.AddField("height", height);
+ exMatrix.AddField("width", width);
+ for (int i = 0; i < width; ++i)
+ {
+ for (unsigned j = 0; j < height; ++j)
{
- if (height && width)
- {
- unsigned colNum;
- unsigned rowNum;
- child->GetValue(colNum);
- if (colNum < width)
- {
- child->ClearCounter();
- for (XmlElement *item = child->NextElement(); item; item = child->NextElement())
- {
- item->GetValue(rowNum);
- if ((item->GetName() == "item") && (rowNum < height))
- matrix[colNum][rowNum].ImportXml(*item);
- else
- Log("Matrix Import: Item out of bounds", PM_DEBUG_ERROR);
- }
- }
- else
- Log("Matrix Import: Column out of bounds", PM_DEBUG_ERROR);
- }
- else
- Log("Matrix Import: Elements out of order", PM_DEBUG_ERROR);
+ exMatrix.AddField(String("Element-%d-%d-x", i, j), matrix[i][j].GetX());
+ exMatrix.AddField(String("Element-%d-%d-y", i, j), matrix[i][j].GetY());
}
- else
- LogUnknownXml("Matrix", curName);
}
- LogImportOver("Matrix", id, name);
+ Log(String("Matrix Export: Finished %s", val.c_str()), PM_DEBUG_INFO);
}
-template<class T>
-PokeGen::PokeMod::XmlElement PokeGen::PokeMod::Matrix<T>::ExportXml(const String &val)
+template<>
+void PokeGen::PokeMod::Matrix<PokeGen::PokeMod::Frac>::ExportIni(std::ofstream &fout, const String &val)
{
Log(String("Matrix Export: Starting %s", val.c_str()), PM_DEBUG_INFO);
// Declare the elements
- XmlElement exMatrix(val, 0, true);
- exMatrix.AddElement("height", height);
- exMatrix.AddElement("width", width);
- for (int i = 0; i < width; ++i)
+ Ini exMatrix(val);
+ exMatrix.AddField("height", height);
+ exMatrix.AddField("width", width);
+ for (unsigned i = 0; i < width; ++i)
{
- XmlElement col("column", i, true);
- for (int j = 0; j < height; ++j)
+ for (unsigned j = 0; j < height; ++j)
{
- XmlElement item("item", j, true);
- item.AddElement(matrix[i][j].ExportXml());
+ exMatrix.AddField(String("Element-%d-%d-i", i, j), matrix[i][j].GetImproper());
+ exMatrix.AddField(String("Element-%d-%d-n", i, j), matrix[i][j].GetNum());
+ exMatrix.AddField(String("Element-%d-%d-d", i, j), matrix[i][j].GetDenom());
}
- exMatrix.AddElement(col);
}
+ exMatrix.Export(fout);
Log(String("Matrix Export: Finished %s", val.c_str()), PM_DEBUG_INFO);
- return exMatrix;
}
template<class T>
-void PokeGen::PokeMod::Matrix<T>::AddCol(T &d)
+void PokeGen::PokeMod::Matrix<T>::AddRow(const T &d)
+{
+ for (std::vector<T> *i = matrix.begin(); i != matrix.end(); ++i)
+ i->push_back(d);
+ ++height;
+}
+
+template<class T>
+void PokeGen::PokeMod::Matrix<T>::AddCol(const T &d)
{
matrix.push_back(std::vector<T>(GetHeight(), d));
++width;
}
template<class T>
-bool PokeGen::PokeMod::Matrix<T>::InsertRow(unsigned pos, T &d)
+bool PokeGen::PokeMod::Matrix<T>::InsertRow(unsigned pos, const T &d)
{
if (height < pos)
return false;
@@ -148,7 +171,7 @@ bool PokeGen::PokeMod::Matrix<T>::InsertRow(unsigned pos, T &d) }
template<class T>
-bool PokeGen::PokeMod::Matrix<T>::InsertCol(unsigned pos, T &d)
+bool PokeGen::PokeMod::Matrix<T>::InsertCol(unsigned pos, const T &d)
{
if (width < pos)
return false;
@@ -179,7 +202,7 @@ bool PokeGen::PokeMod::Matrix<T>::DeleteCol(unsigned pos) }
template<class T>
-bool PokeGen::PokeMod::Matrix<T>::Set(unsigned row, unsigned col, T &s)
+bool PokeGen::PokeMod::Matrix<T>::Set(unsigned row, unsigned col, const T &s)
{
if ((width <= col) || (height <= col))
return false;
diff --git a/pokemod/Matrix.h b/pokemod/Matrix.h index 3b1611cc..b11186cf 100644 --- a/pokemod/Matrix.h +++ b/pokemod/Matrix.h @@ -26,7 +26,8 @@ #include <vector>
#include "Point.h"
-#include "Xml.h"
+#include "Frac.h"
+#include "Ini.h"
namespace PokeGen
{
@@ -36,20 +37,20 @@ namespace PokeGen {
public:
Matrix();
- Matrix(unsigned w, unsigned h, T &d = T());
- Matrix(XmlElement &xml);
+ Matrix(Ini &ini);
+ Matrix(unsigned w, unsigned h, const T &d = T());
- void ImportXml(XmlElement &xml);
- XmlElement ExportXml(const String &val);
+ void ImportIni(Ini &ini);
+ void ExportIni(std::ofstream &fout, const String &val);
- void AddRow(T &d = T());
- void AddCol(T &d = T());
- bool InsertRow(unsigned pos, T &d = T());
- bool InsertCol(unsigned pos, T &d = T());
+ void AddRow(const T &d = T());
+ void AddCol(const T &d = T());
+ bool InsertRow(unsigned pos, const T &d = T());
+ bool InsertCol(unsigned pos, const T &d = T());
bool DeleteRow(unsigned pos);
bool DeleteCol(unsigned pos);
- bool Set(unsigned row, unsigned col, T &s);
+ bool Set(unsigned row, unsigned col, const T &s);
T Get(unsigned row, unsigned col);
std::vector<T> GetRow(unsigned row);
@@ -64,6 +65,24 @@ namespace PokeGen unsigned height;
unsigned width;
};
+
+ template<> class Matrix<Point>
+ {
+ public:
+ Matrix(Ini &ini);
+
+ void ImportIni(Ini &ini);
+ void ExportIni(std::ofstream &fout, const String &val);
+ };
+
+ template<> class Matrix<Frac>
+ {
+ public:
+ Matrix(Ini &ini);
+
+ void ImportIni(Ini &ini);
+ void ExportIni(std::ofstream &fout, const String &val);
+ };
}
}
diff --git a/pokemod/Nature.cpp b/pokemod/Nature.cpp index 71a714fb..a38615ac 100644 --- a/pokemod/Nature.cpp +++ b/pokemod/Nature.cpp @@ -31,10 +31,10 @@ PokeGen::PokeMod::Nature::Nature(unsigned _id) id = _id;
}
-PokeGen::PokeMod::Nature::Nature(XmlElement &xml, unsigned _id)
+PokeGen::PokeMod::Nature::Nature(Ini &ini, unsigned _id)
{
- LogCtorXml("Nature", _id);
- ImportXml(xml, _id);
+ LogCtorIni("Nature", _id);
+ ImportIni(ini, _id);
if (id == UINT_MAX)
LogIdError("Nature");
}
@@ -100,44 +100,33 @@ void PokeGen::PokeMod::Nature::Validate(wxListBox &output) }
#endif
-void PokeGen::PokeMod::Nature::ImportXml(XmlElement &xml, unsigned _id)
+void PokeGen::PokeMod::Nature::ImportIni(Ini &ini, unsigned _id)
{
- LogImport("Nature");
+ LogImportStart("Nature");
String curName;
if (_id == UINT_MAX)
{
- xml.GetValue(id);
- // Was there an id associated with the element?
+ ini.GetValue("id", id, UINT_MAX);
+ // Was there an id associated with the section?
if (id == UINT_MAX)
LogIdNotFound("Nature");
}
else
id = _id;
- name = "";
effects.clear();
- xml.ClearCounter();
- for (XmlElement *child = xml.NextElement(); child; child = xml.NextElement())
- {
- curName = child->GetName();
- if (curName == "name")
- child->GetValue(name);
- else if (curName == "effect")
- effects.push_back(NatureEffect(*child));
- else
- LogUnknownXml("Nature", curName);
- }
+ ini.GetValue("name", name, "");
LogImportOver("Nature");
}
-PokeGen::PokeMod::XmlElement PokeGen::PokeMod::Nature::ExportXml()
+void PokeGen::PokeMod::Nature::ExportIni(const std::ofstream &fout)
{
LogExportStart("Nature");
- XmlElement exNature("nature", id, true);
- exNature.AddElement("name", name);
+ Ini exNature("nature");
+ exNature.AddField("name", name);
+ exNature.Export(fout);
for (std::vector<NatureEffect>::iterator i = effects.begin(); i != effects.end(); ++i)
- exNature.AddElement(i->ExportXml());
+ i->ExportIni(fout, name);
LogExportOver("Nature");
- return exNature;
}
void PokeGen::PokeMod::Nature::SetName(const String &n)
@@ -170,7 +159,7 @@ unsigned PokeGen::PokeMod::Nature::GetNatureEffectCount() return effects.size();
}
-void PokeGen::PokeMod::Nature::NewNatureEffect()
+void PokeGen::PokeMod::Nature::NewNatureEffect(Ini *ini)
{
unsigned i = 0;
// Find the first unused ID in the vector
@@ -180,8 +169,8 @@ void PokeGen::PokeMod::Nature::NewNatureEffect() break;
}
NatureEffect newNatureEffect(i);
- if (xml)
- newNatureEffect.ImportXml(*xml);
+ if (ini)
+ newNatureEffect.ImportIni(*ini);
LogSubmoduleNew("Nature", "effect", i, id, name);
effects.push_back(newNatureEffect);
}
diff --git a/pokemod/Nature.h b/pokemod/Nature.h index 1d6425bb..a5cbc377 100644 --- a/pokemod/Nature.h +++ b/pokemod/Nature.h @@ -38,11 +38,11 @@ namespace PokeGen {
public:
Nature(unsigned _id);
- Nature(XmlElement &xml, unsigned _id = UINT_MAX);
+ Nature(Ini &ini, unsigned _id = UINT_MAX);
~Nature();
- void ImportXml(XmlElement &xml, unsigned _id = UINT_MAX);
- XmlElement ExportXml();
+ void ImportIni(Ini &ini, unsigned _id = UINT_MAX);
+ void ExportIni(const std::ofstream &fout);
void SetName(const String &n);
@@ -50,7 +50,7 @@ namespace PokeGen NatureEffect *GetNatureEffect(unsigned _id);
unsigned GetNatureEffectCount();
- void NewNatureEffect(XmlElement *xml = NULL);
+ void NewNatureEffect(Ini *ini = NULL);
void DeleteNatureEffect(unsigned _id);
private:
# ifdef PG_DEBUG_WINDOW
diff --git a/pokemod/Object.h b/pokemod/Object.h index 3bed05ca..1f76db68 100644 --- a/pokemod/Object.h +++ b/pokemod/Object.h @@ -28,7 +28,7 @@ # include <wx/listbox.h>
#endif
-#imclude <fstream>
+#include <fstream>
#include "Debug.h"
#include "Ini.h"
@@ -40,7 +40,7 @@ namespace PokeGen {
public:
virtual ~Object();
- virtual Ini ExportXml(const std::ofstream &fout);
+ virtual void ExportIni(std::ofstream &fout);
unsigned GetId();
bool IsValid();
diff --git a/pokemod/Path.cpp b/pokemod/Path.cpp index c31bff6c..c8945e28 100644 --- a/pokemod/Path.cpp +++ b/pokemod/Path.cpp @@ -71,7 +71,7 @@ bool PokeGen::PokeMod::Path::HasExtension(const String &ext) return ret;
}
-bool PokeGen::PokeMod::Path::CopyTo(const PMString &dest)
+bool PokeGen::PokeMod::Path::CopyTo(const String &dest)
{
if (!DoesExist())
return false;
diff --git a/pokemod/Path.h b/pokemod/Path.h index 701f6c25..e27b0781 100644 --- a/pokemod/Path.h +++ b/pokemod/Path.h @@ -32,7 +32,7 @@ namespace PokeGen {
namespace PokeMod
{
- class Path: public std::string
+ class Path : public String
{
public:
Path();
diff --git a/pokemod/Point.cpp b/pokemod/Point.cpp index dd8f77db..6bdb96b6 100644 --- a/pokemod/Point.cpp +++ b/pokemod/Point.cpp @@ -25,23 +25,20 @@ void PokeGen::PokeMod::Point::ImportIni(Ini &ini)
{
- String curName;
LogImportStart("Point");
- x = 0;
- y = 0;
ini.GetValue("x", x, 0);
ini.GetValue("y", y, 0);
Log(String("Point Import: Imported (%d, %d)", x, y), PM_DEBUG_INFO);
}
-PokeGen::PokeMod::XmlElement PokeGen::PokeMod::Point::ExportXml(const std::ofstream &fout, const String &val)
+void PokeGen::PokeMod::Point::ExportIni(std::ofstream &fout, const String &val)
{
Log(String("Point Export: Starting (%d, %d) as %s", x, y, val.c_str()), PM_DEBUG_INFO);
// Declare the elements
- XmlElement exPoint(val, 0, true);
- exPoint.AddElement("x", x);
- exPoint.AddElement("y", y);
+ Ini exPoint(val);
+ exPoint.AddField("x", x);
+ exPoint.AddField("y", y);
+ exPoint.Export(fout);
Log(String("Point Export: Finished (%d, %d) as %s", x, y, val.c_str()), PM_DEBUG_INFO);
- return exPoint;
}
diff --git a/pokemod/Point.h b/pokemod/Point.h index a4eea0f8..05317a7b 100644 --- a/pokemod/Point.h +++ b/pokemod/Point.h @@ -38,7 +38,7 @@ namespace PokeGen inline Point(int _x, int _y): x(_x), y(_y) {}
void ImportIni(Ini &ini);
- Ini ExportIni(const std::ofstream &fout, const String &val);
+ void ExportIni(std::ofstream &fout, const String &val);
inline void Set(int _x, int _y)
{
|
