-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntity.ms
75 lines (60 loc) · 1.63 KB
/
Entity.ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
let Entity = {
create = => {
let tag = null;
return {
components = {},
world = null,
inView = false,
getTag = -> { return tag; },
setTag = |newTag| -> {
if (this.world != null) {
this.world->setEntityTag(this, newTag);
}
tag = newTag;
}
} @ Entity;
},
addComponent = |component| -> {
this.components[component->getType()] = component;
},
removeComponent = |component| -> {
this.components[component->getType()] = null;
},
getComponent = |type| -> {
return this.components[type];
},
isInView = -> {
return this.inView;
},
getBB = func entityGetBB -> {
let sr = this.SpriteRenderer;
let fa = this.FrameAnimation;
let ca = this.Camera;
let tr = this.Transform;
if (tr == null) {
return null;
}
let size = null;
if (fa != null) {
size = fa->getSize();
} else if (sr != null) {
size = sr->getSize();
} else if (ca != null) {
return ca->getBB(tr);
}
if (size == null) {
return null;
}
return tr->getBB(size);
},
[object.symbols.getPropertyOperator] = |prop| -> {
if (!object.hasKey(Entity, prop) && !object.hasKey(this, prop)) {
let v = this->getComponent(prop);
if (v != null) {
return v;
}
}
return false;
}
};
return Entity;