-/*
- * ComplexAnimation.cpp
- *
- * Created on: Sep 5, 2012
- * Author: holy
- */
-
#include "ComplexAnimation.h"
+#include "../loader/Interpreter.h"
#include "../loader/TypeDescription.h"
+using math::Vector;
using loader::FieldDescription;
+using loader::Interpreter;
using loader::TypeDescription;
namespace graphics {
+ComplexAnimation::ComplexAnimation()
+: frames(0)
+, numFrames(0) {
+
+}
+
+ComplexAnimation::ComplexAnimation(
+ const Sprite *sprite,
+ int frameTime,
+ bool repeat)
+: Animation(sprite, frameTime, repeat)
+, frames(0)
+, numFrames(0) {
+
+}
+
+
+int ComplexAnimation::NumFrames() const {
+ return numFrames;
+}
+
+int ComplexAnimation::Col(int frame) const {
+ return frames[frame].col;
+}
+
+int ComplexAnimation::Row(int frame) const {
+ return frames[frame].row;
+}
+
+Vector<int> ComplexAnimation::Offset(int frame) const {
+ return frames[frame].disposition;
+}
+
+
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) {