-/*
- * Caster.cpp
- *
- * Created on: Sep 19, 2012
- * Author: holy
- */
-
#include "Caster.h"
+#include "Interpreter.h"
+#include "Loader.h"
#include "TypeDescription.h"
+#include "../battle/Resources.h"
+#include "../battle/Monster.h"
+#include "../battle/PartyLayout.h"
+#include "../common/Capsule.h"
+#include "../common/Hero.h"
+#include "../common/Item.h"
+#include "../common/Spell.h"
+#include "../map/Map.h"
+#include "../menu/Resources.h"
-using battle::Hero;
using battle::Monster;
using battle::PartyLayout;
+using common::Capsule;
+using common::Hero;
using common::Item;
using common::Spell;
+using map::Map;
using std::string;
namespace loader {
-Caster::Caster(Interpreter &intp)
-: intp(intp)
-, battleResourcesId(TypeDescription::GetTypeId("BattleResources"))
-, heroId(TypeDescription::GetTypeId("Hero"))
-, itemId(TypeDescription::GetTypeId("Item"))
-, monsterId(TypeDescription::GetTypeId("Monster"))
-, partyLayoutId(TypeDescription::GetTypeId("PartyLayout"))
-, spellId(TypeDescription::GetTypeId("Spell")) {
+Caster::Caster(Loader &ld, Interpreter &intp)
+: ld(ld)
+, intp(intp) {
}
battle::Resources *Caster::GetBattleResources(const string &ident) {
- return reinterpret_cast<battle::Resources *>(intp.GetObject(battleResourcesId, ident));
+ return reinterpret_cast<battle::Resources *>(
+ GetObject(battle::Resources::TYPE_ID, ident));
+}
+
+Capsule *Caster::GetCapsule(const string &ident) {
+ return reinterpret_cast<Capsule *>(
+ GetObject(Capsule::TYPE_ID, ident));
}
Hero *Caster::GetHero(const string &ident) {
- return reinterpret_cast<Hero *>(intp.GetObject(heroId, ident));
+ return reinterpret_cast<Hero *>(
+ GetObject(Hero::TYPE_ID, ident));
}
Item *Caster::GetItem(const string &ident) {
- return reinterpret_cast<Item *>(intp.GetObject(itemId, ident));
+ return reinterpret_cast<Item *>(
+ GetObject(Item::TYPE_ID, ident));
+}
+
+Map *Caster::GetMap(const string &ident) {
+ return reinterpret_cast<Map *>(
+ GetObject(Map::TYPE_ID, ident));
+}
+
+menu::Resources *Caster::GetMenuResources(const string &ident) {
+ return reinterpret_cast<menu::Resources *>(
+ GetObject(menu::Resources::TYPE_ID, ident));
}
Monster *Caster::GetMonster(const string &ident) {
- return reinterpret_cast<Monster *>(intp.GetObject(monsterId, ident));
+ return reinterpret_cast<Monster *>(
+ GetObject(Monster::TYPE_ID, ident));
}
PartyLayout *Caster::GetPartyLayout(const string &ident) {
- return reinterpret_cast<PartyLayout *>(intp.GetObject(partyLayoutId, ident));
+ return reinterpret_cast<PartyLayout *>(
+ GetObject(PartyLayout::TYPE_ID, ident));
}
Spell *Caster::GetSpell(const string &ident) {
- return reinterpret_cast<Spell *>(intp.GetObject(spellId, ident));
+ return reinterpret_cast<Spell *>(
+ GetObject(Spell::TYPE_ID, ident));
+}
+
+
+void *Caster::GetObject(int typeId, const string &ident) {
+ std::map<string, LoadedExport>::const_iterator i(
+ ld.Exports().find(ident));
+ if (i != ld.Exports().end()) {
+ if (i->second.typeId != typeId) {
+ throw std::runtime_error("mismatched type for "
+ + ident);
+ } else {
+ return i->second.location;
+ }
+ }
+ return intp.GetObject(typeId, ident);
}
}