summaryrefslogtreecommitdiffstats
path: root/sigmod
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-01-16 18:49:24 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-01-16 18:49:24 -0500
commit599434121243d16ef44355a16f5db36596c05630 (patch)
treea5ef2dcf76cc2e883fc32e713889b57691331fb9 /sigmod
parent208ac8217cc25cf81e61e5ad3269259bf921265c (diff)
downloadsigen-599434121243d16ef44355a16f5db36596c05630.tar.gz
sigen-599434121243d16ef44355a16f5db36596c05630.tar.xz
sigen-599434121243d16ef44355a16f5db36596c05630.zip
Added special load/save for enumerations
Diffstat (limited to 'sigmod')
-rw-r--r--sigmod/CoinListItem.cpp6
-rw-r--r--sigmod/ItemType.cpp6
-rw-r--r--sigmod/Macros.h2
-rw-r--r--sigmod/Map.cpp4
-rw-r--r--sigmod/MapWarp.cpp6
-rw-r--r--sigmod/Object.h10
-rw-r--r--sigmod/Sound.cpp6
-rw-r--r--sigmod/Species.cpp4
-rw-r--r--sigmod/Trainer.cpp22
9 files changed, 39 insertions, 27 deletions
diff --git a/sigmod/CoinListItem.cpp b/sigmod/CoinListItem.cpp
index 64ef7fce..d9b50228 100644
--- a/sigmod/CoinListItem.cpp
+++ b/sigmod/CoinListItem.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2007-2009 Ben Boeckel <MathStuf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -67,7 +67,7 @@ void Sigmod::CoinListItem::validate()
void Sigmod::CoinListItem::load(const QDomElement& xml)
{
LOAD_BEGIN();
- LOAD(type);
+ LOAD_ENUM(type, Type);
LOAD(object);
LOAD(cost);
}
@@ -75,7 +75,7 @@ void Sigmod::CoinListItem::load(const QDomElement& xml)
QDomElement Sigmod::CoinListItem::save() const
{
SAVE_CREATE();
- SAVE(type);
+ SAVE_ENUM(type, Type);
SAVE(object);
SAVE(cost);
return xml;
diff --git a/sigmod/ItemType.cpp b/sigmod/ItemType.cpp
index 1a0b43f7..58432dc4 100644
--- a/sigmod/ItemType.cpp
+++ b/sigmod/ItemType.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2007-2009 Ben Boeckel <MathStuf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -76,7 +76,7 @@ void Sigmod::ItemType::load(const QDomElement& xml)
LOAD(computer);
LOAD(player);
LOAD(maxWeight);
- LOAD(count);
+ LOAD_ENUM(count, Count);
}
QDomElement Sigmod::ItemType::save() const
@@ -86,7 +86,7 @@ QDomElement Sigmod::ItemType::save() const
SAVE(computer);
SAVE(player);
SAVE(maxWeight);
- SAVE(count);
+ SAVE_ENUM(count, Count);
return xml;
}
diff --git a/sigmod/Macros.h b/sigmod/Macros.h
index 3cb0dd1f..4bf6d9e9 100644
--- a/sigmod/Macros.h
+++ b/sigmod/Macros.h
@@ -32,6 +32,7 @@
setId(newId)
#define LOAD_BEGIN() clear()
#define LOAD(variable) loadValue(xml.firstChildElement(#variable), &m_##variable)
+#define LOAD_ENUM(variable, type) loadEnum(xml.firstChildElement(#variable), &m_##variable, type##Str)
#define LOAD_ARRAY(variable) loadArray(xml.firstChildElement(#variable), &m_##variable)
#define LOAD_LIST(variable) loadList(xml.firstChildElement(#variable), &m_##variable)
#define LOAD_MAP(variable) loadMap(xml.firstChildElement(#variable), &m_##variable)
@@ -48,6 +49,7 @@
QDomElement xml = QDomDocument().createElement(className()); \
xml.setAttribute("id", id())
#define SAVE(variable) xml.appendChild(saveValue(#variable, m_##variable))
+#define SAVE_ENUM(variable, type) xml.appendChild(saveEnum(#variable, m_##variable, type##Str))
#define SAVE_ARRAY(variable) xml.appendChild(saveArray(#variable, m_##variable))
#define SAVE_LIST(variable) xml.appendChild(saveList(#variable, m_##variable))
#define SAVE_MAP(variable) xml.appendChild(saveMap(#variable, m_##variable))
diff --git a/sigmod/Map.cpp b/sigmod/Map.cpp
index 0c7a8f02..582e5967 100644
--- a/sigmod/Map.cpp
+++ b/sigmod/Map.cpp
@@ -118,7 +118,7 @@ void Sigmod::Map::load(const QDomElement& xml)
LOAD_BEGIN();
LOAD(name);
LOAD(flyWarp);
- LOAD(type);
+ LOAD_ENUM(type, Type);
LOAD(width);
LOAD(height);
LOAD_SUB(newEffect, MapEffect);
@@ -133,7 +133,7 @@ QDomElement Sigmod::Map::save() const
SAVE_CREATE();
SAVE(name);
SAVE(flyWarp);
- SAVE(type);
+ SAVE_ENUM(type, Type);
SAVE(width);
SAVE(height);
SAVE_SUB(MapEffect, effects);
diff --git a/sigmod/MapWarp.cpp b/sigmod/MapWarp.cpp
index 157f2de9..ba0276dd 100644
--- a/sigmod/MapWarp.cpp
+++ b/sigmod/MapWarp.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2007-2009 Ben Boeckel <MathStuf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -71,7 +71,7 @@ void Sigmod::MapWarp::load(const QDomElement& xml)
LOAD_BEGIN();
LOAD(name);
LOAD(area);
- LOAD(type);
+ LOAD_ENUM(type, Type);
LOAD(toMap);
LOAD(toWarp);
LOAD(script);
@@ -82,7 +82,7 @@ QDomElement Sigmod::MapWarp::save() const
SAVE_CREATE();
SAVE(name);
SAVE(area);
- SAVE(type);
+ SAVE_ENUM(type, Type);
SAVE(toMap);
SAVE(toWarp);
SAVE(script);
diff --git a/sigmod/Object.h b/sigmod/Object.h
index e001f0e2..dea69215 100644
--- a/sigmod/Object.h
+++ b/sigmod/Object.h
@@ -211,6 +211,11 @@ template<> inline void loadValue<Sigcore::Script>(const QDomElement& xml, Sigcor
value->setScript(xml.firstChild().toText().data());
}
+template<typename T> inline void loadEnum(const QDomElement& xml, T* value, const QStringList& array)
+{
+ *value = static_cast<T>(array.indexOf(xml.firstChild().toText().data()));
+}
+
template<typename T, int S> inline void loadArray(const QDomElement& xml, QVarLengthArray<T, S>* value)
{
QDomElement node = xml.firstChildElement("element");
@@ -325,6 +330,11 @@ template<> inline QDomElement saveValue<Sigcore::Script>(const QString& name, co
return element;
}
+template<typename T> inline QDomElement saveEnum(const QString& name, const T& value, const QStringList& array)
+{
+ return saveValue<QString>(name, array[value]);
+}
+
template<typename T, int S> inline QDomElement saveArray(const QString& name, const QVarLengthArray<T, S>& value)
{
QDomElement element = QDomDocument().createElement(name);
diff --git a/sigmod/Sound.cpp b/sigmod/Sound.cpp
index 8e6060bf..e5ad5ce5 100644
--- a/sigmod/Sound.cpp
+++ b/sigmod/Sound.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2007-2009 Ben Boeckel <MathStuf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -65,7 +65,7 @@ void Sigmod::Sound::load(const QDomElement& xml)
{
LOAD_BEGIN();
LOAD(name);
- LOAD(type);
+ LOAD_ENUM(type, Type);
LOAD(data);
}
@@ -73,7 +73,7 @@ QDomElement Sigmod::Sound::save() const
{
SAVE_CREATE();
SAVE(name);
- SAVE(type);
+ SAVE_ENUM(type, Type);
SAVE(data);
return xml;
}
diff --git a/sigmod/Species.cpp b/sigmod/Species.cpp
index a4a9133c..a4cd4a4c 100644
--- a/sigmod/Species.cpp
+++ b/sigmod/Species.cpp
@@ -188,7 +188,7 @@ void Sigmod::Species::load(const QDomElement& xml)
LOAD(name);
LOAD_ARRAY(baseStat);
LOAD_ARRAY(effortValue);
- LOAD(growth);
+ LOAD_ENUM(growth, Style);
LOAD(experienceValue);
LOAD(catchValue);
LOAD(maxHoldWeight);
@@ -221,7 +221,7 @@ QDomElement Sigmod::Species::save() const
SAVE(name);
SAVE_ARRAY(baseStat);
SAVE_ARRAY(effortValue);
- SAVE(growth);
+ SAVE_ENUM(growth, Style);
SAVE(experienceValue);
SAVE(catchValue);
SAVE(maxHoldWeight);
diff --git a/sigmod/Trainer.cpp b/sigmod/Trainer.cpp
index d7a08618..17a8d955 100644
--- a/sigmod/Trainer.cpp
+++ b/sigmod/Trainer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -75,11 +75,11 @@ void Sigmod::Trainer::load(const QDomElement& xml)
LOAD(moneyFactor);
LOAD(skin);
LOAD(depth);
- LOAD(teamIntel);
- LOAD(moveIntel);
- LOAD(itemIntel);
- LOAD(abilityIntel);
- LOAD(statIntel);
+ LOAD_ENUM(teamIntel, Intelligence);
+ LOAD_ENUM(moveIntel, Intelligence);
+ LOAD_ENUM(itemIntel, Intelligence);
+ LOAD_ENUM(abilityIntel, Intelligence);
+ LOAD_ENUM(statIntel, Intelligence);
}
QDomElement Sigmod::Trainer::save() const
@@ -89,11 +89,11 @@ QDomElement Sigmod::Trainer::save() const
SAVE(moneyFactor);
SAVE(skin);
SAVE(depth);
- SAVE(teamIntel);
- SAVE(moveIntel);
- SAVE(itemIntel);
- SAVE(abilityIntel);
- SAVE(statIntel);
+ SAVE_ENUM(teamIntel, Intelligence);
+ SAVE_ENUM(moveIntel, Intelligence);
+ SAVE_ENUM(itemIntel, Intelligence);
+ SAVE_ENUM(abilityIntel, Intelligence);
+ SAVE_ENUM(statIntel, Intelligence);
return xml;
}