]> git.localhorst.tv Git - l2e.git/blob - src/graphics/SimpleAnimation.cpp
new language, new compiler
[l2e.git] / src / graphics / SimpleAnimation.cpp
1 #include "SimpleAnimation.h"
2
3 #include "../loader/Interpreter.h"
4 #include "../loader/TypeDescription.h"
5
6 using loader::FieldDescription;
7 using loader::Interpreter;
8 using loader::TypeDescription;
9
10 namespace graphics {
11
12 SimpleAnimation::SimpleAnimation()
13 : numFrames(0)
14 , col(0)
15 , row(0) {
16
17 }
18
19 SimpleAnimation::SimpleAnimation(
20                 const Sprite *sprite,
21                 int frameTime,
22                 int numFrames,
23                 int col,
24                 int row,
25                 bool repeat)
26 : Animation(sprite, frameTime, repeat)
27 , numFrames(numFrames)
28 , col(col)
29 , row(row) {
30
31 }
32
33 SimpleAnimation::SimpleAnimation(loader::noinit_t n)
34 : Animation(n) {
35
36 }
37
38
39 int SimpleAnimation::NumFrames() const {
40         return numFrames;
41 }
42
43 int SimpleAnimation::Col(int frame) const {
44         return col;
45 }
46
47 int SimpleAnimation::Row(int frame) const {
48         return row + frame;
49 }
50
51
52 void SimpleAnimation::CreateTypeDescription() {
53         SimpleAnimation sa;
54         Animation *a(&sa);
55
56         TypeDescription &td(TypeDescription::Create(TYPE_ID, "SimpleAnimation"));
57         td.SetDescription("An animation that uses a fixed column and increasing row of a sprite based on the frame number.");
58         td.SetConstructor(&Construct);
59         td.SetInitializer(&Initialize);
60         td.SetSize(sizeof(SimpleAnimation));
61         td.AddSupertype(Animation::TYPE_ID, ((char *)a) - ((char *)&sa));
62
63         Animation::AddFields(td, sa, ((char *)a) - ((char *)&sa));
64         td.AddField("framecount", FieldDescription(((char *)&sa.numFrames) - ((char *)&sa), Interpreter::NUMBER_ID).SetDescription("number of frames of a single run"));
65         td.AddField("col", FieldDescription(((char *)&sa.col) - ((char *)&sa), Interpreter::NUMBER_ID).SetDescription("the column of the sprite to draw from"));
66         td.AddField("row", FieldDescription(((char *)&sa.row) - ((char *)&sa), Interpreter::NUMBER_ID).SetDescription("the row of the sprite of the first frame"));
67 }
68
69 void SimpleAnimation::Construct(void *data) {
70         new (data) SimpleAnimation;
71 }
72
73 void SimpleAnimation::Initialize(void *data) {
74         new (data) SimpleAnimation(loader::noinit);
75 }
76
77 }