-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdynamicWorker.js
92 lines (77 loc) · 2.07 KB
/
dynamicWorker.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
importScripts('spine.js', 'animation.js');
Array.prototype.remove = function (item) {
var index = this.indexOf(item);
if (index >= 0) return this.splice(index, 1);
return item;
}
var window = self;
var devicePixelRatio = 1;
var documentZoom = 1;
var HTMLCanvasElement = function () { return 'HTMLCanvasElement'; };
var HTMLElement = function () { return 'HTMLElement'; };
var dynamics = [];
dynamics.getById = function (id) {
for (var i = 0; i < this.length; i++) {
if (this[i].id == id) return this[i];
}
return null;
};
onmessage = function (e) {
var data = e.data;
switch (data.message) {
case 'CREATE':
if (dynamics.length >= 4) return;
var dynamic = new duilib.AnimationPlayer(data.pathPrefix, 'offscreen', data.canvas);
dynamic.id = data.id;
dynamics.push(dynamic);
break;
case 'PLAY':
var dynamic = dynamics.getById(data.id);
if (!dynamic) return;
update(dynamic, data);
var sprite = (typeof data.sprite == 'string') ? { name: data.sprite } : data.sprite;
sprite.loop = true;
var run = function () {
var t = dynamic.playSpine(sprite);
t.opacity = 0;
t.fadeTo(1, 600);
};
if (dynamic.hasSpine(sprite.name)) {
run();
} else {
dynamic.loadSpine(sprite.name, 'skel', run);
}
break;
case 'STOP':
var dynamic = dynamics.getById(data.id);
if (!dynamic) return;
dynamic.stopSpine(data.sprite);
break;
case 'STOPALL':
var dynamic = dynamics.getById(data.id);
if (!dynamic) return;
dynamic.stopSpineAll();
break;
case 'UPDATE':
var dynamic = dynamics.getById(data.id);
if (!dynamic) return;
update(dynamic, data);
break;
}
};
function update(dynamic, data) {
dynamic.resized = false;
if (data.dpr != null)
dynamic.dpr = data.dpr;
if (data.dprAdaptive != null)
dynamic.dprAdaptive = data.dprAdaptive;
if (data.outcropMask != null)
dynamic.outcropMask = data.outcropMask;
if (data.useMipMaps != null)
dynamic.useMipMaps = data.useMipMaps;
if (data.width != null)
dynamic.width = data.width;
if (data.height != null)
dynamic.height = data.height;
}