diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..735982a
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,4 @@
+{
+ "tabWidth": 2,
+ "printWidth": 120
+}
diff --git a/src/actiontext.js b/src/actiontext.js
index dd316c1..73d57df 100644
--- a/src/actiontext.js
+++ b/src/actiontext.js
@@ -7,307 +7,341 @@ const SPIKE_TIMER = 1000;
const MAX_HEIGHT = 250;
class Displayer {
+ constructor(index) {
+ this.index = index;
+ this.id = 0;
+ this.displayedActions = [];
+ this.spike = 0;
+ this.lastAttack = 0;
+ this.lastSpikeAttack = 0;
+ }
- constructor(index) {
- this.index = index;
- this.id = 0;
- this.displayedActions = [];
- this.spike = 0;
- this.lastAttack = 0;
- this.lastSpikeAttack = 0;
- }
-
- displayNewAction(value, atk) {
+ displayNewAction(value, atk) {
+ if (!Config().ENABLE_ACTION_TEXT) return;
- if (!Config().ENABLE_ACTION_TEXT)
- return;
-
- let ctime = (new Date()).getTime();
- let spike_tracker = document.getElementById(`atk_spike_${this.index + 1}`);
- if (ctime - this.lastAttack < SPIKE_TIMER) {
- this.spike += value;
- } else {
- this.spike = value
- }
- if (this.spike >= 10) {
- spike_tracker.classList.remove("fade");
- spike_tracker.classList.add("fade", "in");
- spike_tracker.innerHTML = `${this.spike} SPIKE`;
- this.lastSpikeAttack = ctime;
- setTimeout((time) => {
- if (this.lastSpikeAttack == time) {
- spike_tracker.classList.remove("in");
- setTimeout((remove_from) => {
- remove_from.innerHTML = "";
- }, FADEOUT * 1000, spike_tracker);
- this.spike = 0;
- }
- }, SPIKE_TIMER, ctime);
- }
- this.lastAttack = ctime;
- let action = document.createElement("p");
- action.innerHTML = `+${value}
${atk}`;
- action.setAttribute("id", `atk_text_${this.index + 1}_${this.id++}`);
- action.setAttribute("class", "action-text fade in");
- action.style.textAlign = "center";
- if (value >= 5) {
- action.style.fontSize = "large";
- action.style.fontWeight = "bold";
- }
- if (value >= 10) {
- action.style.color = "red";
- }
- document.getElementById(`atk_div_${this.index + 1}`).prepend(action);
- this.displayedActions.splice(0, 0, action.id);
- setTimeout((ind, id) => {
- try {
- let target = document.getElementById(`atk_text_${ind + 1}_${id - 1}`);
- target.classList.remove("in");
- setTimeout((target) => {
- try {
- this.displayedActions = this.displayedActions.filter((i) => i != target.id);
- target.parentNode.removeChild(target);
- } catch (e) { } // idc
- }, FADEOUT * 1000, target);
- } catch (e) { } // idc
- }, DELAY, this.index, this.id);
+ let ctime = new Date().getTime();
+ let spike_tracker = document.getElementById(`atk_spike_${this.index + 1}`);
+ if (ctime - this.lastAttack < SPIKE_TIMER) {
+ this.spike += value;
+ } else {
+ this.spike = value;
}
-
- reset() {
- for (let action of this.displayedActions) {
- try {
- action.parentNode.removeChild(action);
- } catch (e) { }
- }
- this.displayedActions = [];
- this.id = 0;
+ if (this.spike >= 10) {
+ spike_tracker.classList.remove("fade");
+ spike_tracker.classList.add("fade", "in");
+ spike_tracker.textContent = `${this.spike} SPIKE`;
+ this.lastSpikeAttack = ctime;
+ setTimeout(
+ (time) => {
+ if (this.lastSpikeAttack == time) {
+ spike_tracker.classList.remove("in");
+ setTimeout(
+ (remove_from) => {
+ remove_from.textContent = "";
+ },
+ FADEOUT * 1000,
+ spike_tracker
+ );
+ this.spike = 0;
+ }
+ },
+ SPIKE_TIMER,
+ ctime
+ );
+ }
+ this.lastAttack = ctime;
+ let action = document.createElement("p");
+ action.innerText = `+${value}\n ${atk}`;
+ action.setAttribute("id", `atk_text_${this.index + 1}_${this.id++}`);
+ action.setAttribute("class", "action-text fade in");
+ action.style.textAlign = "center";
+ if (value >= 5) {
+ action.style.fontSize = "large";
+ action.style.fontWeight = "bold";
}
+ if (value >= 10) {
+ action.style.color = "red";
+ }
+ document.getElementById(`atk_div_${this.index + 1}`).prepend(action);
+ this.displayedActions.splice(0, 0, action.id);
+ setTimeout(
+ (ind, id) => {
+ try {
+ let target = document.getElementById(`atk_text_${ind + 1}_${id - 1}`);
+ target.classList.remove("in");
+ setTimeout(
+ (target) => {
+ try {
+ this.displayedActions = this.displayedActions.filter((i) => i != target.id);
+ target.parentNode.removeChild(target);
+ } catch (e) {} // idc
+ },
+ FADEOUT * 1000,
+ target
+ );
+ } catch (e) {} // idc
+ },
+ DELAY,
+ this.index,
+ this.id
+ );
+ }
+ reset() {
+ for (let action of this.displayedActions) {
+ try {
+ action.parentNode.removeChild(action);
+ } catch (e) {}
+ }
+ this.displayedActions = [];
+ this.id = 0;
+ }
}
class DisplayerManager {
- constructor() {
- this.displayers = [];
- }
+ constructor() {
+ this.displayers = [];
+ }
- createDisplayer() {
- let a = new Displayer();
- a.index = this.addDisplayer(a);
- return a;
- }
+ createDisplayer() {
+ let a = new Displayer();
+ a.index = this.addDisplayer(a);
+ return a;
+ }
- addDisplayer(displayer) {
- for (let i = 0; i < this.displayers.length; i++) {
- if (this.displayers[i] == null) {
- this.displayers[i] = displayer;
- return i;
- }
- }
- this.displayers.push(displayer);
- return this.displayers.length - 1;
+ addDisplayer(displayer) {
+ for (let i = 0; i < this.displayers.length; i++) {
+ if (this.displayers[i] == null) {
+ this.displayers[i] = displayer;
+ return i;
+ }
}
+ this.displayers.push(displayer);
+ return this.displayers.length - 1;
+ }
- destroyDisplayer(displayer) {
- for (let i = 0; i < this.displayers.length; i++) {
- if (this.displayers[i] == displayer) {
- this.displayers[i] = null;
- return i;
- }
- }
+ destroyDisplayer(displayer) {
+ for (let i = 0; i < this.displayers.length; i++) {
+ if (this.displayers[i] == displayer) {
+ this.displayers[i] = null;
+ return i;
+ }
}
+ }
}
export const initActionText = () => {
- 'use strict';
- window.displayerManager = new DisplayerManager();
- let lstages = document.getElementsByClassName("lstage");
- if (lstages.length == 0) {
- let canvases = document.querySelectorAll("div#main > canvas"); // who tf uses the same ID for multiple thing smh
- for (let canvas of canvases) {
- let div = document.createElement("div");
- div.setAttribute("class", "lstage");
- canvas.parentNode.insertBefore(div, canvas);
- div.appendChild(canvas);
- }
+ "use strict";
+ window.displayerManager = new DisplayerManager();
+ let lstages = document.getElementsByClassName("lstage");
+ if (lstages.length == 0) {
+ let canvases = document.querySelectorAll("div#main > canvas"); // who tf uses the same ID for multiple thing smh
+ for (let canvas of canvases) {
+ let div = document.createElement("div");
+ div.setAttribute("class", "lstage");
+ canvas.parentNode.insertBefore(div, canvas);
+ div.appendChild(canvas);
}
- lstages = document.getElementsByClassName("lstage");
- for (let i = 1; i <= lstages.length; i++) {
- let lstage = lstages[i - 1];
- let num = window.displayerManager.createDisplayer();
- let spike_tracker = document.createElement("p");
- spike_tracker.setAttribute("id", `atk_spike_${num.index + 1}`);
- spike_tracker.setAttribute("style", `max-width: 96px; color: yellow; font-weight: bold;`);
- spike_tracker.setAttribute("class", "spike-tracker fade in");
- lstage.appendChild(spike_tracker);
- let atkdiv = document.createElement("div");
- atkdiv.setAttribute("style", `max-width: 96px; max-height: ${MAX_HEIGHT}px; overflow: hidden; padding: 5px;`);
- atkdiv.setAttribute("id", `atk_div_${num.index + 1}`);
- lstage.appendChild(atkdiv);
- }
- if (typeof trim != "function") { var trim = a => { a = a.slice(0, -1); a = a.substr(a.indexOf("{") + 1); return a } }
- if (typeof getArgs != "function") {
- var getArgs = a => {
- let args = a.toString().match(/function\s*(?:[_a-zA-Z]\w*\s*)?\(((?:(?:[_a-zA-Z]\w*)\s*,\s*?)*(?:[_a-zA-Z]\w*)?)\)/);
- if (args.length > 1) return args[1].split(/\s*,\s*/g);
- return [];
- }
- }
- let displayActionText = function () {
- try {
- let parseCanvasName = function (name) {
- let number = name.match(/(\d+)$/);
- if (number === null) return 1; // no number, assume is first player
- return parseInt(number[0]);
- }
-
+ }
+ lstages = document.getElementsByClassName("lstage");
+ for (let i = 1; i <= lstages.length; i++) {
+ let lstage = lstages[i - 1];
+ let num = window.displayerManager.createDisplayer();
+ let spike_tracker = document.createElement("p");
+ spike_tracker.setAttribute("id", `atk_spike_${num.index + 1}`);
+ spike_tracker.setAttribute("style", `max-width: 96px; color: yellow; font-weight: bold;`);
+ spike_tracker.setAttribute("class", "spike-tracker fade in");
+ lstage.appendChild(spike_tracker);
+ let atkdiv = document.createElement("div");
+ atkdiv.setAttribute("style", `max-width: 96px; max-height: ${MAX_HEIGHT}px; overflow: hidden; padding: 5px;`);
+ atkdiv.setAttribute("id", `atk_div_${num.index + 1}`);
+ lstage.appendChild(atkdiv);
+ }
+ if (typeof trim != "function") {
+ var trim = (a) => {
+ a = a.slice(0, -1);
+ a = a.substr(a.indexOf("{") + 1);
+ return a;
+ };
+ }
+ if (typeof getArgs != "function") {
+ var getArgs = (a) => {
+ let args = a
+ .toString()
+ .match(/function\s*(?:[_a-zA-Z]\w*\s*)?\(((?:(?:[_a-zA-Z]\w*)\s*,\s*?)*(?:[_a-zA-Z]\w*)?)\)/);
+ if (args.length > 1) return args[1].split(/\s*,\s*/g);
+ return [];
+ };
+ }
+ let displayActionText = function () {
+ try {
+ let parseCanvasName = function (name) {
+ let number = name.match(/(\d+)$/);
+ if (number === null) return 1; // no number, assume is first player
+ return parseInt(number[0]);
+ };
- let IS_BOT = false;
- let playerNum;
- switch (this.v.constructor.name) {
- case "Ctx2DView":
- case "View":
- playerNum = parseCanvasName(this.v.ctx.canvas.id) - 1;
- break;
- case "WebGLView":
- playerNum = parseCanvasName(this.v.ctxs[0].elem.id) - 1;
- break;
- case "SlotView":
- IS_BOT = !!(this.p && this.p.bot && this.p.bot.IS_BOT);
- playerNum = (this.v.displayer) ? this.v.displayer.index : -1;
- break;
- default:
- console.log("Uhoh looks like something unknown happened >.<");
- break;
- }
+ let IS_BOT = false;
+ let playerNum;
+ switch (this.v.constructor.name) {
+ case "Ctx2DView":
+ case "View":
+ playerNum = parseCanvasName(this.v.ctx.canvas.id) - 1;
+ break;
+ case "WebGLView":
+ playerNum = parseCanvasName(this.v.ctxs[0].elem.id) - 1;
+ break;
+ case "SlotView":
+ IS_BOT = !!(this.p && this.p.bot && this.p.bot.IS_BOT);
+ playerNum = this.v.displayer ? this.v.displayer.index : -1;
+ break;
+ default:
+ console.log("Uhoh looks like something unknown happened >.<");
+ break;
+ }
- if (IS_BOT || (this.clock !== 0 && playerNum !== -1)) {
- if (!this.displayer) {
- this.displayer = window.displayerManager.displayers[playerNum];
- }
+ if (IS_BOT || (this.clock !== 0 && playerNum !== -1)) {
+ if (!this.displayer) {
+ this.displayer = window.displayerManager.displayers[playerNum];
+ }
- // generate clear text string
- let clearText;
- if (type !== this.Scoring.A.PERFECT_CLEAR) {
- let lcNames = ["", "Single", "Double", "Triple", "Quad", "Multi"];
- clearText = lcNames[Math.min(linesCleared, 5)];
+ // generate clear text string
+ let clearText;
+ if (type !== this.Scoring.A.PERFECT_CLEAR) {
+ let lcNames = ["", "Single", "Double", "Triple", "Quad", "Multi"];
+ clearText = lcNames[Math.min(linesCleared, 5)];
- let blockName = this.blockSets[this.activeBlock.set].blocks[this.activeBlock.id].name;
- if (this.spinPossible) clearText = blockName + "‑Spin " + clearText; // ‑ is non-breaking hyphen, is non-brekaing space
- else if (this.spinMiniPossible) clearText = blockName + "‑Spin " + clearText + " Mini";
- }
- else {
- clearText = "Perfect Clear!";
- }
+ let blockName = this.blockSets[this.activeBlock.set].blocks[this.activeBlock.id].name;
+ if (this.spinPossible) clearText = blockName + "‑Spin " + clearText;
+ // ‑ is non-breaking hyphen, is non-brekaing space
+ else if (this.spinMiniPossible) clearText = blockName + "‑Spin " + clearText + " Mini";
+ } else {
+ clearText = "Perfect Clear!";
+ }
- if (b2b && this.isBack2Back) clearText = "B2B " + clearText;
- if (cmb > 0) clearText += ` combo${cmb}`;
+ if (b2b && this.isBack2Back) clearText = "B2B " + clearText;
+ if (cmb > 0) clearText += ` combo${cmb}`;
- this.displayer.displayNewAction(atk + cba, clearText);
- }
- } catch (e) { console.log(e); }
+ this.displayer.displayNewAction(atk + cba, clearText);
+ }
+ } catch (e) {
+ console.log(e);
}
- try {
+ };
+ try {
+ let functionStr = trim(GameCore.prototype.checkLineClears.toString());
- let functionStr = trim(GameCore.prototype.checkLineClears.toString());
-
- const linesClearedPattern = /switch\((_0x[a-f0-9]+)\)/
- const matchLineClearCheck = functionStr.match(linesClearedPattern);
- if (!matchLineClearCheck) {
- console.log("action text injection failed.");
- }
+ const linesClearedPattern = /switch\((_0x[a-f0-9]+)\)/;
+ const matchLineClearCheck = functionStr.match(linesClearedPattern);
+ if (!matchLineClearCheck) {
+ console.log("action text injection failed.");
+ }
- // find switch(linesCleared) to get linesCleared variable
- functionStr = functionStr.replace(linesClearedPattern, (_, p1) => `let linesCleared=${p1}; switch(${p1})`);
+ // find switch(linesCleared) to get linesCleared variable
+ functionStr = functionStr.replace(linesClearedPattern, (_, p1) => `let linesCleared=${p1}; switch(${p1})`);
- // insert displayActionText after the following code:
- // ... atk, cba);
- // let atkMeta={type:_,b2b:this._,cmb:this._};
- let replacePattern = /(_0x[a-f0-9]+),(_0x[a-f0-9]+)\);let (_0x[a-f0-9]+)=\{'type':_0x[a-f0-9]+,'b2b':this\[.*\],'cmb':this\[.*\]};/;
+ // insert displayActionText after the following code:
+ // ... atk, cba);
+ // let atkMeta={type:_,b2b:this._,cmb:this._};
+ let replacePattern =
+ /(_0x[a-f0-9]+),(_0x[a-f0-9]+)\);let (_0x[a-f0-9]+)=\{'type':_0x[a-f0-9]+,'b2b':this\[.*\],'cmb':this\[.*\]};/;
- const matchCheck = functionStr.match(replacePattern);
- if (!matchCheck) {
- console.log("action text injection failed.");
- }
+ const matchCheck = functionStr.match(replacePattern);
+ if (!matchCheck) {
+ console.log("action text injection failed.");
+ }
- let replacer = function (match, atk, cba, atkMeta) {
- console.log('replacing yay')
- return match + `
+ let replacer = function (match, atk, cba, atkMeta) {
+ console.log("replacing yay");
+ return (
+ match +
+ `
let atk = ${atk};
let cba = ${cba};
let type = ${atkMeta}.type;
let b2b = ${atkMeta}.b2b;
let cmb = ${atkMeta}.cmb;
- `
- + trim(displayActionText.toString());
- }
- functionStr = functionStr.replace(replacePattern, replacer);
+ ` +
+ trim(displayActionText.toString())
+ );
+ };
+ functionStr = functionStr.replace(replacePattern, replacer);
- GameCore.prototype.checkLineClears = new Function(...getArgs(GameCore.prototype.checkLineClears), functionStr);
- console.log(functionStr);
- } catch (e) {
- console.log(e); 7
- console.log("Could not inject into line clears!");
- }
- try {
- Replayer.prototype.checkLineClears = function (a) {
- GameCore.prototype.checkLineClears.call(this, a);
- }
- const oldInitReplay = Replayer.prototype.initReplay
- Replayer.prototype.initReplay = function () {
- try {
- if (this.v.displayer && this.v.displayer.reset)
- this.v.displayer.reset()
- } catch (e) {
- console.log(e);
- }
- return oldInitReplay.apply(this, arguments);
- }
- } catch (e) {
+ GameCore.prototype.checkLineClears = new Function(...getArgs(GameCore.prototype.checkLineClears), functionStr);
+ console.log(functionStr);
+ } catch (e) {
+ console.log(e);
+ 7;
+ console.log("Could not inject into line clears!");
+ }
+ try {
+ Replayer.prototype.checkLineClears = function (a) {
+ GameCore.prototype.checkLineClears.call(this, a);
+ };
+ const oldInitReplay = Replayer.prototype.initReplay;
+ Replayer.prototype.initReplay = function () {
+ try {
+ if (this.v.displayer && this.v.displayer.reset) this.v.displayer.reset();
+ } catch (e) {
console.log(e);
- console.log("Could not inject into line clears!");
- }
- try {
- SlotView.prototype.onResized = function () {
- this.block_size = this.slot.gs.liveBlockSize;
- this.holdQueueBlockSize = this.slot.gs.holdQueueBlockSize;
- this.drawBgGrid();
- this.clearMainCanvas();
- if (this.slot.gs.isExtended) {
- this.QueueHoldEnabled = true;
- this.holdCanvas.style.display = 'block';
- this.queueCanvas.style.display = 'block';
- if (shouldRenderEffectsOnView(this)) {
- if (this.displayer === undefined) {
- this.displayer = window.displayerManager.createDisplayer();
- }
- try {
- let top = this.holdCanvas.height + parseInt(this.holdCanvas.style.top);
- let left = parseInt(this.holdCanvas.style.left);
- if (!document.getElementById(`atk_spike_${this.displayer.index + 1}`)) {
- let spike_tracker = document.createElement("p");
- spike_tracker.setAttribute("class", "layer fade in");
- spike_tracker.setAttribute("style", `top: ${top}px; left: ${left}px; width: ${this.holdCanvas.width}px; height: 20px; color: yellow; font-weight: bold;`);
- spike_tracker.setAttribute("id", `atk_spike_${this.displayer.index + 1}`);
- this.holdCanvas.parentNode.appendChild(spike_tracker);
-
- }
- if (!document.getElementById(`atk_div_${this.displayer.index + 1}`)) {
- let atkdiv = document.createElement("div");
- atkdiv.setAttribute("class", "layer");
- atkdiv.setAttribute("style", `top: ${top + 40}px; left: ${left}px; width: ${this.holdCanvas.width}px; max-height: ${MAX_HEIGHT}px; overflow: hidden;`);
- atkdiv.setAttribute("id", `atk_div_${this.displayer.index + 1}`);
- this.holdCanvas.parentNode.appendChild(atkdiv);
- }
- } catch (e) { console.log(e); }
- }
- } else {
- this.QueueHoldEnabled = false;
- this.holdCanvas.style.display = 'none';
- this.queueCanvas.style.display = 'none';
+ }
+ return oldInitReplay.apply(this, arguments);
+ };
+ } catch (e) {
+ console.log(e);
+ console.log("Could not inject into line clears!");
+ }
+ try {
+ SlotView.prototype.onResized = function () {
+ this.block_size = this.slot.gs.liveBlockSize;
+ this.holdQueueBlockSize = this.slot.gs.holdQueueBlockSize;
+ this.drawBgGrid();
+ this.clearMainCanvas();
+ if (this.slot.gs.isExtended) {
+ this.QueueHoldEnabled = true;
+ this.holdCanvas.style.display = "block";
+ this.queueCanvas.style.display = "block";
+ if (shouldRenderEffectsOnView(this)) {
+ if (this.displayer === undefined) {
+ this.displayer = window.displayerManager.createDisplayer();
+ }
+ try {
+ let top = this.holdCanvas.height + parseInt(this.holdCanvas.style.top);
+ let left = parseInt(this.holdCanvas.style.left);
+ if (!document.getElementById(`atk_spike_${this.displayer.index + 1}`)) {
+ let spike_tracker = document.createElement("p");
+ spike_tracker.setAttribute("class", "layer fade in");
+ spike_tracker.setAttribute(
+ "style",
+ `top: ${top}px; left: ${left}px; width: ${this.holdCanvas.width}px; height: 20px; color: yellow; font-weight: bold;`
+ );
+ spike_tracker.setAttribute("id", `atk_spike_${this.displayer.index + 1}`);
+ this.holdCanvas.parentNode.appendChild(spike_tracker);
}
- };
- } catch (e) {
- console.log(e);
- console.log("Could not inject into SlotView!");
- }
+ if (!document.getElementById(`atk_div_${this.displayer.index + 1}`)) {
+ let atkdiv = document.createElement("div");
+ atkdiv.setAttribute("class", "layer");
+ atkdiv.setAttribute(
+ "style",
+ `top: ${top + 40}px; left: ${left}px; width: ${
+ this.holdCanvas.width
+ }px; max-height: ${MAX_HEIGHT}px; overflow: hidden;`
+ );
+ atkdiv.setAttribute("id", `atk_div_${this.displayer.index + 1}`);
+ this.holdCanvas.parentNode.appendChild(atkdiv);
+ }
+ } catch (e) {
+ console.log(e);
+ }
+ }
+ } else {
+ this.QueueHoldEnabled = false;
+ this.holdCanvas.style.display = "none";
+ this.queueCanvas.style.display = "none";
+ }
+ };
+ } catch (e) {
+ console.log(e);
+ console.log("Could not inject into SlotView!");
+ }
};
diff --git a/src/automatic_replay_codes.js b/src/automatic_replay_codes.js
index 88daeb4..5432659 100644
--- a/src/automatic_replay_codes.js
+++ b/src/automatic_replay_codes.js
@@ -1,41 +1,54 @@
import { Config } from "./config";
export const initAutomaticReplayCodes = () => {
- window.copyReplayText = function (number) {
- var copyText = document.getElementById("replay" + number);
- copyText.select();
- document.execCommand("copy");
- document.getElementById("replayButton" + number).innerHTML = "Copied!"
+ window.copyReplayText = function (number) {
+ var copyText = document.getElementById(`replay${number}`);
+ var copyButton = document.getElementById(`replayButton${number}`);
+ navigator.clipboard
+ .writeText(copyText.value)
+ .then(() => {
+ copyButton.textContent = "Copied!";
setTimeout(() => {
- document.getElementById("replayButton" + number).innerHTML = "Copy"
+ copyButton.textContent = "Copy";
}, 1000);
+ })
+ .catch((error) => {
+ console.error(`An error occured while copying text:
+ ${error.message}`);
+ });
+ };
- }
-
- const oldStartPractice = Game.prototype.startPractice;
-
- Game.prototype.startPractice = function() {
-
- //how many pieces should the replay at least have
- let piecesPlacedCutoff = 1
+ const oldStartPractice = Game.prototype.startPractice;
- if (typeof this['replayCounter'] == "undefined") {
- this['replayCounter'] = 1
- }
+ Game.prototype.startPractice = function () {
+ //how many pieces should the replay at least have
+ let piecesPlacedCutoff = 1;
- this['Replay']['getData']();
+ if (typeof this.replayCounter == "undefined") {
+ this.replayCounter = 1;
+ }
- if (this.GameStats.stats.BLOCKS.value > piecesPlacedCutoff && Config().ENABLE_AUTOMATIC_REPLAY_CODES) {
- let replayHTML = "
" + "Fumen code dumped into the chat." + "
" - coderro += `Link` - coderro += '" - this.chatMajorWarning(coderro); - this.chatInput.value = ""; - return - } else if ("/fumen" === msg.substring(0, 6)) { - if (this.p.pmode != 2) { - this.showInChat("Jstris+", "Fumen import only supported in practce mode") - this.chatInput.value = ""; - return - } - let pages = null - try { - pages = decoder.decode(msg.substring(5)) - } catch (error) { - console.log(error) - this.showInChat("Jstris+", error.message) - this.chatInput.value = ""; - return - } - let gamestates = loadFumen(pages) - this.p.loadSaveState(gamestates) - for (let i = this.p.queue.length; i < 7; i++) { - this.p.refillQueue() - } - this.p.redrawAll(); - this.p.saveStates = [] - this.p.addSaveState() - this.p.fumenPages = [] - this.chatInput.value = ""; - this.p.invalidFromSnapshot = true - return - } - const val = chatListener.apply(this, [rawmsg]) - return val + const chatListener = Live.prototype.sendChat; + Live.prototype.sendChat = function (rawmsg) { + var msg = "string" != typeof rawmsg ? this.chatInput.value.replace(/"/g, '\\"') : rawmsg; + if (msg == "/fumen") { + if (this.p.pmode != 2) { + this.showInChat("Jstris+", "Live fumen export only supported in practice mode"); + this.chatInput.value = ""; + return; + } + if (!this.p.fumenPages) { + this.showInChat("Jstris+", "No fumen data available"); + this.chatInput.value = ""; + return; + } + let fumen = encoder.encode(this.p.fumenPages); + var coderro = ` + !${i18n.warning2}!${i18n.repFail}"(Jstris+ Fumen Export) +Fumen code dumped into the chat.
+ Link + + `; + this.chatMajorWarning(coderro); + this.chatInput.value = ""; + return; + } else if ("/fumen" === msg.substring(0, 6)) { + if (this.p.pmode != 2) { + this.showInChat("Jstris+", "Fumen import only supported in practce mode"); + this.chatInput.value = ""; + return; + } + let pages = null; + try { + pages = decoder.decode(msg.substring(5)); + } catch (error) { + console.log(error); + this.showInChat("Jstris+", error.message); + this.chatInput.value = ""; + return; + } + let gamestates = loadFumen(pages); + this.p.loadSaveState(gamestates); + for (let i = this.p.queue.length; i < 7; i++) { + this.p.refillQueue(); + } + this.p.redrawAll(); + this.p.saveStates = []; + this.p.addSaveState(); + this.p.fumenPages = []; + this.chatInput.value = ""; + this.p.invalidFromSnapshot = true; + return; } -} + const val = chatListener.apply(this, [rawmsg]); + return val; + }; +}; export const initReplayerSnapshot = () => { + let repControls = document.getElementById("repControls"); + let skipButton = document.createElement("button"); + skipButton.className = "replay-btn"; + skipButton.textContent = "snapshot"; + let fumenButton = document.createElement("button"); + fumenButton.className = "replay-btn"; + fumenButton.textContent = "fumen"; + let pcButton = document.createElement("button"); + pcButton.className = "replay-btn"; + pcButton.textContent = "pc solver"; + let wellRow1 = document.createElement("div"); + wellRow1.className = "replay-btn-group"; + let injected = false; + const lR = ReplayController.prototype.loadReplay; + ReplayController.prototype.loadReplay = function () { + if (!injected && this.g.length == 1) { + // let well = document.createElement("div") + // well.className = 'well' - let repControls = document.getElementById("repControls") - let skipButton = document.createElement("button") - skipButton.className = "replay-btn" - skipButton.textContent = "snapshot" - let fumenButton = document.createElement("button") - fumenButton.className = "replay-btn" - fumenButton.textContent = "fumen" - let pcButton = document.createElement("button") - pcButton.className = "replay-btn" - pcButton.textContent = "pc solver" - let wellRow1 = document.createElement("div") - wellRow1.className = "replay-btn-group" - let injected = false - const lR = ReplayController.prototype.loadReplay - ReplayController.prototype.loadReplay = function () { - if (!injected && this.g.length == 1) { - // let well = document.createElement("div") - // well.className = 'well' - - - // well.appendChild(wellRow1) - Replayer.prototype.generateFumenQueue = generateFumenQueue.bind(this.g[0]) - Replayer.prototype.generateFumenMatrix = generateFumenMatrix.bind(this.g[0]) - repControls.appendChild(wellRow1) - wellRow1.appendChild(skipButton) - wellRow1.appendChild(fumenButton) - - skipButton.onclick = () => { - let code = this.g[0].snapshotPlus() - window.open(`https://jstris.jezevec10.com/?play=2&snapshotPlus=${code}`, '_blank') - } - pcButton.onclick = () => { - let code = this.g[0].snapshotFumen() - window.open(`https://wirelyre.github.io/tetra-tools/pc-solver.html?fumen=${encodeURIComponent(code)}`, '_blank') - } - fumenButton.onclick = () => { - let rep = document.getElementById('rep0').value - fumenButton.disabled = true - fumenButton.textContent = "loading" - fetch(`https://fumen.tstman.net/jstris`, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: `replay=${rep}` - }).then((response) => response.json()) - .then((data) => { - navigator.clipboard.writeText(data.fumen).then(() => { - fumenButton.textContent = "copied" - }).catch((err) => { - fumenButton.textContent = `err ${err}` - }).finally(() => { - if (data.fumen.length < 8168) { - let newWin = window.open(`https://harddrop.com/fumen/?${data.fumen}`, '_blank') - } - let textArea = document.createElement('textarea') - textArea.className = "repArea" - textArea.rows = 1 - textArea.textContent = data.fumen - let dlButton = document.createElement("button") - dlButton.textContent = "download" - dlButton.className = "replay-btn" - dlButton.onclick = () => { - downloadText('jstrisFumen.txt', data.fumen) - } - let openButton = document.createElement("button") - openButton.textContent = "open" - let fumenLink = `https://harddrop.com/fumen/?${data.fumen}` - if (data.fumen.length >= 8168) { - alert("fumen code too long for url, you'll need to paste the code in manually") - fumenLink = `https://harddrop.com/fumen/?` - } + // well.appendChild(wellRow1) + Replayer.prototype.generateFumenQueue = generateFumenQueue.bind(this.g[0]); + Replayer.prototype.generateFumenMatrix = generateFumenMatrix.bind(this.g[0]); + repControls.appendChild(wellRow1); + wellRow1.appendChild(skipButton); + wellRow1.appendChild(fumenButton); - openButton.className = "replay-btn" - openButton.onclick = () => { - window.open(fumenLink, '_blank') - } - repControls.appendChild(textArea) - repControls.appendChild(dlButton) - repControls.appendChild(openButton) - }); + skipButton.onclick = () => { + let code = this.g[0].snapshotPlus(); + window.open(`https://jstris.jezevec10.com/?play=2&snapshotPlus=${code}`, "_blank"); + }; + pcButton.onclick = () => { + let code = this.g[0].snapshotFumen(); + window.open( + `https://wirelyre.github.io/tetra-tools/pc-solver.html?fumen=${encodeURIComponent(code)}`, + "_blank" + ); + }; + fumenButton.onclick = () => { + let rep = document.getElementById("rep0").value; + fumenButton.disabled = true; + fumenButton.textContent = "loading"; + fetch(`https://fumen.tstman.net/jstris`, { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + body: `replay=${rep}`, + }) + .then((response) => response.json()) + .then((data) => { + navigator.clipboard + .writeText(data.fumen) + .then(() => { + fumenButton.textContent = "copied"; + }) + .catch((err) => { + fumenButton.textContent = `err ${err}`; + }) + .finally(() => { + if (data.fumen.length < 8168) { + let newWin = window.open(`https://harddrop.com/fumen/?${data.fumen}`, "_blank"); + } + let textArea = document.createElement("textarea"); + textArea.className = "repArea"; + textArea.rows = 1; + textArea.textContent = data.fumen; + let dlButton = document.createElement("button"); + dlButton.textContent = "download"; + dlButton.className = "replay-btn"; + dlButton.onclick = () => { + downloadText("jstrisFumen.txt", data.fumen); + }; + let openButton = document.createElement("button"); + openButton.textContent = "open"; + let fumenLink = `https://harddrop.com/fumen/?${data.fumen}`; + if (data.fumen.length >= 8168) { + alert("fumen code too long for url, you'll need to paste the code in manually"); + fumenLink = `https://harddrop.com/fumen/?`; + } - }); - } - injected = true - } - let val = lR.apply(this, arguments) - if (this.g[0].pmode == 8) { - wellRow1.appendChild(pcButton) - } - return val + openButton.className = "replay-btn"; + openButton.onclick = () => { + window.open(fumenLink, "_blank"); + }; + repControls.appendChild(textArea); + repControls.appendChild(dlButton); + repControls.appendChild(openButton); + }); + }); + }; + injected = true; } - Replayer.prototype.snapshotFumen = function () { - - - /* + let val = lR.apply(this, arguments); + if (this.g[0].pmode == 8) { + wellRow1.appendChild(pcButton); + } + return val; + }; + Replayer.prototype.snapshotFumen = function () { + /* let ss = this.activeBlock let x = jstrisToCenterX[ss.id][ss.rot] + this.activeBlock.pos.x let y = 19 - (jstrisToCenterY[ss.id][ss.rot] + this.ghostPiece.pos.y) let msg = { operation: { type: this.blockSets[ss.set].blocks[ss.id].name, rotation: rIndex[ss.rot], x: x, y: y } }*/ - let msg = {} - let fieldStr = this.generateFumenMatrix().substring(170) - let airCount = fieldStr.split('_').length - 1 - msg.field = Field.create(fieldStr) - msg.comment = this.generateFumenQueue().replace(quizFilter, '') - msg.comment = msg.comment.substring(0, Math.floor(airCount / 4) + 1) - console.log(msg) - let code = encoder.encode([msg]) - console.log(code) - return code - } - Replayer.prototype.snapshotPlus = function () { - let matrix = clone(this.matrix) - let deadline = clone(this.deadline) - let placedBlocks = this.placedBlocks - let seed = this.r.c.seed - let activeBlockID = this.activeBlock.id; - let holdID = null - if (this.blockInHold) { - holdID = this.blockInHold.id - } - let rnd = this.R.rnd - return LZString.compressToEncodedURIComponent(JSON.stringify({ - matrix, deadline, placedBlocks, seed, activeBlockID, holdID, rnd - })) + let msg = {}; + let fieldStr = this.generateFumenMatrix().substring(170); + let airCount = fieldStr.split("_").length - 1; + msg.field = Field.create(fieldStr); + msg.comment = this.generateFumenQueue().replace(quizFilter, ""); + msg.comment = msg.comment.substring(0, Math.floor(airCount / 4) + 1); + console.log(msg); + let code = encoder.encode([msg]); + console.log(code); + return code; + }; + Replayer.prototype.snapshotPlus = function () { + let matrix = clone(this.matrix); + let deadline = clone(this.deadline); + let placedBlocks = this.placedBlocks; + let seed = this.r.c.seed; + let activeBlockID = this.activeBlock.id; + let holdID = null; + if (this.blockInHold) { + holdID = this.blockInHold.id; } -} + let rnd = this.R.rnd; + return LZString.compressToEncodedURIComponent( + JSON.stringify({ + matrix, + deadline, + placedBlocks, + seed, + activeBlockID, + holdID, + rnd, + }) + ); + }; +}; export const loadFumen = (pages) => { - - const page = pages[pages.length - 1] - const field = page.field - let matrix = Array(20).fill().map(() => Array(10).fill(0)) - let deadline = Array(10).fill(0) - let activeBlock = new Block(0) - let hold = null, queue = [] - if (page.flags.quiz) { - let match = /^#Q=\[([LOJSTZI]?)\]?\(([LOJSTZI]?)\)([LOJSTZI]*)$/.exec(page.comment); - console.log(match) - if (match[1]) { - hold = new Block(pIndex.indexOf(match[1])) - } - if (match[2]) { - activeBlock = new Block(pIndex.indexOf(match[2])) - } - if (match[3]) { - for (let char of match[3]) { - queue.push(new Block(pIndex.indexOf(char))) - } - } + const page = pages[pages.length - 1]; + const field = page.field; + let matrix = Array(20) + .fill() + .map(() => Array(10).fill(0)); + let deadline = Array(10).fill(0); + let activeBlock = new Block(0); + let hold = null, + queue = []; + if (page.flags.quiz) { + let match = /^#Q=\[([LOJSTZI]?)\]?\(([LOJSTZI]?)\)([LOJSTZI]*)$/.exec(page.comment); + console.log(match); + if (match[1]) { + hold = new Block(pIndex.indexOf(match[1])); } - - - for (let x = 0; x < 10; x++) { - for (let y = 0; y < 20; y++) { - let v = reverseMatrix.indexOf(field.at(x, y)) - if (v > 0) matrix[19 - y][x] = v - } + if (match[2]) { + activeBlock = new Block(pIndex.indexOf(match[2])); } - for (let x = 0; x < 10; x++) { - let v = reverseMatrix.indexOf(field.at(x, 20)) - if (v > 0) deadline[x] = v + if (match[3]) { + for (let char of match[3]) { + queue.push(new Block(pIndex.indexOf(char))); + } } - let game = { - matrix: matrix, - deadline: deadline, - activeBlock: activeBlock, - blockInHold: hold, - queue: queue, - b2b: 0, - combo: 0, - placedBlocks: 0, - totalFinesse: 0, - totalKeyPresses: 0, - incomingGarbage: [], - redBar: 0, - gamedata: { - "lines": 0, - "singles": 0, - "doubles": 0, - "triples": 0, - "tetrises": 0, - "maxCombo": 0, - "linesSent": 0, - "linesReceived": 9, - "PCs": 0, - "lastPC": 0, - "TSD": 0, - "TSD20": 0, - "B2B": 0, - "attack": 0, - "score": 0, - "holds": 0, - "garbageCleared": 0, - "wasted": 1, - "tpieces": 1, - "tspins": 0 - } + } + + for (let x = 0; x < 10; x++) { + for (let y = 0; y < 20; y++) { + let v = reverseMatrix.indexOf(field.at(x, y)); + if (v > 0) matrix[19 - y][x] = v; } - return game -} \ No newline at end of file + } + for (let x = 0; x < 10; x++) { + let v = reverseMatrix.indexOf(field.at(x, 20)); + if (v > 0) deadline[x] = v; + } + let game = { + matrix: matrix, + deadline: deadline, + activeBlock: activeBlock, + blockInHold: hold, + queue: queue, + b2b: 0, + combo: 0, + placedBlocks: 0, + totalFinesse: 0, + totalKeyPresses: 0, + incomingGarbage: [], + redBar: 0, + gamedata: { + lines: 0, + singles: 0, + doubles: 0, + triples: 0, + tetrises: 0, + maxCombo: 0, + linesSent: 0, + linesReceived: 9, + PCs: 0, + lastPC: 0, + TSD: 0, + TSD20: 0, + B2B: 0, + attack: 0, + score: 0, + holds: 0, + garbageCleared: 0, + wasted: 1, + tpieces: 1, + tspins: 0, + }, + }; + return game; +}; diff --git a/src/practiceSurvivalMode.js b/src/practiceSurvivalMode.js index 80be8b1..98b0023 100644 --- a/src/practiceSurvivalMode.js +++ b/src/practiceSurvivalMode.js @@ -1,28 +1,25 @@ - - export const initPracticeSurvivalMode = () => { - // 60 apm cycle from rivi's usermode const baseCycle = [ - {time: 4, attack: 4}, - {time: 4, attack: 5}, - {time: 4, attack: 2}, - {time: 3, attack: 1}, - {time: 4, attack: 4}, - {time: 4, attack: 4}, - {time: 3, attack: 5}, - {time: 3, attack: 5} - ] + { time: 4, attack: 4 }, + { time: 4, attack: 5 }, + { time: 4, attack: 2 }, + { time: 3, attack: 1 }, + { time: 4, attack: 4 }, + { time: 4, attack: 4 }, + { time: 3, attack: 5 }, + { time: 3, attack: 5 }, + ]; let isCycling = false; let shouldStartCycle = false; let shouldCancel = true; let timeFactor = 1; let hangingTimeout = 0; - + const INIT_MESS = 20; - let setMess = m => null; - const changeAPM = (apm) => timeFactor = 60 / apm; + let setMess = (m) => null; + const changeAPM = (apm) => (timeFactor = 60 / apm); let hasInit = false; @@ -35,29 +32,25 @@ export const initPracticeSurvivalMode = () => { if (!isCycling) return; if (game.pmode != 2) return stopCycle(); game.addIntoGarbageQueue(cycleStep.attack); - doCycle(game, (i+1)%baseCycle.length) + doCycle(game, (i + 1) % baseCycle.length); }, cycleStep.time * timeFactor * 1000); - } + }; const startCycle = (game) => { - if (!isCycling) { isCycling = true; doCycle(game, 0); } - - } + }; const stopCycle = () => { clearTimeout(hangingTimeout); isCycling = false; - } + }; if (typeof Game == "function") { - const oldQueueBoxFunc = Game.prototype.updateQueueBox; Game.prototype.updateQueueBox = function () { - if (this.pmode != 2) - return oldQueueBoxFunc.apply(this, arguments); + if (this.pmode != 2) return oldQueueBoxFunc.apply(this, arguments); return oldQueueBoxFunc.apply(this, arguments); - } + }; const oldLineClears = GameCore.prototype.checkLineClears; GameCore.prototype.checkLineClears = function (x) { let oldAttack = this.gamedata.attack; @@ -68,23 +61,19 @@ export const initPracticeSurvivalMode = () => { if (shouldCancel) { this.blockOrSendAttack(curAttack, x); } - } return val; - } - + }; - const oldReadyGo = Game.prototype.readyGo + const oldReadyGo = Game.prototype.readyGo; Game.prototype.readyGo = function () { - if (this.pmode == 2) { settingsDiv.classList.add("show-practice-mode-settings"); } else { settingsDiv.classList.remove("show-practice-mode-settings"); } - if (shouldStartCycle) - startCycle(this); + if (shouldStartCycle) startCycle(this); if (!hasInit) { let oldOnGameEnd = Settings.prototype.onGameEnd; @@ -92,44 +81,41 @@ export const initPracticeSurvivalMode = () => { this.R.mess = INIT_MESS; } window.game = this; - setMess = m => { + setMess = (m) => { if (this.pmode == 2) { this.R.mess = m; } - } - this.Settings.onGameEnd = function() { + }; + this.Settings.onGameEnd = function () { if (this.p.pmode == 2) { stopCycle(); } - return oldOnGameEnd.apply(this, arguments) - } + return oldOnGameEnd.apply(this, arguments); + }; startStopButton.addEventListener("click", () => { shouldStartCycle = !shouldStartCycle; - + if (shouldStartCycle) { startCycle(this); - startStopButton.innerHTML = "Stop APM Cycle"; + startStopButton.textContent = "Stop APM Cycle"; } else { stopCycle(this); - startStopButton.innerHTML = "Start APM Cycle"; + startStopButton.textContent = "Start APM Cycle"; } - - }) + }); startStopButton.disabled = false; hasInit = true; } - return oldReadyGo.apply(this, arguments) - } - + return oldReadyGo.apply(this, arguments); + }; } - const stage = document.getElementById("stage"); const settingsDiv = document.createElement("DIV"); settingsDiv.id = "customPracticeSettings"; - var slider = document.createElement("input") - slider.type = "range" + var slider = document.createElement("input"); + slider.type = "range"; slider.min = 5; slider.max = 200; slider.step = 5; @@ -148,27 +134,27 @@ export const initPracticeSurvivalMode = () => { valueLabel.addEventListener("change", () => { var num = Number.parseFloat(valueLabel.value); - num = Math.max(5,Math.min(num, 200)); + num = Math.max(5, Math.min(num, 200)); slider.value = num.toFixed(0); valueLabel.value = num; changeAPM(num); }); valueLabel.addEventListener("click", () => { - $(window).trigger('modal-opened'); - }) + $(window).trigger("modal-opened"); + }); var label = document.createElement("label"); label.htmlFor = "customApmSlider"; - label.innerHTML = "APM"; + label.textContent = "APM"; var sliderDiv = document.createElement("div"); sliderDiv.appendChild(label); sliderDiv.appendChild(slider); sliderDiv.appendChild(valueLabel); - var messSlider = document.createElement("input") - messSlider.type = "range" + var messSlider = document.createElement("input"); + messSlider.type = "range"; messSlider.min = 0; messSlider.max = 100; messSlider.step = 1; @@ -187,19 +173,19 @@ export const initPracticeSurvivalMode = () => { messValueLabel.addEventListener("change", () => { var num = Number.parseFloat(messValueLabel.value); - num = Math.max(0,Math.min(num, 100)); + num = Math.max(0, Math.min(num, 100)); messSlider.value = num.toFixed(0); messValueLabel.value = num; setMess(num); }); messValueLabel.addEventListener("click", () => { - $(window).trigger('modal-opened'); - }) + $(window).trigger("modal-opened"); + }); var messLabel = document.createElement("label"); messLabel.htmlFor = "customApmSlider"; - messLabel.innerHTML = "🧀%"; + messLabel.textContent = "🧀%"; var messSliderDiv = document.createElement("div"); messSliderDiv.appendChild(messLabel); @@ -208,7 +194,7 @@ export const initPracticeSurvivalMode = () => { var cancelLabel = document.createElement("label"); cancelLabel.htmlFor = "cancelCheckbox"; - cancelLabel.innerHTML = "Allow cancel"; + cancelLabel.textContent = "Allow cancel"; var cancelCheckbox = document.createElement("input"); cancelCheckbox.type = "checkbox"; @@ -216,21 +202,20 @@ export const initPracticeSurvivalMode = () => { cancelCheckbox.checked = true; cancelCheckbox.addEventListener("change", () => { - shouldCancel = cancelCheckbox.checked - }) + shouldCancel = cancelCheckbox.checked; + }); var cancelDiv = document.createElement("div"); cancelDiv.appendChild(cancelLabel); cancelDiv.appendChild(cancelCheckbox); var startStopButton = document.createElement("button"); - startStopButton.innerHTML = "Start APM Cycle"; + startStopButton.textContent = "Start APM Cycle"; startStopButton.disabled = true; - settingsDiv.innerHTML+="Downstack PracticeCheckout the Jstris Customization Database - for a list of skins and backgrounds to use.
`) + for a list of skins and backgrounds to use.`); createTextInput("BACKGROUND_IMAGE_URL", "Background image url (blank for none)"); @@ -191,14 +191,14 @@ const generateBody = () => { createTitle("Audio settings"); fetchPlusSoundPresets(); - createHTML(CUSTOM_PLUS_SOUND_PRESET_ELEMENT) + createHTML(CUSTOM_PLUS_SOUND_PRESET_ELEMENT); createTextArea("CUSTOM_PLUS_SFX_JSON", "Data for custom plus SFX"); createHTML(``); createCheckbox("ENABLE_OPPONENT_SFX", "Enable opponent SFX"); createSliderInput("OPPONENT_SFX_VOLUME_MULTPLIER", "Opponent SFX volume"); createCheckbox("ENABLE_CUSTOM_SFX", "Enable custom SFX (turning off requires refresh)"); - createHTML(`(Turning off custom sounds may require a refresh)
`) + createHTML(`(Turning off custom sounds may require a refresh)
`); createCheckbox("ENABLE_CUSTOM_VFX", "Enable custom spawn SFX (voice annotations)"); createHTML(`(Custom SFX must be enabled for spawn SFX)
`); @@ -209,7 +209,7 @@ const generateBody = () => { createHTML(`Refer to the guide and the
Jstris Customization Database
- for custom SFX resources.`)
+ for custom SFX resources.`);
createTitle("Custom stats settings");
createCheckbox("ENABLE_STAT_APP", "Enable attack per piece stat (for all modes)");
@@ -222,30 +222,29 @@ const generateBody = () => {
createTitle("Misc settings");
createCheckbox("ENABLE_AUTOMATIC_REPLAY_CODES", "Enable automatic replay code saving on reset");
- createHTML(createKeyInputElement("UNDO_KEYCODE", "keybind to undo moves in practice mode"));
+ createHTML(createKeyInputElement("UNDO_KEY", "keybind to undo moves in practice mode"));
createCheckbox("ENABLE_CHAT_TIMESTAMPS", "Enable chat timestamps");
createCheckbox("SHOW_MM_BUTTON", "Show matchmaking button");
createCheckbox("SHOW_QUEUE_INFO", "Show matchmaking queue info");
- createHTML(createKeyInputElement("TOGGLE_CHAT_KEYCODE", "Open chat with this button"));
- createHTML(createKeyInputElement("CLOSE_CHAT_KEYCODE", "Close chat with this button"));
- createHTML(createKeyInputElement("SCREENSHOT_KEYCODE", "Take a screenshot with this button"));
-}
+ createHTML(createKeyInputElement("TOGGLE_CHAT_KEY", "Open chat with this button"));
+ createHTML(createKeyInputElement("CLOSE_CHAT_KEY", "Close chat with this button"));
+ createHTML(createKeyInputElement("SCREENSHOT_KEY", "Take a screenshot with this button"));
+};
export const initModal = () => {
-
-
// modal UI inject
var modalButton = document.createElement("IMG");
- modalButton.src = "https://media.istockphoto.com/vectors/gear-icon-vector-illustration-vector-id857768248?k=6&m=857768248&s=170667a&w=0&h=p8E79IurGj0VrH8FO3l1-NXmMubUiShDW88xXynZpjE=";
+ modalButton.src =
+ "https://media.istockphoto.com/vectors/gear-icon-vector-illustration-vector-id857768248?k=6&m=857768248&s=170667a&w=0&h=p8E79IurGj0VrH8FO3l1-NXmMubUiShDW88xXynZpjE=";
modalButton.className = "settings-modalOpenButton";
var modalCloseButton = document.createElement("IMG");
- modalCloseButton.src = "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fcdn.onlinewebfonts.com%2Fsvg%2Fimg_324119.png&f=1&nofb=1";
- modalCloseButton.className = "settings-modalCloseButton"
+ modalCloseButton.src =
+ "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fcdn.onlinewebfonts.com%2Fsvg%2Fimg_324119.png&f=1&nofb=1";
+ modalCloseButton.className = "settings-modalCloseButton";
modalButton.addEventListener("click", () => {
- if (typeof ($) == "function")
- $(window).trigger('modal-opened');
+ if (typeof $ == "function") $(window).trigger("modal-opened");
modal.style.display = "flex";
});
modalCloseButton.addEventListener("click", () => {
@@ -258,15 +257,14 @@ export const initModal = () => {
var modalContent = document.createElement("div");
modalContent.className = "settings-modal-content";
-
var modalHeader = document.createElement("div");
modalHeader.className = "settings-modal-header";
var header = document.createElement("h2");
- header.innerHTML = "Jstris+ Settings";
+ header.textContent = "Jstris+ Settings";
modalHeader.appendChild(header);
- modalHeader.appendChild(modalCloseButton)
+ modalHeader.appendChild(modalCloseButton);
var modalBody = document.createElement("div");
modalBody.id = "settingsBody";
@@ -279,7 +277,5 @@ export const initModal = () => {
document.body.appendChild(modal);
document.body.appendChild(modalButton);
-
generateBody();
-
-}
\ No newline at end of file
+};
diff --git a/src/sfxLoader.js b/src/sfxLoader.js
index 3437746..2906344 100644
--- a/src/sfxLoader.js
+++ b/src/sfxLoader.js
@@ -1,25 +1,28 @@
-import { Config } from "./config"
+import { Config } from "./config";
const attemptLoadSFX = function () {
- if (typeof loadSFX == "function") {
- loadSFX(...arguments);
- } else {
- setTimeout(() => attemptLoadSFX(...arguments), 200);
- }
-}
+ if (typeof loadSFX == "function") {
+ loadSFX(...arguments);
+ } else {
+ setTimeout(() => attemptLoadSFX(...arguments), 200);
+ }
+};
const loadSound = (name, url) => {
- if (!name || !url) {
- return;
- }
- let ishta = url.url
- if (ishta) {
-
- let enslee = createjs.Sound.registerSound(ishta, name);
- if (!enslee || !createjs.Sound._idHash[name]) {
- return void console.error("loadSounds error: src parse / cannot init plugins, id=" + name + (false === enslee ? ", rs=false" : ", no _idHash"));
- }
- createjs.Sound._idHash[name].sndObj = url;
+ if (!name || !url) {
+ return;
+ }
+ let ishta = url.url;
+ if (ishta) {
+ let enslee = createjs.Sound.registerSound(ishta, name);
+ if (!enslee || !createjs.Sound._idHash[name]) {
+ return void console.error(
+ "loadSounds error: src parse / cannot init plugins, id=" +
+ name +
+ (false === enslee ? ", rs=false" : ", no _idHash")
+ );
}
+ createjs.Sound._idHash[name].sndObj = url;
+ }
};
/*
@@ -70,44 +73,44 @@ const loadReplayerSFX = function (sfx) {
*/
const loadDefaultSFX = () => {
- console.log("loading default sfx")
- try {
- loadSFX(new window.SFXsets[localStorage["SFXset"]].data());
- } catch (e) { // just in case
- console.log("failed loading default sfx: " + e);
- }
- return;
-}
+ console.log("loading default sfx");
+ try {
+ loadSFX(new window.SFXsets[localStorage["SFXset"]].data());
+ } catch (e) {
+ // just in case
+ console.log("failed loading default sfx: " + e);
+ }
+ return;
+};
const changeSFX = () => {
- var json = Config().CUSTOM_SFX_JSON;
- let sfx = null;
+ var json = Config().CUSTOM_SFX_JSON;
+ let sfx = null;
- if (json) {
- try {
- sfx = JSON.parse(json);
- document.getElementById("custom_sfx_json_err").innerHTML = "Loaded " + (sfx.name || "custom sounds");
- } catch (e) {
- console.log("SFX json was invalid.");
- document.getElementById("custom_sfx_json_err").innerHTML = "SFX json is invalid.";
- }
- } else {
- document.getElementById("custom_sfx_json_err").innerHTML = "";
+ if (json) {
+ try {
+ sfx = JSON.parse(json);
+ document.getElementById("custom_sfx_json_err").textContent = "Loaded " + (sfx.name || "custom sounds");
+ } catch (e) {
+ console.log("SFX json was invalid.");
+ document.getElementById("custom_sfx_json_err").textContent = "SFX json is invalid.";
}
- if (typeof Game == "function") {
- if (!Config().ENABLE_CUSTOM_SFX || !sfx) {
- loadDefaultSFX();
- } else {
- console.log("Changing SFX...");
- console.log(sfx);
-
- let csfx = loadCustomSFX(sfx);
- attemptLoadSFX(csfx)
+ } else {
+ document.getElementById("custom_sfx_json_err").textContent = "";
+ }
+ if (typeof Game == "function") {
+ if (!Config().ENABLE_CUSTOM_SFX || !sfx) {
+ loadDefaultSFX();
+ } else {
+ console.log("Changing SFX...");
+ console.log(sfx);
- }
+ let csfx = loadCustomSFX(sfx);
+ attemptLoadSFX(csfx);
}
+ }
- /*
+ /*
// functionality here now addressed in replayer-sfx.js
if (typeof window.View == "function" && typeof window.Live != "function") { //force sfx on replayers
let onready = View.prototype.onReady
@@ -121,166 +124,182 @@ const changeSFX = () => {
}
}
*/
-}
+};
export const initCustomSFX = () => {
- if (!createjs) return
+ if (!createjs) return;
+ if (typeof Game == "function") {
+ let onnextblock = Game.prototype.getNextBlock;
+ Game.prototype.getNextBlock = function () {
+ if (Config().ENABLE_CUSTOM_VFX) {
+ this.playCurrentPieceSound();
+ }
+ let val = onnextblock.apply(this, arguments);
+ return val;
+ };
+ let onholdblock = Game.prototype.holdBlock;
+ Game.prototype.holdBlock = function () {
+ if (Config().ENABLE_CUSTOM_VFX) {
+ this.playCurrentPieceSound();
+ }
+ let val = onholdblock.apply(this, arguments);
+ return val;
+ };
+ }
- if (typeof Game == "function") {
- let onnextblock = Game.prototype.getNextBlock
- Game.prototype.getNextBlock = function () {
-
- if (Config().ENABLE_CUSTOM_VFX) {
- this.playCurrentPieceSound()
- }
- let val = onnextblock.apply(this, arguments)
- return val
- }
- let onholdblock = Game.prototype.holdBlock
- Game.prototype.holdBlock = function () {
- if (Config().ENABLE_CUSTOM_VFX) {
- this.playCurrentPieceSound()
- }
- let val = onholdblock.apply(this, arguments)
- return val
- }
- }
-
- /* let onPlay = createjs.Sound.play
+ /* let onPlay = createjs.Sound.play
createjs.Sound.play = function () {
console.log(arguments[0])
let val = onPlay.apply(this, arguments)
return val
}*/
- changeSFX(Config().CUSTOM_SFX_JSON)
- Config().onChange("CUSTOM_SFX_JSON", changeSFX);
- Config().onChange("ENABLE_CUSTOM_SFX", changeSFX);
- Config().onChange("ENABLE_CUSTOM_VFX", changeSFX);
- return true
-}
+ changeSFX(Config().CUSTOM_SFX_JSON);
+ Config().onChange("CUSTOM_SFX_JSON", changeSFX);
+ Config().onChange("ENABLE_CUSTOM_SFX", changeSFX);
+ Config().onChange("ENABLE_CUSTOM_VFX", changeSFX);
+ return true;
+};
export const loadCustomSFX = (sfx = {}) => {
- const SOUNDS = ["hold", "linefall", "lock", "harddrop", "rotate", "success", "garbage", "b2b", "land", "move", "died", "ready", "go", "golive", "ding", "msg", "fault", "item", "pickup"]
- let SCORES = [
- "SOFT_DROP",
- "HARD_DROP",
- "CLEAR1",
- "CLEAR2",
- "CLEAR3",
- "CLEAR4",
- "TSPIN_MINI",
- "TSPIN",
- "TSPIN_MINI_SINGLE",
- "TSPIN_SINGLE",
- "TSPIN_DOUBLE",
- "TSPIN_TRIPLE",
- "PERFECT_CLEAR",
- "COMBO",
- "CLEAR5"
- ]
- function CustomSFXset() {
- this.volume = 1
- }
- CustomSFXset.prototype = new BaseSFXset;
- CustomSFXset.prototype.getSoundUrlFromObj = function (obj) {
- return obj.url
- }
+ const SOUNDS = [
+ "hold",
+ "linefall",
+ "lock",
+ "harddrop",
+ "rotate",
+ "success",
+ "garbage",
+ "b2b",
+ "land",
+ "move",
+ "died",
+ "ready",
+ "go",
+ "golive",
+ "ding",
+ "msg",
+ "fault",
+ "item",
+ "pickup",
+ ];
+ let SCORES = [
+ "SOFT_DROP",
+ "HARD_DROP",
+ "CLEAR1",
+ "CLEAR2",
+ "CLEAR3",
+ "CLEAR4",
+ "TSPIN_MINI",
+ "TSPIN",
+ "TSPIN_MINI_SINGLE",
+ "TSPIN_SINGLE",
+ "TSPIN_DOUBLE",
+ "TSPIN_TRIPLE",
+ "PERFECT_CLEAR",
+ "COMBO",
+ "CLEAR5",
+ ];
+ function CustomSFXset() {
+ this.volume = 1;
+ }
+ CustomSFXset.prototype = new BaseSFXset();
+ CustomSFXset.prototype.getSoundUrlFromObj = function (obj) {
+ return obj.url;
+ };
- CustomSFXset.prototype.getClearSFX = function (altClearType, clearType, b2b, combo) {
- let sounds = [],
- prefix = '';
- let specialSound = null
- let override = false
- if (this.specialScoring) {
- let scorings = [this.specialScoring[SCORES[clearType]]]
- if ((clearType > 4 && clearType <= 11) || clearType == 14) {
- if (this.specialScoring.TSPINORTETRIS) {
- scorings.push(this.specialScoring.TSPINORTETRIS)
- }
- } else if (clearType == 127) {
- if (this.specialScoring.ALLSPIN) {
- scorings.push(this.specialScoring.ALLSPIN)
- }
+ CustomSFXset.prototype.getClearSFX = function (altClearType, clearType, b2b, combo) {
+ let sounds = [],
+ prefix = "";
+ let specialSound = null;
+ let override = false;
+ if (this.specialScoring) {
+ let scorings = [this.specialScoring[SCORES[clearType]]];
+ if ((clearType > 4 && clearType <= 11) || clearType == 14) {
+ if (this.specialScoring.TSPINORTETRIS) {
+ scorings.push(this.specialScoring.TSPINORTETRIS);
+ }
+ } else if (clearType == 127) {
+ if (this.specialScoring.ALLSPIN) {
+ scorings.push(this.specialScoring.ALLSPIN);
+ }
+ }
+ for (let scoring of scorings) {
+ if (Array.isArray(scoring)) {
+ let bestFit = { score: 0.5, sound: null, combo: -1 };
+ for (let sfx of scoring) {
+ let score = 0;
+ if (sfx.hasOwnProperty("b2b") && sfx.b2b == b2b) {
+ score += 1;
}
- for (let scoring of scorings) {
- if (Array.isArray(scoring)) {
-
- let bestFit = { score: 0.5, sound: null, combo: -1 }
- for (let sfx of scoring) {
- let score = 0
- if (sfx.hasOwnProperty("b2b") && sfx.b2b == b2b) {
- score += 1
- }
- if (sfx.hasOwnProperty("combo") && sfx.combo <= combo) {
- score += 1
- }
- if (bestFit.score < score) {
- override = sfx.override
- bestFit = { score: score, sound: sfx.name, combo: combo }
- } else if (bestFit.score == score) {
- if (sfx.combo && combo > bestFit.combo) {
- override = sfx.override
- bestFit = { score: score, sound: sfx.name, combo: combo }
- }
- }
- }
- if (bestFit.sound != null) {
- specialSound = bestFit.sound
- sounds.push(specialSound)
- }
- }
+ if (sfx.hasOwnProperty("combo") && sfx.combo <= combo) {
+ score += 1;
+ }
+ if (bestFit.score < score) {
+ override = sfx.override;
+ bestFit = { score: score, sound: sfx.name, combo: combo };
+ } else if (bestFit.score == score) {
+ if (sfx.combo && combo > bestFit.combo) {
+ override = sfx.override;
+ bestFit = { score: score, sound: sfx.name, combo: combo };
+ }
}
+ }
+ if (bestFit.sound != null) {
+ specialSound = bestFit.sound;
+ sounds.push(specialSound);
+ }
+ }
+ }
- if (this.specialScoring.ANY) {
- let bestFit = { score: 0, sound: null, combo: -1 }
+ if (this.specialScoring.ANY) {
+ let bestFit = { score: 0, sound: null, combo: -1 };
- for (let sfx of this.specialScoring.ANY) {
- let score = 0
- if (sfx.hasOwnProperty("b2b")) {
- if (sfx.b2b == b2b) score += 1
- else continue
- }
+ for (let sfx of this.specialScoring.ANY) {
+ let score = 0;
+ if (sfx.hasOwnProperty("b2b")) {
+ if (sfx.b2b == b2b) score += 1;
+ else continue;
+ }
- if (sfx.hasOwnProperty("combo")) {
- if (sfx.combo <= combo) score += 1
- else continue
- }
- if (bestFit.score < score) {
- override = sfx.override
- bestFit = { score: score, sound: sfx.name, combo: combo }
- } else if (bestFit.score == score) {
- if (sfx.combo && combo > bestFit.combo) {
- override = sfx.override
- bestFit = { score: score, sound: sfx.name, combo: combo }
- }
- }
- }
- if (bestFit.sound != null) {
- specialSound = bestFit.sound
- sounds.push(specialSound)
- }
+ if (sfx.hasOwnProperty("combo")) {
+ if (sfx.combo <= combo) score += 1;
+ else continue;
+ }
+ if (bestFit.score < score) {
+ override = sfx.override;
+ bestFit = { score: score, sound: sfx.name, combo: combo };
+ } else if (bestFit.score == score) {
+ if (sfx.combo && combo > bestFit.combo) {
+ override = sfx.override;
+ bestFit = { score: score, sound: sfx.name, combo: combo };
}
-
- }
- if (sfx.hasOwnProperty(b2b) && b2b) {
- sounds.push('b2b')
- }
- if (combo >= 0) {
- sounds.push(this.getComboSFX(combo))
+ }
}
- if (this.scoring && (!specialSound || override == false)) {
- sounds.push(prefix + this.getScoreSFX(clearType))
+ if (bestFit.sound != null) {
+ specialSound = bestFit.sound;
+ sounds.push(specialSound);
}
- if (altClearType == Score.A.PERFECT_CLEAR) {
- sounds.push(prefix + this.getScoreSFX(altClearType))
- }
- // console.log(sounds)
- return sounds
+ }
+ }
+ if (sfx.hasOwnProperty(b2b) && b2b) {
+ sounds.push("b2b");
+ }
+ if (combo >= 0) {
+ sounds.push(this.getComboSFX(combo));
+ }
+ if (this.scoring && (!specialSound || override == false)) {
+ sounds.push(prefix + this.getScoreSFX(clearType));
}
- let customSFX = new CustomSFXset
+ if (altClearType == Score.A.PERFECT_CLEAR) {
+ sounds.push(prefix + this.getScoreSFX(altClearType));
+ }
+ // console.log(sounds)
+ return sounds;
+ };
+ let customSFX = new CustomSFXset();
- /* function CustomVFXset() {
+ /* function CustomVFXset() {
this.volume = 1
}
CustomVFXset.prototype = new NullSFXset
@@ -289,78 +308,72 @@ export const loadCustomSFX = (sfx = {}) => {
}
let customVFX = new CustomVFXset*/
- for (let name of SOUNDS) {
- if (sfx.hasOwnProperty(name)) {
- customSFX[name] = {
- url: sfx[name],
- }
- } else {
- customSFX[name] = {
- url: "null.wav",
- }
- }
+ for (let name of SOUNDS) {
+ if (sfx.hasOwnProperty(name)) {
+ customSFX[name] = {
+ url: sfx[name],
+ };
+ } else {
+ customSFX[name] = {
+ url: "null.wav",
+ };
}
- if (sfx.comboTones) {
- if (Array.isArray(sfx.comboTones)) {
- customSFX.comboTones = []
- for (let tone of sfx.comboTones) {
- if (typeof tone === 'string') {
- customSFX.comboTones.push({ url: tone })
- } else {
- customSFX.comboTones.push({ url: "null.wav" })
- }
- }
- } else if (typeof sfx.comboTones == "object") {
- if (sfx.comboTones.duration && sfx.comboTones.spacing && sfx.comboTones.cnt) {
- customSFX.comboTones = {
- url: sfx.comboTones.url,
- duration: sfx.comboTones.duration,
- spacing: sfx.comboTones.spacing,
- cnt: sfx.comboTones.cnt,
- }
- }
+ }
+ if (sfx.comboTones) {
+ if (Array.isArray(sfx.comboTones)) {
+ customSFX.comboTones = [];
+ for (let tone of sfx.comboTones) {
+ if (typeof tone === "string") {
+ customSFX.comboTones.push({ url: tone });
+ } else {
+ customSFX.comboTones.push({ url: "null.wav" });
}
+ }
+ } else if (typeof sfx.comboTones == "object") {
+ if (sfx.comboTones.duration && sfx.comboTones.spacing && sfx.comboTones.cnt) {
+ customSFX.comboTones = {
+ url: sfx.comboTones.url,
+ duration: sfx.comboTones.duration,
+ spacing: sfx.comboTones.spacing,
+ cnt: sfx.comboTones.cnt,
+ };
+ }
}
- if (sfx.specialScoring && typeof sfx.specialScoring == "object") {
- for (let key in sfx.specialScoring) {
- if (!Array.isArray(sfx.specialScoring[key])) continue
- for (let i in sfx.specialScoring[key]) {
- let sound = sfx.specialScoring[key][i]
- sound.name = "CUSTOMSFX" + key + i
- loadSound(sound.name, sound)
- }
- }
- customSFX.specialScoring = sfx.specialScoring
+ }
+ if (sfx.specialScoring && typeof sfx.specialScoring == "object") {
+ for (let key in sfx.specialScoring) {
+ if (!Array.isArray(sfx.specialScoring[key])) continue;
+ for (let i in sfx.specialScoring[key]) {
+ let sound = sfx.specialScoring[key][i];
+ sound.name = "CUSTOMSFX" + key + i;
+ loadSound(sound.name, sound);
+ }
}
- if (sfx.scoring && typeof sfx.scoring == "object") {
- customSFX.scoring = Array(15)
+ customSFX.specialScoring = sfx.specialScoring;
+ }
+ if (sfx.scoring && typeof sfx.scoring == "object") {
+ customSFX.scoring = Array(15);
- for (let key in sfx.scoring) {
- let i = SCORES.indexOf(key)
- if (i < 0) continue
- customSFX.scoring[i] = { url: sfx.scoring[key] }
- }
+ for (let key in sfx.scoring) {
+ let i = SCORES.indexOf(key);
+ if (i < 0) continue;
+ customSFX.scoring[i] = { url: sfx.scoring[key] };
}
- if (sfx.spawns && typeof sfx.spawns == "object") {
- let scores = [
- "I", "O", "T", "L", "J", "S", "Z"
- ]
- for (let key in sfx.spawns) {
- let i = scores.indexOf(key)
- if (i > 0) {
- loadSound("b_" + key, { url: sfx.spawns[key] })
- }
-
- }
- } else {
- let scores = [
- "I", "O", "T", "L", "J", "S", "Z"
- ]
- for (var key of scores) {
- loadSound("b_" + key, { url: "null.wav" })
- }
+ }
+ if (sfx.spawns && typeof sfx.spawns == "object") {
+ let scores = ["I", "O", "T", "L", "J", "S", "Z"];
+ for (let key in sfx.spawns) {
+ let i = scores.indexOf(key);
+ if (i > 0) {
+ loadSound("b_" + key, { url: sfx.spawns[key] });
+ }
}
- return customSFX
- // attemptLoadSFX(customSFX);
-
-}
+ } else {
+ let scores = ["I", "O", "T", "L", "J", "S", "Z"];
+ for (var key of scores) {
+ loadSound("b_" + key, { url: "null.wav" });
+ }
+ }
+ return customSFX;
+ // attemptLoadSFX(customSFX);
+};
diff --git a/src/skin.js b/src/skin.js
index 5d0745a..3ff9f76 100644
--- a/src/skin.js
+++ b/src/skin.js
@@ -1,355 +1,490 @@
-import { Config } from "./config"
-let offscreenCanvas = document.createElement('canvas');
+import { Config } from "./config";
+let offscreenCanvas = document.createElement("canvas");
let offscreenContext = offscreenCanvas.getContext("2d");
offscreenCanvas.height = 32;
offscreenCanvas.width = 32;
-let customSkinSize = 32
-let customGhostSkinSize = 32
-let usingConnected = false
-let usingGhostConnected = false
+let customSkinSize = 32;
+let customGhostSkinSize = 32;
+let usingConnected = false;
+let usingGhostConnected = false;
function loadCustomSkin(url, ghost = false) {
-
// if not allowing force replay skin, don't load custom skin
- if (location.href.includes('replay') && !Config().ENABLE_REPLAY_SKIN) {
+ if (location.href.includes("replay") && !Config().ENABLE_REPLAY_SKIN) {
return;
}
let img = new Image();
- console.log(url, ghost)
+ console.log(url, ghost);
img.onload = function () {
var height = img.height;
var width = img.width;
if (width / height == 9 && !ghost) {
- customSkinSize = height
- usingConnected = false
- if (window.loadSkin) loadSkin(url, customSkinSize)
+ customSkinSize = height;
+ usingConnected = false;
+ if (window.loadSkin) loadSkin(url, customSkinSize);
} else if (width / height == 9 / 20 && !ghost) {
- usingConnected = true
- customSkinSize = width / 9
- if (window.loadSkin) loadSkin(url, customSkinSize)
+ usingConnected = true;
+ customSkinSize = width / 9;
+ if (window.loadSkin) loadSkin(url, customSkinSize);
} else if (width / height == 7 && ghost) {
- usingGhostConnected = false
- customGhostSkinSize = height
- if (window.loadGhostSkin) loadGhostSkin(url, height)
+ usingGhostConnected = false;
+ customGhostSkinSize = height;
+ if (window.loadGhostSkin) loadGhostSkin(url, height);
} else if (width / height == 7 / 20 && ghost) {
offscreenCanvas.height = width / 7;
offscreenCanvas.width = width / 7;
- usingGhostConnected = true
- customGhostSkinSize = width / 7
- if (window.loadSkin) loadGhostSkin(url, width / 7)
+ usingGhostConnected = true;
+ customGhostSkinSize = width / 7;
+ if (window.loadSkin) loadGhostSkin(url, width / 7);
}
- }
+ };
img.src = url;
-
}
-window.loadCustomSkin = loadCustomSkin
+window.loadCustomSkin = loadCustomSkin;
export const initCustomSkin = () => {
- initConnectedSkins()
- let skinLoaded = false
- let game = null
- if (Config().CUSTOM_SKIN_URL)
- loadCustomSkin(Config().CUSTOM_SKIN_URL);
+ initConnectedSkins();
+ let skinLoaded = false;
+ let game = null;
+ if (Config().CUSTOM_SKIN_URL) loadCustomSkin(Config().CUSTOM_SKIN_URL);
- if (Config().CUSTOM_GHOST_SKIN_URL)
- loadCustomSkin(Config().CUSTOM_GHOST_SKIN_URL, true)
+ if (Config().CUSTOM_GHOST_SKIN_URL) loadCustomSkin(Config().CUSTOM_GHOST_SKIN_URL, true);
if (typeof window.Live == "function") {
- Config().onChange("CUSTOM_SKIN_URL", val => {
- if (val)
- loadCustomSkin(val);
+ Config().onChange("CUSTOM_SKIN_URL", (val) => {
+ if (val) loadCustomSkin(val);
else {
- loadSkin("resetRegular")
+ loadSkin("resetRegular");
}
});
- Config().onChange("CUSTOM_GHOST_SKIN_URL", val => {
- if (val) loadCustomSkin(val, true)
+ Config().onChange("CUSTOM_GHOST_SKIN_URL", (val) => {
+ if (val) loadCustomSkin(val, true);
else if (game) {
- game.ghostSkinId = 0
- usingGhostConnected = false
+ game.ghostSkinId = 0;
+ usingGhostConnected = false;
}
});
- let onload = Live.prototype.onCIDassigned
+ let onload = Live.prototype.onCIDassigned;
Live.prototype.onCIDassigned = function () {
- let v = onload.apply(this, arguments)
+ let v = onload.apply(this, arguments);
if (!skinLoaded) {
- game = this.p
- skinLoaded = true
- if (Config().CUSTOM_SKIN_URL)
- loadCustomSkin(Config().CUSTOM_SKIN_URL);
+ game = this.p;
+ skinLoaded = true;
+ if (Config().CUSTOM_SKIN_URL) loadCustomSkin(Config().CUSTOM_SKIN_URL);
- if (Config().CUSTOM_GHOST_SKIN_URL)
- loadCustomSkin(Config().CUSTOM_GHOST_SKIN_URL, true)
+ if (Config().CUSTOM_GHOST_SKIN_URL) loadCustomSkin(Config().CUSTOM_GHOST_SKIN_URL, true);
}
- return v
- }
+ return v;
+ };
}
- if (typeof window.View == "function" && typeof window.Live != "function") { //force skin on replayers
- let onready = View.prototype.onReady
+ if (typeof window.View == "function" && typeof window.Live != "function") {
+ //force skin on replayers
+ let onready = View.prototype.onReady;
View.prototype.onReady = function () {
let val = onready.apply(this, arguments);
if (Config().ENABLE_REPLAY_SKIN && Config().CUSTOM_SKIN_URL) {
- this.tex.crossOrigin = "anonymous"
- this.skinId = 1
- this.g.skins[1].data = Config().CUSTOM_SKIN_URL
- this.g.skins[1].w = customSkinSize
- this.tex.src = this.g.skins[1].data
+ this.tex.crossOrigin = "anonymous";
+ this.skinId = 1;
+ this.g.skins[1].data = Config().CUSTOM_SKIN_URL;
+ this.g.skins[1].w = customSkinSize;
+ this.tex.src = this.g.skins[1].data;
}
- return val
- }
+ return val;
+ };
}
if (typeof window.Game == "function") {
- let ls = Game.prototype.changeSkin
+ let ls = Game.prototype.changeSkin;
Game.prototype.changeSkin = function () {
- let val = ls.apply(this, arguments)
- let url = this.skins[arguments[0]].data
+ let val = ls.apply(this, arguments);
+ let url = this.skins[arguments[0]].data;
if (url == "resetRegular") {
- usingConnected = false
- ls.apply(this, [0])
- return val
+ usingConnected = false;
+ ls.apply(this, [0]);
+ return val;
}
if (this.v && this.v.NAME == "webGL") {
- this.v.ai_setBlend()
+ this.v.ai_setBlend();
}
- return val
- }
+ return val;
+ };
}
console.log("Custom skin loaded.");
-
-}
+};
export const initConnectedSkins = () => {
- const removeDimple = true
- const ghostAlpha = 0.5
+ const removeDimple = true;
+ const ghostAlpha = 0.5;
// const blockConnections = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
- const blockConnections = [-1, 1, 1, 1, 1, 1, 1, 1, 2, 3]
-
+ const blockConnections = [-1, 1, 1, 1, 1, 1, 1, 1, 2, 3];
- let colors = blockConnections
+ let colors = blockConnections;
function solveConnected(blocks, x, y) {
- let connect_value = 0
- let checks = { N: false, S: false, E: false, W: false }
- let row = y
- let col = x
- if (row != 0 && blocks[row - 1][col] > 0) { connect_value += 1; checks.N = true }
- if (row != blocks.length - 1 && blocks[row + 1][col] > 0) { connect_value += 2; checks.S = true }
- if (blocks[row][col - 1] > 0) { connect_value += 4; checks.W = true; }
- if (blocks[row][col + 1] > 0) { connect_value += 8; checks.E = true; }
- let corners = { a: false, b: false, c: false, d: false }
-
- if (checks.N && checks.E && row != 0 && blocks[row - 1][col + 1] > 0) corners.a = true
- if (checks.S && checks.E && blocks[row + 1][col + 1] > 0) corners.b = true
- if (checks.S && checks.W && blocks[row + 1][col - 1] > 0) corners.c = true
- if (checks.N && checks.W && row != 0 && blocks[row - 1][col - 1] > 0) corners.d = true
- let overlay = 0
- if (corners.a) overlay = 16
- if (corners.b) overlay = 17
- if (corners.c) overlay = 18
- if (corners.d) overlay = 19
- return { connect_value: connect_value, overlay: overlay }
+ let connect_value = 0;
+ let checks = { N: false, S: false, E: false, W: false };
+ let row = y;
+ let col = x;
+ if (row != 0 && blocks[row - 1][col] > 0) {
+ connect_value += 1;
+ checks.N = true;
+ }
+ if (row != blocks.length - 1 && blocks[row + 1][col] > 0) {
+ connect_value += 2;
+ checks.S = true;
+ }
+ if (blocks[row][col - 1] > 0) {
+ connect_value += 4;
+ checks.W = true;
+ }
+ if (blocks[row][col + 1] > 0) {
+ connect_value += 8;
+ checks.E = true;
+ }
+ let corners = { a: false, b: false, c: false, d: false };
+
+ if (checks.N && checks.E && row != 0 && blocks[row - 1][col + 1] > 0) corners.a = true;
+ if (checks.S && checks.E && blocks[row + 1][col + 1] > 0) corners.b = true;
+ if (checks.S && checks.W && blocks[row + 1][col - 1] > 0) corners.c = true;
+ if (checks.N && checks.W && row != 0 && blocks[row - 1][col - 1] > 0) corners.d = true;
+ let overlay = 0;
+ if (corners.a) overlay = 16;
+ if (corners.b) overlay = 17;
+ if (corners.c) overlay = 18;
+ if (corners.d) overlay = 19;
+ return { connect_value: connect_value, overlay: overlay };
}
- let drawCanvas = false
+ let drawCanvas = false;
if (window.WebGLView != undefined) {
- let onRedrawMatrix = WebGLView['prototype']['redrawMatrix']
- WebGLView['prototype']['redrawMatrix'] = function () {
+ let onRedrawMatrix = WebGLView.prototype.redrawMatrix;
+ WebGLView.prototype.redrawMatrix = function () {
if (usingConnected) {
- this['clearMainCanvas']();
- if (this['g']['isInvisibleSkin']) {
- return
- };
- this.g.ai_drawMatrix()
- return
+ this.clearMainCanvas();
+ if (this.g.isInvisibleSkin) {
+ return;
+ }
+ this.g.ai_drawMatrix();
+ return;
}
- let val = onRedrawMatrix.apply(this, arguments)
- return val
- }
- let onWebglLoad = WebGLView.prototype.initRenderer
+ let val = onRedrawMatrix.apply(this, arguments);
+ return val;
+ };
+ let onWebglLoad = WebGLView.prototype.initRenderer;
WebGLView.prototype.initRenderer = function () {
- let val = onWebglLoad.apply(this, arguments)
- this.ai_setBlend()
- return val
- }
+ let val = onWebglLoad.apply(this, arguments);
+ this.ai_setBlend();
+ return val;
+ };
WebGLView.prototype.ai_setBlend = function () {
for (let ctx of this.ctxs) {
- let gl = ctx.gl
+ let gl = ctx.gl;
gl.enable(gl.BLEND);
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
}
- }
- WebGLView['prototype']['ai_drawBlock'] = function (pos_x, pos_y, block_value, connect_value, main) {
+ };
+ WebGLView.prototype.ai_drawBlock = function (pos_x, pos_y, block_value, connect_value, main) {
if (block_value) {
- let skin = this.g.skins[this.g.skinId]
- let scale = this['g']['drawScale'] * this['g']['block_size'];
- let cmain = this['ctxs'][main],
- texture = cmain['textureInfos'][0];
-
- this['drawImage'](cmain, texture['texture'], texture['width'], texture['height'], this['g']['coffset'][block_value] * skin.w, connect_value * skin.w, skin.w, skin.w, pos_x * this['g']['block_size'], pos_y * this['g']['block_size'], scale, scale)
+ let skin = this.g.skins[this.g.skinId];
+ let scale = this.g.drawScale * this.g.block_size;
+ let cmain = this.ctxs[main],
+ texture = cmain.textureInfos[0];
+
+ this.drawImage(
+ cmain,
+ texture.texture,
+ texture.width,
+ texture.height,
+ this.g.coffset[block_value] * skin.w,
+ connect_value * skin.w,
+ skin.w,
+ skin.w,
+ pos_x * this.g.block_size,
+ pos_y * this.g.block_size,
+ scale,
+ scale
+ );
}
};
- WebGLView['prototype']['ai_drawGhostBlock'] = function (pos_x, pos_y, block_value, connect_value) {
- let skinSize = this.g.skins[this.g.skinId].w
- var cmain = this['ctxs'][0];
- if (this['g']['ghostSkinId'] === 0) {
- cmain['gl']['uniform1f'](cmain['globalAlpha'], 0.5);
- this['ai_drawBlock'](pos_x, pos_y, block_value, connect_value, 0);
- cmain['gl']['uniform1f'](cmain['globalAlpha'], 1)
+ WebGLView.prototype.ai_drawGhostBlock = function (pos_x, pos_y, block_value, connect_value) {
+ let skinSize = this.g.skins[this.g.skinId].w;
+ var cmain = this.ctxs[0];
+ if (this.g.ghostSkinId === 0) {
+ cmain.gl.uniform1f(cmain.globalAlpha, 0.5);
+ this.ai_drawBlock(pos_x, pos_y, block_value, connect_value, 0);
+ cmain.gl.uniform1f(cmain.globalAlpha, 1);
} else {
- var scale = this['g']['drawScale'] * this['g']['block_size'];
- var texture = cmain['textureInfos'][1];
- this['drawImage'](cmain, texture['texture'], texture['width'], texture['height'], (this['g']['coffset'][block_value] - 2) * skinSize, connect_value * skinSize, skinSize, skinSize, pos_x * this['g']['block_size'], pos_y * this['g']['block_size'], scale, scale)
+ var scale = this.g.drawScale * this.g.block_size;
+ var texture = cmain.textureInfos[1];
+ this.drawImage(
+ cmain,
+ texture.texture,
+ texture.width,
+ texture.height,
+ (this.g.coffset[block_value] - 2) * skinSize,
+ connect_value * skinSize,
+ skinSize,
+ skinSize,
+ pos_x * this.g.block_size,
+ pos_y * this.g.block_size,
+ scale,
+ scale
+ );
}
-
};
- WebGLView['prototype']['ai_drawBlockOnCanvas'] = function (a, b, c, d, e) {
- this['ai_drawBlock'](a, b, c, d, e)
+ WebGLView.prototype.ai_drawBlockOnCanvas = function (a, b, c, d, e) {
+ this.ai_drawBlock(a, b, c, d, e);
};
}
if (window.Ctx2DView != undefined) {
- let onRedrawMatrix = Ctx2DView['prototype']['redrawMatrix']
- Ctx2DView['prototype']['redrawMatrix'] = function () {
+ let onRedrawMatrix = Ctx2DView.prototype.redrawMatrix;
+ Ctx2DView.prototype.redrawMatrix = function () {
if (usingConnected) {
- this['clearMainCanvas']();
- if (this['g']['isInvisibleSkin']) {
- return
- };
- this.g.ai_drawMatrix()
- return
+ this.clearMainCanvas();
+ if (this.g.isInvisibleSkin) {
+ return;
+ }
+ this.g.ai_drawMatrix();
+ return;
}
- let val = onRedrawMatrix.apply(this, arguments)
- return val
- }
- Ctx2DView['prototype']['ai_drawBlock'] = function (pos_x, pos_y, block_value, connect_value) {
+ let val = onRedrawMatrix.apply(this, arguments);
+ return val;
+ };
+ Ctx2DView.prototype.ai_drawBlock = function (pos_x, pos_y, block_value, connect_value) {
if (block_value && pos_x >= 0 && pos_y >= 0 && pos_x < 10 && pos_y < 20) {
- var scale = this['g']['drawScale'] * this['g']['block_size'];
- if (this['g']['skinId']) {
- this['ctx']['drawImage'](this['g']['tex'], this['g']['coffset'][block_value] * this['g']['skins'][this['g']['skinId']]['w'], connect_value * this['g']['skins'][this['g']['skinId']]['w'], this['g']['skins'][this['g']['skinId']]['w'], this['g']['skins'][this['g']['skinId']]['w'], pos_x * this['g']['block_size'], pos_y * this['g']['block_size'], scale, scale)
+ var scale = this.g.drawScale * this.g.block_size;
+ if (this.g.skinId) {
+ this.ctx.drawImage(
+ this.g.tex,
+ this.g.coffset[block_value] * this.g.skins[this.g.skinId].w,
+ connect_value * this.g.skins[this.g.skinId].w,
+ this.g.skins[this.g.skinId].w,
+ this.g.skins[this.g.skinId].w,
+ pos_x * this.g.block_size,
+ pos_y * this.g.block_size,
+ scale,
+ scale
+ );
} else {
- var mono = (this['g']['monochromeSkin'] && block_value <= 7) ? this['g']['monochromeSkin'] : this['g']['colors'][block_value];
- this['drawRectangle'](this['ctx'], pos_x * this['g']['block_size'], pos_y * this['g']['block_size'], scale, scale, mono)
+ var mono = this.g.monochromeSkin && block_value <= 7 ? this.g.monochromeSkin : this.g.colors[block_value];
+ this.drawRectangle(this.ctx, pos_x * this.g.block_size, pos_y * this.g.block_size, scale, scale, mono);
}
}
};
- Ctx2DView['prototype']['ai_drawGhostBlock'] = function (pos_x, pos_y, block_value, connect_value) {
- let scale = this['g']['drawScale'] * this['g']['block_size'];
- let skin = this.g.ghostSkins[this.g.ghostSkinId]
- let tex = this.g.ghostTex
- let coffset = this.g.coffset[block_value] - 2
+ Ctx2DView.prototype.ai_drawGhostBlock = function (pos_x, pos_y, block_value, connect_value) {
+ let scale = this.g.drawScale * this.g.block_size;
+ let skin = this.g.ghostSkins[this.g.ghostSkinId];
+ let tex = this.g.ghostTex;
+ let coffset = this.g.coffset[block_value] - 2;
if (this.g.ghostSkinId === 0) {
- this['ctx']['globalAlpha'] = ghostAlpha;
- skin = this.g.skins[this.g.skinId]
- tex = this.g.tex
- coffset += 2
+ this.ctx.globalAlpha = ghostAlpha;
+ skin = this.g.skins[this.g.skinId];
+ tex = this.g.tex;
+ coffset += 2;
}
- offscreenContext.drawImage(tex, coffset * skin.w, connect_value * skin.w, skin.w, skin.w, 0, 0, skin.w, skin.w)
+ offscreenContext.drawImage(tex, coffset * skin.w, connect_value * skin.w, skin.w, skin.w, 0, 0, skin.w, skin.w);
if (drawCanvas) {
- this.ctx.drawImage(offscreenCanvas, 0, 0, skin.w, skin.w, pos_x * this['g']['block_size'], pos_y * this['g']['block_size'], scale, scale)
- }
- this['ctx']['globalAlpha'] = 1
- }
- Ctx2DView['prototype']['ai_drawBlockOnCanvas'] = function (pos_x, pos_y, block_value, connect_value, render) {
- var renderer = (render === this['HOLD']) ? this['hctx'] : this['qctx'];
- if (this['g']['skinId'] === 0) {
- var mono = (this['g']['monochromeSkin'] && block_value <= 7) ? this['g']['monochromeSkin'] : this['g']['colors'][block_value];
- this['drawRectangle'](renderer, pos_x * this['g']['block_size'], pos_y * this['g']['block_size'], this['g']['block_size'], this['g']['block_size'], mono)
+ this.ctx.drawImage(
+ offscreenCanvas,
+ 0,
+ 0,
+ skin.w,
+ skin.w,
+ pos_x * this.g.block_size,
+ pos_y * this.g.block_size,
+ scale,
+ scale
+ );
+ }
+ this.ctx.globalAlpha = 1;
+ };
+ Ctx2DView.prototype.ai_drawBlockOnCanvas = function (pos_x, pos_y, block_value, connect_value, render) {
+ var renderer = render === this.HOLD ? this.hctx : this.qctx;
+ if (this.g.skinId === 0) {
+ var mono = this.g.monochromeSkin && block_value <= 7 ? this.g.monochromeSkin : this.g.colors[block_value];
+ this.drawRectangle(
+ renderer,
+ pos_x * this.g.block_size,
+ pos_y * this.g.block_size,
+ this.g.block_size,
+ this.g.block_size,
+ mono
+ );
} else {
- renderer['drawImage'](this['g']['tex'], this['g']['coffset'][block_value] * this['g']['skins'][this['g']['skinId']]['w'], connect_value * this['g']['skins'][this['g']['skinId']]['w'], this['g']['skins'][this['g']['skinId']]['w'], this['g']['skins'][this['g']['skinId']]['w'], pos_x * this['g']['block_size'], pos_y * this['g']['block_size'], this['g']['block_size'], this['g']['block_size'])
+ renderer.drawImage(
+ this.g.tex,
+ this.g.coffset[block_value] * this.g.skins[this.g.skinId].w,
+ connect_value * this.g.skins[this.g.skinId].w,
+ this.g.skins[this.g.skinId].w,
+ this.g.skins[this.g.skinId].w,
+ pos_x * this.g.block_size,
+ pos_y * this.g.block_size,
+ this.g.block_size,
+ this.g.block_size
+ );
}
};
-
- };
+ }
let template1 = function () {
- let blockset = this['blockSets'][this['activeBlock']['set']],
- blocks = (blockset['scale'] === 1) ? blockset['blocks'][this['activeBlock']['id']]['blocks'][this['activeBlock']['rot']] : blockset['previewAs']['blocks'][this['activeBlock']['id']]['blocks'][this['activeBlock']['rot']],
- blocks_length = blocks['length'];
- this['drawScale'] = blockset['scale'];
- if (this['ghostEnabled'] && !this['gameEnded']) {
+ let blockset = this.blockSets[this.activeBlock.set],
+ blocks =
+ blockset.scale === 1
+ ? blockset.blocks[this.activeBlock.id].blocks[this.activeBlock["rot"]]
+ : blockset.previewAs.blocks[this.activeBlock.id].blocks[this.activeBlock["rot"]],
+ blocks_length = blocks.length;
+ this.drawScale = blockset.scale;
+ if (this.ghostEnabled && !this.gameEnded) {
for (let y = 0; y < blocks_length; y++) {
for (let x = 0; x < blocks_length; x++) {
if (blocks[y][x] > 0) {
if (!usingGhostConnected && this.ghostSkinId != 0) {
- this.v.drawGhostBlock(this.ghostPiece.pos.x + x * this.drawScale, this.ghostPiece.pos.y + y * this.drawScale, blockset.blocks[this.activeBlock.id].color)
+ this.v.drawGhostBlock(
+ this.ghostPiece.pos.x + x * this.drawScale,
+ this.ghostPiece.pos.y + y * this.drawScale,
+ blockset.blocks[this.activeBlock.id].color
+ );
if (this.activeBlock.item && blocks[y][x] === this.activeBlock.item) {
- this.v.drawBrickOverlay(this.ghostPiece.pos.x + x * this.drawScale, this.ghostPiece.pos.y + y * this.drawScale, true)
+ this.v.drawBrickOverlay(
+ this.ghostPiece.pos.x + x * this.drawScale,
+ this.ghostPiece.pos.y + y * this.drawScale,
+ true
+ );
}
- continue
+ continue;
}
- let solve = solveConnected(blocks, x, y)
- offscreenContext.clearRect(0, 0, this.skins[this.skinId].w, this.skins[this.skinId].w)
+ let solve = solveConnected(blocks, x, y);
+ offscreenContext.clearRect(0, 0, this.skins[this.skinId].w, this.skins[this.skinId].w);
if (solve.overlay > 0 && removeDimple) {
- drawCanvas = false
- this['v']['ai_drawGhostBlock'](this['ghostPiece']['pos']['x'] + x * this['drawScale'], this['ghostPiece']['pos']['y'] + y * this['drawScale'], blockset['blocks'][this['activeBlock']['id']]['color'], solve.connect_value, 0);
- if (this['activeBlock']['item'] && blocks[y][x] === this['activeBlock']['item']) {
- this['v']['drawBrickOverlay'](this['ghostPiece']['pos']['x'] + x * this['drawScale'], this['ghostPiece']['pos']['y'] + y * this['drawScale'], true)
+ drawCanvas = false;
+ this.v.ai_drawGhostBlock(
+ this.ghostPiece.pos.x + x * this.drawScale,
+ this.ghostPiece.pos.y + y * this.drawScale,
+ blockset.blocks[this.activeBlock.id].color,
+ solve.connect_value,
+ 0
+ );
+ if (this.activeBlock.item && blocks[y][x] === this.activeBlock.item) {
+ this.v.drawBrickOverlay(
+ this.ghostPiece.pos.x + x * this.drawScale,
+ this.ghostPiece.pos.y + y * this.drawScale,
+ true
+ );
}
- drawCanvas = true
- this['v']['ai_drawGhostBlock'](this['ghostPiece']['pos']['x'] + x * this['drawScale'], this['ghostPiece']['pos']['y'] + y * this['drawScale'], blockset['blocks'][this['activeBlock']['id']]['color'], solve.overlay, 0)
- }
- else {
- drawCanvas = true
- this['v']['ai_drawGhostBlock'](this['ghostPiece']['pos']['x'] + x * this['drawScale'], this['ghostPiece']['pos']['y'] + y * this['drawScale'], blockset['blocks'][this['activeBlock']['id']]['color'], solve.connect_value, 0);
+ drawCanvas = true;
+ this.v.ai_drawGhostBlock(
+ this.ghostPiece.pos.x + x * this.drawScale,
+ this.ghostPiece.pos.y + y * this.drawScale,
+ blockset.blocks[this.activeBlock.id].color,
+ solve.overlay,
+ 0
+ );
+ } else {
+ drawCanvas = true;
+ this.v.ai_drawGhostBlock(
+ this.ghostPiece.pos.x + x * this.drawScale,
+ this.ghostPiece.pos.y + y * this.drawScale,
+ blockset.blocks[this.activeBlock.id].color,
+ solve.connect_value,
+ 0
+ );
- if (this['activeBlock']['item'] && blocks[y][x] === this['activeBlock']['item']) {
- this['v']['drawBrickOverlay'](this['ghostPiece']['pos']['x'] + x * this['drawScale'], this['ghostPiece']['pos']['y'] + y * this['drawScale'], true)
+ if (this.activeBlock.item && blocks[y][x] === this.activeBlock.item) {
+ this.v.drawBrickOverlay(
+ this.ghostPiece.pos.x + x * this.drawScale,
+ this.ghostPiece.pos.y + y * this.drawScale,
+ true
+ );
}
}
}
}
}
- };
- if (!this['gameEnded']) {
+ }
+ if (!this.gameEnded) {
for (let y = 0; y < blocks_length; y++) {
for (let x = 0; x < blocks_length; x++) {
if (blocks[y][x] > 0) {
-
if (!usingConnected) {
- this.v.drawBlock(this.activeBlock.pos.x + x * this.drawScale, this.activeBlock.pos.y + y * this.drawScale, blockset.blocks[this.activeBlock.id].color, 0)
- if (this['activeBlock']['item'] && blocks[y][x] === this['activeBlock']['item']) {
- this['v']['drawBrickOverlay'](this['activeBlock']['pos']['x'] + x * this['drawScale'], this['activeBlock']['pos']['y'] + y * this['drawScale'], false)
+ this.v.drawBlock(
+ this.activeBlock.pos.x + x * this.drawScale,
+ this.activeBlock.pos.y + y * this.drawScale,
+ blockset.blocks[this.activeBlock.id].color,
+ 0
+ );
+ if (this.activeBlock.item && blocks[y][x] === this.activeBlock.item) {
+ this.v.drawBrickOverlay(
+ this.activeBlock.pos.x + x * this.drawScale,
+ this.activeBlock.pos.y + y * this.drawScale,
+ false
+ );
}
- continue
+ continue;
}
- let solve = solveConnected(blocks, x, y)
- this['v']['ai_drawBlock'](this['activeBlock']['pos']['x'] + x * this['drawScale'], this['activeBlock']['pos']['y'] + y * this['drawScale'], blockset['blocks'][this['activeBlock']['id']]['color'], solve.connect_value, 0);
- if (this['activeBlock']['item'] && blocks[y][x] === this['activeBlock']['item']) {
- this['v']['drawBrickOverlay'](this['activeBlock']['pos']['x'] + x * this['drawScale'], this['activeBlock']['pos']['y'] + y * this['drawScale'], false)
+ let solve = solveConnected(blocks, x, y);
+ this.v.ai_drawBlock(
+ this.activeBlock.pos.x + x * this.drawScale,
+ this.activeBlock.pos.y + y * this.drawScale,
+ blockset.blocks[this.activeBlock.id].color,
+ solve.connect_value,
+ 0
+ );
+ if (this.activeBlock.item && blocks[y][x] === this.activeBlock.item) {
+ this.v.drawBrickOverlay(
+ this.activeBlock.pos.x + x * this.drawScale,
+ this.activeBlock.pos.y + y * this.drawScale,
+ false
+ );
}
- if (solve.overlay > 0 && removeDimple) this['v']['ai_drawBlock'](this['activeBlock']['pos']['x'] + x * this['drawScale'], this['activeBlock']['pos']['y'] + y * this['drawScale'], blockset['blocks'][this['activeBlock']['id']]['color'], solve.overlay, 0);
+ if (solve.overlay > 0 && removeDimple)
+ this.v.ai_drawBlock(
+ this.activeBlock.pos.x + x * this.drawScale,
+ this.activeBlock.pos.y + y * this.drawScale,
+ blockset.blocks[this.activeBlock.id].color,
+ solve.overlay,
+ 0
+ );
}
}
}
- };
- this['drawScale'] = 1
+ }
+ this.drawScale = 1;
};
let template2 = function () {
- if (this['ISGAME'] && this['redrawBlocked']) {
- return
- };
- if (!this['ISGAME'] && (this['v']['redrawBlocked'] || !this['v']['QueueHoldEnabled'])) {
- return
- };
- this['v']['clearHoldCanvas']();
- if (this['blockInHold'] !== null) {
- var currSet = this['blockSets'][this['blockInHold']['set']]['previewAs'],
- blocks = currSet['blocks'][this['blockInHold']['id']]['blocks'][0],
- currColor = currSet['blocks'][this['blockInHold']['id']]['color'],
- currWeird = (!currSet['equidist']) ? currSet['blocks'][this['blockInHold']['id']]['yp'] : [0, 3],
- blocks_length = blocks['length'],
- something = (currSet['blocks'][this['blockInHold']['id']]['xp']) ? currSet['blocks'][this['blockInHold']['id']]['xp'] : [0, blocks_length - 1];
+ if (this.ISGAME && this.redrawBlocked) {
+ return;
+ }
+ if (!this.ISGAME && (this.v.redrawBlocked || !this.v.QueueHoldEnabled)) {
+ return;
+ }
+ this.v.clearHoldCanvas();
+ if (this.blockInHold !== null) {
+ var currSet = this.blockSets[this.blockInHold.set].previewAs,
+ blocks = currSet.blocks[this.blockInHold.id].blocks[0],
+ currColor = currSet.blocks[this.blockInHold.id].color,
+ currWeird = !currSet.equidist ? currSet.blocks[this.blockInHold.id].yp : [0, 3],
+ blocks_length = blocks.length,
+ something = currSet.blocks[this.blockInHold.id].xp
+ ? currSet.blocks[this.blockInHold.id].xp
+ : [0, blocks_length - 1];
for (var y = currWeird[0]; y <= currWeird[1]; y++) {
for (var x = something[0]; x <= something[1]; x++) {
if (blocks[y][x] > 0) {
- let solve = solveConnected(blocks, x, y)
- this['v']['ai_drawBlockOnCanvas'](x - something[0], y - currWeird[0], currColor, solve.connect_value, this['v'].HOLD);
- if (this['blockInHold']['item'] && blocks[y][x] === this['blockInHold']['item']) {
- this['v']['drawBrickOverlayOnCanvas'](x - something[0], y - currWeird[0], this['v'].HOLD)
+ let solve = solveConnected(blocks, x, y);
+ this.v.ai_drawBlockOnCanvas(
+ x - something[0],
+ y - currWeird[0],
+ currColor,
+ solve.connect_value,
+ this.v.HOLD
+ );
+ if (this.blockInHold.item && blocks[y][x] === this.blockInHold.item) {
+ this.v.drawBrickOverlayOnCanvas(x - something[0], y - currWeird[0], this.v.HOLD);
}
- if (solve.overlay > 0 && removeDimple) this['v']['ai_drawBlockOnCanvas'](x - something[0], y - currWeird[0], currColor, solve.overlay, this['v'].HOLD);
+ if (solve.overlay > 0 && removeDimple)
+ this.v.ai_drawBlockOnCanvas(x - something[0], y - currWeird[0], currColor, solve.overlay, this.v.HOLD);
}
}
}
@@ -358,202 +493,304 @@ export const initConnectedSkins = () => {
let template3 = function () {
for (var row = 0; row < 20; row++) {
for (var col = 0; col < 10; col++) {
- let block_value = this['matrix'][row][col]
- if (!block_value) continue
- let block_color = block_value
+ let block_value = this.matrix[row][col];
+ if (!block_value) continue;
+ let block_color = block_value;
- block_value = colors[block_value]
+ block_value = colors[block_value];
- let connect_value = 0
- let checks = { N: false, S: false, E: false, W: false }
+ let connect_value = 0;
+ let checks = { N: false, S: false, E: false, W: false };
- if (row == 0) { if (colors[this.deadline[col]] == block_value) { connect_value += 1; checks.N = true } }
- else if (colors[this.matrix[row - 1][col]] == block_value) { connect_value += 1; checks.N = true }
- if (row != 19 && colors[this.matrix[row + 1][col]] == block_value) { connect_value += 2; checks.S = true }
- if (colors[this.matrix[row][col - 1]] == block_value) { connect_value += 4; checks.W = true; }
- if (colors[this.matrix[row][col + 1]] == block_value) { connect_value += 8; checks.E = true; }
- let corners = { a: false, b: false, c: false, d: false }
+ if (row == 0) {
+ if (colors[this.deadline[col]] == block_value) {
+ connect_value += 1;
+ checks.N = true;
+ }
+ } else if (colors[this.matrix[row - 1][col]] == block_value) {
+ connect_value += 1;
+ checks.N = true;
+ }
+ if (row != 19 && colors[this.matrix[row + 1][col]] == block_value) {
+ connect_value += 2;
+ checks.S = true;
+ }
+ if (colors[this.matrix[row][col - 1]] == block_value) {
+ connect_value += 4;
+ checks.W = true;
+ }
+ if (colors[this.matrix[row][col + 1]] == block_value) {
+ connect_value += 8;
+ checks.E = true;
+ }
+ let corners = { a: false, b: false, c: false, d: false };
- if (checks.N && checks.E) { if (row == 0) { if (colors[this.deadline[col + 1]] == block_value) corners.a = true } else if (colors[this.matrix[row - 1][col + 1]] == block_value) corners.a = true }
- if (checks.S && checks.E && colors[this.matrix[row + 1][col + 1]] == block_value) corners.b = true
- if (checks.S && checks.W && colors[this.matrix[row + 1][col - 1]] == block_value) corners.c = true
- if (checks.N && checks.W) { if (row == 0) { if (colors[this.deadline[col - 1]] == block_value) corners.d = true } else if (colors[this.matrix[row - 1][col - 1]] == block_value) corners.d = true }
+ if (checks.N && checks.E) {
+ if (row == 0) {
+ if (colors[this.deadline[col + 1]] == block_value) corners.a = true;
+ } else if (colors[this.matrix[row - 1][col + 1]] == block_value) corners.a = true;
+ }
+ if (checks.S && checks.E && colors[this.matrix[row + 1][col + 1]] == block_value) corners.b = true;
+ if (checks.S && checks.W && colors[this.matrix[row + 1][col - 1]] == block_value) corners.c = true;
+ if (checks.N && checks.W) {
+ if (row == 0) {
+ if (colors[this.deadline[col - 1]] == block_value) corners.d = true;
+ } else if (colors[this.matrix[row - 1][col - 1]] == block_value) corners.d = true;
+ }
- this['v']['ai_drawBlock'](col, row, block_color, connect_value, this.v.MAIN)
+ this.v.ai_drawBlock(col, row, block_color, connect_value, this.v.MAIN);
- if (!removeDimple) continue
- if (corners.a) this['v']['ai_drawBlock'](col, row, block_color, 16, this.v.MAIN)
- if (corners.b) this['v']['ai_drawBlock'](col, row, block_color, 17, this.v.MAIN)
- if (corners.c) this['v']['ai_drawBlock'](col, row, block_color, 18, this.v.MAIN)
- if (corners.d) this['v']['ai_drawBlock'](col, row, block_color, 19, this.v.MAIN)
+ if (!removeDimple) continue;
+ if (corners.a) this.v.ai_drawBlock(col, row, block_color, 16, this.v.MAIN);
+ if (corners.b) this.v.ai_drawBlock(col, row, block_color, 17, this.v.MAIN);
+ if (corners.c) this.v.ai_drawBlock(col, row, block_color, 18, this.v.MAIN);
+ if (corners.d) this.v.ai_drawBlock(col, row, block_color, 19, this.v.MAIN);
}
}
- }
+ };
let template4 = function () {
- if (this['ISGAME'] && this['redrawBlocked']) {
- return
+ if (this.ISGAME && this.redrawBlocked) {
+ return;
} else {
- if (!this['ISGAME'] && (this['v']['redrawBlocked'] || !this['v']['QueueHoldEnabled'])) {
- return
+ if (!this.ISGAME && (this.v.redrawBlocked || !this.v.QueueHoldEnabled)) {
+ return;
}
- };
- this['v']['clearQueueCanvas']();
+ }
+ this.v.clearQueueCanvas();
let plug = 0;
- for (var count = 0; count < this['R']['showPreviews']; count++) {
- if (count >= this['queue']['length']) {
- if (this['pmode'] != 9) {
- break
- };
- if (this['ModeManager']['repeatQueue']) {
- this['ModeManager']['addStaticQueueToQueue']()
+ for (var count = 0; count < this.R.showPreviews; count++) {
+ if (count >= this.queue.length) {
+ if (this.pmode != 9) {
+ break;
+ }
+ if (this.ModeManager.repeatQueue) {
+ this.ModeManager.addStaticQueueToQueue();
} else {
- break
+ break;
}
- };
- var currPiece = this['queue'][count];
- var currSet = this['blockSets'][currPiece['set']]['previewAs'],
- blocks = currSet['blocks'][currPiece['id']]['blocks'][0],
- currColor = currSet['blocks'][currPiece['id']]['color'],
- currWeird = (!currSet['equidist']) ? currSet['blocks'][currPiece['id']]['yp'] : [0, 3],
- blocks_length = blocks['length'],
- something = (currSet['blocks'][currPiece['id']]['xp']) ? currSet['blocks'][currPiece['id']]['xp'] : [0, blocks_length - 1];
+ }
+ var currPiece = this.queue[count];
+ var currSet = this.blockSets[currPiece.set].previewAs,
+ blocks = currSet.blocks[currPiece.id].blocks[0],
+ currColor = currSet.blocks[currPiece.id].color,
+ currWeird = !currSet.equidist ? currSet.blocks[currPiece.id].yp : [0, 3],
+ blocks_length = blocks.length,
+ something = currSet.blocks[currPiece.id].xp ? currSet.blocks[currPiece.id].xp : [0, blocks_length - 1];
for (var y = currWeird[0]; y <= currWeird[1]; y++) {
for (var x = something[0]; x <= something[1]; x++) {
if (blocks[y][x] > 0) {
- let solve = solveConnected(blocks, x, y)
- this['v']['ai_drawBlockOnCanvas'](x - something[0], y - currWeird[0] + plug, currColor, solve.connect_value, this['v'].QUEUE);
- if (currPiece['item'] && blocks[y][x] === currPiece['item']) {
- this['v']['drawBrickOverlayOnCanvas'](x - something[0], y - currWeird[0] + plug, this['v'].QUEUE)
+ let solve = solveConnected(blocks, x, y);
+ this.v.ai_drawBlockOnCanvas(
+ x - something[0],
+ y - currWeird[0] + plug,
+ currColor,
+ solve.connect_value,
+ this.v.QUEUE
+ );
+ if (currPiece.item && blocks[y][x] === currPiece.item) {
+ this.v.drawBrickOverlayOnCanvas(x - something[0], y - currWeird[0] + plug, this.v.QUEUE);
}
- if (solve.overlay > 0 && removeDimple) this['v']['ai_drawBlockOnCanvas'](x - something[0], y - currWeird[0] + plug, currColor, solve.overlay, this['v'].QUEUE);
+ if (solve.overlay > 0 && removeDimple)
+ this.v.ai_drawBlockOnCanvas(
+ x - something[0],
+ y - currWeird[0] + plug,
+ currColor,
+ solve.overlay,
+ this.v.QUEUE
+ );
}
}
- };
- if (currSet['equidist']) {
- plug += 3
+ }
+ if (currSet.equidist) {
+ plug += 3;
} else {
- plug += currWeird[1] - currWeird[0] + 2
+ plug += currWeird[1] - currWeird[0] + 2;
}
}
};
if (window.Game != undefined) {
- let onG = Game['prototype']['drawGhostAndCurrent']
- Game['prototype']['drawGhostAndCurrent'] = function () {
+ let onG = Game.prototype.drawGhostAndCurrent;
+ Game.prototype.drawGhostAndCurrent = function () {
if (usingConnected || usingGhostConnected) {
- return template1.call(this)
+ return template1.call(this);
}
- let val = onG.apply(this, arguments)
- return val
- }
- let onH = Game['prototype']['redrawHoldBox']
- Game['prototype']['redrawHoldBox'] = function () {
+ let val = onG.apply(this, arguments);
+ return val;
+ };
+ let onH = Game.prototype.redrawHoldBox;
+ Game.prototype.redrawHoldBox = function () {
if (usingConnected) {
- return template2.call(this)
+ return template2.call(this);
}
- let val = onH.apply(this, arguments)
- return val
- }
- let onQ = Game['prototype']['updateQueueBox']
- Game['prototype']['updateQueueBox'] = function () {
+ let val = onH.apply(this, arguments);
+ return val;
+ };
+ let onQ = Game.prototype.updateQueueBox;
+ Game.prototype.updateQueueBox = function () {
if (usingConnected) {
- return template4.call(this)
+ return template4.call(this);
}
- let val = onQ.apply(this, arguments)
- return val
- }
- Game.prototype.ai_drawMatrix = template3
+ let val = onQ.apply(this, arguments);
+ return val;
+ };
+ Game.prototype.ai_drawMatrix = template3;
}
- if (window.Replayer != undefined && location.href.includes('replay')) {
- Replayer.prototype.ai_drawMatrix = template3
+ if (window.Replayer != undefined && location.href.includes("replay")) {
+ Replayer.prototype.ai_drawMatrix = template3;
- let onG = Replayer['prototype']['drawGhostAndCurrent']
- Replayer['prototype']['drawGhostAndCurrent'] = function () {
+ let onG = Replayer.prototype.drawGhostAndCurrent;
+ Replayer.prototype.drawGhostAndCurrent = function () {
if (usingConnected || (usingGhostConnected && this.g.ghostSkinId === 0)) {
- return template1.call(this)
+ return template1.call(this);
}
- let val = onG.apply(this, arguments)
- return val
- }
- let onH = Replayer['prototype']['redrawHoldBox']
- Replayer['prototype']['redrawHoldBox'] = function () {
+ let val = onG.apply(this, arguments);
+ return val;
+ };
+ let onH = Replayer.prototype.redrawHoldBox;
+ Replayer.prototype.redrawHoldBox = function () {
if (usingConnected) {
- return template2.call(this)
+ return template2.call(this);
}
- let val = onH.apply(this, arguments)
- return val
- }
- let onQ = Replayer['prototype']['updateQueueBox']
- Replayer['prototype']['updateQueueBox'] = function () {
+ let val = onH.apply(this, arguments);
+ return val;
+ };
+ let onQ = Replayer.prototype.updateQueueBox;
+ Replayer.prototype.updateQueueBox = function () {
if (usingConnected) {
- return template4.call(this)
+ return template4.call(this);
}
- let val = onQ.apply(this, arguments)
- return val
- }
+ let val = onQ.apply(this, arguments);
+ return val;
+ };
}
if (window.View != undefined) {
- if (!location.href.includes('export')) {
+ if (!location.href.includes("export")) {
View.prototype.ai_drawBlockOnCanvas = function (t, e, i, c, s) {
let o = s === this.HOLD ? this.hctx : this.qctx;
if (0 === this.skinId) {
var n = this.g.monochromeSkin && i <= 7 ? this.g.monochromeSkin : this.g.colors[i];
- this.drawRectangle(o, t * this.block_size, e * this.block_size, this.block_size, this.block_size, n)
+ this.drawRectangle(o, t * this.block_size, e * this.block_size, this.block_size, this.block_size, n);
} else {
- o.drawImage(this.tex, this.g.coffset[i] * this.g.skins[this.skinId].w, c * this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, t * this.block_size, e * this.block_size, this.block_size, this.block_size)
+ o.drawImage(
+ this.tex,
+ this.g.coffset[i] * this.g.skins[this.skinId].w,
+ c * this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ t * this.block_size,
+ e * this.block_size,
+ this.block_size,
+ this.block_size
+ );
}
- }
- let redraw = View.prototype.redraw
+ };
+ let redraw = View.prototype.redraw;
View.prototype.redraw = function () {
if (usingConnected) {
if (!this.redrawBlocked) {
- if (this.clearMainCanvas(), !this.g.isInvisibleSkin) this.g.ai_drawMatrix()
- this.drawGhostAndCurrent(), this.g.redBar && this.drawRectangle(this.ctx, 240, (20 - this.g.redBar) * this.block_size, 8, this.g.redBar * this.block_size, "#FF270F")
+ if ((this.clearMainCanvas(), !this.g.isInvisibleSkin)) this.g.ai_drawMatrix();
+ this.drawGhostAndCurrent(),
+ this.g.redBar &&
+ this.drawRectangle(
+ this.ctx,
+ 240,
+ (20 - this.g.redBar) * this.block_size,
+ 8,
+ this.g.redBar * this.block_size,
+ "#FF270F"
+ );
}
- return
+ return;
}
- return redraw.apply(this, arguments)
- }
+ return redraw.apply(this, arguments);
+ };
View.prototype.ai_drawBlock = function (t, e, i, c) {
if (i && t >= 0 && e >= 0 && t < 10 && e < 20) {
var s = this.drawScale * this.block_size;
- this.ctx.drawImage(this.tex, this.g.coffset[i] * this.g.skins[this.skinId].w, c * this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, t * this.block_size, e * this.block_size, s, s);
+ this.ctx.drawImage(
+ this.tex,
+ this.g.coffset[i] * this.g.skins[this.skinId].w,
+ c * this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ t * this.block_size,
+ e * this.block_size,
+ s,
+ s
+ );
}
- }
+ };
View.prototype.ai_drawGhostBlock = function (t, e, i, c) {
if (t >= 0 && e >= 0 && t < 10 && e < 20) {
var s = this.drawScale * this.block_size;
- this.ctx.globalAlpha = ghostAlpha
- offscreenContext.drawImage(this.tex, this.g.coffset[i] * this.g.skins[this.skinId].w, c * this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, 0, 0, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w)
- if (drawCanvas) this.ctx.drawImage(offscreenCanvas, 0, 0, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, t * this.block_size, e * this.block_size, s, s)
+ this.ctx.globalAlpha = ghostAlpha;
+ offscreenContext.drawImage(
+ this.tex,
+ this.g.coffset[i] * this.g.skins[this.skinId].w,
+ c * this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ 0,
+ 0,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w
+ );
+ if (drawCanvas)
+ this.ctx.drawImage(
+ offscreenCanvas,
+ 0,
+ 0,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ t * this.block_size,
+ e * this.block_size,
+ s,
+ s
+ );
this.ctx.globalAlpha = 1;
}
- }
+ };
var oldDrawGhostAndCurrent = View.prototype.drawGhostAndCurrent;
View.prototype.drawGhostAndCurrent = function () {
-
- if (!usingConnected)
- return oldDrawGhostAndCurrent.apply(this, arguments);
+ if (!usingConnected) return oldDrawGhostAndCurrent.apply(this, arguments);
var t = this.g.blockSets[this.g.activeBlock.set],
- e = 1 === t.scale ? t.blocks[this.g.activeBlock.id].blocks[this.g.activeBlock.rot] : t.previewAs.blocks[this.g.activeBlock.id].blocks[this.g.activeBlock.rot],
+ e =
+ 1 === t.scale
+ ? t.blocks[this.g.activeBlock.id].blocks[this.g.activeBlock.rot]
+ : t.previewAs.blocks[this.g.activeBlock.id].blocks[this.g.activeBlock.rot],
i = e.length;
- if (this.drawScale = t.scale, this.ghostEnabled) {
+ if (((this.drawScale = t.scale), this.ghostEnabled)) {
for (var s = 0; s < i; s++) {
for (var o = 0; o < i; o++) {
if (e[s][o] > 0) {
- let solve = solveConnected(e, o, s)
- offscreenContext.clearRect(0, 0, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w)
- drawCanvas = false
+ let solve = solveConnected(e, o, s);
+ offscreenContext.clearRect(0, 0, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w);
+ drawCanvas = false;
if (solve.overlay > 0 && removeDimple) {
- this.ai_drawGhostBlock(this.g.ghostPiece.pos.x + o * this.drawScale, this.g.ghostPiece.pos.y + s * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.connect_value);
- drawCanvas = true
- this.ai_drawGhostBlock(this.g.ghostPiece.pos.x + o * this.drawScale, this.g.ghostPiece.pos.y + s * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.overlay);
- }
- else {
- drawCanvas = true
- this.ai_drawGhostBlock(this.g.ghostPiece.pos.x + o * this.drawScale, this.g.ghostPiece.pos.y + s * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.connect_value);
+ this.ai_drawGhostBlock(
+ this.g.ghostPiece.pos.x + o * this.drawScale,
+ this.g.ghostPiece.pos.y + s * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.connect_value
+ );
+ drawCanvas = true;
+ this.ai_drawGhostBlock(
+ this.g.ghostPiece.pos.x + o * this.drawScale,
+ this.g.ghostPiece.pos.y + s * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.overlay
+ );
+ } else {
+ drawCanvas = true;
+ this.ai_drawGhostBlock(
+ this.g.ghostPiece.pos.x + o * this.drawScale,
+ this.g.ghostPiece.pos.y + s * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.connect_value
+ );
}
}
}
@@ -562,71 +799,160 @@ export const initConnectedSkins = () => {
for (s = 0; s < i; s++) {
for (o = 0; o < i; o++) {
if (e[s][o] > 0) {
- let solve = solveConnected(e, o, s)
- this.ai_drawBlock(this.g.activeBlock.pos.x + o * this.drawScale, this.g.activeBlock.pos.y + s * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.connect_value);
- if (solve.overlay > 0 && removeDimple) this.ai_drawBlock(this.g.activeBlock.pos.x + o * this.drawScale, this.g.activeBlock.pos.y + s * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.overlay);
+ let solve = solveConnected(e, o, s);
+ this.ai_drawBlock(
+ this.g.activeBlock.pos.x + o * this.drawScale,
+ this.g.activeBlock.pos.y + s * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.connect_value
+ );
+ if (solve.overlay > 0 && removeDimple)
+ this.ai_drawBlock(
+ this.g.activeBlock.pos.x + o * this.drawScale,
+ this.g.activeBlock.pos.y + s * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.overlay
+ );
}
}
}
- this.drawScale = 1
- }
- }
- else {
+ this.drawScale = 1;
+ };
+ } else {
View.prototype.ai_drawBlockOnCanvas = function (t, i, s, c, e) {
let h = this.block_size,
o = this.ctx;
- if (e === this.HOLD ? (this.drawOffsetTop = this.AP.HLD.T, this.drawOffsetLeft = this.AP.HLD.L, this.block_size = this.AP.HLD.BS) : (this.drawOffsetTop = this.AP.QUE.T, this.drawOffsetLeft = this.AP.QUE.L, this.block_size = this.AP.QUE.BS), 0 === this.skinId) {
+ if (
+ (e === this.HOLD
+ ? ((this.drawOffsetTop = this.AP.HLD.T),
+ (this.drawOffsetLeft = this.AP.HLD.L),
+ (this.block_size = this.AP.HLD.BS))
+ : ((this.drawOffsetTop = this.AP.QUE.T),
+ (this.drawOffsetLeft = this.AP.QUE.L),
+ (this.block_size = this.AP.QUE.BS)),
+ 0 === this.skinId)
+ ) {
var r = this.g.monochromeSkin && s <= 7 ? this.g.monochromeSkin : this.g.colors[s];
- this.drawRectangle(o, t * this.block_size, i * this.block_size, this.block_size, this.block_size, r)
- } else this.drawImage(o, this.tex, this.g.coffset[s] * this.g.skins[this.skinId].w, c * this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, t * this.block_size, i * this.block_size, this.block_size, this.block_size);
- this.block_size = h
- }
- let redraw = View.prototype.drawMainStage
+ this.drawRectangle(o, t * this.block_size, i * this.block_size, this.block_size, this.block_size, r);
+ } else
+ this.drawImage(
+ o,
+ this.tex,
+ this.g.coffset[s] * this.g.skins[this.skinId].w,
+ c * this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ t * this.block_size,
+ i * this.block_size,
+ this.block_size,
+ this.block_size
+ );
+ this.block_size = h;
+ };
+ let redraw = View.prototype.drawMainStage;
View.prototype.drawMainStage = function () {
if (!usingConnected) {
- return redraw.apply(this, arguments)
+ return redraw.apply(this, arguments);
}
- if (this.drawOffsetTop = this.AP.STG.T, this.drawOffsetLeft = this.AP.STG.L, !this.g.isInvisibleSkin) this.g.ai_drawMatrix()
- this.drawGhostAndCurrent()
- if (this.g.redBar) this.drawRectangle(this.ctx, this.AP.STG.W, (20 - this.g.redBar) * this.BS, 8, this.g.redBar * this.BS, "#FF270F")
- }
+ if (((this.drawOffsetTop = this.AP.STG.T), (this.drawOffsetLeft = this.AP.STG.L), !this.g.isInvisibleSkin))
+ this.g.ai_drawMatrix();
+ this.drawGhostAndCurrent();
+ if (this.g.redBar)
+ this.drawRectangle(
+ this.ctx,
+ this.AP.STG.W,
+ (20 - this.g.redBar) * this.BS,
+ 8,
+ this.g.redBar * this.BS,
+ "#FF270F"
+ );
+ };
View.prototype.ai_drawBlock = function (t, i, s, c) {
if (s && t >= 0 && i >= 0 && t < 10 && i < 20) {
var e = this.drawScale * this.BS;
- this.drawImage(this.ctx, this.tex, this.g.coffset[s] * this.g.skins[this.skinId].w, c * this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, t * this.BS, i * this.BS, e, e);
+ this.drawImage(
+ this.ctx,
+ this.tex,
+ this.g.coffset[s] * this.g.skins[this.skinId].w,
+ c * this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ t * this.BS,
+ i * this.BS,
+ e,
+ e
+ );
}
- }
+ };
View.prototype.ai_drawGhostBlock = function (t, i, s, c) {
if (t >= 0 && i >= 0 && t < 10 && i < 20) {
var e = this.drawScale * this.BS;
- this.ctx.globalAlpha = ghostAlpha
- offscreenContext.drawImage(this.tex, this.g.coffset[s] * this.g.skins[this.skinId].w, c * this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, 0, 0, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w)
- if (drawCanvas) this.drawImage(this.ctx, offscreenCanvas, 0, 0, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w, t * this.BS, i * this.BS, e, e)
+ this.ctx.globalAlpha = ghostAlpha;
+ offscreenContext.drawImage(
+ this.tex,
+ this.g.coffset[s] * this.g.skins[this.skinId].w,
+ c * this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ 0,
+ 0,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w
+ );
+ if (drawCanvas)
+ this.drawImage(
+ this.ctx,
+ offscreenCanvas,
+ 0,
+ 0,
+ this.g.skins[this.skinId].w,
+ this.g.skins[this.skinId].w,
+ t * this.BS,
+ i * this.BS,
+ e,
+ e
+ );
this.ctx.globalAlpha = 1;
}
- }
+ };
var oldDrawGhostAndCurrent = View.prototype.drawGhostAndCurrent;
View.prototype.drawGhostAndCurrent = function () {
- if (!usingConnected)
- return oldDrawGhostAndCurrent.apply(this, arguments);
+ if (!usingConnected) return oldDrawGhostAndCurrent.apply(this, arguments);
var t = this.g.blockSets[this.g.activeBlock.set],
- i = 1 === t.scale ? t.blocks[this.g.activeBlock.id].blocks[this.g.activeBlock.rot] : t.previewAs.blocks[this.g.activeBlock.id].blocks[this.g.activeBlock.rot],
+ i =
+ 1 === t.scale
+ ? t.blocks[this.g.activeBlock.id].blocks[this.g.activeBlock.rot]
+ : t.previewAs.blocks[this.g.activeBlock.id].blocks[this.g.activeBlock.rot],
s = i.length;
- if (this.drawScale = t.scale, this.ghostEnabled) {
+ if (((this.drawScale = t.scale), this.ghostEnabled)) {
for (var e = 0; e < s; e++) {
for (var h = 0; h < s; h++) {
if (i[e][h] > 0) {
- let solve = solveConnected(i, h, e)
- offscreenContext.clearRect(0, 0, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w)
- drawCanvas = false
+ let solve = solveConnected(i, h, e);
+ offscreenContext.clearRect(0, 0, this.g.skins[this.skinId].w, this.g.skins[this.skinId].w);
+ drawCanvas = false;
if (solve.overlay > 0 && removeDimple) {
- this.ai_drawGhostBlock(this.g.ghostPiece.pos.x + h * this.drawScale, this.g.ghostPiece.pos.y + e * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.connect_value);
- drawCanvas = true
- this.ai_drawGhostBlock(this.g.ghostPiece.pos.x + h * this.drawScale, this.g.ghostPiece.pos.y + e * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.overlay);
- }
- else {
- drawCanvas = true
- this.ai_drawGhostBlock(this.g.ghostPiece.pos.x + h * this.drawScale, this.g.ghostPiece.pos.y + e * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.connect_value);
+ this.ai_drawGhostBlock(
+ this.g.ghostPiece.pos.x + h * this.drawScale,
+ this.g.ghostPiece.pos.y + e * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.connect_value
+ );
+ drawCanvas = true;
+ this.ai_drawGhostBlock(
+ this.g.ghostPiece.pos.x + h * this.drawScale,
+ this.g.ghostPiece.pos.y + e * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.overlay
+ );
+ } else {
+ drawCanvas = true;
+ this.ai_drawGhostBlock(
+ this.g.ghostPiece.pos.x + h * this.drawScale,
+ this.g.ghostPiece.pos.y + e * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.connect_value
+ );
}
}
}
@@ -635,16 +961,25 @@ export const initConnectedSkins = () => {
for (e = 0; e < s; e++) {
for (h = 0; h < s; h++) {
if (i[e][h] > 0) {
- let solve = solveConnected(i, h, e)
- this.ai_drawBlock(this.g.activeBlock.pos.x + h * this.drawScale, this.g.activeBlock.pos.y + e * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.connect_value);
- if (solve.overlay > 0 && removeDimple) this.ai_drawBlock(this.g.activeBlock.pos.x + h * this.drawScale, this.g.activeBlock.pos.y + e * this.drawScale, t.blocks[this.g.activeBlock.id].color, solve.overlay);
-
+ let solve = solveConnected(i, h, e);
+ this.ai_drawBlock(
+ this.g.activeBlock.pos.x + h * this.drawScale,
+ this.g.activeBlock.pos.y + e * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.connect_value
+ );
+ if (solve.overlay > 0 && removeDimple)
+ this.ai_drawBlock(
+ this.g.activeBlock.pos.x + h * this.drawScale,
+ this.g.activeBlock.pos.y + e * this.drawScale,
+ t.blocks[this.g.activeBlock.id].color,
+ solve.overlay
+ );
}
}
}
- this.drawScale = 1
- }
+ this.drawScale = 1;
+ };
}
-
}
-}
\ No newline at end of file
+};
diff --git a/src/stats.js b/src/stats.js
index 4e616ea..c10a098 100644
--- a/src/stats.js
+++ b/src/stats.js
@@ -1,18 +1,14 @@
-import { Config } from "./config"
-
+import { Config } from "./config";
const replaceBadValues = (n, defaultValue) => {
// NaN check
- if (Number.isNaN(n) || !Number.isFinite(n))
- return defaultValue || 0;
+ if (Number.isNaN(n) || !Number.isFinite(n)) return defaultValue || 0;
return n;
-
-}
+};
let stats = [];
const updateStats = function () {
-
- const index = this.ISGAME? 0 : parseInt(this.v.canvas.parentElement.getAttribute("data-index"));
+ const index = this.ISGAME ? 0 : parseInt(this.v.canvas.parentElement.getAttribute("data-index"));
stats[index].forEach((stat) => {
if (stat.enabled && stat.row) {
if (stat.enabledMode && stat.enabledMode != this.pmode) {
@@ -21,12 +17,12 @@ const updateStats = function () {
}
stat.row.style.display = "table-row";
var val = stat.calc(this);
- stat.row.children[1].innerHTML = val;
+ stat.row.children[1].textContent = val;
} else {
stat.row.style.display = "none";
}
});
-}
+};
const initStat = (index, name, configVar, calc, options = {}) => {
stats[index].push({
name,
@@ -34,132 +30,159 @@ const initStat = (index, name, configVar, calc, options = {}) => {
val: 0,
enabled: Config()[configVar],
initialValue: options.initialValue || 0,
- enabledMode: options.enabledMode || 0, // 0 = enabled for all modes
+ enabledMode: options.enabledMode || 0, // 0 = enabled for all modes
});
- Config().onChange(configVar, val => {
- for (var individualStats of stats)
- var stat = individualStats.find(e => e.name == name);
- stat.enabled = val;
- })
-}
+ Config().onChange(configVar, (val) => {
+ for (var individualStats of stats) var stat = individualStats.find((e) => e.name == name);
+ stat.enabled = val;
+ });
+};
export const initStats = () => {
const stages = document.querySelectorAll("#stage");
stages.forEach((stageEle, i) => {
- stageEle.setAttribute("data-index", i);
+ stageEle.setAttribute("data-index", i);
stats.push([]);
initGameStats(stageEle, i);
- })
-
-}
+ });
+};
export const initGameStats = (stageEle, index) => {
// these must be non-arrow functions so they can be bound
- initStat(index,"APP", "ENABLE_STAT_APP", game => replaceBadValues(game.gamedata.attack / game.placedBlocks).toFixed(3));
- initStat(index,"PPD", "ENABLE_STAT_PPD", game => replaceBadValues(game.placedBlocks / game.gamedata.garbageCleared).toFixed(3));
-
- initStat(index,"Block pace", "ENABLE_STAT_CHEESE_BLOCK_PACE", game => {
- let totalLines = game.ISGAME ? game["cheeseModes"][game["sprintMode"]] : game.initialLines;
- let linesLeft = game.linesRemaining
- let linesCleared = totalLines - linesLeft
- var piecePace = replaceBadValues((linesLeft / linesCleared) * game["placedBlocks"] + game["placedBlocks"])
- return (piecePace * 0 + 1) ? Math.floor(piecePace) : '0'
- }, { enabledMode: 3 });
-
- initStat(index,"Time pace", "ENABLE_STAT_CHEESE_TIME_PACE", game => {
- let totalLines = game.ISGAME ? game["cheeseModes"][game["sprintMode"]] : game.initialLines;
- let linesLeft = game.linesRemaining
- let linesCleared = totalLines - linesLeft;
- let time = game.ISGAME? game.clock : game.clock / 1000;
- var seconds = replaceBadValues((totalLines / linesCleared) * time);
- let m = Math.floor(seconds / 60)
- let s = Math.floor(seconds % 60)
- let ms = Math.floor((seconds % 1) * 100)
- return (m ? (m + ":") : '') + ("0" + s).slice(-2) + "." + ("0" + ms).slice(-2)
- }, { enabledMode: 3 });
-
- initStat(index,"PPB", "ENABLE_STAT_PPB", game => {
- var score = game["gamedata"]["score"];
- var placedBlocks = game["placedBlocks"];
- return replaceBadValues(score / placedBlocks).toFixed(2);
- }, { enabledMode: 5 });
-
- initStat(index,"Score pace", "ENABLE_STAT_SCORE_PACE", game => {
- var score = game["gamedata"]["score"];
- let time = game.ISGAME? game.clock : game.clock / 1000;
- return replaceBadValues(score + score / time * (120 - time)).toFixed(0);
- }, { enabledMode: 5 });
-
- initStat(index,"PC #", "ENABLE_STAT_PC_NUMBER", game => {
- let suffixes = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th'];
- let pcs = game.gamedata.PCs;
-
- if (!game.PCdata)
- return "1st";
- var blocks = game.placedBlocks - game.PCdata.blocks;
- let pcNumber = ((pcs + 1 + 3 * ((10 * pcs - blocks) / 5)) % 7) || 7;
- pcNumber = replaceBadValues(pcNumber, 1);
- if (!Number.isInteger(pcNumber))
- return "";
- return pcNumber + suffixes[pcNumber];
- }, { enabledMode: 8 });
+ initStat(index, "APP", "ENABLE_STAT_APP", (game) =>
+ replaceBadValues(game.gamedata.attack / game.placedBlocks).toFixed(3)
+ );
+ initStat(index, "PPD", "ENABLE_STAT_PPD", (game) =>
+ replaceBadValues(game.placedBlocks / game.gamedata.garbageCleared).toFixed(3)
+ );
+
+ initStat(
+ index,
+ "Block pace",
+ "ENABLE_STAT_CHEESE_BLOCK_PACE",
+ (game) => {
+ let totalLines = game.ISGAME ? game["cheeseModes"][game["sprintMode"]] : game.initialLines;
+ let linesLeft = game.linesRemaining;
+ let linesCleared = totalLines - linesLeft;
+ var piecePace = replaceBadValues((linesLeft / linesCleared) * game["placedBlocks"] + game["placedBlocks"]);
+ return piecePace * 0 + 1 ? Math.floor(piecePace) : "0";
+ },
+ { enabledMode: 3 }
+ );
+
+ initStat(
+ index,
+ "Time pace",
+ "ENABLE_STAT_CHEESE_TIME_PACE",
+ (game) => {
+ let totalLines = game.ISGAME ? game["cheeseModes"][game["sprintMode"]] : game.initialLines;
+ let linesLeft = game.linesRemaining;
+ let linesCleared = totalLines - linesLeft;
+ let time = game.ISGAME ? game.clock : game.clock / 1000;
+ var seconds = replaceBadValues((totalLines / linesCleared) * time);
+ let m = Math.floor(seconds / 60);
+ let s = Math.floor(seconds % 60);
+ let ms = Math.floor((seconds % 1) * 100);
+ return (m ? m + ":" : "") + ("0" + s).slice(-2) + "." + ("0" + ms).slice(-2);
+ },
+ { enabledMode: 3 }
+ );
+
+ initStat(
+ index,
+ "PPB",
+ "ENABLE_STAT_PPB",
+ (game) => {
+ var score = game["gamedata"]["score"];
+ var placedBlocks = game["placedBlocks"];
+ return replaceBadValues(score / placedBlocks).toFixed(2);
+ },
+ { enabledMode: 5 }
+ );
+
+ initStat(
+ index,
+ "Score pace",
+ "ENABLE_STAT_SCORE_PACE",
+ (game) => {
+ var score = game["gamedata"]["score"];
+ let time = game.ISGAME ? game.clock : game.clock / 1000;
+ return replaceBadValues(score + (score / time) * (120 - time)).toFixed(0);
+ },
+ { enabledMode: 5 }
+ );
+
+ initStat(
+ index,
+ "PC #",
+ "ENABLE_STAT_PC_NUMBER",
+ (game) => {
+ let suffixes = ["th", "st", "nd", "rd", "th", "th", "th", "th"];
+ let pcs = game.gamedata.PCs;
+
+ if (!game.PCdata) return "1st";
+ var blocks = game.placedBlocks - game.PCdata.blocks;
+ let pcNumber = (pcs + 1 + 3 * ((10 * pcs - blocks) / 5)) % 7 || 7;
+ pcNumber = replaceBadValues(pcNumber, 1);
+ if (!Number.isInteger(pcNumber)) return "";
+ return pcNumber + suffixes[pcNumber];
+ },
+ { enabledMode: 8 }
+ );
const statsTable = document.createElement("TABLE");
- statsTable.className = 'stats-table'
+ statsTable.className = "stats-table";
//document.getElementById("stage").appendChild(statsTable);
stageEle.appendChild(statsTable);
- stats[index].forEach(stat => {
- const row = document.createElement('tr');
+ stats[index].forEach((stat) => {
+ const row = document.createElement("tr");
row.style.display = "none";
- const name = document.createElement('td');
+ const name = document.createElement("td");
name.innerHTML = stat.name;
- const val = document.createElement('td');
- val.className = 'val';
+ const val = document.createElement("td");
+ val.className = "val";
val.id = `${stat.name}-val`;
val.innerHTML = stat.val;
row.appendChild(name);
row.appendChild(val);
statsTable.appendChild(row);
stat.row = row;
- })
+ });
if (typeof Game == "function") {
let oldQueueBoxFunc = Game.prototype.updateQueueBox;
Game.prototype.updateQueueBox = function () {
- updateStats.call(this)
+ updateStats.call(this);
return oldQueueBoxFunc.apply(this, arguments);
- }
+ };
}
if (typeof Replayer == "function" && typeof Game != "function") {
let oldQueueBoxFunc = Replayer.prototype.updateQueueBox;
Replayer.prototype.updateQueueBox = function () {
- updateStats.call(this)
+ updateStats.call(this);
return oldQueueBoxFunc.apply(this, arguments);
- }
+ };
let oldCheckLineClears = Replayer.prototype.checkLineClears;
- Replayer.prototype.checkLineClears = function() {
+ Replayer.prototype.checkLineClears = function () {
let val = oldCheckLineClears.apply(this, arguments);
if (this.PCdata) {
// empty matrix check
- if (this.matrix.every(row => row.every(cell => cell == 0))) {
+ if (this.matrix.every((row) => row.every((cell) => cell == 0))) {
this.PCdata.blocks = 0;
} else {
this.PCdata.blocks++;
}
-
}
return val;
- }
+ };
var oldInitReplay = Replayer.prototype.initReplay;
Replayer.prototype.initReplay = function () {
let val = oldInitReplay.apply(this, arguments);
this.initialLines = this.linesRemaining;
- if (this.pmode == 8)
- this.PCdata = { blocks : 0 }
+ if (this.pmode == 8) this.PCdata = { blocks: 0 };
return val;
- }
+ };
}
-
-}
\ No newline at end of file
+};
diff --git a/src/style.css b/src/style.css
index 8553b85..8bc45ac 100644
--- a/src/style.css
+++ b/src/style.css
@@ -1,4 +1,4 @@
-@import url('https://fonts.googleapis.com/css2?family=Gugi&display=swap');
+@import url("https://fonts.googleapis.com/css2?family=Gugi&display=swap");
/* =========== settings modal css ============= */
@@ -41,7 +41,6 @@
height: 30px;
font-size: 25px;
border: solid 1px black;
-
}
.settings-modalTextarea {
@@ -84,7 +83,6 @@
bottom: 30px;
transition: 0.5s;
-
}
.settings-modalCloseButton {
@@ -164,8 +162,8 @@
background: #d3d3d3;
outline: none;
opacity: 0.7;
- -webkit-transition: .2s;
- transition: opacity .2s;
+ -webkit-transition: 0.2s;
+ transition: opacity 0.2s;
}
.settings-slider:hover {
@@ -178,7 +176,7 @@
width: 25px;
height: 25px;
border-radius: 50%;
- background: #04AA6D;
+ background: #04aa6d;
cursor: pointer;
}
@@ -186,7 +184,7 @@
width: 25px;
height: 25px;
border-radius: 50%;
- background: #04AA6D;
+ background: #04aa6d;
cursor: pointer;
}
@@ -194,44 +192,44 @@
@-webkit-keyframes slideIn {
from {
bottom: -300px;
- opacity: 0
+ opacity: 0;
}
to {
bottom: 0;
- opacity: 1
+ opacity: 1;
}
}
@keyframes slideIn {
from {
bottom: -300px;
- opacity: 0
+ opacity: 0;
}
to {
bottom: 0;
- opacity: 1
+ opacity: 1;
}
}
@-webkit-keyframes fadeIn {
from {
- opacity: 0
+ opacity: 0;
}
to {
- opacity: 1
+ opacity: 1;
}
}
@keyframes fadeIn {
from {
- opacity: 0
+ opacity: 0;
}
to {
- opacity: 1
+ opacity: 1;
}
}
@@ -257,7 +255,7 @@
.mmLoader {
border: 16px solid white;
- border-top: 16px solid #04AA6D;
+ border-top: 16px solid #04aa6d;
border-radius: 50%;
width: 120px;
height: 120px;
@@ -373,7 +371,7 @@
margin: 2px 2px;
border-radius: 100%;
border: 2px solid #222222;
- background-color: #04AA6D;
+ background-color: #04aa6d;
}
.mm-button:hover {
@@ -393,7 +391,7 @@
text-decoration: none;
margin: 2px 2px;
border: 2px solid #222222;
- background-color: #04AA6D;
+ background-color: #04aa6d;
}
.mm-ready-button:hover {
@@ -438,7 +436,6 @@
display: inline !important;
}
-
/* ===== stats css ===== */
.stats-table {
@@ -550,7 +547,6 @@
pointer-events: none;
}
-
/* practice mode settings */
.show-practice-mode-settings {
display: block !important;
@@ -584,7 +580,7 @@
/* replay addons */
.replay-btn {
- padding: .25em .5em;
+ padding: 0.25em 0.5em;
border: solid 1px white;
border-radius: 4px;
display: inline-block;
@@ -596,7 +592,7 @@
.replay-btn:hover,
.replay-btn:focus {
cursor: pointer;
- color: #04AA6D;
+ color: #04aa6d;
}
.replay-btn-group {
@@ -606,12 +602,12 @@
border-radius: 4px;
}
-.replay-btn-group>.c-btn {
+.replay-btn-group > .c-btn {
border-radius: 0;
border: none;
border-right: 1px solid white;
}
-.replay-btn-group>.c-btn:last-child {
+.replay-btn-group > .c-btn:last-child {
border-right: none;
-}
\ No newline at end of file
+}
diff --git a/src/teamsMode.js b/src/teamsMode.js
index 373095f..f7473ac 100644
--- a/src/teamsMode.js
+++ b/src/teamsMode.js
@@ -1,157 +1,184 @@
export const fixTeamsMode = () => {
- let oldDecode = Live.prototype.decodeActionsAndPlay
- Live.prototype.decodeActionsAndPlay = function () {
- let temp = this.p.GS.extendedAvailable
- if (this.p.GS.teamData) {
- this.p.GS.extendedAvailable = true
- var cid = this.rcS[arguments[0][1]];
- if (cid in this.p.GS.cidSlots && this.clients[cid].rep) {
- this.clients[cid].rep.v.cancelLiveMatrix = true
- }
- }
- let v = oldDecode.apply(this, arguments)
- this.p.GS.extendedAvailable = temp
- return v
+ let oldDecode = Live.prototype.decodeActionsAndPlay;
+ Live.prototype.decodeActionsAndPlay = function () {
+ let temp = this.p.GS.extendedAvailable;
+ if (this.p.GS.teamData) {
+ this.p.GS.extendedAvailable = true;
+ var cid = this.rcS[arguments[0][1]];
+ if (cid in this.p.GS.cidSlots && this.clients[cid].rep) {
+ this.clients[cid].rep.v.cancelLiveMatrix = true;
+ }
}
- let oldRep = Game.prototype.sendRepFragment
- Game.prototype.sendRepFragment = function () {
- let temp = this.transmitMode
- if (this.GS.teamData) {
- this.transmitMode = 1
- }
- let v = oldRep.apply(this, arguments)
- this.transmitMode = temp
- return v
+ let v = oldDecode.apply(this, arguments);
+ this.p.GS.extendedAvailable = temp;
+ return v;
+ };
+ let oldRep = Game.prototype.sendRepFragment;
+ Game.prototype.sendRepFragment = function () {
+ let temp = this.transmitMode;
+ if (this.GS.teamData) {
+ this.transmitMode = 1;
}
- let oldUpdate = Game.prototype.update
- Game.prototype.update = function () {
- let temp = this.transmitMode
- if (this.GS.teamData) {
- this.transmitMode = 1
- }
- let v = oldUpdate.apply(this, arguments)
- this.transmitMode = temp
- return v
+ let v = oldRep.apply(this, arguments);
+ this.transmitMode = temp;
+ return v;
+ };
+ let oldUpdate = Game.prototype.update;
+ Game.prototype.update = function () {
+ let temp = this.transmitMode;
+ if (this.GS.teamData) {
+ this.transmitMode = 1;
}
- let oldFlash = SlotView.prototype.updateLiveMatrix
- SlotView.prototype.updateLiveMatrix = function () {
- if (this.cancelLiveMatrix) {
- this.queueCanvas.style.display = "block"
- this.holdCanvas.style.display = "block"
- return
- }
- this.queueCanvas.style.display = "none"
- this.holdCanvas.style.display = "none"
- return oldFlash.apply(this, arguments)
+ let v = oldUpdate.apply(this, arguments);
+ this.transmitMode = temp;
+ return v;
+ };
+ let oldFlash = SlotView.prototype.updateLiveMatrix;
+ SlotView.prototype.updateLiveMatrix = function () {
+ if (this.cancelLiveMatrix) {
+ this.queueCanvas.style.display = "block";
+ this.holdCanvas.style.display = "block";
+ return;
}
- let oldHold = Replayer.prototype.redrawHoldBox
- Replayer.prototype.redrawHoldBox = function () {
- this.v.QueueHoldEnabled = true;
- this.v.holdCanvas.style.display = 'block';
- return oldHold.apply(this, arguments)
+ this.queueCanvas.style.display = "none";
+ this.holdCanvas.style.display = "none";
+ return oldFlash.apply(this, arguments);
+ };
+ let oldHold = Replayer.prototype.redrawHoldBox;
+ Replayer.prototype.redrawHoldBox = function () {
+ this.v.QueueHoldEnabled = true;
+ this.v.holdCanvas.style.display = "block";
+ return oldHold.apply(this, arguments);
+ };
+ let oldQueue = Replayer.prototype.updateQueueBox;
+ Replayer.prototype.updateQueueBox = function () {
+ this.v.QueueHoldEnabled = true;
+ this.v.queueCanvas.style.display = "block";
+ return oldQueue.apply(this, arguments);
+ };
+ let oldSlotInit = Slot.prototype.init;
+ Slot.prototype.init = function () {
+ let life = this.gs.p.Live;
+ if (life?.roomConfig?.mode != 2) {
+ return oldSlotInit.apply(this, arguments);
}
- let oldQueue = Replayer.prototype.updateQueueBox
- Replayer.prototype.updateQueueBox = function () {
- this.v.QueueHoldEnabled = true;
- this.v.queueCanvas.style.display = 'block';
- return oldQueue.apply(this, arguments)
+ this.v.queueCanvas.style.display = "none";
+ this.v.holdCanvas.style.display = "none";
+ this.gs.holdQueueBlockSize = this.gs.matrixHeight / 20;
+ // console.log("hi2", this.gs.holdQueueBlockSize)
+ this.v.QueueHoldEnabled = true;
+ this.v.cancelLiveMatrix = false;
+ this.slotDiv.className = "slot";
+ this.slotDiv.style.left = this.x + "px";
+ this.slotDiv.style.top = this.y + "px";
+ this.stageDiv.style.position = "relative";
+ this.name.style.width = this.gs.matrixWidth + 2 + "px";
+ this.name.style.height = this.gs.nameHeight + "px";
+ this.name.style.fontSize = this.gs.nameFontSize + "px";
+ this.pCan.width = this.bgCan.width = this.gs.matrixWidth;
+ this.pCan.height = this.bgCan.height = this.gs.matrixHeight;
+ this.queueCan.width = this.holdCan.width = 4 * this.gs.holdQueueBlockSize;
+ this.holdCan.height = 4 * this.gs.holdQueueBlockSize;
+ this.queueCan.height = 15 * this.gs.holdQueueBlockSize;
+ (this.pCan.style.top =
+ this.bgCan.style.top =
+ this.holdCan.style.top =
+ this.queueCan.style.top =
+ this.gs.nameHeight + "px"),
+ (this.holdCan.style.left = "0px");
+ var widad = 0.8 * this.gs.holdQueueBlockSize;
+ let keior = 4 * this.gs.holdQueueBlockSize + widad;
+ if (
+ ((this.name.style.left = keior + "px"),
+ (this.pCan.style.left = this.bgCan.style.left = keior + "px"),
+ (this.queueCan.style.left = keior + this.pCan.width + widad + "px"),
+ this.gs.slotStats && this.gs.matrixWidth >= 50)
+ ) {
+ this.stats.init(), (this.stats.statsDiv.style.left = keior + "px"), this.slotDiv.appendChild(this.stats.statsDiv);
+ let leonilla = 1.1 * this.stats.statsDiv.childNodes[0].clientWidth,
+ thorson = 2 * leonilla < 0.85 * this.gs.matrixWidth || leonilla > 0.6 * this.gs.matrixWidth;
+ this.stats.winCounter.style.display = thorson ? null : "none";
+ } else {
+ this.stats.disable();
}
- let oldSlotInit = Slot.prototype.init
- Slot.prototype.init = function () {
- let life = this.gs.p.Live
- if (life?.roomConfig?.mode != 2) {
- return oldSlotInit.apply(this, arguments)
- }
- this.v.queueCanvas.style.display = "none"
- this.v.holdCanvas.style.display = "none"
- this.gs.holdQueueBlockSize = this.gs.matrixHeight / 20
- // console.log("hi2", this.gs.holdQueueBlockSize)
- this.v.QueueHoldEnabled = true
- this.v.cancelLiveMatrix = false
- this.slotDiv.className = "slot"
- this.slotDiv.style.left = this.x + "px"
- this.slotDiv.style.top = this.y + "px"
- this.stageDiv.style.position = "relative"
- this.name.style.width = this.gs.matrixWidth + 2 + "px"
- this.name.style.height = this.gs.nameHeight + "px"
- this.name.style.fontSize = this.gs.nameFontSize + "px"
- this.pCan.width = this.bgCan.width = this.gs.matrixWidth
- this.pCan.height = this.bgCan.height = this.gs.matrixHeight
- this.queueCan.width = this.holdCan.width = 4 * this.gs.holdQueueBlockSize
- this.holdCan.height = 4 * this.gs.holdQueueBlockSize
- this.queueCan.height = 15 * this.gs.holdQueueBlockSize
- this.pCan.style.top = this.bgCan.style.top = this.holdCan.style.top = this.queueCan.style.top = this.gs.nameHeight + "px", this.holdCan.style.left = "0px";
- var widad = .8 * this.gs.holdQueueBlockSize
- let keior = 4 * this.gs.holdQueueBlockSize + widad;
- if (this.name.style.left = keior + "px", this.pCan.style.left = this.bgCan.style.left = keior + "px", this.queueCan.style.left = keior + this.pCan.width + widad + "px", this.gs.slotStats && this.gs.matrixWidth >= 50) {
- this.stats.init(), this.stats.statsDiv.style.left = keior + "px", this.slotDiv.appendChild(this.stats.statsDiv);
- let leonilla = 1.1 * this.stats.statsDiv.childNodes[0].clientWidth, thorson = 2 * leonilla < .85 * this.gs.matrixWidth || leonilla > .6 * this.gs.matrixWidth;
- this.stats.winCounter.style.display = thorson ? null : "none";
- } else {
- this.stats.disable();
- }
- ;
- this.slotDiv.appendChild(this.name), this.slotDiv.appendChild(this.stageDiv), this.stageDiv.appendChild(this.bgCan), this.stageDiv.appendChild(this.pCan), this.stageDiv.appendChild(this.holdCan), this.stageDiv.appendChild(this.queueCan), this.slotDiv.style.display = "block", this.gs.gsDiv.appendChild(this.slotDiv), this.v.onResized();
+ this.slotDiv.appendChild(this.name),
+ this.slotDiv.appendChild(this.stageDiv),
+ this.stageDiv.appendChild(this.bgCan),
+ this.stageDiv.appendChild(this.pCan),
+ this.stageDiv.appendChild(this.holdCan),
+ this.stageDiv.appendChild(this.queueCan),
+ (this.slotDiv.style.display = "block"),
+ this.gs.gsDiv.appendChild(this.slotDiv),
+ this.v.onResized();
- this.stats.statsDiv.style.width = "250px"
- }
- GameSlots.prototype.tsetup = function (teamLengths) {
- var maxTeamLength = Math.max.apply(null, teamLengths),
- edweina = this.h / 2,
- slotIndex = 0;
- this.isExtended = false, this.nameFontSize = 15, this.nameHeight = 18;
- var shonte = edweina,
- coline = 1 === (curTeamLength = maxTeamLength) ? 0 : (2 === curTeamLength ? 30 : 60) / (curTeamLength - 1),
- cinnamin = this.tagHeight + 2;
+ this.stats.statsDiv.style.width = "250px";
+ };
+ GameSlots.prototype.tsetup = function (teamLengths) {
+ var maxTeamLength = Math.max.apply(null, teamLengths),
+ edweina = this.h / 2,
+ slotIndex = 0;
+ (this.isExtended = false), (this.nameFontSize = 15), (this.nameHeight = 18);
+ var shonte = edweina,
+ coline = 1 === (curTeamLength = maxTeamLength) ? 0 : (2 === curTeamLength ? 30 : 60) / (curTeamLength - 1),
+ cinnamin = this.tagHeight + 2;
- this.slotHeight = this.nmob(shonte - this.nameHeight - 15)
+ this.slotHeight = this.nmob(shonte - this.nameHeight - 15);
- this.redBarWidth = Math.ceil(this.slotHeight / 55) + 1
- this.slotWidth = this.slotHeight / 2 + this.redBarWidth;
+ this.redBarWidth = Math.ceil(this.slotHeight / 55) + 1;
+ this.slotWidth = this.slotHeight / 2 + this.redBarWidth;
- var janishia = this.slotWidth * curTeamLength + (curTeamLength - 1) * coline;
- janishia > this.w && (this.slotWidth = Math.floor(this.w / curTeamLength) - coline, this.slotHeight = this.nmob(2 * (this.slotWidth - this.redBarWidth)), this.redBarWidth = Math.ceil(this.slotHeight / 55) + 1, this.slotWidth = this.slotHeight / 2 + this.redBarWidth, janishia = this.slotWidth * curTeamLength + (curTeamLength - 1) * coline), this.liveBlockSize = this.slotHeight / 20;
+ var janishia = this.slotWidth * curTeamLength + (curTeamLength - 1) * coline;
+ janishia > this.w &&
+ ((this.slotWidth = Math.floor(this.w / curTeamLength) - coline),
+ (this.slotHeight = this.nmob(2 * (this.slotWidth - this.redBarWidth))),
+ (this.redBarWidth = Math.ceil(this.slotHeight / 55) + 1),
+ (this.slotWidth = this.slotHeight / 2 + this.redBarWidth),
+ (janishia = this.slotWidth * curTeamLength + (curTeamLength - 1) * coline)),
+ (this.liveBlockSize = this.slotHeight / 20);
- // OLD
- //var estarlin = this.slotHeight + this.nameHeight + 15 + cinnamin;
- // INJECTED
- var estarlin = this.slotHeight + this.nameHeight * (this.slotStats ? 3 : 1) + 15 + cinnamin;
+ // OLD
+ //var estarlin = this.slotHeight + this.nameHeight + 15 + cinnamin;
+ // INJECTED
+ var estarlin = this.slotHeight + this.nameHeight * (this.slotStats ? 3 : 1) + 15 + cinnamin;
- this.matrixHeight = this.slotHeight
- this.matrixWidth = this.slotWidth;
+ this.matrixHeight = this.slotHeight;
+ this.matrixWidth = this.slotWidth;
- // inject slot width here instead of in Slot.init because tsetup is called first.
- this.slotWidth = this.matrixWidth * 1.7413
+ // inject slot width here instead of in Slot.init because tsetup is called first.
+ this.slotWidth = this.matrixWidth * 1.7413;
- for (var teamIndex = 0; teamIndex < teamLengths.length; teamIndex++) {
- var curTeamLength = teamLengths[teamIndex];
+ for (var teamIndex = 0; teamIndex < teamLengths.length; teamIndex++) {
+ var curTeamLength = teamLengths[teamIndex];
- // begin injected code
- let queueHoldBoxPadding = .8 * this.holdQueueBlockSize
- let queueHoldBoxWidthPlusPadding = 4 * this.holdQueueBlockSize + queueHoldBoxPadding;
+ // begin injected code
+ let queueHoldBoxPadding = 0.8 * this.holdQueueBlockSize;
+ let queueHoldBoxWidthPlusPadding = 4 * this.holdQueueBlockSize + queueHoldBoxPadding;
- // OLD LINE:
- //janishia = this.slotWidth * letrina + (letrina - 1) * coline;
- // INJECTED LINE:
- janishia = this.slotWidth * curTeamLength + (curTeamLength - 1) * coline + queueHoldBoxWidthPlusPadding;
+ // OLD LINE:
+ //janishia = this.slotWidth * letrina + (letrina - 1) * coline;
+ // INJECTED LINE:
+ janishia = this.slotWidth * curTeamLength + (curTeamLength - 1) * coline + queueHoldBoxWidthPlusPadding;
- // OLD LINE:
- //var baseSlotXCoord = Math.floor((this.w - janishia) / 2);
- // INJECTED LINE (TO PREVENT OVERLAP WITH BOARD)
- var baseSlotXCoord = Math.max(0, Math.floor((this.w - janishia) / 2));
+ // OLD LINE:
+ //var baseSlotXCoord = Math.floor((this.w - janishia) / 2);
+ // INJECTED LINE (TO PREVENT OVERLAP WITH BOARD)
+ var baseSlotXCoord = Math.max(0, Math.floor((this.w - janishia) / 2));
- // end injected code
+ // end injected code
- curTeamLength > 0 && this.initTeamTag(teamIndex, baseSlotXCoord, estarlin * teamIndex, janishia);
- for (var teamSlot = 0; teamSlot < curTeamLength; teamSlot++) {
- var slotX = baseSlotXCoord + teamSlot * (this.slotWidth + coline),
- slotY = estarlin * teamIndex + cinnamin;
- slotIndex >= this.slots.length ? this.slots[slotIndex] = new Slot(slotIndex, slotX, slotY, this) : (this.slots[slotIndex].x = slotX, this.slots[slotIndex].y = slotY, this.slots[slotIndex].init()), slotIndex++;
- }
- };
- for (this.shownSlots = slotIndex; slotIndex < this.slots.length;) {
- this.slots[slotIndex].hide(), slotIndex++;
- };
- this.realHeight = estarlin * teamLengths.length - 15, this.resizeElements();
+ curTeamLength > 0 && this.initTeamTag(teamIndex, baseSlotXCoord, estarlin * teamIndex, janishia);
+ for (var teamSlot = 0; teamSlot < curTeamLength; teamSlot++) {
+ var slotX = baseSlotXCoord + teamSlot * (this.slotWidth + coline),
+ slotY = estarlin * teamIndex + cinnamin;
+ slotIndex >= this.slots.length
+ ? (this.slots[slotIndex] = new Slot(slotIndex, slotX, slotY, this))
+ : ((this.slots[slotIndex].x = slotX), (this.slots[slotIndex].y = slotY), this.slots[slotIndex].init()),
+ slotIndex++;
+ }
+ }
+ for (this.shownSlots = slotIndex; slotIndex < this.slots.length; ) {
+ this.slots[slotIndex].hide(), slotIndex++;
}
-}
\ No newline at end of file
+ (this.realHeight = estarlin * teamLengths.length - 15), this.resizeElements();
+ };
+};
diff --git a/src/toggleChatKeyInput.js b/src/toggleChatKeyInput.js
index f74624a..824d45e 100644
--- a/src/toggleChatKeyInput.js
+++ b/src/toggleChatKeyInput.js
@@ -3,28 +3,28 @@ import { Config } from "./config";
export const createKeyInputElement = (varName, desc) => {
const TOGGLE_CHAT_KEY_INPUT_ELEMENT = document.createElement("div");
TOGGLE_CHAT_KEY_INPUT_ELEMENT.className = "settings-inputRow";
- TOGGLE_CHAT_KEY_INPUT_ELEMENT.innerHTML += `${desc}`
+ TOGGLE_CHAT_KEY_INPUT_ELEMENT.innerHTML += `${desc}`;
const inputDiv = document.createElement("div");
const input = document.createElement("input");
- input.value = displayKeyCode(Config().TOGGLE_CHAT_KEYCODE);
+ input.value = displayKey(Config().varName);
input.id = `${varName}_INPUT_ELEMENT`;
- input.addEventListener("keydown", e => {
- var charCode = (e.which) ? e.which : e.keyCode
- Config().set(varName, charCode);
- input.value = displayKeyCode(charCode);
+ input.addEventListener("keydown", (e) => {
+ let key = e.code;
+ Config().set(varName, key);
+ input.value = displayKey(key);
e.stopPropagation();
e.preventDefault();
- return false;
+ return;
});
input.addEventListener("keypress", () => false);
const clearBtn = document.createElement("button");
- clearBtn.addEventListener("click", e => {
+ clearBtn.addEventListener("click", (e) => {
Config().set(varName, null);
- input.value = displayKeyCode(null);
- })
- clearBtn.innerHTML = "Clear";
+ input.value = displayKey(null);
+ });
+ clearBtn.textContent = "Clear";
input.style.marginRight = "5px";
inputDiv.style.display = "flex";
@@ -33,80 +33,82 @@ export const createKeyInputElement = (varName, desc) => {
TOGGLE_CHAT_KEY_INPUT_ELEMENT.appendChild(inputDiv);
return TOGGLE_CHAT_KEY_INPUT_ELEMENT;
+};
-}
-
-
-// stolen from https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
-export function displayKeyCode(charCode) {
-
- if (charCode == null) {
+export function displayKey(key) {
+ if (key == null) {
return "