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

리버티게임(개발), 모두가 만들어가는 자유로운 게임
둘러보기로 이동 검색으로 이동
(추가)
 
잔글편집 요약 없음
27번째 줄: 27번째 줄:
});
});
}
}
 
var gamepath = document.getElementById("libertygame-gamepath").innerText;
function UE4_loadElement() {
function UE4_loadElement() {
try {
try {
var gamepath = document.getElementById("libertygame-gamepath").innerText;
var canvasparent = document.getElementById("mainarea"); // first element of mediawiki contents
var canvasparent = document.getElementById("mainarea"); // first element of mediawiki contents
// Add game canvas to div
// Add game canvas to div

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

/**
 * 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 gamepath = document.getElementById("libertygame-gamepath").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/"+gamepath, "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);