summaryrefslogtreecommitdiffstats
path: root/pokescripting
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-08-04 23:06:44 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-08-04 23:06:44 +0000
commit56b91df6010a9f3d304438cf95816399a6e46622 (patch)
tree4fc79267d86ebca445c91e00630cb29cfc5c1da4 /pokescripting
parentc014db49f5044f15e7ad0236437ac9ae4aa3b23f (diff)
downloadsigen-56b91df6010a9f3d304438cf95816399a6e46622.tar.gz
sigen-56b91df6010a9f3d304438cf95816399a6e46622.tar.xz
sigen-56b91df6010a9f3d304438cf95816399a6e46622.zip
[FIX] SoundUI widget has a better layout
[FIX] Sound playback works in SoundUI [FIX] SoundWrapper returns a Phonon object for playback in scripts now [FIX] Wrapper classes now won't be duplicated (persistent storage is possible now) [FIX] Linking to libraries is fixed for RPM [FIX] Pokemod Macros.h is hidden if not compiling pokemod [FIX] make-tarball script is simpler now (and works as upstream, not local copy) [FIX] Cleaned up spec file per review request for Fedora git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@236 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokescripting')
-rw-r--r--pokescripting/AbilityWrapper.h8
-rw-r--r--pokescripting/AuthorWrapper.h8
-rw-r--r--pokescripting/BadgeWrapper.h20
-rw-r--r--pokescripting/CMakeLists.txt4
-rw-r--r--pokescripting/CoinListObjectWrapper.h20
-rw-r--r--pokescripting/CoinListWrapper.h14
-rw-r--r--pokescripting/EggGroupWrapper.h8
-rw-r--r--pokescripting/GlobalScriptWrapper.h8
-rw-r--r--pokescripting/ItemTypeWrapper.h8
-rw-r--r--pokescripting/ItemWrapper.h14
-rw-r--r--pokescripting/MapEffectWrapper.h14
-rw-r--r--pokescripting/MapTrainerTeamMemberWrapper.h14
-rw-r--r--pokescripting/MapTrainerWrapper.h24
-rw-r--r--pokescripting/MapWarpWrapper.h14
-rw-r--r--pokescripting/MapWildListEncounterWrapper.h14
-rw-r--r--pokescripting/MapWildListWrapper.h14
-rw-r--r--pokescripting/MapWrapper.h44
-rw-r--r--pokescripting/MoveWrapper.h14
-rw-r--r--pokescripting/NatureWrapper.h8
-rw-r--r--pokescripting/ObjectWrapper.cpp21
-rw-r--r--pokescripting/ObjectWrapper.h3
-rw-r--r--pokescripting/PokemodWrapper.h150
-rw-r--r--pokescripting/RulesWrapper.h8
-rw-r--r--pokescripting/SkinWrapper.h8
-rw-r--r--pokescripting/SoundWrapper.h26
-rw-r--r--pokescripting/SpeciesAbilityWrapper.h14
-rw-r--r--pokescripting/SpeciesItemWrapper.h14
-rw-r--r--pokescripting/SpeciesMoveWrapper.h14
-rw-r--r--pokescripting/SpeciesWrapper.h56
-rw-r--r--pokescripting/SpriteWrapper.h8
-rw-r--r--pokescripting/StatusWrapper.h8
-rw-r--r--pokescripting/StoreWrapper.h8
-rw-r--r--pokescripting/TODO2
-rw-r--r--pokescripting/TileWrapper.h14
-rw-r--r--pokescripting/TimeWrapper.h8
-rw-r--r--pokescripting/TrainerWrapper.h14
-rw-r--r--pokescripting/TypeWrapper.h8
-rw-r--r--pokescripting/WeatherWrapper.h8
38 files changed, 458 insertions, 206 deletions
diff --git a/pokescripting/AbilityWrapper.h b/pokescripting/AbilityWrapper.h
index aa749e66..d563427c 100644
--- a/pokescripting/AbilityWrapper.h
+++ b/pokescripting/AbilityWrapper.h
@@ -31,12 +31,18 @@ class POKESCRIPTING_EXPORT AbilityWrapper : public ObjectWrapper
Q_OBJECT
public:
- AbilityWrapper(const Pokemod::Ability* ability, QObject* parent);
+ static AbilityWrapper* create(const Pokemod::Ability* ability, QObject* parent)
+ {
+ if (!m_instances.contains(ability->id()))
+ m_instances[ability->id()] = new AbilityWrapper(ability, parent);
+ return qobject_cast<AbilityWrapper*>(m_instances[ability->id()]);
+ }
public slots:
QString name() const;
int priority() const;
QString description() const;
private:
+ AbilityWrapper(const Pokemod::Ability* ability, QObject* parent);
AbilityWrapper& operator=(const AbilityWrapper& rhs);
const Pokemod::Ability* m_ability;
diff --git a/pokescripting/AuthorWrapper.h b/pokescripting/AuthorWrapper.h
index 6eca1e5b..f4784fec 100644
--- a/pokescripting/AuthorWrapper.h
+++ b/pokescripting/AuthorWrapper.h
@@ -31,12 +31,18 @@ class POKESCRIPTING_EXPORT AuthorWrapper : public ObjectWrapper
Q_OBJECT
public:
- AuthorWrapper(const Pokemod::Author* author, QObject* parent);
+ static AuthorWrapper* create(const Pokemod::Author* author, QObject* parent)
+ {
+ if (!m_instances.contains(author->id()))
+ m_instances[author->id()] = new AuthorWrapper(author, parent);
+ return qobject_cast<AuthorWrapper*>(m_instances[author->id()]);
+ }
public slots:
QString name() const;
QString email() const;
QString role() const;
private:
+ AuthorWrapper(const Pokemod::Author* author, QObject* parent);
AuthorWrapper& operator=(const AuthorWrapper& rhs);
const Pokemod::Author* m_author;
diff --git a/pokescripting/BadgeWrapper.h b/pokescripting/BadgeWrapper.h
index 6cfd637a..b1f018cb 100644
--- a/pokescripting/BadgeWrapper.h
+++ b/pokescripting/BadgeWrapper.h
@@ -32,14 +32,20 @@ class POKESCRIPTING_EXPORT BadgeWrapper : public ObjectWrapper
Q_OBJECT
public:
- BadgeWrapper(const Pokemod::Badge* badge, QObject* parent);
+ static BadgeWrapper* create(const Pokemod::Badge* badge, QObject* parent)
+ {
+ if (!m_instances.contains(badge->id()))
+ m_instances[badge->id()] = new BadgeWrapper(badge, parent);
+ return qobject_cast<BadgeWrapper*>(m_instances[badge->id()]);
+ }
public slots:
QString name() const;
- const SpriteWrapper* face() const;
- const SpriteWrapper* badge() const;
+ SpriteWrapper* face();
+ SpriteWrapper* badge();
int obey() const;
Pokemod::Fraction stat(const int stat) const;
private:
+ BadgeWrapper(const Pokemod::Badge* badge, QObject* parent);
BadgeWrapper& operator=(const BadgeWrapper& rhs);
const Pokemod::Badge* m_badge;
@@ -56,14 +62,14 @@ inline QString BadgeWrapper::name() const
return m_badge->name();
}
-inline const Pokescripting::SpriteWrapper* BadgeWrapper::face() const
+inline Pokescripting::SpriteWrapper* BadgeWrapper::face()
{
- return new SpriteWrapper(pokemod()->spriteById(m_badge->face()), const_cast<BadgeWrapper*>(this));
+ return SpriteWrapper::create(pokemod()->spriteById(m_badge->face()), this);
}
-inline const Pokescripting::SpriteWrapper* BadgeWrapper::badge() const
+inline Pokescripting::SpriteWrapper* BadgeWrapper::badge()
{
- return new SpriteWrapper(pokemod()->spriteById(m_badge->badge()), const_cast<BadgeWrapper*>(this));
+ return SpriteWrapper::create(pokemod()->spriteById(m_badge->badge()), this);
}
inline int BadgeWrapper::obey() const
diff --git a/pokescripting/CMakeLists.txt b/pokescripting/CMakeLists.txt
index 1f5a44f4..e4ede5a9 100644
--- a/pokescripting/CMakeLists.txt
+++ b/pokescripting/CMakeLists.txt
@@ -53,6 +53,7 @@ SET(pokescripting_DEVEL
)
SET(pokescripting_SRCS
Config.cpp
+ ObjectWrapper.cpp
)
ADD_LIBRARY(pokescripting
@@ -66,7 +67,8 @@ SET_TARGET_PROPERTIES(pokescripting
)
TARGET_LINK_LIBRARIES(pokescripting
${QT_QTCORE_LIBRARY}
- ${KDE4_KROSSCORE_LIBS}
+ ${PHONON_LIBRARY}
+ ${KDE4_KROSSCORE_LIBRARY}
pokemod
)
diff --git a/pokescripting/CoinListObjectWrapper.h b/pokescripting/CoinListObjectWrapper.h
index 6fb71cea..117b6d11 100644
--- a/pokescripting/CoinListObjectWrapper.h
+++ b/pokescripting/CoinListObjectWrapper.h
@@ -33,14 +33,20 @@ class POKESCRIPTING_EXPORT CoinListObjectWrapper : public ObjectWrapper
Q_OBJECT
public:
- CoinListObjectWrapper(const Pokemod::CoinListObject* object, QObject* parent);
+ static CoinListObjectWrapper* create(const Pokemod::CoinListObject* object, QObject* parent)
+ {
+ if (!m_instances.contains(object->id()))
+ m_instances[object->id()] = new CoinListObjectWrapper(object, parent);
+ return qobject_cast<CoinListObjectWrapper*>(m_instances[object->id()]);
+ }
public slots:
int type() const;
- const ItemWrapper* itemObject() const;
- const SpeciesWrapper* speciesObject() const;
+ ItemWrapper* itemObject();
+ SpeciesWrapper* speciesObject();
int amount() const;
int cost() const;
private:
+ CoinListObjectWrapper(const Pokemod::CoinListObject* object, QObject* parent);
CoinListObjectWrapper& operator=(const CoinListObjectWrapper& rhs);
const Pokemod::CoinListObject* m_object;
@@ -57,17 +63,17 @@ inline int CoinListObjectWrapper::type() const
return m_object->type();
}
-inline const ItemWrapper* CoinListObjectWrapper::itemObject() const
+inline ItemWrapper* CoinListObjectWrapper::itemObject()
{
if (m_object->type() == Pokemod::CoinListObject::Item)
- return new ItemWrapper(pokemod()->itemById(m_object->object()), const_cast<CoinListObjectWrapper*>(this));
+ return ItemWrapper::create(pokemod()->itemById(m_object->object()), this);
return NULL;
}
-inline const SpeciesWrapper* CoinListObjectWrapper::speciesObject() const
+inline SpeciesWrapper* CoinListObjectWrapper::speciesObject()
{
if (m_object->type() == Pokemod::CoinListObject::Species)
- return new SpeciesWrapper(pokemod()->speciesById(m_object->object()), const_cast<CoinListObjectWrapper*>(this));
+ return SpeciesWrapper::create(pokemod()->speciesById(m_object->object()), this);
return NULL;
}
diff --git a/pokescripting/CoinListWrapper.h b/pokescripting/CoinListWrapper.h
index 21b902b2..a224545a 100644
--- a/pokescripting/CoinListWrapper.h
+++ b/pokescripting/CoinListWrapper.h
@@ -32,13 +32,19 @@ class POKESCRIPTING_EXPORT CoinListWrapper : public ObjectWrapper
Q_OBJECT
public:
- CoinListWrapper(const Pokemod::CoinList* coinList, QObject* parent);
+ static CoinListWrapper* create(const Pokemod::CoinList* coinList, QObject* parent)
+ {
+ if (!m_instances.contains(coinList->id()))
+ m_instances[coinList->id()] = new CoinListWrapper(coinList, parent);
+ return qobject_cast<CoinListWrapper*>(m_instances[coinList->id()]);
+ }
public slots:
QString name() const;
- const CoinListObjectWrapper* object(const int index) const;
+ CoinListObjectWrapper* object(const int index);
int objectCount() const;
private:
+ CoinListWrapper(const Pokemod::CoinList* coinList, QObject* parent);
CoinListWrapper& operator=(const CoinListWrapper& rhs);
const Pokemod::CoinList* m_coinList;
@@ -55,9 +61,9 @@ inline QString CoinListWrapper::name() const
return m_coinList->name();
}
-inline const CoinListObjectWrapper* CoinListWrapper::object(const int index) const
+inline CoinListObjectWrapper* CoinListWrapper::object(const int index)
{
- return new CoinListObjectWrapper(m_coinList->object(index), const_cast<CoinListWrapper*>(this));
+ return CoinListObjectWrapper::create(m_coinList->object(index), this);
}
inline int CoinListWrapper::objectCount() const
diff --git a/pokescripting/EggGroupWrapper.h b/pokescripting/EggGroupWrapper.h
index d8d33683..91ca7661 100644
--- a/pokescripting/EggGroupWrapper.h
+++ b/pokescripting/EggGroupWrapper.h
@@ -31,10 +31,16 @@ class POKESCRIPTING_EXPORT EggGroupWrapper : public ObjectWrapper
Q_OBJECT
public:
- EggGroupWrapper(const Pokemod::EggGroup* eggGroup, QObject* parent);
+ static EggGroupWrapper* create(const Pokemod::EggGroup* eggGroup, QObject* parent)
+ {
+ if (!m_instances.contains(eggGroup->id()))
+ m_instances[eggGroup->id()] = new EggGroupWrapper(eggGroup, parent);
+ return qobject_cast<EggGroupWrapper*>(m_instances[eggGroup->id()]);
+ }
public slots:
QString name() const;
private:
+ EggGroupWrapper(const Pokemod::EggGroup* eggGroup, QObject* parent);
EggGroupWrapper& operator=(const EggGroupWrapper& rhs);
const Pokemod::EggGroup* m_eggGroup;
diff --git a/pokescripting/GlobalScriptWrapper.h b/pokescripting/GlobalScriptWrapper.h
index cfd42065..eb65b913 100644
--- a/pokescripting/GlobalScriptWrapper.h
+++ b/pokescripting/GlobalScriptWrapper.h
@@ -31,10 +31,16 @@ class POKESCRIPTING_EXPORT GlobalScriptWrapper : public ObjectWrapper
Q_OBJECT
public:
- GlobalScriptWrapper(const Pokemod::GlobalScript* globalScript, QObject* parent);
+ static GlobalScriptWrapper* create(const Pokemod::GlobalScript* globalScript, QObject* parent)
+ {
+ if (!m_instances.contains(globalScript->id()))
+ m_instances[globalScript->id()] = new GlobalScriptWrapper(globalScript, parent);
+ return qobject_cast<GlobalScriptWrapper*>(m_instances[globalScript->id()]);
+ }
public slots:
QString name() const;
private:
+ GlobalScriptWrapper(const Pokemod::GlobalScript* globalScript, QObject* parent);
GlobalScriptWrapper& operator=(const GlobalScriptWrapper& rhs);
const Pokemod::GlobalScript* m_globalScript;
diff --git a/pokescripting/ItemTypeWrapper.h b/pokescripting/ItemTypeWrapper.h
index 4092d800..7521f964 100644
--- a/pokescripting/ItemTypeWrapper.h
+++ b/pokescripting/ItemTypeWrapper.h
@@ -31,13 +31,19 @@ class POKESCRIPTING_EXPORT ItemTypeWrapper : public ObjectWrapper
Q_OBJECT
public:
- ItemTypeWrapper(const Pokemod::ItemType* itemType, QObject* parent);
+ static ItemTypeWrapper* create(const Pokemod::ItemType* itemType, QObject* parent)
+ {
+ if (!m_instances.contains(itemType->id()))
+ m_instances[itemType->id()] = new ItemTypeWrapper(itemType, parent);
+ return qobject_cast<ItemTypeWrapper*>(m_instances[itemType->id()]);
+ }
public slots:
QString name() const;
int computer() const;
int player() const;
int count() const;
private:
+ ItemTypeWrapper(const Pokemod::ItemType* itemType, QObject* parent);
ItemTypeWrapper& operator=(const ItemTypeWrapper& rhs);
const Pokemod::ItemType* m_itemType;
diff --git a/pokescripting/ItemWrapper.h b/pokescripting/ItemWrapper.h
index 784cd63c..124f7dda 100644
--- a/pokescripting/ItemWrapper.h
+++ b/pokescripting/ItemWrapper.h
@@ -32,14 +32,20 @@ class POKESCRIPTING_EXPORT ItemWrapper : public ObjectWrapper
Q_OBJECT
public:
- ItemWrapper(const Pokemod::Item* item, QObject* parent);
+ static ItemWrapper* create(const Pokemod::Item* item, QObject* parent)
+ {
+ if (!m_instances.contains(item->id()))
+ m_instances[item->id()] = new ItemWrapper(item, parent);
+ return qobject_cast<ItemWrapper*>(m_instances[item->id()]);
+ }
public slots:
QString name() const;
bool sellable() const;
- const ItemTypeWrapper* type() const;
+ ItemTypeWrapper* type();
int price() const;
QString description() const;
private:
+ ItemWrapper(const Pokemod::Item* item, QObject* parent);
ItemWrapper& operator=(const ItemWrapper& rhs);
const Pokemod::Item* m_item;
@@ -61,9 +67,9 @@ inline bool ItemWrapper::sellable() const
return m_item->sellable();
}
-inline const ItemTypeWrapper* ItemWrapper::type() const
+inline ItemTypeWrapper* ItemWrapper::type()
{
- return new ItemTypeWrapper(pokemod()->itemTypeById(m_item->type()), const_cast<ItemWrapper*>(this));
+ return ItemTypeWrapper::create(pokemod()->itemTypeById(m_item->type()), this);
}
inline int ItemWrapper::price() const
diff --git a/pokescripting/MapEffectWrapper.h b/pokescripting/MapEffectWrapper.h
index bf2bb127..a4fbb19f 100644
--- a/pokescripting/MapEffectWrapper.h
+++ b/pokescripting/MapEffectWrapper.h
@@ -32,12 +32,18 @@ class POKESCRIPTING_EXPORT MapEffectWrapper : public ObjectWrapper
Q_OBJECT
public:
- MapEffectWrapper(const Pokemod::MapEffect* effect, QObject* parent);
+ static MapEffectWrapper* create(const Pokemod::MapEffect* effect, QObject* parent)
+ {
+ if (!m_instances.contains(effect->id()))
+ m_instances[effect->id()] = new MapEffectWrapper(effect, parent);
+ return qobject_cast<MapEffectWrapper*>(m_instances[effect->id()]);
+ }
public slots:
QString name() const;
- const SkinWrapper* skin() const;
+ SkinWrapper* skin();
bool isGhost() const;
private:
+ MapEffectWrapper(const Pokemod::MapEffect* effect, QObject* parent);
MapEffectWrapper& operator=(const MapEffectWrapper& rhs);
const Pokemod::MapEffect* m_effect;
@@ -54,9 +60,9 @@ inline QString MapEffectWrapper::name() const
return m_effect->name();
}
-inline const Pokescripting::SkinWrapper* MapEffectWrapper::skin() const
+inline Pokescripting::SkinWrapper* MapEffectWrapper::skin()
{
- return new SkinWrapper(pokemod()->skinById(m_effect->skin()), const_cast<MapEffectWrapper*>(this));
+ return SkinWrapper::create(pokemod()->skinById(m_effect->skin()), this);
}
inline bool MapEffectWrapper::isGhost() const
diff --git a/pokescripting/MapTrainerTeamMemberWrapper.h b/pokescripting/MapTrainerTeamMemberWrapper.h
index b8495745..c0330469 100644
--- a/pokescripting/MapTrainerTeamMemberWrapper.h
+++ b/pokescripting/MapTrainerTeamMemberWrapper.h
@@ -36,15 +36,21 @@ class POKESCRIPTING_EXPORT MapTrainerTeamMemberWrapper : public ObjectWrapper
Q_OBJECT
public:
- MapTrainerTeamMemberWrapper(const Pokemod::MapTrainerTeamMember* teamMember, QObject* parent);
+ static MapTrainerTeamMemberWrapper* create(const Pokemod::MapTrainerTeamMember* teamMember, QObject* parent)
+ {
+ if (!m_instances.contains(teamMember->id()))
+ m_instances[teamMember->id()] = new MapTrainerTeamMemberWrapper(teamMember, parent);
+ return qobject_cast<MapTrainerTeamMemberWrapper*>(m_instances[teamMember->id()]);
+ }
public slots:
- const SpeciesWrapper* species() const;
+ SpeciesWrapper* species();
int level() const;
bool ability(const int ability) const;
bool item(const int item) const;
bool move(const int move) const;
bool nature(const int nature) const;
private:
+ MapTrainerTeamMemberWrapper(const Pokemod::MapTrainerTeamMember* teamMember, QObject* parent);
MapTrainerTeamMemberWrapper& operator=(const MapTrainerTeamMemberWrapper& rhs);
const Pokemod::MapTrainerTeamMember* m_teamMember;
@@ -56,9 +62,9 @@ inline MapTrainerTeamMemberWrapper::MapTrainerTeamMemberWrapper(const Pokemod::M
{
}
-inline const SpeciesWrapper* MapTrainerTeamMemberWrapper::species() const
+inline SpeciesWrapper* MapTrainerTeamMemberWrapper::species()
{
- return new SpeciesWrapper(pokemod()->speciesById(m_teamMember->species()), const_cast<MapTrainerTeamMemberWrapper*>(this));
+ return SpeciesWrapper::create(pokemod()->speciesById(m_teamMember->species()), this);
}
inline int MapTrainerTeamMemberWrapper::level() const
diff --git a/pokescripting/MapTrainerWrapper.h b/pokescripting/MapTrainerWrapper.h
index c6554d55..1e558a04 100644
--- a/pokescripting/MapTrainerWrapper.h
+++ b/pokescripting/MapTrainerWrapper.h
@@ -33,16 +33,22 @@ class POKESCRIPTING_EXPORT MapTrainerWrapper : public ObjectWrapper
Q_OBJECT
public:
- MapTrainerWrapper(const Pokemod::MapTrainer* trainer, QObject* parent);
+ static MapTrainerWrapper* create(const Pokemod::MapTrainer* trainer, QObject* parent)
+ {
+ if (!m_instances.contains(trainer->id()))
+ m_instances[trainer->id()] = new MapTrainerWrapper(trainer, parent);
+ return qobject_cast<MapTrainerWrapper*>(m_instances[trainer->id()]);
+ }
public slots:
QString name() const;
- const TrainerWrapper* trainerClass() const;
+ TrainerWrapper* trainerClass();
int numberFight() const;
- const MapTrainerTeamMemberWrapper* leadTeamMember() const;
+ MapTrainerTeamMemberWrapper* leadTeamMember();
- const MapTrainerTeamMemberWrapper* teamMember(const int index) const;
+ MapTrainerTeamMemberWrapper* teamMember(const int index);
int teamMemberCount() const;
private:
+ MapTrainerWrapper(const Pokemod::MapTrainer* trainer, QObject* parent);
MapTrainerWrapper& operator=(const MapTrainerWrapper& rhs);
const Pokemod::MapTrainer* m_trainer;
@@ -59,9 +65,9 @@ inline QString MapTrainerWrapper::name() const
return m_trainer->name();
}
-inline const TrainerWrapper* MapTrainerWrapper::trainerClass() const
+inline TrainerWrapper* MapTrainerWrapper::trainerClass()
{
- return new TrainerWrapper(pokemod()->trainerById(m_trainer->trainerClass()), const_cast<MapTrainerWrapper*>(this));
+ return TrainerWrapper::create(pokemod()->trainerById(m_trainer->trainerClass()), this);
}
inline int MapTrainerWrapper::numberFight() const
@@ -69,14 +75,14 @@ inline int MapTrainerWrapper::numberFight() const
return m_trainer->numberFight();
}
-inline const MapTrainerTeamMemberWrapper* MapTrainerWrapper::leadTeamMember() const
+inline MapTrainerTeamMemberWrapper* MapTrainerWrapper::leadTeamMember()
{
return teamMember(m_trainer->leadTeamMember());
}
-inline const MapTrainerTeamMemberWrapper* MapTrainerWrapper::teamMember(const int index) const
+inline MapTrainerTeamMemberWrapper* MapTrainerWrapper::teamMember(const int index)
{
- return new MapTrainerTeamMemberWrapper(m_trainer->teamMember(index), const_cast<MapTrainerWrapper*>(this));
+ return MapTrainerTeamMemberWrapper::create(m_trainer->teamMember(index), this);
}
inline int MapTrainerWrapper::teamMemberCount() const
diff --git a/pokescripting/MapWarpWrapper.h b/pokescripting/MapWarpWrapper.h
index 5d1dd8ec..8bc3a7da 100644
--- a/pokescripting/MapWarpWrapper.h
+++ b/pokescripting/MapWarpWrapper.h
@@ -32,13 +32,19 @@ class POKESCRIPTING_EXPORT MapWarpWrapper : public ObjectWrapper
Q_OBJECT
public:
- MapWarpWrapper(const Pokemod::MapWarp* warp, QObject* parent);
+ static MapWarpWrapper* create(const Pokemod::MapWarp* warp, QObject* parent)
+ {
+ if (!m_instances.contains(warp->id()))
+ m_instances[warp->id()] = new MapWarpWrapper(warp, parent);
+ return qobject_cast<MapWarpWrapper*>(m_instances[warp->id()]);
+ }
public slots:
QString name() const;
QPoint coordinate() const;
int type() const;
- const MapWarpWrapper* toWarp() const;
+ MapWarpWrapper* toWarp();
private:
+ MapWarpWrapper(const Pokemod::MapWarp* warp, QObject* parent);
MapWarpWrapper& operator=(const MapWarpWrapper& rhs);
const Pokemod::MapWarp* m_warp;
@@ -65,9 +71,9 @@ inline int MapWarpWrapper::type() const
return m_warp->type();
}
-inline const MapWarpWrapper* MapWarpWrapper::toWarp() const
+inline MapWarpWrapper* MapWarpWrapper::toWarp()
{
- return new MapWarpWrapper(pokemod()->mapById(m_warp->toMap())->warpById(m_warp->toWarp()), const_cast<MapWarpWrapper*>(this));
+ return new MapWarpWrapper(pokemod()->mapById(m_warp->toMap())->warpById(m_warp->toWarp()), this);
}
}
diff --git a/pokescripting/MapWildListEncounterWrapper.h b/pokescripting/MapWildListEncounterWrapper.h
index 2fcb357a..2d1a2724 100644
--- a/pokescripting/MapWildListEncounterWrapper.h
+++ b/pokescripting/MapWildListEncounterWrapper.h
@@ -32,12 +32,18 @@ class POKESCRIPTING_EXPORT MapWildListEncounterWrapper : public ObjectWrapper
Q_OBJECT
public:
- MapWildListEncounterWrapper(const Pokemod::MapWildListEncounter* encounter, QObject* parent);
+ static MapWildListEncounterWrapper* create(const Pokemod::MapWildListEncounter* encounter, QObject* parent)
+ {
+ if (!m_instances.contains(encounter->id()))
+ m_instances[encounter->id()] = new MapWildListEncounterWrapper(encounter, parent);
+ return qobject_cast<MapWildListEncounterWrapper*>(m_instances[encounter->id()]);
+ }
public slots:
- const SpeciesWrapper* species() const;
+ SpeciesWrapper* species();
int level() const;
int weight() const;
private:
+ MapWildListEncounterWrapper(const Pokemod::MapWildListEncounter* encounter, QObject* parent);
MapWildListEncounterWrapper& operator=(const MapWildListEncounterWrapper& rhs);
const Pokemod::MapWildListEncounter* m_encounter;
@@ -49,9 +55,9 @@ inline MapWildListEncounterWrapper::MapWildListEncounterWrapper(const Pokemod::M
{
}
-inline const SpeciesWrapper* MapWildListEncounterWrapper::species() const
+inline SpeciesWrapper* MapWildListEncounterWrapper::species()
{
- return new SpeciesWrapper(pokemod()->speciesById(m_encounter->species()), const_cast<MapWildListEncounterWrapper*>(this));
+ return SpeciesWrapper::create(pokemod()->speciesById(m_encounter->species()), this);
}
inline int MapWildListEncounterWrapper::level() const
diff --git a/pokescripting/MapWildListWrapper.h b/pokescripting/MapWildListWrapper.h
index cf37a07a..b11a2346 100644
--- a/pokescripting/MapWildListWrapper.h
+++ b/pokescripting/MapWildListWrapper.h
@@ -32,13 +32,19 @@ class POKESCRIPTING_EXPORT MapWildListWrapper : public ObjectWrapper
Q_OBJECT
public:
- MapWildListWrapper(const Pokemod::MapWildList* wildList, QObject* parent);
+ static MapWildListWrapper* create(const Pokemod::MapWildList* wildList, QObject* parent)
+ {
+ if (!m_instances.contains(wildList->id()))
+ m_instances[wildList->id()] = new MapWildListWrapper(wildList, parent);
+ return qobject_cast<MapWildListWrapper*>(m_instances[wildList->id()]);
+ }
public slots:
QString name() const;
- const MapWildListEncounterWrapper* encounter(const int index) const;
+ MapWildListEncounterWrapper* encounter(const int index);
int encounterCount() const;
private:
+ MapWildListWrapper(const Pokemod::MapWildList* wildList, QObject* parent);
MapWildListWrapper& operator=(const MapWildListWrapper& rhs);
const Pokemod::MapWildList* m_wildList;
@@ -55,9 +61,9 @@ inline QString MapWildListWrapper::name() const
return m_wildList->name();
}
-inline const MapWildListEncounterWrapper* MapWildListWrapper::encounter(const int index) const
+inline MapWildListEncounterWrapper* MapWildListWrapper::encounter(const int index)
{
- return new MapWildListEncounterWrapper(m_wildList->encounter(index), const_cast<MapWildListWrapper*>(this));
+ return MapWildListEncounterWrapper::create(m_wildList->encounter(index), this);
}
inline int MapWildListWrapper::encounterCount() const
diff --git a/pokescripting/MapWrapper.h b/pokescripting/MapWrapper.h
index 7221b1cc..50cd207b 100644
--- a/pokescripting/MapWrapper.h
+++ b/pokescripting/MapWrapper.h
@@ -36,19 +36,25 @@ class POKESCRIPTING_EXPORT MapWrapper : public ObjectWrapper
Q_OBJECT
public:
- MapWrapper(const Pokemod::Map* map, QObject* parent);
+ static MapWrapper* create(const Pokemod::Map* map, QObject* parent)
+ {
+ if (!m_instances.contains(map->id()))
+ m_instances[map->id()] = new MapWrapper(map, parent);
+ return qobject_cast<MapWrapper*>(m_instances[map->id()]);
+ }
public slots:
QString name() const;
- const MapWarpWrapper* flyWarp() const;
+ MapWarpWrapper* flyWarp();
int type() const;
- const TileWrapper* tile(const int row, const int column) const;
+ TileWrapper* tile(const int row, const int column);
QPoint mapSize() const;
- const MapEffectWrapper* effect(const QString& name) const;
- const MapTrainerWrapper* trainer(const QString& name) const;
- const MapWarpWrapper* warp(const QString& name) const;
- const MapWildListWrapper* wildList(const QString& name) const;
+ MapEffectWrapper* effect(const QString& name);
+ MapTrainerWrapper* trainer(const QString& name);
+ MapWarpWrapper* warp(const QString& name);
+ MapWildListWrapper* wildList(const QString& name);
private:
+ MapWrapper(const Pokemod::Map* map, QObject* parent);
MapWrapper& operator=(const MapWrapper& rhs);
const Pokemod::Map* m_map;
@@ -65,9 +71,9 @@ inline QString MapWrapper::name() const
return m_map->name();
}
-inline const MapWarpWrapper* MapWrapper::flyWarp() const
+inline MapWarpWrapper* MapWrapper::flyWarp()
{
- return new MapWarpWrapper(m_map->warpById(m_map->flyWarp()), const_cast<MapWrapper*>(this));
+ return MapWarpWrapper::create(m_map->warpById(m_map->flyWarp()), this);
}
inline int MapWrapper::type() const
@@ -75,9 +81,9 @@ inline int MapWrapper::type() const
return m_map->type();
}
-inline const TileWrapper* MapWrapper::tile(const int row, const int column) const
+inline TileWrapper* MapWrapper::tile(const int row, const int column)
{
- return new TileWrapper(pokemod()->tileById(m_map->tile(row, column)), const_cast<MapWrapper*>(this));
+ return TileWrapper::create(pokemod()->tileById(m_map->tile(row, column)), this);
}
inline QPoint MapWrapper::mapSize() const
@@ -85,42 +91,42 @@ inline QPoint MapWrapper::mapSize() const
return m_map->size();
}
-inline const MapEffectWrapper* MapWrapper::effect(const QString& name) const
+inline MapEffectWrapper* MapWrapper::effect(const QString& name)
{
for (int i = 0; i < m_map->effectCount(); ++i)
{
if (m_map->effect(i)->name() == name)
- return new MapEffectWrapper(m_map->effect(i), const_cast<MapWrapper*>(this));
+ return MapEffectWrapper::create(m_map->effect(i), this);
}
return NULL;
}
-inline const MapTrainerWrapper* MapWrapper::trainer(const QString& name) const
+inline MapTrainerWrapper* MapWrapper::trainer(const QString& name)
{
for (int i = 0; i < m_map->trainerCount(); ++i)
{
if (m_map->trainer(i)->name() == name)
- return new MapTrainerWrapper(m_map->trainer(i), const_cast<MapWrapper*>(this));
+ return MapTrainerWrapper::create(m_map->trainer(i), this);
}
return NULL;
}
-inline const MapWarpWrapper* MapWrapper::warp(const QString& name) const
+inline MapWarpWrapper* MapWrapper::warp(const QString& name)
{
for (int i = 0; i < m_map->warpCount(); ++i)
{
if (m_map->warp(i)->name() == name)
- return new MapWarpWrapper(m_map->warp(i), const_cast<MapWrapper*>(this));
+ return MapWarpWrapper::create(m_map->warp(i), this);
}
return NULL;
}
-inline const MapWildListWrapper* MapWrapper::wildList(const QString& name) const
+inline MapWildListWrapper* MapWrapper::wildList(const QString& name)
{
for (int i = 0; i < m_map->wildListCount(); ++i)
{
if (m_map->wildList(i)->name() == name)
- return new MapWildListWrapper(m_map->wildList(i), const_cast<MapWrapper*>(this));
+ return MapWildListWrapper::create(m_map->wildList(i), this);
}
return NULL;
}
diff --git a/pokescripting/MoveWrapper.h b/pokescripting/MoveWrapper.h
index 7dbb48cf..aac393a9 100644
--- a/pokescripting/MoveWrapper.h
+++ b/pokescripting/MoveWrapper.h
@@ -32,17 +32,23 @@ class POKESCRIPTING_EXPORT MoveWrapper : public ObjectWrapper
Q_OBJECT
public:
- MoveWrapper(const Pokemod::Move* move, QObject* parent);
+ static MoveWrapper* create(const Pokemod::Move* move, QObject* parent)
+ {
+ if (!m_instances.contains(move->id()))
+ m_instances[move->id()] = new MoveWrapper(move, parent);
+ return qobject_cast<MoveWrapper*>(m_instances[move->id()]);
+ }
public slots:
QString name() const;
Pokemod::Fraction accuracy() const;
int power() const;
- const TypeWrapper* type() const;
+ TypeWrapper* type();
bool special() const;
int powerPoints() const;
int priority() const;
QString description() const;
private:
+ MoveWrapper(const Pokemod::Move* move, QObject* parent);
MoveWrapper& operator=(const MoveWrapper& rhs);
const Pokemod::Move* m_move;
@@ -69,9 +75,9 @@ inline int MoveWrapper::power() const
return m_move->power();
}
-inline const TypeWrapper* MoveWrapper::type() const
+inline TypeWrapper* MoveWrapper::type()
{
- return new TypeWrapper(pokemod()->typeById(m_move->type()), const_cast<MoveWrapper*>(this));
+ return TypeWrapper::create(pokemod()->typeById(m_move->type()), this);
}
inline bool MoveWrapper::special() const
diff --git a/pokescripting/NatureWrapper.h b/pokescripting/NatureWrapper.h
index 776716cf..14a87ae8 100644
--- a/pokescripting/NatureWrapper.h
+++ b/pokescripting/NatureWrapper.h
@@ -31,12 +31,18 @@ class POKESCRIPTING_EXPORT NatureWrapper : public ObjectWrapper
Q_OBJECT
public:
- NatureWrapper(const Pokemod::Nature* nature, QObject* parent);
+ static NatureWrapper* create(const Pokemod::Nature* nature, QObject* parent)
+ {
+ if (!m_instances.contains(nature->id()))
+ m_instances[nature->id()] = new NatureWrapper(nature, parent);
+ return qobject_cast<NatureWrapper*>(m_instances[nature->id()]);
+ }
public slots:
QString name() const;
Pokemod::Fraction stat(const int stat) const;
int weight() const;
private:
+ NatureWrapper(const Pokemod::Nature* nature, QObject* parent);
NatureWrapper& operator=(const NatureWrapper& rhs);
const Pokemod::Nature* m_nature;
diff --git a/pokescripting/ObjectWrapper.cpp b/pokescripting/ObjectWrapper.cpp
new file mode 100644
index 00000000..0e5b734a
--- /dev/null
+++ b/pokescripting/ObjectWrapper.cpp
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2008 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Header include
+#include "ObjectWrapper.h"
+
+QMap<int, Pokescripting::ObjectWrapper*> Pokescripting::ObjectWrapper::m_instances;
diff --git a/pokescripting/ObjectWrapper.h b/pokescripting/ObjectWrapper.h
index 8b3aee29..2cb9f9c4 100644
--- a/pokescripting/ObjectWrapper.h
+++ b/pokescripting/ObjectWrapper.h
@@ -26,6 +26,7 @@
#include "../pokemod/Pokemod.h"
// Qt includes
+#include <QtCore/QMap>
#include <QtCore/QObject>
namespace Pokescripting
@@ -40,6 +41,8 @@ class POKESCRIPTING_EXPORT ObjectWrapper : public Config
int id() const;
const Pokemod::Pokemod* pokemod() const;
+ protected:
+ static QMap<int, ObjectWrapper*> m_instances;
private:
const Pokemod::Object* m_object;
};
diff --git a/pokescripting/PokemodWrapper.h b/pokescripting/PokemodWrapper.h
index 08125a79..c8ea704c 100644
--- a/pokescripting/PokemodWrapper.h
+++ b/pokescripting/PokemodWrapper.h
@@ -32,6 +32,7 @@
#include "NatureWrapper.h"
#include "ObjectWrapper.h"
#include "RulesWrapper.h"
+#include "SkinWrapper.h"
#include "SoundWrapper.h"
#include "SpeciesWrapper.h"
#include "SpriteWrapper.h"
@@ -58,31 +59,32 @@ class POKESCRIPTING_EXPORT PokemodWrapper : public ObjectWrapper
QString title() const;
QString version() const;
QString description() const;
- const MapWarpWrapper* startWarp() const;
+ MapWarpWrapper* startWarp();
Pokemod::Fraction effectiveness(const TypeWrapper* attacker, const TypeWrapper* defender) const;
- const RulesWrapper* rules() const;
+ RulesWrapper* rules();
- const AbilityWrapper* ability(const QString& name) const;
- const AuthorWrapper* author(const QString& name) const;
- const BadgeWrapper* badge(const QString& name) const;
- const CoinListWrapper* coinList(const QString& name) const;
- const EggGroupWrapper* eggGroup(const QString& name) const;
- const GlobalScriptWrapper* globalScript(const QString& name) const;
- const ItemWrapper* item(const QString& name) const;
- const ItemTypeWrapper* itemType(const QString& name) const;
- const MapWrapper* map(const QString& name) const;
- const MoveWrapper* move(const QString& name) const;
- const NatureWrapper* nature(const QString& name) const;
- const SoundWrapper* sound(const QString& name) const;
- const SpeciesWrapper* species(const QString& name) const;
- const SpriteWrapper* sprite(const QString& name) const;
- const StatusWrapper* status(const QString& name) const;
- const StoreWrapper* store(const QString& name) const;
- const TileWrapper* tile(const QString& name) const;
- const TimeWrapper* time(const QString& name) const;
- const TrainerWrapper* trainer(const QString& name) const;
- const TypeWrapper* type(const QString& name) const;
- const WeatherWrapper* weather(const QString& name) const;
+ AbilityWrapper* ability(const QString& name);
+ AuthorWrapper* author(const QString& name);
+ BadgeWrapper* badge(const QString& name);
+ CoinListWrapper* coinList(const QString& name);
+ EggGroupWrapper* eggGroup(const QString& name);
+ GlobalScriptWrapper* globalScript(const QString& name);
+ ItemWrapper* item(const QString& name);
+ ItemTypeWrapper* itemType(const QString& name);
+ MapWrapper* map(const QString& name);
+ MoveWrapper* move(const QString& name);
+ NatureWrapper* nature(const QString& name);
+ SkinWrapper* skin(const QString& name);
+ SoundWrapper* sound(const QString& name);
+ SpeciesWrapper* species(const QString& name);
+ SpriteWrapper* sprite(const QString& name);
+ StatusWrapper* status(const QString& name);
+ StoreWrapper* store(const QString& name);
+ TileWrapper* tile(const QString& name);
+ TimeWrapper* time(const QString& name);
+ TrainerWrapper* trainer(const QString& name);
+ TypeWrapper* type(const QString& name);
+ WeatherWrapper* weather(const QString& name);
private:
PokemodWrapper& operator=(const PokemodWrapper& rhs);
@@ -110,9 +112,9 @@ inline QString PokemodWrapper::description() const
return m_pokemod->description();
}
-inline const MapWarpWrapper* PokemodWrapper::startWarp() const
+inline MapWarpWrapper* PokemodWrapper::startWarp()
{
- return new MapWarpWrapper(m_pokemod->mapById(m_pokemod->startMap())->warpById(m_pokemod->startWarp()), const_cast<PokemodWrapper*>(this));
+ return MapWarpWrapper::create(m_pokemod->mapById(m_pokemod->startMap())->warpById(m_pokemod->startWarp()), this);
}
inline Pokemod::Fraction PokemodWrapper::effectiveness(const TypeWrapper* attacker, const TypeWrapper* defender) const
@@ -120,217 +122,227 @@ inline Pokemod::Fraction PokemodWrapper::effectiveness(const TypeWrapper* attack
return m_pokemod->typechart(m_pokemod->typeIndex(attacker->id()), m_pokemod->typeIndex(defender->id()));
}
-const RulesWrapper* PokemodWrapper::rules() const
+inline RulesWrapper* PokemodWrapper::rules()
{
- return new RulesWrapper(m_pokemod->rules(), const_cast<PokemodWrapper*>(this));
+ return RulesWrapper::create(m_pokemod->rules(), this);
}
-inline const AbilityWrapper* PokemodWrapper::ability(const QString& name) const
+inline AbilityWrapper* PokemodWrapper::ability(const QString& name)
{
for (int i = 0; i < m_pokemod->abilityCount(); ++i)
{
if (m_pokemod->ability(i)->name() == name)
- return new AbilityWrapper(m_pokemod->ability(i), const_cast<PokemodWrapper*>(this));
+ return AbilityWrapper::create(m_pokemod->ability(i), this);
}
return NULL;
}
-inline const AuthorWrapper* PokemodWrapper::author(const QString& name) const
+inline AuthorWrapper* PokemodWrapper::author(const QString& name)
{
for (int i = 0; i < m_pokemod->authorCount(); ++i)
{
if (m_pokemod->author(i)->name() == name)
- return new AuthorWrapper(m_pokemod->author(i), const_cast<PokemodWrapper*>(this));
+ return AuthorWrapper::create(m_pokemod->author(i), this);
}
return NULL;
}
-inline const BadgeWrapper* PokemodWrapper::badge(const QString& name) const
+inline BadgeWrapper* PokemodWrapper::badge(const QString& name)
{
for (int i = 0; i < m_pokemod->badgeCount(); ++i)
{
if (m_pokemod->badge(i)->name() == name)
- return new BadgeWrapper(m_pokemod->badge(i), const_cast<PokemodWrapper*>(this));
+ return BadgeWrapper::create(m_pokemod->badge(i), this);
}
return NULL;
}
-inline const CoinListWrapper* PokemodWrapper::coinList(const QString& name) const
+inline CoinListWrapper* PokemodWrapper::coinList(const QString& name)
{
for (int i = 0; i < m_pokemod->coinListCount(); ++i)
{
if (m_pokemod->coinList(i)->name() == name)
- return new CoinListWrapper(m_pokemod->coinList(i), const_cast<PokemodWrapper*>(this));
+ return CoinListWrapper::create(m_pokemod->coinList(i), this);
}
return NULL;
}
-inline const EggGroupWrapper* PokemodWrapper::eggGroup(const QString& name) const
+inline EggGroupWrapper* PokemodWrapper::eggGroup(const QString& name)
{
for (int i = 0; i < m_pokemod->eggGroupCount(); ++i)
{
if (m_pokemod->eggGroup(i)->name() == name)
- return new EggGroupWrapper(m_pokemod->eggGroup(i), const_cast<PokemodWrapper*>(this));
+ return EggGroupWrapper::create(m_pokemod->eggGroup(i), this);
}
return NULL;
}
-inline const GlobalScriptWrapper* PokemodWrapper::globalScript(const QString& name) const
+inline GlobalScriptWrapper* PokemodWrapper::globalScript(const QString& name)
{
for (int i = 0; i < m_pokemod->globalScriptCount(); ++i)
{
if (m_pokemod->globalScript(i)->name() == name)
- return new GlobalScriptWrapper(m_pokemod->globalScript(i), const_cast<PokemodWrapper*>(this));
+ return GlobalScriptWrapper::create(m_pokemod->globalScript(i), this);
}
return NULL;
}
-inline const ItemWrapper* PokemodWrapper::item(const QString& name) const
+inline ItemWrapper* PokemodWrapper::item(const QString& name)
{
for (int i = 0; i < m_pokemod->itemCount(); ++i)
{
if (m_pokemod->item(i)->name() == name)
- return new ItemWrapper(m_pokemod->item(i), const_cast<PokemodWrapper*>(this));
+ return ItemWrapper::create(m_pokemod->item(i), this);
}
return NULL;
}
-inline const ItemTypeWrapper* PokemodWrapper::itemType(const QString& name) const
+inline ItemTypeWrapper* PokemodWrapper::itemType(const QString& name)
{
for (int i = 0; i < m_pokemod->itemTypeCount(); ++i)
{
if (m_pokemod->itemType(i)->name() == name)
- return new ItemTypeWrapper(m_pokemod->itemType(i), const_cast<PokemodWrapper*>(this));
+ return ItemTypeWrapper::create(m_pokemod->itemType(i), this);
}
return NULL;
}
-inline const MapWrapper* PokemodWrapper::map(const QString& name) const
+inline MapWrapper* PokemodWrapper::map(const QString& name)
{
for (int i = 0; i < m_pokemod->mapCount(); ++i)
{
if (m_pokemod->map(i)->name() == name)
- return new MapWrapper(m_pokemod->map(i), const_cast<PokemodWrapper*>(this));
+ return MapWrapper::create(m_pokemod->map(i), this);
}
return NULL;
}
-inline const MoveWrapper* PokemodWrapper::move(const QString& name) const
+inline MoveWrapper* PokemodWrapper::move(const QString& name)
{
for (int i = 0; i < m_pokemod->moveCount(); ++i)
{
if (m_pokemod->move(i)->name() == name)
- return new MoveWrapper(m_pokemod->move(i), const_cast<PokemodWrapper*>(this));
+ return MoveWrapper::create(m_pokemod->move(i), this);
}
return NULL;
}
-inline const NatureWrapper* PokemodWrapper::nature(const QString& name) const
+inline NatureWrapper* PokemodWrapper::nature(const QString& name)
{
for (int i = 0; i < m_pokemod->natureCount(); ++i)
{
if (m_pokemod->nature(i)->name() == name)
- return new NatureWrapper(m_pokemod->nature(i), const_cast<PokemodWrapper*>(this));
+ return NatureWrapper::create(m_pokemod->nature(i), this);
}
return NULL;
}
-inline const SoundWrapper* PokemodWrapper::sound(const QString& name) const
+inline SkinWrapper* PokemodWrapper::skin(const QString& name)
+{
+ for (int i = 0; i < m_pokemod->skinCount(); ++i)
+ {
+ if (m_pokemod->skin(i)->name() == name)
+ return SkinWrapper::create(m_pokemod->skin(i), this);
+ }
+ return NULL;
+}
+
+inline SoundWrapper* PokemodWrapper::sound(const QString& name)
{
for (int i = 0; i < m_pokemod->soundCount(); ++i)
{
if (m_pokemod->sound(i)->name() == name)
- return new SoundWrapper(m_pokemod->sound(i), const_cast<PokemodWrapper*>(this));
+ return SoundWrapper::create(m_pokemod->sound(i), this);
}
return NULL;
}
-inline const SpeciesWrapper* PokemodWrapper::species(const QString& name) const
+inline SpeciesWrapper* PokemodWrapper::species(const QString& name)
{
for (int i = 0; i < m_pokemod->speciesCount(); ++i)
{
if (m_pokemod->species(i)->name() == name)
- return new SpeciesWrapper(m_pokemod->species(i), const_cast<PokemodWrapper*>(this));
+ return SpeciesWrapper::create(m_pokemod->species(i), this);
}
return NULL;
}
-inline const SpriteWrapper* PokemodWrapper::sprite(const QString& name) const
+inline SpriteWrapper* PokemodWrapper::sprite(const QString& name)
{
for (int i = 0; i < m_pokemod->spriteCount(); ++i)
{
if (m_pokemod->sprite(i)->name() == name)
- return new SpriteWrapper(m_pokemod->sprite(i), const_cast<PokemodWrapper*>(this));
+ return SpriteWrapper::create(m_pokemod->sprite(i), this);
}
return NULL;
}
-inline const StatusWrapper* PokemodWrapper::status(const QString& name) const
+inline StatusWrapper* PokemodWrapper::status(const QString& name)
{
for (int i = 0; i < m_pokemod->statusCount(); ++i)
{
if (m_pokemod->status(i)->name() == name)
- return new StatusWrapper(m_pokemod->status(i), const_cast<PokemodWrapper*>(this));
+ return StatusWrapper::create(m_pokemod->status(i), this);
}
return NULL;
}
-inline const StoreWrapper* PokemodWrapper::store(const QString& name) const
+inline StoreWrapper* PokemodWrapper::store(const QString& name)
{
for (int i = 0; i < m_pokemod->storeCount(); ++i)
{
if (m_pokemod->store(i)->name() == name)
- return new StoreWrapper(m_pokemod->store(i), const_cast<PokemodWrapper*>(this));
+ return StoreWrapper::create(m_pokemod->store(i), this);
}
return NULL;
}
-inline const TileWrapper* PokemodWrapper::tile(const QString& name) const
+inline TileWrapper* PokemodWrapper::tile(const QString& name)
{
for (int i = 0; i < m_pokemod->tileCount(); ++i)
{
if (m_pokemod->tile(i)->name() == name)
- return new TileWrapper(m_pokemod->tile(i), const_cast<PokemodWrapper*>(this));
+ return TileWrapper::create(m_pokemod->tile(i), this);
}
return NULL;
}
-inline const TimeWrapper* PokemodWrapper::time(const QString& name) const
+inline TimeWrapper* PokemodWrapper::time(const QString& name)
{
for (int i = 0; i < m_pokemod->timeCount(); ++i)
{
if (m_pokemod->time(i)->name() == name)
- return new TimeWrapper(m_pokemod->time(i), const_cast<PokemodWrapper*>(this));
+ return TimeWrapper::create(m_pokemod->time(i), this);
}
return NULL;
}
-inline const TrainerWrapper* PokemodWrapper::trainer(const QString& name) const
+inline TrainerWrapper* PokemodWrapper::trainer(const QString& name)
{
for (int i = 0; i < m_pokemod->trainerCount(); ++i)
{
if (m_pokemod->trainer(i)->name() == name)
- return new TrainerWrapper(m_pokemod->trainer(i), const_cast<PokemodWrapper*>(this));
+ return TrainerWrapper::create(m_pokemod->trainer(i), this);
}
return NULL;
}
-inline const TypeWrapper* PokemodWrapper::type(const QString& name) const
+inline TypeWrapper* PokemodWrapper::type(const QString& name)
{
for (int i = 0; i < m_pokemod->typeCount(); ++i)
{
if (m_pokemod->type(i)->name() == name)
- return new TypeWrapper(m_pokemod->type(i), const_cast<PokemodWrapper*>(this));
+ return TypeWrapper::create(m_pokemod->type(i), this);
}
return NULL;
}
-inline const WeatherWrapper* PokemodWrapper::weather(const QString& name) const
+inline WeatherWrapper* PokemodWrapper::weather(const QString& name)
{
for (int i = 0; i < m_pokemod->weatherCount(); ++i)
{
if (m_pokemod->weather(i)->name() == name)
- return new WeatherWrapper(m_pokemod->weather(i), const_cast<PokemodWrapper*>(this));
+ return WeatherWrapper::create(m_pokemod->weather(i), this);
}
return NULL;
}
diff --git a/pokescripting/RulesWrapper.h b/pokescripting/RulesWrapper.h
index fc816306..8d907aa9 100644
--- a/pokescripting/RulesWrapper.h
+++ b/pokescripting/RulesWrapper.h
@@ -31,7 +31,12 @@ class POKESCRIPTING_EXPORT RulesWrapper : public ObjectWrapper
Q_OBJECT
public:
- RulesWrapper(const Pokemod::Rules* rules, QObject* parent);
+ static RulesWrapper* create(const Pokemod::Rules* rules, QObject* parent)
+ {
+ if (!m_instances.contains(rules->id()))
+ m_instances[rules->id()] = new RulesWrapper(rules, parent);
+ return qobject_cast<RulesWrapper*>(m_instances[rules->id()]);
+ }
public slots:
bool genderAllowed() const;
bool breedingAllowed() const;
@@ -57,6 +62,7 @@ class POKESCRIPTING_EXPORT RulesWrapper : public ObjectWrapper
int maxTotalEV() const;
int maxEVPerStat() const;
private:
+ RulesWrapper(const Pokemod::Rules* rules, QObject* parent);
RulesWrapper& operator=(const RulesWrapper& rhs);
const Pokemod::Rules* m_rules;
diff --git a/pokescripting/SkinWrapper.h b/pokescripting/SkinWrapper.h
index 46d4c2a2..5d96e0f6 100644
--- a/pokescripting/SkinWrapper.h
+++ b/pokescripting/SkinWrapper.h
@@ -31,10 +31,16 @@ class POKESCRIPTING_EXPORT SkinWrapper : public ObjectWrapper
Q_OBJECT
public:
- SkinWrapper(const Pokemod::Skin* skin, QObject* parent);
+ static SkinWrapper* create(const Pokemod::Skin* skin, QObject* parent)
+ {
+ if (!m_instances.contains(skin->id()))
+ m_instances[skin->id()] = new SkinWrapper(skin, parent);
+ return qobject_cast<SkinWrapper*>(m_instances[skin->id()]);
+ }
public slots:
QString name() const;
private:
+ SkinWrapper(const Pokemod::Skin* skin, QObject* parent);
SkinWrapper& operator=(const SkinWrapper& rhs);
const Pokemod::Skin* m_skin;
diff --git a/pokescripting/SoundWrapper.h b/pokescripting/SoundWrapper.h
index 683cca13..9f7f7eec 100644
--- a/pokescripting/SoundWrapper.h
+++ b/pokescripting/SoundWrapper.h
@@ -24,6 +24,13 @@
// Pokemod includes
#include "../pokemod/Sound.h"
+// Qt includes
+#include <QtCore/QBuffer>
+
+// Phonon includes
+#include <Phonon/MediaObject>
+#include <Phonon/MediaSource>
+
namespace Pokescripting
{
class POKESCRIPTING_EXPORT SoundWrapper : public ObjectWrapper
@@ -31,11 +38,17 @@ class POKESCRIPTING_EXPORT SoundWrapper : public ObjectWrapper
Q_OBJECT
public:
- SoundWrapper(const Pokemod::Sound* sound, QObject* parent);
+ static SoundWrapper* create(const Pokemod::Sound* sound, QObject* parent)
+ {
+ if (!m_instances.contains(sound->id()))
+ m_instances[sound->id()] = new SoundWrapper(sound, parent);
+ return qobject_cast<SoundWrapper*>(m_instances[sound->id()]);
+ }
public slots:
QString name() const;
- // TODO: Get audio data from it
+ Phonon::MediaObject* data();
private:
+ SoundWrapper(const Pokemod::Sound* sound, QObject* parent);
SoundWrapper& operator=(const SoundWrapper& rhs);
const Pokemod::Sound* m_sound;
@@ -52,6 +65,15 @@ inline QString SoundWrapper::name() const
return m_sound->name();
}
+inline Phonon::MediaObject* SoundWrapper::data()
+{
+ Phonon::MediaObject* media = new Phonon::MediaObject(this);
+ QBuffer* buffer = new QBuffer(media);
+ buffer->setData(m_sound->data());
+ media->setCurrentSource(buffer);
+ return media;
+}
+
}
#endif
diff --git a/pokescripting/SpeciesAbilityWrapper.h b/pokescripting/SpeciesAbilityWrapper.h
index d052d697..272a9c0d 100644
--- a/pokescripting/SpeciesAbilityWrapper.h
+++ b/pokescripting/SpeciesAbilityWrapper.h
@@ -32,11 +32,17 @@ class POKESCRIPTING_EXPORT SpeciesAbilityWrapper : public ObjectWrapper
Q_OBJECT
public:
- SpeciesAbilityWrapper(const Pokemod::SpeciesAbility* ability, QObject* parent);
+ static SpeciesAbilityWrapper* create(const Pokemod::SpeciesAbility* ability, QObject* parent)
+ {
+ if (!m_instances.contains(ability->id()))
+ m_instances[ability->id()] = new SpeciesAbilityWrapper(ability, parent);
+ return qobject_cast<SpeciesAbilityWrapper*>(m_instances[ability->id()]);
+ }
public slots:
- const AbilityWrapper* ability() const;
+ AbilityWrapper* ability();
int weight() const;
private:
+ SpeciesAbilityWrapper(const Pokemod::SpeciesAbility* ability, QObject* parent);
SpeciesAbilityWrapper& operator=(const SpeciesAbilityWrapper& rhs);
const Pokemod::SpeciesAbility* m_ability;
@@ -48,9 +54,9 @@ inline SpeciesAbilityWrapper::SpeciesAbilityWrapper(const Pokemod::SpeciesAbilit
{
}
-inline const AbilityWrapper* SpeciesAbilityWrapper::ability() const
+inline AbilityWrapper* SpeciesAbilityWrapper::ability()
{
- return new AbilityWrapper(pokemod()->abilityById(m_ability->ability()), const_cast<SpeciesAbilityWrapper*>(this));
+ return AbilityWrapper::create(pokemod()->abilityById(m_ability->ability()), this);
}
inline int SpeciesAbilityWrapper::weight() const
diff --git a/pokescripting/SpeciesItemWrapper.h b/pokescripting/SpeciesItemWrapper.h
index 2d82fdd8..ebe72daf 100644
--- a/pokescripting/SpeciesItemWrapper.h
+++ b/pokescripting/SpeciesItemWrapper.h
@@ -32,11 +32,17 @@ class POKESCRIPTING_EXPORT SpeciesItemWrapper : public ObjectWrapper
Q_OBJECT
public:
- SpeciesItemWrapper(const Pokemod::SpeciesItem* item, QObject* parent);
+ static SpeciesItemWrapper* create(const Pokemod::SpeciesItem* item, QObject* parent)
+ {
+ if (!m_instances.contains(item->id()))
+ m_instances[item->id()] = new SpeciesItemWrapper(item, parent);
+ return qobject_cast<SpeciesItemWrapper*>(m_instances[item->id()]);
+ }
public slots:
- const ItemWrapper* item() const;
+ ItemWrapper* item();
int weight() const;
private:
+ SpeciesItemWrapper(const Pokemod::SpeciesItem* item, QObject* parent);
SpeciesItemWrapper& operator=(const SpeciesItemWrapper& rhs);
const Pokemod::SpeciesItem* m_item;
@@ -48,9 +54,9 @@ inline SpeciesItemWrapper::SpeciesItemWrapper(const Pokemod::SpeciesItem* item,
{
}
-inline const ItemWrapper* SpeciesItemWrapper::item() const
+inline ItemWrapper* SpeciesItemWrapper::item()
{
- return new ItemWrapper(pokemod()->itemById(m_item->item()), const_cast<SpeciesItemWrapper*>(this));
+ return ItemWrapper::create(pokemod()->itemById(m_item->item()), this);
}
inline int SpeciesItemWrapper::weight() const
diff --git a/pokescripting/SpeciesMoveWrapper.h b/pokescripting/SpeciesMoveWrapper.h
index e8012f5e..b351c3f8 100644
--- a/pokescripting/SpeciesMoveWrapper.h
+++ b/pokescripting/SpeciesMoveWrapper.h
@@ -32,12 +32,18 @@ class POKESCRIPTING_EXPORT SpeciesMoveWrapper : public ObjectWrapper
Q_OBJECT
public:
- SpeciesMoveWrapper(const Pokemod::SpeciesMove* move, QObject* parent);
+ static SpeciesMoveWrapper* create(const Pokemod::SpeciesMove* move, QObject* parent)
+ {
+ if (!m_instances.contains(move->id()))
+ m_instances[move->id()] = new SpeciesMoveWrapper(move, parent);
+ return qobject_cast<SpeciesMoveWrapper*>(m_instances[move->id()]);
+ }
public slots:
- const MoveWrapper* move() const;
+ MoveWrapper* move();
int level() const;
int wild() const;
private:
+ SpeciesMoveWrapper(const Pokemod::SpeciesMove* move, QObject* parent);
SpeciesMoveWrapper& operator=(const SpeciesMoveWrapper& rhs);
const Pokemod::SpeciesMove* m_move;
@@ -49,9 +55,9 @@ inline SpeciesMoveWrapper::SpeciesMoveWrapper(const Pokemod::SpeciesMove* move,
{
}
-inline const MoveWrapper* SpeciesMoveWrapper::move() const
+inline MoveWrapper* SpeciesMoveWrapper::move()
{
- return new MoveWrapper(pokemod()->moveById(m_move->move()), const_cast<SpeciesMoveWrapper*>(this));
+ return MoveWrapper::create(pokemod()->moveById(m_move->move()), this);
}
inline int SpeciesMoveWrapper::level() const
diff --git a/pokescripting/SpeciesWrapper.h b/pokescripting/SpeciesWrapper.h
index d0938e25..f34ec777 100644
--- a/pokescripting/SpeciesWrapper.h
+++ b/pokescripting/SpeciesWrapper.h
@@ -36,7 +36,12 @@ class POKESCRIPTING_EXPORT SpeciesWrapper : public ObjectWrapper
Q_OBJECT
public:
- SpeciesWrapper(const Pokemod::Species* species, QObject* parent);
+ static SpeciesWrapper* create(const Pokemod::Species* species, QObject* parent)
+ {
+ if (!m_instances.contains(species->id()))
+ m_instances[species->id()] = new SpeciesWrapper(species, parent);
+ return qobject_cast<SpeciesWrapper*>(m_instances[species->id()]);
+ }
public slots:
QString name() const;
int baseStat(const int stat) const;
@@ -51,26 +56,27 @@ class POKESCRIPTING_EXPORT SpeciesWrapper : public ObjectWrapper
int weight() const;
int height() const;
QString pokedexEntry() const;
- const SpriteWrapper* frontMaleSprite() const;
- const SpriteWrapper* backMaleSprite() const;
- const SpriteWrapper* frontFemaleSprite() const;
- const SpriteWrapper* backFemaleSprite() const;
- const SkinWrapper* skin() const;
+ SpriteWrapper* frontMaleSprite();
+ SpriteWrapper* backMaleSprite();
+ SpriteWrapper* frontFemaleSprite();
+ SpriteWrapper* backFemaleSprite();
+ SkinWrapper* skin();
Pokemod::Fraction genderFactor() const;
int eggSpecies() const;
int eggSteps() const;
bool type(const int type) const;
bool eggGroup(const int eggGroup) const;
- const SpeciesAbilityWrapper* ability(const int index) const;
+ SpeciesAbilityWrapper* ability(const int index);
int abilityCount() const;
- const SpeciesItemWrapper* item(const int index) const;
+ SpeciesItemWrapper* item(const int index);
int itemCount() const;
- const SpeciesMoveWrapper* move(const int index) const;
+ SpeciesMoveWrapper* move(const int index);
int moveCount() const;
private:
+ SpeciesWrapper(const Pokemod::Species* species, QObject* parent);
SpeciesWrapper& operator=(const SpeciesWrapper& rhs);
const Pokemod::Species* m_species;
@@ -147,29 +153,29 @@ inline QString SpeciesWrapper::pokedexEntry() const
return m_species->pokedexEntry();
}
-inline const Pokescripting::SpriteWrapper* SpeciesWrapper::frontMaleSprite() const
+inline Pokescripting::SpriteWrapper* SpeciesWrapper::frontMaleSprite()
{
- return new SpriteWrapper(pokemod()->spriteById(m_species->frontMaleSprite()), const_cast<SpeciesWrapper*>(this));
+ return SpriteWrapper::create(pokemod()->spriteById(m_species->frontMaleSprite()), this);
}
-inline const Pokescripting::SpriteWrapper* SpeciesWrapper::backMaleSprite() const
+inline Pokescripting::SpriteWrapper* SpeciesWrapper::backMaleSprite()
{
- return new SpriteWrapper(pokemod()->spriteById(m_species->backMaleSprite()), const_cast<SpeciesWrapper*>(this));
+ return SpriteWrapper::create(pokemod()->spriteById(m_species->backMaleSprite()), this);
}
-inline const Pokescripting::SpriteWrapper* SpeciesWrapper::frontFemaleSprite() const
+inline Pokescripting::SpriteWrapper* SpeciesWrapper::frontFemaleSprite()
{
- return new SpriteWrapper(pokemod()->spriteById(m_species->frontFemaleSprite()), const_cast<SpeciesWrapper*>(this));
+ return SpriteWrapper::create(pokemod()->spriteById(m_species->frontFemaleSprite()), this);
}
-inline const Pokescripting::SpriteWrapper* SpeciesWrapper::backFemaleSprite() const
+inline Pokescripting::SpriteWrapper* SpeciesWrapper::backFemaleSprite()
{
- return new SpriteWrapper(pokemod()->spriteById(m_species->backFemaleSprite()), const_cast<SpeciesWrapper*>(this));
+ return SpriteWrapper::create(pokemod()->spriteById(m_species->backFemaleSprite()), this);
}
-inline const Pokescripting::SkinWrapper* SpeciesWrapper::skin() const
+inline Pokescripting::SkinWrapper* SpeciesWrapper::skin()
{
- return new SkinWrapper(pokemod()->skinById(m_species->skin()), const_cast<SpeciesWrapper*>(this));
+ return SkinWrapper::create(pokemod()->skinById(m_species->skin()), this);
}
inline Pokemod::Fraction SpeciesWrapper::genderFactor() const
@@ -197,9 +203,9 @@ inline bool SpeciesWrapper::eggGroup(const int eggGroup) const
return m_species->eggGroup(eggGroup);
}
-inline const SpeciesAbilityWrapper* SpeciesWrapper::ability(const int index) const
+inline SpeciesAbilityWrapper* SpeciesWrapper::ability(const int index)
{
- return new SpeciesAbilityWrapper(m_species->ability(index), const_cast<SpeciesWrapper*>(this));
+ return SpeciesAbilityWrapper::create(m_species->ability(index), this);
}
inline int SpeciesWrapper::abilityCount() const
@@ -207,9 +213,9 @@ inline int SpeciesWrapper::abilityCount() const
return m_species->abilityCount();
}
-inline const SpeciesItemWrapper* SpeciesWrapper::item(const int index) const
+inline SpeciesItemWrapper* SpeciesWrapper::item(const int index)
{
- return new SpeciesItemWrapper(m_species->item(index), const_cast<SpeciesWrapper*>(this));
+ return SpeciesItemWrapper::create(m_species->item(index), this);
}
inline int SpeciesWrapper::itemCount() const
@@ -217,9 +223,9 @@ inline int SpeciesWrapper::itemCount() const
return m_species->itemCount();
}
-inline const SpeciesMoveWrapper* SpeciesWrapper::move(const int index) const
+inline SpeciesMoveWrapper* SpeciesWrapper::move(const int index)
{
- return new SpeciesMoveWrapper(m_species->move(index), const_cast<SpeciesWrapper*>(this));
+ return SpeciesMoveWrapper::create(m_species->move(index), this);
}
inline int SpeciesWrapper::moveCount() const
diff --git a/pokescripting/SpriteWrapper.h b/pokescripting/SpriteWrapper.h
index 3e94e836..b0b73cf2 100644
--- a/pokescripting/SpriteWrapper.h
+++ b/pokescripting/SpriteWrapper.h
@@ -31,11 +31,17 @@ class POKESCRIPTING_EXPORT SpriteWrapper : public ObjectWrapper
Q_OBJECT
public:
- SpriteWrapper(const Pokemod::Sprite* sprite, QObject* parent);
+ static SpriteWrapper* create(const Pokemod::Sprite* sprite, QObject* parent)
+ {
+ if (!m_instances.contains(sprite->id()))
+ m_instances[sprite->id()] = new SpriteWrapper(sprite, parent);
+ return qobject_cast<SpriteWrapper*>(m_instances[sprite->id()]);
+ }
public slots:
QString name() const;
QPixmap sprite() const;
private:
+ SpriteWrapper(const Pokemod::Sprite* sprite, QObject* parent);
SpriteWrapper& operator=(const SpriteWrapper& rhs);
const Pokemod::Sprite* m_sprite;
diff --git a/pokescripting/StatusWrapper.h b/pokescripting/StatusWrapper.h
index e2a77318..d207354b 100644
--- a/pokescripting/StatusWrapper.h
+++ b/pokescripting/StatusWrapper.h
@@ -31,10 +31,16 @@ class POKESCRIPTING_EXPORT StatusWrapper : public ObjectWrapper
Q_OBJECT
public:
- StatusWrapper(const Pokemod::Status* status, QObject* parent);
+ static StatusWrapper* create(const Pokemod::Status* status, QObject* parent)
+ {
+ if (!m_instances.contains(status->id()))
+ m_instances[status->id()] = new StatusWrapper(status, parent);
+ return qobject_cast<StatusWrapper*>(m_instances[status->id()]);
+ }
public slots:
QString name() const;
private:
+ StatusWrapper(const Pokemod::Status* status, QObject* parent);
StatusWrapper& operator=(const StatusWrapper& rhs);
const Pokemod::Status* m_status;
diff --git a/pokescripting/StoreWrapper.h b/pokescripting/StoreWrapper.h
index cadc527b..09132982 100644
--- a/pokescripting/StoreWrapper.h
+++ b/pokescripting/StoreWrapper.h
@@ -31,11 +31,17 @@ class POKESCRIPTING_EXPORT StoreWrapper : public ObjectWrapper
Q_OBJECT
public:
- StoreWrapper(const Pokemod::Store* store, QObject* parent);
+ static StoreWrapper* create(const Pokemod::Store* store, QObject* parent)
+ {
+ if (!m_instances.contains(store->id()))
+ m_instances[store->id()] = new StoreWrapper(store, parent);
+ return qobject_cast<StoreWrapper*>(m_instances[store->id()]);
+ }
public slots:
QString name() const;
bool item(const int item) const;
private:
+ StoreWrapper(const Pokemod::Store* store, QObject* parent);
StoreWrapper& operator=(const StoreWrapper& rhs);
const Pokemod::Store* m_store;
diff --git a/pokescripting/TODO b/pokescripting/TODO
index eafd89bb..984b29fb 100644
--- a/pokescripting/TODO
+++ b/pokescripting/TODO
@@ -1 +1 @@
-Make it a mirror (dont create another Wrapper instance if one has already been created)
+Add script getters to wrappers
diff --git a/pokescripting/TileWrapper.h b/pokescripting/TileWrapper.h
index babc304e..0bf72ed2 100644
--- a/pokescripting/TileWrapper.h
+++ b/pokescripting/TileWrapper.h
@@ -32,12 +32,18 @@ class POKESCRIPTING_EXPORT TileWrapper : public ObjectWrapper
Q_OBJECT
public:
- TileWrapper(const Pokemod::Tile* tile, QObject* parent);
+ static TileWrapper* create(const Pokemod::Tile* tile, QObject* parent)
+ {
+ if (!m_instances.contains(tile->id()))
+ m_instances[tile->id()] = new TileWrapper(tile, parent);
+ return qobject_cast<TileWrapper*>(m_instances[tile->id()]);
+ }
public slots:
QString name() const;
- const SpriteWrapper* sprite() const;
+ SpriteWrapper* sprite();
bool from(const int direction) const;
private:
+ TileWrapper(const Pokemod::Tile* tile, QObject* parent);
TileWrapper& operator=(const TileWrapper& rhs);
const Pokemod::Tile* m_tile;
@@ -54,9 +60,9 @@ inline QString TileWrapper::name() const
return m_tile->name();
}
-inline const Pokescripting::SpriteWrapper* TileWrapper::sprite() const
+inline Pokescripting::SpriteWrapper* TileWrapper::sprite()
{
- return new SpriteWrapper(pokemod()->spriteById(m_tile->sprite()), const_cast<TileWrapper*>(this));
+ return SpriteWrapper::create(pokemod()->spriteById(m_tile->sprite()), this);
}
inline bool TileWrapper::from(const int direction) const
diff --git a/pokescripting/TimeWrapper.h b/pokescripting/TimeWrapper.h
index f82aa229..b8ae979f 100644
--- a/pokescripting/TimeWrapper.h
+++ b/pokescripting/TimeWrapper.h
@@ -31,12 +31,18 @@ class POKESCRIPTING_EXPORT TimeWrapper : public ObjectWrapper
Q_OBJECT
public:
- TimeWrapper(const Pokemod::Time* time, QObject* parent);
+ static TimeWrapper* create(const Pokemod::Time* time, QObject* parent)
+ {
+ if (!m_instances.contains(time->id()))
+ m_instances[time->id()] = new TimeWrapper(time, parent);
+ return qobject_cast<TimeWrapper*>(m_instances[time->id()]);
+ }
public slots:
QString name() const;
int hour() const;
int minute() const;
private:
+ TimeWrapper(const Pokemod::Time* time, QObject* parent);
TimeWrapper& operator=(const TimeWrapper& rhs);
const Pokemod::Time* m_time;
diff --git a/pokescripting/TrainerWrapper.h b/pokescripting/TrainerWrapper.h
index 963e153f..ba24d105 100644
--- a/pokescripting/TrainerWrapper.h
+++ b/pokescripting/TrainerWrapper.h
@@ -32,11 +32,16 @@ class POKESCRIPTING_EXPORT TrainerWrapper : public ObjectWrapper
Q_OBJECT
public:
- TrainerWrapper(const Pokemod::Trainer* trainer, QObject* parent);
+ static TrainerWrapper* create(const Pokemod::Trainer* trainer, QObject* parent)
+ {
+ if (!m_instances.contains(trainer->id()))
+ m_instances[trainer->id()] = new TrainerWrapper(trainer, parent);
+ return qobject_cast<TrainerWrapper*>(m_instances[trainer->id()]);
+ }
public slots:
QString name() const;
int moneyFactor() const;
- const SkinWrapper* skin() const;
+ SkinWrapper* skin();
int depth() const;
int teamIntel() const;
int moveIntel() const;
@@ -44,6 +49,7 @@ class POKESCRIPTING_EXPORT TrainerWrapper : public ObjectWrapper
int abilityIntel() const;
int statIntel() const;
private:
+ TrainerWrapper(const Pokemod::Trainer* trainer, QObject* parent);
TrainerWrapper& operator=(const TrainerWrapper& rhs);
const Pokemod::Trainer* m_trainer;
@@ -65,9 +71,9 @@ inline int TrainerWrapper::TrainerWrapper::moneyFactor() const
return m_trainer->moneyFactor();
}
-inline const Pokescripting::SkinWrapper* TrainerWrapper::TrainerWrapper::skin() const
+inline Pokescripting::SkinWrapper* TrainerWrapper::TrainerWrapper::skin()
{
- return new SkinWrapper(pokemod()->skinById(m_trainer->skin()), const_cast<TrainerWrapper*>(this));
+ return SkinWrapper::create(pokemod()->skinById(m_trainer->skin()), this);
}
inline int TrainerWrapper::TrainerWrapper::depth() const
diff --git a/pokescripting/TypeWrapper.h b/pokescripting/TypeWrapper.h
index 9c4eb730..1c44c11b 100644
--- a/pokescripting/TypeWrapper.h
+++ b/pokescripting/TypeWrapper.h
@@ -31,11 +31,17 @@ class POKESCRIPTING_EXPORT TypeWrapper : public ObjectWrapper
Q_OBJECT
public:
- TypeWrapper(const Pokemod::Type* type, QObject* parent);
+ static TypeWrapper* create(const Pokemod::Type* type, QObject* parent)
+ {
+ if (!m_instances.contains(type->id()))
+ m_instances[type->id()] = new TypeWrapper(type, parent);
+ return qobject_cast<TypeWrapper*>(m_instances[type->id()]);
+ }
public slots:
QString name() const;
Pokemod::Fraction stab() const;
private:
+ TypeWrapper(const Pokemod::Type* type, QObject* parent);
TypeWrapper& operator=(const TypeWrapper& rhs);
const Pokemod::Type* m_type;
diff --git a/pokescripting/WeatherWrapper.h b/pokescripting/WeatherWrapper.h
index 6de468fe..29b11740 100644
--- a/pokescripting/WeatherWrapper.h
+++ b/pokescripting/WeatherWrapper.h
@@ -31,10 +31,16 @@ class POKESCRIPTING_EXPORT WeatherWrapper : public ObjectWrapper
Q_OBJECT
public:
- WeatherWrapper(const Pokemod::Weather* weather, QObject* parent);
+ static WeatherWrapper* create(const Pokemod::Weather* weather, QObject* parent)
+ {
+ if (!m_instances.contains(weather->id()))
+ m_instances[weather->id()] = new WeatherWrapper(weather, parent);
+ return qobject_cast<WeatherWrapper*>(m_instances[weather->id()]);
+ }
public slots:
QString name() const;
private:
+ WeatherWrapper(const Pokemod::Weather* weather, QObject* parent);
WeatherWrapper& operator=(const WeatherWrapper& rhs);
const Pokemod::Weather* m_weather;