Fix shell indentation
This commit is contained in:
		
							parent
							
								
									6e5a0603c0
								
							
						
					
					
						commit
						eedee762b7
					
				
					 1 changed files with 146 additions and 148 deletions
				
			
		
							
								
								
									
										294
									
								
								extra/shell.html
									
										
									
									
									
								
							
							
						
						
									
										294
									
								
								extra/shell.html
									
										
									
									
									
								
							| 
						 | 
					@ -178,184 +178,182 @@
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <script type='text/javascript'>
 | 
					    <script type='text/javascript'>
 | 
				
			||||||
      var namespace = 'kne';
 | 
					        var namespace = 'kne';
 | 
				
			||||||
      var wTitle = 'KN_E'
 | 
					        var wTitle = 'KN_E'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      window.saveFile = function(filename) {
 | 
					        window.saveFile = function(filename) {
 | 
				
			||||||
          const buf = FS.readFile('/game/' + filename);
 | 
					            const buf = FS.readFile('/game/' + filename);
 | 
				
			||||||
          const b64 = _bytesToBase64(buf);
 | 
					            const b64 = _bytesToBase64(buf);
 | 
				
			||||||
          localforage.setItem(namespace + filename, b64);
 | 
					            localforage.setItem(namespace + filename, b64);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          localforage.getItem(namespace, function(err, res) {
 | 
					            localforage.getItem(namespace, function(err, res) {
 | 
				
			||||||
              if (err || !res) res = {};
 | 
					                if (err || !res) res = {};
 | 
				
			||||||
              res[filename] = 1;
 | 
					                res[filename] = 1;
 | 
				
			||||||
              localforage.setItem(namespace, res);
 | 
					                localforage.setItem(namespace, res);
 | 
				
			||||||
          });
 | 
					            });
 | 
				
			||||||
      };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      var loadFiles = function() {
 | 
					        var loadFiles = function() {
 | 
				
			||||||
          localforage.getItem(namespace, function(err, res) {
 | 
					            localforage.getItem(namespace, function(err, res) {
 | 
				
			||||||
              if (err || !res) return;
 | 
					                if (err || !res) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              const keys = Object.keys(res);
 | 
					                const keys = Object.keys(res);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              console.log('Locally stored savefiles', keys);
 | 
					                console.log('Locally stored savefiles', keys);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              keys.forEach((key) => {
 | 
					                keys.forEach((key) => {
 | 
				
			||||||
                  localforage.getItem(namespace + key, (err, res) => {
 | 
					                    localforage.getItem(namespace + key, (err, res) => {
 | 
				
			||||||
                      if (err) return;
 | 
					                        if (err) return;
 | 
				
			||||||
 | 
					 | 
				
			||||||
                      const buf = _base64ToBytes(res);
 | 
					 | 
				
			||||||
                      FS.writeFile('/game/' + key, buf);
 | 
					 | 
				
			||||||
                  });
 | 
					 | 
				
			||||||
              });
 | 
					 | 
				
			||||||
          });
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      var createDummies = function() {
 | 
					 | 
				
			||||||
          // Base directory
 | 
					 | 
				
			||||||
          FS.mkdir('/game');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          // Create dummy objects
 | 
					 | 
				
			||||||
          Object.values(mapping).forEach((file) => {
 | 
					 | 
				
			||||||
              // Get filename
 | 
					 | 
				
			||||||
              const filename = '/game/' + file.split("?")[0];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
              // Check if folder
 | 
					 | 
				
			||||||
              if (file.endsWith('h=')) {
 | 
					 | 
				
			||||||
                  return FS.mkdir(filename);
 | 
					 | 
				
			||||||
              }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
              // Create dummy file
 | 
					 | 
				
			||||||
              FS.writeFile(filename, '1');
 | 
					 | 
				
			||||||
          });
 | 
					 | 
				
			||||||
      };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      var Module = {
 | 
					 | 
				
			||||||
        preRun: [createDummies],
 | 
					 | 
				
			||||||
        postRun: [loadFiles],
 | 
					 | 
				
			||||||
        noAudioDecoding: true,
 | 
					 | 
				
			||||||
        print: (function() {
 | 
					 | 
				
			||||||
          return function(text) {
 | 
					 | 
				
			||||||
            console.log(text);
 | 
					 | 
				
			||||||
          };
 | 
					 | 
				
			||||||
        })(),
 | 
					 | 
				
			||||||
        printErr: function(text) {
 | 
					 | 
				
			||||||
          if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
 | 
					 | 
				
			||||||
          console.error(text);
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        canvas: (function() {
 | 
					 | 
				
			||||||
          var canvas = document.getElementById('canvas');
 | 
					 | 
				
			||||||
          canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          return canvas;
 | 
					 | 
				
			||||||
        })(),
 | 
					 | 
				
			||||||
        setStatus: function(text) {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        const buf = _base64ToBytes(res);
 | 
				
			||||||
 | 
					                        FS.writeFile('/game/' + key, buf);
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      window.setBusy = function() {
 | 
					        var createDummies = function() {
 | 
				
			||||||
          document.getElementById('spinner').style.opacity = "0.5";
 | 
					            // Base directory
 | 
				
			||||||
      };
 | 
					            FS.mkdir('/game');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      window.setNotBusy = function() {
 | 
					            // Create dummy objects
 | 
				
			||||||
          document.getElementById('spinner').style.opacity = "0";
 | 
					            Object.values(mapping).forEach((file) => {
 | 
				
			||||||
      };
 | 
					                // Get filename
 | 
				
			||||||
 | 
					                const filename = '/game/' + file.split("?")[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      function fullscreen() {
 | 
					                // Check if folder
 | 
				
			||||||
 | 
					                if (file.endsWith('h=')) {
 | 
				
			||||||
 | 
					                    return FS.mkdir(filename);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Create dummy file
 | 
				
			||||||
 | 
					                FS.writeFile(filename, '1');
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var Module = {
 | 
				
			||||||
 | 
					            preRun: [createDummies],
 | 
				
			||||||
 | 
					            postRun: [loadFiles],
 | 
				
			||||||
 | 
					            noAudioDecoding: true,
 | 
				
			||||||
 | 
					            print: (function() {
 | 
				
			||||||
 | 
					                return function(text) {
 | 
				
			||||||
 | 
					                    console.log(text);
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					            })(),
 | 
				
			||||||
 | 
					            printErr: function(text) {
 | 
				
			||||||
 | 
					                if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
 | 
				
			||||||
 | 
					                console.error(text);
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            canvas: (function() {
 | 
				
			||||||
 | 
					                var canvas = document.getElementById('canvas');
 | 
				
			||||||
 | 
					                canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return canvas;
 | 
				
			||||||
 | 
					            })(),
 | 
				
			||||||
 | 
					            setStatus: function(text) {}
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        window.setBusy = function() {
 | 
				
			||||||
 | 
					            document.getElementById('spinner').style.opacity = "0.5";
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        window.setNotBusy = function() {
 | 
				
			||||||
 | 
					            document.getElementById('spinner').style.opacity = "0";
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        function fullscreen() {
 | 
				
			||||||
            document.getElementById('main').requestFullscreen();
 | 
					            document.getElementById('main').requestFullscreen();
 | 
				
			||||||
            screen.orientation.lock("landscape")
 | 
					            screen.orientation.lock("landscape")
 | 
				
			||||||
      }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      window.onerror = function() {
 | 
					        window.onerror = function() {
 | 
				
			||||||
          console.error("An error occured!")
 | 
					            console.error("An error occured!")
 | 
				
			||||||
      };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      window.fileLoadedAsync = function(file) {
 | 
					        window.fileLoadedAsync = function(file) {
 | 
				
			||||||
          document.title = wTitle;
 | 
					            document.title = wTitle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (!(/.*Map.*rxdata/i.test(file))) return;
 | 
					            if (!(/.*Map.*rxdata/i.test(file))) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          fetch('preload/' + file + '.json')
 | 
					            fetch('preload/' + file + '.json')
 | 
				
			||||||
              .then(function(response) {
 | 
					                .then(function(response) {
 | 
				
			||||||
                  return response.json();
 | 
					                    return response.json();
 | 
				
			||||||
              })
 | 
					                })
 | 
				
			||||||
              .then(function(jsonResponse) {
 | 
					                .then(function(jsonResponse) {
 | 
				
			||||||
                  jsonResponse.forEach((f) => {
 | 
					                    jsonResponse.forEach((f) => {
 | 
				
			||||||
                      const url = mapping[f.toLowerCase().replace(new RegExp("\\.[^/.]+$"), "")];
 | 
					                        const url = mapping[f.toLowerCase().replace(new RegExp("\\.[^/.]+$"), "")];
 | 
				
			||||||
                      if (!url) return;
 | 
					                        if (!url) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                      // Preload the asset
 | 
					                        // Preload the asset
 | 
				
			||||||
                      setTimeout(() => {
 | 
					                        setTimeout(() => {
 | 
				
			||||||
                          fetch('gameasync/' + url).then().catch();
 | 
					                            fetch('gameasync/' + url).then().catch();
 | 
				
			||||||
                      }, 1000);
 | 
					                        }, 1000);
 | 
				
			||||||
                  });
 | 
					                    });
 | 
				
			||||||
              });
 | 
					                });
 | 
				
			||||||
      };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      var hideTimer = 0;
 | 
					        var hideTimer = 0;
 | 
				
			||||||
      function getLazyAsset(url, filename, callback) {
 | 
					        function getLazyAsset(url, filename, callback) {
 | 
				
			||||||
          const xhr = new XMLHttpRequest();
 | 
					            const xhr = new XMLHttpRequest();
 | 
				
			||||||
          xhr.responseType = "arraybuffer";
 | 
					            xhr.responseType = "arraybuffer";
 | 
				
			||||||
          const pdiv = document.getElementById("progress");
 | 
					            const pdiv = document.getElementById("progress");
 | 
				
			||||||
          let showTimer = 0;
 | 
					            let showTimer = 0;
 | 
				
			||||||
          let abortTimer = 0;
 | 
					            let abortTimer = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          const retry = () => {
 | 
					            const retry = () => {
 | 
				
			||||||
              xhr.abort();
 | 
					                xhr.abort();
 | 
				
			||||||
              getLazyAsset(url, filename, callback);
 | 
					                getLazyAsset(url, filename, callback);
 | 
				
			||||||
          }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          xhr.onreadystatechange = function() {
 | 
					            xhr.onreadystatechange = function() {
 | 
				
			||||||
              if (xhr.readyState == XMLHttpRequest.DONE && xhr.status >= 200 && xhr.status < 400) {
 | 
					                if (xhr.readyState == XMLHttpRequest.DONE && xhr.status >= 200 && xhr.status < 400) {
 | 
				
			||||||
                  pdiv.innerHTML = `${filename} - done`;
 | 
					                    pdiv.innerHTML = `${filename} - done`;
 | 
				
			||||||
                  hideTimer = setTimeout(() => {
 | 
					                    hideTimer = setTimeout(() => {
 | 
				
			||||||
                      pdiv.style.opacity = '0';
 | 
					                        pdiv.style.opacity = '0';
 | 
				
			||||||
                      hideTimer = 0;
 | 
					                        hideTimer = 0;
 | 
				
			||||||
                  }, 500);
 | 
					                    }, 500);
 | 
				
			||||||
                  clearTimeout(showTimer);
 | 
					                    clearTimeout(showTimer);
 | 
				
			||||||
                  clearTimeout(abortTimer);
 | 
					                    clearTimeout(abortTimer);
 | 
				
			||||||
                  callback(xhr.response);
 | 
					                    callback(xhr.response);
 | 
				
			||||||
              }
 | 
					                }
 | 
				
			||||||
          }
 | 
					            }
 | 
				
			||||||
          xhr.onprogress = function (event) {
 | 
					            xhr.onprogress = function (event) {
 | 
				
			||||||
              const loaded = Math.round(event.loaded / 1024);
 | 
					                const loaded = Math.round(event.loaded / 1024);
 | 
				
			||||||
              const total = Math.round(event.total / 1024);
 | 
					                const total = Math.round(event.total / 1024);
 | 
				
			||||||
              pdiv.innerHTML = `${filename} - ${loaded}KB / ${total}KB`;
 | 
					                pdiv.innerHTML = `${filename} - ${loaded}KB / ${total}KB`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              clearTimeout(abortTimer);
 | 
					                clearTimeout(abortTimer);
 | 
				
			||||||
              abortTimer = setTimeout(retry, 3000);
 | 
					                abortTimer = setTimeout(retry, 3000);
 | 
				
			||||||
          };
 | 
					            };
 | 
				
			||||||
          xhr.open('GET', url);
 | 
					            xhr.open('GET', url);
 | 
				
			||||||
          xhr.send();
 | 
					            xhr.send();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          pdiv.innerHTML = `${filename} - starting`;
 | 
					            pdiv.innerHTML = `${filename} - starting`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          showTimer = setTimeout(() => {
 | 
					            showTimer = setTimeout(() => {
 | 
				
			||||||
              pdiv.style.opacity = '0.5';
 | 
					                pdiv.style.opacity = '0.5';
 | 
				
			||||||
          }, 100);
 | 
					            }, 100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          abortTimer = setTimeout(retry, 3000);
 | 
					            abortTimer = setTimeout(retry, 3000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (hideTimer) {
 | 
					            if (hideTimer) {
 | 
				
			||||||
              clearTimeout(hideTimer);
 | 
					                clearTimeout(hideTimer);
 | 
				
			||||||
              hideTimer = 0;
 | 
					                hideTimer = 0;
 | 
				
			||||||
          }
 | 
					            }
 | 
				
			||||||
      }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      document.title = wTitle;
 | 
					        document.title = wTitle;
 | 
				
			||||||
    </script>
 | 
					    </script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <script>
 | 
					    <script>
 | 
				
			||||||
      // Load wasm then initialize
 | 
					        // Load wasm then initialize
 | 
				
			||||||
      setTimeout(() => {
 | 
					        setTimeout(() => {
 | 
				
			||||||
          getLazyAsset('mkxp.wasm', 'Game engine', () => {
 | 
					            getLazyAsset('mkxp.wasm', 'Game engine', () => {
 | 
				
			||||||
              const s = document.createElement('script');
 | 
					                const s = document.createElement('script');
 | 
				
			||||||
              s.setAttribute('src', 'mkxp.js');
 | 
					                s.setAttribute('src', 'mkxp.js');
 | 
				
			||||||
              document.body.appendChild(s);
 | 
					                document.body.appendChild(s);
 | 
				
			||||||
          });
 | 
					            });
 | 
				
			||||||
      }, 500);
 | 
					        }, 500);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function simulateKeyEvent(eventType, keyCode, charCode) {
 | 
					    function simulateKeyEvent(eventType, keyCode, charCode) {
 | 
				
			||||||
        var e = document.createEventObject ? document.createEventObject() : document.createEvent("Events");
 | 
					        var e = document.createEventObject ? document.createEventObject() : document.createEvent("Events");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue