미디어위키:Gadget-godot3.js
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 인터넷 익스플로러 / 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
- 오페라: Ctrl-F5를 입력.
/**
* Godot3 for Libertygame loader
* 제작자: [[사용자:senouis]]
**/
function godot3_asyncJSLoader(url, type) {
return new Promise(function (resolve, reject) {
try {
var scriptElement = document.createElement("script");
scriptElement.src = url;
scriptElement.async = true; // force asynchronous loading
scriptElement.type = type;
var contextsection = document.getElementById("mw-content-text");
scriptElement.addEventListener("load", function (ev) {
resolve({ status: true });
});
scriptElement.addEventListener("error", function (ev) {
reject({
status: false,
message: "Failed to load the script"
});
});
contextsection.appendChild(scriptElement);
} catch (e) {
reject(e);
}
});
}
function ExecuteSupplementScript(){
var gamepath = String(document.getElementById("libertygame-godot3-basegamepath").innerText);
var myPck = "https://cdn.jsdelivr.net/gh/" + gamepath+".pck";
var engine = new Engine();
Promise.all([
// Load and init the engine
engine.init("https://cdn.jsdelivr.net/gh/"+gamepath),
// And the pck concurrently
engine.preloadFile(myPck),
]).then(function () {
// Now start the engine.
return engine.start({ args: ['--main-pack', myPck],executable: "https://"+gamepath, canvasResizePolicy:1});
}).then(function () {
console.log('Godot 3 Engine has started!');
});
}
var basegamepath = "";
function Godot3_loadElement() {
try {
// Game canvas
var canvas = document.createElement("canvas");
canvas.id = "canvas";
var ratio = 640 / canvas.width;
canvas.height = canvas.height * ratio;
canvas.width = 640;
canvas.innerHTML = "로딩 중...";
var canvasparent = document.getElementById("libertygame-godot3"); // first element of emscripten-border
canvasparent.appendChild(canvas);
// now load js files from external server
basegamepath = String(document.getElementById("libertygame-godot3-basegamepath").innerText);
console.log("basepath is "+ basegamepath);
godot3_asyncJSLoader("https://"+basegamepath, "text/javascript")
.then(function (data) {
ExecuteSupplementScript();
});
} catch (e){
console.log("initiating Godot 3 for libertygame failed, stop loading elements...");
}
}
$(Godot3_loadElement);