forked from dumorando/dumorando.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnail.js
More file actions
59 lines (52 loc) · 1.59 KB
/
snail.js
File metadata and controls
59 lines (52 loc) · 1.59 KB
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
// make the div for the ui section
// reference vm.runtime.renderer.canvas
if (CurrentUI) {
CurrentUI = null;
}
let snailjsdiv = null;
if (!document.getElementById("SNAILJS_UICANVAS")) {
snailjsdiv = document.createElement("div");
snailjsdiv.id = "SNAILJS_UICANVAS";
} else {
snailjsdiv = document.getElementById("SNAILJS_UICANVAS");
}
class UIManagement {
constructor() {
this._div = snailjsdiv;
this.Realign();
}
Realign() {
this._div.style = `position: absolute;left: 0px;width: 100%;height: 100%;top: 0px;z-index: 1000;`
if (!vm.runtime.renderer) return;
vm.runtime.renderer.canvas.parentElement.prepend(this._div);
}
}
var CurrentUI = new UIManagement();
setInterval(() => CurrentUI.Realign(), 100)
window.snailjs = {
loadScriptPromise: (url) => {
return new Promise((resolve, reject) => {
let newscript = document.createElement("script");
newscript.onload = function() { //instead of using arrow functions, im using classic functions cuz idk if arrow functions work with these
resolve()
}
newscript.onerror = function() {
reject()
}
newscript.src = url;
document.body.appendChild(newscript);
});
},
ui: {
addElement: (element) => {
CurrentUI._div.appendChild(element);
CurrentUI.Realign();
},
getParent: () => {
return CurrentUI._div;
},
clearScreen: () => {
CurrentUI._div.innerHTML = "";
}
}
}