-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathstage.as
444 lines (331 loc) · 10.1 KB
/
stage.as
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
stop();
stage.quality = "best";
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.net.*;
//var loadfont: URLLoader = new URLLoader();
//loadfont.load(new URLRequest("双字体.swf"));
var loadcfg: URLLoader = new URLLoader();
loadcfg.dataFormat = URLLoaderDataFormat.TEXT;
loadcfg.addEventListener(Event.COMPLETE, cfgLoaded);
loadcfg.load(new URLRequest("config.csv"));
var cfg: Array;
var fp: int;
var RKcon: Sprite = new Sprite(); // RankBar 容器
var BKcon: Sprite = new Sprite(); // 背景线容器
var bkList: Array;
var bk: bkgL;
var wid: Number;
function cfgLoaded(evt: Event): void {
cfg = loadcfg.data.split("\n");
for(i = 0; i < cfg.length; i++) {
cfg[i] = cfg[i].split(",");
}
stage.color = cfg[2][0];
var icon: Loader = new Loader();
icon.contentLoaderInfo.addEventListener(Event.COMPLETE, bkgLoaded);
icon.load(new URLRequest(cfg[2][2]));
stage.frameRate = int(cfg[5][0]);
fp = cfg[6][0]; // 几帧过一个数据
RKcon.x = cfg[20][0];
RKcon.y = cfg[21][0];
addChildAt(RKcon, 1);
BKcon.x = RKcon.x + Number(cfg[24][0]);
BKcon.y = RKcon.y - Number(cfg[52][0]);
addChildAt(BKcon, 0);
bkList = cfg[48];
for(i = 0; i < bkList.length; i++) {
bk = new bkgL();
bk.initialize(bkList[i], cfg);
BKcon.addChild(bk);
}
tltext.x = cfg[58][0];
tltext.y = cfg[59][0];
tltext.text = cfg[60][0];
var format1: TextFormat = new TextFormat();
format1.color = cfg[2][1];
format1.size = cfg[61][0];
tltext.setTextFormat(format1);
yeart.x = cfg[76][0];
yeart.y = cfg[77][0];
current.x = Number(cfg[79][0]); //yeart.x +
current.y = Number(cfg[80][0]);
wid = cfg[78][1] * cfg[81][0];
kuangmo.x = cfg[91][0];
kuangmo.y = cfg[92][0];
shichang.x = kuangmo.x;
shichang.y = kuangmo.y + 78;
}
// include "data.as";
var loader: URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, dataLoaded);
loader.load(new URLRequest("data.csv"));
var da: Array;
var Num: int;
var rk: rankBar;
var pofix: String; // 所加载图片的后缀
function dataLoaded(evt: Event): void {
da = loader.data.split("\n");
for(i = 0; i < da.length; i++) {
da[i] = da[i].split(",");
}
// 从第3行第1列开始过滤非数字
for(i = 3; i < da.length; i++) {
for(j = 1; j < da[i].length; j++){
da[i][j] = Number(da[i][j]);
if(isNaN(da[i][j])){
da[i][j]=0;
}
}
}
pofix = da[0][0];
Num = da[1].length - 1; // 计算条目数
for(i = 0; i < Num; i++) {
rk = new rankBar();
rk.initialize(i + 1, da[0][i + 1], da[1][i + 1], da[2][i + 1], pofix, cfg, da[3][i + 1]);
RKcon.addChildAt(rk, i);
}
stage.addEventListener(Event.ENTER_FRAME, movie);
}
var i: int;
var j: int;
var t: int = -1;
var T: int = 2; // 数据从第4行开始
var tres: int = 0;
var bar1: rankBar;
var bar2: rankBar;
var po: Number=0.0001; // population
var maxr: Number; // 计算缩放率用
var maxfan: Number; // 只缩不放用
var absmaxr:Number; // 兼容负数据用
var Tcon: Sprite = new Sprite(); // 冠军条容器
addChildAt(Tcon, 3);
var rect: Sprite = new Sprite();
Tcon.addChild(rect);
var lastid: String; // 更新冠军头像
var Icon: Sprite = new Sprite(); // 冠军头像容器
addChildAt(Icon, 0);
var curbub:CurBub = new CurBub(); //当前冠军
function movie(event: Event): void {
if(t == 0) {
// 解决某个 as 的 bug
maxr = 0;
absmaxr = 0;
maxfan = 0;
lastid = "2";
//stage.frameRate = 0; // 启动时暂停
}
if(t < da.length * fp) {
t++;
} else {
stage.removeEventListener(Event.ENTER_FRAME, movie);
}
tres = t % fp;
if(tres == 0) {
T++;
if(T < da.length) {
yeart.text = da[T][0];
}
if(T < da.length - 1) {
if(cfg[14][0]=="1"){
for(j=1; j<da[T].length; j++){
da[T+1][j]=Number(da[T+1][j])+Number(da[T][j])
}
} // 将数据替换成一阶积分
}
}
for(i = 0; i < RKcon.numChildren; i++) {
rk = RKcon.getChildAt(i) as rankBar;
j = rk.n;
if(T < da.length - 1) {
if(cfg[13][0]=="2"){ // 关掉线性补间,使用变速缓冲
po = rk.po + (da[T][j]-rk.po)/Number(cfg[8][0]);
}else if(cfg[13][0]=="3"){
po = rk.po + (da[T+1][j]-rk.po)/Number(cfg[8][0]);
}else{
po = da[T][j] * (1 - tres/fp) + da[T + 1][j] * tres/fp; // 线性补间
}
rk.update(po);
}
}
var RKmax = RKcon.numChildren-1;
if(t%int(cfg[125][0])==1){ // 自定义每几帧更新次水印
for(i = RKmax; i >= 0; i--) {
bar1 = RKcon.getChildAt(i) as rankBar;
bar1.updateWater();
}
}
if(!isNaN(cfg[15][0])){
if(t%int(cfg[15][0])==1){ // 自定义每几帧更新次排序
// 冒泡排序法(反转,最大的放最上层
for(i = RKmax; i >= 0; i--) {
bar1 = RKcon.getChildAt(i) as rankBar;
for(j = i + 1; j <= RKmax; j++) {
var bar2: rankBar = RKcon.getChildAt(j) as rankBar;
if(bar1.fan > bar2.fan) {
bar1.rank = RKmax-j;
}else{
break;
}
}
RKcon.setChildIndex(bar1, RKmax-bar1.rank);
}
}
}
// 可选宽度跟随第几名
bar1 = RKcon.getChildAt(RKmax-int(cfg[75][1]-1)) as rankBar;
maxr += (Number(cfg[51][0]) / userfunc(bar1.fan, maxfan, cfg[53][0] == "1") - maxr) / Number(cfg[7][0]); // 加点缓冲
if(Math.abs(maxfan) < Math.abs(bar1.fan)) {
maxfan = bar1.fan;
} else {
maxfan += (bar1.fan - maxfan) * Number(cfg[54][0]); // 带缓冲地回缩
}
absmaxr = Math.abs(maxr);
for(i = 0; i < RKcon.numChildren; i++) {
bar1 = RKcon.getChildAt(i) as rankBar;
bar1.rank = RKmax-i;
bar1.updatey(bar1.rank, absmaxr); //bkggrid.scaleX
}
for(i = 0; i < BKcon.numChildren; i++) {
bk = BKcon.getChildAt(i) as bkgL;
bk.updatex(absmaxr);
}
// 可选高亮第几名
bar1 = RKcon.getChildAt(RKmax-int(cfg[75][0]-1)) as rankBar;
// 冠军条
yeart.x += Number(cfg[78][0]);
current.x += Number(cfg[78][1]);
Tcon.x -= Number(cfg[78][2]);
if(t % int(cfg[81][0]) == 0) {
rect.graphics.beginFill(bar1.col);
// rect.graphics.drawRect(current.x - wid, current.y + 63, wid, cfg[82][0]);
rect.graphics.drawRect(current.x - wid, current.y + 75-userheight(bar1), wid, userheight(bar1));
rect.graphics.endFill();
}
if(t % fp == 0 && da[T][0].slice(int(cfg[84][0]), int(cfg[84][1])) == cfg[84][2]) {
var ye: yearL = new yearL();
ye.te.text = da[T][0].slice(int(cfg[84][3]), int(cfg[84][4]));
ye.x = current.x;
ye.y = current.y + Number(cfg[85][0]);
Tcon.addChildAt(ye, 0);
}
kuangmo.text = cfg[93][0] + bar1.cn;
shichang.text = cfg[94][0] + bar1.fan.toFixed(cfg[95][0]) + cfg[96][0];
if(t == 2) { // 启动时冠军头像多检查一次更新
var icon: Loader = new Loader();
icon.contentLoaderInfo.addEventListener(Event.COMPLETE, iconLoaded);
icon.load(new URLRequest(bar1.id + pofix));
lastid = bar1.id;
Icon.removeChildAt(0);
}
if(bar1.id != lastid && t > 2) {
var icon2: Loader = new Loader();
icon2.contentLoaderInfo.addEventListener(Event.COMPLETE, iconLoaded);
icon2.load(new URLRequest(bar1.id + pofix));
curbub = new CurBub();
curbub.loadp(bar1.id + pofix);
curbub.x=current.x-15;
curbub.y=current.y+75-15;
Tcon.addChild(curbub);
lastid = bar1.id;
}else{
curbub.x += Number(cfg[78][1])/2;
}
}
function userfunc(fan: Number, maxf: Number, iflog: Boolean): Number {
var temp: Number;
if(Math.abs(maxf) < Math.abs(fan)) {
temp = fan;
} else {
temp = maxf;
}
if(iflog) {
return(Math.log(1 + temp))
} else {
return(temp)
}
}
function userheight(bar1:rankBar):Number{
if(cfg[82][0]=="A"){
return(bar1.fan/Number(cfg[82][1]))
}else if(cfg[82][0]=="D"){
return((Number(da[T+int(cfg[82][2])][bar1.n])-Number(da[T][bar1.n]))/Number(cfg[82][1]))
}else{
return(Number(cfg[82][0]))
}
}
function iconLoaded(e: Event): void {
var image: Bitmap = new Bitmap(e.target.content.bitmapData);
image.x = Number(cfg[97][0]);
image.y = Number(cfg[98][0]);
// image.width = cfg[99][0];
// image.height = cfg[100][0];
image.scaleX = Number(cfg[99][0])/image.width;
image.scaleY = image.scaleX;
image.alpha=0;
image.addEventListener(Event.ENTER_FRAME, fadein);
if(Icon.numChildren > 0) {
Icon.getChildAt(0).addEventListener(Event.ENTER_FRAME, fadeout);
}
if(cfg[99][1]=="1"){ // 裁圆形
var maskCircle: Sprite = new Sprite();
maskCircle.graphics.beginFill(0x000000);
maskCircle.graphics.drawEllipse(image.x, image.y, image.width, image.width);
maskCircle.graphics.endFill();
maskCircle.visible = false;
Icon.addChild(maskCircle);
image.mask = maskCircle;
}
Icon.addChild(image);
}
function fadein(event: Event): void {
if(event.target.alpha<Number(cfg[100][0])){ event.target.alpha+=Number(cfg[101][0])}
else{event.target.alpha=Number(cfg[100][0]);event.target.removeEventListener(Event.ENTER_FRAME, fadein);}
}
function fadeout(event: Event): void {
if(event.target.alpha>0){ event.target.alpha-=Number(cfg[101][0])}
else{event.target.alpha=0;event.target.removeEventListener(Event.ENTER_FRAME, fadeout); Icon.removeChildAt(0);}
}
var bkimage: Bitmap;
function bkgLoaded(e: Event): void {
bkimage = new Bitmap(e.target.content.bitmapData);
bkimage.scaleX = 1920/bkimage.width;
bkimage.scaleY = bkimage.scaleX;
bkimage.alpha=cfg[2][3];
addChildAt(bkimage,0);
}
var fadeupy:Number = 0;
addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
function keyPressed(event: KeyboardEvent): void {
if(event.keyCode == Keyboard.SPACE) {
if(stage.frameRate <= 1){
stage.frameRate = int(cfg[5][0]);
}else{
stage.frameRate = 0;
}
}
// 方向键控制柱子移动
if(event.keyCode == Keyboard.RIGHT) {
RKcon.x+=2;
}
if(event.keyCode == Keyboard.LEFT) {
RKcon.x-=2;
}
if(event.keyCode == Keyboard.UP) {
fadeupy = RKcon.y - Number(cfg[16][0]);
RKcon.addEventListener(Event.ENTER_FRAME, fadeup);
}
if(event.keyCode == Keyboard.DOWN) {
fadeupy = RKcon.y + Number(cfg[16][0]);
RKcon.addEventListener(Event.ENTER_FRAME, fadeup);
}
}
function fadeup(event: Event): void {
RKcon.y -= (RKcon.y-fadeupy)/Number(cfg[16][1]);
if(Math.abs(RKcon.y-fadeupy)<1){
RKcon.y = fadeupy;
event.target.removeEventListener(Event.ENTER_FRAME, fadeup);
}
}