#include "Monster.h"
+#include "../common/Stats.h"
+#include "../graphics/Animation.h"
+#include "../graphics/Sprite.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
+using common::Stats;
+using graphics::Animation;
+using graphics::Sprite;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace battle {
void Monster::CreateTypeDescription() {
Monster m;
- int animationId(TypeDescription::GetTypeId("Animation"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
- int statsId(TypeDescription::GetTypeId("Stats"));
- int stringId(TypeDescription::GetTypeId("String"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Monster"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Monster"));
td.SetDescription("All data of a monster.");
td.SetConstructor(&Construct);
td.SetSize(sizeof(Monster));
- td.AddField("name", FieldDescription(((char *)&m.name) - ((char *)&m), stringId).SetReferenced());
- td.AddField("sprite", FieldDescription(((char *)&m.sprite) - ((char *)&m), spriteId).SetReferenced());
- td.AddField("level", FieldDescription(((char *)&m.level) - ((char *)&m), numberId));
+ td.AddField("name", FieldDescription(((char *)&m.name) - ((char *)&m), Interpreter::STRING_ID).SetReferenced());
+ td.AddField("sprite", FieldDescription(((char *)&m.sprite) - ((char *)&m), Sprite::TYPE_ID).SetReferenced());
+ td.AddField("level", FieldDescription(((char *)&m.level) - ((char *)&m), Interpreter::NUMBER_ID));
- td.AddField("maxHealth", FieldDescription(((char *)&m.maxHealth) - ((char *)&m), numberId));
- td.AddField("health", FieldDescription(((char *)&m.health) - ((char *)&m), numberId));
- td.AddField("maxMana", FieldDescription(((char *)&m.maxMana) - ((char *)&m), numberId));
- td.AddField("mana", FieldDescription(((char *)&m.mana) - ((char *)&m), numberId));
- td.AddField("stats", FieldDescription(((char *)&m.stats) - ((char *)&m), statsId));
+ td.AddField("maxHealth", FieldDescription(((char *)&m.maxHealth) - ((char *)&m), Interpreter::NUMBER_ID));
+ td.AddField("health", FieldDescription(((char *)&m.health) - ((char *)&m), Interpreter::NUMBER_ID));
+ td.AddField("maxMana", FieldDescription(((char *)&m.maxMana) - ((char *)&m), Interpreter::NUMBER_ID));
+ td.AddField("mana", FieldDescription(((char *)&m.mana) - ((char *)&m), Interpreter::NUMBER_ID));
+ td.AddField("stats", FieldDescription(((char *)&m.stats) - ((char *)&m), Stats::TYPE_ID));
- td.AddField("attackAnimation", FieldDescription(((char *)&m.attackAnimation) - ((char *)&m), animationId).SetReferenced());
- td.AddField("spellAnimation", FieldDescription(((char *)&m.spellAnimation) - ((char *)&m), animationId).SetReferenced());
- td.AddField("meleeAnimation", FieldDescription(((char *)&m.meleeAnimation) - ((char *)&m), animationId).SetReferenced());
+ td.AddField("attackAnimation", FieldDescription(((char *)&m.attackAnimation) - ((char *)&m), Animation::TYPE_ID).SetReferenced());
+ td.AddField("spellAnimation", FieldDescription(((char *)&m.spellAnimation) - ((char *)&m), Animation::TYPE_ID).SetReferenced());
+ td.AddField("meleeAnimation", FieldDescription(((char *)&m.meleeAnimation) - ((char *)&m), Animation::TYPE_ID).SetReferenced());
}
void Monster::Construct(void *data) {
class Monster {
+public:
+ static const int TYPE_ID = 202;
+
public:
Monster();
~Monster();
#include "PartyLayout.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using geometry::Vector;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
using std::vector;
void PartyLayout::CreateTypeDescription() {
PartyLayout p;
- int vectorId(TypeDescription::GetTypeId("Vector"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("PartyLayout"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "PartyLayout"));
td.SetDescription("Positions of party members");
td.SetConstructor(&Construct);
td.SetSize(sizeof(PartyLayout));
- td.AddField("positions", FieldDescription(((char *)&p.positions) - ((char *)&p), vectorId).SetReferenced().SetAggregate().SetDescription("the members' positions"));
+ td.AddField("positions", FieldDescription(((char *)&p.positions) - ((char *)&p), Interpreter::VECTOR_ID).SetReferenced().SetAggregate().SetDescription("the members' positions"));
}
void PartyLayout::Construct(void *data) {
class PartyLayout {
+ public:
+ static const int TYPE_ID = 203;
+
public:
PartyLayout() : positions(0), numPositions(0) { }
#include "Resources.h"
+#include "../graphics/Animation.h"
+#include "../graphics/Font.h"
+#include "../graphics/Frame.h"
+#include "../graphics/Gauge.h"
+#include "../graphics/Menu.h"
+#include "../graphics/Sprite.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
+using graphics::Animation;
+using graphics::Font;
+using graphics::Frame;
+using graphics::Gauge;
+using graphics::MenuProperties;
+using graphics::Sprite;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace battle {
void Resources::CreateTypeDescription() {
Resources r;
- int animationId(TypeDescription::GetTypeId("Animation"));
- int colorId(TypeDescription::GetTypeId("Color"));
- int fontId(TypeDescription::GetTypeId("Font"));
- int frameId(TypeDescription::GetTypeId("Frame"));
- int gaugeId(TypeDescription::GetTypeId("Gauge"));
- int menuPropertiesId(TypeDescription::GetTypeId("MenuProperties"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
- int stringId(TypeDescription::GetTypeId("String"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("BattleResources"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "BattleResources"));
td.SetConstructor(&Construct);
td.SetSize(sizeof(Resources));
- td.AddField("swapCursor", FieldDescription(((char *)&r.swapCursor) - ((char *)&r), spriteId).SetReferenced().SetDescription("the cursor sprite for swapping heroes"));
- td.AddField("moveIcons", FieldDescription(((char *)&r.moveIcons) - ((char *)&r), spriteId).SetReferenced().SetDescription("the icons of the move selection menu"));
- td.AddField("attackIcons", FieldDescription(((char *)&r.attackIcons) - ((char *)&r), spriteId).SetReferenced().SetDescription("the icons of the attack selection menu"));
- td.AddField("attackChoiceIcons", FieldDescription(((char *)&r.attackChoiceIcons) - ((char *)&r), spriteId).SetReferenced().SetDescription("the icons showing the hero's attack choice in the respective tag"));
+ td.AddField("swapCursor", FieldDescription(((char *)&r.swapCursor) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("the cursor sprite for swapping heroes"));
+ td.AddField("moveIcons", FieldDescription(((char *)&r.moveIcons) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("the icons of the move selection menu"));
+ td.AddField("attackIcons", FieldDescription(((char *)&r.attackIcons) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("the icons of the attack selection menu"));
+ td.AddField("attackChoiceIcons", FieldDescription(((char *)&r.attackChoiceIcons) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("the icons showing the hero's attack choice in the respective tag"));
- td.AddField("titleFrame", FieldDescription(((char *)&r.titleFrame) - ((char *)&r), frameId).SetReferenced().SetDescription("frame for title headings (spell names, status information, etc.)"));
- td.AddField("titleFont", FieldDescription(((char *)&r.titleFont) - ((char *)&r), fontId).SetReferenced().SetDescription("the font for title headings"));
+ td.AddField("titleFrame", FieldDescription(((char *)&r.titleFrame) - ((char *)&r), Frame::TYPE_ID).SetReferenced().SetDescription("frame for title headings (spell names, status information, etc.)"));
+ td.AddField("titleFont", FieldDescription(((char *)&r.titleFont) - ((char *)&r), Font::TYPE_ID).SetReferenced().SetDescription("the font for title headings"));
- td.AddField("heroTagFrame", FieldDescription(((char *)&r.heroTagFrame) - ((char *)&r), frameId).SetReferenced().SetDescription("frame for hero tags"));
- td.AddField("activeHeroTagFrame", FieldDescription(((char *)&r.activeHeroTagFrame) - ((char *)&r), frameId).SetReferenced().SetDescription("frame for the active hero's tag"));
- td.AddField("smallHeroTagFrame", FieldDescription(((char *)&r.smallHeroTagFrame) - ((char *)&r), frameId).SetReferenced().SetDescription("frame for small hero tags (during attack animation)"));
- td.AddField("lastSmallHeroTagFrame", FieldDescription(((char *)&r.lastSmallHeroTagFrame) - ((char *)&r), frameId).SetReferenced().SetDescription("frame for the last small hero tag"));
+ td.AddField("heroTagFrame", FieldDescription(((char *)&r.heroTagFrame) - ((char *)&r), Frame::TYPE_ID).SetReferenced().SetDescription("frame for hero tags"));
+ td.AddField("activeHeroTagFrame", FieldDescription(((char *)&r.activeHeroTagFrame) - ((char *)&r), Frame::TYPE_ID).SetReferenced().SetDescription("frame for the active hero's tag"));
+ td.AddField("smallHeroTagFrame", FieldDescription(((char *)&r.smallHeroTagFrame) - ((char *)&r), Frame::TYPE_ID).SetReferenced().SetDescription("frame for small hero tags (during attack animation)"));
+ td.AddField("lastSmallHeroTagFrame", FieldDescription(((char *)&r.lastSmallHeroTagFrame) - ((char *)&r), Frame::TYPE_ID).SetReferenced().SetDescription("frame for the last small hero tag"));
- td.AddField("heroTagFont", FieldDescription(((char *)&r.heroTagFont) - ((char *)&r), fontId).SetReferenced().SetDescription("font for hero tags (hero names)"));
- td.AddField("heroTagLabels", FieldDescription(((char *)&r.heroTagLabels) - ((char *)&r), spriteId).SetReferenced().SetDescription("labels on the hero tag (hp/mp/ip/lvl/move)"));
+ td.AddField("heroTagFont", FieldDescription(((char *)&r.heroTagFont) - ((char *)&r), Font::TYPE_ID).SetReferenced().SetDescription("font for hero tags (hero names)"));
+ td.AddField("heroTagLabels", FieldDescription(((char *)&r.heroTagLabels) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("labels on the hero tag (hp/mp/ip/lvl/move)"));
- td.AddField("healthGauge", FieldDescription(((char *)&r.healthGauge) - ((char *)&r), gaugeId).SetReferenced().SetDescription("health gauge"));
- td.AddField("manaGauge", FieldDescription(((char *)&r.manaGauge) - ((char *)&r), gaugeId).SetReferenced().SetDescription("mana gauge"));
- td.AddField("ikariGauge", FieldDescription(((char *)&r.ikariGauge) - ((char *)&r), gaugeId).SetReferenced().SetDescription("ikari gauge"));
+ td.AddField("healthGauge", FieldDescription(((char *)&r.healthGauge) - ((char *)&r), Gauge::TYPE_ID).SetReferenced().SetDescription("health gauge"));
+ td.AddField("manaGauge", FieldDescription(((char *)&r.manaGauge) - ((char *)&r), Gauge::TYPE_ID).SetReferenced().SetDescription("mana gauge"));
+ td.AddField("ikariGauge", FieldDescription(((char *)&r.ikariGauge) - ((char *)&r), Gauge::TYPE_ID).SetReferenced().SetDescription("ikari gauge"));
- td.AddField("selectFrame", FieldDescription(((char *)&r.selectFrame) - ((char *)&r), frameId).SetReferenced().SetDescription("frame for spell, item, and ikari menus"));
+ td.AddField("selectFrame", FieldDescription(((char *)&r.selectFrame) - ((char *)&r), Frame::TYPE_ID).SetReferenced().SetDescription("frame for spell, item, and ikari menus"));
- td.AddField("normalFont", FieldDescription(((char *)&r.normalFont) - ((char *)&r), fontId).SetReferenced().SetDescription("font for menus"));
- td.AddField("disabledFont", FieldDescription(((char *)&r.disabledFont) - ((char *)&r), fontId).SetReferenced().SetDescription("font for disabled entries in menus"));
+ td.AddField("normalFont", FieldDescription(((char *)&r.normalFont) - ((char *)&r), Font::TYPE_ID).SetReferenced().SetDescription("font for menus"));
+ td.AddField("disabledFont", FieldDescription(((char *)&r.disabledFont) - ((char *)&r), Font::TYPE_ID).SetReferenced().SetDescription("font for disabled entries in menus"));
- td.AddField("menuCursor", FieldDescription(((char *)&r.menuCursor) - ((char *)&r), spriteId).SetReferenced().SetDescription("selection indicator for menus"));
- td.AddField("weaponTargetCursor", FieldDescription(((char *)&r.weaponTargetCursor) - ((char *)&r), spriteId).SetReferenced().SetDescription("cursor for selectiong attack targets"));
- td.AddField("magicTargetCursor", FieldDescription(((char *)&r.magicTargetCursor) - ((char *)&r), spriteId).SetReferenced().SetDescription("cursor for selectiong spell targets"));
- td.AddField("itemTargetCursor", FieldDescription(((char *)&r.itemTargetCursor) - ((char *)&r), spriteId).SetReferenced().SetDescription("cursor for selectiong item targets"));
+ td.AddField("menuCursor", FieldDescription(((char *)&r.menuCursor) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("selection indicator for menus"));
+ td.AddField("weaponTargetCursor", FieldDescription(((char *)&r.weaponTargetCursor) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("cursor for selectiong attack targets"));
+ td.AddField("magicTargetCursor", FieldDescription(((char *)&r.magicTargetCursor) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("cursor for selectiong spell targets"));
+ td.AddField("itemTargetCursor", FieldDescription(((char *)&r.itemTargetCursor) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("cursor for selectiong item targets"));
- td.AddField("spellMenuHeadline", FieldDescription(((char *)&r.spellMenuHeadline) - ((char *)&r), stringId).SetReferenced().SetDescription("headline of the spell menu"));
- td.AddField("spellMenuProperties", FieldDescription(((char *)&r.spellMenuProperties) - ((char *)&r), menuPropertiesId).SetReferenced().SetDescription("properties of the spell menu"));
+ td.AddField("spellMenuHeadline", FieldDescription(((char *)&r.spellMenuHeadline) - ((char *)&r), Interpreter::STRING_ID).SetReferenced().SetDescription("headline of the spell menu"));
+ td.AddField("spellMenuProperties", FieldDescription(((char *)&r.spellMenuProperties) - ((char *)&r), MenuProperties::TYPE_ID).SetReferenced().SetDescription("properties of the spell menu"));
- td.AddField("itemMenuHeadline", FieldDescription(((char *)&r.itemMenuHeadline) - ((char *)&r), stringId).SetReferenced().SetDescription("headline of the item menu"));
- td.AddField("itemMenuProperties", FieldDescription(((char *)&r.itemMenuProperties) - ((char *)&r), menuPropertiesId).SetReferenced().SetDescription("properties of the item menu"));
+ td.AddField("itemMenuHeadline", FieldDescription(((char *)&r.itemMenuHeadline) - ((char *)&r), Interpreter::STRING_ID).SetReferenced().SetDescription("headline of the item menu"));
+ td.AddField("itemMenuProperties", FieldDescription(((char *)&r.itemMenuProperties) - ((char *)&r), MenuProperties::TYPE_ID).SetReferenced().SetDescription("properties of the item menu"));
- td.AddField("ikariMenuHeadline", FieldDescription(((char *)&r.ikariMenuHeadline) - ((char *)&r), stringId).SetReferenced().SetDescription("headline of the ikari menu"));
- td.AddField("ikariMenuProperties", FieldDescription(((char *)&r.ikariMenuProperties) - ((char *)&r), menuPropertiesId).SetReferenced().SetDescription("properties of the ikari menu"));
- td.AddField("noEquipmentText", FieldDescription(((char *)&r.noEquipmentText) - ((char *)&r), stringId).SetReferenced().SetDescription("text to show for missing equipment"));
+ td.AddField("ikariMenuHeadline", FieldDescription(((char *)&r.ikariMenuHeadline) - ((char *)&r), Interpreter::STRING_ID).SetReferenced().SetDescription("headline of the ikari menu"));
+ td.AddField("ikariMenuProperties", FieldDescription(((char *)&r.ikariMenuProperties) - ((char *)&r), MenuProperties::TYPE_ID).SetReferenced().SetDescription("properties of the ikari menu"));
+ td.AddField("noEquipmentText", FieldDescription(((char *)&r.noEquipmentText) - ((char *)&r), Interpreter::STRING_ID).SetReferenced().SetDescription("text to show for missing equipment"));
- td.AddField("escapeText", FieldDescription(((char *)&r.escapeText) - ((char *)&r), stringId).SetReferenced().SetDescription("displayed when the party escapes"));
+ td.AddField("escapeText", FieldDescription(((char *)&r.escapeText) - ((char *)&r), Interpreter::STRING_ID).SetReferenced().SetDescription("displayed when the party escapes"));
- td.AddField("numberAnimationPrototype", FieldDescription(((char *)&r.numberAnimationPrototype) - ((char *)&r), animationId).SetReferenced().SetDescription("animation of an attack's result digit"));
+ td.AddField("numberAnimationPrototype", FieldDescription(((char *)&r.numberAnimationPrototype) - ((char *)&r), Animation::TYPE_ID).SetReferenced().SetDescription("animation of an attack's result digit"));
- td.AddField("bigNumberSprite", FieldDescription(((char *)&r.bigNumberSprite) - ((char *)&r), spriteId).SetReferenced().SetDescription("sprite containing the damage numbers"));
- td.AddField("greenNumberSprite", FieldDescription(((char *)&r.greenNumberSprite) - ((char *)&r), spriteId).SetReferenced().SetDescription("sprite containing the healing numbers"));
+ td.AddField("bigNumberSprite", FieldDescription(((char *)&r.bigNumberSprite) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("sprite containing the damage numbers"));
+ td.AddField("greenNumberSprite", FieldDescription(((char *)&r.greenNumberSprite) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("sprite containing the healing numbers"));
- td.AddField("weaponMenuIcon", FieldDescription(((char *)&r.weaponMenuIcon) - ((char *)&r), spriteId).SetReferenced().SetDescription("weapon icon for ikari menu"));
- td.AddField("armorMenuIcon", FieldDescription(((char *)&r.armorMenuIcon) - ((char *)&r), spriteId).SetReferenced().SetDescription("armor icon for ikari menu"));
- td.AddField("shieldMenuIcon", FieldDescription(((char *)&r.shieldMenuIcon) - ((char *)&r), spriteId).SetReferenced().SetDescription("shield icon for ikari menu"));
- td.AddField("helmetMenuIcon", FieldDescription(((char *)&r.helmetMenuIcon) - ((char *)&r), spriteId).SetReferenced().SetDescription("helmet icon for ikari menu"));
- td.AddField("ringMenuIcon", FieldDescription(((char *)&r.ringMenuIcon) - ((char *)&r), spriteId).SetReferenced().SetDescription("ring icon for ikari menu"));
- td.AddField("jewelMenuIcon", FieldDescription(((char *)&r.jewelMenuIcon) - ((char *)&r), spriteId).SetReferenced().SetDescription("jewel icon for ikari menu"));
+ td.AddField("weaponMenuIcon", FieldDescription(((char *)&r.weaponMenuIcon) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("weapon icon for ikari menu"));
+ td.AddField("armorMenuIcon", FieldDescription(((char *)&r.armorMenuIcon) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("armor icon for ikari menu"));
+ td.AddField("shieldMenuIcon", FieldDescription(((char *)&r.shieldMenuIcon) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("shield icon for ikari menu"));
+ td.AddField("helmetMenuIcon", FieldDescription(((char *)&r.helmetMenuIcon) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("helmet icon for ikari menu"));
+ td.AddField("ringMenuIcon", FieldDescription(((char *)&r.ringMenuIcon) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("ring icon for ikari menu"));
+ td.AddField("jewelMenuIcon", FieldDescription(((char *)&r.jewelMenuIcon) - ((char *)&r), Sprite::TYPE_ID).SetReferenced().SetDescription("jewel icon for ikari menu"));
- td.AddField("levelLabelRow", FieldDescription(((char *)&r.levelLabelRow) - ((char *)&r), numberId).SetDescription("column of the level label in heroTagLabels"));
- td.AddField("levelLabelCol", FieldDescription(((char *)&r.levelLabelCol) - ((char *)&r), numberId).SetDescription("row of the level label in heroTagLabels"));
- td.AddField("healthLabelRow", FieldDescription(((char *)&r.healthLabelRow) - ((char *)&r), numberId).SetDescription("column of the health label in heroTagLabels"));
- td.AddField("healthLabelCol", FieldDescription(((char *)&r.healthLabelCol) - ((char *)&r), numberId).SetDescription("row of the health label in heroTagLabels"));
- td.AddField("manaLabelRow", FieldDescription(((char *)&r.manaLabelRow) - ((char *)&r), numberId).SetDescription("column of the mana label in heroTagLabels"));
- td.AddField("manaLabelCol", FieldDescription(((char *)&r.manaLabelCol) - ((char *)&r), numberId).SetDescription("row of the mana label in heroTagLabels"));
- td.AddField("moveLabelRow", FieldDescription(((char *)&r.moveLabelRow) - ((char *)&r), numberId).SetDescription("column of the move label in heroTagLabels"));
- td.AddField("moveLabelCol", FieldDescription(((char *)&r.moveLabelCol) - ((char *)&r), numberId).SetDescription("row of the move label in heroTagLabels"));
- td.AddField("ikariLabelRow", FieldDescription(((char *)&r.ikariLabelRow) - ((char *)&r), numberId).SetDescription("column of the ikari label in heroTagLabels"));
- td.AddField("ikariLabelCol", FieldDescription(((char *)&r.ikariLabelCol) - ((char *)&r), numberId).SetDescription("row of the ikari label in heroTagLabels"));
+ td.AddField("levelLabelRow", FieldDescription(((char *)&r.levelLabelRow) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("column of the level label in heroTagLabels"));
+ td.AddField("levelLabelCol", FieldDescription(((char *)&r.levelLabelCol) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("row of the level label in heroTagLabels"));
+ td.AddField("healthLabelRow", FieldDescription(((char *)&r.healthLabelRow) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("column of the health label in heroTagLabels"));
+ td.AddField("healthLabelCol", FieldDescription(((char *)&r.healthLabelCol) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("row of the health label in heroTagLabels"));
+ td.AddField("manaLabelRow", FieldDescription(((char *)&r.manaLabelRow) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("column of the mana label in heroTagLabels"));
+ td.AddField("manaLabelCol", FieldDescription(((char *)&r.manaLabelCol) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("row of the mana label in heroTagLabels"));
+ td.AddField("moveLabelRow", FieldDescription(((char *)&r.moveLabelRow) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("column of the move label in heroTagLabels"));
+ td.AddField("moveLabelCol", FieldDescription(((char *)&r.moveLabelCol) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("row of the move label in heroTagLabels"));
+ td.AddField("ikariLabelRow", FieldDescription(((char *)&r.ikariLabelRow) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("column of the ikari label in heroTagLabels"));
+ td.AddField("ikariLabelCol", FieldDescription(((char *)&r.ikariLabelCol) - ((char *)&r), Interpreter::NUMBER_ID).SetDescription("row of the ikari label in heroTagLabels"));
- td.AddField("heroesBgColor", FieldDescription(((char *)&r.heroesBgColor) - ((char *)&r), colorId).SetDescription("background color of the small tags during attack animation"));
+ td.AddField("heroesBgColor", FieldDescription(((char *)&r.heroesBgColor) - ((char *)&r), Interpreter::COLOR_ID).SetDescription("background color of the small tags during attack animation"));
}
void Resources::Construct(void *data) {
struct Resources {
+ static const int TYPE_ID = 201;
+
graphics::Sprite *swapCursor;
graphics::Sprite *moveIcons;
graphics::Sprite *attackIcons;
#include "Hero.h"
+#include "../graphics/Animation.h"
+#include "../graphics/Sprite.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
+#include "../map/Entity.h"
+using graphics::Animation;
+using graphics::Sprite;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
+using map::Entity;
namespace common {
void Hero::CreateTypeDescription() {
Hero h;
- int animationId(TypeDescription::GetTypeId("Animation"));
- int entityId(TypeDescription::GetTypeId("Entity"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
- int statsId(TypeDescription::GetTypeId("Stats"));
- int stringId(TypeDescription::GetTypeId("String"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Hero"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Hero"));
td.SetConstructor(&Construct);
td.SetSize(sizeof(Hero));
- td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), stringId).SetReferenced());
+ td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), Interpreter::STRING_ID).SetReferenced());
- td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), numberId));
- td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), numberId));
- td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), numberId));
- td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), numberId));
- td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), numberId));
+ td.AddField("maxHealth", FieldDescription(((char *)&h.maxHealth) - ((char *)&h), Interpreter::NUMBER_ID));
+ td.AddField("health", FieldDescription(((char *)&h.health) - ((char *)&h), Interpreter::NUMBER_ID));
+ td.AddField("maxMana", FieldDescription(((char *)&h.maxMana) - ((char *)&h), Interpreter::NUMBER_ID));
+ td.AddField("mana", FieldDescription(((char *)&h.mana) - ((char *)&h), Interpreter::NUMBER_ID));
+ td.AddField("ip", FieldDescription(((char *)&h.ip) - ((char *)&h), Interpreter::NUMBER_ID));
- td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), statsId));
+ td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), Stats::TYPE_ID));
- td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), numberId));
+ td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID));
- td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), spriteId).SetReferenced().SetDescription("the sprite used for battle scenes"));
- td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), animationId).SetReferenced().SetDescription("the animation played for physical attacks"));
- td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), animationId).SetReferenced().SetDescription("the animation played for magical attacks"));
- td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId).SetReferenced().SetDescription("the animation played on attacked monsters when the hero has no weapon"));
+ td.AddField("battleSprite", FieldDescription(((char *)&h.battleSprite) - ((char *)&h), Sprite::TYPE_ID).SetReferenced().SetDescription("the sprite used for battle scenes"));
+ td.AddField("attackAnimation", FieldDescription(((char *)&h.attackAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for physical attacks"));
+ td.AddField("spellAnimation", FieldDescription(((char *)&h.spellAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played for magical attacks"));
+ td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), Animation::TYPE_ID).SetReferenced().SetDescription("the animation played on attacked monsters when the hero has no weapon"));
- td.AddField("mapEntity", FieldDescription(((char *)&h.mapEntity) - ((char *)&h), entityId).SetDescription("the entity representing the hero on maps"));
+ td.AddField("mapEntity", FieldDescription(((char *)&h.mapEntity) - ((char *)&h), Entity::TYPE_ID).SetDescription("the entity representing the hero on maps"));
}
void Hero::Construct(void *data) {
class Hero {
+public:
+ static const int TYPE_ID = 301;
+
public:
Hero();
~Hero() { }
#include "Ikari.h"
+#include "TargetingMode.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace common {
void Ikari::CreateTypeDescription() {
Ikari i;
- int boolId(TypeDescription::GetTypeId("Boolean"));
- int numberId(TypeDescription::GetTypeId("Number")); // FIXME: need small number type
- int stringId(TypeDescription::GetTypeId("String"));
- int targetsId(TypeDescription::GetTypeId("TargetingMode"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Ikari"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Ikari"));
td.SetDescription(
"Information of a single ikari attack.");
td.SetConstructor(&Construct);
td.SetSize(sizeof(Ikari));
- td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), stringId).SetReferenced().SetDescription("the attack's name"));
- td.AddField("cost", FieldDescription(((char *)&i.cost) - ((char *)&i), numberId).SetDescription("amount of ikari points needed and deducted for use"));
- td.AddField("targets", FieldDescription(((char *)&i.targetingMode) - ((char *)&i), targetsId).SetDescription("how target selection is to be performed"));
- td.AddField("type", FieldDescription(((char *)&i.isPhysical) - ((char *)&i), boolId).SetDescription("if the attack is physical (true) or magical(false)"));
+ td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), Interpreter::STRING_ID).SetReferenced().SetDescription("the attack's name"));
+ td.AddField("cost", FieldDescription(((char *)&i.cost) - ((char *)&i), Interpreter::NUMBER_ID).SetDescription("amount of ikari points needed and deducted for use"));
+ td.AddField("targets", FieldDescription(((char *)&i.targetingMode) - ((char *)&i), TargetingMode::TYPE_ID).SetDescription("how target selection is to be performed"));
+ td.AddField("type", FieldDescription(((char *)&i.isPhysical) - ((char *)&i), Interpreter::BOOLEAN_ID).SetDescription("if the attack is physical (true) or magical(false)"));
}
void Ikari::Construct(void *data) {
// TODO: looks like Ikari and Spell have _quite_ a lot in common…
class Ikari {
+public:
+ static const int TYPE_ID = 302;
+
public:
Ikari();
#include "Item.h"
+#include "Ikari.h"
+#include "TargetingMode.h"
+#include "../graphics/Animation.h"
+#include "../graphics/Sprite.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
+using graphics::Animation;
+using graphics::Sprite;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace common {
void Item::CreateTypeDescription() {
Item i;
- int animationId(TypeDescription::GetTypeId("Animation"));
- int boolId(TypeDescription::GetTypeId("Boolean"));
- int ikariId(TypeDescription::GetTypeId("Ikari"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
- int stringId(TypeDescription::GetTypeId("String"));
- int targetsId(TypeDescription::GetTypeId("TargetingMode"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Item"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Item"));
td.SetDescription("All data of an item (soon).");
td.SetConstructor(&Construct);
td.SetSize(sizeof(Item));
- td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), stringId).SetReferenced().SetDescription("the item's name"));
- td.AddField("menuicon", FieldDescription(((char *)&i.menuIcon) - ((char *)&i), spriteId).SetReferenced().SetDescription("icon that is displayed in menus"));
+ td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), Interpreter::STRING_ID).SetReferenced().SetDescription("the item's name"));
+ td.AddField("menuicon", FieldDescription(((char *)&i.menuIcon) - ((char *)&i), Sprite::TYPE_ID).SetReferenced().SetDescription("icon that is displayed in menus"));
- td.AddField("mostUseful", FieldDescription(((char *)&i.mostUseful) - ((char *)&i), boolId));
- td.AddField("equipable", FieldDescription(((char *)&i.equipable) - ((char *)&i), boolId));
- td.AddField("cursed", FieldDescription(((char *)&i.cursed) - ((char *)&i), boolId));
- td.AddField("fruit", FieldDescription(((char *)&i.fruit) - ((char *)&i), boolId));
- td.AddField("scenario", FieldDescription(((char *)&i.scenario) - ((char *)&i), boolId));
- td.AddField("status", FieldDescription(((char *)&i.status) - ((char *)&i), boolId));
- td.AddField("battle", FieldDescription(((char *)&i.battle) - ((char *)&i), boolId).SetDescription("if the item can be used in battle"));
+ td.AddField("mostUseful", FieldDescription(((char *)&i.mostUseful) - ((char *)&i), Interpreter::BOOLEAN_ID));
+ td.AddField("equipable", FieldDescription(((char *)&i.equipable) - ((char *)&i), Interpreter::BOOLEAN_ID));
+ td.AddField("cursed", FieldDescription(((char *)&i.cursed) - ((char *)&i), Interpreter::BOOLEAN_ID));
+ td.AddField("fruit", FieldDescription(((char *)&i.fruit) - ((char *)&i), Interpreter::BOOLEAN_ID));
+ td.AddField("scenario", FieldDescription(((char *)&i.scenario) - ((char *)&i), Interpreter::BOOLEAN_ID));
+ td.AddField("status", FieldDescription(((char *)&i.status) - ((char *)&i), Interpreter::BOOLEAN_ID));
+ td.AddField("battle", FieldDescription(((char *)&i.battle) - ((char *)&i), Interpreter::BOOLEAN_ID).SetDescription("if the item can be used in battle"));
- td.AddField("targets", FieldDescription(((char *)&i.targettingMode) - ((char *)&i), targetsId).SetDescription("how target selection is to be performed"));
- td.AddField("ikari", FieldDescription(((char *)&i.ikari) - ((char *)&i), ikariId).SetReferenced().SetDescription("ikari attack of the item (sensible only for equipment)"));
- td.AddField("attackanimation", FieldDescription(((char *)&i.attackAnimation) - ((char *)&i), animationId).SetReferenced().SetDescription("animation that is run when the item is used for attacking"));
+ td.AddField("targets", FieldDescription(((char *)&i.targettingMode) - ((char *)&i), TargetingMode::TYPE_ID).SetDescription("how target selection is to be performed"));
+ td.AddField("ikari", FieldDescription(((char *)&i.ikari) - ((char *)&i), Ikari::TYPE_ID).SetReferenced().SetDescription("ikari attack of the item (sensible only for equipment)"));
+ td.AddField("attackanimation", FieldDescription(((char *)&i.attackAnimation) - ((char *)&i), Animation::TYPE_ID).SetReferenced().SetDescription("animation that is run when the item is used for attacking"));
}
void Item::Construct(void *data) {
class Item {
+public:
+ static const int TYPE_ID = 303;
+
public:
Item();
#include "Spell.h"
+#include "TargetingMode.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace common {
void Spell::CreateTypeDescription() {
Spell s;
- int boolId(TypeDescription::GetTypeId("Boolean"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int stringId(TypeDescription::GetTypeId("String"));
- int targetsId(TypeDescription::GetTypeId("TargetingMode"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Spell"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Spell"));
td.SetDescription("All data about a spell (soon).");
td.SetConstructor(&Construct);
td.SetSize(sizeof(Spell));
- td.AddField("name", FieldDescription(((char *)&s.name) - ((char *)&s), stringId).SetReferenced().SetDescription("the spell's name"));
- td.AddField("cost", FieldDescription(((char *)&s.cost) - ((char *)&s), numberId).SetDescription("Amount of magic points needed and deducted for invocation"));
- td.AddField("targets", FieldDescription(((char *)&s.targetingMode) - ((char *)&s), targetsId).SetDescription("how target selection is to be performed"));
- td.AddField("status", FieldDescription(((char *)&s.status) - ((char *)&s), boolId).SetDescription("if the spell can be used at the status screen"));
- td.AddField("battle", FieldDescription(((char *)&s.battle) - ((char *)&s), boolId).SetDescription("if the spell can be used in battle"));
+ td.AddField("name", FieldDescription(((char *)&s.name) - ((char *)&s), Interpreter::STRING_ID).SetReferenced().SetDescription("the spell's name"));
+ td.AddField("cost", FieldDescription(((char *)&s.cost) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("Amount of magic points needed and deducted for invocation"));
+ td.AddField("targets", FieldDescription(((char *)&s.targetingMode) - ((char *)&s), TargetingMode::TYPE_ID).SetDescription("how target selection is to be performed"));
+ td.AddField("status", FieldDescription(((char *)&s.status) - ((char *)&s), Interpreter::BOOLEAN_ID).SetDescription("if the spell can be used at the status screen"));
+ td.AddField("battle", FieldDescription(((char *)&s.battle) - ((char *)&s), Interpreter::BOOLEAN_ID).SetDescription("if the spell can be used in battle"));
}
void Spell::Construct(void *data) {
class Spell {
+public:
+ static const int TYPE_ID = 304;
+
public:
Spell();
#include "Stats.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace common {
void Stats::CreateTypeDescription() {
Stats s;
- int numberId(TypeDescription::GetTypeId("Number"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Stats"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Stats"));
td.SetDescription("Attributes of a battle's participant.");
td.SetConstructor(&Construct);
td.SetSize(sizeof(Stats));
- td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s), numberId).SetDescription("attack points"));
- td.AddField("dfp", FieldDescription(((char *)&s.defense) - ((char *)&s), numberId).SetDescription("defense points"));
- td.AddField("str", FieldDescription(((char *)&s.strength) - ((char *)&s), numberId).SetDescription("strength"));
- td.AddField("agl", FieldDescription(((char *)&s.agility) - ((char *)&s), numberId).SetDescription("agility"));
- td.AddField("int", FieldDescription(((char *)&s.intelligence) - ((char *)&s), numberId).SetDescription("intelligence"));
- td.AddField("gut", FieldDescription(((char *)&s.gut) - ((char *)&s), numberId).SetDescription("gut (ikari factor)"));
- td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s), numberId).SetDescription("magic resistance"));
+ td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("attack points"));
+ td.AddField("dfp", FieldDescription(((char *)&s.defense) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("defense points"));
+ td.AddField("str", FieldDescription(((char *)&s.strength) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("strength"));
+ td.AddField("agl", FieldDescription(((char *)&s.agility) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("agility"));
+ td.AddField("int", FieldDescription(((char *)&s.intelligence) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("intelligence"));
+ td.AddField("gut", FieldDescription(((char *)&s.gut) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("gut (ikari factor)"));
+ td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("magic resistance"));
}
void Stats::Construct(void *data) {
class Stats {
+public:
+ static const int TYPE_ID = 305;
+
public:
Stats();
Stats(Uint16 attack, Uint16 defense, Uint16 strength, Uint16 agility, Uint16 intelligence, Uint8 gut, Uint16 magicResistance);
#include "TargetingMode.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace common {
void TargetingMode::CreateTypeDescription() {
TargetingMode t;
- int boolId(TypeDescription::GetTypeId("Boolean"));
- int numberId(TypeDescription::GetTypeId("Number"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("TargetingMode"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "TargetingMode"));
td.SetDescription("Specifies how selection of a target (e.g. for a spell) is performed.");
td.SetConstructor(&Construct);
td.SetSize(sizeof(TargetingMode));
- td.AddField("faction", FieldDescription(((char *)&t.ally) - ((char *)&t), boolId).SetDescription("targetted faction; true for ally, false for enemy"));
- td.AddField("mode", FieldDescription(((char *)&t.mode) - ((char *)&t), numberId).SetDescription("attack mode; 0 = all, 1 = multiple, 2 = single"));
+ td.AddField("faction", FieldDescription(((char *)&t.ally) - ((char *)&t), Interpreter::BOOLEAN_ID).SetDescription("targetted faction; true for ally, false for enemy"));
+ td.AddField("mode", FieldDescription(((char *)&t.mode) - ((char *)&t), Interpreter::NUMBER_ID).SetDescription("attack mode; 0 = all, 1 = multiple, 2 = single"));
}
void TargetingMode::Construct(void *data) {
class TargetingMode {
+public:
+ static const int TYPE_ID = 306;
+
public:
TargetingMode() : mode(0), ally(true) { }
#include "Animation.h"
+#include "Sprite.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace graphics {
-void Animation::AddFields(TypeDescription &td, const Animation &a, std::ptrdiff_t offset, int boolId, int numberId, int spriteId) {
- td.AddField("sprite", FieldDescription(((char *)&a.sprite) - ((char *)&a) - offset, spriteId).SetReferenced().SetDescription("the sprite used for cutting out frames"));
- td.AddField("frametime", FieldDescription(((char *)&a.frameTime) - ((char *)&a) - offset, numberId).SetDescription("duration of a frame in miliseconds"));
- td.AddField("repeat", FieldDescription(((char *)&a.repeat) - ((char *)&a) - offset, boolId).SetDescription("whether the animation should start over at the beginning after reaching the last frame"));
+void Animation::CreateTypeDescription() {
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Animation"));
+ td.SetDescription("Abstract base type for animations.");
+ td.SetSize(sizeof(Animation));
+}
+
+void Animation::AddFields(TypeDescription &td, const Animation &a, std::ptrdiff_t offset) {
+ td.AddField("sprite", FieldDescription(((char *)&a.sprite) - ((char *)&a) - offset, Sprite::TYPE_ID).SetReferenced().SetDescription("the sprite used for cutting out frames"));
+ td.AddField("frametime", FieldDescription(((char *)&a.frameTime) - ((char *)&a) - offset, Interpreter::NUMBER_ID).SetDescription("duration of a frame in miliseconds"));
+ td.AddField("repeat", FieldDescription(((char *)&a.repeat) - ((char *)&a) - offset, Interpreter::BOOLEAN_ID).SetDescription("whether the animation should start over at the beginning after reaching the last frame"));
}
}
class Animation {
+public:
+ static const int TYPE_ID = 401;
+
public:
Animation()
: sprite(0), frameTime(0), repeat(false) { }
virtual int Row(int frame) const = 0;
virtual geometry::Vector<int> Offset(int frame) const { return geometry::Vector<int>(); }
+ static void CreateTypeDescription();
+
protected:
- static void AddFields(loader::TypeDescription &, const Animation &, std::ptrdiff_t offset, int boolId, int numberId, int spriteId);
+ static void AddFields(loader::TypeDescription &, const Animation &, std::ptrdiff_t offset);
private:
const Sprite *sprite;
#include "ComplexAnimation.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace graphics {
ComplexAnimation ca;
Animation *a(&ca);
- int animationId(TypeDescription::GetTypeId("Animation"));
- int boolId(TypeDescription::GetTypeId("Boolean"));
- int frameId(TypeDescription::GetTypeId("ComplexAnimationFrame"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
- int vectorId(TypeDescription::GetTypeId("Vector"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("ComplexAnimation"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "ComplexAnimation"));
td.SetDescription("Complex animation type that supports per-frame disposition and non-linear sprite offset selection.");
td.SetConstructor(&Construct);
td.SetSize(sizeof(ComplexAnimation));
- td.AddSupertype(animationId, ((char *)a) - ((char *)&ca));
+ td.AddSupertype(Animation::TYPE_ID, ((char *)a) - ((char *)&ca));
- Animation::AddFields(td, ca, ((char *)a) - ((char *)&ca), boolId, numberId, spriteId);
- td.AddField("frames", FieldDescription(((char *)&ca.frames) - ((char *)&ca), frameId).SetReferenced().SetAggregate().SetDescription("a variable number of frames"));
+ Animation::AddFields(td, ca, ((char *)a) - ((char *)&ca));
+ td.AddField("frames", FieldDescription(((char *)&ca.frames) - ((char *)&ca), FrameProp::TYPE_ID).SetReferenced().SetAggregate().SetDescription("a variable number of frames"));
FrameProp fp;
- TypeDescription &ftd(TypeDescription::CreateOrGet("ComplexAnimationFrame"));
+ TypeDescription &ftd(TypeDescription::Create(FrameProp::TYPE_ID, "ComplexAnimationFrame"));
ftd.SetDescription("Information about how a frame of a complex animation should be rendered.");
ftd.SetSize(sizeof(FrameProp));
- ftd.AddField("column", FieldDescription(((char *)&fp.col) - ((char *)&fp), numberId).SetDescription("the column of the sprite that will be drawn"));
- ftd.AddField("row", FieldDescription(((char *)&fp.row) - ((char *)&fp), numberId).SetDescription("the row of the sprite that will be drawn"));
- ftd.AddField("disposition", FieldDescription(((char *)&fp.disposition) - ((char *)&fp), vectorId).SetDescription("offset from the original drawing position"));
+ ftd.AddField("column", FieldDescription(((char *)&fp.col) - ((char *)&fp), Interpreter::NUMBER_ID).SetDescription("the column of the sprite that will be drawn"));
+ ftd.AddField("row", FieldDescription(((char *)&fp.row) - ((char *)&fp), Interpreter::NUMBER_ID).SetDescription("the row of the sprite that will be drawn"));
+ ftd.AddField("disposition", FieldDescription(((char *)&fp.disposition) - ((char *)&fp), Interpreter::VECTOR_ID).SetDescription("offset from the original drawing position"));
}
void ComplexAnimation::Construct(void *data) {
class ComplexAnimation
: public Animation {
+public:
+ static const int TYPE_ID = 402;
+
public:
ComplexAnimation() : frames(0), numFrames(0) { }
ComplexAnimation(const Sprite *sprite, int frameTime, bool repeat = false)
public:
struct FrameProp {
+ static const int TYPE_ID = 403;
FrameProp() : col(0), row(0) { }
FrameProp(int col, int row, const geometry::Vector<int> &disposition)
: col(col), row(row), disposition(disposition) {}
#include "Font.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
#include <cmath>
using geometry::Vector;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
using std::pow;
void Font::CreateTypeDescription() {
Font f;
- int numberId(TypeDescription::GetTypeId("Number"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Font"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Font"));
td.SetDescription(
"Simple font with fixed-width characters using a sprite for rendering.\n"
"Characters from strings are mapped as follows:\n"
td.SetConstructor(&Construct);
td.SetSize(sizeof(Font));
- td.AddField("sprite", FieldDescription(((char *)&f.sprite) - ((char *)&f), spriteId).SetReferenced().SetDescription("a sprite where each tile corresponds to a character"));
- td.AddField("columnoffset", FieldDescription(((char *)&f.colOffset) - ((char *)&f), numberId).SetDescription("offset of the column of the first character"));
- td.AddField("rowoffset", FieldDescription(((char *)&f.rowOffset) - ((char *)&f), numberId).SetDescription("offset of the row of the first character"));
+ td.AddField("sprite", FieldDescription(((char *)&f.sprite) - ((char *)&f), Sprite::TYPE_ID).SetReferenced().SetDescription("a sprite where each tile corresponds to a character"));
+ td.AddField("columnoffset", FieldDescription(((char *)&f.colOffset) - ((char *)&f), Interpreter::NUMBER_ID).SetDescription("offset of the column of the first character"));
+ td.AddField("rowoffset", FieldDescription(((char *)&f.rowOffset) - ((char *)&f), Interpreter::NUMBER_ID).SetDescription("offset of the row of the first character"));
}
void Font::Construct(void *data) {
class Font {
+public:
+ static const int TYPE_ID = 404;
+
public:
explicit Font(const Sprite *sprite = 0, int colOffset = 0, int rowOffset = 0)
: sprite(sprite), colOffset(colOffset), rowOffset(rowOffset) {
#include "Frame.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using geometry::Vector;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace graphics {
void Frame::CreateTypeDescription() {
Frame f;
- int imageId(TypeDescription::GetTypeId("Image"));
- int vectorId(TypeDescription::GetTypeId("Vector"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Frame"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Frame"));
td.SetDescription(
"A frame is basically a border + a background texture.\n"
"It splits an image into 3*3 parts where the edges are kept as is and the sides and the middle part are repeated as needed.");
td.SetConstructor(&Construct);
td.SetSize(sizeof(Frame));
- td.AddField("image", FieldDescription(((char *)&f.surface) - ((char *)&f), imageId).SetReferenced().SetDescription("the underlying graphic from which the frame parts are cut"));
- td.AddField("border", FieldDescription(((char *)&f.borderSize) - ((char *)&f), vectorId).SetDescription("size of the border part, dimensions of top-left corner"));
- td.AddField("repeat", FieldDescription(((char *)&f.repeatSize) - ((char *)&f), vectorId).SetDescription("size of the repeat part, dimensions of a single tile of the background texture"));
- td.AddField("offset", FieldDescription(((char *)&f.offset) - ((char *)&f), vectorId).SetDescription("offset into the image where to start cutting, coordinates of the top-left corner on the image"));
+ td.AddField("image", FieldDescription(((char *)&f.surface) - ((char *)&f), Interpreter::IMAGE_ID).SetReferenced().SetDescription("the underlying graphic from which the frame parts are cut"));
+ td.AddField("border", FieldDescription(((char *)&f.borderSize) - ((char *)&f), Interpreter::VECTOR_ID).SetDescription("size of the border part, dimensions of top-left corner"));
+ td.AddField("repeat", FieldDescription(((char *)&f.repeatSize) - ((char *)&f), Interpreter::VECTOR_ID).SetDescription("size of the repeat part, dimensions of a single tile of the background texture"));
+ td.AddField("offset", FieldDescription(((char *)&f.offset) - ((char *)&f), Interpreter::VECTOR_ID).SetDescription("offset into the image where to start cutting, coordinates of the top-left corner on the image"));
}
void Frame::Construct(void *data) {
class Frame {
+public:
+ static const int TYPE_ID = 405;
+
public:
explicit Frame(SDL_Surface *s = 0, int borderWidth = 1, int borderHeight = 1, int repeatWidth = 1, int repeatHeight = 1, int xOffset = 0, int yOffset = 0)
: surface(s), borderSize(borderWidth, borderHeight), repeatSize(repeatWidth, repeatHeight), offset(xOffset, yOffset) { }
#include "Gauge.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using geometry::Vector;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace graphics {
void Gauge::CreateTypeDescription() {
Gauge g;
- int imageId(TypeDescription::GetTypeId("Image"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int vectorId(TypeDescription::GetTypeId("Vector"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Gauge"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Gauge"));
td.SetDescription(
"Gauges display a percentage by filling the left part different than the right.\n"
"The fill level is only mapped with repeat.\n"
td.SetConstructor(&Construct);
td.SetSize(sizeof(Gauge));
- td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), imageId).SetReferenced().SetDescription("the underlying graphic from which the gauge parts are cut"));
- td.AddField("full", FieldDescription(((char *)&g.fullOffset) - ((char *)&g), vectorId).SetDescription("top-left corner of the filled gauge"));
- td.AddField("empty", FieldDescription(((char *)&g.emptyOffset) - ((char *)&g), vectorId).SetDescription("top-left corner of the empty gauge"));
- td.AddField("height", FieldDescription(((char *)&g.height) - ((char *)&g), numberId).SetDescription("height of the gauges"));
- td.AddField("start", FieldDescription(((char *)&g.startWidth) - ((char *)&g), numberId).SetDescription("width of the start part"));
- td.AddField("repeat", FieldDescription(((char *)&g.repeatWidth) - ((char *)&g), numberId).SetDescription("width of the repeat part"));
- td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), numberId).SetDescription("width of the end part"));
+ td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), Interpreter::IMAGE_ID).SetReferenced().SetDescription("the underlying graphic from which the gauge parts are cut"));
+ td.AddField("full", FieldDescription(((char *)&g.fullOffset) - ((char *)&g), Interpreter::VECTOR_ID).SetDescription("top-left corner of the filled gauge"));
+ td.AddField("empty", FieldDescription(((char *)&g.emptyOffset) - ((char *)&g), Interpreter::VECTOR_ID).SetDescription("top-left corner of the empty gauge"));
+ td.AddField("height", FieldDescription(((char *)&g.height) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("height of the gauges"));
+ td.AddField("start", FieldDescription(((char *)&g.startWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the start part"));
+ td.AddField("repeat", FieldDescription(((char *)&g.repeatWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the repeat part"));
+ td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), Interpreter::NUMBER_ID).SetDescription("width of the end part"));
}
void Gauge::Construct(void *data) {
class Gauge {
+ public:
+ static const int TYPE_ID = 406;
+
public:
explicit Gauge(SDL_Surface *s = 0, int fullX = 0, int fullY = 0, int emptyX = 0, int emptyY = 0, int height = 1, int startWidth = 0, int repeatWidth = 1, int endWidth = 0)
: surface(s), fullOffset(fullX, fullY), emptyOffset(emptyX, emptyY), height(height), startWidth(startWidth), repeatWidth(repeatWidth), endWidth(endWidth) { }
#include "Menu.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace graphics {
void MenuProperties::CreateTypeDescription() {
MenuProperties p;
- int fontId(TypeDescription::GetTypeId("Font"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
- int stringId(TypeDescription::GetTypeId("String"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("MenuProperties"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "MenuProperties"));
td.SetConstructor(&Construct);
td.SetSize(sizeof(MenuProperties));
- td.AddField("font", FieldDescription(((char *)&p.font) - ((char *)&p), fontId).SetReferenced().SetDescription("the font to use for normal/enabled entries"));
- td.AddField("disabledFont", FieldDescription(((char *)&p.disabledFont) - ((char *)&p), fontId).SetReferenced().SetDescription("the font for disabled entries"));
- td.AddField("cursor", FieldDescription(((char *)&p.cursor) - ((char *)&p), spriteId).SetReferenced().SetDescription("the cursor sprite indicating the current selection"));
- td.AddField("charsPerEntry", FieldDescription(((char *)&p.charsPerEntry) - ((char *)&p), numberId).SetDescription("width of an entry in characters"));
- td.AddField("rows", FieldDescription(((char *)&p.rows) - ((char *)&p), numberId).SetDescription("number of visible rows"));
- td.AddField("rowGap", FieldDescription(((char *)&p.rowGap) - ((char *)&p), numberId).SetDescription("space between rows in pixles"));
- td.AddField("iconSpace", FieldDescription(((char *)&p.iconSpace) - ((char *)&p), numberId).SetDescription("space reserved for icons in pixels"));
- td.AddField("cols", FieldDescription(((char *)&p.cols) - ((char *)&p), numberId).SetDescription("number of columns"));
- td.AddField("colGap", FieldDescription(((char *)&p.colGap) - ((char *)&p), numberId).SetDescription("space between cols in pixels"));
- td.AddField("delimiter", FieldDescription(((char *)&p.delimiter) - ((char *)&p), stringId).SetDescription("delimiter between text and number; only first character is used"));
- td.AddField("charsPerNumber", FieldDescription(((char *)&p.charsPerNumber) - ((char *)&p), numberId).SetDescription("maximum width of a number in chars"));
- td.AddField("charsPerAdditionalText", FieldDescription(((char *)&p.charsPerAdditionalText) - ((char *)&p), numberId).SetDescription("maximum number of additional text characters"));
- td.AddField("additionalTextGap", FieldDescription(((char *)&p.additionalTextGap) - ((char *)&p), numberId).SetDescription("space between normal and additional text in pixels"));
+ td.AddField("font", FieldDescription(((char *)&p.font) - ((char *)&p), Font::TYPE_ID).SetReferenced().SetDescription("the font to use for normal/enabled entries"));
+ td.AddField("disabledFont", FieldDescription(((char *)&p.disabledFont) - ((char *)&p), Font::TYPE_ID).SetReferenced().SetDescription("the font for disabled entries"));
+ td.AddField("cursor", FieldDescription(((char *)&p.cursor) - ((char *)&p), Sprite::TYPE_ID).SetReferenced().SetDescription("the cursor sprite indicating the current selection"));
+ td.AddField("charsPerEntry", FieldDescription(((char *)&p.charsPerEntry) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("width of an entry in characters"));
+ td.AddField("rows", FieldDescription(((char *)&p.rows) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("number of visible rows"));
+ td.AddField("rowGap", FieldDescription(((char *)&p.rowGap) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("space between rows in pixles"));
+ td.AddField("iconSpace", FieldDescription(((char *)&p.iconSpace) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("space reserved for icons in pixels"));
+ td.AddField("cols", FieldDescription(((char *)&p.cols) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("number of columns"));
+ td.AddField("colGap", FieldDescription(((char *)&p.colGap) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("space between cols in pixels"));
+ td.AddField("delimiter", FieldDescription(((char *)&p.delimiter) - ((char *)&p), Interpreter::STRING_ID).SetDescription("delimiter between text and number; only first character is used"));
+ td.AddField("charsPerNumber", FieldDescription(((char *)&p.charsPerNumber) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("maximum width of a number in chars"));
+ td.AddField("charsPerAdditionalText", FieldDescription(((char *)&p.charsPerAdditionalText) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("maximum number of additional text characters"));
+ td.AddField("additionalTextGap", FieldDescription(((char *)&p.additionalTextGap) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("space between normal and additional text in pixels"));
}
void MenuProperties::Construct(void *data) {
namespace graphics {
struct MenuProperties {
+ static const int TYPE_ID = 407;
+
const Font *font;
const Font *disabledFont;
const Sprite *cursor;
#include "SimpleAnimation.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace graphics {
SimpleAnimation sa;
Animation *a(&sa);
- int animationId(TypeDescription::GetTypeId("Animation"));
- int boolId(TypeDescription::GetTypeId("Boolean"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("SimpleAnimation"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "SimpleAnimation"));
td.SetDescription("An animation that uses a fixed column and increasing row of a sprite based on the frame number.");
td.SetConstructor(&Construct);
td.SetSize(sizeof(SimpleAnimation));
- td.AddSupertype(animationId, ((char *)a) - ((char *)&sa));
+ td.AddSupertype(Animation::TYPE_ID, ((char *)a) - ((char *)&sa));
- Animation::AddFields(td, sa, ((char *)a) - ((char *)&sa), boolId, numberId, spriteId);
- td.AddField("framecount", FieldDescription(((char *)&sa.numFrames) - ((char *)&sa), numberId).SetDescription("number of frames of a single run"));
- td.AddField("col", FieldDescription(((char *)&sa.col) - ((char *)&sa), numberId).SetDescription("the column of the sprite to draw from"));
- td.AddField("row", FieldDescription(((char *)&sa.row) - ((char *)&sa), numberId).SetDescription("the row of the sprite of the first frame"));
+ Animation::AddFields(td, sa, ((char *)a) - ((char *)&sa));
+ td.AddField("framecount", FieldDescription(((char *)&sa.numFrames) - ((char *)&sa), Interpreter::NUMBER_ID).SetDescription("number of frames of a single run"));
+ td.AddField("col", FieldDescription(((char *)&sa.col) - ((char *)&sa), Interpreter::NUMBER_ID).SetDescription("the column of the sprite to draw from"));
+ td.AddField("row", FieldDescription(((char *)&sa.row) - ((char *)&sa), Interpreter::NUMBER_ID).SetDescription("the row of the sprite of the first frame"));
}
void SimpleAnimation::Construct(void *data) {
class SimpleAnimation
: public Animation {
+public:
+ static const int TYPE_ID = 408;
+
public:
SimpleAnimation()
: numFrames(0), col(0), row(0) { }
#include "Sprite.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using geometry::Vector;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace graphics {
void Sprite::CreateTypeDescription() {
Sprite s;
- int imageId(TypeDescription::GetTypeId("Image"));
- int vectorId(TypeDescription::GetTypeId("Vector"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Sprite"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Sprite"));
td.SetDescription(
"An image + a size and offset.\n"
"The resulting section or a section offset by a multiple of its size can be drawn.");
td.SetConstructor(&Construct);
td.SetSize(sizeof(Sprite));
- td.AddField("image", FieldDescription(((char *)&s.surface) - ((char *)&s), imageId).SetReferenced().SetDescription("the image to cut this sprite from"));
- td.AddField("size", FieldDescription(((char *)&s.size) - ((char *)&s), vectorId).SetDescription("dimensions of the sprite"));
- td.AddField("offset", FieldDescription(((char *)&s.offset) - ((char *)&s), vectorId).SetDescription("offset into the image, top-left corner of the sprite's (0,0) clip"));
+ td.AddField("image", FieldDescription(((char *)&s.surface) - ((char *)&s), Interpreter::IMAGE_ID).SetReferenced().SetDescription("the image to cut this sprite from"));
+ td.AddField("size", FieldDescription(((char *)&s.size) - ((char *)&s), Interpreter::VECTOR_ID).SetDescription("dimensions of the sprite"));
+ td.AddField("offset", FieldDescription(((char *)&s.offset) - ((char *)&s), Interpreter::VECTOR_ID).SetDescription("offset into the image, top-left corner of the sprite's (0,0) clip"));
}
void Sprite::Construct(void *data) {
class Sprite {
+public:
+ static const int TYPE_ID = 409;
+
public:
Sprite() : surface(0), size(64, 64), offset() { }
Sprite(SDL_Surface *s, int width, int height, int xOffset = 0, int yOffset = 0)
void Interpreter::CreateTypeDescriptions() {
{
- TypeDescription &td(TypeDescription::CreateOrGet("Boolean"));
+ TypeDescription &td(TypeDescription::Create(BOOLEAN_ID, "Boolean"));
td.SetDescription("Logical value which can be either true or false.");
td.SetSize(sizeof(bool));
}
{
- TypeDescription &td(TypeDescription::CreateOrGet("Color"));
+ TypeDescription &td(TypeDescription::Create(COLOR_ID, "Color"));
td.SetDescription(
"A color in RGB format with an optional alpha channel.\n"
"Components range from 0 to 255.\n"
td.SetSize(sizeof(Color));
}
{
- TypeDescription &td(TypeDescription::CreateOrGet("Image"));
+ TypeDescription &td(TypeDescription::Create(IMAGE_ID, "Image"));
td.SetDescription("Path to a PNG file with image data.");
td.SetSize(sizeof(SDL_Surface));
}
{
- TypeDescription &td(TypeDescription::CreateOrGet("Number"));
+ TypeDescription &td(TypeDescription::Create(NUMBER_ID, "Number"));
td.SetDescription("A signed integer.");
td.SetSize(sizeof(int));
}
- {
- int stringId(TypeDescription::GetTypeId("String"));
- TypeDescription &td(TypeDescription::CreateOrGet("Path"));
+ {;
+ TypeDescription &td(TypeDescription::Create(PATH_ID, "Path"));
td.SetDescription("A path in the filesystem which is interpreted relative to the source file's location.");
td.SetSize(1);
- td.AddSupertype(stringId, 0);
+ td.AddSupertype(STRING_ID, 0);
}
{
- TypeDescription &td(TypeDescription::CreateOrGet("Script"));
+ TypeDescription &td(TypeDescription::Create(SCRIPT_ID, "Script"));
td.SetDescription("Collection of commands that define a behaviour.");
td.SetSize(sizeof(Script));
}
{
- TypeDescription &td(TypeDescription::CreateOrGet("String"));
+ TypeDescription &td(TypeDescription::Create(STRING_ID, "String"));
td.SetDescription("Some characters.");
td.SetSize(1);
}
{
- TypeDescription &td(TypeDescription::CreateOrGet("Vector"));
+ TypeDescription &td(TypeDescription::Create(VECTOR_ID, "Vector"));
td.SetDescription("A pair of numbers usually describing a 2D translation or offset.");
td.SetSize(sizeof(Vector<int>));
}
class Interpreter {
public:
+ static const int BOOLEAN_ID = 1;
+ static const int COLOR_ID = 2;
+ static const int IMAGE_ID = 3;
+ static const int NUMBER_ID = 4;
+ static const int PATH_ID = 5;
+ static const int SCRIPT_ID = 6;
+ static const int STRING_ID = 7;
+ static const int VECTOR_ID = 8;
+
class Error: public std::runtime_error {
public:
Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
#include <cassert>
#include <cstring>
#include <ostream>
+#include <sstream>
#include <stdexcept>
using std::endl;
+using std::invalid_argument;
+using std::make_pair;
using std::map;
using std::string;
+using std::stringstream;
using std::vector;
namespace loader {
}
-vector<TypeDescription> TypeDescription::typeDescriptions;
+map<int, TypeDescription> TypeDescription::typeDescriptions;
+map<string, int> TypeDescription::typeName2ID;
-TypeDescription &TypeDescription::CreateOrGet(const std::string &name) {
- for (vector<TypeDescription>::iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) {
- if (i->name == name) {
- return *i;
- }
+TypeDescription &TypeDescription::Create(int id, const std::string &name) {
+ if (typeDescriptions.count(id)) {
+ std::stringstream msg;
+ msg << "duplicate type ID " << id
+ << " (have " << Get(id).TypeName() << ", got " << name << ")";
+ throw std::invalid_argument(msg.str());
+ }
+ if (typeName2ID.count(name)) {
+ std::stringstream msg;
+ msg << "duplicate type name " << name
+ << " (have " << GetTypeId(name) << ", got " << id << ")";
+ throw std::invalid_argument(msg.str());
}
- typeDescriptions.push_back(TypeDescription(typeDescriptions.size(), name));
- return typeDescriptions.back();
+ typeName2ID[name] = id;
+ return typeDescriptions.insert(make_pair(id, TypeDescription(id, name))).first->second;
}
int TypeDescription::GetTypeId(const std::string &name) {
- for (vector<TypeDescription>::size_type i(0), end(typeDescriptions.size()); i < end; ++i) {
- if (typeDescriptions[i].name == name) {
- return i;
- }
+ map<string, int>::const_iterator i(typeName2ID.find(name));
+ if (i != typeName2ID.end()) {
+ return i->second;
+ } else {
+ throw invalid_argument("unknown type name " + name);
}
- typeDescriptions.push_back(TypeDescription(typeDescriptions.size(), name));
- return typeDescriptions.size() - 1;
}
const TypeDescription &TypeDescription::Get(int id) {
- assert(id >= 0 && id < int(typeDescriptions.size()));
- return typeDescriptions[id];
+ map<int, TypeDescription>::const_iterator i(typeDescriptions.find(id));
+ if (i != typeDescriptions.end()) {
+ return i->second;
+ } else {
+ std::stringstream msg;
+ msg << "invalid type ID " << id;
+ throw invalid_argument(msg.str());
+ }
}
void TypeDescription::WriteSourceWiki(std::ostream &out) {
vector<string> types;
- for (vector<TypeDescription>::const_iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) {
- if (i->name != "Animation") {
- types.push_back(i->name);
+ for (map<int, TypeDescription>::const_iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) {
+ if (i->second.name != "Animation") {
+ types.push_back(i->second.name);
}
}
std::sort(types.begin(), types.end());
FieldIterator FieldsBegin() const { return fields.begin(); }
FieldIterator FieldsEnd() const { return fields.end(); }
- static TypeDescription &CreateOrGet(const std::string &name);
+ static TypeDescription &Create(int id, const std::string &name);
static int GetTypeId(const std::string &);
static const TypeDescription &Get(int id);
int id;
int size;
- static std::vector<TypeDescription> typeDescriptions;
+ static std::map<int, TypeDescription> typeDescriptions;
+ static std::map<std::string, int> typeName2ID;
};
using battle::PartyLayout;
using common::GameConfig;
using common::GameState;
-using common::Hero;
-using common::Ikari;
-using common::Inventory;
-using common::Item;
-using common::Script;
using common::Spell;
-using common::Stats;
using geometry::Vector;
-using graphics::ComplexAnimation;
-using graphics::Font;
-using graphics::Frame;
-using graphics::Gauge;
-using graphics::Menu;
-using graphics::SimpleAnimation;
-using graphics::Sprite;
using loader::Caster;
using loader::Interpreter;
using loader::ParsedSource;
using loader::Parser;
using loader::TypeDescription;
-using map::Area;
using map::Entity;
-using map::Map;
using map::MapState;
-using map::Tile;
-using map::Trigger;
using sdl::InitImage;
using sdl::InitScreen;
using sdl::InitSDL;
InitSDL sdl;
InitImage image(IMG_INIT_PNG);
- Area::CreateTypeDescription();
- battle::Resources::CreateTypeDescription();
- ComplexAnimation::CreateTypeDescription();
- Font::CreateTypeDescription();
- Frame::CreateTypeDescription();
- Gauge::CreateTypeDescription();
- Hero::CreateTypeDescription();
- Ikari::CreateTypeDescription();
Interpreter::CreateTypeDescriptions();
- Item::CreateTypeDescription();
- Map::CreateTypeDescription();
- graphics::MenuProperties::CreateTypeDescription();
- Monster::CreateTypeDescription();
- PartyLayout::CreateTypeDescription();
- SimpleAnimation::CreateTypeDescription();
- Spell::CreateTypeDescription();
- Sprite::CreateTypeDescription();
- Stats::CreateTypeDescription();
+
+ battle::Resources::CreateTypeDescription();
+ battle::Monster::CreateTypeDescription();
+ battle::PartyLayout::CreateTypeDescription();
+
+ common::Hero::CreateTypeDescription();
+ common::Ikari::CreateTypeDescription();
+ common::Item::CreateTypeDescription();
+ common::Stats::CreateTypeDescription();
+ common::Spell::CreateTypeDescription();
common::TargetingMode::CreateTypeDescription();
- Tile::CreateTypeDescription();
- Trigger::CreateTypeDescription();
- Entity::CreateTypeDescription();
+
+ graphics::Animation::CreateTypeDescription();
+ graphics::ComplexAnimation::CreateTypeDescription();
+ graphics::Font::CreateTypeDescription();
+ graphics::Frame::CreateTypeDescription();
+ graphics::Gauge::CreateTypeDescription();
+ graphics::MenuProperties::CreateTypeDescription();
+ graphics::SimpleAnimation::CreateTypeDescription();
+ graphics::Sprite::CreateTypeDescription();
+
+ map::Area::CreateTypeDescription();
+ map::Entity::CreateTypeDescription();
+ map::Map::CreateTypeDescription();
+ map::Tile::CreateTypeDescription();
+ map::Trigger::CreateTypeDescription();
Arguments args;
args.Read(argc, argv);
#include "Tile.h"
#include "../graphics/Sprite.h"
#include "../loader/TypeDescription.h"
+#include "../loader/Interpreter.h"
#include "../sdl/utility.h"
#include <stdexcept>
using geometry::Vector;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace map {
void Area::CreateTypeDescription() {
Area a;
- int imageId(TypeDescription::GetTypeId("Image"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int tileId(TypeDescription::GetTypeId("Tile"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Area"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Area"));
td.SetConstructor(&Construct);
td.SetSize(sizeof(Area));
- td.AddField("battlebg", FieldDescription(((char *)&a.battlebg) - ((char *)&a), imageId).SetReferenced());
- td.AddField("tiles", FieldDescription(((char *)&a.tiles) - ((char *)&a), tileId).SetReferenced().SetAggregate());
- td.AddField("width", FieldDescription(((char *)&a.width) - ((char *)&a), numberId));
+ td.AddField("battlebg", FieldDescription(((char *)&a.battlebg) - ((char *)&a), Interpreter::IMAGE_ID).SetReferenced());
+ td.AddField("tiles", FieldDescription(((char *)&a.tiles) - ((char *)&a), Tile::TYPE_ID).SetReferenced().SetAggregate());
+ td.AddField("width", FieldDescription(((char *)&a.width) - ((char *)&a), Interpreter::NUMBER_ID));
}
void Area::Construct(void *data) {
/// Missing tiles in the last row are possible but don't fool yourself.
class Area {
+public:
+ static const int TYPE_ID = 601;
+
public:
Area();
~Area() { }
#include "Entity.h"
+#include "../battle/Monster.h"
+#include "../battle/PartyLayout.h"
+#include "../graphics/Animation.h"
+#include "../graphics/Sprite.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
+using battle::Monster;
+using battle::PartyLayout;
+using graphics::Animation;
+using graphics::Sprite;
using geometry::Vector;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace map {
void Entity::CreateTypeDescription() {
Entity e;
- int animationId(TypeDescription::GetTypeId("Animation"));
- int monsterId(TypeDescription::GetTypeId("Monster"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int partyLayoutId(TypeDescription::GetTypeId("PartyLayout"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
- int vectorId(TypeDescription::GetTypeId("Vector"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Entity"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Entity"));
td.SetConstructor(&Construct);
td.SetLoader(&Load);
td.SetSize(sizeof(Entity));
- td.AddField("animation", FieldDescription(((char *)&e.animation) - ((char *)&e), animationId).SetReferenced());
- td.AddField("sprite", FieldDescription(((char *)&e.sprite) - ((char *)&e), spriteId).SetReferenced());
- td.AddField("partyLayout", FieldDescription(((char *)&e.partyLayout) - ((char *)&e), partyLayoutId).SetReferenced());
- td.AddField("monsters", FieldDescription(((char *)&e.monsters) - ((char *)&e), monsterId).SetReferenced().SetAggregate());
- td.AddField("spriteOffset", FieldDescription(((char *)&e.spriteOffset) - ((char *)&e), vectorId));
- td.AddField("position", FieldDescription(((char *)&e.tilePosition) - ((char *)&e), vectorId));
- td.AddField("flags", FieldDescription(((char *)&e.flags) - ((char *)&e), numberId));
+ td.AddField("animation", FieldDescription(((char *)&e.animation) - ((char *)&e), Animation::TYPE_ID).SetReferenced());
+ td.AddField("sprite", FieldDescription(((char *)&e.sprite) - ((char *)&e), Sprite::TYPE_ID).SetReferenced());
+ td.AddField("partyLayout", FieldDescription(((char *)&e.partyLayout) - ((char *)&e), PartyLayout::TYPE_ID).SetReferenced());
+ td.AddField("monsters", FieldDescription(((char *)&e.monsters) - ((char *)&e), Monster::TYPE_ID).SetReferenced().SetAggregate());
+ td.AddField("spriteOffset", FieldDescription(((char *)&e.spriteOffset) - ((char *)&e), Interpreter::VECTOR_ID));
+ td.AddField("position", FieldDescription(((char *)&e.tilePosition) - ((char *)&e), Interpreter::VECTOR_ID));
+ td.AddField("flags", FieldDescription(((char *)&e.flags) - ((char *)&e), Interpreter::NUMBER_ID));
}
void Entity::Construct(void *data) {
/// interact with the player.
class Entity {
+public:
+ static const int TYPE_ID = 605;
+
public:
Entity();
~Entity() { }
#include "Tile.h"
#include "Trigger.h"
#include "../graphics/Sprite.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
#include "../sdl/utility.h"
#include <stdexcept>
using geometry::Vector;
+using graphics::Sprite;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace map {
void Map::CreateTypeDescription() {
Map m;
- int areaId(TypeDescription::GetTypeId("Area"));
- int entityId(TypeDescription::GetTypeId("Entity"));
- int imageId(TypeDescription::GetTypeId("Image"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int spriteId(TypeDescription::GetTypeId("Sprite"));
- int triggerId(TypeDescription::GetTypeId("Trigger"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Map"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Map"));
td.SetConstructor(&Construct);
td.SetSize(sizeof(Map));
- td.AddField("tileset", FieldDescription(((char *)&m.tileset) - ((char *)&m), spriteId).SetReferenced());
- td.AddField("battlebg", FieldDescription(((char *)&m.battlebg) - ((char *)&m), imageId).SetReferenced());
- td.AddField("areas", FieldDescription(((char *)&m.areas) - ((char *)&m), areaId).SetReferenced().SetAggregate());
- td.AddField("triggers", FieldDescription(((char *)&m.triggers) - ((char *)&m), triggerId).SetReferenced().SetAggregate());
- td.AddField("entities", FieldDescription(((char *)&m.entities) - ((char *)&m), entityId).SetReferenced().SetAggregate());
- td.AddField("width", FieldDescription(((char *)&m.width) - ((char *)&m), numberId));
+ td.AddField("tileset", FieldDescription(((char *)&m.tileset) - ((char *)&m), Sprite::TYPE_ID).SetReferenced());
+ td.AddField("battlebg", FieldDescription(((char *)&m.battlebg) - ((char *)&m), Interpreter::IMAGE_ID).SetReferenced());
+ td.AddField("areas", FieldDescription(((char *)&m.areas) - ((char *)&m), Area::TYPE_ID).SetReferenced().SetAggregate());
+ td.AddField("triggers", FieldDescription(((char *)&m.triggers) - ((char *)&m), Trigger::TYPE_ID).SetReferenced().SetAggregate());
+ td.AddField("entities", FieldDescription(((char *)&m.entities) - ((char *)&m), Entity::TYPE_ID).SetReferenced().SetAggregate());
+ td.AddField("width", FieldDescription(((char *)&m.width) - ((char *)&m), Interpreter::NUMBER_ID));
}
void Map::Construct(void *data) {
/// extending to the right and down respectively.
class Map {
+public:
+ static const int TYPE_ID = 602;
+
public:
Map();
~Map() { }
#include "Tile.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace map {
void Tile::CreateTypeDescription() {
Tile t;
- int imageId(TypeDescription::GetTypeId("Image"));
- int numberId(TypeDescription::GetTypeId("Number"));
- int vectorId(TypeDescription::GetTypeId("Vector"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Tile"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Tile"));
td.SetConstructor(&Construct);
td.SetSize(sizeof(Tile));
- td.AddField("battlebg", FieldDescription(((char *)&t.battlebg) - ((char *)&t), imageId).SetReferenced());
- td.AddField("t", FieldDescription(((char *)&t.offset) - ((char *)&t), vectorId));
- td.AddField("flags", FieldDescription(((char *)&t.flags) - ((char *)&t), numberId));
+ td.AddField("battlebg", FieldDescription(((char *)&t.battlebg) - ((char *)&t), Interpreter::IMAGE_ID).SetReferenced());
+ td.AddField("t", FieldDescription(((char *)&t.offset) - ((char *)&t), Interpreter::VECTOR_ID));
+ td.AddField("flags", FieldDescription(((char *)&t.flags) - ((char *)&t), Interpreter::NUMBER_ID));
}
class Tile {
+public:
+ static const int TYPE_ID = 603;
+
public:
Tile();
~Tile() { }
#include "Trigger.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace map {
void Trigger::CreateTypeDescription() {
Trigger t;
- int numberId(TypeDescription::GetTypeId("Number"));
- int scriptId(TypeDescription::GetTypeId("Script"));
- int vectorId(TypeDescription::GetTypeId("Vector"));
-
- TypeDescription &td(TypeDescription::CreateOrGet("Trigger"));
+ TypeDescription &td(TypeDescription::Create(TYPE_ID, "Trigger"));
td.SetConstructor(&Construct);
td.SetSize(sizeof(Trigger));
- td.AddField("script", FieldDescription(((char *)&t.script) - ((char *)&t), scriptId).SetReferenced());
- td.AddField("position", FieldDescription(((char *)&t.tilePosition) - ((char *)&t), vectorId));
- td.AddField("type", FieldDescription(((char *)&t.type) - ((char *)&t), numberId));
+ td.AddField("script", FieldDescription(((char *)&t.script) - ((char *)&t), Interpreter::SCRIPT_ID).SetReferenced());
+ td.AddField("position", FieldDescription(((char *)&t.tilePosition) - ((char *)&t), Interpreter::VECTOR_ID));
+ td.AddField("type", FieldDescription(((char *)&t.type) - ((char *)&t), Interpreter::NUMBER_ID));
}
void Trigger::Construct(void *data) {
class Trigger {
+public:
+ static const int TYPE_ID = 604;
+
public:
Trigger();
~Trigger() { }