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

리버티게임(개발), 모두가 만들어가는 자유로운 게임
둘러보기로 이동 검색으로 이동
잔글편집 요약 없음
(버튼 추가 동작을 추가함)
 
(같은 사용자의 중간 판 6개는 보이지 않습니다)
1번째 줄: 1번째 줄:
/**
/**
  * Unreal Engine 4 loader
  * Unreal Engine 4 loader
* 2024년 12월 31일 이전까지 완전 작동을 목표로 개발 예정
  * 제작자: [[사용자:senouis]]
  * 제작자: [[사용자:senouis]]
**/
**/
28번째 줄: 29번째 줄:
}
}
var liberty_gamepath = document.getElementById("libertygame-gamepath").innerText;
var liberty_gamepath = document.getElementById("libertygame-gamepath").innerText;
var liberty_gamename = document.getElementById("libertygame-gamename").innerText;
function UE4_loadElement() {
function UE4_loadElement() {
try {
try {
39번째 줄: 41번째 줄:
canvasElem.style.display = "none";
canvasElem.style.display = "none";
canvasparent.appendChild(canvasElem);
canvasparent.appendChild(canvasElem);
// place buttons below the canvas
var buttonclass = document.getElementsByClassName("col-sm-2 text-center");
var button1 = document.createElement("button");
button1.type = "button";
button1.classname = "btn btn-primary";
button1.addEventListener("click", function () {try { Module['pauseMainLoop'](); } catch(e) {console.error(e);}});
button1.innerText = "일시 정지";
buttonclass['1'].appendChild(button1);
var button2 = document.createElement("button");
button2.type = "button";
button2.classname = "btn btn-primary";
button2.addEventListener("click", function () {try { Module['resumeMainLoop'](); } catch(e) {console.error(e);}});
button2.innerText = "계속하기";
buttonclass['2'].appendChild(button2);
var button3 = document.createElement("button");
button3.type = "button";
button3.classname = "btn btn-primary";
button3.addEventListener("click", function () {
var w = document.getElementById('logwindow');
w.style.display = w.style.display ? '' : 'none';
});
button3.innerText = "로그 보기/닫기";
buttonclass['3'].appendChild(button3);
var button4 = document.createElement("button");
button4.type = "button";
button4.classname = "btn btn-primary";
button4.id = "clear_indexeddb";
button4.addEventListener("click", function () {try { deleteIndexedDBStorage(); } catch(e) {console.error(e);}});
button4.innerText = "저장소 비우기";
buttonclass['4'].appendChild(button4);
var button5 = document.createElement("button");
button5.type = "button";
button5.classname = "btn btn-primary";
button5.id = "fullscreen_request";
button5.innerText = "전체 화면";
buttonclass['5'].appendChild(button5);
// now load js files from external server
// now load js files from external server
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, "text/javascript")
asyncJSLoader("https://"+liberty_gamepath + liberty_gamename, "text/javascript")
.then(function (data) {
.then(function (data) {
console.log("UE4 Game Loaded!");
console.log("UE4 Game Loaded!");

2024년 1월 20일 (토) 14:07 기준 최신판

/**
 * Unreal Engine 4 loader
 * 2024년 12월 31일 이전까지 완전 작동을 목표로 개발 예정
 * 제작자: [[사용자: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);
		// place buttons below the canvas
		var buttonclass = document.getElementsByClassName("col-sm-2 text-center");
		var button1 = document.createElement("button");
		button1.type = "button";
		button1.classname = "btn btn-primary";
		button1.addEventListener("click", function () {try { Module['pauseMainLoop'](); } catch(e) {console.error(e);}});
		button1.innerText = "일시 정지";
		buttonclass['1'].appendChild(button1);
		var button2 = document.createElement("button");
		button2.type = "button";
		button2.classname = "btn btn-primary";
		button2.addEventListener("click", function () {try { Module['resumeMainLoop'](); } catch(e) {console.error(e);}});
		button2.innerText = "계속하기";
		buttonclass['2'].appendChild(button2);
		var button3 = document.createElement("button");
		button3.type = "button";
		button3.classname = "btn btn-primary";
		button3.addEventListener("click", function () { 
			var w = document.getElementById('logwindow');
			w.style.display = w.style.display ? '' : 'none'; 
		});
		button3.innerText = "로그 보기/닫기";
		buttonclass['3'].appendChild(button3);
		var button4 = document.createElement("button");
		button4.type = "button";
		button4.classname = "btn btn-primary";
		button4.id = "clear_indexeddb";
		button4.addEventListener("click", function () {try { deleteIndexedDBStorage(); } catch(e) {console.error(e);}});
		button4.innerText = "저장소 비우기";
		buttonclass['4'].appendChild(button4);
		var button5 = document.createElement("button");
		button5.type = "button";
		button5.classname = "btn btn-primary";
		button5.id = "fullscreen_request";
		button5.innerText = "전체 화면";
		buttonclass['5'].appendChild(button5);
		// 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://"+liberty_gamepath + liberty_gamename, "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);