-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime.ts
97 lines (80 loc) · 2.74 KB
/
runtime.ts
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
const s = [
"border: solid 4px #fb5900",
"border-radius: 8px",
"color: white",
"backround-color: black",
"padding: 10px",
"font-size: 20px",
"font-weigth: bold"
].join(";");
console.log("%cAWAYFL: __VERSION__\nBUILD: __DATE__", s);
import { AVM1Handler } from "@awayfl/avm1";
import { AVM2Handler } from "@awayfl/avm2";
import { LoaderInfo, PlayerGlobal } from "@awayfl/playerglobal";
import { AVMStage } from "@awayfl/swf-loader";
import { Settings as GraphicsSettings } from '@awayjs/graphics';
import { Settings as SceneSettings } from "@awayjs/scene";
//@ts-ignore;
export const VERSION = "__VERSION__";
//@ts-ignore
export const RUNTIME = JSON.parse(__LIBS__);
export class Player extends AVMStage {
constructor(public container: HTMLDivElement, conf: any) {
super(Object.assign({
x:'0%', y: '0%', w: '100%', h: '100%',
stageScaleMode: 'showAll', runtimeFlags : {}
}, conf || {}));
const runtime = this._gameConfig.runtimeFlags;
GraphicsSettings.SMOOTH_BITMAP_FILL_DEFAULT = runtime.defaultSmoothBitmap;
SceneSettings.USE_UNSAFE_BLENDS = runtime.enableBlends;
SceneSettings.USE_UNSAFE_FILTERS = runtime.enableFilters;
if(!this._gameConfig.files) {
this._gameConfig.files = [];
}
this._gameConfig.files.push(
{
path: `${(conf?.baseUrl ? conf?.baseUrl + "/" : "")}assets/fonts.swf`,
resourceType: <any>"FONTS"
},
);
if (conf?.baseUrl) {
// builtins located in assets
PlayerGlobal.builtinsBaseUrl = conf.baseUrl + '/assets/builtins';
}
this.registerAVMStageHandler( new AVM1Handler());
this.registerAVMStageHandler( new AVM2Handler(new PlayerGlobal()));
}
loadAndPlay(): Promise<void> {
return new Promise((res, rej) => {
this.addEventListener('loaderComplete', () =>{
this.play();
res();
});
this.addEventListener('loadError', (r) => {
rej(r);
});
this.load();
});
}
loadBuffer(buffer: ArrayBuffer): Promise<void> {
this._gameConfig.files.push({
//@ts-ignore
data: buffer, path: 'assets/game.swf', resourceType: "GAME"
});
return new Promise((res)=>{
this.addEventListener('loaderComplete', () => res());
this.loadNextResource();
});
}
play() {
super.play();
//@ts-ignore
this.resizeCallback();
}
stop() {
//@ts-ignore
this._timer.stop();
//@ts-ignore
this._timer.setCallback(undefined, undefined);
}
}