미디어위키:Gadget-godot3.js: 두 판 사이의 차이
둘러보기로 이동
검색으로 이동
(CDN 주소 부분 제거 및 틀:고도3으로 넘김) |
잔글편집 요약 없음 태그: 수동 되돌리기 |
||
(같은 사용자의 중간 판 3개는 보이지 않습니다) | |||
30번째 줄: | 30번째 줄: | ||
function ExecuteSupplementScript(){ | function ExecuteSupplementScript(){ | ||
var gamepath = String(document.getElementById("libertygame-godot3-basegamepath").innerText); | var gamepath = String(document.getElementById("libertygame-godot3-basegamepath").innerText); | ||
var myPck = "https:/ | var myPck = "https://" + gamepath+".pck"; | ||
var engine = new Engine(); | var engine = new Engine(); | ||
Promise.all([ | Promise.all([ | ||
// Load and init the engine | // Load and init the engine | ||
engine.init("https:/ | engine.init("https://"+gamepath), | ||
// And the pck concurrently | // And the pck concurrently | ||
engine.preloadFile(myPck), | engine.preloadFile(myPck), | ||
60번째 줄: | 60번째 줄: | ||
basegamepath = String(document.getElementById("libertygame-godot3-basegamepath").innerText); | basegamepath = String(document.getElementById("libertygame-godot3-basegamepath").innerText); | ||
console.log("basepath is "+ basegamepath); | console.log("basepath is "+ basegamepath); | ||
godot3_asyncJSLoader("https:/ | godot3_asyncJSLoader("https://"+basegamepath + ".js", "text/javascript") | ||
.then(function (data) { | .then(function (data) { | ||
ExecuteSupplementScript(); | ExecuteSupplementScript(); |
2024년 4월 16일 (화) 23:38 기준 최신판
/**
* 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://" + gamepath+".pck";
var engine = new Engine();
Promise.all([
// Load and init the engine
engine.init("https://"+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 + ".js", "text/javascript")
.then(function (data) {
ExecuteSupplementScript();
});
} catch (e){
console.log("initiating Godot 3 for libertygame failed, stop loading elements...");
}
}
$(Godot3_loadElement);