-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprites.js
77 lines (65 loc) · 1.97 KB
/
sprites.js
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
76
77
function Sprite(type, colour)
{
this._constructor_unit =
function(filename)
{
this.svg_object = create_group(mySvg);
create_image(this.svg_object, 0, 0, filename);
}
this._constructor_building =
function(filename)
{
this.svg_object = create_group(mySvg);
create_image(this.svg_object, 0, 0, filename, 3, 3);
}
this.fill = colour;
this.text_object = null;
switch (type)
{
case "building" : this._constructor_building("tower.svg"); break;
default: this._constructor_unit(type+".svg");
}
var elems = this.svg_object.getElementsByTagName("*");
for (var i = 0; i < elems.length ;i++)
{
if (elems[i].getAttribute("class") == "team_col")
{
elems[i].setAttribute("fill", this.fill);
}
}
this.setPosition =
function(x, y)
{
this.svg_object.setAttributeNS(null, "transform", "translate("+x+","+y+")");
}
this.setText =
function(value)
{
assert(this.text_object == null);
this.text_object = create_text(this.svg_object, value, -(hex_size / 2), -(hex_size / 4), "black");
}
this.changeText =
function(value)
{
update_text(this.text_object, value);
}
}
Sprite.prototype.addStyleSheet =
function(filename)
{
var s = document.createElementNS(svgns, "LINK");
s.setAttribute("rel", "stylesheet");
s.setAttribute("type", "text/css");
s.setAttribute("href", filename);
this.svg_object.appendChild(s);
}
Sprite.prototype.setOpacity =
function(alpha)
{
this.svg_object.setAttribute("opacity", ""+alpha);
}
Sprite.prototype.destroy =
function()
{
this.svg_object.parentNode.removeChild(this.svg_object);
}