From 1907ca03c5e865c4d398170042aa384c67ffff29 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 18 Oct 2012 22:40:48 +0200 Subject: [PATCH] switched to static type IDs --- src/battle/Monster.cpp | 38 ++++----- src/battle/Monster.h | 3 + src/battle/PartyLayout.cpp | 8 +- src/battle/PartyLayout.h | 3 + src/battle/Resources.cpp | 126 +++++++++++++++--------------- src/battle/Resources.h | 2 + src/common/Hero.cpp | 43 +++++----- src/common/Hero.h | 3 + src/common/Ikari.cpp | 18 ++--- src/common/Ikari.h | 3 + src/common/Item.cpp | 41 +++++----- src/common/Item.h | 3 + src/common/Spell.cpp | 20 +++-- src/common/Spell.h | 3 + src/common/Stats.cpp | 20 ++--- src/common/Stats.h | 3 + src/common/TargetingMode.cpp | 11 ++- src/common/TargetingMode.h | 3 + src/graphics/Animation.cpp | 17 +++- src/graphics/Animation.h | 7 +- src/graphics/ComplexAnimation.cpp | 25 +++--- src/graphics/ComplexAnimation.h | 4 + src/graphics/Font.cpp | 13 ++- src/graphics/Font.h | 3 + src/graphics/Frame.cpp | 15 ++-- src/graphics/Frame.h | 3 + src/graphics/Gauge.cpp | 22 +++--- src/graphics/Gauge.h | 3 + src/graphics/Menu.cpp | 35 ++++----- src/graphics/Menu.h | 2 + src/graphics/SimpleAnimation.cpp | 19 ++--- src/graphics/SimpleAnimation.h | 3 + src/graphics/Sprite.cpp | 13 ++- src/graphics/Sprite.h | 3 + src/loader/Interpreter.cpp | 21 +++-- src/loader/Interpreter.h | 9 +++ src/loader/TypeDescription.cpp | 55 ++++++++----- src/loader/TypeDescription.h | 5 +- src/main.cpp | 62 ++++++--------- src/map/Area.cpp | 14 ++-- src/map/Area.h | 3 + src/map/Entity.cpp | 33 ++++---- src/map/Entity.h | 3 + src/map/Map.cpp | 24 +++--- src/map/Map.h | 3 + src/map/Tile.cpp | 14 ++-- src/map/Tile.h | 3 + src/map/Trigger.cpp | 14 ++-- src/map/Trigger.h | 3 + 49 files changed, 437 insertions(+), 367 deletions(-) diff --git a/src/battle/Monster.cpp b/src/battle/Monster.cpp index 498a8c6..8ea79e6 100644 --- a/src/battle/Monster.cpp +++ b/src/battle/Monster.cpp @@ -7,9 +7,17 @@ #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 { @@ -55,30 +63,24 @@ void Monster::SubtractHealth(int amount) { 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) { diff --git a/src/battle/Monster.h b/src/battle/Monster.h index f1073f2..e73f4e8 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -21,6 +21,9 @@ namespace battle { class Monster { +public: + static const int TYPE_ID = 202; + public: Monster(); ~Monster(); diff --git a/src/battle/PartyLayout.cpp b/src/battle/PartyLayout.cpp index 27d587e..c9451cb 100644 --- a/src/battle/PartyLayout.cpp +++ b/src/battle/PartyLayout.cpp @@ -7,10 +7,12 @@ #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; @@ -39,14 +41,12 @@ void PartyLayout::CalculatePositions(int width, int height, 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) { diff --git a/src/battle/PartyLayout.h b/src/battle/PartyLayout.h index e4f7d1b..a50d006 100644 --- a/src/battle/PartyLayout.h +++ b/src/battle/PartyLayout.h @@ -18,6 +18,9 @@ namespace battle { class PartyLayout { + public: + static const int TYPE_ID = 203; + public: PartyLayout() : positions(0), numPositions(0) { } diff --git a/src/battle/Resources.cpp b/src/battle/Resources.cpp index 3320c9f..b3bfb76 100644 --- a/src/battle/Resources.cpp +++ b/src/battle/Resources.cpp @@ -7,9 +7,23 @@ #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 { @@ -83,86 +97,76 @@ Resources::Resources() 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) { diff --git a/src/battle/Resources.h b/src/battle/Resources.h index 051879c..a33cabf 100644 --- a/src/battle/Resources.h +++ b/src/battle/Resources.h @@ -19,6 +19,8 @@ namespace battle { struct Resources { + static const int TYPE_ID = 201; + graphics::Sprite *swapCursor; graphics::Sprite *moveIcons; graphics::Sprite *attackIcons; diff --git a/src/common/Hero.cpp b/src/common/Hero.cpp index bef60a4..02c4dcc 100644 --- a/src/common/Hero.cpp +++ b/src/common/Hero.cpp @@ -7,10 +7,18 @@ #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 { @@ -58,35 +66,28 @@ void Hero::SubtractHealth(int amount) { 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) { diff --git a/src/common/Hero.h b/src/common/Hero.h index caa8f4d..ca4651c 100644 --- a/src/common/Hero.h +++ b/src/common/Hero.h @@ -19,6 +19,9 @@ namespace common { class Hero { +public: + static const int TYPE_ID = 301; + public: Hero(); ~Hero() { } diff --git a/src/common/Ikari.cpp b/src/common/Ikari.cpp index 3a02392..e432149 100644 --- a/src/common/Ikari.cpp +++ b/src/common/Ikari.cpp @@ -7,9 +7,12 @@ #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 { @@ -25,21 +28,16 @@ Ikari::Ikari() 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) { diff --git a/src/common/Ikari.h b/src/common/Ikari.h index 979015b..557e77d 100644 --- a/src/common/Ikari.h +++ b/src/common/Ikari.h @@ -15,6 +15,9 @@ namespace common { // TODO: looks like Ikari and Spell have _quite_ a lot in common… class Ikari { +public: + static const int TYPE_ID = 302; + public: Ikari(); diff --git a/src/common/Item.cpp b/src/common/Item.cpp index 56f083e..2bd337d 100644 --- a/src/common/Item.cpp +++ b/src/common/Item.cpp @@ -7,9 +7,17 @@ #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 { @@ -40,32 +48,25 @@ Item::Item() 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) { diff --git a/src/common/Item.h b/src/common/Item.h index eb60891..2792355 100644 --- a/src/common/Item.h +++ b/src/common/Item.h @@ -19,6 +19,9 @@ namespace common { class Item { +public: + static const int TYPE_ID = 303; + public: Item(); diff --git a/src/common/Spell.cpp b/src/common/Spell.cpp index bcf7f29..4fce22f 100644 --- a/src/common/Spell.cpp +++ b/src/common/Spell.cpp @@ -7,9 +7,12 @@ #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 { @@ -23,21 +26,16 @@ Spell::Spell() 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) { diff --git a/src/common/Spell.h b/src/common/Spell.h index d960126..0f864b8 100644 --- a/src/common/Spell.h +++ b/src/common/Spell.h @@ -15,6 +15,9 @@ namespace common { class Spell { +public: + static const int TYPE_ID = 304; + public: Spell(); diff --git a/src/common/Stats.cpp b/src/common/Stats.cpp index a31d7b5..5a48b66 100644 --- a/src/common/Stats.cpp +++ b/src/common/Stats.cpp @@ -7,9 +7,11 @@ #include "Stats.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace common { @@ -40,20 +42,18 @@ Stats::Stats(Uint16 attack, Uint16 defense, Uint16 strength, Uint16 agility, Uin 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) { diff --git a/src/common/Stats.h b/src/common/Stats.h index 620fc1d..5210ada 100644 --- a/src/common/Stats.h +++ b/src/common/Stats.h @@ -14,6 +14,9 @@ namespace common { 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); diff --git a/src/common/TargetingMode.cpp b/src/common/TargetingMode.cpp index 9f8972c..19b41ec 100644 --- a/src/common/TargetingMode.cpp +++ b/src/common/TargetingMode.cpp @@ -7,9 +7,11 @@ #include "TargetingMode.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace common { @@ -17,16 +19,13 @@ 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) { diff --git a/src/common/TargetingMode.h b/src/common/TargetingMode.h index ef29698..f6f9e53 100644 --- a/src/common/TargetingMode.h +++ b/src/common/TargetingMode.h @@ -14,6 +14,9 @@ namespace common { class TargetingMode { +public: + static const int TYPE_ID = 306; + public: TargetingMode() : mode(0), ally(true) { } diff --git a/src/graphics/Animation.cpp b/src/graphics/Animation.cpp index 2534a26..03bef18 100644 --- a/src/graphics/Animation.cpp +++ b/src/graphics/Animation.cpp @@ -7,17 +7,26 @@ #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")); } } diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index 7424918..be92ca1 100644 --- a/src/graphics/Animation.h +++ b/src/graphics/Animation.h @@ -22,6 +22,9 @@ namespace graphics { class Animation { +public: + static const int TYPE_ID = 401; + public: Animation() : sprite(0), frameTime(0), repeat(false) { } @@ -45,8 +48,10 @@ public: virtual int Row(int frame) const = 0; virtual geometry::Vector Offset(int frame) const { return geometry::Vector(); } + 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; diff --git a/src/graphics/ComplexAnimation.cpp b/src/graphics/ComplexAnimation.cpp index c828e4c..b3784dd 100644 --- a/src/graphics/ComplexAnimation.cpp +++ b/src/graphics/ComplexAnimation.cpp @@ -7,9 +7,11 @@ #include "ComplexAnimation.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace graphics { @@ -18,32 +20,25 @@ void ComplexAnimation::CreateTypeDescription() { 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) { diff --git a/src/graphics/ComplexAnimation.h b/src/graphics/ComplexAnimation.h index e35895d..4e2cb32 100644 --- a/src/graphics/ComplexAnimation.h +++ b/src/graphics/ComplexAnimation.h @@ -15,6 +15,9 @@ namespace graphics { 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) @@ -22,6 +25,7 @@ public: public: struct FrameProp { + static const int TYPE_ID = 403; FrameProp() : col(0), row(0) { } FrameProp(int col, int row, const geometry::Vector &disposition) : col(col), row(row), disposition(disposition) {} diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index efaad15..be96a2c 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -7,6 +7,7 @@ #include "Font.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" #include @@ -14,6 +15,7 @@ using geometry::Vector; using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; using std::pow; @@ -78,10 +80,7 @@ void Font::DrawNumber(int numberIn, SDL_Surface *dest, const Vector &positi 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" @@ -90,9 +89,9 @@ void Font::CreateTypeDescription() { 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) { diff --git a/src/graphics/Font.h b/src/graphics/Font.h index 3fcc7d2..07cd35f 100644 --- a/src/graphics/Font.h +++ b/src/graphics/Font.h @@ -17,6 +17,9 @@ namespace graphics { 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) { diff --git a/src/graphics/Frame.cpp b/src/graphics/Frame.cpp index 01264e8..46fa1b5 100644 --- a/src/graphics/Frame.cpp +++ b/src/graphics/Frame.cpp @@ -7,10 +7,12 @@ #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 { @@ -122,20 +124,17 @@ void Frame::Draw(SDL_Surface *dest, const Vector &position, int width, int 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) { diff --git a/src/graphics/Frame.h b/src/graphics/Frame.h index c6fb602..defa6b1 100644 --- a/src/graphics/Frame.h +++ b/src/graphics/Frame.h @@ -16,6 +16,9 @@ namespace graphics { 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) { } diff --git a/src/graphics/Gauge.cpp b/src/graphics/Gauge.cpp index d0e891a..6f44173 100644 --- a/src/graphics/Gauge.cpp +++ b/src/graphics/Gauge.cpp @@ -7,10 +7,12 @@ #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 { @@ -86,11 +88,7 @@ void Gauge::Draw(SDL_Surface *dest, const Vector &position, int width, Uint 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" @@ -98,13 +96,13 @@ void Gauge::CreateTypeDescription() { 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) { diff --git a/src/graphics/Gauge.h b/src/graphics/Gauge.h index 5938a02..e4750ca 100644 --- a/src/graphics/Gauge.h +++ b/src/graphics/Gauge.h @@ -16,6 +16,9 @@ namespace graphics { 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) { } diff --git a/src/graphics/Menu.cpp b/src/graphics/Menu.cpp index 113e415..7a1f25d 100644 --- a/src/graphics/Menu.cpp +++ b/src/graphics/Menu.cpp @@ -7,9 +7,11 @@ #include "Menu.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace graphics { @@ -17,28 +19,23 @@ 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) { diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index b581fe2..4dc6032 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -19,6 +19,8 @@ namespace graphics { struct MenuProperties { + static const int TYPE_ID = 407; + const Font *font; const Font *disabledFont; const Sprite *cursor; diff --git a/src/graphics/SimpleAnimation.cpp b/src/graphics/SimpleAnimation.cpp index 7ed7993..9162064 100644 --- a/src/graphics/SimpleAnimation.cpp +++ b/src/graphics/SimpleAnimation.cpp @@ -7,9 +7,11 @@ #include "SimpleAnimation.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace graphics { @@ -18,21 +20,16 @@ void SimpleAnimation::CreateTypeDescription() { 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) { diff --git a/src/graphics/SimpleAnimation.h b/src/graphics/SimpleAnimation.h index 8374f08..d5d758f 100644 --- a/src/graphics/SimpleAnimation.h +++ b/src/graphics/SimpleAnimation.h @@ -15,6 +15,9 @@ namespace graphics { class SimpleAnimation : public Animation { +public: + static const int TYPE_ID = 408; + public: SimpleAnimation() : numFrames(0), col(0), row(0) { } diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp index 2495cad..5b50096 100644 --- a/src/graphics/Sprite.cpp +++ b/src/graphics/Sprite.cpp @@ -7,10 +7,12 @@ #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 { @@ -44,19 +46,16 @@ void Sprite::Draw(SDL_Surface *dest, const Vector &position, int col, int r 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) { diff --git a/src/graphics/Sprite.h b/src/graphics/Sprite.h index c22965a..0d5a751 100644 --- a/src/graphics/Sprite.h +++ b/src/graphics/Sprite.h @@ -16,6 +16,9 @@ namespace graphics { 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) diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 6bb022f..5adb08e 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -757,12 +757,12 @@ void Interpreter::Postpone(int type, int id, std::ptrdiff_t offset, const std::s 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" @@ -770,34 +770,33 @@ void Interpreter::CreateTypeDescriptions() { 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)); } diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index 9795a60..e78de12 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -31,6 +31,15 @@ namespace loader { 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) { } diff --git a/src/loader/TypeDescription.cpp b/src/loader/TypeDescription.cpp index 27906fa..bcc480c 100644 --- a/src/loader/TypeDescription.cpp +++ b/src/loader/TypeDescription.cpp @@ -11,11 +11,15 @@ #include #include #include +#include #include 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 { @@ -69,39 +73,52 @@ std::ptrdiff_t TypeDescription::SupertypeOffset(int id) const { } -vector TypeDescription::typeDescriptions; +map TypeDescription::typeDescriptions; +map TypeDescription::typeName2ID; -TypeDescription &TypeDescription::CreateOrGet(const std::string &name) { - for (vector::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::size_type i(0), end(typeDescriptions.size()); i < end; ++i) { - if (typeDescriptions[i].name == name) { - return i; - } + map::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::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 types; - for (vector::const_iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) { - if (i->name != "Animation") { - types.push_back(i->name); + for (map::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()); diff --git a/src/loader/TypeDescription.h b/src/loader/TypeDescription.h index ab8c1bf..0f530d8 100644 --- a/src/loader/TypeDescription.h +++ b/src/loader/TypeDescription.h @@ -70,7 +70,7 @@ public: 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); @@ -89,7 +89,8 @@ private: int id; int size; - static std::vector typeDescriptions; + static std::map typeDescriptions; + static std::map typeName2ID; }; diff --git a/src/main.cpp b/src/main.cpp index 0a69788..f70103a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,32 +62,15 @@ using battle::Monster; 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; @@ -113,28 +96,33 @@ int main(int argc, char **argv) { 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); diff --git a/src/map/Area.cpp b/src/map/Area.cpp index 1b9488a..b6d02f6 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -10,12 +10,14 @@ #include "Tile.h" #include "../graphics/Sprite.h" #include "../loader/TypeDescription.h" +#include "../loader/Interpreter.h" #include "../sdl/utility.h" #include using geometry::Vector; using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace map { @@ -93,17 +95,13 @@ void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const 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) { diff --git a/src/map/Area.h b/src/map/Area.h index 9da3083..d839e96 100644 --- a/src/map/Area.h +++ b/src/map/Area.h @@ -21,6 +21,9 @@ namespace map { /// 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() { } diff --git a/src/map/Entity.cpp b/src/map/Entity.cpp index 9929534..b9261a2 100644 --- a/src/map/Entity.cpp +++ b/src/map/Entity.cpp @@ -7,10 +7,20 @@ #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 { @@ -141,25 +151,18 @@ void Entity::Render(SDL_Surface *dest, const Vector &offset) const { 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) { diff --git a/src/map/Entity.h b/src/map/Entity.h index 8d5c6a5..8832fca 100644 --- a/src/map/Entity.h +++ b/src/map/Entity.h @@ -23,6 +23,9 @@ namespace map { /// interact with the player. class Entity { +public: + static const int TYPE_ID = 605; + public: Entity(); ~Entity() { } diff --git a/src/map/Map.cpp b/src/map/Map.cpp index 3f05962..8ff7f18 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -11,13 +11,16 @@ #include "Tile.h" #include "Trigger.h" #include "../graphics/Sprite.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" #include "../sdl/utility.h" #include using geometry::Vector; +using graphics::Sprite; using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace map { @@ -156,23 +159,16 @@ void Map::RenderDebug(SDL_Surface *dest, const Vector &inOffset) const { 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) { diff --git a/src/map/Map.h b/src/map/Map.h index b751d5e..fbc98f3 100644 --- a/src/map/Map.h +++ b/src/map/Map.h @@ -28,6 +28,9 @@ namespace map { /// extending to the right and down respectively. class Map { +public: + static const int TYPE_ID = 602; + public: Map(); ~Map() { } diff --git a/src/map/Tile.cpp b/src/map/Tile.cpp index 650bbdb..9f75d22 100644 --- a/src/map/Tile.cpp +++ b/src/map/Tile.cpp @@ -7,9 +7,11 @@ #include "Tile.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace map { @@ -24,17 +26,13 @@ Tile::Tile() 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)); } diff --git a/src/map/Tile.h b/src/map/Tile.h index 6706b01..43f9dbb 100644 --- a/src/map/Tile.h +++ b/src/map/Tile.h @@ -16,6 +16,9 @@ namespace map { class Tile { +public: + static const int TYPE_ID = 603; + public: Tile(); ~Tile() { } diff --git a/src/map/Trigger.cpp b/src/map/Trigger.cpp index ff4863d..bc8f163 100644 --- a/src/map/Trigger.cpp +++ b/src/map/Trigger.cpp @@ -7,9 +7,11 @@ #include "Trigger.h" +#include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" using loader::FieldDescription; +using loader::Interpreter; using loader::TypeDescription; namespace map { @@ -24,17 +26,13 @@ Trigger::Trigger() 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) { diff --git a/src/map/Trigger.h b/src/map/Trigger.h index eb17460..d1b915e 100644 --- a/src/map/Trigger.h +++ b/src/map/Trigger.h @@ -17,6 +17,9 @@ namespace map { class Trigger { +public: + static const int TYPE_ID = 604; + public: Trigger(); ~Trigger() { } -- 2.39.2