미디어위키:Gadget-UE4.js: 두 판 사이의 차이

리버티게임, 모두가 만들어가는 자유로운 게임
잔글편집 요약 없음
잔글편집 요약 없음
태그: 되돌려진 기여
43번째 줄: 43번째 줄:
asyncJSLoader("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js", "text/javascript")
asyncJSLoader("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js", "text/javascript")
.then(function (data) {
.then(function (data) {
asyncJSLoader("https://cdn.jsdelivr.net/"+liberty_gamepath + liberty_gamename, "text/javascript")
asyncJSLoader("https://cdn.jsdelivr.net/"+liberty_gamepath + liberty_gamename+".js", "text/javascript")
.then(function (data) {
.then(function (data) {
console.log("UE4 Game Loaded!");
console.log("UE4 Game Loaded!");

2024년 1월 18일 (목) 22:51 판

/**
 * Unreal Engine 4 loader
 * 제작자: [[사용자:senouis]]
**/

function 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);
    }
	});
}
var liberty_gamepath = document.getElementById("libertygame-gamepath").innerText;
var liberty_gamename = document.getElementById("libertygame-gamename").innerText;
function UE4_loadElement() {
	try {
		var canvasparent = document.getElementById("mainarea"); // first element of mediawiki contents
		// Add game canvas to div
		var canvasElem = document.createElement("canvas");
		canvasElem.tabindex = 0;
		canvasElem.className = "emscripten";
		canvasElem.id = "canvas";
		canvasElem.addEventListener("contextmenu", function (event) {event.preventDefault();});
		canvasElem.style.display = "none";
		canvasparent.appendChild(canvasElem);
		// now load js files from external server
		asyncJSLoader("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js", "text/javascript")
		.then(function (data) {
			asyncJSLoader("https://cdn.jsdelivr.net/"+liberty_gamepath + liberty_gamename+".js", "text/javascript")
			.then(function (data) {
				console.log("UE4 Game Loaded!");
			});
		});
	} catch (e){
		console.log("initiating Unreal Engine 4 for libertygame failed, stop loading elements...");
	}
}
$(UE4_loadElement);