-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Polyfill.ts
114 lines (103 loc) · 4.15 KB
/
Polyfill.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//@ts-nocheck
/**
* Polyfills missing GDevelop API features for games made with older versions of GDevelop.
*/
export const installPolyfills = () => {
if (!gdjs.callbacksFirstRuntimeSceneLoaded) {
gdjs.callbacksFirstRuntimeSceneLoaded = [];
const RuntimeSceneCtr = gdjs.RuntimeScene;
let once = false;
gdjs.RuntimeScene = function (...args) {
RuntimeSceneCtr.apply(this, args);
if (!once) {
once = true;
for (const e of gdjs.callbacksFirstRuntimeSceneLoaded) e(this);
}
};
Object.assign(gdjs.RuntimeScene, RuntimeSceneCtr);
gdjs.RuntimeScene.prototype = Object.create(RuntimeSceneCtr.prototype);
}
if (!gdjs.callbacksRuntimeSceneLoaded) {
gdjs.callbacksRuntimeSceneLoaded = [];
const RuntimeSceneCtr = gdjs.RuntimeScene;
gdjs.RuntimeScene = function (...args) {
RuntimeSceneCtr.apply(this, args);
for (const e of gdjs.callbacksRuntimeSceneLoaded) e(this);
};
Object.assign(gdjs.RuntimeScene, RuntimeSceneCtr);
gdjs.RuntimeScene.prototype = Object.create(RuntimeSceneCtr.prototype);
}
if (!gdjs.callbacksRuntimeScenePreEvents) {
gdjs.callbacksRuntimeScenePreEvents = [];
const renderAndStep = gdjs.RuntimeScene.prototype.renderAndStep;
gdjs.RuntimeScene.prototype.renderAndStep = function (...args) {
for (const e of gdjs.callbacksRuntimeScenePreEvents) e(this);
return renderAndStep.apply(this, args);
};
}
if (!gdjs.callbacksRuntimeScenePostEvents) {
gdjs.callbacksRuntimeScenePostEvents = [];
const renderAndStep = gdjs.RuntimeScene.prototype.renderAndStep;
gdjs.RuntimeScene.prototype.renderAndStep = function (...args) {
const retVal = renderAndStep.apply(this, args);
for (const e of gdjs.callbacksRuntimeScenePostEvents) e(this);
return retVal;
};
}
if (!gdjs.callbacksRuntimeSceneUnloading) {
gdjs.callbacksRuntimeSceneUnloading = [];
const unloadScene = gdjs.RuntimeScene.prototype.unloadScene;
gdjs.RuntimeScene.prototype.unloadScene = function (...args) {
for (const e of gdjs.callbacksRuntimeSceneUnloading) e(this);
return unloadScene.apply(this, args);
};
}
if (!gdjs.callbacksRuntimeSceneUnloaded) {
gdjs.callbacksRuntimeSceneUnloaded = [];
const unloadScene = gdjs.RuntimeScene.prototype.unloadScene;
gdjs.RuntimeScene.prototype.unloadScene = function (...args) {
const retVal = unloadScene.apply(this, args);
for (const e of gdjs.callbacksRuntimeSceneUnloaded) e(this);
return retVal;
};
}
if (!gdjs.callbacksRuntimeScenePaused) {
gdjs.callbacksRuntimeScenePaused = [];
const push = gdjs.SceneStack.prototype.push;
gdjs.SceneStack.prototype.push = function (...args) {
const retVal = push.apply(this, args);
for (const e of gdjs.callbacksRuntimeScenePaused) e(GDAPI.currentScene);
return retVal;
};
}
if (!gdjs.callbacksRuntimeSceneResumed) {
gdjs.callbacksRuntimeSceneResumed = [];
const pop = gdjs.SceneStack.prototype.pop;
gdjs.SceneStack.prototype.pop = function (...args) {
const retVal = pop.apply(this, args);
for (const e of gdjs.callbacksRuntimeSceneResumed) e(GDAPI.currentScene);
return retVal;
};
}
if (!gdjs.callbacksObjectDeletedFromScene) {
gdjs.callbacksObjectDeletedFromScene = [];
const deleteFromScene = gdjs.RuntimeObject.prototype.deleteFromScene;
gdjs.RuntimeObject.prototype.deleteFromScene = function (...args) {
const retVal = deleteFromScene.apply(this, args);
for (const e of gdjs.callbacksObjectDeletedFromScene) e(this);
return retVal;
};
}
gdjs.RuntimeScene.prototype.registerObject =
gdjs.RuntimeScene.prototype.registerObject ||
function (objectData) {
this._objects.put(objectData.name, objectData);
this._instances.put(objectData.name, []); //Also reserve an array for the instances
this._instancesCache.put(objectData.name, []); //and for cached instances
this._objectsCtor.put(
objectData.name,
gdjs.getObjectConstructor(objectData.type)
); //And cache the constructor for the performance sake
};
PIXI.Texture.fromURL = PIXI.Texture.fromURL || PIXI.Texture.from;
};