From bfee51eff4787938e0b5bf1ea54d04c76bde5d50 Mon Sep 17 00:00:00 2001 From: "PolicyChanges1@gmail.com" Date: Sat, 13 Mar 2021 10:08:46 -0500 Subject: [PATCH] buggy but better --- deploy.sh.bat | 1 + dist/tetrion.js | 28 +++++++++++++++------------- src/main.js | 13 ++++++------- src/openers.js | 15 +++++++++------ startserver.sh.bat | 1 + 5 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 deploy.sh.bat create mode 100644 startserver.sh.bat diff --git a/deploy.sh.bat b/deploy.sh.bat new file mode 100644 index 0000000..37866ff --- /dev/null +++ b/deploy.sh.bat @@ -0,0 +1 @@ +browserify ./src/main.js -o ./dist/tetrion.js \ No newline at end of file diff --git a/dist/tetrion.js b/dist/tetrion.js index 0daef75..e82ab90 100644 --- a/dist/tetrion.js +++ b/dist/tetrion.js @@ -993,7 +993,8 @@ Tetris.prototype = { this.levelTime = this.startTime; this.prevInputTime = this.startTime; // current tetrino index gets set to 0 at the end of opener sequence - this.currentMinoInx = 0; + //if(this.currentMinoInx == undefined || this.currentMinoInx < 1000) // todo: refactor -- seppuku worthy + this.currentMinoInx = 0; this.shapeQueue = []; this.hintQueue = []; this.holdStack = []; @@ -1041,7 +1042,7 @@ Tetris.prototype = { if(this.holdStack.length > 0) { this.canPopFromHoldStack = false; this.shapeQueue.unshift(utils.deepClone(this.shape)); - this.shape = this.holdStack.pop(); + this.shape = utils.deepClone(this.holdStack.pop()); this.shape.resetOrigin(); this._draw(); }else if(this.holdStack.length < 4) { @@ -1070,7 +1071,7 @@ Tetris.prototype = { if(this.shape.canDown(this.matrix)) return; this.shape.copyTo(this.matrix); this.shapeQueue.unshift(utils.deepClone(this.shape)); - this.shape = this.holdStack.pop(); + this.shape = utils.deepClone(this.holdStack.pop()); this._check(); this._draw(); return; @@ -1114,12 +1115,12 @@ Tetris.prototype = { _processOpenerTrainerQueue: function() { while(this.shapeQueue.length <= 4) { - this.preparedShape = openers.getNextMino(this.currentOpener); + this.preparedShape = utils.deepClone(openers.getNextMino(this.currentOpener)); this.shapeQueue.push(this.preparedShape); } while(this.hintQueue.length <= 4) { - this.preparedShape = openers.getNextHint(this.currentOpener); + this.preparedShape = utils.deepClone(openers.getNextHint(this.currentOpener)); this.hintQueue.push(this.preparedShape); } @@ -1137,8 +1138,6 @@ Tetris.prototype = { if(besttime == "" || deltaTime/1000.0 < parseFloat(besttime)) { document.getElementById("besttime").value = (deltaTime/1000.0).toString(); } - - } this.hintQueue = []; @@ -1539,7 +1538,8 @@ var openerGenerator = { hintIdx: 0, isInit: 0, isHintInit: 0, - + customShapeQueue: [], + customHintQueue: [], // O - 1, I - 6, L - 0, S - 5, J - 4, Z - 2, T - 3 // Current Tetriminos init(opener) { @@ -1710,10 +1710,11 @@ var openerGenerator = { }, getNextMino(opener) { + if(this.customShapeQueue.length > 0) return this.customShapeQueue[this.idx++%this.customShapeQueue.length]; this.init(opener); var mino = this.shapeQueue[this.idx]; this.idx++; - if(this.idx == this.shapeQueue.length) { + if(this.idx >= this.shapeQueue.length) { this.idx = 0; if(opener < 1000) this.isInit = 0; @@ -1986,10 +1987,11 @@ var openerGenerator = { // End initHint getNextHint(opener) { + if(this.customHintQueue.length > 0) return this.customHintQueue[this.hintIdx++%this.customHintQueue.length]; this.initHint(opener); var mino = this.hintQueue[this.hintIdx]; this.hintIdx++; - if(this.hintIdx == this.hintQueue.length) { + if(this.hintIdx >= this.hintQueue.length) { this.hintIdx = 0; if(opener < 1000) this.isHintInit = 0; @@ -2007,7 +2009,7 @@ var openerGenerator = { this.isHintInit = 0; }, getLength() { - return this.hintQueue.length; + return this.customHintQueue.length || this.hintQueue.length; }, addSequence(sequence) { //this.reset(); @@ -2020,10 +2022,10 @@ var openerGenerator = { shape.x = sequence[i].x; shape.y = sequence[i].y; shape.state = sequence[i].state; - this.hintQueue.unshift(utils.deepClone(shape)); + this.customHintQueue.unshift(utils.deepClone(shape)); shape.x = shape.originX; shape.y = shape.originY; - this.shapeQueue.unshift(utils.deepClone(shape)); + this.customShapeQueue.unshift(utils.deepClone(shape)); this.isInit = 1; this.isHintInit = 1; this.idx = 0; diff --git a/src/main.js b/src/main.js index 79a0856..da5d759 100644 --- a/src/main.js +++ b/src/main.js @@ -309,7 +309,8 @@ Tetris.prototype = { this.levelTime = this.startTime; this.prevInputTime = this.startTime; // current tetrino index gets set to 0 at the end of opener sequence - this.currentMinoInx = 0; + //if(this.currentMinoInx == undefined || this.currentMinoInx < 1000) // todo: refactor -- seppuku worthy + this.currentMinoInx = 0; this.shapeQueue = []; this.hintQueue = []; this.holdStack = []; @@ -357,7 +358,7 @@ Tetris.prototype = { if(this.holdStack.length > 0) { this.canPopFromHoldStack = false; this.shapeQueue.unshift(utils.deepClone(this.shape)); - this.shape = this.holdStack.pop(); + this.shape = utils.deepClone(this.holdStack.pop()); this.shape.resetOrigin(); this._draw(); }else if(this.holdStack.length < 4) { @@ -386,7 +387,7 @@ Tetris.prototype = { if(this.shape.canDown(this.matrix)) return; this.shape.copyTo(this.matrix); this.shapeQueue.unshift(utils.deepClone(this.shape)); - this.shape = this.holdStack.pop(); + this.shape = utils.deepClone(this.holdStack.pop()); this._check(); this._draw(); return; @@ -430,12 +431,12 @@ Tetris.prototype = { _processOpenerTrainerQueue: function() { while(this.shapeQueue.length <= 4) { - this.preparedShape = openers.getNextMino(this.currentOpener); + this.preparedShape = utils.deepClone(openers.getNextMino(this.currentOpener)); this.shapeQueue.push(this.preparedShape); } while(this.hintQueue.length <= 4) { - this.preparedShape = openers.getNextHint(this.currentOpener); + this.preparedShape = utils.deepClone(openers.getNextHint(this.currentOpener)); this.hintQueue.push(this.preparedShape); } @@ -453,8 +454,6 @@ Tetris.prototype = { if(besttime == "" || deltaTime/1000.0 < parseFloat(besttime)) { document.getElementById("besttime").value = (deltaTime/1000.0).toString(); } - - } this.hintQueue = []; diff --git a/src/openers.js b/src/openers.js index d619435..b567498 100644 --- a/src/openers.js +++ b/src/openers.js @@ -11,7 +11,8 @@ var openerGenerator = { hintIdx: 0, isInit: 0, isHintInit: 0, - + customShapeQueue: [], + customHintQueue: [], // O - 1, I - 6, L - 0, S - 5, J - 4, Z - 2, T - 3 // Current Tetriminos init(opener) { @@ -182,10 +183,11 @@ var openerGenerator = { }, getNextMino(opener) { + if(this.customShapeQueue.length > 0) return this.customShapeQueue[this.idx++%this.customShapeQueue.length]; this.init(opener); var mino = this.shapeQueue[this.idx]; this.idx++; - if(this.idx == this.shapeQueue.length) { + if(this.idx >= this.shapeQueue.length) { this.idx = 0; if(opener < 1000) this.isInit = 0; @@ -458,10 +460,11 @@ var openerGenerator = { // End initHint getNextHint(opener) { + if(this.customHintQueue.length > 0) return this.customHintQueue[this.hintIdx++%this.customHintQueue.length]; this.initHint(opener); var mino = this.hintQueue[this.hintIdx]; this.hintIdx++; - if(this.hintIdx == this.hintQueue.length) { + if(this.hintIdx >= this.hintQueue.length) { this.hintIdx = 0; if(opener < 1000) this.isHintInit = 0; @@ -479,7 +482,7 @@ var openerGenerator = { this.isHintInit = 0; }, getLength() { - return this.hintQueue.length; + return this.customHintQueue.length || this.hintQueue.length; }, addSequence(sequence) { //this.reset(); @@ -492,10 +495,10 @@ var openerGenerator = { shape.x = sequence[i].x; shape.y = sequence[i].y; shape.state = sequence[i].state; - this.hintQueue.unshift(utils.deepClone(shape)); + this.customHintQueue.unshift(utils.deepClone(shape)); shape.x = shape.originX; shape.y = shape.originY; - this.shapeQueue.unshift(utils.deepClone(shape)); + this.customShapeQueue.unshift(utils.deepClone(shape)); this.isInit = 1; this.isHintInit = 1; this.idx = 0; diff --git a/startserver.sh.bat b/startserver.sh.bat new file mode 100644 index 0000000..846e510 --- /dev/null +++ b/startserver.sh.bat @@ -0,0 +1 @@ +python3 -m http.server