Initial commit

This commit is contained in:
Dakedres
2022-10-28 02:48:42 -06:00
commit cf9323beae
59 changed files with 11866 additions and 0 deletions

63
view/_main.html Executable file
View File

@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="MobileOptimized" content="640"/>
<meta name="HandheldFriendly" content="true"/>
<title>Xash3D Emscripten Port</title>
<style>
body {
font-family: arial;
margin: 0;
padding: none;
background-color: #555555;
color: #f0b418;
}
</style>
</head>
<body onerror=alert(event);>
<div class="emscripten_border">
<canvas style="display:none" class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
</div>
<div style="float:left;" id="status">Downloading...</div>
<div style=width:100%><span id='controls'>
<a class="glow"><span><input type="checkbox" id="resize">Resize canvas</span></a>
<a class="glow"><span><input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer &nbsp;&nbsp;&nbsp;</span></a>
<span><input type="button" value="Fullscreen" onclick="Module.requestFullscreen(document.getElementById('pointerLock').checked, document.getElementById('resize').checked)"></span>
</span></div>
<!-- <textarea id="output" rows="8"></textarea><div id="asyncDialog" style="float:left"></div> -->
<script type='text/javascript' lsrc='../init.js'></script>
<script>
// Causes the app to freeze. Maybe make async?
function loadingDone() {
(function() {
// var memoryInitializer = 'xash.html.mem';
var memoryInitializer = 'xash.html.mem' // not gonna cuz locateFile will handle it
if (typeof Module['locateFile'] === 'function') {
memoryInitializer = Module['locateFile'](memoryInitializer);
} else if (Module['memoryInitializerPrefixURL']) {
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer;
}
var xhr = Module['memoryInitializerRequest'] = new XMLHttpRequest();
xhr.open('GET', memoryInitializer, true);
xhr.responseType = 'arraybuffer';
xhr.send(null);
})();
var script = document.createElement('script');
// script.src = "xash.js";
script.src = instance.import['xash.js'] // temp
document.body.appendChild(script);
}
</script>
</body>
</html>

1
view/assets/play.svg Normal file
View File

@@ -0,0 +1 @@
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 10 10" shape-rendering="crispEdges"><rect x="3" y="0" width="1" height="1" fill="#000000"/><rect x="4" y="0" width="1" height="1" fill="#000000"/><rect x="3" y="1" width="1" height="1" fill="#000000"/><rect x="4" y="1" width="1" height="1" fill="#000000"/><rect x="5" y="1" width="1" height="1" fill="#000000"/><rect x="3" y="2" width="1" height="1" fill="#000000"/><rect x="4" y="2" width="1" height="1" fill="#000000"/><rect x="5" y="2" width="1" height="1" fill="#000000"/><rect x="6" y="2" width="1" height="1" fill="#000000"/><rect x="3" y="3" width="1" height="1" fill="#000000"/><rect x="4" y="3" width="1" height="1" fill="#000000"/><rect x="5" y="3" width="1" height="1" fill="#000000"/><rect x="6" y="3" width="1" height="1" fill="#000000"/><rect x="7" y="3" width="1" height="1" fill="#000000"/><rect x="3" y="4" width="1" height="1" fill="#000000"/><rect x="4" y="4" width="1" height="1" fill="#000000"/><rect x="5" y="4" width="1" height="1" fill="#000000"/><rect x="6" y="4" width="1" height="1" fill="#000000"/><rect x="7" y="4" width="1" height="1" fill="#000000"/><rect x="8" y="4" width="1" height="1" fill="#000000"/><rect x="3" y="5" width="1" height="1" fill="#000000"/><rect x="4" y="5" width="1" height="1" fill="#000000"/><rect x="5" y="5" width="1" height="1" fill="#000000"/><rect x="6" y="5" width="1" height="1" fill="#000000"/><rect x="7" y="5" width="1" height="1" fill="#000000"/><rect x="8" y="5" width="1" height="1" fill="#000000"/><rect x="3" y="6" width="1" height="1" fill="#000000"/><rect x="4" y="6" width="1" height="1" fill="#000000"/><rect x="5" y="6" width="1" height="1" fill="#000000"/><rect x="6" y="6" width="1" height="1" fill="#000000"/><rect x="7" y="6" width="1" height="1" fill="#000000"/><rect x="3" y="7" width="1" height="1" fill="#000000"/><rect x="4" y="7" width="1" height="1" fill="#000000"/><rect x="5" y="7" width="1" height="1" fill="#000000"/><rect x="6" y="7" width="1" height="1" fill="#000000"/><rect x="3" y="8" width="1" height="1" fill="#000000"/><rect x="4" y="8" width="1" height="1" fill="#000000"/><rect x="5" y="8" width="1" height="1" fill="#000000"/><rect x="3" y="9" width="1" height="1" fill="#000000"/><rect x="4" y="9" width="1" height="1" fill="#000000"/></svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

3
view/bundle.config.json Executable file
View File

@@ -0,0 +1,3 @@
{
"entry": "/dist/xash.js"
}

208
view/dist/xash.js vendored Executable file

File diff suppressed because one or more lines are too long

75
view/global.css Normal file
View File

@@ -0,0 +1,75 @@
.xash3d_terminal code {
display: block;
width: 60ch;
white-space: pre-wrap;
word-break: break-word;
overflow-wrap: break-word;
color: white;
}
.xash3d_launcher {
--mod-height: 36px;
background: #333 var(--xash3d-trame);
background-size: 4px;
background-repeat: repeat;
}
.xash3d_launcher > ul {
margin: 4px 2px;
padding: 0;
}
.xash3d_launcher .mod {
margin-bottom: 6px;
}
.xash3d_launcher .mod header {
display: flex;
padding: 1px;
box-sizing: content-box;
height: var(--mod-height)
}
.xash3d_launcher .info {
border-right: 1px solid #666;
flex: 1;
align-self: center;
margin: 2px 0 2px 5px;
}
.xash3d_launcher .info h5 {
font-size: 8px;
margin: 0
}
.xash3d_launcher .info span {
color: #555;
}
.xash3d_launcher .launch {
width: var(--mod-height);
height: var(--mod-height);
box-sizing: content-box;
background-image: var(--xash3d-play);
background-size: 20px 20px;
background-repeat: no-repeat;
background-position: center;
}
.xash3d_launcher .launch:active {
opacity: .6;
}
span.ui_menu__item__ico > img[src="/c/sys/skins/w93/xash"],
div.ui_icon__file img[src="/c/sys/skins/w93/xash"] {
display: block;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-image: var(--xash3d-icon);
background-repeat: no-repeat;
/* It's a little blurry and should really just be pixel art but whatever for now */
background-size: 100%;
}

BIN
view/half-trame.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 B

394
view/init.js Executable file
View File

@@ -0,0 +1,394 @@
// Heavily-modified version of the xash.html set-up script
// from Xash3d-Emscripten
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var asyncDialog = document.getElementById('asyncDialog');
var myerrorbuf = ''
var myerrordate = new Date();
var mounted = false;
var gamedir = 'valve';
var moduleCount = 0;
//var mem = 150;
var mfs;
var zipSize;
var modPackage;
// // make BrowserFS to work on ES5 browsers
// if (!ArrayBuffer['isView']) {
// ArrayBuffer.isView = function(a) {
// return a !== null && typeof(a) === "object" && a['buffer'] instanceof ArrayBuffer;
// };
// }
// showElement('optionsTitle', false);
// function prepareSelects()
// {
// var len = zipMods.length;
// var select = document.getElementById('selectZip');
// if( len )
// {
// showElement('zipHider', true);
// if(len > 1)
// {
// var links = '';
// for(var i = 0; i < len; i++)
// {
// select.options[i] = new Option(zipMods[i][1], zipMods[i][0]);
// links += '<br><a href="'+zipMods[i][0]+'">'+zipMods[i][1]+'</a>';
// }
// select.style.display = 'block';
// document.getElementById('linksPlaceholder').innerHTML += links;
// showElement('linksPlaceholder', true);
// }
// }
// else
// document.getElementById('rZip').checked = false;
// len = pkgMods.length;
// select = document.getElementById('selectPkg');
// if( len )
// {
// showElement('pkgHider', true);
// if(len > 1)
// {
// for(var i = 0; i < len; i++)
// select.options[i] = new Option(pkgMods[i][1], pkgMods[i][0]);
// select.style.display = 'block';
// }
// }
// else
// document.getElementById('rPackage').checked = false;
// if( !zipMods.length && !len )
// {
// document.getElementById('rLocalZip').checked = true;
// showElement('rLocalZip', false);
// }
// }
try{mem = Math.round(window.location.hash.substring(1));}catch(e){};
function wrapPrint(func) {
return (...args) => {
if(args.length > 0)
instance.console[func](...args)
}
}
var Module = {
TOTAL_MEMORY: mem * 1024 * 1024,
preRun: [],
postRun: [],
// print: (function() {
// var element = document.getElementById('output');
// if (element) element.value = ''; // clear browser cache
// return function(text) {
// if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// // These replacements are necessary if you render to raw HTML
// //text = text.replace(/&/g, "&amp;");
// //text = text.replace(/</g, "&lt;");
// //text = text.replace(/>/g, "&gt;");
// //text = text.replace('\n', '<br>', 'g');
// //console.log(text);
// if(text)
// myerrorbuf += text + '\n';
// if (element) {
// if(element.value.length > 65536)
// element.value = element.value.substring(512) + myerrorbuf;
// else
// element.value += myerrorbuf;
// element.scrollTop = element.scrollHeight; // focus on bottom
// }
// myerrorbuf = ''
// };
// })(),
print: wrapPrint('log'),
// printErr: function(text) {
// if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// if (0) { // XXX disabled for safety typeof dump == 'function') {
// dump(text + '\n'); // fast, straight to the real console
// } else {
// if( myerrorbuf.length > 2048 )
// myerrorbuf = 'some lines skipped\n'+ myerrorbuf.substring(512);
// myerrorbuf += text + '\n';
// if( new Date() - myerrordate > 3000 )
// {
// myerrordate = new Date();
// Module.print();
// }
// }
// },
printErr: wrapPrint('error'),
canvas: (function() {
var canvas = document.getElementById('canvas');
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})(),
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.text) return;
if( new Date() - myerrordate > 3000 )
{
myerrordate = new Date();
Module.print();
}
statusElement.innerHTML = text;
if( progressElement )
{
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
if(m)
{
var progress = Math.round(parseInt(m[2])*100/parseInt(m[4]));
progressElement.style.color = progress > 5?'#303030':'#aaa000';
progressElement.style.width = progressElement.innerHTML = ''+progress+'%';
}
showElement('progress1', !!m);
}
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
if(left)
Module.setStatus('Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')');
},
// Added:
// This is needed for it to load the package's data from a URI
// https://emscripten.org/docs/porting/files/packaging_files.html#changing-the-data-file-location
locateFile(dataName) {
return instance.import[dataName] || modPackage.getURL(dataName)
}
//
};
function syncFS() {
FS.syncfs(false, function(err) {
instance.emulatedIDB.sync()
Module.print('Saving IDBFS' + err ? `: ${err}` : '')
})
}
window.onerror = function(event) {
if(mounted) {
// console.error('Errored: ', event)
syncFS()
} if( (''+event).indexOf('SimulateInfiniteLoop') > 0 )
return;
var text = 'Exception thrown: ' + event;
text = text.replace(/&/g, "&amp;");
text = text.replace(/</g, "&lt;");
text = text.replace(/>/g, "&gt;");
text = text.replace('\n', '<br>', 'g');
Module.setStatus(text);
Module.print('Exception thrown: ' + event);
};
function haltRun()
{
}
var savedRun;
function radioChecked(id)
{
var r = document.getElementById('r'+id);
if(r) return r.checked;
return false;
}
function showElement(id, show)
{
var e = document.getElementById(id);
if(!e) return;
e.style.display=show?'block':'none';
}
Module.setStatus('Downloading...');
function startXash()
{
// showElement('loader1', false);
// showElement('optionsTitle', false);
// showElement('fSettings', false);
setupFS();
Module.arguments = instance.arguments;
Module.run = run = savedRun;
// if( radioChecked('Zip') )
// fetchZIP(zipMods.length>1?document.getElementById('selectZip').value:zipMods[0][0], savedRun);
// else if( (!zipMods.length && !pkgMods.length) || radioChecked('LocalZip') )
// {
// var reader = new FileReader();
// reader.onload = function(){
// mountZIP(reader.result);
// Module.print("Loaded zip data");
// savedRun();
// };
// reader.readAsArrayBuffer(document.getElementById('iZipFile').files[0]);
// }
// else if( radioChecked('Package') )
// {
var script = document.createElement('script');
script.onload = savedRun;
document.body.appendChild(script);
// script.src = pkgMods.length>1?document.getElementById('selectPkg').value:pkgMods[0][0];
// }
instance.package.then(data => {
console.log('Loading package...')
modPackage = data
script.src = modPackage.getURL(modPackage.manifest.entry)
console.log('PAYLOAD: ', script.src)
})
showElement('canvas', true);
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = 'Leave the game?';
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
});
// Added
document.addEventListener("onkeydown", function (e) {
e = e || window.event;//Get event
if (!e.ctrlKey) return;
var code = e.which || e.keyCode;//Get key code
switch (code) {
case 83://Block Ctrl+S
case 87://Block Ctrl+W -- Not work in Chrome and new Firefox
e.preventDefault();
e.stopPropagation();
break;
}
})
if(instance.app.config.pauseOnLostFocus)
document.addEventListener('mouseleave', function(event) {
console.log('aaa')
canvas.dispatchEvent(new KeyboardEvent({ key: 'Esc' }))
})
}
// function mountZIP(data)
// {
// var Buffer = BrowserFS.BFSRequire('buffer').Buffer;
// mfs.mount('/zip', new BrowserFS.FileSystem.ZipFS(Buffer.from(data)));
// FS.mount(new BrowserFS.EmscriptenFS(), {root:'/zip'}, '/rodir');
// }
// function fetchZIP(packageName, cb)
// {
// var xhr = new XMLHttpRequest();
// xhr.open('GET', packageName, true);
// xhr.responseType = 'arraybuffer';
// xhr.onprogress = function(event) {
// var url = packageName;
// var size;
// if (event.total) size = event.total;
// else size = zipMods[document.getElementById('selectZip').selectedIndex][2];
// if (event.loaded) {
// var total = size;
// var loaded = event.loaded;
// var num = 0;
// if (Module['setStatus']) Module['setStatus']('Downloading data... (' + loaded + '/' + total + ')');
// } else if (!Module.dataFileDownloads) {
// if (Module['setStatus']) Module['setStatus']('Downloading data...');
// }
// };
// xhr.onerror = function(event) {
// throw new Error("NetworkError");
// }
// xhr.onload = function(event) {
// if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
// mountZIP(xhr.response);
// cb();
// } else {
// throw new Error(xhr.statusText + " : " + xhr.responseURL);
// }
// };
// xhr.send(null);
// }
let localForageOperations = []
function setupFS()
{
// TODO: Determined by the new "mod id"
let fsPath = '/' + modPackage.manifest.id
FS.mkdir('/rodir');
FS.mkdir(fsPath);
instance.emulatedIDB.patch(IDBFS)
FS.mount(IDBFS, {}, fsPath);
FS.syncfs(true, function(err) {
if(err)
Module.print('Loading IDBFS: ' + err)
})
mounted = true;
FS.chdir(fsPath);
}
function skipRun()
{
savedRun = run;
Module.run = haltRun;
run = haltRun;
Module.setStatus("Engine downloaded!");
// showElement('loader1', false);
// showElement('optionsTitle', true);
// if(window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB)
// showElement('idbHider', true);
// prepareSelects();
// showElement('fSettings',true);
ENV.XASH3D_GAMEDIR = gamedir;
ENV.XASH3D_RODIR = '/rodir'
function loadModule(name)
{
var script = document.createElement('script');
script.onload = function() {
moduleCount++
if(moduleCount == 3) {
Module.setStatus("Scripts downloaded!")
// We'll now wanna start xash right away
startXash()
}
}
document.body.appendChild(script);
// script.src = name + ".js";
script.src = instance.import[name + '.js']
}
loadModule("server");
loadModule("client");
loadModule("menu");
};
Module.preInit = [skipRun];
Module.websocket = [];
Module.websocket.url = 'wsproxy://the-swank.pp.ua:3000/'
ENV = [];
loadingDone()

55
view/launcher.css Normal file
View File

@@ -0,0 +1,55 @@
:root {
--mod-height: 36px;
}
html {
/* im not gonna write a preprocessor for the css so i'm refrencing an element here */
background: #333 var(--trame);
background-size: 4px;
background-repeat: repeat;
}
.mod {
display: flex;
padding: 1px;
box-sizing: content-box;
height: var(--mod-height)
}
.mod .info {
border-right: 1px solid #666;
flex: 1;
align-self: center;
margin: 2px 0 2px 5px;
}
.info h4 {
font-size: 16px;
margin: 0
}
.mod .button {
width: var(--mod-height);
height: var(--mod-height);
box-sizing: content-box;
background-image: var(--xash3d-play);
background-size: 20px 20px;
background-repeat: no-repeat;
background-position: center;
}
.button:before {
content: " ";
float: left;
padding-top: 100%;
}
.mod .button:active {
opacity: .6;
}
.version-info {
color: #555;
text-align: center;
height: 16px;
}

10
view/launcher.html Normal file
View File

@@ -0,0 +1,10 @@
<ul class="mods">
<li class="skin_outset mod">
<div class="info">
<h4>Test</h4>
<span>Data</span>
</div>
<div class="launch"></div>
</li>
</ul>

12
view/launcher.js Normal file
View File

@@ -0,0 +1,12 @@
// Load the trame and save it's url to the appropriate
// css variable
//
// Gross we have to do it this way but it's whatever
app.bundle.open('./half-trame.png', 'URL')
.then(url => document.querySelector(':root').style.setProperty('--xash-trame', `url(${url})`) )
{
const modList = document.getElementById('mods')
console.log(app)
}

21
view/main.css Executable file
View File

@@ -0,0 +1,21 @@
body {
margin: 0;
background: #000;
/* For some reason the canvas gets huge
during loading so */
overflow: hidden;
}
#canvas {
height: 100vh;
width: auto;
margin: auto;
}
#status {
position: absolute;
bottom: 0;
left: 0;
color: #f0b418;
background: rgba(0, 0, 0, .5);
}

91
view/main.html Executable file
View File

@@ -0,0 +1,91 @@
<!-- Although this is in the root of the bundle, it is loaded into
the import/ directory. -->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/c/sys/skins/w93.css" >
<!-- <link rel="stylesheet" lhref="../main.css"> -->
<style>
html {
/* For some reason the status messages cause the scrollbars to appear */
overflow: hidden;
}
body {
margin: 0;
background: #000;
}
#canvas {
height: 100vh;
width: auto;
margin: auto;
}
#status {
position: absolute;
bottom: 0;
left: 0;
color: #f0b418;
background: rgba(0, 0, 0, .5);
}
</style>
</head>
<body>
<canvas style="display:none" class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<code id="status"></code>
<script>
{
// const { indexedDb } = window
// window.indexedDB = new Proxy(indexedDb, {
// get(target, prop) {
// if(prop == 'open') {
// return function(...args) {
// if(args[0] == 'UPLINK') {
// console.log('Preventing IDB cache')
// return {}
// } else {
// return indexedDb.open.call(this, ...args)
// }
// }
// } else {
// return indexedDb[prop]
// }
// }
// })
// indexedDB.open('UPLINK', 1)
}
</script>
<script type='text/javascript' lsrc='../init.js'></script>
<script>
// Causes the app to freeze. Maybe make async?
function loadingDone() {
(function() {
// locateFile will handle the uri conversion on this one
var memoryInitializer = 'xash.html.mem';
if (typeof Module['locateFile'] === 'function') {
memoryInitializer = Module['locateFile'](memoryInitializer);
} else if (Module['memoryInitializerPrefixURL']) {
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer;
}
// Send it the request so it can handle the data
var xhr = Module['memoryInitializerRequest'] = new XMLHttpRequest();
xhr.open('GET', memoryInitializer, true);
xhr.responseType = 'arraybuffer';
xhr.send(null);
})();
var script = document.createElement('script');
script.src = instance.import['xash.js'];
document.body.appendChild(script);
}
</script>
</body>
</html>

BIN
view/quarter-trame.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 B