Pause when tab is hidden, using visibility change api
|
@ -11,8 +11,8 @@ android {
|
|||
applicationId = "me.lecaro.breakout"
|
||||
minSdk = 21
|
||||
targetSdk = 34
|
||||
versionCode = 29030875
|
||||
versionName = "29030875"
|
||||
versionCode = 29033834
|
||||
versionName = "29033834"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
|
||||
/>
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||
<title>Breakout 71 privacy policy</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🕹️</text></svg>">
|
||||
|
||||
<style type="text/css">
|
||||
body {
|
||||
max-width: 800px;
|
||||
margin: 40px auto;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Privacy policy</h1>
|
||||
<p>
|
||||
<a href="https://breakout.lecaro.me">Breakout 71</a> is published
|
||||
by Renan LE CARO, a French citizen and programmer. You can contact me at
|
||||
this adress : breakout71@lecaro.me
|
||||
</p>
|
||||
<p>
|
||||
If you access breakout.lecaro.me though a web browser, your IP address
|
||||
will be logged on my server to prevent abuses.
|
||||
<a href="https://staging.lecaro.me/">My server</a> is hosted by Hetzner
|
||||
Online GmbH in germany.
|
||||
</p>
|
||||
<p>
|
||||
If you install the app through google play or f-droid, no information will
|
||||
be collected at all by me.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -12,7 +12,7 @@ class MainActivity : android.app.Activity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
window.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN,er
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||
);
|
||||
// WebView.setWebContentsDebuggingEnabled(true)
|
||||
|
|
9
build.sh
|
@ -1,7 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
# the version number is just a unix timestamp in minutes
|
||||
versionCode=$1
|
||||
|
||||
defaultVersionCode=$(($(date +%s) / 60))
|
||||
versionCode=${1:-$defaultVersionCode}
|
||||
|
||||
# TODO crash without app version
|
||||
|
||||
source ~/.nvm/nvm.sh;
|
||||
|
||||
|
@ -48,4 +52,5 @@ npm run build
|
|||
|
||||
rm -rf ./app/src/main/assets/*
|
||||
cp public/* dist
|
||||
cp dist/* ./app/src/main/assets/
|
||||
rm -rf ./app/src/main/assets/*
|
||||
cp dist/index.html ./app/src/main/assets/
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
versionCode=$(($(date +%s) / 60))
|
||||
|
||||
bash ./build.sh $versionCode
|
||||
|
|
602
dist/editor-fe.b49a32c1.js
vendored
|
@ -1,602 +0,0 @@
|
|||
// modules are defined as an array
|
||||
// [ module function, map of requires ]
|
||||
//
|
||||
// map of requires is short require name -> numeric require
|
||||
//
|
||||
// anything defined in a previous bundle is accessed via the
|
||||
// orig method which is the require for previous bundles
|
||||
|
||||
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
||||
/* eslint-disable no-undef */
|
||||
var globalObject =
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof global !== 'undefined'
|
||||
? global
|
||||
: {};
|
||||
/* eslint-enable no-undef */
|
||||
|
||||
// Save the require from previous bundle to this closure if any
|
||||
var previousRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
|
||||
var cache = previousRequire.cache || {};
|
||||
// Do not use `require` to prevent Webpack from trying to bundle this call
|
||||
var nodeRequire =
|
||||
typeof module !== 'undefined' &&
|
||||
typeof module.require === 'function' &&
|
||||
module.require.bind(module);
|
||||
|
||||
function newRequire(name, jumped) {
|
||||
if (!cache[name]) {
|
||||
if (!modules[name]) {
|
||||
// if we cannot find the module within our internal map or
|
||||
// cache jump to the current global require ie. the last bundle
|
||||
// that was added to the page.
|
||||
var currentRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
if (!jumped && currentRequire) {
|
||||
return currentRequire(name, true);
|
||||
}
|
||||
|
||||
// If there are other bundles on this page the require from the
|
||||
// previous one is saved to 'previousRequire'. Repeat this as
|
||||
// many times as there are bundles until the module is found or
|
||||
// we exhaust the require chain.
|
||||
if (previousRequire) {
|
||||
return previousRequire(name, true);
|
||||
}
|
||||
|
||||
// Try the node require function if it exists.
|
||||
if (nodeRequire && typeof name === 'string') {
|
||||
return nodeRequire(name);
|
||||
}
|
||||
|
||||
var err = new Error("Cannot find module '" + name + "'");
|
||||
err.code = 'MODULE_NOT_FOUND';
|
||||
throw err;
|
||||
}
|
||||
|
||||
localRequire.resolve = resolve;
|
||||
localRequire.cache = {};
|
||||
|
||||
var module = (cache[name] = new newRequire.Module(name));
|
||||
|
||||
modules[name][0].call(
|
||||
module.exports,
|
||||
localRequire,
|
||||
module,
|
||||
module.exports,
|
||||
globalObject
|
||||
);
|
||||
}
|
||||
|
||||
return cache[name].exports;
|
||||
|
||||
function localRequire(x) {
|
||||
var res = localRequire.resolve(x);
|
||||
return res === false ? {} : newRequire(res);
|
||||
}
|
||||
|
||||
function resolve(x) {
|
||||
var id = modules[name][1][x];
|
||||
return id != null ? id : x;
|
||||
}
|
||||
}
|
||||
|
||||
function Module(moduleName) {
|
||||
this.id = moduleName;
|
||||
this.bundle = newRequire;
|
||||
this.exports = {};
|
||||
}
|
||||
|
||||
newRequire.isParcelRequire = true;
|
||||
newRequire.Module = Module;
|
||||
newRequire.modules = modules;
|
||||
newRequire.cache = cache;
|
||||
newRequire.parent = previousRequire;
|
||||
newRequire.register = function (id, exports) {
|
||||
modules[id] = [
|
||||
function (require, module) {
|
||||
module.exports = exports;
|
||||
},
|
||||
{},
|
||||
];
|
||||
};
|
||||
|
||||
Object.defineProperty(newRequire, 'root', {
|
||||
get: function () {
|
||||
return globalObject[parcelRequireName];
|
||||
},
|
||||
});
|
||||
|
||||
globalObject[parcelRequireName] = newRequire;
|
||||
|
||||
for (var i = 0; i < entry.length; i++) {
|
||||
newRequire(entry[i]);
|
||||
}
|
||||
|
||||
if (mainEntry) {
|
||||
// Expose entry point to Node, AMD or browser globals
|
||||
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
|
||||
var mainExports = newRequire(mainEntry);
|
||||
|
||||
// CommonJS
|
||||
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
||||
module.exports = mainExports;
|
||||
|
||||
// RequireJS
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
define(function () {
|
||||
return mainExports;
|
||||
});
|
||||
|
||||
// <script>
|
||||
} else if (globalName) {
|
||||
this[globalName] = mainExports;
|
||||
}
|
||||
}
|
||||
})({"bCtBW":[function(require,module,exports,__globalThis) {
|
||||
var global = arguments[3];
|
||||
var HMR_HOST = null;
|
||||
var HMR_PORT = null;
|
||||
var HMR_SECURE = false;
|
||||
var HMR_ENV_HASH = "d6ea1d42532a7575";
|
||||
var HMR_USE_SSE = false;
|
||||
module.bundle.HMR_BUNDLE_ID = "62211006b49a32c1";
|
||||
"use strict";
|
||||
/* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, HMR_USE_SSE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */ /*::
|
||||
import type {
|
||||
HMRAsset,
|
||||
HMRMessage,
|
||||
} from '@parcel/reporter-dev-server/src/HMRServer.js';
|
||||
interface ParcelRequire {
|
||||
(string): mixed;
|
||||
cache: {|[string]: ParcelModule|};
|
||||
hotData: {|[string]: mixed|};
|
||||
Module: any;
|
||||
parent: ?ParcelRequire;
|
||||
isParcelRequire: true;
|
||||
modules: {|[string]: [Function, {|[string]: string|}]|};
|
||||
HMR_BUNDLE_ID: string;
|
||||
root: ParcelRequire;
|
||||
}
|
||||
interface ParcelModule {
|
||||
hot: {|
|
||||
data: mixed,
|
||||
accept(cb: (Function) => void): void,
|
||||
dispose(cb: (mixed) => void): void,
|
||||
// accept(deps: Array<string> | string, cb: (Function) => void): void,
|
||||
// decline(): void,
|
||||
_acceptCallbacks: Array<(Function) => void>,
|
||||
_disposeCallbacks: Array<(mixed) => void>,
|
||||
|};
|
||||
}
|
||||
interface ExtensionContext {
|
||||
runtime: {|
|
||||
reload(): void,
|
||||
getURL(url: string): string;
|
||||
getManifest(): {manifest_version: number, ...};
|
||||
|};
|
||||
}
|
||||
declare var module: {bundle: ParcelRequire, ...};
|
||||
declare var HMR_HOST: string;
|
||||
declare var HMR_PORT: string;
|
||||
declare var HMR_ENV_HASH: string;
|
||||
declare var HMR_SECURE: boolean;
|
||||
declare var HMR_USE_SSE: boolean;
|
||||
declare var chrome: ExtensionContext;
|
||||
declare var browser: ExtensionContext;
|
||||
declare var __parcel__import__: (string) => Promise<void>;
|
||||
declare var __parcel__importScripts__: (string) => Promise<void>;
|
||||
declare var globalThis: typeof self;
|
||||
declare var ServiceWorkerGlobalScope: Object;
|
||||
*/ var OVERLAY_ID = '__parcel__error__overlay__';
|
||||
var OldModule = module.bundle.Module;
|
||||
function Module(moduleName) {
|
||||
OldModule.call(this, moduleName);
|
||||
this.hot = {
|
||||
data: module.bundle.hotData[moduleName],
|
||||
_acceptCallbacks: [],
|
||||
_disposeCallbacks: [],
|
||||
accept: function(fn) {
|
||||
this._acceptCallbacks.push(fn || function() {});
|
||||
},
|
||||
dispose: function(fn) {
|
||||
this._disposeCallbacks.push(fn);
|
||||
}
|
||||
};
|
||||
module.bundle.hotData[moduleName] = undefined;
|
||||
}
|
||||
module.bundle.Module = Module;
|
||||
module.bundle.hotData = {};
|
||||
var checkedAssets /*: {|[string]: boolean|} */ , disposedAssets /*: {|[string]: boolean|} */ , assetsToDispose /*: Array<[ParcelRequire, string]> */ , assetsToAccept /*: Array<[ParcelRequire, string]> */ ;
|
||||
function getHostname() {
|
||||
return HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
|
||||
}
|
||||
function getPort() {
|
||||
return HMR_PORT || location.port;
|
||||
}
|
||||
// eslint-disable-next-line no-redeclare
|
||||
var parent = module.bundle.parent;
|
||||
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
||||
var hostname = getHostname();
|
||||
var port = getPort();
|
||||
var protocol = HMR_SECURE || location.protocol == 'https:' && ![
|
||||
'localhost',
|
||||
'127.0.0.1',
|
||||
'0.0.0.0'
|
||||
].includes(hostname) ? 'wss' : 'ws';
|
||||
var ws;
|
||||
if (HMR_USE_SSE) ws = new EventSource('/__parcel_hmr');
|
||||
else try {
|
||||
ws = new WebSocket(protocol + '://' + hostname + (port ? ':' + port : '') + '/');
|
||||
} catch (err) {
|
||||
if (err.message) console.error(err.message);
|
||||
ws = {};
|
||||
}
|
||||
// Web extension context
|
||||
var extCtx = typeof browser === 'undefined' ? typeof chrome === 'undefined' ? null : chrome : browser;
|
||||
// Safari doesn't support sourceURL in error stacks.
|
||||
// eval may also be disabled via CSP, so do a quick check.
|
||||
var supportsSourceURL = false;
|
||||
try {
|
||||
(0, eval)('throw new Error("test"); //# sourceURL=test.js');
|
||||
} catch (err) {
|
||||
supportsSourceURL = err.stack.includes('test.js');
|
||||
}
|
||||
// $FlowFixMe
|
||||
ws.onmessage = async function(event /*: {data: string, ...} */ ) {
|
||||
checkedAssets = {} /*: {|[string]: boolean|} */ ;
|
||||
disposedAssets = {} /*: {|[string]: boolean|} */ ;
|
||||
assetsToAccept = [];
|
||||
assetsToDispose = [];
|
||||
var data /*: HMRMessage */ = JSON.parse(event.data);
|
||||
if (data.type === 'reload') fullReload();
|
||||
else if (data.type === 'update') {
|
||||
// Remove error overlay if there is one
|
||||
if (typeof document !== 'undefined') removeErrorOverlay();
|
||||
let assets = data.assets.filter((asset)=>asset.envHash === HMR_ENV_HASH);
|
||||
// Handle HMR Update
|
||||
let handled = assets.every((asset)=>{
|
||||
return asset.type === 'css' || asset.type === 'js' && hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
|
||||
});
|
||||
if (handled) {
|
||||
console.clear();
|
||||
// Dispatch custom event so other runtimes (e.g React Refresh) are aware.
|
||||
if (typeof window !== 'undefined' && typeof CustomEvent !== 'undefined') window.dispatchEvent(new CustomEvent('parcelhmraccept'));
|
||||
await hmrApplyUpdates(assets);
|
||||
hmrDisposeQueue();
|
||||
// Run accept callbacks. This will also re-execute other disposed assets in topological order.
|
||||
let processedAssets = {};
|
||||
for(let i = 0; i < assetsToAccept.length; i++){
|
||||
let id = assetsToAccept[i][1];
|
||||
if (!processedAssets[id]) {
|
||||
hmrAccept(assetsToAccept[i][0], id);
|
||||
processedAssets[id] = true;
|
||||
}
|
||||
}
|
||||
} else fullReload();
|
||||
}
|
||||
if (data.type === 'error') {
|
||||
// Log parcel errors to console
|
||||
for (let ansiDiagnostic of data.diagnostics.ansi){
|
||||
let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
|
||||
console.error("\uD83D\uDEA8 [parcel]: " + ansiDiagnostic.message + '\n' + stack + '\n\n' + ansiDiagnostic.hints.join('\n'));
|
||||
}
|
||||
if (typeof document !== 'undefined') {
|
||||
// Render the fancy html overlay
|
||||
removeErrorOverlay();
|
||||
var overlay = createErrorOverlay(data.diagnostics.html);
|
||||
// $FlowFixMe
|
||||
document.body.appendChild(overlay);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (ws instanceof WebSocket) {
|
||||
ws.onerror = function(e) {
|
||||
if (e.message) console.error(e.message);
|
||||
};
|
||||
ws.onclose = function() {
|
||||
console.warn("[parcel] \uD83D\uDEA8 Connection to the HMR server was lost");
|
||||
};
|
||||
}
|
||||
}
|
||||
function removeErrorOverlay() {
|
||||
var overlay = document.getElementById(OVERLAY_ID);
|
||||
if (overlay) {
|
||||
overlay.remove();
|
||||
console.log("[parcel] \u2728 Error resolved");
|
||||
}
|
||||
}
|
||||
function createErrorOverlay(diagnostics) {
|
||||
var overlay = document.createElement('div');
|
||||
overlay.id = OVERLAY_ID;
|
||||
let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';
|
||||
for (let diagnostic of diagnostics){
|
||||
let stack = diagnostic.frames.length ? diagnostic.frames.reduce((p, frame)=>{
|
||||
return `${p}
|
||||
<a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
|
||||
${frame.code}`;
|
||||
}, '') : diagnostic.stack;
|
||||
errorHTML += `
|
||||
<div>
|
||||
<div style="font-size: 18px; font-weight: bold; margin-top: 20px;">
|
||||
\u{1F6A8} ${diagnostic.message}
|
||||
</div>
|
||||
<pre>${stack}</pre>
|
||||
<div>
|
||||
${diagnostic.hints.map((hint)=>"<div>\uD83D\uDCA1 " + hint + '</div>').join('')}
|
||||
</div>
|
||||
${diagnostic.documentation ? `<div>\u{1F4DD} <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ''}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
errorHTML += '</div>';
|
||||
overlay.innerHTML = errorHTML;
|
||||
return overlay;
|
||||
}
|
||||
function fullReload() {
|
||||
if ('reload' in location) location.reload();
|
||||
else if (extCtx && extCtx.runtime && extCtx.runtime.reload) extCtx.runtime.reload();
|
||||
}
|
||||
function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
|
||||
var modules = bundle.modules;
|
||||
if (!modules) return [];
|
||||
var parents = [];
|
||||
var k, d, dep;
|
||||
for(k in modules)for(d in modules[k][1]){
|
||||
dep = modules[k][1][d];
|
||||
if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) parents.push([
|
||||
bundle,
|
||||
k
|
||||
]);
|
||||
}
|
||||
if (bundle.parent) parents = parents.concat(getParents(bundle.parent, id));
|
||||
return parents;
|
||||
}
|
||||
function updateLink(link) {
|
||||
var href = link.getAttribute('href');
|
||||
if (!href) return;
|
||||
var newLink = link.cloneNode();
|
||||
newLink.onload = function() {
|
||||
if (link.parentNode !== null) // $FlowFixMe
|
||||
link.parentNode.removeChild(link);
|
||||
};
|
||||
newLink.setAttribute('href', // $FlowFixMe
|
||||
href.split('?')[0] + '?' + Date.now());
|
||||
// $FlowFixMe
|
||||
link.parentNode.insertBefore(newLink, link.nextSibling);
|
||||
}
|
||||
var cssTimeout = null;
|
||||
function reloadCSS() {
|
||||
if (cssTimeout) return;
|
||||
cssTimeout = setTimeout(function() {
|
||||
var links = document.querySelectorAll('link[rel="stylesheet"]');
|
||||
for(var i = 0; i < links.length; i++){
|
||||
// $FlowFixMe[incompatible-type]
|
||||
var href /*: string */ = links[i].getAttribute('href');
|
||||
var hostname = getHostname();
|
||||
var servedFromHMRServer = hostname === 'localhost' ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()).test(href) : href.indexOf(hostname + ':' + getPort());
|
||||
var absolute = /^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
|
||||
if (!absolute) updateLink(links[i]);
|
||||
}
|
||||
cssTimeout = null;
|
||||
}, 50);
|
||||
}
|
||||
function hmrDownload(asset) {
|
||||
if (asset.type === 'js') {
|
||||
if (typeof document !== 'undefined') {
|
||||
let script = document.createElement('script');
|
||||
script.src = asset.url + '?t=' + Date.now();
|
||||
if (asset.outputFormat === 'esmodule') script.type = 'module';
|
||||
return new Promise((resolve, reject)=>{
|
||||
var _document$head;
|
||||
script.onload = ()=>resolve(script);
|
||||
script.onerror = reject;
|
||||
(_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script);
|
||||
});
|
||||
} else if (typeof importScripts === 'function') {
|
||||
// Worker scripts
|
||||
if (asset.outputFormat === 'esmodule') return import(asset.url + '?t=' + Date.now());
|
||||
else return new Promise((resolve, reject)=>{
|
||||
try {
|
||||
importScripts(asset.url + '?t=' + Date.now());
|
||||
resolve();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
async function hmrApplyUpdates(assets) {
|
||||
global.parcelHotUpdate = Object.create(null);
|
||||
let scriptsToRemove;
|
||||
try {
|
||||
// If sourceURL comments aren't supported in eval, we need to load
|
||||
// the update from the dev server over HTTP so that stack traces
|
||||
// are correct in errors/logs. This is much slower than eval, so
|
||||
// we only do it if needed (currently just Safari).
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=137297
|
||||
// This path is also taken if a CSP disallows eval.
|
||||
if (!supportsSourceURL) {
|
||||
let promises = assets.map((asset)=>{
|
||||
var _hmrDownload;
|
||||
return (_hmrDownload = hmrDownload(asset)) === null || _hmrDownload === void 0 ? void 0 : _hmrDownload.catch((err)=>{
|
||||
// Web extension fix
|
||||
if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 && typeof ServiceWorkerGlobalScope != 'undefined' && global instanceof ServiceWorkerGlobalScope) {
|
||||
extCtx.runtime.reload();
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
scriptsToRemove = await Promise.all(promises);
|
||||
}
|
||||
assets.forEach(function(asset) {
|
||||
hmrApply(module.bundle.root, asset);
|
||||
});
|
||||
} finally{
|
||||
delete global.parcelHotUpdate;
|
||||
if (scriptsToRemove) scriptsToRemove.forEach((script)=>{
|
||||
if (script) {
|
||||
var _document$head2;
|
||||
(_document$head2 = document.head) === null || _document$head2 === void 0 || _document$head2.removeChild(script);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function hmrApply(bundle /*: ParcelRequire */ , asset /*: HMRAsset */ ) {
|
||||
var modules = bundle.modules;
|
||||
if (!modules) return;
|
||||
if (asset.type === 'css') reloadCSS();
|
||||
else if (asset.type === 'js') {
|
||||
let deps = asset.depsByBundle[bundle.HMR_BUNDLE_ID];
|
||||
if (deps) {
|
||||
if (modules[asset.id]) {
|
||||
// Remove dependencies that are removed and will become orphaned.
|
||||
// This is necessary so that if the asset is added back again, the cache is gone, and we prevent a full page reload.
|
||||
let oldDeps = modules[asset.id][1];
|
||||
for(let dep in oldDeps)if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
|
||||
let id = oldDeps[dep];
|
||||
let parents = getParents(module.bundle.root, id);
|
||||
if (parents.length === 1) hmrDelete(module.bundle.root, id);
|
||||
}
|
||||
}
|
||||
if (supportsSourceURL) // Global eval. We would use `new Function` here but browser
|
||||
// support for source maps is better with eval.
|
||||
(0, eval)(asset.output);
|
||||
// $FlowFixMe
|
||||
let fn = global.parcelHotUpdate[asset.id];
|
||||
modules[asset.id] = [
|
||||
fn,
|
||||
deps
|
||||
];
|
||||
}
|
||||
// Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
|
||||
// This is required in case modules are duplicated. We need to ensure all instances have the updated code.
|
||||
if (bundle.parent) hmrApply(bundle.parent, asset);
|
||||
}
|
||||
}
|
||||
function hmrDelete(bundle, id) {
|
||||
let modules = bundle.modules;
|
||||
if (!modules) return;
|
||||
if (modules[id]) {
|
||||
// Collect dependencies that will become orphaned when this module is deleted.
|
||||
let deps = modules[id][1];
|
||||
let orphans = [];
|
||||
for(let dep in deps){
|
||||
let parents = getParents(module.bundle.root, deps[dep]);
|
||||
if (parents.length === 1) orphans.push(deps[dep]);
|
||||
}
|
||||
// Delete the module. This must be done before deleting dependencies in case of circular dependencies.
|
||||
delete modules[id];
|
||||
delete bundle.cache[id];
|
||||
// Now delete the orphans.
|
||||
orphans.forEach((id)=>{
|
||||
hmrDelete(module.bundle.root, id);
|
||||
});
|
||||
} else if (bundle.parent) hmrDelete(bundle.parent, id);
|
||||
}
|
||||
function hmrAcceptCheck(bundle /*: ParcelRequire */ , id /*: string */ , depsByBundle /*: ?{ [string]: { [string]: string } }*/ ) {
|
||||
if (hmrAcceptCheckOne(bundle, id, depsByBundle)) return true;
|
||||
// Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
|
||||
let parents = getParents(module.bundle.root, id);
|
||||
let accepted = false;
|
||||
while(parents.length > 0){
|
||||
let v = parents.shift();
|
||||
let a = hmrAcceptCheckOne(v[0], v[1], null);
|
||||
if (a) // If this parent accepts, stop traversing upward, but still consider siblings.
|
||||
accepted = true;
|
||||
else {
|
||||
// Otherwise, queue the parents in the next level upward.
|
||||
let p = getParents(module.bundle.root, v[1]);
|
||||
if (p.length === 0) {
|
||||
// If there are no parents, then we've reached an entry without accepting. Reload.
|
||||
accepted = false;
|
||||
break;
|
||||
}
|
||||
parents.push(...p);
|
||||
}
|
||||
}
|
||||
return accepted;
|
||||
}
|
||||
function hmrAcceptCheckOne(bundle /*: ParcelRequire */ , id /*: string */ , depsByBundle /*: ?{ [string]: { [string]: string } }*/ ) {
|
||||
var modules = bundle.modules;
|
||||
if (!modules) return;
|
||||
if (depsByBundle && !depsByBundle[bundle.HMR_BUNDLE_ID]) {
|
||||
// If we reached the root bundle without finding where the asset should go,
|
||||
// there's nothing to do. Mark as "accepted" so we don't reload the page.
|
||||
if (!bundle.parent) return true;
|
||||
return hmrAcceptCheck(bundle.parent, id, depsByBundle);
|
||||
}
|
||||
if (checkedAssets[id]) return true;
|
||||
checkedAssets[id] = true;
|
||||
var cached = bundle.cache[id];
|
||||
assetsToDispose.push([
|
||||
bundle,
|
||||
id
|
||||
]);
|
||||
if (!cached || cached.hot && cached.hot._acceptCallbacks.length) {
|
||||
assetsToAccept.push([
|
||||
bundle,
|
||||
id
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function hmrDisposeQueue() {
|
||||
// Dispose all old assets.
|
||||
for(let i = 0; i < assetsToDispose.length; i++){
|
||||
let id = assetsToDispose[i][1];
|
||||
if (!disposedAssets[id]) {
|
||||
hmrDispose(assetsToDispose[i][0], id);
|
||||
disposedAssets[id] = true;
|
||||
}
|
||||
}
|
||||
assetsToDispose = [];
|
||||
}
|
||||
function hmrDispose(bundle /*: ParcelRequire */ , id /*: string */ ) {
|
||||
var cached = bundle.cache[id];
|
||||
bundle.hotData[id] = {};
|
||||
if (cached && cached.hot) cached.hot.data = bundle.hotData[id];
|
||||
if (cached && cached.hot && cached.hot._disposeCallbacks.length) cached.hot._disposeCallbacks.forEach(function(cb) {
|
||||
cb(bundle.hotData[id]);
|
||||
});
|
||||
delete bundle.cache[id];
|
||||
}
|
||||
function hmrAccept(bundle /*: ParcelRequire */ , id /*: string */ ) {
|
||||
// Execute the module.
|
||||
bundle(id);
|
||||
// Run the accept callbacks in the new version of the module.
|
||||
var cached = bundle.cache[id];
|
||||
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
|
||||
let assetsToAlsoAccept = [];
|
||||
cached.hot._acceptCallbacks.forEach(function(cb) {
|
||||
let additionalAssets = cb(function() {
|
||||
return getParents(module.bundle.root, id);
|
||||
});
|
||||
if (Array.isArray(additionalAssets) && additionalAssets.length) assetsToAlsoAccept.push(...additionalAssets);
|
||||
});
|
||||
if (assetsToAlsoAccept.length) {
|
||||
let handled = assetsToAlsoAccept.every(function(a) {
|
||||
return hmrAcceptCheck(a[0], a[1]);
|
||||
});
|
||||
if (!handled) return fullReload();
|
||||
hmrDisposeQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},{}],"3Egqq":[function(require,module,exports,__globalThis) {
|
||||
|
||||
},{}]},["bCtBW","3Egqq"], "3Egqq", "parcelRequire94c2")
|
||||
|
||||
//# sourceMappingURL=editor-fe.b49a32c1.js.map
|
1
dist/editor-fe.b49a32c1.js.map
vendored
602
dist/editor.767b7f59.js
vendored
|
@ -1,602 +0,0 @@
|
|||
// modules are defined as an array
|
||||
// [ module function, map of requires ]
|
||||
//
|
||||
// map of requires is short require name -> numeric require
|
||||
//
|
||||
// anything defined in a previous bundle is accessed via the
|
||||
// orig method which is the require for previous bundles
|
||||
|
||||
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
||||
/* eslint-disable no-undef */
|
||||
var globalObject =
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof global !== 'undefined'
|
||||
? global
|
||||
: {};
|
||||
/* eslint-enable no-undef */
|
||||
|
||||
// Save the require from previous bundle to this closure if any
|
||||
var previousRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
|
||||
var cache = previousRequire.cache || {};
|
||||
// Do not use `require` to prevent Webpack from trying to bundle this call
|
||||
var nodeRequire =
|
||||
typeof module !== 'undefined' &&
|
||||
typeof module.require === 'function' &&
|
||||
module.require.bind(module);
|
||||
|
||||
function newRequire(name, jumped) {
|
||||
if (!cache[name]) {
|
||||
if (!modules[name]) {
|
||||
// if we cannot find the module within our internal map or
|
||||
// cache jump to the current global require ie. the last bundle
|
||||
// that was added to the page.
|
||||
var currentRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
if (!jumped && currentRequire) {
|
||||
return currentRequire(name, true);
|
||||
}
|
||||
|
||||
// If there are other bundles on this page the require from the
|
||||
// previous one is saved to 'previousRequire'. Repeat this as
|
||||
// many times as there are bundles until the module is found or
|
||||
// we exhaust the require chain.
|
||||
if (previousRequire) {
|
||||
return previousRequire(name, true);
|
||||
}
|
||||
|
||||
// Try the node require function if it exists.
|
||||
if (nodeRequire && typeof name === 'string') {
|
||||
return nodeRequire(name);
|
||||
}
|
||||
|
||||
var err = new Error("Cannot find module '" + name + "'");
|
||||
err.code = 'MODULE_NOT_FOUND';
|
||||
throw err;
|
||||
}
|
||||
|
||||
localRequire.resolve = resolve;
|
||||
localRequire.cache = {};
|
||||
|
||||
var module = (cache[name] = new newRequire.Module(name));
|
||||
|
||||
modules[name][0].call(
|
||||
module.exports,
|
||||
localRequire,
|
||||
module,
|
||||
module.exports,
|
||||
globalObject
|
||||
);
|
||||
}
|
||||
|
||||
return cache[name].exports;
|
||||
|
||||
function localRequire(x) {
|
||||
var res = localRequire.resolve(x);
|
||||
return res === false ? {} : newRequire(res);
|
||||
}
|
||||
|
||||
function resolve(x) {
|
||||
var id = modules[name][1][x];
|
||||
return id != null ? id : x;
|
||||
}
|
||||
}
|
||||
|
||||
function Module(moduleName) {
|
||||
this.id = moduleName;
|
||||
this.bundle = newRequire;
|
||||
this.exports = {};
|
||||
}
|
||||
|
||||
newRequire.isParcelRequire = true;
|
||||
newRequire.Module = Module;
|
||||
newRequire.modules = modules;
|
||||
newRequire.cache = cache;
|
||||
newRequire.parent = previousRequire;
|
||||
newRequire.register = function (id, exports) {
|
||||
modules[id] = [
|
||||
function (require, module) {
|
||||
module.exports = exports;
|
||||
},
|
||||
{},
|
||||
];
|
||||
};
|
||||
|
||||
Object.defineProperty(newRequire, 'root', {
|
||||
get: function () {
|
||||
return globalObject[parcelRequireName];
|
||||
},
|
||||
});
|
||||
|
||||
globalObject[parcelRequireName] = newRequire;
|
||||
|
||||
for (var i = 0; i < entry.length; i++) {
|
||||
newRequire(entry[i]);
|
||||
}
|
||||
|
||||
if (mainEntry) {
|
||||
// Expose entry point to Node, AMD or browser globals
|
||||
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
|
||||
var mainExports = newRequire(mainEntry);
|
||||
|
||||
// CommonJS
|
||||
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
||||
module.exports = mainExports;
|
||||
|
||||
// RequireJS
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
define(function () {
|
||||
return mainExports;
|
||||
});
|
||||
|
||||
// <script>
|
||||
} else if (globalName) {
|
||||
this[globalName] = mainExports;
|
||||
}
|
||||
}
|
||||
})({"dOfEu":[function(require,module,exports,__globalThis) {
|
||||
var global = arguments[3];
|
||||
var HMR_HOST = null;
|
||||
var HMR_PORT = null;
|
||||
var HMR_SECURE = false;
|
||||
var HMR_ENV_HASH = "d6ea1d42532a7575";
|
||||
var HMR_USE_SSE = false;
|
||||
module.bundle.HMR_BUNDLE_ID = "c9ef8121767b7f59";
|
||||
"use strict";
|
||||
/* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, HMR_USE_SSE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */ /*::
|
||||
import type {
|
||||
HMRAsset,
|
||||
HMRMessage,
|
||||
} from '@parcel/reporter-dev-server/src/HMRServer.js';
|
||||
interface ParcelRequire {
|
||||
(string): mixed;
|
||||
cache: {|[string]: ParcelModule|};
|
||||
hotData: {|[string]: mixed|};
|
||||
Module: any;
|
||||
parent: ?ParcelRequire;
|
||||
isParcelRequire: true;
|
||||
modules: {|[string]: [Function, {|[string]: string|}]|};
|
||||
HMR_BUNDLE_ID: string;
|
||||
root: ParcelRequire;
|
||||
}
|
||||
interface ParcelModule {
|
||||
hot: {|
|
||||
data: mixed,
|
||||
accept(cb: (Function) => void): void,
|
||||
dispose(cb: (mixed) => void): void,
|
||||
// accept(deps: Array<string> | string, cb: (Function) => void): void,
|
||||
// decline(): void,
|
||||
_acceptCallbacks: Array<(Function) => void>,
|
||||
_disposeCallbacks: Array<(mixed) => void>,
|
||||
|};
|
||||
}
|
||||
interface ExtensionContext {
|
||||
runtime: {|
|
||||
reload(): void,
|
||||
getURL(url: string): string;
|
||||
getManifest(): {manifest_version: number, ...};
|
||||
|};
|
||||
}
|
||||
declare var module: {bundle: ParcelRequire, ...};
|
||||
declare var HMR_HOST: string;
|
||||
declare var HMR_PORT: string;
|
||||
declare var HMR_ENV_HASH: string;
|
||||
declare var HMR_SECURE: boolean;
|
||||
declare var HMR_USE_SSE: boolean;
|
||||
declare var chrome: ExtensionContext;
|
||||
declare var browser: ExtensionContext;
|
||||
declare var __parcel__import__: (string) => Promise<void>;
|
||||
declare var __parcel__importScripts__: (string) => Promise<void>;
|
||||
declare var globalThis: typeof self;
|
||||
declare var ServiceWorkerGlobalScope: Object;
|
||||
*/ var OVERLAY_ID = '__parcel__error__overlay__';
|
||||
var OldModule = module.bundle.Module;
|
||||
function Module(moduleName) {
|
||||
OldModule.call(this, moduleName);
|
||||
this.hot = {
|
||||
data: module.bundle.hotData[moduleName],
|
||||
_acceptCallbacks: [],
|
||||
_disposeCallbacks: [],
|
||||
accept: function(fn) {
|
||||
this._acceptCallbacks.push(fn || function() {});
|
||||
},
|
||||
dispose: function(fn) {
|
||||
this._disposeCallbacks.push(fn);
|
||||
}
|
||||
};
|
||||
module.bundle.hotData[moduleName] = undefined;
|
||||
}
|
||||
module.bundle.Module = Module;
|
||||
module.bundle.hotData = {};
|
||||
var checkedAssets /*: {|[string]: boolean|} */ , disposedAssets /*: {|[string]: boolean|} */ , assetsToDispose /*: Array<[ParcelRequire, string]> */ , assetsToAccept /*: Array<[ParcelRequire, string]> */ ;
|
||||
function getHostname() {
|
||||
return HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
|
||||
}
|
||||
function getPort() {
|
||||
return HMR_PORT || location.port;
|
||||
}
|
||||
// eslint-disable-next-line no-redeclare
|
||||
var parent = module.bundle.parent;
|
||||
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
||||
var hostname = getHostname();
|
||||
var port = getPort();
|
||||
var protocol = HMR_SECURE || location.protocol == 'https:' && ![
|
||||
'localhost',
|
||||
'127.0.0.1',
|
||||
'0.0.0.0'
|
||||
].includes(hostname) ? 'wss' : 'ws';
|
||||
var ws;
|
||||
if (HMR_USE_SSE) ws = new EventSource('/__parcel_hmr');
|
||||
else try {
|
||||
ws = new WebSocket(protocol + '://' + hostname + (port ? ':' + port : '') + '/');
|
||||
} catch (err) {
|
||||
if (err.message) console.error(err.message);
|
||||
ws = {};
|
||||
}
|
||||
// Web extension context
|
||||
var extCtx = typeof browser === 'undefined' ? typeof chrome === 'undefined' ? null : chrome : browser;
|
||||
// Safari doesn't support sourceURL in error stacks.
|
||||
// eval may also be disabled via CSP, so do a quick check.
|
||||
var supportsSourceURL = false;
|
||||
try {
|
||||
(0, eval)('throw new Error("test"); //# sourceURL=test.js');
|
||||
} catch (err) {
|
||||
supportsSourceURL = err.stack.includes('test.js');
|
||||
}
|
||||
// $FlowFixMe
|
||||
ws.onmessage = async function(event /*: {data: string, ...} */ ) {
|
||||
checkedAssets = {} /*: {|[string]: boolean|} */ ;
|
||||
disposedAssets = {} /*: {|[string]: boolean|} */ ;
|
||||
assetsToAccept = [];
|
||||
assetsToDispose = [];
|
||||
var data /*: HMRMessage */ = JSON.parse(event.data);
|
||||
if (data.type === 'reload') fullReload();
|
||||
else if (data.type === 'update') {
|
||||
// Remove error overlay if there is one
|
||||
if (typeof document !== 'undefined') removeErrorOverlay();
|
||||
let assets = data.assets.filter((asset)=>asset.envHash === HMR_ENV_HASH);
|
||||
// Handle HMR Update
|
||||
let handled = assets.every((asset)=>{
|
||||
return asset.type === 'css' || asset.type === 'js' && hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
|
||||
});
|
||||
if (handled) {
|
||||
console.clear();
|
||||
// Dispatch custom event so other runtimes (e.g React Refresh) are aware.
|
||||
if (typeof window !== 'undefined' && typeof CustomEvent !== 'undefined') window.dispatchEvent(new CustomEvent('parcelhmraccept'));
|
||||
await hmrApplyUpdates(assets);
|
||||
hmrDisposeQueue();
|
||||
// Run accept callbacks. This will also re-execute other disposed assets in topological order.
|
||||
let processedAssets = {};
|
||||
for(let i = 0; i < assetsToAccept.length; i++){
|
||||
let id = assetsToAccept[i][1];
|
||||
if (!processedAssets[id]) {
|
||||
hmrAccept(assetsToAccept[i][0], id);
|
||||
processedAssets[id] = true;
|
||||
}
|
||||
}
|
||||
} else fullReload();
|
||||
}
|
||||
if (data.type === 'error') {
|
||||
// Log parcel errors to console
|
||||
for (let ansiDiagnostic of data.diagnostics.ansi){
|
||||
let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
|
||||
console.error("\uD83D\uDEA8 [parcel]: " + ansiDiagnostic.message + '\n' + stack + '\n\n' + ansiDiagnostic.hints.join('\n'));
|
||||
}
|
||||
if (typeof document !== 'undefined') {
|
||||
// Render the fancy html overlay
|
||||
removeErrorOverlay();
|
||||
var overlay = createErrorOverlay(data.diagnostics.html);
|
||||
// $FlowFixMe
|
||||
document.body.appendChild(overlay);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (ws instanceof WebSocket) {
|
||||
ws.onerror = function(e) {
|
||||
if (e.message) console.error(e.message);
|
||||
};
|
||||
ws.onclose = function() {
|
||||
console.warn("[parcel] \uD83D\uDEA8 Connection to the HMR server was lost");
|
||||
};
|
||||
}
|
||||
}
|
||||
function removeErrorOverlay() {
|
||||
var overlay = document.getElementById(OVERLAY_ID);
|
||||
if (overlay) {
|
||||
overlay.remove();
|
||||
console.log("[parcel] \u2728 Error resolved");
|
||||
}
|
||||
}
|
||||
function createErrorOverlay(diagnostics) {
|
||||
var overlay = document.createElement('div');
|
||||
overlay.id = OVERLAY_ID;
|
||||
let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';
|
||||
for (let diagnostic of diagnostics){
|
||||
let stack = diagnostic.frames.length ? diagnostic.frames.reduce((p, frame)=>{
|
||||
return `${p}
|
||||
<a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
|
||||
${frame.code}`;
|
||||
}, '') : diagnostic.stack;
|
||||
errorHTML += `
|
||||
<div>
|
||||
<div style="font-size: 18px; font-weight: bold; margin-top: 20px;">
|
||||
\u{1F6A8} ${diagnostic.message}
|
||||
</div>
|
||||
<pre>${stack}</pre>
|
||||
<div>
|
||||
${diagnostic.hints.map((hint)=>"<div>\uD83D\uDCA1 " + hint + '</div>').join('')}
|
||||
</div>
|
||||
${diagnostic.documentation ? `<div>\u{1F4DD} <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ''}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
errorHTML += '</div>';
|
||||
overlay.innerHTML = errorHTML;
|
||||
return overlay;
|
||||
}
|
||||
function fullReload() {
|
||||
if ('reload' in location) location.reload();
|
||||
else if (extCtx && extCtx.runtime && extCtx.runtime.reload) extCtx.runtime.reload();
|
||||
}
|
||||
function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
|
||||
var modules = bundle.modules;
|
||||
if (!modules) return [];
|
||||
var parents = [];
|
||||
var k, d, dep;
|
||||
for(k in modules)for(d in modules[k][1]){
|
||||
dep = modules[k][1][d];
|
||||
if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) parents.push([
|
||||
bundle,
|
||||
k
|
||||
]);
|
||||
}
|
||||
if (bundle.parent) parents = parents.concat(getParents(bundle.parent, id));
|
||||
return parents;
|
||||
}
|
||||
function updateLink(link) {
|
||||
var href = link.getAttribute('href');
|
||||
if (!href) return;
|
||||
var newLink = link.cloneNode();
|
||||
newLink.onload = function() {
|
||||
if (link.parentNode !== null) // $FlowFixMe
|
||||
link.parentNode.removeChild(link);
|
||||
};
|
||||
newLink.setAttribute('href', // $FlowFixMe
|
||||
href.split('?')[0] + '?' + Date.now());
|
||||
// $FlowFixMe
|
||||
link.parentNode.insertBefore(newLink, link.nextSibling);
|
||||
}
|
||||
var cssTimeout = null;
|
||||
function reloadCSS() {
|
||||
if (cssTimeout) return;
|
||||
cssTimeout = setTimeout(function() {
|
||||
var links = document.querySelectorAll('link[rel="stylesheet"]');
|
||||
for(var i = 0; i < links.length; i++){
|
||||
// $FlowFixMe[incompatible-type]
|
||||
var href /*: string */ = links[i].getAttribute('href');
|
||||
var hostname = getHostname();
|
||||
var servedFromHMRServer = hostname === 'localhost' ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()).test(href) : href.indexOf(hostname + ':' + getPort());
|
||||
var absolute = /^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
|
||||
if (!absolute) updateLink(links[i]);
|
||||
}
|
||||
cssTimeout = null;
|
||||
}, 50);
|
||||
}
|
||||
function hmrDownload(asset) {
|
||||
if (asset.type === 'js') {
|
||||
if (typeof document !== 'undefined') {
|
||||
let script = document.createElement('script');
|
||||
script.src = asset.url + '?t=' + Date.now();
|
||||
if (asset.outputFormat === 'esmodule') script.type = 'module';
|
||||
return new Promise((resolve, reject)=>{
|
||||
var _document$head;
|
||||
script.onload = ()=>resolve(script);
|
||||
script.onerror = reject;
|
||||
(_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script);
|
||||
});
|
||||
} else if (typeof importScripts === 'function') {
|
||||
// Worker scripts
|
||||
if (asset.outputFormat === 'esmodule') return import(asset.url + '?t=' + Date.now());
|
||||
else return new Promise((resolve, reject)=>{
|
||||
try {
|
||||
importScripts(asset.url + '?t=' + Date.now());
|
||||
resolve();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
async function hmrApplyUpdates(assets) {
|
||||
global.parcelHotUpdate = Object.create(null);
|
||||
let scriptsToRemove;
|
||||
try {
|
||||
// If sourceURL comments aren't supported in eval, we need to load
|
||||
// the update from the dev server over HTTP so that stack traces
|
||||
// are correct in errors/logs. This is much slower than eval, so
|
||||
// we only do it if needed (currently just Safari).
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=137297
|
||||
// This path is also taken if a CSP disallows eval.
|
||||
if (!supportsSourceURL) {
|
||||
let promises = assets.map((asset)=>{
|
||||
var _hmrDownload;
|
||||
return (_hmrDownload = hmrDownload(asset)) === null || _hmrDownload === void 0 ? void 0 : _hmrDownload.catch((err)=>{
|
||||
// Web extension fix
|
||||
if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 && typeof ServiceWorkerGlobalScope != 'undefined' && global instanceof ServiceWorkerGlobalScope) {
|
||||
extCtx.runtime.reload();
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
scriptsToRemove = await Promise.all(promises);
|
||||
}
|
||||
assets.forEach(function(asset) {
|
||||
hmrApply(module.bundle.root, asset);
|
||||
});
|
||||
} finally{
|
||||
delete global.parcelHotUpdate;
|
||||
if (scriptsToRemove) scriptsToRemove.forEach((script)=>{
|
||||
if (script) {
|
||||
var _document$head2;
|
||||
(_document$head2 = document.head) === null || _document$head2 === void 0 || _document$head2.removeChild(script);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function hmrApply(bundle /*: ParcelRequire */ , asset /*: HMRAsset */ ) {
|
||||
var modules = bundle.modules;
|
||||
if (!modules) return;
|
||||
if (asset.type === 'css') reloadCSS();
|
||||
else if (asset.type === 'js') {
|
||||
let deps = asset.depsByBundle[bundle.HMR_BUNDLE_ID];
|
||||
if (deps) {
|
||||
if (modules[asset.id]) {
|
||||
// Remove dependencies that are removed and will become orphaned.
|
||||
// This is necessary so that if the asset is added back again, the cache is gone, and we prevent a full page reload.
|
||||
let oldDeps = modules[asset.id][1];
|
||||
for(let dep in oldDeps)if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
|
||||
let id = oldDeps[dep];
|
||||
let parents = getParents(module.bundle.root, id);
|
||||
if (parents.length === 1) hmrDelete(module.bundle.root, id);
|
||||
}
|
||||
}
|
||||
if (supportsSourceURL) // Global eval. We would use `new Function` here but browser
|
||||
// support for source maps is better with eval.
|
||||
(0, eval)(asset.output);
|
||||
// $FlowFixMe
|
||||
let fn = global.parcelHotUpdate[asset.id];
|
||||
modules[asset.id] = [
|
||||
fn,
|
||||
deps
|
||||
];
|
||||
}
|
||||
// Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
|
||||
// This is required in case modules are duplicated. We need to ensure all instances have the updated code.
|
||||
if (bundle.parent) hmrApply(bundle.parent, asset);
|
||||
}
|
||||
}
|
||||
function hmrDelete(bundle, id) {
|
||||
let modules = bundle.modules;
|
||||
if (!modules) return;
|
||||
if (modules[id]) {
|
||||
// Collect dependencies that will become orphaned when this module is deleted.
|
||||
let deps = modules[id][1];
|
||||
let orphans = [];
|
||||
for(let dep in deps){
|
||||
let parents = getParents(module.bundle.root, deps[dep]);
|
||||
if (parents.length === 1) orphans.push(deps[dep]);
|
||||
}
|
||||
// Delete the module. This must be done before deleting dependencies in case of circular dependencies.
|
||||
delete modules[id];
|
||||
delete bundle.cache[id];
|
||||
// Now delete the orphans.
|
||||
orphans.forEach((id)=>{
|
||||
hmrDelete(module.bundle.root, id);
|
||||
});
|
||||
} else if (bundle.parent) hmrDelete(bundle.parent, id);
|
||||
}
|
||||
function hmrAcceptCheck(bundle /*: ParcelRequire */ , id /*: string */ , depsByBundle /*: ?{ [string]: { [string]: string } }*/ ) {
|
||||
if (hmrAcceptCheckOne(bundle, id, depsByBundle)) return true;
|
||||
// Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
|
||||
let parents = getParents(module.bundle.root, id);
|
||||
let accepted = false;
|
||||
while(parents.length > 0){
|
||||
let v = parents.shift();
|
||||
let a = hmrAcceptCheckOne(v[0], v[1], null);
|
||||
if (a) // If this parent accepts, stop traversing upward, but still consider siblings.
|
||||
accepted = true;
|
||||
else {
|
||||
// Otherwise, queue the parents in the next level upward.
|
||||
let p = getParents(module.bundle.root, v[1]);
|
||||
if (p.length === 0) {
|
||||
// If there are no parents, then we've reached an entry without accepting. Reload.
|
||||
accepted = false;
|
||||
break;
|
||||
}
|
||||
parents.push(...p);
|
||||
}
|
||||
}
|
||||
return accepted;
|
||||
}
|
||||
function hmrAcceptCheckOne(bundle /*: ParcelRequire */ , id /*: string */ , depsByBundle /*: ?{ [string]: { [string]: string } }*/ ) {
|
||||
var modules = bundle.modules;
|
||||
if (!modules) return;
|
||||
if (depsByBundle && !depsByBundle[bundle.HMR_BUNDLE_ID]) {
|
||||
// If we reached the root bundle without finding where the asset should go,
|
||||
// there's nothing to do. Mark as "accepted" so we don't reload the page.
|
||||
if (!bundle.parent) return true;
|
||||
return hmrAcceptCheck(bundle.parent, id, depsByBundle);
|
||||
}
|
||||
if (checkedAssets[id]) return true;
|
||||
checkedAssets[id] = true;
|
||||
var cached = bundle.cache[id];
|
||||
assetsToDispose.push([
|
||||
bundle,
|
||||
id
|
||||
]);
|
||||
if (!cached || cached.hot && cached.hot._acceptCallbacks.length) {
|
||||
assetsToAccept.push([
|
||||
bundle,
|
||||
id
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function hmrDisposeQueue() {
|
||||
// Dispose all old assets.
|
||||
for(let i = 0; i < assetsToDispose.length; i++){
|
||||
let id = assetsToDispose[i][1];
|
||||
if (!disposedAssets[id]) {
|
||||
hmrDispose(assetsToDispose[i][0], id);
|
||||
disposedAssets[id] = true;
|
||||
}
|
||||
}
|
||||
assetsToDispose = [];
|
||||
}
|
||||
function hmrDispose(bundle /*: ParcelRequire */ , id /*: string */ ) {
|
||||
var cached = bundle.cache[id];
|
||||
bundle.hotData[id] = {};
|
||||
if (cached && cached.hot) cached.hot.data = bundle.hotData[id];
|
||||
if (cached && cached.hot && cached.hot._disposeCallbacks.length) cached.hot._disposeCallbacks.forEach(function(cb) {
|
||||
cb(bundle.hotData[id]);
|
||||
});
|
||||
delete bundle.cache[id];
|
||||
}
|
||||
function hmrAccept(bundle /*: ParcelRequire */ , id /*: string */ ) {
|
||||
// Execute the module.
|
||||
bundle(id);
|
||||
// Run the accept callbacks in the new version of the module.
|
||||
var cached = bundle.cache[id];
|
||||
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
|
||||
let assetsToAlsoAccept = [];
|
||||
cached.hot._acceptCallbacks.forEach(function(cb) {
|
||||
let additionalAssets = cb(function() {
|
||||
return getParents(module.bundle.root, id);
|
||||
});
|
||||
if (Array.isArray(additionalAssets) && additionalAssets.length) assetsToAlsoAccept.push(...additionalAssets);
|
||||
});
|
||||
if (assetsToAlsoAccept.length) {
|
||||
let handled = assetsToAlsoAccept.every(function(a) {
|
||||
return hmrAcceptCheck(a[0], a[1]);
|
||||
});
|
||||
if (!handled) return fullReload();
|
||||
hmrDisposeQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},{}],"5n6Un":[function(require,module,exports,__globalThis) {
|
||||
|
||||
},{}]},["dOfEu","5n6Un"], "5n6Un", "parcelRequire94c2")
|
||||
|
||||
//# sourceMappingURL=editor.767b7f59.js.map
|
1
dist/editor.767b7f59.js.map
vendored
BIN
dist/icon-128.59c1f720.png
vendored
Normal file
After Width: | Height: | Size: 651 B |
BIN
dist/icon-512.e79a8a4c.png
vendored
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
dist/icon-64.2922f911.png
vendored
Normal file
After Width: | Height: | Size: 415 B |
217
dist/index.23c89b7f.js
vendored
|
@ -1,217 +0,0 @@
|
|||
let currentCode = '_';
|
||||
const paletteEl = document.getElementById('palette');
|
||||
Object.entries(palette).forEach(([code, color])=>{
|
||||
const btn = document.createElement('button');
|
||||
Object.assign(btn.style, {
|
||||
background: color || 'linear-gradient(45deg,black,white)',
|
||||
display: 'inline-block',
|
||||
width: '40px',
|
||||
height: '40px',
|
||||
border: '1px solid black'
|
||||
});
|
||||
if (code === currentCode) btn.className = 'active';
|
||||
paletteEl.appendChild(btn);
|
||||
btn.addEventListener('click', (e)=>{
|
||||
currentCode = code;
|
||||
e.preventDefault();
|
||||
document.querySelector('#palette button.active')?.classList.remove('active');
|
||||
btn.classList.add('active');
|
||||
});
|
||||
});
|
||||
function renderAllLevels() {
|
||||
allLevels.forEach((level, levelIndex)=>{
|
||||
addLevelEditorToList(level, levelIndex);
|
||||
});
|
||||
}
|
||||
function addLevelEditorToList(level, levelIndex) {
|
||||
const { name, bricks, size, svg, color } = level;
|
||||
let div = document.createElement('div');
|
||||
div.innerHTML = `
|
||||
<button data-level="${levelIndex}" data-rename="yep">${name}</button>
|
||||
<div>
|
||||
<button data-level="${levelIndex}" data-delete="yep">Delete</button>
|
||||
<button data-offset-level-size="-1" data-level="${levelIndex}">-</button>
|
||||
<button data-offset-level-size="1" data-level="${levelIndex}">+</button>
|
||||
<button data-offset-x="-1" data-offset-y="0" data-level="${levelIndex}">L</button>
|
||||
<button data-offset-x="1" data-offset-y="0" data-level="${levelIndex}">R</button>
|
||||
<button data-offset-x="0" data-offset-y="-1" data-level="${levelIndex}">U</button>
|
||||
<button data-offset-x="0" data-offset-y="1" data-level="${levelIndex}">D</button>
|
||||
<input type="color" value="${level.color || ''}" data-level="${levelIndex}" />
|
||||
<input type="number" value="${level.svg || hashCode(level.name) % backgrounds.length}" data-level="${levelIndex}" data-num-val="svg" />
|
||||
|
||||
<button data-level="${levelIndex}" data-set-bg-svg="true" >${svg ? 'replace' : 'set'}</button>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="level-bricks-preview" id="bricks-of-${levelIndex}" >
|
||||
</div>
|
||||
`;
|
||||
document.getElementById('levels').appendChild(div);
|
||||
renderLevelBricks(levelIndex);
|
||||
updateLevelBackground(levelIndex);
|
||||
}
|
||||
function updateLevelBackground(levelIndex) {
|
||||
const div = document.getElementById("bricks-of-" + levelIndex);
|
||||
const level = allLevels[levelIndex];
|
||||
const { svg, color } = level;
|
||||
if (color) Object.assign(div.style, {
|
||||
backgroundImage: 'none',
|
||||
backgroundColor: color
|
||||
});
|
||||
else {
|
||||
const index = svg || hashCode(level.name) % backgrounds.length;
|
||||
const svgSource = backgrounds[index];
|
||||
console.log(index);
|
||||
div.setAttribute('data-svg', svgSource);
|
||||
Object.assign(div.style, {
|
||||
backgroundImage: `url("data:image/svg+xml;UTF8,${encodeURIComponent(svgSource)}")`,
|
||||
backgroundColor: 'transparent'
|
||||
});
|
||||
}
|
||||
}
|
||||
function renderLevelBricks(levelIndex) {
|
||||
const { size, bricks } = allLevels[levelIndex];
|
||||
const buttons = [];
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++){
|
||||
const index = y * size + x;
|
||||
buttons.push(`<button style="background: ${palette[bricks[index]] || 'transparent'}; left:${x * 40}px;top:${y * 40}px;width:40px;height: 40px; position: absolute" data-set-color-of="${index}" data-level="${levelIndex}"></button>`);
|
||||
}
|
||||
const div = document.getElementById("bricks-of-" + levelIndex);
|
||||
div.innerHTML = buttons.join('');
|
||||
Object.assign(div.style, {
|
||||
width: size * 40 + 'px',
|
||||
height: size * 40 + 'px'
|
||||
});
|
||||
}
|
||||
document.getElementById('levels').addEventListener('change', (e)=>{
|
||||
const levelIndexStr = e.target.getAttribute('data-level');
|
||||
if (levelIndexStr) {
|
||||
const levelIndex = parseInt(levelIndexStr);
|
||||
const level = allLevels[levelIndex];
|
||||
if (e.target.getAttribute('type') === 'color') {
|
||||
level.color = e.target.value;
|
||||
level.svg = '';
|
||||
updateLevelBackground(levelIndex);
|
||||
} else if (e.target.getAttribute('type') === 'checkbox' && e.target.hasAttribute('data-field')) {
|
||||
const field = e.target.getAttribute('data-field');
|
||||
if (field === 'focus') allLevels.forEach((l)=>l.focus = false);
|
||||
level[field] = !!e.target.checked;
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
document.getElementById('levels').addEventListener('click', (e)=>{
|
||||
const resize = e.target.getAttribute('data-offset-level-size');
|
||||
const moveX = e.target.getAttribute('data-offset-x');
|
||||
const moveY = e.target.getAttribute('data-offset-y');
|
||||
const levelIndexStr = e.target.getAttribute('data-level');
|
||||
if (!levelIndexStr) return;
|
||||
if (e.target.tagName !== 'BUTTON') return;
|
||||
const levelIndex = parseInt(levelIndexStr);
|
||||
const level = allLevels[levelIndex];
|
||||
const { bricks, size } = level;
|
||||
if (resize) {
|
||||
const newSize = size + parseInt(resize);
|
||||
const newBricks = new Array(newSize * newSize).fill('_');
|
||||
for(let x = 0; x < Math.min(size, newSize); x++)for(let y = 0; y < Math.min(size, newSize); y++)newBricks[y * newSize + x] = bricks.split('')[y * size + x] || '_';
|
||||
level.size = newSize;
|
||||
level.bricks = newBricks.map((b)=>b || '_').join('');
|
||||
} else if (moveX && moveY) {
|
||||
const dx = parseInt(moveX), dy = parseInt(moveY);
|
||||
const newBricks = new Array(size * size).fill('_');
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++)newBricks[(y + dy) * size + (x + dx)] = bricks.split('')[y * size + x] || '_';
|
||||
level.bricks = newBricks.map((b)=>b || '_').join('');
|
||||
} else if (e.target.getAttribute('data-rename')) {
|
||||
const newName = prompt('Name ? ', level.name);
|
||||
if (newName) {
|
||||
level.name = newName;
|
||||
e.target.textContent = newName;
|
||||
}
|
||||
} else if (e.target.getAttribute('data-delete')) {
|
||||
if (confirm('Delete level')) {
|
||||
allLevels = allLevels.filter((l, i)=>i !== levelIndex);
|
||||
save().then(()=>window.location.reload());
|
||||
}
|
||||
} else if (e.target.getAttribute('data-set-bg-svg')) {
|
||||
const newBg = prompt('New svg code', level.svg || '');
|
||||
if (newBg) {
|
||||
level.svg = newBg;
|
||||
level.color = '';
|
||||
}
|
||||
updateLevelBackground(levelIndex);
|
||||
}
|
||||
renderLevelBricks(levelIndex);
|
||||
save();
|
||||
}, true);
|
||||
let applying = '';
|
||||
function colorPixel(e) {
|
||||
if (applying === '') return;
|
||||
console.log('colorPixel', applying);
|
||||
const index = e.target.getAttribute('data-set-color-of');
|
||||
const level = e.target.getAttribute('data-level');
|
||||
if (index && level) {
|
||||
const levelIndex = parseInt(level);
|
||||
e.target.style.background = palette[applying] || 'transparent';
|
||||
setBrick(levelIndex, parseInt(index), applying);
|
||||
}
|
||||
}
|
||||
function setBrick(levelIndex, index, chr) {
|
||||
const bricks = allLevels[levelIndex].bricks;
|
||||
allLevels[levelIndex].bricks = bricks.substring(0, index) + chr + bricks.substring(index + 1);
|
||||
}
|
||||
document.getElementById('levels').addEventListener('mousedown', (e)=>{
|
||||
const index = parseInt(e.target.getAttribute('data-set-color-of'));
|
||||
const level = e.target.getAttribute('data-level');
|
||||
if (typeof index !== "undefined" && level) {
|
||||
const before = allLevels[parseInt(level)].bricks[index] || '';
|
||||
applying = before === currentCode ? '_' : currentCode;
|
||||
console.log({
|
||||
before,
|
||||
applying,
|
||||
currentCode
|
||||
});
|
||||
colorPixel(e);
|
||||
}
|
||||
});
|
||||
document.getElementById('levels').addEventListener('mouseenter', (e)=>{
|
||||
if (applying !== '') colorPixel(e);
|
||||
}, true);
|
||||
document.addEventListener('mouseup', (e)=>{
|
||||
applying = '';
|
||||
save();
|
||||
});
|
||||
document.getElementById('new-level').addEventListener('click', (e)=>{
|
||||
const name = prompt("Name ? ");
|
||||
if (!name) return;
|
||||
allLevels.push({
|
||||
name,
|
||||
size: 8,
|
||||
bricks: '',
|
||||
svg: ''
|
||||
});
|
||||
const levelIndex = allLevels.length - 1;
|
||||
addLevelEditorToList(allLevels[levelIndex], levelIndex);
|
||||
save();
|
||||
}, true);
|
||||
renderAllLevels();
|
||||
function save() {
|
||||
return fetch('/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
},
|
||||
body: JSON.stringify(allLevels, null, 2)
|
||||
});
|
||||
}
|
||||
function hashCode(string) {
|
||||
var hash = 0;
|
||||
for(var i = 0; i < string.length; i++){
|
||||
var code = string.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + code;
|
||||
hash = hash & hash; // Convert to 32bit integer
|
||||
}
|
||||
return Math.abs(hash);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.23c89b7f.js.map
|
1
dist/index.23c89b7f.js.map
vendored
52
dist/index.248e51be.css
vendored
|
@ -1,52 +0,0 @@
|
|||
body {
|
||||
color: #fff;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
#palette {
|
||||
width: 80px;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#palette button.active {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
#levels {
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-start;
|
||||
gap: 40px;
|
||||
margin-right: 80px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#levels .level-bricks-preview {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#levels > div {
|
||||
grid-template-columns: auto auto;
|
||||
grid-template-areas: ". name"
|
||||
"buttons bricks";
|
||||
display: grid;
|
||||
}
|
||||
|
||||
#levels > div > :first-child {
|
||||
grid-area: name;
|
||||
}
|
||||
|
||||
#levels > div > div:nth-child(2) {
|
||||
flex-direction: column;
|
||||
grid-area: buttons;
|
||||
align-items: flex-end;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#levels > div > div:nth-child(3) {
|
||||
grid-area: bricks;
|
||||
}
|
||||
/*# sourceMappingURL=index.248e51be.css.map */
|
1
dist/index.248e51be.css.map
vendored
|
@ -1 +0,0 @@
|
|||
{"mappings":"AACA;;;;;AAKA;;;;;;;;;AAAA;;;;AAcA;;;;;;;;AAAA;;;;AAWE;;;;;;;AAKE;;;;AAIA;;;;;;;AAOA","sources":["editor-fe/editclient.less"],"sourcesContent":["\nbody {\n background: black;\n color: white;\n}\n\n#palette {\n position: fixed;\n top: 0;\n right: 0;\n width: 80px;\n bottom: 0;\n overflow: auto;\n\n button.active {\n transform: scale(1.2);\n }\n\n}\n\n#levels {\n display: flex;\n gap: 40px;\n align-items: flex-start;\n flex-wrap: wrap;\n margin-right: 80px;\n\n .level-bricks-preview {\n position: relative;\n }\n\n & > div {\n display: grid;\n grid-template-columns: auto auto;\n grid-template-areas: \". name\" \"buttons bricks\";\n\n & > *:nth-child(1) {\n grid-area: name;\n }\n\n & > div:nth-child(2) {\n grid-area: buttons;\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n }\n\n & > div:nth-child(3) {\n grid-area: bricks;\n }\n\n }\n\n}\n\n"],"names":[],"version":3,"file":"index.248e51be.css.map","sourceRoot":"/__parcel_source_root/"}
|
52
dist/index.25267e01.css
vendored
|
@ -1,52 +0,0 @@
|
|||
body {
|
||||
color: #fff;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
#palette {
|
||||
width: 80px;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#palette button.active {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
#levels {
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-start;
|
||||
gap: 40px;
|
||||
margin-right: 80px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#levels .level-bricks-preview {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#levels > div {
|
||||
grid-template-columns: auto auto;
|
||||
grid-template-areas: ". name"
|
||||
"buttons bricks";
|
||||
display: grid;
|
||||
}
|
||||
|
||||
#levels > div > :first-child {
|
||||
grid-area: name;
|
||||
}
|
||||
|
||||
#levels > div > div:nth-child(2) {
|
||||
flex-direction: column;
|
||||
grid-area: buttons;
|
||||
align-items: flex-end;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#levels > div > div:nth-child(3) {
|
||||
grid-area: bricks;
|
||||
}
|
||||
/*# sourceMappingURL=index.25267e01.css.map */
|
1
dist/index.25267e01.css.map
vendored
|
@ -1 +0,0 @@
|
|||
{"mappings":"AACA;;;;;AAKA;;;;;;;;;AAAA;;;;AAcA;;;;;;;;AAAA;;;;AAWE;;;;;;;AAKE;;;;AAIA;;;;;;;AAOA","sources":["editor/editclient.less"],"sourcesContent":["\nbody {\n background: black;\n color: white;\n}\n\n#palette {\n position: fixed;\n top: 0;\n right: 0;\n width: 80px;\n bottom: 0;\n overflow: auto;\n\n button.active {\n transform: scale(1.2);\n }\n\n}\n\n#levels {\n display: flex;\n gap: 40px;\n align-items: flex-start;\n flex-wrap: wrap;\n margin-right: 80px;\n\n.level-bricks-preview {\n position: relative;\n}\n\n & > div {\n display: grid;\n grid-template-columns: auto auto;\n grid-template-areas: \". name\" \"buttons bricks\";\n\n & > *:nth-child(1) {\n grid-area: name;\n }\n\n & > div:nth-child(2) {\n grid-area: buttons;\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n }\n\n & > div:nth-child(3) {\n grid-area: bricks;\n }\n\n }\n\n}\n\n"],"names":[],"version":3,"file":"index.25267e01.css.map","sourceRoot":"/__parcel_source_root/"}
|
186
dist/index.497c99a1.js
vendored
1
dist/index.497c99a1.js.map
vendored
52
dist/index.74a459a7.css
vendored
|
@ -1,52 +0,0 @@
|
|||
body {
|
||||
color: #fff;
|
||||
background: #000;
|
||||
}
|
||||
|
||||
#palette button.active {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
.level-bricks-preview {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#palette {
|
||||
width: 80px;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
#levels {
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-start;
|
||||
gap: 40px;
|
||||
margin-right: 80px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#levels > div {
|
||||
grid-template-columns: auto auto;
|
||||
grid-template-areas: ". name"
|
||||
"buttons bricks";
|
||||
display: grid;
|
||||
}
|
||||
|
||||
#levels > div > :first-child {
|
||||
grid-area: name;
|
||||
}
|
||||
|
||||
#levels > div > div:nth-child(2) {
|
||||
flex-direction: column;
|
||||
grid-area: buttons;
|
||||
align-items: flex-end;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
#levels > div > div:nth-child(3) {
|
||||
grid-area: bricks;
|
||||
}
|
||||
/*# sourceMappingURL=index.74a459a7.css.map */
|
1
dist/index.74a459a7.css.map
vendored
|
@ -1 +0,0 @@
|
|||
{"mappings":"AACA;;;;;AAKA;;;;AAIA;;;;AAIA;;;;;;;;;AASA;;;;;;;;AASA;;;;;;;AAKA;;;;AAGA;;;;;;;AAMA","sources":["editor/editclient.css"],"sourcesContent":["\nbody {\n background: black;\n color: white;\n}\n\n#palette button.active {\n transform: scale(1.2);\n}\n\n.level-bricks-preview {\n position: relative;\n}\n\n#palette {\n position: fixed;\n top: 0;\n right: 0;\n width: 80px;\n bottom: 0;\n overflow: auto;\n}\n\n#levels {\n display: flex;\n gap: 40px;\n align-items: flex-start;\n flex-wrap: wrap;\n margin-right: 80px;\n}\n\n\n#levels>div {\n display: grid;\n grid-template-columns: auto auto;\n grid-template-areas: \". name\" \"buttons bricks\";\n}\n#levels>div>*:nth-child(1) {\n grid-area: name;\n}\n#levels>div>div:nth-child(2) {\n grid-area: buttons;\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n}\n#levels>div>div:nth-child(3) {\n grid-area: bricks;\n}\n"],"names":[],"version":3,"file":"index.74a459a7.css.map","sourceRoot":"/__parcel_source_root/"}
|
218
dist/index.a9335429.js
vendored
|
@ -1,218 +0,0 @@
|
|||
console.log('WTF');
|
||||
let currentCode = '_';
|
||||
const paletteEl = document.getElementById('palette');
|
||||
Object.entries(palette).forEach(([code, color])=>{
|
||||
const btn = document.createElement('button');
|
||||
Object.assign(btn.style, {
|
||||
background: color || 'linear-gradient(45deg,black,white)',
|
||||
display: 'inline-block',
|
||||
width: '40px',
|
||||
height: '40px',
|
||||
border: '1px solid black'
|
||||
});
|
||||
if (code === currentCode) btn.className = 'active';
|
||||
paletteEl.appendChild(btn);
|
||||
btn.addEventListener('click', (e)=>{
|
||||
currentCode = code;
|
||||
e.preventDefault();
|
||||
document.querySelector('#palette button.active')?.classList.remove('active');
|
||||
btn.classList.add('active');
|
||||
});
|
||||
});
|
||||
function renderAllLevels() {
|
||||
allLevels.forEach((level, levelIndex)=>{
|
||||
addLevelEditorToList(level, levelIndex);
|
||||
});
|
||||
}
|
||||
function addLevelEditorToList(level, levelIndex) {
|
||||
const { name, bricks, size, svg, color } = level;
|
||||
let div = document.createElement('div');
|
||||
div.innerHTML = `
|
||||
<button data-level="${levelIndex}" data-rename="yep">${name}</button>
|
||||
<div>
|
||||
<button data-level="${levelIndex}" data-delete="yep">Delete</button>
|
||||
<button data-offset-level-size="-1" data-level="${levelIndex}">-</button>
|
||||
<button data-offset-level-size="1" data-level="${levelIndex}">+</button>
|
||||
<button data-offset-x="-1" data-offset-y="0" data-level="${levelIndex}">L</button>
|
||||
<button data-offset-x="1" data-offset-y="0" data-level="${levelIndex}">R</button>
|
||||
<button data-offset-x="0" data-offset-y="-1" data-level="${levelIndex}">U</button>
|
||||
<button data-offset-x="0" data-offset-y="1" data-level="${levelIndex}">D</button>
|
||||
<input type="color" value="${level.color || ''}" data-level="${levelIndex}" />
|
||||
<input type="number" value="${level.svg || hashCode(level.name) % backgrounds.length}" data-level="${levelIndex}" data-num-val="svg" />
|
||||
|
||||
<button data-level="${levelIndex}" data-set-bg-svg="true" >${svg ? 'replace' : 'set'}</button>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="level-bricks-preview" id="bricks-of-${levelIndex}" >
|
||||
</div>
|
||||
`;
|
||||
document.getElementById('levels').appendChild(div);
|
||||
renderLevelBricks(levelIndex);
|
||||
updateLevelBackground(levelIndex);
|
||||
}
|
||||
function updateLevelBackground(levelIndex) {
|
||||
const div = document.getElementById("bricks-of-" + levelIndex);
|
||||
const level = allLevels[levelIndex];
|
||||
const { svg, color } = level;
|
||||
if (color) Object.assign(div.style, {
|
||||
backgroundImage: 'none',
|
||||
backgroundColor: color
|
||||
});
|
||||
else {
|
||||
const index = svg || hashCode(level.name) % backgrounds.length;
|
||||
const svgSource = backgrounds[index];
|
||||
console.log(index);
|
||||
div.setAttribute('data-svg', svgSource);
|
||||
Object.assign(div.style, {
|
||||
backgroundImage: `url("data:image/svg+xml;UTF8,${encodeURIComponent(svgSource)}")`,
|
||||
backgroundColor: 'transparent'
|
||||
});
|
||||
}
|
||||
}
|
||||
function renderLevelBricks(levelIndex) {
|
||||
const { size, bricks } = allLevels[levelIndex];
|
||||
const buttons = [];
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++){
|
||||
const index = y * size + x;
|
||||
buttons.push(`<button style="background: ${palette[bricks[index]] || 'transparent'}; left:${x * 40}px;top:${y * 40}px;width:40px;height: 40px; position: absolute" data-set-color-of="${index}" data-level="${levelIndex}"></button>`);
|
||||
}
|
||||
const div = document.getElementById("bricks-of-" + levelIndex);
|
||||
div.innerHTML = buttons.join('');
|
||||
Object.assign(div.style, {
|
||||
width: size * 40 + 'px',
|
||||
height: size * 40 + 'px'
|
||||
});
|
||||
}
|
||||
document.getElementById('levels').addEventListener('change', (e)=>{
|
||||
const levelIndexStr = e.target.getAttribute('data-level');
|
||||
if (levelIndexStr) {
|
||||
const levelIndex = parseInt(levelIndexStr);
|
||||
const level = allLevels[levelIndex];
|
||||
if (e.target.getAttribute('type') === 'color') {
|
||||
level.color = e.target.value;
|
||||
level.svg = '';
|
||||
updateLevelBackground(levelIndex);
|
||||
} else if (e.target.getAttribute('type') === 'checkbox' && e.target.hasAttribute('data-field')) {
|
||||
const field = e.target.getAttribute('data-field');
|
||||
if (field === 'focus') allLevels.forEach((l)=>l.focus = false);
|
||||
level[field] = !!e.target.checked;
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
document.getElementById('levels').addEventListener('click', (e)=>{
|
||||
const resize = e.target.getAttribute('data-offset-level-size');
|
||||
const moveX = e.target.getAttribute('data-offset-x');
|
||||
const moveY = e.target.getAttribute('data-offset-y');
|
||||
const levelIndexStr = e.target.getAttribute('data-level');
|
||||
if (!levelIndexStr) return;
|
||||
if (e.target.tagName !== 'BUTTON') return;
|
||||
const levelIndex = parseInt(levelIndexStr);
|
||||
const level = allLevels[levelIndex];
|
||||
const { bricks, size } = level;
|
||||
if (resize) {
|
||||
const newSize = size + parseInt(resize);
|
||||
const newBricks = new Array(newSize * newSize).fill('_');
|
||||
for(let x = 0; x < Math.min(size, newSize); x++)for(let y = 0; y < Math.min(size, newSize); y++)newBricks[y * newSize + x] = bricks.split('')[y * size + x] || '_';
|
||||
level.size = newSize;
|
||||
level.bricks = newBricks.map((b)=>b || '_').join('');
|
||||
} else if (moveX && moveY) {
|
||||
const dx = parseInt(moveX), dy = parseInt(moveY);
|
||||
const newBricks = new Array(size * size).fill('_');
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++)newBricks[(y + dy) * size + (x + dx)] = bricks.split('')[y * size + x] || '_';
|
||||
level.bricks = newBricks.map((b)=>b || '_').join('');
|
||||
} else if (e.target.getAttribute('data-rename')) {
|
||||
const newName = prompt('Name ? ', level.name);
|
||||
if (newName) {
|
||||
level.name = newName;
|
||||
e.target.textContent = newName;
|
||||
}
|
||||
} else if (e.target.getAttribute('data-delete')) {
|
||||
if (confirm('Delete level')) {
|
||||
allLevels = allLevels.filter((l, i)=>i !== levelIndex);
|
||||
save().then(()=>window.location.reload());
|
||||
}
|
||||
} else if (e.target.getAttribute('data-set-bg-svg')) {
|
||||
const newBg = prompt('New svg code', level.svg || '');
|
||||
if (newBg) {
|
||||
level.svg = newBg;
|
||||
level.color = '';
|
||||
}
|
||||
updateLevelBackground(levelIndex);
|
||||
}
|
||||
renderLevelBricks(levelIndex);
|
||||
save();
|
||||
}, true);
|
||||
let applying = '';
|
||||
function colorPixel(e) {
|
||||
if (applying === '') return;
|
||||
console.log('colorPixel', applying);
|
||||
const index = e.target.getAttribute('data-set-color-of');
|
||||
const level = e.target.getAttribute('data-level');
|
||||
if (index && level) {
|
||||
const levelIndex = parseInt(level);
|
||||
e.target.style.background = palette[applying] || 'transparent';
|
||||
setBrick(levelIndex, parseInt(index), applying);
|
||||
}
|
||||
}
|
||||
function setBrick(levelIndex, index, chr) {
|
||||
const bricks = allLevels[levelIndex].bricks;
|
||||
allLevels[levelIndex].bricks = bricks.substring(0, index) + chr + bricks.substring(index + 1);
|
||||
}
|
||||
document.getElementById('levels').addEventListener('mousedown', (e)=>{
|
||||
const index = parseInt(e.target.getAttribute('data-set-color-of'));
|
||||
const level = e.target.getAttribute('data-level');
|
||||
if (typeof index !== "undefined" && level) {
|
||||
const before = allLevels[parseInt(level)].bricks[index] || '';
|
||||
applying = before === currentCode ? '_' : currentCode;
|
||||
console.log({
|
||||
before,
|
||||
applying,
|
||||
currentCode
|
||||
});
|
||||
colorPixel(e);
|
||||
}
|
||||
});
|
||||
document.getElementById('levels').addEventListener('mouseenter', (e)=>{
|
||||
if (applying !== '') colorPixel(e);
|
||||
}, true);
|
||||
document.addEventListener('mouseup', (e)=>{
|
||||
applying = '';
|
||||
save();
|
||||
});
|
||||
document.getElementById('new-level').addEventListener('click', (e)=>{
|
||||
const name = prompt("Name ? ");
|
||||
if (!name) return;
|
||||
allLevels.push({
|
||||
name,
|
||||
size: 8,
|
||||
bricks: '',
|
||||
svg: ''
|
||||
});
|
||||
const levelIndex = allLevels.length - 1;
|
||||
addLevelEditorToList(allLevels[levelIndex], levelIndex);
|
||||
save();
|
||||
}, true);
|
||||
renderAllLevels();
|
||||
function save() {
|
||||
return fetch('/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
},
|
||||
body: JSON.stringify(allLevels, null, 2)
|
||||
});
|
||||
}
|
||||
function hashCode(string) {
|
||||
var hash = 0;
|
||||
for(var i = 0; i < string.length; i++){
|
||||
var code = string.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + code;
|
||||
hash = hash & hash; // Convert to 32bit integer
|
||||
}
|
||||
return Math.abs(hash);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.a9335429.js.map
|
1
dist/index.a9335429.js.map
vendored
2
dist/index.c0fd3053.js.map
vendored
217
dist/index.e2e3b31c.js
vendored
|
@ -1,217 +0,0 @@
|
|||
let currentCode = '_';
|
||||
const paletteEl = document.getElementById('palette');
|
||||
Object.entries(palette).forEach(([code, color])=>{
|
||||
const btn = document.createElement('button');
|
||||
Object.assign(btn.style, {
|
||||
background: color || 'linear-gradient(45deg,black,white)',
|
||||
display: 'inline-block',
|
||||
width: '40px',
|
||||
height: '40px',
|
||||
border: '1px solid black'
|
||||
});
|
||||
if (code === currentCode) btn.className = 'active';
|
||||
paletteEl.appendChild(btn);
|
||||
btn.addEventListener('click', (e)=>{
|
||||
currentCode = code;
|
||||
e.preventDefault();
|
||||
document.querySelector('#palette button.active')?.classList.remove('active');
|
||||
btn.classList.add('active');
|
||||
});
|
||||
});
|
||||
function renderAllLevels() {
|
||||
allLevels.forEach((level, levelIndex)=>{
|
||||
addLevelEditorToList(level, levelIndex);
|
||||
});
|
||||
}
|
||||
function addLevelEditorToList(level, levelIndex) {
|
||||
const { name, bricks, size, svg, color } = level;
|
||||
let div = document.createElement('div');
|
||||
div.innerHTML = `
|
||||
<button data-level="${levelIndex}" data-rename="yep">${name}</button>
|
||||
<div>
|
||||
<button data-level="${levelIndex}" data-delete="yep">Delete</button>
|
||||
<button data-offset-level-size="-1" data-level="${levelIndex}">-</button>
|
||||
<button data-offset-level-size="1" data-level="${levelIndex}">+</button>
|
||||
<button data-offset-x="-1" data-offset-y="0" data-level="${levelIndex}">L</button>
|
||||
<button data-offset-x="1" data-offset-y="0" data-level="${levelIndex}">R</button>
|
||||
<button data-offset-x="0" data-offset-y="-1" data-level="${levelIndex}">U</button>
|
||||
<button data-offset-x="0" data-offset-y="1" data-level="${levelIndex}">D</button>
|
||||
<input type="color" value="${level.color || ''}" data-level="${levelIndex}" />
|
||||
<input type="number" value="${level.svg || hashCode(level.name) % backgrounds.length}" data-level="${levelIndex}" data-num-val="svg" />
|
||||
|
||||
<button data-level="${levelIndex}" data-set-bg-svg="true" >${svg ? 'replace' : 'set'}</button>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="level-bricks-preview" id="bricks-of-${levelIndex}" >
|
||||
</div>
|
||||
`;
|
||||
document.getElementById('levels').appendChild(div);
|
||||
renderLevelBricks(levelIndex);
|
||||
updateLevelBackground(levelIndex);
|
||||
}
|
||||
function updateLevelBackground(levelIndex) {
|
||||
const div = document.getElementById("bricks-of-" + levelIndex);
|
||||
const level = allLevels[levelIndex];
|
||||
const { svg, color } = level;
|
||||
if (color) Object.assign(div.style, {
|
||||
backgroundImage: 'none',
|
||||
backgroundColor: color
|
||||
});
|
||||
else {
|
||||
const index = svg || hashCode(level.name) % backgrounds.length;
|
||||
const svgSource = backgrounds[index];
|
||||
console.log(index);
|
||||
div.setAttribute('data-svg', svgSource);
|
||||
Object.assign(div.style, {
|
||||
backgroundImage: `url("data:image/svg+xml;UTF8,${encodeURIComponent(svgSource)}")`,
|
||||
backgroundColor: 'transparent'
|
||||
});
|
||||
}
|
||||
}
|
||||
function renderLevelBricks(levelIndex) {
|
||||
const { size, bricks } = allLevels[levelIndex];
|
||||
const buttons = [];
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++){
|
||||
const index = y * size + x;
|
||||
buttons.push(`<button style="background: ${palette[bricks[index]] || 'transparent'}; left:${x * 40}px;top:${y * 40}px;width:40px;height: 40px; position: absolute" data-set-color-of="${index}" data-level="${levelIndex}"></button>`);
|
||||
}
|
||||
const div = document.getElementById("bricks-of-" + levelIndex);
|
||||
div.innerHTML = buttons.join('');
|
||||
Object.assign(div.style, {
|
||||
width: size * 40 + 'px',
|
||||
height: size * 40 + 'px'
|
||||
});
|
||||
}
|
||||
document.getElementById('levels').addEventListener('change', (e)=>{
|
||||
const levelIndexStr = e.target.getAttribute('data-level');
|
||||
if (levelIndexStr) {
|
||||
const levelIndex = parseInt(levelIndexStr);
|
||||
const level = allLevels[levelIndex];
|
||||
if (e.target.getAttribute('type') === 'color') {
|
||||
level.color = e.target.value;
|
||||
level.svg = '';
|
||||
updateLevelBackground(levelIndex);
|
||||
} else if (e.target.getAttribute('type') === 'checkbox' && e.target.hasAttribute('data-field')) {
|
||||
const field = e.target.getAttribute('data-field');
|
||||
if (field === 'focus') allLevels.forEach((l)=>l.focus = false);
|
||||
level[field] = !!e.target.checked;
|
||||
}
|
||||
save();
|
||||
}
|
||||
});
|
||||
document.getElementById('levels').addEventListener('click', (e)=>{
|
||||
const resize = e.target.getAttribute('data-offset-level-size');
|
||||
const moveX = e.target.getAttribute('data-offset-x');
|
||||
const moveY = e.target.getAttribute('data-offset-y');
|
||||
const levelIndexStr = e.target.getAttribute('data-level');
|
||||
if (!levelIndexStr) return;
|
||||
if (e.target.tagName !== 'BUTTON') return;
|
||||
const levelIndex = parseInt(levelIndexStr);
|
||||
const level = allLevels[levelIndex];
|
||||
const { bricks, size } = level;
|
||||
if (resize) {
|
||||
const newSize = size + parseInt(resize);
|
||||
const newBricks = new Array(newSize * newSize).fill('_');
|
||||
for(let x = 0; x < Math.min(size, newSize); x++)for(let y = 0; y < Math.min(size, newSize); y++)newBricks[y * newSize + x] = bricks.split('')[y * size + x] || '_';
|
||||
level.size = newSize;
|
||||
level.bricks = newBricks.map((b)=>b || '_').join('');
|
||||
} else if (moveX && moveY) {
|
||||
const dx = parseInt(moveX), dy = parseInt(moveY);
|
||||
const newBricks = new Array(size * size).fill('_');
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++)newBricks[(y + dy) * size + (x + dx)] = bricks.split('')[y * size + x] || '_';
|
||||
level.bricks = newBricks.map((b)=>b || '_').join('');
|
||||
} else if (e.target.getAttribute('data-rename')) {
|
||||
const newName = prompt('Name ? ', level.name);
|
||||
if (newName) {
|
||||
level.name = newName;
|
||||
e.target.textContent = newName;
|
||||
}
|
||||
} else if (e.target.getAttribute('data-delete')) {
|
||||
if (confirm('Delete level')) {
|
||||
allLevels = allLevels.filter((l, i)=>i !== levelIndex);
|
||||
save().then(()=>window.location.reload());
|
||||
}
|
||||
} else if (e.target.getAttribute('data-set-bg-svg')) {
|
||||
const newBg = prompt('New svg code', level.svg || '');
|
||||
if (newBg) {
|
||||
level.svg = newBg;
|
||||
level.color = '';
|
||||
}
|
||||
updateLevelBackground(levelIndex);
|
||||
}
|
||||
renderLevelBricks(levelIndex);
|
||||
save();
|
||||
}, true);
|
||||
let applying = '';
|
||||
function colorPixel(e) {
|
||||
if (applying === '') return;
|
||||
console.log('colorPixel', applying);
|
||||
const index = e.target.getAttribute('data-set-color-of');
|
||||
const level = e.target.getAttribute('data-level');
|
||||
if (index && level) {
|
||||
const levelIndex = parseInt(level);
|
||||
e.target.style.background = palette[applying] || 'transparent';
|
||||
setBrick(levelIndex, parseInt(index), applying);
|
||||
}
|
||||
}
|
||||
function setBrick(levelIndex, index, chr) {
|
||||
const bricks = allLevels[levelIndex].bricks;
|
||||
allLevels[levelIndex].bricks = bricks.substring(0, index) + chr + bricks.substring(index + 1);
|
||||
}
|
||||
document.getElementById('levels').addEventListener('mousedown', (e)=>{
|
||||
const index = parseInt(e.target.getAttribute('data-set-color-of'));
|
||||
const level = e.target.getAttribute('data-level');
|
||||
if (typeof index !== "undefined" && level) {
|
||||
const before = allLevels[parseInt(level)].bricks[index] || '';
|
||||
applying = before === currentCode ? '_' : currentCode;
|
||||
console.log({
|
||||
before,
|
||||
applying,
|
||||
currentCode
|
||||
});
|
||||
colorPixel(e);
|
||||
}
|
||||
});
|
||||
document.getElementById('levels').addEventListener('mouseenter', (e)=>{
|
||||
if (applying !== '') colorPixel(e);
|
||||
}, true);
|
||||
document.addEventListener('mouseup', (e)=>{
|
||||
applying = '';
|
||||
save();
|
||||
});
|
||||
document.getElementById('new-level').addEventListener('click', (e)=>{
|
||||
const name = prompt("Name ? ");
|
||||
if (!name) return;
|
||||
allLevels.push({
|
||||
name,
|
||||
size: 8,
|
||||
bricks: '',
|
||||
svg: ''
|
||||
});
|
||||
const levelIndex = allLevels.length - 1;
|
||||
addLevelEditorToList(allLevels[levelIndex], levelIndex);
|
||||
save();
|
||||
}, true);
|
||||
renderAllLevels();
|
||||
function save() {
|
||||
return fetch('/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
},
|
||||
body: JSON.stringify(allLevels, null, 2)
|
||||
});
|
||||
}
|
||||
function hashCode(string) {
|
||||
var hash = 0;
|
||||
for(var i = 0; i < string.length; i++){
|
||||
var code = string.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + code;
|
||||
hash = hash & hash; // Convert to 32bit integer
|
||||
}
|
||||
return Math.abs(hash);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.e2e3b31c.js.map
|
1
dist/index.e2e3b31c.js.map
vendored
230
dist/index.html
vendored
467
dist/levels_editor.227fd609.js
vendored
|
@ -1,467 +0,0 @@
|
|||
// modules are defined as an array
|
||||
// [ module function, map of requires ]
|
||||
//
|
||||
// map of requires is short require name -> numeric require
|
||||
//
|
||||
// anything defined in a previous bundle is accessed via the
|
||||
// orig method which is the require for previous bundles
|
||||
|
||||
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
||||
/* eslint-disable no-undef */
|
||||
var globalObject =
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof global !== 'undefined'
|
||||
? global
|
||||
: {};
|
||||
/* eslint-enable no-undef */
|
||||
|
||||
// Save the require from previous bundle to this closure if any
|
||||
var previousRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
|
||||
var cache = previousRequire.cache || {};
|
||||
// Do not use `require` to prevent Webpack from trying to bundle this call
|
||||
var nodeRequire =
|
||||
typeof module !== 'undefined' &&
|
||||
typeof module.require === 'function' &&
|
||||
module.require.bind(module);
|
||||
|
||||
function newRequire(name, jumped) {
|
||||
if (!cache[name]) {
|
||||
if (!modules[name]) {
|
||||
// if we cannot find the module within our internal map or
|
||||
// cache jump to the current global require ie. the last bundle
|
||||
// that was added to the page.
|
||||
var currentRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
if (!jumped && currentRequire) {
|
||||
return currentRequire(name, true);
|
||||
}
|
||||
|
||||
// If there are other bundles on this page the require from the
|
||||
// previous one is saved to 'previousRequire'. Repeat this as
|
||||
// many times as there are bundles until the module is found or
|
||||
// we exhaust the require chain.
|
||||
if (previousRequire) {
|
||||
return previousRequire(name, true);
|
||||
}
|
||||
|
||||
// Try the node require function if it exists.
|
||||
if (nodeRequire && typeof name === 'string') {
|
||||
return nodeRequire(name);
|
||||
}
|
||||
|
||||
var err = new Error("Cannot find module '" + name + "'");
|
||||
err.code = 'MODULE_NOT_FOUND';
|
||||
throw err;
|
||||
}
|
||||
|
||||
localRequire.resolve = resolve;
|
||||
localRequire.cache = {};
|
||||
|
||||
var module = (cache[name] = new newRequire.Module(name));
|
||||
|
||||
modules[name][0].call(
|
||||
module.exports,
|
||||
localRequire,
|
||||
module,
|
||||
module.exports,
|
||||
globalObject
|
||||
);
|
||||
}
|
||||
|
||||
return cache[name].exports;
|
||||
|
||||
function localRequire(x) {
|
||||
var res = localRequire.resolve(x);
|
||||
return res === false ? {} : newRequire(res);
|
||||
}
|
||||
|
||||
function resolve(x) {
|
||||
var id = modules[name][1][x];
|
||||
return id != null ? id : x;
|
||||
}
|
||||
}
|
||||
|
||||
function Module(moduleName) {
|
||||
this.id = moduleName;
|
||||
this.bundle = newRequire;
|
||||
this.exports = {};
|
||||
}
|
||||
|
||||
newRequire.isParcelRequire = true;
|
||||
newRequire.Module = Module;
|
||||
newRequire.modules = modules;
|
||||
newRequire.cache = cache;
|
||||
newRequire.parent = previousRequire;
|
||||
newRequire.register = function (id, exports) {
|
||||
modules[id] = [
|
||||
function (require, module) {
|
||||
module.exports = exports;
|
||||
},
|
||||
{},
|
||||
];
|
||||
};
|
||||
|
||||
Object.defineProperty(newRequire, 'root', {
|
||||
get: function () {
|
||||
return globalObject[parcelRequireName];
|
||||
},
|
||||
});
|
||||
|
||||
globalObject[parcelRequireName] = newRequire;
|
||||
|
||||
for (var i = 0; i < entry.length; i++) {
|
||||
newRequire(entry[i]);
|
||||
}
|
||||
|
||||
if (mainEntry) {
|
||||
// Expose entry point to Node, AMD or browser globals
|
||||
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
|
||||
var mainExports = newRequire(mainEntry);
|
||||
|
||||
// CommonJS
|
||||
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
||||
module.exports = mainExports;
|
||||
|
||||
// RequireJS
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
define(function () {
|
||||
return mainExports;
|
||||
});
|
||||
|
||||
// <script>
|
||||
} else if (globalName) {
|
||||
this[globalName] = mainExports;
|
||||
}
|
||||
}
|
||||
})({"7tSz9":[function(require,module,exports,__globalThis) {
|
||||
require("27eb2bc3af6e974d")(require("b23fa2c1e78907d1").getBundleURL('izxdV') + "index.c0fd3053.js");
|
||||
|
||||
},{"27eb2bc3af6e974d":"61B45","b23fa2c1e78907d1":"lgJ39"}],"61B45":[function(require,module,exports,__globalThis) {
|
||||
"use strict";
|
||||
var cacheLoader = require("ca2a84f7fa4a3bb0");
|
||||
module.exports = cacheLoader(function(bundle) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
// Don't insert the same script twice (e.g. if it was already in the HTML)
|
||||
var existingScripts = document.getElementsByTagName('script');
|
||||
if ([].concat(existingScripts).some(function(script) {
|
||||
return script.src === bundle;
|
||||
})) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
var preloadLink = document.createElement('link');
|
||||
preloadLink.href = bundle;
|
||||
preloadLink.rel = 'preload';
|
||||
preloadLink.as = 'script';
|
||||
document.head.appendChild(preloadLink);
|
||||
var script = document.createElement('script');
|
||||
script.async = true;
|
||||
script.type = 'text/javascript';
|
||||
script.src = bundle;
|
||||
script.onerror = function(e) {
|
||||
var error = new TypeError("Failed to fetch dynamically imported module: ".concat(bundle, ". Error: ").concat(e.message));
|
||||
script.onerror = script.onload = null;
|
||||
script.remove();
|
||||
reject(error);
|
||||
};
|
||||
script.onload = function() {
|
||||
script.onerror = script.onload = null;
|
||||
resolve();
|
||||
};
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
});
|
||||
});
|
||||
|
||||
},{"ca2a84f7fa4a3bb0":"j49pS"}],"j49pS":[function(require,module,exports,__globalThis) {
|
||||
"use strict";
|
||||
var cachedBundles = {};
|
||||
var cachedPreloads = {};
|
||||
var cachedPrefetches = {};
|
||||
function getCache(type) {
|
||||
switch(type){
|
||||
case 'preload':
|
||||
return cachedPreloads;
|
||||
case 'prefetch':
|
||||
return cachedPrefetches;
|
||||
default:
|
||||
return cachedBundles;
|
||||
}
|
||||
}
|
||||
module.exports = function(loader, type) {
|
||||
return function(bundle) {
|
||||
var cache = getCache(type);
|
||||
if (cache[bundle]) return cache[bundle];
|
||||
return cache[bundle] = loader.apply(null, arguments).catch(function(e) {
|
||||
delete cache[bundle];
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
},{}],"lgJ39":[function(require,module,exports,__globalThis) {
|
||||
"use strict";
|
||||
var bundleURL = {};
|
||||
function getBundleURLCached(id) {
|
||||
var value = bundleURL[id];
|
||||
if (!value) {
|
||||
value = getBundleURL();
|
||||
bundleURL[id] = value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function getBundleURL() {
|
||||
try {
|
||||
throw new Error();
|
||||
} catch (err) {
|
||||
var matches = ('' + err.stack).match(/(https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/[^)\n]+/g);
|
||||
if (matches) // The first two stack frames will be this function and getBundleURLCached.
|
||||
// Use the 3rd one, which will be a runtime in the original bundle.
|
||||
return getBaseURL(matches[2]);
|
||||
}
|
||||
return '/';
|
||||
}
|
||||
function getBaseURL(url) {
|
||||
return ('' + url).replace(/^((?:https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/.+)\/[^/]+$/, '$1') + '/';
|
||||
}
|
||||
// TODO: Replace uses with `new URL(url).origin` when ie11 is no longer supported.
|
||||
function getOrigin(url) {
|
||||
var matches = ('' + url).match(/(https?|file|ftp|(chrome|moz|safari-web)-extension):\/\/[^/]+/);
|
||||
if (!matches) throw new Error('Origin not found');
|
||||
return matches[0];
|
||||
}
|
||||
exports.getBundleURL = getBundleURLCached;
|
||||
exports.getBaseURL = getBaseURL;
|
||||
exports.getOrigin = getOrigin;
|
||||
|
||||
},{}],"434tO":[function(require,module,exports,__globalThis) {
|
||||
var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
|
||||
var _backgroundsJson = require("./backgrounds.json");
|
||||
var _backgroundsJsonDefault = parcelHelpers.interopDefault(_backgroundsJson);
|
||||
var _paletteJson = require("./palette.json");
|
||||
var _paletteJsonDefault = parcelHelpers.interopDefault(_paletteJson);
|
||||
var _levelsJson = require("./levels.json");
|
||||
var _levelsJsonDefault = parcelHelpers.interopDefault(_levelsJson);
|
||||
var _getLevelBackground = require("./getLevelBackground");
|
||||
const backgrounds = (0, _backgroundsJsonDefault.default);
|
||||
const palette = (0, _paletteJsonDefault.default);
|
||||
let allLevels = (0, _levelsJsonDefault.default);
|
||||
let currentCode = '_';
|
||||
const paletteEl = document.getElementById('palette');
|
||||
Object.entries(palette).forEach(([code, color])=>{
|
||||
const btn = document.createElement('button');
|
||||
Object.assign(btn.style, {
|
||||
background: color || 'linear-gradient(45deg,black,white)',
|
||||
display: 'inline-block',
|
||||
width: '40px',
|
||||
height: '40px',
|
||||
border: '1px solid black'
|
||||
});
|
||||
if (code === currentCode) btn.className = 'active';
|
||||
paletteEl.appendChild(btn);
|
||||
btn.addEventListener('click', (e)=>{
|
||||
currentCode = code;
|
||||
e.preventDefault();
|
||||
document.querySelector('#palette button.active')?.classList.remove('active');
|
||||
btn.classList.add('active');
|
||||
});
|
||||
});
|
||||
function renderAllLevels() {
|
||||
allLevels.forEach((level, levelIndex)=>{
|
||||
addLevelEditorToList(level, levelIndex);
|
||||
});
|
||||
}
|
||||
const levelsListEl = document?.getElementById('levels');
|
||||
function addLevelEditorToList(level, levelIndex) {
|
||||
const { name, bricks, size, svg, color } = level;
|
||||
let div = document.createElement('div');
|
||||
div.innerHTML = `
|
||||
<input type="text" value="${level.name || ''}" data-level="${levelIndex}" data-text-val="name" />
|
||||
<div>
|
||||
<button data-level="${levelIndex}" data-delete="yep">Delete</button>
|
||||
<button data-offset-level-size="-1" data-level="${levelIndex}">-</button>
|
||||
<button data-offset-level-size="1" data-level="${levelIndex}">+</button>
|
||||
<button data-offset-x="-1" data-offset-y="0" data-level="${levelIndex}">L</button>
|
||||
<button data-offset-x="1" data-offset-y="0" data-level="${levelIndex}">R</button>
|
||||
<button data-offset-x="0" data-offset-y="-1" data-level="${levelIndex}">U</button>
|
||||
<button data-offset-x="0" data-offset-y="1" data-level="${levelIndex}">D</button>
|
||||
<input type="color" value="${level.color || ''}" data-level="${levelIndex}" data-text-val="color" />
|
||||
<input type="number" value="${level.svg || (0, _getLevelBackground.hashCode)(level.name) % backgrounds.length}" data-level="${levelIndex}" data-num-val="svg" />
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="level-bricks-preview" id="bricks-of-${levelIndex}" >
|
||||
</div>
|
||||
`;
|
||||
levelsListEl.appendChild(div);
|
||||
renderLevelBricks(levelIndex);
|
||||
updateLevelBackground(levelIndex);
|
||||
}
|
||||
function updateLevelBackground(levelIndex) {
|
||||
const div = document.getElementById("bricks-of-" + levelIndex);
|
||||
const level = allLevels[levelIndex];
|
||||
const { svg, color } = level;
|
||||
if (color) Object.assign(div.style, {
|
||||
backgroundImage: 'none',
|
||||
backgroundColor: color
|
||||
});
|
||||
else {
|
||||
const svgSource = (0, _getLevelBackground.getLevelBackground)(level);
|
||||
div.setAttribute('data-svg', svgSource);
|
||||
Object.assign(div.style, {
|
||||
backgroundImage: `url("data:image/svg+xml;UTF8,${encodeURIComponent(svgSource)}")`,
|
||||
backgroundColor: 'transparent'
|
||||
});
|
||||
}
|
||||
}
|
||||
function renderLevelBricks(levelIndex) {
|
||||
const { size, bricks } = allLevels[levelIndex];
|
||||
const buttons = [];
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++){
|
||||
const index = y * size + x;
|
||||
buttons.push(`<button style="background: ${palette[bricks[index]] || 'transparent'}; left:${x * 40}px;top:${y * 40}px;width:40px;height: 40px; position: absolute" data-set-color-of="${index}" data-level="${levelIndex}"></button>`);
|
||||
}
|
||||
const div = document.getElementById("bricks-of-" + levelIndex);
|
||||
div.innerHTML = buttons.join('');
|
||||
Object.assign(div.style, {
|
||||
width: size * 40 + 'px',
|
||||
height: size * 40 + 'px'
|
||||
});
|
||||
}
|
||||
levelsListEl.addEventListener('change', (e)=>{
|
||||
const target = e.target;
|
||||
const levelIndexStr = target.getAttribute('data-level');
|
||||
if (!levelIndexStr) return;
|
||||
const levelIndex = parseInt(levelIndexStr);
|
||||
const level = allLevels[levelIndex];
|
||||
if (target.getAttribute('data-text-val') == 'name') level.name = target.value;
|
||||
if (target.getAttribute('data-text-val') == 'color') {
|
||||
level.color = target.value;
|
||||
level.svg = null;
|
||||
}
|
||||
if (target.getAttribute('data-num-val') == 'svg') {
|
||||
level.color = '';
|
||||
level.svg = parseFloat(target.value);
|
||||
}
|
||||
updateLevelBackground(levelIndex);
|
||||
save();
|
||||
});
|
||||
levelsListEl.addEventListener('click', (e)=>{
|
||||
const target = e.target;
|
||||
if (target.tagName !== 'BUTTON') return;
|
||||
const resize = target.getAttribute('data-offset-level-size');
|
||||
const moveX = target.getAttribute('data-offset-x');
|
||||
const moveY = target.getAttribute('data-offset-y');
|
||||
const levelIndexStr = target.getAttribute('data-level');
|
||||
if (!levelIndexStr) return;
|
||||
const levelIndex = parseInt(levelIndexStr);
|
||||
const level = allLevels[levelIndex];
|
||||
const { bricks, size } = level;
|
||||
if (resize) {
|
||||
const newSize = size + parseInt(resize);
|
||||
const newBricks = new Array(newSize * newSize).fill('_');
|
||||
for(let x = 0; x < Math.min(size, newSize); x++)for(let y = 0; y < Math.min(size, newSize); y++)newBricks[y * newSize + x] = bricks.split('')[y * size + x] || '_';
|
||||
level.size = newSize;
|
||||
level.bricks = newBricks.map((b)=>b || '_').join('');
|
||||
} else if (moveX && moveY) {
|
||||
const dx = parseInt(moveX), dy = parseInt(moveY);
|
||||
const newBricks = new Array(size * size).fill('_');
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++)newBricks[(y + dy) * size + (x + dx)] = bricks.split('')[y * size + x] || '_';
|
||||
level.bricks = newBricks.map((b)=>b || '_').join('');
|
||||
} else if (target.getAttribute('data-rename')) {
|
||||
const newName = prompt('Name ? ', level.name);
|
||||
if (newName) {
|
||||
level.name = newName;
|
||||
target.textContent = newName;
|
||||
}
|
||||
} else if (target.getAttribute('data-delete')) {
|
||||
if (confirm('Delete level')) {
|
||||
allLevels = allLevels.filter((l, i)=>i !== levelIndex);
|
||||
save().then(()=>window.location.reload());
|
||||
}
|
||||
}
|
||||
renderLevelBricks(levelIndex);
|
||||
save();
|
||||
}, true);
|
||||
let applying = '';
|
||||
function colorPixel(e) {
|
||||
const target = e.target;
|
||||
if (applying === '') return;
|
||||
console.log('colorPixel', applying);
|
||||
const index = target.getAttribute('data-set-color-of');
|
||||
const level = target.getAttribute('data-level');
|
||||
if (index && level) {
|
||||
const levelIndex = parseInt(level);
|
||||
target.style.background = palette[applying] || 'transparent';
|
||||
setBrick(levelIndex, parseInt(index), applying);
|
||||
}
|
||||
}
|
||||
function setBrick(levelIndex, index, chr) {
|
||||
const bricks = allLevels[levelIndex].bricks;
|
||||
allLevels[levelIndex].bricks = bricks.substring(0, index) + chr + bricks.substring(index + 1);
|
||||
}
|
||||
let changed = 0;
|
||||
levelsListEl.addEventListener('mousedown', (e)=>{
|
||||
const target = e.target;
|
||||
const index = target.getAttribute('data-set-color-of');
|
||||
const level = target.getAttribute('data-level');
|
||||
if (index && level) {
|
||||
changed = 0;
|
||||
const before = allLevels[parseInt(level)].bricks[parseInt(index)] || '';
|
||||
applying = before === currentCode ? '_' : currentCode;
|
||||
console.log({
|
||||
before,
|
||||
applying,
|
||||
currentCode
|
||||
});
|
||||
colorPixel(e);
|
||||
}
|
||||
});
|
||||
levelsListEl.addEventListener('mouseenter', (e)=>{
|
||||
if (applying !== '') {
|
||||
colorPixel(e);
|
||||
changed++;
|
||||
}
|
||||
}, true);
|
||||
document.addEventListener('mouseup', (e)=>{
|
||||
applying = '';
|
||||
if (changed) save();
|
||||
});
|
||||
document.getElementById('new-level').addEventListener('click', (e)=>{
|
||||
const name = prompt("Name ? ");
|
||||
if (!name) return;
|
||||
allLevels.push({
|
||||
name,
|
||||
size: 8,
|
||||
bricks: '________________________________________________________________',
|
||||
svg: null,
|
||||
color: ''
|
||||
});
|
||||
const levelIndex = allLevels.length - 1;
|
||||
addLevelEditorToList(allLevels[levelIndex], levelIndex);
|
||||
save();
|
||||
}, true);
|
||||
renderAllLevels();
|
||||
function save() {
|
||||
return fetch('http://localhost:4400/src/levels.json', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
},
|
||||
body: JSON.stringify(allLevels, null, 2)
|
||||
});
|
||||
}
|
||||
|
||||
},{"./backgrounds.json":"el6Kx","./palette.json":"jhnsJ","./levels.json":"kqnNl","@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3","./getLevelBackground":"7OIPf"}]},["7tSz9","434tO"], "434tO", "parcelRequire94c2")
|
||||
|
||||
//# sourceMappingURL=levels_editor.227fd609.js.map
|
1
dist/levels_editor.227fd609.js.map
vendored
602
dist/levels_editor.2b1191d6.js
vendored
|
@ -1,602 +0,0 @@
|
|||
// modules are defined as an array
|
||||
// [ module function, map of requires ]
|
||||
//
|
||||
// map of requires is short require name -> numeric require
|
||||
//
|
||||
// anything defined in a previous bundle is accessed via the
|
||||
// orig method which is the require for previous bundles
|
||||
|
||||
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
||||
/* eslint-disable no-undef */
|
||||
var globalObject =
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
: typeof self !== 'undefined'
|
||||
? self
|
||||
: typeof window !== 'undefined'
|
||||
? window
|
||||
: typeof global !== 'undefined'
|
||||
? global
|
||||
: {};
|
||||
/* eslint-enable no-undef */
|
||||
|
||||
// Save the require from previous bundle to this closure if any
|
||||
var previousRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
|
||||
var cache = previousRequire.cache || {};
|
||||
// Do not use `require` to prevent Webpack from trying to bundle this call
|
||||
var nodeRequire =
|
||||
typeof module !== 'undefined' &&
|
||||
typeof module.require === 'function' &&
|
||||
module.require.bind(module);
|
||||
|
||||
function newRequire(name, jumped) {
|
||||
if (!cache[name]) {
|
||||
if (!modules[name]) {
|
||||
// if we cannot find the module within our internal map or
|
||||
// cache jump to the current global require ie. the last bundle
|
||||
// that was added to the page.
|
||||
var currentRequire =
|
||||
typeof globalObject[parcelRequireName] === 'function' &&
|
||||
globalObject[parcelRequireName];
|
||||
if (!jumped && currentRequire) {
|
||||
return currentRequire(name, true);
|
||||
}
|
||||
|
||||
// If there are other bundles on this page the require from the
|
||||
// previous one is saved to 'previousRequire'. Repeat this as
|
||||
// many times as there are bundles until the module is found or
|
||||
// we exhaust the require chain.
|
||||
if (previousRequire) {
|
||||
return previousRequire(name, true);
|
||||
}
|
||||
|
||||
// Try the node require function if it exists.
|
||||
if (nodeRequire && typeof name === 'string') {
|
||||
return nodeRequire(name);
|
||||
}
|
||||
|
||||
var err = new Error("Cannot find module '" + name + "'");
|
||||
err.code = 'MODULE_NOT_FOUND';
|
||||
throw err;
|
||||
}
|
||||
|
||||
localRequire.resolve = resolve;
|
||||
localRequire.cache = {};
|
||||
|
||||
var module = (cache[name] = new newRequire.Module(name));
|
||||
|
||||
modules[name][0].call(
|
||||
module.exports,
|
||||
localRequire,
|
||||
module,
|
||||
module.exports,
|
||||
globalObject
|
||||
);
|
||||
}
|
||||
|
||||
return cache[name].exports;
|
||||
|
||||
function localRequire(x) {
|
||||
var res = localRequire.resolve(x);
|
||||
return res === false ? {} : newRequire(res);
|
||||
}
|
||||
|
||||
function resolve(x) {
|
||||
var id = modules[name][1][x];
|
||||
return id != null ? id : x;
|
||||
}
|
||||
}
|
||||
|
||||
function Module(moduleName) {
|
||||
this.id = moduleName;
|
||||
this.bundle = newRequire;
|
||||
this.exports = {};
|
||||
}
|
||||
|
||||
newRequire.isParcelRequire = true;
|
||||
newRequire.Module = Module;
|
||||
newRequire.modules = modules;
|
||||
newRequire.cache = cache;
|
||||
newRequire.parent = previousRequire;
|
||||
newRequire.register = function (id, exports) {
|
||||
modules[id] = [
|
||||
function (require, module) {
|
||||
module.exports = exports;
|
||||
},
|
||||
{},
|
||||
];
|
||||
};
|
||||
|
||||
Object.defineProperty(newRequire, 'root', {
|
||||
get: function () {
|
||||
return globalObject[parcelRequireName];
|
||||
},
|
||||
});
|
||||
|
||||
globalObject[parcelRequireName] = newRequire;
|
||||
|
||||
for (var i = 0; i < entry.length; i++) {
|
||||
newRequire(entry[i]);
|
||||
}
|
||||
|
||||
if (mainEntry) {
|
||||
// Expose entry point to Node, AMD or browser globals
|
||||
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
|
||||
var mainExports = newRequire(mainEntry);
|
||||
|
||||
// CommonJS
|
||||
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
||||
module.exports = mainExports;
|
||||
|
||||
// RequireJS
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
define(function () {
|
||||
return mainExports;
|
||||
});
|
||||
|
||||
// <script>
|
||||
} else if (globalName) {
|
||||
this[globalName] = mainExports;
|
||||
}
|
||||
}
|
||||
})({"3h6wz":[function(require,module,exports,__globalThis) {
|
||||
var global = arguments[3];
|
||||
var HMR_HOST = null;
|
||||
var HMR_PORT = null;
|
||||
var HMR_SECURE = false;
|
||||
var HMR_ENV_HASH = "d6ea1d42532a7575";
|
||||
var HMR_USE_SSE = false;
|
||||
module.bundle.HMR_BUNDLE_ID = "084fd22b2b1191d6";
|
||||
"use strict";
|
||||
/* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, HMR_USE_SSE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */ /*::
|
||||
import type {
|
||||
HMRAsset,
|
||||
HMRMessage,
|
||||
} from '@parcel/reporter-dev-server/src/HMRServer.js';
|
||||
interface ParcelRequire {
|
||||
(string): mixed;
|
||||
cache: {|[string]: ParcelModule|};
|
||||
hotData: {|[string]: mixed|};
|
||||
Module: any;
|
||||
parent: ?ParcelRequire;
|
||||
isParcelRequire: true;
|
||||
modules: {|[string]: [Function, {|[string]: string|}]|};
|
||||
HMR_BUNDLE_ID: string;
|
||||
root: ParcelRequire;
|
||||
}
|
||||
interface ParcelModule {
|
||||
hot: {|
|
||||
data: mixed,
|
||||
accept(cb: (Function) => void): void,
|
||||
dispose(cb: (mixed) => void): void,
|
||||
// accept(deps: Array<string> | string, cb: (Function) => void): void,
|
||||
// decline(): void,
|
||||
_acceptCallbacks: Array<(Function) => void>,
|
||||
_disposeCallbacks: Array<(mixed) => void>,
|
||||
|};
|
||||
}
|
||||
interface ExtensionContext {
|
||||
runtime: {|
|
||||
reload(): void,
|
||||
getURL(url: string): string;
|
||||
getManifest(): {manifest_version: number, ...};
|
||||
|};
|
||||
}
|
||||
declare var module: {bundle: ParcelRequire, ...};
|
||||
declare var HMR_HOST: string;
|
||||
declare var HMR_PORT: string;
|
||||
declare var HMR_ENV_HASH: string;
|
||||
declare var HMR_SECURE: boolean;
|
||||
declare var HMR_USE_SSE: boolean;
|
||||
declare var chrome: ExtensionContext;
|
||||
declare var browser: ExtensionContext;
|
||||
declare var __parcel__import__: (string) => Promise<void>;
|
||||
declare var __parcel__importScripts__: (string) => Promise<void>;
|
||||
declare var globalThis: typeof self;
|
||||
declare var ServiceWorkerGlobalScope: Object;
|
||||
*/ var OVERLAY_ID = '__parcel__error__overlay__';
|
||||
var OldModule = module.bundle.Module;
|
||||
function Module(moduleName) {
|
||||
OldModule.call(this, moduleName);
|
||||
this.hot = {
|
||||
data: module.bundle.hotData[moduleName],
|
||||
_acceptCallbacks: [],
|
||||
_disposeCallbacks: [],
|
||||
accept: function(fn) {
|
||||
this._acceptCallbacks.push(fn || function() {});
|
||||
},
|
||||
dispose: function(fn) {
|
||||
this._disposeCallbacks.push(fn);
|
||||
}
|
||||
};
|
||||
module.bundle.hotData[moduleName] = undefined;
|
||||
}
|
||||
module.bundle.Module = Module;
|
||||
module.bundle.hotData = {};
|
||||
var checkedAssets /*: {|[string]: boolean|} */ , disposedAssets /*: {|[string]: boolean|} */ , assetsToDispose /*: Array<[ParcelRequire, string]> */ , assetsToAccept /*: Array<[ParcelRequire, string]> */ ;
|
||||
function getHostname() {
|
||||
return HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
|
||||
}
|
||||
function getPort() {
|
||||
return HMR_PORT || location.port;
|
||||
}
|
||||
// eslint-disable-next-line no-redeclare
|
||||
var parent = module.bundle.parent;
|
||||
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
||||
var hostname = getHostname();
|
||||
var port = getPort();
|
||||
var protocol = HMR_SECURE || location.protocol == 'https:' && ![
|
||||
'localhost',
|
||||
'127.0.0.1',
|
||||
'0.0.0.0'
|
||||
].includes(hostname) ? 'wss' : 'ws';
|
||||
var ws;
|
||||
if (HMR_USE_SSE) ws = new EventSource('/__parcel_hmr');
|
||||
else try {
|
||||
ws = new WebSocket(protocol + '://' + hostname + (port ? ':' + port : '') + '/');
|
||||
} catch (err) {
|
||||
if (err.message) console.error(err.message);
|
||||
ws = {};
|
||||
}
|
||||
// Web extension context
|
||||
var extCtx = typeof browser === 'undefined' ? typeof chrome === 'undefined' ? null : chrome : browser;
|
||||
// Safari doesn't support sourceURL in error stacks.
|
||||
// eval may also be disabled via CSP, so do a quick check.
|
||||
var supportsSourceURL = false;
|
||||
try {
|
||||
(0, eval)('throw new Error("test"); //# sourceURL=test.js');
|
||||
} catch (err) {
|
||||
supportsSourceURL = err.stack.includes('test.js');
|
||||
}
|
||||
// $FlowFixMe
|
||||
ws.onmessage = async function(event /*: {data: string, ...} */ ) {
|
||||
checkedAssets = {} /*: {|[string]: boolean|} */ ;
|
||||
disposedAssets = {} /*: {|[string]: boolean|} */ ;
|
||||
assetsToAccept = [];
|
||||
assetsToDispose = [];
|
||||
var data /*: HMRMessage */ = JSON.parse(event.data);
|
||||
if (data.type === 'reload') fullReload();
|
||||
else if (data.type === 'update') {
|
||||
// Remove error overlay if there is one
|
||||
if (typeof document !== 'undefined') removeErrorOverlay();
|
||||
let assets = data.assets.filter((asset)=>asset.envHash === HMR_ENV_HASH);
|
||||
// Handle HMR Update
|
||||
let handled = assets.every((asset)=>{
|
||||
return asset.type === 'css' || asset.type === 'js' && hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
|
||||
});
|
||||
if (handled) {
|
||||
console.clear();
|
||||
// Dispatch custom event so other runtimes (e.g React Refresh) are aware.
|
||||
if (typeof window !== 'undefined' && typeof CustomEvent !== 'undefined') window.dispatchEvent(new CustomEvent('parcelhmraccept'));
|
||||
await hmrApplyUpdates(assets);
|
||||
hmrDisposeQueue();
|
||||
// Run accept callbacks. This will also re-execute other disposed assets in topological order.
|
||||
let processedAssets = {};
|
||||
for(let i = 0; i < assetsToAccept.length; i++){
|
||||
let id = assetsToAccept[i][1];
|
||||
if (!processedAssets[id]) {
|
||||
hmrAccept(assetsToAccept[i][0], id);
|
||||
processedAssets[id] = true;
|
||||
}
|
||||
}
|
||||
} else fullReload();
|
||||
}
|
||||
if (data.type === 'error') {
|
||||
// Log parcel errors to console
|
||||
for (let ansiDiagnostic of data.diagnostics.ansi){
|
||||
let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
|
||||
console.error("\uD83D\uDEA8 [parcel]: " + ansiDiagnostic.message + '\n' + stack + '\n\n' + ansiDiagnostic.hints.join('\n'));
|
||||
}
|
||||
if (typeof document !== 'undefined') {
|
||||
// Render the fancy html overlay
|
||||
removeErrorOverlay();
|
||||
var overlay = createErrorOverlay(data.diagnostics.html);
|
||||
// $FlowFixMe
|
||||
document.body.appendChild(overlay);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (ws instanceof WebSocket) {
|
||||
ws.onerror = function(e) {
|
||||
if (e.message) console.error(e.message);
|
||||
};
|
||||
ws.onclose = function() {
|
||||
console.warn("[parcel] \uD83D\uDEA8 Connection to the HMR server was lost");
|
||||
};
|
||||
}
|
||||
}
|
||||
function removeErrorOverlay() {
|
||||
var overlay = document.getElementById(OVERLAY_ID);
|
||||
if (overlay) {
|
||||
overlay.remove();
|
||||
console.log("[parcel] \u2728 Error resolved");
|
||||
}
|
||||
}
|
||||
function createErrorOverlay(diagnostics) {
|
||||
var overlay = document.createElement('div');
|
||||
overlay.id = OVERLAY_ID;
|
||||
let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';
|
||||
for (let diagnostic of diagnostics){
|
||||
let stack = diagnostic.frames.length ? diagnostic.frames.reduce((p, frame)=>{
|
||||
return `${p}
|
||||
<a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
|
||||
${frame.code}`;
|
||||
}, '') : diagnostic.stack;
|
||||
errorHTML += `
|
||||
<div>
|
||||
<div style="font-size: 18px; font-weight: bold; margin-top: 20px;">
|
||||
\u{1F6A8} ${diagnostic.message}
|
||||
</div>
|
||||
<pre>${stack}</pre>
|
||||
<div>
|
||||
${diagnostic.hints.map((hint)=>"<div>\uD83D\uDCA1 " + hint + '</div>').join('')}
|
||||
</div>
|
||||
${diagnostic.documentation ? `<div>\u{1F4DD} <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ''}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
errorHTML += '</div>';
|
||||
overlay.innerHTML = errorHTML;
|
||||
return overlay;
|
||||
}
|
||||
function fullReload() {
|
||||
if ('reload' in location) location.reload();
|
||||
else if (extCtx && extCtx.runtime && extCtx.runtime.reload) extCtx.runtime.reload();
|
||||
}
|
||||
function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
|
||||
var modules = bundle.modules;
|
||||
if (!modules) return [];
|
||||
var parents = [];
|
||||
var k, d, dep;
|
||||
for(k in modules)for(d in modules[k][1]){
|
||||
dep = modules[k][1][d];
|
||||
if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) parents.push([
|
||||
bundle,
|
||||
k
|
||||
]);
|
||||
}
|
||||
if (bundle.parent) parents = parents.concat(getParents(bundle.parent, id));
|
||||
return parents;
|
||||
}
|
||||
function updateLink(link) {
|
||||
var href = link.getAttribute('href');
|
||||
if (!href) return;
|
||||
var newLink = link.cloneNode();
|
||||
newLink.onload = function() {
|
||||
if (link.parentNode !== null) // $FlowFixMe
|
||||
link.parentNode.removeChild(link);
|
||||
};
|
||||
newLink.setAttribute('href', // $FlowFixMe
|
||||
href.split('?')[0] + '?' + Date.now());
|
||||
// $FlowFixMe
|
||||
link.parentNode.insertBefore(newLink, link.nextSibling);
|
||||
}
|
||||
var cssTimeout = null;
|
||||
function reloadCSS() {
|
||||
if (cssTimeout) return;
|
||||
cssTimeout = setTimeout(function() {
|
||||
var links = document.querySelectorAll('link[rel="stylesheet"]');
|
||||
for(var i = 0; i < links.length; i++){
|
||||
// $FlowFixMe[incompatible-type]
|
||||
var href /*: string */ = links[i].getAttribute('href');
|
||||
var hostname = getHostname();
|
||||
var servedFromHMRServer = hostname === 'localhost' ? new RegExp('^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):' + getPort()).test(href) : href.indexOf(hostname + ':' + getPort());
|
||||
var absolute = /^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
|
||||
if (!absolute) updateLink(links[i]);
|
||||
}
|
||||
cssTimeout = null;
|
||||
}, 50);
|
||||
}
|
||||
function hmrDownload(asset) {
|
||||
if (asset.type === 'js') {
|
||||
if (typeof document !== 'undefined') {
|
||||
let script = document.createElement('script');
|
||||
script.src = asset.url + '?t=' + Date.now();
|
||||
if (asset.outputFormat === 'esmodule') script.type = 'module';
|
||||
return new Promise((resolve, reject)=>{
|
||||
var _document$head;
|
||||
script.onload = ()=>resolve(script);
|
||||
script.onerror = reject;
|
||||
(_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script);
|
||||
});
|
||||
} else if (typeof importScripts === 'function') {
|
||||
// Worker scripts
|
||||
if (asset.outputFormat === 'esmodule') return import(asset.url + '?t=' + Date.now());
|
||||
else return new Promise((resolve, reject)=>{
|
||||
try {
|
||||
importScripts(asset.url + '?t=' + Date.now());
|
||||
resolve();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
async function hmrApplyUpdates(assets) {
|
||||
global.parcelHotUpdate = Object.create(null);
|
||||
let scriptsToRemove;
|
||||
try {
|
||||
// If sourceURL comments aren't supported in eval, we need to load
|
||||
// the update from the dev server over HTTP so that stack traces
|
||||
// are correct in errors/logs. This is much slower than eval, so
|
||||
// we only do it if needed (currently just Safari).
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=137297
|
||||
// This path is also taken if a CSP disallows eval.
|
||||
if (!supportsSourceURL) {
|
||||
let promises = assets.map((asset)=>{
|
||||
var _hmrDownload;
|
||||
return (_hmrDownload = hmrDownload(asset)) === null || _hmrDownload === void 0 ? void 0 : _hmrDownload.catch((err)=>{
|
||||
// Web extension fix
|
||||
if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 && typeof ServiceWorkerGlobalScope != 'undefined' && global instanceof ServiceWorkerGlobalScope) {
|
||||
extCtx.runtime.reload();
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
scriptsToRemove = await Promise.all(promises);
|
||||
}
|
||||
assets.forEach(function(asset) {
|
||||
hmrApply(module.bundle.root, asset);
|
||||
});
|
||||
} finally{
|
||||
delete global.parcelHotUpdate;
|
||||
if (scriptsToRemove) scriptsToRemove.forEach((script)=>{
|
||||
if (script) {
|
||||
var _document$head2;
|
||||
(_document$head2 = document.head) === null || _document$head2 === void 0 || _document$head2.removeChild(script);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function hmrApply(bundle /*: ParcelRequire */ , asset /*: HMRAsset */ ) {
|
||||
var modules = bundle.modules;
|
||||
if (!modules) return;
|
||||
if (asset.type === 'css') reloadCSS();
|
||||
else if (asset.type === 'js') {
|
||||
let deps = asset.depsByBundle[bundle.HMR_BUNDLE_ID];
|
||||
if (deps) {
|
||||
if (modules[asset.id]) {
|
||||
// Remove dependencies that are removed and will become orphaned.
|
||||
// This is necessary so that if the asset is added back again, the cache is gone, and we prevent a full page reload.
|
||||
let oldDeps = modules[asset.id][1];
|
||||
for(let dep in oldDeps)if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
|
||||
let id = oldDeps[dep];
|
||||
let parents = getParents(module.bundle.root, id);
|
||||
if (parents.length === 1) hmrDelete(module.bundle.root, id);
|
||||
}
|
||||
}
|
||||
if (supportsSourceURL) // Global eval. We would use `new Function` here but browser
|
||||
// support for source maps is better with eval.
|
||||
(0, eval)(asset.output);
|
||||
// $FlowFixMe
|
||||
let fn = global.parcelHotUpdate[asset.id];
|
||||
modules[asset.id] = [
|
||||
fn,
|
||||
deps
|
||||
];
|
||||
}
|
||||
// Always traverse to the parent bundle, even if we already replaced the asset in this bundle.
|
||||
// This is required in case modules are duplicated. We need to ensure all instances have the updated code.
|
||||
if (bundle.parent) hmrApply(bundle.parent, asset);
|
||||
}
|
||||
}
|
||||
function hmrDelete(bundle, id) {
|
||||
let modules = bundle.modules;
|
||||
if (!modules) return;
|
||||
if (modules[id]) {
|
||||
// Collect dependencies that will become orphaned when this module is deleted.
|
||||
let deps = modules[id][1];
|
||||
let orphans = [];
|
||||
for(let dep in deps){
|
||||
let parents = getParents(module.bundle.root, deps[dep]);
|
||||
if (parents.length === 1) orphans.push(deps[dep]);
|
||||
}
|
||||
// Delete the module. This must be done before deleting dependencies in case of circular dependencies.
|
||||
delete modules[id];
|
||||
delete bundle.cache[id];
|
||||
// Now delete the orphans.
|
||||
orphans.forEach((id)=>{
|
||||
hmrDelete(module.bundle.root, id);
|
||||
});
|
||||
} else if (bundle.parent) hmrDelete(bundle.parent, id);
|
||||
}
|
||||
function hmrAcceptCheck(bundle /*: ParcelRequire */ , id /*: string */ , depsByBundle /*: ?{ [string]: { [string]: string } }*/ ) {
|
||||
if (hmrAcceptCheckOne(bundle, id, depsByBundle)) return true;
|
||||
// Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
|
||||
let parents = getParents(module.bundle.root, id);
|
||||
let accepted = false;
|
||||
while(parents.length > 0){
|
||||
let v = parents.shift();
|
||||
let a = hmrAcceptCheckOne(v[0], v[1], null);
|
||||
if (a) // If this parent accepts, stop traversing upward, but still consider siblings.
|
||||
accepted = true;
|
||||
else {
|
||||
// Otherwise, queue the parents in the next level upward.
|
||||
let p = getParents(module.bundle.root, v[1]);
|
||||
if (p.length === 0) {
|
||||
// If there are no parents, then we've reached an entry without accepting. Reload.
|
||||
accepted = false;
|
||||
break;
|
||||
}
|
||||
parents.push(...p);
|
||||
}
|
||||
}
|
||||
return accepted;
|
||||
}
|
||||
function hmrAcceptCheckOne(bundle /*: ParcelRequire */ , id /*: string */ , depsByBundle /*: ?{ [string]: { [string]: string } }*/ ) {
|
||||
var modules = bundle.modules;
|
||||
if (!modules) return;
|
||||
if (depsByBundle && !depsByBundle[bundle.HMR_BUNDLE_ID]) {
|
||||
// If we reached the root bundle without finding where the asset should go,
|
||||
// there's nothing to do. Mark as "accepted" so we don't reload the page.
|
||||
if (!bundle.parent) return true;
|
||||
return hmrAcceptCheck(bundle.parent, id, depsByBundle);
|
||||
}
|
||||
if (checkedAssets[id]) return true;
|
||||
checkedAssets[id] = true;
|
||||
var cached = bundle.cache[id];
|
||||
assetsToDispose.push([
|
||||
bundle,
|
||||
id
|
||||
]);
|
||||
if (!cached || cached.hot && cached.hot._acceptCallbacks.length) {
|
||||
assetsToAccept.push([
|
||||
bundle,
|
||||
id
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function hmrDisposeQueue() {
|
||||
// Dispose all old assets.
|
||||
for(let i = 0; i < assetsToDispose.length; i++){
|
||||
let id = assetsToDispose[i][1];
|
||||
if (!disposedAssets[id]) {
|
||||
hmrDispose(assetsToDispose[i][0], id);
|
||||
disposedAssets[id] = true;
|
||||
}
|
||||
}
|
||||
assetsToDispose = [];
|
||||
}
|
||||
function hmrDispose(bundle /*: ParcelRequire */ , id /*: string */ ) {
|
||||
var cached = bundle.cache[id];
|
||||
bundle.hotData[id] = {};
|
||||
if (cached && cached.hot) cached.hot.data = bundle.hotData[id];
|
||||
if (cached && cached.hot && cached.hot._disposeCallbacks.length) cached.hot._disposeCallbacks.forEach(function(cb) {
|
||||
cb(bundle.hotData[id]);
|
||||
});
|
||||
delete bundle.cache[id];
|
||||
}
|
||||
function hmrAccept(bundle /*: ParcelRequire */ , id /*: string */ ) {
|
||||
// Execute the module.
|
||||
bundle(id);
|
||||
// Run the accept callbacks in the new version of the module.
|
||||
var cached = bundle.cache[id];
|
||||
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
|
||||
let assetsToAlsoAccept = [];
|
||||
cached.hot._acceptCallbacks.forEach(function(cb) {
|
||||
let additionalAssets = cb(function() {
|
||||
return getParents(module.bundle.root, id);
|
||||
});
|
||||
if (Array.isArray(additionalAssets) && additionalAssets.length) assetsToAlsoAccept.push(...additionalAssets);
|
||||
});
|
||||
if (assetsToAlsoAccept.length) {
|
||||
let handled = assetsToAlsoAccept.every(function(a) {
|
||||
return hmrAcceptCheck(a[0], a[1]);
|
||||
});
|
||||
if (!handled) return fullReload();
|
||||
hmrDisposeQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},{}],"7ns8t":[function(require,module,exports,__globalThis) {
|
||||
|
||||
},{}]},["3h6wz","7ns8t"], "7ns8t", "parcelRequire94c2")
|
||||
|
||||
//# sourceMappingURL=levels_editor.2b1191d6.js.map
|
1
dist/levels_editor.2b1191d6.js.map
vendored
2
dist/levels_editor.de5e7f9b.css.map
vendored
|
@ -1 +1 @@
|
|||
{"mappings":"AACA;;;;;AAKA;;;;;;;;;AAAA;;;;AAcA;;;;;;;;AAAA;;;;AAAA;;;;AAcE;;;;;;;AAKE;;;;AAIA;;;;;;;AAOA","sources":["src/levels_editor.less"],"sourcesContent":["\nbody {\n background: black;\n color: white;\n}\n\n#palette {\n position: fixed;\n top: 0;\n right: 0;\n width: 80px;\n bottom: 0;\n overflow: auto;\n\n button.active {\n transform: scale(1.2);\n }\n\n}\n\n#levels {\n display: flex;\n gap: 40px;\n align-items: flex-start;\n flex-wrap: wrap;\n margin-right: 80px;\n\n .level-bricks-preview {\n position: relative;\n }\n input[type=\"number\"]{\n width: 50px;\n }\n\n & > div {\n display: grid;\n grid-template-columns: auto auto;\n grid-template-areas: \". name\" \"buttons bricks\";\n\n & > *:nth-child(1) {\n grid-area: name;\n }\n\n & > div:nth-child(2) {\n grid-area: buttons;\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n }\n\n & > div:nth-child(3) {\n grid-area: bricks;\n }\n\n }\n\n}\n\n"],"names":[],"version":3,"file":"levels_editor.de5e7f9b.css.map","sourceRoot":"/__parcel_source_root/"}
|
||||
{"mappings":"AAAA;;;;;AAKA;;;;;;;;;AAAA;;;;AAaA;;;;;;;;AAAA;;;;AAAA;;;;AAcE;;;;;;;AAKE;;;;AAIA;;;;;;;AAOA","sources":["src/levels_editor.less"],"sourcesContent":["body {\n background: black;\n color: white;\n}\n\n#palette {\n position: fixed;\n top: 0;\n right: 0;\n width: 80px;\n bottom: 0;\n overflow: auto;\n\n button.active {\n transform: scale(1.2);\n }\n}\n\n#levels {\n display: flex;\n gap: 40px;\n align-items: flex-start;\n flex-wrap: wrap;\n margin-right: 80px;\n\n .level-bricks-preview {\n position: relative;\n }\n input[type=\"number\"] {\n width: 50px;\n }\n\n & > div {\n display: grid;\n grid-template-columns: auto auto;\n grid-template-areas: \". name\" \"buttons bricks\";\n\n & > *:nth-child(1) {\n grid-area: name;\n }\n\n & > div:nth-child(2) {\n grid-area: buttons;\n display: flex;\n flex-direction: column;\n align-items: flex-end;\n }\n\n & > div:nth-child(3) {\n grid-area: bricks;\n }\n }\n}\n"],"names":[],"version":3,"file":"levels_editor.de5e7f9b.css.map","sourceRoot":"/__parcel_source_root/"}
|
137
dist/levels_editor.ef3c2e1a.js
vendored
|
@ -259,8 +259,8 @@ const backgrounds = (0, _backgroundsJsonDefault.default);
|
|||
const palette = (0, _paletteJsonDefault.default);
|
||||
let allLevels = (0, _levelsJsonDefault.default);
|
||||
function App() {
|
||||
const [selected, setSelected] = (0, _react.useState)('W');
|
||||
const [applying, setApplying] = (0, _react.useState)('');
|
||||
const [selected, setSelected] = (0, _react.useState)("W");
|
||||
const [applying, setApplying] = (0, _react.useState)("");
|
||||
const [levels, setLevels] = (0, _react.useState)(allLevels);
|
||||
const updateLevel = (0, _react.useCallback)((index, change)=>{
|
||||
setLevels((list)=>list.map((l, li)=>li === index ? {
|
||||
|
@ -269,14 +269,14 @@ function App() {
|
|||
} : l));
|
||||
}, []);
|
||||
const deleteLevel = (0, _react.useCallback)((li)=>{
|
||||
if (confirm('Delete level')) setLevels(allLevels.filter((l, i)=>i !== li));
|
||||
if (confirm("Delete level")) setLevels(allLevels.filter((l, i)=>i !== li));
|
||||
}, []);
|
||||
(0, _react.useEffect)(()=>{
|
||||
const timoutId = setTimeout(()=>{
|
||||
return fetch('http://localhost:4400/src/levels.json', {
|
||||
method: 'POST',
|
||||
return fetch("http://localhost:4400/src/levels.json", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
"Content-Type": "text/plain"
|
||||
},
|
||||
body: JSON.stringify(levels, null, 2)
|
||||
});
|
||||
|
@ -287,8 +287,7 @@ function App() {
|
|||
]);
|
||||
return /*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("div", {
|
||||
onMouseUp: ()=>{
|
||||
console.log('mouse up');
|
||||
setApplying('');
|
||||
setApplying("");
|
||||
},
|
||||
children: [
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("div", {
|
||||
|
@ -301,8 +300,7 @@ function App() {
|
|||
brickButtons.push(/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("button", {
|
||||
onMouseDown: ()=>{
|
||||
if (!applying) {
|
||||
console.log(selected, bricks[index], applying);
|
||||
const color = selected === bricks[index] ? '_' : selected;
|
||||
const color = selected === bricks[index] ? "_" : selected;
|
||||
setApplying(color);
|
||||
updateLevel(li, (0, _levelsEditorUtil.setBrick)(level, index, color));
|
||||
}
|
||||
|
@ -311,25 +309,25 @@ function App() {
|
|||
if (applying) updateLevel(li, (0, _levelsEditorUtil.setBrick)(level, index, applying));
|
||||
},
|
||||
style: {
|
||||
background: palette[bricks[index]] || 'transparent',
|
||||
background: palette[bricks[index]] || "transparent",
|
||||
left: x * 40,
|
||||
top: y * 40,
|
||||
width: 40,
|
||||
height: 40,
|
||||
position: 'absolute'
|
||||
position: "absolute"
|
||||
}
|
||||
}, index, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 61,
|
||||
columnNumber: 51
|
||||
lineNumber: 63,
|
||||
columnNumber: 17
|
||||
}, this));
|
||||
}
|
||||
const background = color ? {
|
||||
backgroundImage: 'none',
|
||||
backgroundImage: "none",
|
||||
backgroundColor: color
|
||||
} : {
|
||||
backgroundImage: `url("data:image/svg+xml;UTF8,${encodeURIComponent((0, _getLevelBackground.getLevelBackground)(level))}")`,
|
||||
backgroundColor: 'transparent'
|
||||
backgroundColor: "transparent"
|
||||
};
|
||||
return /*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("div", {
|
||||
children: [
|
||||
|
@ -341,8 +339,8 @@ function App() {
|
|||
})
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 90,
|
||||
columnNumber: 29
|
||||
lineNumber: 99,
|
||||
columnNumber: 15
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("div", {
|
||||
children: [
|
||||
|
@ -351,85 +349,85 @@ function App() {
|
|||
children: "Delete"
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 92,
|
||||
columnNumber: 33
|
||||
lineNumber: 105,
|
||||
columnNumber: 17
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("button", {
|
||||
onClick: ()=>updateLevel(li, (0, _levelsEditorUtil.resizeLevel)(level, -1)),
|
||||
children: "-"
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 93,
|
||||
columnNumber: 33
|
||||
lineNumber: 106,
|
||||
columnNumber: 17
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("button", {
|
||||
onClick: ()=>updateLevel(li, (0, _levelsEditorUtil.resizeLevel)(level, 1)),
|
||||
children: "+"
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 94,
|
||||
columnNumber: 33
|
||||
lineNumber: 109,
|
||||
columnNumber: 17
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("button", {
|
||||
onClick: ()=>updateLevel(li, (0, _levelsEditorUtil.moveLevel)(level, -1, 0)),
|
||||
children: "L"
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 95,
|
||||
columnNumber: 33
|
||||
lineNumber: 112,
|
||||
columnNumber: 17
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("button", {
|
||||
onClick: ()=>updateLevel(li, (0, _levelsEditorUtil.moveLevel)(level, 1, 0)),
|
||||
children: "R"
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 96,
|
||||
columnNumber: 33
|
||||
lineNumber: 117,
|
||||
columnNumber: 17
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("button", {
|
||||
onClick: ()=>updateLevel(li, (0, _levelsEditorUtil.moveLevel)(level, 0, -1)),
|
||||
children: "U"
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 97,
|
||||
columnNumber: 33
|
||||
lineNumber: 120,
|
||||
columnNumber: 17
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("button", {
|
||||
onClick: ()=>updateLevel(li, (0, _levelsEditorUtil.moveLevel)(level, 0, 1)),
|
||||
children: "D"
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 98,
|
||||
columnNumber: 33
|
||||
lineNumber: 125,
|
||||
columnNumber: 17
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("input", {
|
||||
type: "color",
|
||||
value: level.color || '',
|
||||
value: level.color || "",
|
||||
onChange: (e)=>e.target.value && updateLevel(li, {
|
||||
color: e.target.value
|
||||
})
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 99,
|
||||
columnNumber: 33
|
||||
lineNumber: 128,
|
||||
columnNumber: 17
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("input", {
|
||||
type: "number",
|
||||
value: level.svg || (0, _getLevelBackground.hashCode)(level.name) % backgrounds.length,
|
||||
onChange: (e)=>!isNaN(parseFloat(e.target.value)) && updateLevel(li, {
|
||||
color: '',
|
||||
color: "",
|
||||
svg: parseFloat(e.target.value)
|
||||
})
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 101,
|
||||
columnNumber: 33
|
||||
lineNumber: 135,
|
||||
columnNumber: 17
|
||||
}, this)
|
||||
]
|
||||
}, void 0, true, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 91,
|
||||
columnNumber: 29
|
||||
lineNumber: 104,
|
||||
columnNumber: 15
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("div", {
|
||||
className: "level-bricks-preview",
|
||||
|
@ -441,42 +439,42 @@ function App() {
|
|||
children: brickButtons
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 109,
|
||||
columnNumber: 29
|
||||
lineNumber: 147,
|
||||
columnNumber: 15
|
||||
}, this)
|
||||
]
|
||||
}, li, true, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 89,
|
||||
columnNumber: 32
|
||||
lineNumber: 98,
|
||||
columnNumber: 13
|
||||
}, this);
|
||||
})
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 52,
|
||||
columnNumber: 9
|
||||
lineNumber: 54,
|
||||
columnNumber: 7
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("div", {
|
||||
id: "palette",
|
||||
children: Object.entries(palette).map(([code, color])=>/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("button", {
|
||||
className: code === selected ? 'active' : '',
|
||||
className: code === selected ? "active" : "",
|
||||
style: {
|
||||
background: color || 'linear-gradient(45deg,black,white)',
|
||||
display: 'inline-block',
|
||||
width: '40px',
|
||||
height: '40px',
|
||||
border: '1px solid black'
|
||||
background: color || "linear-gradient(45deg,black,white)",
|
||||
display: "inline-block",
|
||||
width: "40px",
|
||||
height: "40px",
|
||||
border: "1px solid black"
|
||||
},
|
||||
onClick: ()=>setSelected(code)
|
||||
}, code, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 127,
|
||||
columnNumber: 64
|
||||
lineNumber: 163,
|
||||
columnNumber: 11
|
||||
}, this))
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 125,
|
||||
columnNumber: 9
|
||||
lineNumber: 161,
|
||||
columnNumber: 7
|
||||
}, this),
|
||||
/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)("button", {
|
||||
id: "new-level",
|
||||
|
@ -488,29 +486,29 @@ function App() {
|
|||
{
|
||||
name,
|
||||
size: 8,
|
||||
bricks: '________________________________________________________________',
|
||||
bricks: "________________________________________________________________",
|
||||
svg: null,
|
||||
color: ''
|
||||
color: ""
|
||||
}
|
||||
]);
|
||||
},
|
||||
children: "new"
|
||||
}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 141,
|
||||
columnNumber: 9
|
||||
lineNumber: 177,
|
||||
columnNumber: 7
|
||||
}, this)
|
||||
]
|
||||
}, void 0, true, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 48,
|
||||
columnNumber: 12
|
||||
lineNumber: 49,
|
||||
columnNumber: 5
|
||||
}, this);
|
||||
}
|
||||
const root = (0, _client.createRoot)(document.getElementById('app'));
|
||||
const root = (0, _client.createRoot)(document.getElementById("app"));
|
||||
root.render(/*#__PURE__*/ (0, _jsxDevRuntime.jsxDEV)(App, {}, void 0, false, {
|
||||
fileName: "src/levels_editor.tsx",
|
||||
lineNumber: 160,
|
||||
lineNumber: 203,
|
||||
columnNumber: 13
|
||||
}, undefined));
|
||||
|
||||
|
@ -16268,22 +16266,21 @@ function resizeLevel(level, sizeDelta) {
|
|||
for(let x = 0; x < newSize; x++)for(let y = 0; y < newSize; y++)newBricks[y * newSize + x] = brickAt(level, x, y);
|
||||
return {
|
||||
size: newSize,
|
||||
bricks: newBricks.join('')
|
||||
bricks: newBricks.join("")
|
||||
};
|
||||
}
|
||||
function brickAt(level, x, y) {
|
||||
return x >= 0 && x < level.size && y >= 0 && y < level.size && level.bricks.split('')[y * level.size + x] || '_';
|
||||
return x >= 0 && x < level.size && y >= 0 && y < level.size && level.bricks.split("")[y * level.size + x] || "_";
|
||||
}
|
||||
function moveLevel(level, dx, dy) {
|
||||
const { size } = level;
|
||||
const newBricks = new Array(size * size).fill('_');
|
||||
const newBricks = new Array(size * size).fill("_");
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++)newBricks[y * size + x] = brickAt(level, x - dx, y - dy);
|
||||
return {
|
||||
bricks: newBricks.join('')
|
||||
bricks: newBricks.join("")
|
||||
};
|
||||
}
|
||||
function setBrick(level, index, colorCode) {
|
||||
console.log('setBrick', level.name, index, colorCode);
|
||||
const { size } = level;
|
||||
const newBricks = [];
|
||||
for(let x = 0; x < size; x++)for(let y = 0; y < size; y++){
|
||||
|
@ -16291,7 +16288,7 @@ function setBrick(level, index, colorCode) {
|
|||
newBricks[brickIndex] = brickIndex === index && colorCode || brickAt(level, x, y);
|
||||
}
|
||||
return {
|
||||
bricks: newBricks.join('')
|
||||
bricks: newBricks.join("")
|
||||
};
|
||||
}
|
||||
|
||||
|
|
2
dist/levels_editor.ef3c2e1a.js.map
vendored
8
dist/levels_editor.html
vendored
|
@ -1,16 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head><script src="/index.c0fd3053.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>Level editor</title>
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎨</text></svg>">
|
||||
<link rel="stylesheet" href="/levels_editor.de5e7f9b.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app"></div>
|
||||
|
||||
|
||||
<script src="/levels_editor.ef3c2e1a.js" defer=""></script>
|
||||
</body></html>
|
||||
</body>
|
||||
</html>
|
||||
|
|
1
dist/manifest.webmanifest
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"short_name":"B71","name":"Breakout 71","icons":[{"src":"/icon-512.e79a8a4c.png","sizes":"512x512","type":"image/png"},{"src":"/icon-128.59c1f720.png","sizes":"128x128","type":"image/png"},{"src":"/icon-64.2922f911.png","sizes":"64x64","type":"image/png"}],"start_url":"/index.html?isPWA=true","display":"fullscreen","theme_color":"#5DA3EA","background_color":"#ffffff"}
|
4
dist/sw-b71.js
vendored
|
@ -1,5 +1,5 @@
|
|||
// The version of the cache.
|
||||
const VERSION = '29032991';
|
||||
const VERSION = "29033834";
|
||||
// The name of the cache
|
||||
const CACHE_NAME = `breakout-71-${VERSION}`;
|
||||
// The static resources that the app needs to function.
|
||||
|
@ -24,7 +24,7 @@ self.addEventListener("activate", (event)=>{
|
|||
})());
|
||||
});
|
||||
self.addEventListener("fetch", (event)=>{
|
||||
if (event.request.mode === "navigate" && event.request.url.endsWith('/index.html?isPWA=true')) {
|
||||
if (event.request.mode === "navigate" && event.request.url.endsWith("/index.html?isPWA=true")) {
|
||||
event.respondWith(caches.match("/"));
|
||||
return;
|
||||
}
|
||||
|
|
2
dist/sw-b71.js.map
vendored
|
@ -1 +1 @@
|
|||
{"mappings":"AAAA,4BAA4B;AAC5B,MAAO,UAAU;AAEjB,wBAAwB;AACxB,MAAM,aAAa,CAAC,YAAY,EAAE,SAAS;AAE3C,uDAAuD;AACvD,MAAM,uBAAuB;IAC3B;CACD;AAED,yCAAyC;AACzC,KAAK,gBAAgB,CAAC,WAAW,CAAC;IAChC,MAAM,SAAS,CACb,AAAC,CAAA;QACC,MAAM,QAAQ,MAAM,OAAO,IAAI,CAAC;QAChC,MAAM,MAAM,CAAC;IACf,CAAA;AAEJ;AAEA,gCAAgC;AAChC,KAAK,gBAAgB,CAAC,YAAY,CAAC;IACjC,MAAM,SAAS,CACb,AAAC,CAAA;QACC,MAAM,QAAQ,MAAM,OAAO,IAAI;QAC/B,MAAM,QAAQ,GAAG,CACf,MAAM,GAAG,CAAC,CAAC;YACT,IAAI,SAAS,YACX,OAAO,OAAO,MAAM,CAAC;QAEzB;QAEF,MAAM,QAAQ,KAAK;IACrB,CAAA;AAEJ;AAEA,KAAK,gBAAgB,CAAC,SAAS,CAAC;IAC9B,IAAI,MAAM,OAAO,CAAC,IAAI,KAAK,cAAc,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,2BAA2B;QAC7F,MAAM,WAAW,CAAC,OAAO,KAAK,CAAC;QAC/B;IACF;AACF","sources":["src/sw-b71.js"],"sourcesContent":["// The version of the cache.\nconst VERSION = '29032991'\n\n// The name of the cache\nconst CACHE_NAME = `breakout-71-${VERSION}`;\n\n// The static resources that the app needs to function.\nconst APP_STATIC_RESOURCES = [\n \"/\"\n];\n\n// On install, cache the static resources\nself.addEventListener(\"install\", (event) => {\n event.waitUntil(\n (async () => {\n const cache = await caches.open(CACHE_NAME);\n cache.addAll(APP_STATIC_RESOURCES);\n })(),\n );\n});\n\n// delete old caches on activate\nself.addEventListener(\"activate\", (event) => {\n event.waitUntil(\n (async () => {\n const names = await caches.keys();\n await Promise.all(\n names.map((name) => {\n if (name !== CACHE_NAME) {\n return caches.delete(name);\n }\n }),\n );\n await clients.claim();\n })(),\n );\n});\n\nself.addEventListener(\"fetch\", (event) => {\n if (event.request.mode === \"navigate\" && event.request.url.endsWith('/index.html?isPWA=true')) {\n event.respondWith(caches.match(\"/\"));\n return;\n }\n});\n"],"names":[],"version":3,"file":"sw-b71.js.map","sourceRoot":"/__parcel_source_root/"}
|
||||
{"mappings":"AAAA,4BAA4B;AAC5B,MAAM,UAAU;AAEhB,wBAAwB;AACxB,MAAM,aAAa,CAAC,YAAY,EAAE,SAAS;AAE3C,uDAAuD;AACvD,MAAM,uBAAuB;IAAC;CAAI;AAElC,yCAAyC;AACzC,KAAK,gBAAgB,CAAC,WAAW,CAAC;IAChC,MAAM,SAAS,CACb,AAAC,CAAA;QACC,MAAM,QAAQ,MAAM,OAAO,IAAI,CAAC;QAChC,MAAM,MAAM,CAAC;IACf,CAAA;AAEJ;AAEA,gCAAgC;AAChC,KAAK,gBAAgB,CAAC,YAAY,CAAC;IACjC,MAAM,SAAS,CACb,AAAC,CAAA;QACC,MAAM,QAAQ,MAAM,OAAO,IAAI;QAC/B,MAAM,QAAQ,GAAG,CACf,MAAM,GAAG,CAAC,CAAC;YACT,IAAI,SAAS,YACX,OAAO,OAAO,MAAM,CAAC;QAEzB;QAEF,MAAM,QAAQ,KAAK;IACrB,CAAA;AAEJ;AAEA,KAAK,gBAAgB,CAAC,SAAS,CAAC;IAC9B,IACE,MAAM,OAAO,CAAC,IAAI,KAAK,cACvB,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,2BAC3B;QACA,MAAM,WAAW,CAAC,OAAO,KAAK,CAAC;QAC/B;IACF;AACF","sources":["src/sw-b71.js"],"sourcesContent":["// The version of the cache.\nconst VERSION = \"29033834\";\n\n// The name of the cache\nconst CACHE_NAME = `breakout-71-${VERSION}`;\n\n// The static resources that the app needs to function.\nconst APP_STATIC_RESOURCES = [\"/\"];\n\n// On install, cache the static resources\nself.addEventListener(\"install\", (event) => {\n event.waitUntil(\n (async () => {\n const cache = await caches.open(CACHE_NAME);\n cache.addAll(APP_STATIC_RESOURCES);\n })(),\n );\n});\n\n// delete old caches on activate\nself.addEventListener(\"activate\", (event) => {\n event.waitUntil(\n (async () => {\n const names = await caches.keys();\n await Promise.all(\n names.map((name) => {\n if (name !== CACHE_NAME) {\n return caches.delete(name);\n }\n }),\n );\n await clients.claim();\n })(),\n );\n});\n\nself.addEventListener(\"fetch\", (event) => {\n if (\n event.request.mode === \"navigate\" &&\n event.request.url.endsWith(\"/index.html?isPWA=true\")\n ) {\n event.respondWith(caches.match(\"/\"));\n return;\n }\n});\n"],"names":[],"version":3,"file":"sw-b71.js.map","sourceRoot":"/__parcel_source_root/"}
|
|
@ -17,5 +17,5 @@ app.post('/src/levels.json', (req, res) => {
|
|||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening on port http://localhost:${port}`)
|
||||
console.info(`Editor BE listening on port http://localhost:${port}`)
|
||||
})
|
||||
|
|
19
package-lock.json
generated
|
@ -26,6 +26,7 @@
|
|||
"svgo": "^3.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@parcel/packager-raw-url": "^2.13.3",
|
||||
"@parcel/transformer-webmanifest": "^2.13.3",
|
||||
"@types/jest": "^29.5.14",
|
||||
"jest": "^29.7.0",
|
||||
|
@ -1698,6 +1699,24 @@
|
|||
"url": "https://opencollective.com/parcel"
|
||||
}
|
||||
},
|
||||
"node_modules/@parcel/packager-raw-url": {
|
||||
"version": "2.13.3",
|
||||
"resolved": "https://registry.npmjs.org/@parcel/packager-raw-url/-/packager-raw-url-2.13.3.tgz",
|
||||
"integrity": "sha512-Dc8WeVagLGEUzVP4FqJBljXN59XSkvLoZaHeysvN9P33eznocrhIvc9T/OAQjOmsCj18X8jwxm0dIE7LNJbVCA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@parcel/plugin": "2.13.3",
|
||||
"@parcel/utils": "2.13.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16.0.0",
|
||||
"parcel": "^2.13.3"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/parcel"
|
||||
}
|
||||
},
|
||||
"node_modules/@parcel/packager-svg": {
|
||||
"version": "2.13.3",
|
||||
"resolved": "https://registry.npmjs.org/@parcel/packager-svg/-/packager-svg-2.13.3.tgz",
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
"svgo": "^3.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@parcel/packager-raw-url": "^2.13.3",
|
||||
"@parcel/transformer-webmanifest": "^2.13.3",
|
||||
"@types/jest": "^29.5.14",
|
||||
"jest": "^29.7.0",
|
||||
|
|
17
src/combo.ts
|
@ -5,14 +5,20 @@ export function baseCombo(gameState: GameState) {
|
|||
return 1 + gameState.perks.base_combo * 3 + gameState.perks.smaller_puck * 5;
|
||||
}
|
||||
|
||||
export function resetCombo(gameState: GameState, x: number | undefined, y: number | undefined) {
|
||||
export function resetCombo(
|
||||
gameState: GameState,
|
||||
x: number | undefined,
|
||||
y: number | undefined,
|
||||
) {
|
||||
const prev = gameState.combo;
|
||||
gameState.combo = baseCombo(gameState);
|
||||
if (!gameState.levelTime) {
|
||||
gameState.combo += gameState.perks.hot_start * 15;
|
||||
}
|
||||
if (prev > gameState.combo && gameState.perks.soft_reset) {
|
||||
gameState.combo += Math.floor((prev - gameState.combo) / (1 + gameState.perks.soft_reset));
|
||||
gameState.combo += Math.floor(
|
||||
(prev - gameState.combo) / (1 + gameState.perks.soft_reset),
|
||||
);
|
||||
}
|
||||
const lost = Math.max(0, prev - gameState.combo);
|
||||
if (lost) {
|
||||
|
@ -35,7 +41,12 @@ export function resetCombo(gameState: GameState, x: number | undefined, y: numbe
|
|||
return lost;
|
||||
}
|
||||
|
||||
export function decreaseCombo(gameState: GameState, by: number, x: number, y: number) {
|
||||
export function decreaseCombo(
|
||||
gameState: GameState,
|
||||
by: number,
|
||||
x: number,
|
||||
y: number,
|
||||
) {
|
||||
const prev = gameState.combo;
|
||||
gameState.combo = Math.max(baseCombo(gameState), gameState.combo - by);
|
||||
const lost = Math.max(0, prev - gameState.combo);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
* {
|
||||
font-family: Courier New,
|
||||
font-family:
|
||||
Courier New,
|
||||
Courier,
|
||||
Lucida Sans Typewriter,
|
||||
Lucida Typewriter,
|
||||
|
@ -50,7 +51,6 @@ body {
|
|||
background: rgba(0, 0, 0, 0.3);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#score {
|
||||
|
@ -66,7 +66,6 @@ body {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
.popup {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
|
@ -199,7 +198,6 @@ body {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*Unlocks progress bar*/
|
||||
.progress {
|
||||
display: block;
|
||||
|
@ -239,7 +237,6 @@ body {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#level-recording-container {
|
||||
max-width: 400px;
|
||||
text-align: center;
|
||||
|
@ -270,7 +267,6 @@ body {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
.histogram {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
|
@ -311,7 +307,6 @@ body {
|
|||
left: 50%;
|
||||
transform: translate(-50%, 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
& > span:not(:hover):not(.active) > span > span {
|
||||
|
|
432
src/game.ts
|
@ -17,7 +17,7 @@ import {putBallsAtPuck, resetBalls} from "./resetBalls";
|
|||
import { makeEmptyPerksMap, sumOfKeys } from "./game_utils";
|
||||
import { baseCombo, decreaseCombo, resetCombo } from "./combo";
|
||||
|
||||
import './sw_loader'
|
||||
import "./sw_loader";
|
||||
|
||||
const gameCanvas = document.getElementById("game") as HTMLCanvasElement;
|
||||
const ctx = gameCanvas.getContext("2d", {
|
||||
|
@ -31,7 +31,6 @@ bombSVG.src =
|
|||
<path d="m6.1528 26.516c-2.6992-3.4942-2.9332-8.281-.58305-11.981a10.454 10.454 0 017.3701-4.7582c1.962-.27726 4.1646.05953 5.8835.90027l.45013.22017.89782-.87417c.83748-.81464.91169-.87499 1.0992-.90271.40528-.058713.58876.03425 1.1971.6116l.55451.52679 1.0821-1.0821c1.1963-1.1963 1.383-1.3357 2.1039-1.5877.57898-.20223 1.5681-.19816 2.1691.00897 1.4613.50314 2.3673 1.7622 2.3567 3.2773-.0058.95654-.24464 1.5795-.90924 2.3746-.40936.48928-.55533.81057-.57898 1.2737-.02039.41018.1109.77714.42322 1.1792.30172.38816.3694.61323.2797.93044-.12803.45666-.56674.71598-1.0242.60507-.601-.14597-1.3031-1.3088-1.3969-2.3126-.09459-1.0161.19245-1.8682.92392-2.7432.42567-.50885.5643-.82851.5643-1.3031 0-.50151-.14026-.83177-.51211-1.2028-.50966-.50966-1.0968-.64829-1.781-.41996l-.37348.12477-2.1006 2.1006.52597.55696c.45421.48194.5325.58876.57898.78855.09622.41588.07502.45014-.88396 1.4548l-.87173.9125.26339.57979a10.193 10.193 0 01.9231 4.1001c.03996 2.046-.41996 3.8082-1.4442 5.537-.55044.928-1.0185 1.5013-1.8968 2.3241-.83503.78284-1.5526 1.2827-2.4904 1.7361-3.4266 1.657-7.4721 1.3422-10.549-.82035-.73473-.51782-1.7312-1.4621-2.2515-2.1357zm21.869-4.5584c-.0579-.19734-.05871-2.2662 0-2.4545.11906-.39142.57898-.63361 1.0038-.53005.23812.05708.54147.32455.6116.5382.06279.19163.06769 2.1805.0065 2.3811-.12558.40773-.61649.67602-1.0462.57164-.234-.05708-.51615-.30498-.57568-.50722m3.0417-2.6013c-.12313-.6222.37837-1.1049 1.0479-1.0079.18348.0261.25279.08399 1.0071.83911.75838.75838.81301.82362.84074 1.0112.10193.68499-.40365 1.1938-1.034 1.0405-.1949-.0473-.28786-.12558-1.0144-.85216-.7649-.76409-.80241-.81057-.84645-1.0316m.61323-3.0629a.85623.85623 0 01.59284-.99975c.28949-.09214 2.1814-.08318 2.3917.01141.38734.17369.6279.61078.53984.98181-.06035.25606-.35391.57327-.60181.64992-.25279.07747-2.2278.053-2.4097-.03017-.26013-.11906-.46318-.36125-.51374-.61323" fill="#fff" opacity="0.3"/>
|
||||
</svg>`);
|
||||
|
||||
|
||||
export function play() {
|
||||
if (gameState.running) return;
|
||||
gameState.running = true;
|
||||
|
@ -72,7 +71,6 @@ export function pause(playerAskedForPause: boolean) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
const background = document.createElement("img");
|
||||
const backgroundCanvas = document.createElement("canvas");
|
||||
background.addEventListener("load", () => {
|
||||
|
@ -91,11 +89,17 @@ export const fitSize = () => {
|
|||
backgroundCanvas.width = width;
|
||||
backgroundCanvas.height = height;
|
||||
|
||||
gameState.gameZoneHeight = isSettingOn("mobile-mode") ? (height * 80) / 100 : height;
|
||||
const baseWidth = Math.round(Math.min(gameState.canvasWidth, gameState.gameZoneHeight * 0.73));
|
||||
gameState.gameZoneHeight = isSettingOn("mobile-mode")
|
||||
? (height * 80) / 100
|
||||
: height;
|
||||
const baseWidth = Math.round(
|
||||
Math.min(gameState.canvasWidth, gameState.gameZoneHeight * 0.73),
|
||||
);
|
||||
gameState.brickWidth = Math.floor(baseWidth / gameState.gridSize / 2) * 2;
|
||||
gameState.gameZoneWidth = gameState.brickWidth * gameState.gridSize;
|
||||
gameState.offsetX = Math.floor((gameState.canvasWidth - gameState.gameZoneWidth) / 2);
|
||||
gameState.offsetX = Math.floor(
|
||||
(gameState.canvasWidth - gameState.gameZoneWidth) / 2,
|
||||
);
|
||||
gameState.offsetXRoundedDown = gameState.offsetX;
|
||||
if (gameState.offsetX < gameState.ballSize) gameState.offsetXRoundedDown = 0;
|
||||
gameState.gameZoneWidthRoundedUp = width - 2 * gameState.offsetXRoundedDown;
|
||||
|
@ -118,7 +122,8 @@ window.addEventListener("fullscreenchange", fitSize);
|
|||
setInterval(() => {
|
||||
// Sometimes, the page changes size without triggering the event (when switching to fullscreen, closing debug panel...)
|
||||
const { width, height } = gameCanvas.getBoundingClientRect();
|
||||
if (width !== gameState.canvasWidth || height !== gameState.canvasHeight) fitSize();
|
||||
if (width !== gameState.canvasWidth || height !== gameState.canvasHeight)
|
||||
fitSize();
|
||||
}, 1000);
|
||||
|
||||
export function recomputeTargetBaseSpeed() {
|
||||
|
@ -133,7 +138,10 @@ export function recomputeTargetBaseSpeed() {
|
|||
}
|
||||
|
||||
export function brickCenterX(index: number) {
|
||||
return gameState.offsetX + ((index % gameState.gridSize) + 0.5) * gameState.brickWidth;
|
||||
return (
|
||||
gameState.offsetX +
|
||||
((index % gameState.gridSize) + 0.5) * gameState.brickWidth
|
||||
);
|
||||
}
|
||||
|
||||
export function brickCenterY(index: number) {
|
||||
|
@ -141,7 +149,13 @@ export function brickCenterY(index: number) {
|
|||
}
|
||||
|
||||
export function getRowColIndex(row: number, col: number) {
|
||||
if (row < 0 || col < 0 || row >= gameState.gridSize || col >= gameState.gridSize) return -1;
|
||||
if (
|
||||
row < 0 ||
|
||||
col < 0 ||
|
||||
row >= gameState.gridSize ||
|
||||
col >= gameState.gridSize
|
||||
)
|
||||
return -1;
|
||||
return row * gameState.gridSize + col;
|
||||
}
|
||||
|
||||
|
@ -174,7 +188,6 @@ export function spawnExplosion(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
export function addToScore(coin: Coin) {
|
||||
coin.destroyed = true;
|
||||
gameState.score += coin.points;
|
||||
|
@ -207,17 +220,19 @@ export function addToScore(coin: Coin) {
|
|||
gameState.runStatistics.score += coin.points;
|
||||
}
|
||||
|
||||
|
||||
export function pickedUpgradesHTMl() {
|
||||
let list = "";
|
||||
for (let u of upgrades) {
|
||||
for (let i = 0; i < gameState.perks[u.id]; i++) list += icons["icon:" + u.id] + " ";
|
||||
for (let i = 0; i < gameState.perks[u.id]; i++)
|
||||
list += icons["icon:" + u.id] + " ";
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
async function openUpgradesPicker() {
|
||||
const catchRate = (gameState.score - gameState.levelStartScore) / (gameState.levelSpawnedCoins || 1);
|
||||
const catchRate =
|
||||
(gameState.score - gameState.levelStartScore) /
|
||||
(gameState.levelSpawnedCoins || 1);
|
||||
|
||||
let repeats = 1;
|
||||
let choices = 3;
|
||||
|
@ -252,7 +267,9 @@ async function openUpgradesPicker() {
|
|||
|
||||
while (repeats--) {
|
||||
const actions = pickRandomUpgrades(
|
||||
choices + gameState.perks.one_more_choice - gameState.perks.instant_upgrade,
|
||||
choices +
|
||||
gameState.perks.one_more_choice -
|
||||
gameState.perks.instant_upgrade,
|
||||
);
|
||||
if (!actions.length) break;
|
||||
let textAfterButtons = `
|
||||
|
@ -319,10 +336,11 @@ export function setLevel(l: number) {
|
|||
}
|
||||
|
||||
export function currentLevelInfo() {
|
||||
return gameState.runLevels[gameState.currentLevel % gameState.runLevels.length];
|
||||
return gameState.runLevels[
|
||||
gameState.currentLevel % gameState.runLevels.length
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
export function getPossibleUpgrades(gameState: GameState) {
|
||||
return upgrades
|
||||
.filter((u) => gameState.totalScoreAtRunStart >= u.threshold)
|
||||
|
@ -359,7 +377,10 @@ export function dontOfferTooSoon(gameState: GameState, id: PerkId) {
|
|||
|
||||
export function pickRandomUpgrades(count: number) {
|
||||
let list = getPossibleUpgrades(gameState)
|
||||
.map((u) => ({...u, score: Math.random() + (gameState.lastOffered[u.id] || 0)}))
|
||||
.map((u) => ({
|
||||
...u,
|
||||
score: Math.random() + (gameState.lastOffered[u.id] || 0),
|
||||
}))
|
||||
.sort((a, b) => a.score - b.score)
|
||||
.filter((u) => gameState.perks[u.id] < u.max)
|
||||
.slice(0, count)
|
||||
|
@ -370,24 +391,37 @@ export function pickRandomUpgrades(count: number) {
|
|||
});
|
||||
|
||||
return list.map((u) => ({
|
||||
text: u.name + (gameState.perks[u.id] ? " lvl " + (gameState.perks[u.id] + 1) : ""),
|
||||
text:
|
||||
u.name +
|
||||
(gameState.perks[u.id] ? " lvl " + (gameState.perks[u.id] + 1) : ""),
|
||||
icon: icons["icon:" + u.id],
|
||||
value: u.id as PerkId,
|
||||
help: u.help(gameState.perks[u.id] + 1),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
export function setMousePos(x: number) {
|
||||
gameState.needsRender = true;
|
||||
gameState.puckPosition = x;
|
||||
|
||||
// We have borders visible, enforce them
|
||||
if (gameState.puckPosition < gameState.offsetXRoundedDown + gameState.puckWidth / 2) {
|
||||
gameState.puckPosition = gameState.offsetXRoundedDown + gameState.puckWidth / 2;
|
||||
if (
|
||||
gameState.puckPosition <
|
||||
gameState.offsetXRoundedDown + gameState.puckWidth / 2
|
||||
) {
|
||||
gameState.puckPosition =
|
||||
gameState.offsetXRoundedDown + gameState.puckWidth / 2;
|
||||
}
|
||||
if (gameState.puckPosition > gameState.offsetXRoundedDown + gameState.gameZoneWidthRoundedUp - gameState.puckWidth / 2) {
|
||||
gameState.puckPosition = gameState.offsetXRoundedDown + gameState.gameZoneWidthRoundedUp - gameState.puckWidth / 2;
|
||||
if (
|
||||
gameState.puckPosition >
|
||||
gameState.offsetXRoundedDown +
|
||||
gameState.gameZoneWidthRoundedUp -
|
||||
gameState.puckWidth / 2
|
||||
) {
|
||||
gameState.puckPosition =
|
||||
gameState.offsetXRoundedDown +
|
||||
gameState.gameZoneWidthRoundedUp -
|
||||
gameState.puckWidth / 2;
|
||||
}
|
||||
if (!gameState.running && !gameState.levelTime) {
|
||||
putBallsAtPuck(gameState);
|
||||
|
@ -434,7 +468,6 @@ gameCanvas.addEventListener("touchmove", (e) => {
|
|||
setMousePos(e.touches[0].pageX);
|
||||
});
|
||||
|
||||
|
||||
export function brickIndex(x: number, y: number) {
|
||||
return getRowColIndex(
|
||||
Math.floor(y / gameState.brickWidth),
|
||||
|
@ -461,13 +494,22 @@ export function shouldPierceByColor(
|
|||
chit: number | undefined,
|
||||
) {
|
||||
if (!gameState.perks.pierce_color) return false;
|
||||
if (typeof vhit !== "undefined" && gameState.bricks[vhit] !== gameState.ballsColor) {
|
||||
if (
|
||||
typeof vhit !== "undefined" &&
|
||||
gameState.bricks[vhit] !== gameState.ballsColor
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (typeof hhit !== "undefined" && gameState.bricks[hhit] !== gameState.ballsColor) {
|
||||
if (
|
||||
typeof hhit !== "undefined" &&
|
||||
gameState.bricks[hhit] !== gameState.ballsColor
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (typeof chit !== "undefined" && gameState.bricks[chit] !== gameState.ballsColor) {
|
||||
if (
|
||||
typeof chit !== "undefined" &&
|
||||
gameState.bricks[chit] !== gameState.ballsColor
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -510,7 +552,11 @@ export function coinBrickHitCheck(coin: Coin) {
|
|||
return vhit ?? hhit ?? chit;
|
||||
}
|
||||
|
||||
export function bordersHitCheck(coin: Coin | Ball, radius: number, delta: number) {
|
||||
export function bordersHitCheck(
|
||||
coin: Coin | Ball,
|
||||
radius: number,
|
||||
delta: number,
|
||||
) {
|
||||
if (coin.destroyed) return;
|
||||
coin.previousX = coin.x;
|
||||
coin.previousY = coin.y;
|
||||
|
@ -525,7 +571,9 @@ export function bordersHitCheck(coin: Coin | Ball, radius: number, delta: number
|
|||
|
||||
if (gameState.perks.wind) {
|
||||
coin.vx +=
|
||||
((gameState.puckPosition - (gameState.offsetX + gameState.gameZoneWidth / 2)) / gameState.gameZoneWidth) *
|
||||
((gameState.puckPosition -
|
||||
(gameState.offsetX + gameState.gameZoneWidth / 2)) /
|
||||
gameState.gameZoneWidth) *
|
||||
gameState.perks.wind *
|
||||
0.5;
|
||||
}
|
||||
|
@ -535,7 +583,9 @@ export function bordersHitCheck(coin: Coin | Ball, radius: number, delta: number
|
|||
|
||||
if (coin.x < gameState.offsetXRoundedDown + radius) {
|
||||
coin.x =
|
||||
gameState.offsetXRoundedDown + radius + (gameState.offsetXRoundedDown + radius - coin.x);
|
||||
gameState.offsetXRoundedDown +
|
||||
radius +
|
||||
(gameState.offsetXRoundedDown + radius - coin.x);
|
||||
coin.vx *= -1;
|
||||
hhit = 1;
|
||||
}
|
||||
|
@ -549,7 +599,8 @@ export function bordersHitCheck(coin: Coin | Ball, radius: number, delta: number
|
|||
gameState.canvasWidth -
|
||||
gameState.offsetXRoundedDown -
|
||||
radius -
|
||||
(coin.x - (gameState.canvasWidth - gameState.offsetXRoundedDown - radius));
|
||||
(coin.x -
|
||||
(gameState.canvasWidth - gameState.offsetXRoundedDown - radius));
|
||||
coin.vx *= -1;
|
||||
hhit = 1;
|
||||
}
|
||||
|
@ -557,13 +608,13 @@ export function bordersHitCheck(coin: Coin | Ball, radius: number, delta: number
|
|||
return hhit + vhit * 2;
|
||||
}
|
||||
|
||||
|
||||
export function tick() {
|
||||
recomputeTargetBaseSpeed();
|
||||
const currentTick = performance.now();
|
||||
|
||||
gameState.puckWidth =
|
||||
(gameState.gameZoneWidth / 12) * (3 - gameState.perks.smaller_puck + gameState.perks.bigger_puck);
|
||||
(gameState.gameZoneWidth / 12) *
|
||||
(3 - gameState.perks.smaller_puck + gameState.perks.bigger_puck);
|
||||
|
||||
if (gameState.keyboardPuckSpeed) {
|
||||
setMousePos(gameState.puckPosition + gameState.keyboardPuckSpeed);
|
||||
|
@ -572,7 +623,10 @@ export function tick() {
|
|||
if (gameState.running) {
|
||||
gameState.levelTime += currentTick - gameState.lastTick;
|
||||
gameState.runStatistics.runTime += currentTick - gameState.lastTick;
|
||||
gameState.runStatistics.max_combo = Math.max(gameState.runStatistics.max_combo, gameState.combo);
|
||||
gameState.runStatistics.max_combo = Math.max(
|
||||
gameState.runStatistics.max_combo,
|
||||
gameState.combo,
|
||||
);
|
||||
|
||||
// How many times to compute
|
||||
let delta = Math.min(4, (currentTick - gameState.lastTick) / (1000 / 60));
|
||||
|
@ -581,14 +635,27 @@ export function tick() {
|
|||
gameState.coins = gameState.coins.filter((coin) => !coin.destroyed);
|
||||
gameState.balls = gameState.balls.filter((ball) => !ball.destroyed);
|
||||
|
||||
const remainingBricks = gameState.bricks.filter((b) => b && b !== "black").length;
|
||||
const remainingBricks = gameState.bricks.filter(
|
||||
(b) => b && b !== "black",
|
||||
).length;
|
||||
|
||||
if (gameState.levelTime > gameState.lastTickDown + 1000 && gameState.perks.hot_start) {
|
||||
if (
|
||||
gameState.levelTime > gameState.lastTickDown + 1000 &&
|
||||
gameState.perks.hot_start
|
||||
) {
|
||||
gameState.lastTickDown = gameState.levelTime;
|
||||
decreaseCombo(gameState, gameState.perks.hot_start, gameState.puckPosition, gameState.gameZoneHeight - 2 * gameState.puckHeight);
|
||||
decreaseCombo(
|
||||
gameState,
|
||||
gameState.perks.hot_start,
|
||||
gameState.puckPosition,
|
||||
gameState.gameZoneHeight - 2 * gameState.puckHeight,
|
||||
);
|
||||
}
|
||||
|
||||
if (remainingBricks <= gameState.perks.skip_last && !gameState.autoCleanUses) {
|
||||
if (
|
||||
remainingBricks <= gameState.perks.skip_last &&
|
||||
!gameState.autoCleanUses
|
||||
) {
|
||||
gameState.bricks.forEach((type, index) => {
|
||||
if (type) {
|
||||
explodeBrick(index, gameState.balls[0], true);
|
||||
|
@ -627,10 +694,14 @@ export function tick() {
|
|||
|
||||
coin.vy *= ratio;
|
||||
coin.vx *= ratio;
|
||||
if (coin.vx > 7 * gameState.baseSpeed) coin.vx = 7 * gameState.baseSpeed;
|
||||
if (coin.vx < -7 * gameState.baseSpeed) coin.vx = -7 * gameState.baseSpeed;
|
||||
if (coin.vy > 7 * gameState.baseSpeed) coin.vy = 7 * gameState.baseSpeed;
|
||||
if (coin.vy < -7 * gameState.baseSpeed) coin.vy = -7 * gameState.baseSpeed;
|
||||
if (coin.vx > 7 * gameState.baseSpeed)
|
||||
coin.vx = 7 * gameState.baseSpeed;
|
||||
if (coin.vx < -7 * gameState.baseSpeed)
|
||||
coin.vx = -7 * gameState.baseSpeed;
|
||||
if (coin.vy > 7 * gameState.baseSpeed)
|
||||
coin.vy = 7 * gameState.baseSpeed;
|
||||
if (coin.vy < -7 * gameState.baseSpeed)
|
||||
coin.vy = -7 * gameState.baseSpeed;
|
||||
coin.a += coin.sa;
|
||||
|
||||
// Gravity
|
||||
|
@ -640,7 +711,8 @@ export function tick() {
|
|||
const hitBorder = bordersHitCheck(coin, coin.size / 2, delta);
|
||||
|
||||
if (
|
||||
coin.y > gameState.gameZoneHeight - coinRadius - gameState.puckHeight &&
|
||||
coin.y >
|
||||
gameState.gameZoneHeight - coinRadius - gameState.puckHeight &&
|
||||
coin.y < gameState.gameZoneHeight + gameState.puckHeight + coin.vy &&
|
||||
Math.abs(coin.x - gameState.puckPosition) <
|
||||
coinRadius +
|
||||
|
@ -666,7 +738,7 @@ export function tick() {
|
|||
) {
|
||||
gameState.bricks[hitBrick] = coin.color;
|
||||
coin.coloredABrick = true;
|
||||
sounds.colorChange(coin.x, 0.3)
|
||||
sounds.colorChange(coin.x, 0.3);
|
||||
}
|
||||
}
|
||||
if (typeof hitBrick !== "undefined" || hitBorder) {
|
||||
|
@ -688,7 +760,9 @@ export function tick() {
|
|||
|
||||
if (gameState.perks.wind) {
|
||||
const windD =
|
||||
((gameState.puckPosition - (gameState.offsetX + gameState.gameZoneWidth / 2)) / gameState.gameZoneWidth) *
|
||||
((gameState.puckPosition -
|
||||
(gameState.offsetX + gameState.gameZoneWidth / 2)) /
|
||||
gameState.gameZoneWidth) *
|
||||
2 *
|
||||
gameState.perks.wind;
|
||||
for (let i = 0; i < gameState.perks.wind; i++) {
|
||||
|
@ -700,7 +774,9 @@ export function tick() {
|
|||
time: gameState.levelTime,
|
||||
size: gameState.coinSize / 2,
|
||||
color: rainbowColor(),
|
||||
x: gameState.offsetXRoundedDown + Math.random() * gameState.gameZoneWidthRoundedUp,
|
||||
x:
|
||||
gameState.offsetXRoundedDown +
|
||||
Math.random() * gameState.gameZoneWidthRoundedUp,
|
||||
y: Math.random() * gameState.gameZoneHeight,
|
||||
vx: windD * 8,
|
||||
vy: 0,
|
||||
|
@ -740,7 +816,9 @@ export function tick() {
|
|||
baseParticle &&
|
||||
gameState.flashes.push({
|
||||
...baseParticle,
|
||||
x: gameState.offsetXRoundedDown + Math.random() * gameState.gameZoneWidthRoundedUp,
|
||||
x:
|
||||
gameState.offsetXRoundedDown +
|
||||
Math.random() * gameState.gameZoneWidthRoundedUp,
|
||||
y: 0,
|
||||
vx: (Math.random() - 0.5) * 10,
|
||||
vy: 5,
|
||||
|
@ -771,9 +849,14 @@ export function tick() {
|
|||
let x = gameState.puckPosition,
|
||||
attemps = 0;
|
||||
do {
|
||||
x = gameState.offsetXRoundedDown + gameState.gameZoneWidthRoundedUp * Math.random();
|
||||
x =
|
||||
gameState.offsetXRoundedDown +
|
||||
gameState.gameZoneWidthRoundedUp * Math.random();
|
||||
attemps++;
|
||||
} while (Math.abs(x - gameState.puckPosition) < gameState.puckWidth / 2 && attemps < 10);
|
||||
} while (
|
||||
Math.abs(x - gameState.puckPosition) < gameState.puckWidth / 2 &&
|
||||
attemps < 10
|
||||
);
|
||||
baseParticle &&
|
||||
gameState.flashes.push({
|
||||
...baseParticle,
|
||||
|
@ -820,10 +903,16 @@ export function ballTick(ball: Ball, delta: number) {
|
|||
gameState.perks.ball_attract_ball;
|
||||
if (isTelekinesisActive(ball)) {
|
||||
speedLimitDampener += 3;
|
||||
ball.vx += ((gameState.puckPosition - ball.x) / 1000) * delta * gameState.perks.telekinesis;
|
||||
ball.vx +=
|
||||
((gameState.puckPosition - ball.x) / 1000) *
|
||||
delta *
|
||||
gameState.perks.telekinesis;
|
||||
}
|
||||
|
||||
if (ball.vx * ball.vx + ball.vy * ball.vy < gameState.baseSpeed * gameState.baseSpeed * 2) {
|
||||
if (
|
||||
ball.vx * ball.vx + ball.vy * ball.vy <
|
||||
gameState.baseSpeed * gameState.baseSpeed * 2
|
||||
) {
|
||||
ball.vx *= 1 + 0.02 / speedLimitDampener;
|
||||
ball.vy *= 1 + 0.02 / speedLimitDampener;
|
||||
} else {
|
||||
|
@ -852,7 +941,8 @@ export function ballTick(ball: Ball, delta: number) {
|
|||
if (
|
||||
gameState.perks.puck_repulse_ball &&
|
||||
Math.abs(ball.x - gameState.puckPosition) <
|
||||
gameState.puckWidth / 2 + (gameState.ballSize * (9 + gameState.perks.puck_repulse_ball)) / 10
|
||||
gameState.puckWidth / 2 +
|
||||
(gameState.ballSize * (9 + gameState.perks.puck_repulse_ball)) / 10
|
||||
) {
|
||||
repulse(
|
||||
ball,
|
||||
|
@ -865,8 +955,16 @@ export function ballTick(ball: Ball, delta: number) {
|
|||
);
|
||||
}
|
||||
|
||||
if (gameState.perks.respawn && ball.hitItem?.length > 1 && !isSettingOn("basic")) {
|
||||
for (let i = 0; i < ball.hitItem?.length - 1 && i < gameState.perks.respawn; i++) {
|
||||
if (
|
||||
gameState.perks.respawn &&
|
||||
ball.hitItem?.length > 1 &&
|
||||
!isSettingOn("basic")
|
||||
) {
|
||||
for (
|
||||
let i = 0;
|
||||
i < ball.hitItem?.length - 1 && i < gameState.perks.respawn;
|
||||
i++
|
||||
) {
|
||||
const { index, color } = ball.hitItem[i];
|
||||
if (gameState.bricks[index] || color === "black") continue;
|
||||
const vertical = Math.random() > 0.5;
|
||||
|
@ -914,17 +1012,24 @@ export function ballTick(ball: Ball, delta: number) {
|
|||
}
|
||||
|
||||
// Puck collision
|
||||
const ylimit = gameState.gameZoneHeight - gameState.puckHeight - gameState.ballSize / 2;
|
||||
const ylimit =
|
||||
gameState.gameZoneHeight - gameState.puckHeight - gameState.ballSize / 2;
|
||||
const ballIsUnderPuck =
|
||||
Math.abs(ball.x - gameState.puckPosition) < gameState.ballSize / 2 + gameState.puckWidth / 2;
|
||||
Math.abs(ball.x - gameState.puckPosition) <
|
||||
gameState.ballSize / 2 + gameState.puckWidth / 2;
|
||||
if (
|
||||
ball.y > ylimit &&
|
||||
ball.vy > 0 &&
|
||||
(ballIsUnderPuck || (gameState.perks.extra_life && ball.y > ylimit + gameState.puckHeight / 2))
|
||||
(ballIsUnderPuck ||
|
||||
(gameState.perks.extra_life &&
|
||||
ball.y > ylimit + gameState.puckHeight / 2))
|
||||
) {
|
||||
if (ballIsUnderPuck) {
|
||||
const speed = Math.sqrt(ball.vx * ball.vx + ball.vy * ball.vy);
|
||||
const angle = Math.atan2(-gameState.puckWidth / 2, ball.x - gameState.puckPosition);
|
||||
const angle = Math.atan2(
|
||||
-gameState.puckWidth / 2,
|
||||
ball.x - gameState.puckPosition,
|
||||
);
|
||||
ball.vx = speed * Math.cos(angle);
|
||||
ball.vy = speed * Math.sin(angle);
|
||||
sounds.wallBeep(ball.x);
|
||||
|
@ -958,7 +1063,8 @@ export function ballTick(ball: Ball, delta: number) {
|
|||
.slice(0, -1)
|
||||
.slice(0, gameState.perks.respawn)
|
||||
.forEach(({ index, color }) => {
|
||||
if (!gameState.bricks[index] && color !== "black") gameState.bricks[index] = color;
|
||||
if (!gameState.bricks[index] && color !== "black")
|
||||
gameState.bricks[index] = color;
|
||||
});
|
||||
}
|
||||
ball.hitItem = [];
|
||||
|
@ -989,7 +1095,10 @@ export function ballTick(ball: Ball, delta: number) {
|
|||
];
|
||||
}
|
||||
|
||||
if (ball.y > gameState.gameZoneHeight + gameState.ballSize / 2 && gameState.running) {
|
||||
if (
|
||||
ball.y > gameState.gameZoneHeight + gameState.ballSize / 2 &&
|
||||
gameState.running
|
||||
) {
|
||||
ball.destroyed = true;
|
||||
gameState.runStatistics.balls_lost++;
|
||||
if (!gameState.balls.find((b) => !b.destroyed)) {
|
||||
|
@ -1080,7 +1189,6 @@ export function ballTick(ball: Ball, delta: number) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
export function getTotalScore() {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem("breakout_71_total_score") || "0");
|
||||
|
@ -1096,8 +1204,7 @@ export function addToTotalScore(points: number) {
|
|||
"breakout_71_total_score",
|
||||
JSON.stringify(getTotalScore() + points),
|
||||
);
|
||||
} catch (e) {
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
export function addToTotalPlayTime(ms: number) {
|
||||
|
@ -1109,8 +1216,7 @@ export function addToTotalPlayTime(ms: number) {
|
|||
ms,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
export function gameOver(title: string, intro: string) {
|
||||
|
@ -1169,9 +1275,11 @@ export function gameOver(title: string, intro: string) {
|
|||
});
|
||||
}
|
||||
|
||||
let unlockedItems = list.filter((u) => u.threshold > startTs && u.threshold < endTs);
|
||||
let unlockedItems = list.filter(
|
||||
(u) => u.threshold > startTs && u.threshold < endTs,
|
||||
);
|
||||
if (unlockedItems.length) {
|
||||
unlocksInfo += `<p>You unlocked ${unlockedItems.length} item(s) : ${unlockedItems.map(u => u.title).join(', ')}</p>`
|
||||
unlocksInfo += `<p>You unlocked ${unlockedItems.length} item(s) : ${unlockedItems.map((u) => u.title).join(", ")}</p>`;
|
||||
}
|
||||
|
||||
// Avoid the sad sound right as we restart a new games
|
||||
|
@ -1209,7 +1317,11 @@ export function getHistograms() {
|
|||
runsHistory.sort((a, b) => a.score - b.score).reverse();
|
||||
runsHistory = runsHistory.slice(0, 100);
|
||||
|
||||
runsHistory.push({...gameState.runStatistics, perks: gameState.perks, appVersion});
|
||||
runsHistory.push({
|
||||
...gameState.runStatistics,
|
||||
perks: gameState.perks,
|
||||
appVersion,
|
||||
});
|
||||
|
||||
// Generate some histogram
|
||||
if (!gameState.isCreativeModeRun)
|
||||
|
@ -1332,7 +1444,10 @@ export function explodeBrick(index: number, ball: Ball, isExplosion: boolean) {
|
|||
const i = getRowColIndex(row + dy, col + dx);
|
||||
if (gameState.bricks[i] && i !== -1) {
|
||||
// Study bricks resist explisions too
|
||||
if (gameState.bricks[i] !== "black" && gameState.perks.sturdy_bricks > Math.random() * 5)
|
||||
if (
|
||||
gameState.bricks[i] !== "black" &&
|
||||
gameState.perks.sturdy_bricks > Math.random() * 5
|
||||
)
|
||||
continue;
|
||||
explodeBrick(i, ball, true);
|
||||
}
|
||||
|
@ -1392,7 +1507,9 @@ export function explodeBrick(index: number, ball: Ball, isExplosion: boolean) {
|
|||
gameState.runStatistics.bricks_broken++;
|
||||
const maxCoins = gameState.MAX_COINS * (isSettingOn("basic") ? 0.5 : 1);
|
||||
const spawnableCoins =
|
||||
gameState.coins.length > gameState.MAX_COINS ? 1 : Math.floor(maxCoins - gameState.coins.length) / 3;
|
||||
gameState.coins.length > gameState.MAX_COINS
|
||||
? 1
|
||||
: Math.floor(maxCoins - gameState.coins.length) / 3;
|
||||
|
||||
const pointsPerCoin = Math.max(1, Math.ceil(coinsToSpawn / spawnableCoins));
|
||||
|
||||
|
@ -1405,8 +1522,12 @@ export function explodeBrick(index: number, ball: Ball, isExplosion: boolean) {
|
|||
|
||||
coinsToSpawn -= points;
|
||||
|
||||
const cx = x + (Math.random() - 0.5) * (gameState.brickWidth - gameState.coinSize),
|
||||
cy = y + (Math.random() - 0.5) * (gameState.brickWidth - gameState.coinSize);
|
||||
const cx =
|
||||
x +
|
||||
(Math.random() - 0.5) * (gameState.brickWidth - gameState.coinSize),
|
||||
cy =
|
||||
y +
|
||||
(Math.random() - 0.5) * (gameState.brickWidth - gameState.coinSize);
|
||||
|
||||
gameState.coins.push({
|
||||
points,
|
||||
|
@ -1448,13 +1569,13 @@ export function explodeBrick(index: number, ball: Ball, isExplosion: boolean) {
|
|||
if (gameState.perks.picky_eater) {
|
||||
resetCombo(gameState, ball.x, ball.y);
|
||||
}
|
||||
sounds.colorChange(ball.x, 0.8)
|
||||
gameState.lastExplosion = gameState.levelTime
|
||||
sounds.colorChange(ball.x, 0.8);
|
||||
gameState.lastExplosion = gameState.levelTime;
|
||||
gameState.ballsColor = color;
|
||||
if (!isSettingOn('basic')) {
|
||||
gameState.balls.forEach(ball => {
|
||||
spawnExplosion(7, ball.previousX, ball.previousY, color, 150, 15)
|
||||
})
|
||||
if (!isSettingOn("basic")) {
|
||||
gameState.balls.forEach((ball) => {
|
||||
spawnExplosion(7, ball.previousX, ball.previousY, color, 150, 15);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
sounds.comboIncreaseMaybe(gameState.combo, ball.x, 1);
|
||||
|
@ -1470,7 +1591,14 @@ export function explodeBrick(index: number, ball: Ball, isExplosion: boolean) {
|
|||
x,
|
||||
y,
|
||||
});
|
||||
spawnExplosion(5 + Math.min(gameState.combo, 30), x, y, color, 150, gameState.coinSize / 2);
|
||||
spawnExplosion(
|
||||
5 + Math.min(gameState.combo, 30),
|
||||
x,
|
||||
y,
|
||||
color,
|
||||
150,
|
||||
gameState.coinSize / 2,
|
||||
);
|
||||
}
|
||||
|
||||
if (!gameState.bricks[index] && color !== "black") {
|
||||
|
@ -1497,8 +1625,12 @@ export function render() {
|
|||
if (!width || !height) return;
|
||||
|
||||
scoreDisplay.innerText = `L${gameState.currentLevel + 1}/${max_levels()} $${gameState.score}`;
|
||||
Object.assign(scoreDisplay.style, gameState.lastScoreIncrease < gameState.levelTime - 500 ?
|
||||
{color: 'gold', fontWeight: 'bold', opacity: 1} : {opacity: 0.5})
|
||||
Object.assign(
|
||||
scoreDisplay.style,
|
||||
gameState.lastScoreIncrease < gameState.levelTime - 30
|
||||
? { color: "gold", fontWeight: "bold", opacity: 1 }
|
||||
: { opacity: 0.5, fontWeight: "normal", color: "white" },
|
||||
);
|
||||
|
||||
// Clear
|
||||
if (!isSettingOn("basic") && !level.color && level.svg) {
|
||||
|
@ -1515,14 +1647,26 @@ export function render() {
|
|||
drawFuzzyBall(ctx, coin.color, gameState.coinSize * 2, coin.x, coin.y);
|
||||
});
|
||||
gameState.balls.forEach((ball) => {
|
||||
drawFuzzyBall(ctx, gameState.ballsColor, gameState.ballSize * 2, ball.x, ball.y);
|
||||
drawFuzzyBall(
|
||||
ctx,
|
||||
gameState.ballsColor,
|
||||
gameState.ballSize * 2,
|
||||
ball.x,
|
||||
ball.y,
|
||||
);
|
||||
});
|
||||
ctx.globalAlpha = 0.5;
|
||||
gameState.bricks.forEach((color, index) => {
|
||||
if (!color) return;
|
||||
const x = brickCenterX(index),
|
||||
y = brickCenterY(index);
|
||||
drawFuzzyBall(ctx, color == "black" ? "#666" : color, gameState.brickWidth, x, y);
|
||||
drawFuzzyBall(
|
||||
ctx,
|
||||
color == "black" ? "#666" : color,
|
||||
gameState.brickWidth,
|
||||
x,
|
||||
y,
|
||||
);
|
||||
});
|
||||
ctx.globalAlpha = 1;
|
||||
gameState.flashes.forEach((flash) => {
|
||||
|
@ -1588,7 +1732,8 @@ export function render() {
|
|||
const lastExplosionDelay = Date.now() - gameState.lastExplosion + 5;
|
||||
const shaked = lastExplosionDelay < 200;
|
||||
if (shaked) {
|
||||
const amplitude = ((gameState.perks.bigger_explosions + 1) * 50) / lastExplosionDelay;
|
||||
const amplitude =
|
||||
((gameState.perks.bigger_explosions + 1) * 50) / lastExplosionDelay;
|
||||
ctx.translate(
|
||||
Math.sin(Date.now()) * amplitude,
|
||||
Math.sin(Date.now() + 36) * amplitude,
|
||||
|
@ -1619,7 +1764,13 @@ export function render() {
|
|||
ctx.globalCompositeOperation = "source-over";
|
||||
ctx.globalAlpha = Math.min(0.8, gameState.coins.length / 20);
|
||||
gameState.balls.forEach((ball) => {
|
||||
drawBall(ctx, level.color || "#000", gameState.ballSize * 6, ball.x, ball.y);
|
||||
drawBall(
|
||||
ctx,
|
||||
level.color || "#000",
|
||||
gameState.ballSize * 6,
|
||||
ball.x,
|
||||
ball.y,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1663,12 +1814,26 @@ export function render() {
|
|||
ctx.globalCompositeOperation = "source-over";
|
||||
gameState.balls.forEach((ball) => {
|
||||
// The white border around is to distinguish colored balls from coins/bg
|
||||
drawBall(ctx, gameState.ballsColor, gameState.ballSize, ball.x, ball.y, gameState.puckColor);
|
||||
drawBall(
|
||||
ctx,
|
||||
gameState.ballsColor,
|
||||
gameState.ballSize,
|
||||
ball.x,
|
||||
ball.y,
|
||||
gameState.puckColor,
|
||||
);
|
||||
|
||||
if (isTelekinesisActive(ball)) {
|
||||
ctx.strokeStyle = gameState.puckColor;
|
||||
ctx.beginPath();
|
||||
ctx.bezierCurveTo(gameState.puckPosition, gameState.gameZoneHeight, gameState.puckPosition, ball.y, ball.x, ball.y);
|
||||
ctx.bezierCurveTo(
|
||||
gameState.puckPosition,
|
||||
gameState.gameZoneHeight,
|
||||
gameState.puckPosition,
|
||||
ball.y,
|
||||
ball.x,
|
||||
ball.y,
|
||||
);
|
||||
ctx.stroke();
|
||||
}
|
||||
});
|
||||
|
@ -1722,24 +1887,38 @@ export function render() {
|
|||
ctx.globalCompositeOperation = "source-over";
|
||||
if (gameState.offsetXRoundedDown) {
|
||||
// draw outside of gaming area to avoid capturing borders in recordings
|
||||
ctx.fillStyle = hasCombo && gameState.perks.left_is_lava ? "red" : gameState.puckColor;
|
||||
ctx.fillStyle =
|
||||
hasCombo && gameState.perks.left_is_lava ? "red" : gameState.puckColor;
|
||||
ctx.fillRect(gameState.offsetX - 1, 0, 1, height);
|
||||
ctx.fillStyle = hasCombo && gameState.perks.right_is_lava ? "red" : gameState.puckColor;
|
||||
ctx.fillStyle =
|
||||
hasCombo && gameState.perks.right_is_lava ? "red" : gameState.puckColor;
|
||||
ctx.fillRect(width - gameState.offsetX + 1, 0, 1, height);
|
||||
} else {
|
||||
ctx.fillStyle = "red";
|
||||
if (hasCombo && gameState.perks.left_is_lava) ctx.fillRect(0, 0, 1, height);
|
||||
if (hasCombo && gameState.perks.right_is_lava) ctx.fillRect(width - 1, 0, 1, height);
|
||||
if (hasCombo && gameState.perks.right_is_lava)
|
||||
ctx.fillRect(width - 1, 0, 1, height);
|
||||
}
|
||||
|
||||
if (gameState.perks.top_is_lava && gameState.combo > baseCombo(gameState)) {
|
||||
ctx.fillStyle = "red";
|
||||
ctx.fillRect(gameState.offsetXRoundedDown, 0, gameState.gameZoneWidthRoundedUp, 1);
|
||||
ctx.fillRect(
|
||||
gameState.offsetXRoundedDown,
|
||||
0,
|
||||
gameState.gameZoneWidthRoundedUp,
|
||||
1,
|
||||
);
|
||||
}
|
||||
const redBottom = gameState.perks.compound_interest && gameState.combo > baseCombo(gameState);
|
||||
const redBottom =
|
||||
gameState.perks.compound_interest && gameState.combo > baseCombo(gameState);
|
||||
ctx.fillStyle = redBottom ? "red" : gameState.puckColor;
|
||||
if (isSettingOn("mobile-mode")) {
|
||||
ctx.fillRect(gameState.offsetXRoundedDown, gameState.gameZoneHeight, gameState.gameZoneWidthRoundedUp, 1);
|
||||
ctx.fillRect(
|
||||
gameState.offsetXRoundedDown,
|
||||
gameState.gameZoneHeight,
|
||||
gameState.gameZoneWidthRoundedUp,
|
||||
1,
|
||||
);
|
||||
if (!gameState.running) {
|
||||
drawText(
|
||||
ctx,
|
||||
|
@ -1747,7 +1926,8 @@ export function render() {
|
|||
gameState.puckColor,
|
||||
gameState.puckHeight,
|
||||
gameState.canvasWidth / 2,
|
||||
gameState.gameZoneHeight + (gameState.canvasHeight - gameState.gameZoneHeight) / 2,
|
||||
gameState.gameZoneHeight +
|
||||
(gameState.canvasHeight - gameState.gameZoneHeight) / 2,
|
||||
);
|
||||
}
|
||||
} else if (redBottom) {
|
||||
|
@ -1766,7 +1946,6 @@ export function render() {
|
|||
recordOneFrame();
|
||||
}
|
||||
|
||||
|
||||
let cachedBricksRender = document.createElement("canvas");
|
||||
let cachedBricksRenderKey = "";
|
||||
|
||||
|
@ -2129,7 +2308,6 @@ export function drawText(
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
window.addEventListener("visibilitychange", () => {
|
||||
if (document.hidden) {
|
||||
pause(true);
|
||||
|
@ -2290,6 +2468,14 @@ scoreDisplay.addEventListener("click", (e) => {
|
|||
openScorePanel();
|
||||
});
|
||||
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (document.hidden) {
|
||||
pause(true)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
async function openScorePanel() {
|
||||
pause(true);
|
||||
const cb = await asyncAlert({
|
||||
|
@ -2304,14 +2490,13 @@ async function openScorePanel() {
|
|||
{
|
||||
text: "Resume",
|
||||
help: "Return to your run",
|
||||
value: () => {
|
||||
},
|
||||
value: () => {},
|
||||
},
|
||||
{
|
||||
text: "Restart",
|
||||
help: "Start a brand new run.",
|
||||
value: () => {
|
||||
restart({levelToAvoid: currentLevelInfo().name})
|
||||
restart({ levelToAvoid: currentLevelInfo().name });
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -2333,8 +2518,7 @@ async function openSettingsPanel() {
|
|||
{
|
||||
text: "Resume",
|
||||
help: "Return to your run",
|
||||
value() {
|
||||
},
|
||||
value() {},
|
||||
},
|
||||
{
|
||||
text: "Starting perk",
|
||||
|
@ -2545,7 +2729,10 @@ Click an item above to start a run with it.
|
|||
}
|
||||
}
|
||||
|
||||
export function distance2(a: { x: number; y: number }, b: { x: number; y: number }) {
|
||||
export function distance2(
|
||||
a: { x: number; y: number },
|
||||
b: { x: number; y: number },
|
||||
) {
|
||||
return Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2);
|
||||
}
|
||||
|
||||
|
@ -2560,7 +2747,12 @@ export function rainbowColor(): colorString {
|
|||
return `hsl(${(Math.round(gameState.levelTime / 4) * 2) % 360},100%,70%)`;
|
||||
}
|
||||
|
||||
export function repulse(a: Ball, b: BallLike, power: number, impactsBToo: boolean) {
|
||||
export function repulse(
|
||||
a: Ball,
|
||||
b: BallLike,
|
||||
power: number,
|
||||
impactsBToo: boolean,
|
||||
) {
|
||||
const distance = distanceBetween(a, b);
|
||||
// Ensure we don't get soft locked
|
||||
const max = gameState.gameZoneWidth / 2;
|
||||
|
@ -2627,7 +2819,8 @@ export function attract(a: Ball, b: Ball, power: number) {
|
|||
const dy = (a.y - b.y) / distance;
|
||||
|
||||
const fact =
|
||||
(((power * (distance - min)) / min) * Math.min(500, gameState.levelTime)) / 500;
|
||||
(((power * (distance - min)) / min) * Math.min(500, gameState.levelTime)) /
|
||||
500;
|
||||
b.vx += dx * fact;
|
||||
b.vy += dy * fact;
|
||||
a.vx -= dx * fact;
|
||||
|
@ -2700,7 +2893,11 @@ export function drawMainCanvasOnSmallCanvas() {
|
|||
recordCanvasCtx.textBaseline = "top";
|
||||
recordCanvasCtx.font = "12px monospace";
|
||||
recordCanvasCtx.textAlign = "right";
|
||||
recordCanvasCtx.fillText(gameState.score.toString(), recordCanvas.width - 12, 12);
|
||||
recordCanvasCtx.fillText(
|
||||
gameState.score.toString(),
|
||||
recordCanvas.width - 12,
|
||||
12,
|
||||
);
|
||||
|
||||
recordCanvasCtx.textAlign = "left";
|
||||
recordCanvasCtx.fillText(
|
||||
|
@ -2905,17 +3102,18 @@ document.addEventListener("keyup", async (e) => {
|
|||
} else if (e.key.toLowerCase() === "s" && !alertsOpen) {
|
||||
openScorePanel();
|
||||
} else if (e.key.toLowerCase() === "r" && !alertsOpen) {
|
||||
// TODO
|
||||
restart({ levelToAvoid: currentLevelInfo().name });
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
|
||||
export function newGameState(params: RunParams): GameState {
|
||||
const totalScoreAtRunStart = getTotalScore()
|
||||
const firstLevel = params?.level ? allLevels.filter((l) => l.name === params?.level) : [];
|
||||
const totalScoreAtRunStart = getTotalScore();
|
||||
const firstLevel = params?.level
|
||||
? allLevels.filter((l) => l.name === params?.level)
|
||||
: [];
|
||||
|
||||
const restInRandomOrder = allLevels
|
||||
.filter((l) => totalScoreAtRunStart >= l.threshold)
|
||||
|
@ -2927,7 +3125,7 @@ export function newGameState(params: RunParams): GameState {
|
|||
restInRandomOrder.slice(0, 7 + 3).sort((a, b) => a.sortKey - b.sortKey),
|
||||
);
|
||||
|
||||
const perks = {...makeEmptyPerksMap(upgrades), ...(params?.perks || {})}
|
||||
const perks = { ...makeEmptyPerksMap(upgrades), ...(params?.perks || {}) };
|
||||
|
||||
const gameState: GameState = {
|
||||
runLevels,
|
||||
|
@ -2991,29 +3189,29 @@ export function newGameState(params: RunParams): GameState {
|
|||
lastOffered: {},
|
||||
levelTime: 0,
|
||||
autoCleanUses: 0,
|
||||
}
|
||||
};
|
||||
resetBalls(gameState);
|
||||
|
||||
if (!sumOfKeys(gameState.perks)) {
|
||||
const giftable = getPossibleUpgrades(gameState).filter((u) => u.giftable);
|
||||
const randomGift = (isSettingOn("easy") && "slow_down") ||
|
||||
const randomGift =
|
||||
(isSettingOn("easy") && "slow_down") ||
|
||||
giftable[Math.floor(Math.random() * giftable.length)].id;
|
||||
perks[randomGift] = 1;
|
||||
dontOfferTooSoon(gameState, randomGift);
|
||||
}
|
||||
for (let perk of upgrades) {
|
||||
if (gameState.perks[perk.id]) {
|
||||
dontOfferTooSoon(gameState, perk.id)
|
||||
dontOfferTooSoon(gameState, perk.id);
|
||||
}
|
||||
}
|
||||
return gameState
|
||||
return gameState;
|
||||
}
|
||||
|
||||
|
||||
export const gameState = newGameState({})
|
||||
export const gameState = newGameState({});
|
||||
|
||||
export function restart(params: RunParams) {
|
||||
Object.assign(gameState, newGameState(params))
|
||||
Object.assign(gameState, newGameState(params));
|
||||
pauseRecording();
|
||||
setLevel(0);
|
||||
}
|
||||
|
|
|
@ -1,49 +1,54 @@
|
|||
import {getMajorityValue, makeEmptyPerksMap, sample, sumOfKeys} from "./game_utils";
|
||||
import {
|
||||
getMajorityValue,
|
||||
makeEmptyPerksMap,
|
||||
sample,
|
||||
sumOfKeys,
|
||||
} from "./game_utils";
|
||||
import { Upgrade } from "./types";
|
||||
|
||||
describe('getMajorityValue', ()=>{
|
||||
|
||||
it('returns the most common string',()=>{
|
||||
expect(getMajorityValue(['1','1','2','2','3','2','3','2','2','1'])).toStrictEqual('2')
|
||||
})
|
||||
it('returns the only string',()=>{
|
||||
expect(getMajorityValue(['1'])).toStrictEqual('1')
|
||||
})
|
||||
it('returns nothing for empty array',()=>{
|
||||
expect(getMajorityValue([])).toStrictEqual(undefined)
|
||||
})
|
||||
|
||||
})
|
||||
describe('sample', ()=>{
|
||||
|
||||
it('returns a random pick from the array',()=>{
|
||||
expect(['1','2','3'].includes(sample(['1','2','3']))).toBeTruthy()
|
||||
})
|
||||
it('returns the only item if there is just one',()=>{
|
||||
expect(sample(['1'])).toStrictEqual('1')
|
||||
})
|
||||
it('returns nothing for empty array',()=>{
|
||||
expect(sample([])).toStrictEqual(undefined)
|
||||
})
|
||||
|
||||
})
|
||||
describe('sumOfKeys', ()=>{
|
||||
it('returns the sum of the keys of an array',()=>{
|
||||
expect(sumOfKeys({a:1,b:2})).toEqual(3)
|
||||
})
|
||||
it('returns 0 for an empty object',()=>{
|
||||
expect(sumOfKeys({})).toEqual(0)
|
||||
})
|
||||
it('returns 0 for undefined',()=>{
|
||||
expect(sumOfKeys(undefined)).toEqual(0)
|
||||
})
|
||||
it('returns 0 for null',()=>{
|
||||
expect(sumOfKeys(null)).toEqual(0)
|
||||
})
|
||||
})
|
||||
describe('makeEmptyPerksMap', ()=>{
|
||||
it('returns an object',()=>{
|
||||
expect(makeEmptyPerksMap([{id:"ball_attract_ball"}])).toEqual({ball_attract_ball:0})
|
||||
expect(makeEmptyPerksMap([])).toEqual({})
|
||||
})
|
||||
})
|
||||
describe("getMajorityValue", () => {
|
||||
it("returns the most common string", () => {
|
||||
expect(
|
||||
getMajorityValue(["1", "1", "2", "2", "3", "2", "3", "2", "2", "1"]),
|
||||
).toStrictEqual("2");
|
||||
});
|
||||
it("returns the only string", () => {
|
||||
expect(getMajorityValue(["1"])).toStrictEqual("1");
|
||||
});
|
||||
it("returns nothing for empty array", () => {
|
||||
expect(getMajorityValue([])).toStrictEqual(undefined);
|
||||
});
|
||||
});
|
||||
describe("sample", () => {
|
||||
it("returns a random pick from the array", () => {
|
||||
expect(["1", "2", "3"].includes(sample(["1", "2", "3"]))).toBeTruthy();
|
||||
});
|
||||
it("returns the only item if there is just one", () => {
|
||||
expect(sample(["1"])).toStrictEqual("1");
|
||||
});
|
||||
it("returns nothing for empty array", () => {
|
||||
expect(sample([])).toStrictEqual(undefined);
|
||||
});
|
||||
});
|
||||
describe("sumOfKeys", () => {
|
||||
it("returns the sum of the keys of an array", () => {
|
||||
expect(sumOfKeys({ a: 1, b: 2 })).toEqual(3);
|
||||
});
|
||||
it("returns 0 for an empty object", () => {
|
||||
expect(sumOfKeys({})).toEqual(0);
|
||||
});
|
||||
it("returns 0 for undefined", () => {
|
||||
expect(sumOfKeys(undefined)).toEqual(0);
|
||||
});
|
||||
it("returns 0 for null", () => {
|
||||
expect(sumOfKeys(null)).toEqual(0);
|
||||
});
|
||||
});
|
||||
describe("makeEmptyPerksMap", () => {
|
||||
it("returns an object", () => {
|
||||
expect(makeEmptyPerksMap([{ id: "ball_attract_ball" }])).toEqual({
|
||||
ball_attract_ball: 0,
|
||||
});
|
||||
expect(makeEmptyPerksMap([])).toEqual({});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import { PerkId, PerksMap, Upgrade } from "./types";
|
||||
|
||||
export function getMajorityValue(arr: string[]): string {
|
||||
|
@ -9,14 +8,13 @@ export function getMajorityValue(arr: string[]): string {
|
|||
return sample(Object.keys(count).filter((k) => count[k] == max));
|
||||
}
|
||||
|
||||
|
||||
export function sample<T>(arr: T[]): T {
|
||||
return arr[Math.floor(arr.length * Math.random())];
|
||||
}
|
||||
|
||||
export function sumOfKeys(obj: { [key: string]: number } | undefined | null) {
|
||||
if(!obj) return 0
|
||||
return Object.values(obj)?.reduce((a,b)=>a+b,0) ||0
|
||||
if (!obj) return 0;
|
||||
return Object.values(obj)?.reduce((a, b) => a + b, 0) || 0;
|
||||
}
|
||||
|
||||
export const makeEmptyPerksMap = (upgrades: { id: PerkId }[]) => {
|
||||
|
|
|
@ -4,16 +4,14 @@ import _backgrounds from "./backgrounds.json";
|
|||
const backgrounds = _backgrounds as string[];
|
||||
|
||||
export function getLevelBackground(level: RawLevel) {
|
||||
|
||||
let svg = level.svg !== null && backgrounds[level.svg % backgrounds.length];
|
||||
|
||||
if (!level.color && !svg) {
|
||||
svg = backgrounds[hashCode(level.name) % backgrounds.length];
|
||||
}
|
||||
return svg
|
||||
return svg;
|
||||
}
|
||||
|
||||
|
||||
export function hashCode(string: string) {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
|
|
BIN
src/icon-128.png
Before Width: | Height: | Size: 749 B After Width: | Height: | Size: 715 B |
BIN
src/icon-64.png
Before Width: | Height: | Size: 479 B After Width: | Height: | Size: 445 B |
|
@ -1,47 +1,47 @@
|
|||
import { moveLevel, resizeLevel, setBrick } from "./levels_editor_util";
|
||||
|
||||
const baseLevel = {
|
||||
name: '',
|
||||
bricks: 'AAAA',
|
||||
name: "",
|
||||
bricks: "AAAA",
|
||||
size: 2,
|
||||
svg: null,
|
||||
color: ''
|
||||
}
|
||||
describe('resizeLevel', () => {
|
||||
it('should expand levels', () => {
|
||||
expect(resizeLevel(baseLevel, 1)).toStrictEqual({bricks: 'AA_AA____', size: 3});
|
||||
})
|
||||
it('should shrink levels', () => {
|
||||
expect(resizeLevel(baseLevel, -1)).toStrictEqual({bricks: 'A', size: 1});
|
||||
})
|
||||
})
|
||||
color: "",
|
||||
};
|
||||
describe("resizeLevel", () => {
|
||||
it("should expand levels", () => {
|
||||
expect(resizeLevel(baseLevel, 1)).toStrictEqual({
|
||||
bricks: "AA_AA____",
|
||||
size: 3,
|
||||
});
|
||||
});
|
||||
it("should shrink levels", () => {
|
||||
expect(resizeLevel(baseLevel, -1)).toStrictEqual({ bricks: "A", size: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('moveLevel', () => {
|
||||
describe("moveLevel", () => {
|
||||
it("should do nothing when coords are 0/0", () => {
|
||||
expect(moveLevel(baseLevel, 0, 0)).toStrictEqual({ bricks: "AAAA" });
|
||||
});
|
||||
it("should move right", () => {
|
||||
expect(moveLevel(baseLevel, 1, 0)).toStrictEqual({ bricks: "_A_A" });
|
||||
});
|
||||
it("should move left", () => {
|
||||
expect(moveLevel(baseLevel, -1, 0)).toStrictEqual({ bricks: "A_A_" });
|
||||
});
|
||||
it("should move up", () => {
|
||||
expect(moveLevel(baseLevel, 0, -1)).toStrictEqual({ bricks: "AA__" });
|
||||
});
|
||||
it("should move down", () => {
|
||||
expect(moveLevel(baseLevel, 0, 1)).toStrictEqual({ bricks: "__AA" });
|
||||
});
|
||||
});
|
||||
|
||||
it('should do nothing when coords are 0/0', () => {
|
||||
expect(moveLevel(baseLevel, 0, 0)).toStrictEqual({bricks: 'AAAA'});
|
||||
})
|
||||
it('should move right', () => {
|
||||
expect(moveLevel(baseLevel, 1, 0)).toStrictEqual({bricks: '_A_A'});
|
||||
})
|
||||
it('should move left', () => {
|
||||
expect(moveLevel(baseLevel, -1, 0)).toStrictEqual({bricks: 'A_A_'});
|
||||
})
|
||||
it('should move up', () => {
|
||||
expect(moveLevel(baseLevel, 0, -1)).toStrictEqual({bricks: 'AA__'});
|
||||
})
|
||||
it('should move down', () => {
|
||||
expect(moveLevel(baseLevel, 0, 1)).toStrictEqual({bricks: '__AA'});
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
describe('setBrick', () => {
|
||||
it('should set the first brick', () => {
|
||||
expect(setBrick(baseLevel, 0, 'C')).toStrictEqual({bricks: 'CAAA'});
|
||||
})
|
||||
it('should any brick', () => {
|
||||
expect(setBrick(baseLevel, 2, 'C')).toStrictEqual({bricks: 'AACA'});
|
||||
})
|
||||
})
|
||||
describe("setBrick", () => {
|
||||
it("should set the first brick", () => {
|
||||
expect(setBrick(baseLevel, 0, "C")).toStrictEqual({ bricks: "CAAA" });
|
||||
});
|
||||
it("should any brick", () => {
|
||||
expect(setBrick(baseLevel, 2, "C")).toStrictEqual({ bricks: "AACA" });
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta charset="UTF-8" />
|
||||
<title>Level editor</title>
|
||||
<link rel="icon"
|
||||
<link
|
||||
rel="icon"
|
||||
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎨</text></svg>"
|
||||
/>
|
||||
<link rel="stylesheet" href="./levels_editor.less" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app"></div>
|
||||
|
||||
|
||||
<script type="module" src="levels_editor.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
body {
|
||||
background: black;
|
||||
color: white;
|
||||
|
@ -15,7 +14,6 @@ body {
|
|||
button.active {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#levels {
|
||||
|
@ -51,8 +49,5 @@ body {
|
|||
& > div:nth-child(3) {
|
||||
grid-area: bricks;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { Palette, RawLevel } from "./types";
|
||||
import _backgrounds from './backgrounds.json'
|
||||
import _palette from './palette.json'
|
||||
import _allLevels from './levels.json'
|
||||
import _backgrounds from "./backgrounds.json";
|
||||
import _palette from "./palette.json";
|
||||
import _allLevels from "./levels.json";
|
||||
import { getLevelBackground, hashCode } from "./getLevelBackground";
|
||||
import {createRoot} from 'react-dom/client';
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { moveLevel, resizeLevel, setBrick } from "./levels_editor_util";
|
||||
|
||||
|
@ -13,148 +13,191 @@ const palette = _palette as Palette;
|
|||
|
||||
let allLevels = _allLevels as RawLevel[];
|
||||
|
||||
|
||||
function App() {
|
||||
|
||||
const [selected, setSelected] = useState('W')
|
||||
const [applying, setApplying] = useState('')
|
||||
const [levels, setLevels] = useState(allLevels)
|
||||
const updateLevel = useCallback((index: number, change: Partial<RawLevel>) => {
|
||||
setLevels(list => list.map((l, li) => li === index ? {...l, ...change} : l))
|
||||
}, []);
|
||||
const [selected, setSelected] = useState("W");
|
||||
const [applying, setApplying] = useState("");
|
||||
const [levels, setLevels] = useState(allLevels);
|
||||
const updateLevel = useCallback(
|
||||
(index: number, change: Partial<RawLevel>) => {
|
||||
setLevels((list) =>
|
||||
list.map((l, li) => (li === index ? { ...l, ...change } : l)),
|
||||
);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const deleteLevel = useCallback((li: number) => {
|
||||
if (confirm('Delete level')) {
|
||||
setLevels(allLevels.filter((l, i) => i !== li))
|
||||
if (confirm("Delete level")) {
|
||||
setLevels(allLevels.filter((l, i) => i !== li));
|
||||
}
|
||||
}, [])
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const timoutId = setTimeout(() => {
|
||||
return fetch('http://localhost:4400/src/levels.json', {
|
||||
method: 'POST',
|
||||
return fetch("http://localhost:4400/src/levels.json", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
body: JSON.stringify(levels, null, 2)
|
||||
body: JSON.stringify(levels, null, 2),
|
||||
});
|
||||
}, 500);
|
||||
return () => clearTimeout(timoutId);
|
||||
}, [levels]);
|
||||
|
||||
},500)
|
||||
return ()=>clearTimeout(timoutId)
|
||||
},[levels])
|
||||
|
||||
|
||||
|
||||
return <div onMouseUp={() => {
|
||||
console.log('mouse up')
|
||||
setApplying('')
|
||||
}} >
|
||||
return (
|
||||
<div
|
||||
onMouseUp={() => {
|
||||
setApplying("");
|
||||
}}
|
||||
>
|
||||
<div id={"levels"}>
|
||||
{
|
||||
levels.map((level, li) => {
|
||||
const {name, bricks, size, svg, color} = level
|
||||
{levels.map((level, li) => {
|
||||
const { name, bricks, size, svg, color } = level;
|
||||
|
||||
const brickButtons = []
|
||||
const brickButtons = [];
|
||||
for (let x = 0; x < size; x++) {
|
||||
for (let y = 0; y < size; y++) {
|
||||
const index = y * size + x
|
||||
brickButtons.push(<button
|
||||
const index = y * size + x;
|
||||
brickButtons.push(
|
||||
<button
|
||||
key={index}
|
||||
onMouseDown={() => {
|
||||
if (!applying) {
|
||||
console.log(selected, bricks[index],applying)
|
||||
const color = selected === bricks[index] ? '_' : selected
|
||||
setApplying(color)
|
||||
updateLevel(li, setBrick(level, index, color))
|
||||
const color = selected === bricks[index] ? "_" : selected;
|
||||
setApplying(color);
|
||||
updateLevel(li, setBrick(level, index, color));
|
||||
}
|
||||
}}
|
||||
onMouseEnter={() => {
|
||||
if (applying) {
|
||||
updateLevel(li, setBrick(level, index, applying))
|
||||
updateLevel(li, setBrick(level, index, applying));
|
||||
}
|
||||
}}
|
||||
style={{
|
||||
background: palette[bricks[index]] || 'transparent',
|
||||
left: x * 40, top: y * 40, width: 40, height: 40, position: 'absolute'
|
||||
}}></button>)
|
||||
background: palette[bricks[index]] || "transparent",
|
||||
left: x * 40,
|
||||
top: y * 40,
|
||||
width: 40,
|
||||
height: 40,
|
||||
position: "absolute",
|
||||
}}
|
||||
></button>,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const background = color ? {backgroundImage: 'none', backgroundColor: color} : {
|
||||
const background = color
|
||||
? { backgroundImage: "none", backgroundColor: color }
|
||||
: {
|
||||
backgroundImage: `url("data:image/svg+xml;UTF8,${encodeURIComponent(getLevelBackground(level) as string)}")`,
|
||||
backgroundColor: 'transparent'
|
||||
}
|
||||
backgroundColor: "transparent",
|
||||
};
|
||||
|
||||
|
||||
return <div key={li}>
|
||||
<input type="text" value={name} onChange={e => updateLevel(li, {name: e.target.value})}/>
|
||||
return (
|
||||
<div key={li}>
|
||||
<input
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => updateLevel(li, { name: e.target.value })}
|
||||
/>
|
||||
<div>
|
||||
<button onClick={() => deleteLevel(li)}>Delete</button>
|
||||
<button onClick={() => updateLevel(li, resizeLevel(level, -1))}>-</button>
|
||||
<button onClick={() => updateLevel(li, resizeLevel(level, +1))}>+</button>
|
||||
<button onClick={() => updateLevel(li, moveLevel(level, -1, 0))}>L</button>
|
||||
<button onClick={() => updateLevel(li, moveLevel(level, 1, 0))}>R</button>
|
||||
<button onClick={() => updateLevel(li, moveLevel(level, 0, -1))}>U</button>
|
||||
<button onClick={() => updateLevel(li, moveLevel(level, 0, 1))}>D</button>
|
||||
<input type="color" value={level.color || ''}
|
||||
onChange={e => e.target.value && updateLevel(li, {color: e.target.value})}/>
|
||||
<input type="number" value={level.svg || (hashCode(level.name) % backgrounds.length)}
|
||||
onChange={e => !isNaN(parseFloat(e.target.value)) && updateLevel(li, {
|
||||
color: '',
|
||||
svg: parseFloat(e.target.value)
|
||||
})}
|
||||
<button onClick={() => updateLevel(li, resizeLevel(level, -1))}>
|
||||
-
|
||||
</button>
|
||||
<button onClick={() => updateLevel(li, resizeLevel(level, +1))}>
|
||||
+
|
||||
</button>
|
||||
<button
|
||||
onClick={() => updateLevel(li, moveLevel(level, -1, 0))}
|
||||
>
|
||||
L
|
||||
</button>
|
||||
<button onClick={() => updateLevel(li, moveLevel(level, 1, 0))}>
|
||||
R
|
||||
</button>
|
||||
<button
|
||||
onClick={() => updateLevel(li, moveLevel(level, 0, -1))}
|
||||
>
|
||||
U
|
||||
</button>
|
||||
<button onClick={() => updateLevel(li, moveLevel(level, 0, 1))}>
|
||||
D
|
||||
</button>
|
||||
<input
|
||||
type="color"
|
||||
value={level.color || ""}
|
||||
onChange={(e) =>
|
||||
e.target.value && updateLevel(li, { color: e.target.value })
|
||||
}
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
value={level.svg || hashCode(level.name) % backgrounds.length}
|
||||
onChange={(e) =>
|
||||
!isNaN(parseFloat(e.target.value)) &&
|
||||
updateLevel(li, {
|
||||
color: "",
|
||||
svg: parseFloat(e.target.value),
|
||||
})
|
||||
}
|
||||
/>
|
||||
|
||||
</div>
|
||||
<div className="level-bricks-preview" style={{
|
||||
<div
|
||||
className="level-bricks-preview"
|
||||
style={{
|
||||
width: size * 40,
|
||||
height: size * 40,
|
||||
...background
|
||||
|
||||
}}>
|
||||
...background,
|
||||
}}
|
||||
>
|
||||
{brickButtons}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div id={"palette"}>
|
||||
{
|
||||
Object.entries(palette).map(([code, color]) => <button
|
||||
{Object.entries(palette).map(([code, color]) => (
|
||||
<button
|
||||
key={code}
|
||||
className={code === selected ? 'active' : ''}
|
||||
className={code === selected ? "active" : ""}
|
||||
style={{
|
||||
background: color || 'linear-gradient(45deg,black,white)',
|
||||
display: 'inline-block',
|
||||
width: '40px',
|
||||
height: '40px',
|
||||
border: '1px solid black'
|
||||
background: color || "linear-gradient(45deg,black,white)",
|
||||
display: "inline-block",
|
||||
width: "40px",
|
||||
height: "40px",
|
||||
border: "1px solid black",
|
||||
}}
|
||||
onClick={() => setSelected(code)}></button>
|
||||
)
|
||||
}
|
||||
onClick={() => setSelected(code)}
|
||||
></button>
|
||||
))}
|
||||
</div>
|
||||
<button id="new-level" onClick={() => {
|
||||
|
||||
const name = prompt("Name ? ")
|
||||
<button
|
||||
id="new-level"
|
||||
onClick={() => {
|
||||
const name = prompt("Name ? ");
|
||||
if (!name) return;
|
||||
|
||||
setLevels(l => [...l, {
|
||||
setLevels((l) => [
|
||||
...l,
|
||||
{
|
||||
name,
|
||||
size: 8,
|
||||
bricks: '________________________________________________________________',
|
||||
bricks:
|
||||
"________________________________________________________________",
|
||||
svg: null,
|
||||
color: ''
|
||||
}])
|
||||
|
||||
}}>new
|
||||
color: "",
|
||||
},
|
||||
]);
|
||||
}}
|
||||
>
|
||||
new
|
||||
</button>
|
||||
</div>;
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const root = createRoot(document.getElementById('app') as HTMLDivElement);
|
||||
const root = createRoot(document.getElementById("app") as HTMLDivElement);
|
||||
root.render(<App />);
|
|
@ -1,48 +1,55 @@
|
|||
import { RawLevel } from "./types";
|
||||
|
||||
export function resizeLevel(level: RawLevel, sizeDelta: number) {
|
||||
const {size, bricks} = level
|
||||
const newSize = Math.max(1, size + sizeDelta)
|
||||
const newBricks = []
|
||||
const { size, bricks } = level;
|
||||
const newSize = Math.max(1, size + sizeDelta);
|
||||
const newBricks = [];
|
||||
for (let x = 0; x < newSize; x++) {
|
||||
for (let y = 0; y < newSize; y++) {
|
||||
newBricks[y * newSize + x] = brickAt(level, x, y )
|
||||
newBricks[y * newSize + x] = brickAt(level, x, y);
|
||||
}
|
||||
}
|
||||
return {
|
||||
size: newSize,
|
||||
bricks: newBricks.join('')
|
||||
}
|
||||
bricks: newBricks.join(""),
|
||||
};
|
||||
}
|
||||
|
||||
export function brickAt(level: RawLevel, x: number, y: number) {
|
||||
return x>=0 && x < level.size && y>= 0 && y< level.size && level.bricks.split('')[y * level.size + x] || '_'
|
||||
return (
|
||||
(x >= 0 &&
|
||||
x < level.size &&
|
||||
y >= 0 &&
|
||||
y < level.size &&
|
||||
level.bricks.split("")[y * level.size + x]) ||
|
||||
"_"
|
||||
);
|
||||
}
|
||||
|
||||
export function moveLevel(level: RawLevel, dx: number, dy: number) {
|
||||
const {size} = level
|
||||
const newBricks = new Array(size * size).fill('_')
|
||||
const { size } = level;
|
||||
const newBricks = new Array(size * size).fill("_");
|
||||
for (let x = 0; x < size; x++) {
|
||||
for (let y = 0; y < size; y++) {
|
||||
newBricks[y * size + x] = brickAt(level, x - dx, y - dy)
|
||||
newBricks[y * size + x] = brickAt(level, x - dx, y - dy);
|
||||
}
|
||||
}
|
||||
return {
|
||||
bricks: newBricks.join('')
|
||||
}
|
||||
bricks: newBricks.join(""),
|
||||
};
|
||||
}
|
||||
|
||||
export function setBrick(level: RawLevel, index: number, colorCode: string) {
|
||||
console.log('setBrick', level.name, index, colorCode)
|
||||
const {size} = level
|
||||
const newBricks=[]
|
||||
const { size } = level;
|
||||
const newBricks = [];
|
||||
for (let x = 0; x < size; x++) {
|
||||
for (let y = 0; y < size; y++) {
|
||||
const brickIndex=y * size + x
|
||||
newBricks[brickIndex] = (brickIndex === index && colorCode ) || brickAt(level, x , y)
|
||||
const brickIndex = y * size + x;
|
||||
newBricks[brickIndex] =
|
||||
(brickIndex === index && colorCode) || brickAt(level, x, y);
|
||||
}
|
||||
}
|
||||
return {
|
||||
bricks: newBricks.join('')
|
||||
}
|
||||
bricks: newBricks.join(""),
|
||||
};
|
||||
}
|
|
@ -1,28 +1,35 @@
|
|||
|
||||
import _palette from "./palette.json";
|
||||
import _rawLevelsList from "./levels.json";
|
||||
import _appVersion from "./version.json";
|
||||
|
||||
describe('json data checks', ()=>{
|
||||
it('_rawLevelsList has icon levels', ()=>{
|
||||
expect(_rawLevelsList.filter(l=>l.name.startsWith('icon:')).length).toBeGreaterThan(10)
|
||||
})
|
||||
it('_rawLevelsList has non-icon few levels', ()=>{
|
||||
expect(_rawLevelsList.filter(l=>!l.name.startsWith('icon:')).length).toBeGreaterThan(10)
|
||||
})
|
||||
describe("json data checks", () => {
|
||||
it("_rawLevelsList has icon levels", () => {
|
||||
expect(
|
||||
_rawLevelsList.filter((l) => l.name.startsWith("icon:")).length,
|
||||
).toBeGreaterThan(10);
|
||||
});
|
||||
it("_rawLevelsList has non-icon few levels", () => {
|
||||
expect(
|
||||
_rawLevelsList.filter((l) => !l.name.startsWith("icon:")).length,
|
||||
).toBeGreaterThan(10);
|
||||
});
|
||||
|
||||
it('_rawLevelsList has max 5 colors per level', ()=>{
|
||||
const levelsWithManyBrickColors=_rawLevelsList.filter(l=>{
|
||||
|
||||
const uniqueBricks = l.bricks.split('').filter(b=>b!=='_' && b!=='black').filter((a,b,c)=>c.indexOf(a)===b)
|
||||
return uniqueBricks.length>5
|
||||
}).map(l=>l.name)
|
||||
expect(levelsWithManyBrickColors).toEqual([])
|
||||
})
|
||||
it('Has a few colors', ()=>{
|
||||
expect(Object.keys(_palette).length).toBeGreaterThan(10)
|
||||
})
|
||||
it('Has an _appVersion', ()=>{
|
||||
expect(parseInt(_appVersion)).toBeGreaterThan(2000)
|
||||
})
|
||||
it("_rawLevelsList has max 5 colors per level", () => {
|
||||
const levelsWithManyBrickColors = _rawLevelsList
|
||||
.filter((l) => {
|
||||
const uniqueBricks = l.bricks
|
||||
.split("")
|
||||
.filter((b) => b !== "_" && b !== "black")
|
||||
.filter((a, b, c) => c.indexOf(a) === b);
|
||||
return uniqueBricks.length > 5;
|
||||
})
|
||||
.map((l) => l.name);
|
||||
expect(levelsWithManyBrickColors).toEqual([]);
|
||||
});
|
||||
it("Has a few colors", () => {
|
||||
expect(Object.keys(_palette).length).toBeGreaterThan(10);
|
||||
});
|
||||
it("Has an _appVersion", () => {
|
||||
expect(parseInt(_appVersion)).toBeGreaterThan(2000);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,11 +16,7 @@ const levelIconHTMLCanvasCtx = levelIconHTMLCanvas.getContext("2d", {
|
|||
alpha: true,
|
||||
}) as CanvasRenderingContext2D;
|
||||
|
||||
function levelIconHTML(
|
||||
bricks: string[],
|
||||
levelSize: number,
|
||||
color: string,
|
||||
) {
|
||||
function levelIconHTML(bricks: string[], levelSize: number, color: string) {
|
||||
const size = 40;
|
||||
const c = levelIconHTMLCanvas;
|
||||
const ctx = levelIconHTMLCanvasCtx;
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
"name": "Breakout 71",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icon-512.png",
|
||||
"src": "icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/icon-128.png",
|
||||
"src": "icon-128.png",
|
||||
"sizes": "128x128",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/icon-64.png",
|
||||
"src": "icon-64.png",
|
||||
"sizes": "64x64",
|
||||
"type": "image/png"
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ export const options = {
|
|||
disabled() {
|
||||
return window.location.search.includes("isInWebView=true");
|
||||
},
|
||||
}
|
||||
},
|
||||
} as const satisfies { [k: string]: OptionDef };
|
||||
|
||||
export type OptionDef = {
|
||||
|
|
|
@ -7,10 +7,12 @@ export function resetBalls(gameState: GameState) {
|
|||
gameState.balls = [];
|
||||
gameState.ballsColor = "#FFF";
|
||||
if (gameState.perks.picky_eater || gameState.perks.pierce_color) {
|
||||
gameState.ballsColor = getMajorityValue(gameState.bricks.filter((i) => i)) || "#FFF";
|
||||
gameState.ballsColor =
|
||||
getMajorityValue(gameState.bricks.filter((i) => i)) || "#FFF";
|
||||
}
|
||||
for (let i = 0; i < count; i++) {
|
||||
const x = gameState.puckPosition - gameState.puckWidth / 2 + perBall * (i + 1);
|
||||
const x =
|
||||
gameState.puckPosition - gameState.puckWidth / 2 + perBall * (i + 1);
|
||||
const vx = Math.random() > 0.5 ? gameState.baseSpeed : -gameState.baseSpeed;
|
||||
|
||||
gameState.balls.push({
|
||||
|
@ -40,7 +42,8 @@ export function putBallsAtPuck(gameState: GameState) {
|
|||
const count = gameState.balls.length;
|
||||
const perBall = gameState.puckWidth / (count + 1);
|
||||
gameState.balls.forEach((ball, i) => {
|
||||
const x = gameState.puckPosition - gameState.puckWidth / 2 + perBall * (i + 1);
|
||||
const x =
|
||||
gameState.puckPosition - gameState.puckWidth / 2 + perBall * (i + 1);
|
||||
ball.x = x;
|
||||
ball.previousX = x;
|
||||
ball.y = gameState.gameZoneHeight - 1.5 * gameState.ballSize;
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
import {
|
||||
gameState,
|
||||
isSettingOn,
|
||||
} from "./game";
|
||||
import { gameState, isSettingOn } from "./game";
|
||||
|
||||
export const sounds = {
|
||||
wallBeep: (pan: number) => {
|
||||
|
@ -42,9 +39,9 @@ export const sounds = {
|
|||
createSingleBounceSound(900, pixelsToPan(pan), 0.8, 0.1, "triangle");
|
||||
},
|
||||
colorChange(pan: number, volume: number) {
|
||||
createSingleBounceSound(400, pixelsToPan(pan), volume , 0.5, "sine")
|
||||
createSingleBounceSound(800, pixelsToPan(pan), volume * 0.5, 0.2, "square")
|
||||
}
|
||||
createSingleBounceSound(400, pixelsToPan(pan), volume, 0.5, "sine");
|
||||
createSingleBounceSound(800, pixelsToPan(pan), volume * 0.5, 0.2, "square");
|
||||
},
|
||||
};
|
||||
|
||||
// How to play the code on the leftconst context = new window.AudioContext();
|
||||
|
@ -162,7 +159,10 @@ function createExplosionSound(pan = 0.5) {
|
|||
function pixelsToPan(pan: number) {
|
||||
return Math.max(
|
||||
0,
|
||||
Math.min(1, (pan - gameState.offsetXRoundedDown) / gameState.gameZoneWidthRoundedUp),
|
||||
Math.min(
|
||||
1,
|
||||
(pan - gameState.offsetXRoundedDown) / gameState.gameZoneWidthRoundedUp,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
// The version of the cache.
|
||||
const VERSION = '29032991'
|
||||
const VERSION = "29033834";
|
||||
|
||||
// The name of the cache
|
||||
const CACHE_NAME = `breakout-71-${VERSION}`;
|
||||
|
||||
// The static resources that the app needs to function.
|
||||
const APP_STATIC_RESOURCES = [
|
||||
"/"
|
||||
];
|
||||
const APP_STATIC_RESOURCES = ["/"];
|
||||
|
||||
// On install, cache the static resources
|
||||
self.addEventListener("install", (event) => {
|
||||
|
@ -37,7 +35,10 @@ self.addEventListener("activate", (event) => {
|
|||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
if (event.request.mode === "navigate" && event.request.url.endsWith('/index.html?isPWA=true')) {
|
||||
if (
|
||||
event.request.mode === "navigate" &&
|
||||
event.request.url.endsWith("/index.html?isPWA=true")
|
||||
) {
|
||||
event.respondWith(caches.match("/"));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
if ("serviceWorker" in navigator &&
|
||||
window.location.search.includes("isPWA=true")) {
|
||||
if (
|
||||
"serviceWorker" in navigator &&
|
||||
window.location.search.includes("isPWA=true")
|
||||
) {
|
||||
// @ts-ignore
|
||||
navigator.serviceWorker.register(new URL('sw-b71.js', import.meta.url));
|
||||
navigator.serviceWorker.register(new URL("sw-b71.js", import.meta.url));
|
||||
}
|
6
src/types.d.ts
vendored
|
@ -234,10 +234,10 @@ export type GameState = {
|
|||
lastOffered: Partial<{ [k in PerkId]: number }>;
|
||||
levelTime: number;
|
||||
autoCleanUses: number;
|
||||
}
|
||||
};
|
||||
|
||||
export type RunParams = {
|
||||
level?: string;
|
||||
levelToAvoid?: string;
|
||||
perks?: Partial<PerksMap>
|
||||
}
|
||||
perks?: Partial<PerksMap>;
|
||||
};
|
||||
|
|
|
@ -1 +1 @@
|
|||
"29030875"
|
||||
"29033834"
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
versionCode=$(($(date +%s) / 60))
|
||||
|
||||
bash ./build.sh $versionCode
|
||||
|
||||
|
||||
# we don't add a version tag to let fdroid ignore this build
|
||||
|
||||
# upload to breakout-v3-staging.lecaro.me
|