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

리버티게임(개발), 모두가 만들어가는 자유로운 게임
둘러보기로 이동 검색으로 이동
imported>Senouis
(jquery)
(필수 구현 기능 추가 메모)
 
(사용자 2명의 중간 판 25개는 보이지 않습니다)
4번째 줄: 4번째 줄:
  * 제작자: [[사용자:senouis]]
  * 제작자: [[사용자:senouis]]
**/
**/
function xash3d_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);
    }
});
}
// TODO: Steam Web API로 골드 소스 엔진 기반 게임을 소유했는지 확인하는 작업을 추가할 것
function xash3d_loadElement() {
function xash3d_loadElement() {
try {
try {
// Game canvas
// Game canvas
var canvas = document.createElement("canvas");
var canvas = document.createElement("canvas");
canvas.style = "display:none;";
// canvas.style = "display:none;";
canvas.class = "emscripten";
canvas.className = "xash-render";
canvas.id = "canvas";
canvas.id = "xash-canvas";
canvas.oncontextmenu = "event.preventDefault()";
canvas.oncontextmenu = "event.preventDefault()";
var canvasparent = document.getElementsByClassName("emscripten_border")[0]; // first element of emscripten-border
var canvasparent = document.getElementById("xash3d-lg-main"); // first element of emscripten-border
canvasparent.appendChild(canvas);
canvasparent.appendChild(canvas);
// screen option
// game option
var gamecontrol = document.getElementById('xash-controls');
var gameoption = document.createElement("form");
var a1 = document.createElement("a");
var elem1 = document.createElement("label");
a1.class = "xash-glow";
elem1.for = "zip";
a1.innerHTML = "<span><input type=\"checkbox\" id=\"resize\">Resize canvas</span>";
elem1.id = "xash-filedescription";
gamecontrol.appendChild(a1);
elem1.innerHTML = "Select game data as local .zip file:";
var a2 = document.createElement("a");
gameoption.appendChild(elem1);
a2.class = "xash-glow";
gameoption.appendChild(document.createElement("br"));
a2.innerHTML = "<span><input type=\"checkbox\" id=\"pointerLock\" checked>Lock/hide mouse pointer &nbsp;&nbsp;&nbsp;</span>";
var elem2 = document.createElement("input");
gamecontrol.appendChild(a2);
elem2.type = "file";
var controlinputspan = document.createElement("span");
elem2.name = "zip";
controlinputspan.innerHTML = "<input type=\"button\" value=\"Fullscreen\" onclick=\"Module.requestFullscreen(document.getElementById('pointerLock').checked, document.getElementById('resize').checked)\">";
elem2.id = "zip";
gamecontrol.appendChild(controlinputspan);
gameoption.appendChild(elem2);
var outputcontainer = document.getElementById("xash-output-container");
gameoption.appendChild(document.createElement("br"));
outputcontainer.innerHTML = "<textarea id=\"xash-output\" rows=\"8\"></textarea>";
var elem5 = document.createElement("input");
// game option
elem5.type = "button";
var gameoptionsTitle = document.getElementById("optionsTitle");
elem5.id = "start";
gameoptionsTitle.innerHTML = "<a class=\"glow\"><u><h1>Game Options</h1></u></a>";
elem5.value = "Start";
var pkgHider = document.getElementById("pkgHider");
gameoption.appendChild(elem5);
pkgHider.innerHTML = "<input name=\"b\" type=\"radio\" id=\"rPackage\" checked=true />Emscripten package from server (cached in IndexedDB if availiable)<select id=\"selectPkg\" style=\"display:none\"></select><br>";
gameoption.appendChild(document.createElement("br"));
var zipHider = document.getElementById("zipHider");
canvasparent.appendChild(gameoption);
zipHider.innerHTML = "<input name=\"b\" type=radio id=\"rZip\" />ZIP archive from server (slower, but smaller, no IndexedDB cache)<select id=\"selectZip\" style=\"display:none\"></select><br>";
// now load js files from external server
var localHider = document.getElementById("localHider");
xash3d_asyncJSLoader("https://cdn.jsdelivr.net/gh/Xen-alpha/hl-engine-js@main/browserfs.min.js", "text/javascript")
localHider.innerHTML = "<input name=\"b\" type=radio id=\"rLocalZip\"  />Local ZIP file:<input type=file name=\"c\" id=\"iZipFile\" />";
.then(function (data) {
var xashlauncher = document.getElementById("xash-launch");
xash3d_asyncJSLoader("https://cdn.jsdelivr.net/gh/Xen-alpha/hl-engine-js@main/index.js", "module")
xashlauncher.innerHTML = "Command-line arguments: <input name=\"d\" type=text id=\"iArgs\" /><br><br><input type=button onclick=\"startXash();return false;\" value=\"Launch Xash3D!\" />";
.then(function (data) {
} catch (e){
console.log("xash3d OK!");
console.log("initiating xash3d for libertygame failed, stop loading elements...");
});
}
});
} catch (e){
console.log("initiating xash3d for libertygame failed, stop loading elements...");
}
}
}
$(xash3d_loadElement);
$(xash3d_loadElement);

2024년 2월 29일 (목) 08:58 기준 최신판

/**
 * Xash3D for Libertygame loader
 * external server code: https://github.com/Xen-alpha/Xen-alpha.github.io
 * 제작자: [[사용자:senouis]]
**/

function xash3d_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);
    }
	});
}
// TODO: Steam Web API로 골드 소스 엔진 기반 게임을 소유했는지 확인하는 작업을 추가할 것
function xash3d_loadElement() {
	try {
		// Game canvas
		var canvas = document.createElement("canvas");
		// canvas.style = "display:none;";
		canvas.className = "xash-render";
		canvas.id = "xash-canvas";
		canvas.oncontextmenu = "event.preventDefault()";
		var canvasparent = document.getElementById("xash3d-lg-main"); // first element of emscripten-border
		canvasparent.appendChild(canvas);
		// game option
		var gameoption = document.createElement("form");
		var elem1 = document.createElement("label");
		elem1.for = "zip";
		elem1.id = "xash-filedescription";
		elem1.innerHTML = "Select game data as local .zip file:";
		gameoption.appendChild(elem1);
		gameoption.appendChild(document.createElement("br"));
		var elem2 = document.createElement("input");
		elem2.type = "file";
		elem2.name = "zip";
		elem2.id = "zip";
		gameoption.appendChild(elem2);
		gameoption.appendChild(document.createElement("br"));
		var elem5 = document.createElement("input");
		elem5.type = "button";
		elem5.id = "start";
		elem5.value = "Start";
		gameoption.appendChild(elem5);
		gameoption.appendChild(document.createElement("br"));
		canvasparent.appendChild(gameoption);
		// now load js files from external server
		xash3d_asyncJSLoader("https://cdn.jsdelivr.net/gh/Xen-alpha/hl-engine-js@main/browserfs.min.js", "text/javascript")
		.then(function (data) {
			xash3d_asyncJSLoader("https://cdn.jsdelivr.net/gh/Xen-alpha/hl-engine-js@main/index.js", "module")
			.then(function (data) {
				console.log("xash3d OK!");
			});
		});
	} catch (e){
		console.log("initiating xash3d for libertygame failed, stop loading elements...");
	}
}
$(xash3d_loadElement);