This commit is contained in:
PolicyChanges1@gmail.com 2021-02-25 18:05:22 -05:00
parent e02895e128
commit 6d59dd867c
6 changed files with 312 additions and 63 deletions

View File

@ -2,6 +2,52 @@ html,body{
height:100%; height:100%;
} }
/* Dropdown Button */
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
background-color: #2980B9;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}
body{ body{
background: #000000; background: #000000;
margin:0; margin:0;

156
dist/tetrion.js vendored
View File

@ -423,10 +423,31 @@ module.exports = gamepadAPI;
// export gamepadAPI; // export gamepadAPI;
},{}],4:[function(require,module,exports){ },{}],4:[function(require,module,exports){
var gamepad = require('./gamepad.js'); var gamepad = require('./gamepad.js');
var utils = require('./utils.js');
// import * as gamepad from './gamepad.js'; // import * as gamepad from './gamepad.js';
var UserInputs = { var UserInputs = {
init() { init() {
this.settingsMap = new Map();
var options = "";
// var init = utils.getCookie("init");
// if(init == "")
for(var i in this.settingsList)
utils.setCookie(this.settingsList[i], this.settingsDefault[i], 30); // cookies expire in 30 days
// else
// for(var i in this.settingsList)
// this.settingsDefault[i] = utils.getCookie(this.settingsList[i]);
for(var i in this.settingsList)
this.settingsMap.set(this.settingsList[i], this.settingsDefault[i]);
//document.getElementById("setting").innerHTML = settings;
document.addEventListener('keydown', this.keyDown.bind(this)); document.addEventListener('keydown', this.keyDown.bind(this));
document.addEventListener('keyup', this.keyUp.bind(this)); document.addEventListener('keyup', this.keyUp.bind(this));
}, },
@ -449,15 +470,21 @@ var UserInputs = {
}, },
processGamepadInput() { processGamepadInput() {
this.gamepadButtonsDown("RB"); // this.gamepadButtonsDown("RB"); // hard drop
this.gamepadButtonsDown("LB"); // this.gamepadButtonsDown("LB"); // hold
this.gamepadButtonsDown("A"); // this.gamepadButtonsDown("A"); // rotate counter
this.gamepadButtonsDown("B"); // this.gamepadButtonsDown("B"); // rotate cwise
this.gamepadButtonsDown("DPad-Up"); // this.gamepadButtonsDown("DPad-Up"); // Pop hold stack
this.gamepadButtonsDown("Back"); // this.gamepadButtonsDown("Back"); // reset
//this.gamepadButtonsDown("X"); //this.gamepadButtonsDown("X");
//this.gamepadButtonsDown("Y"); //this.gamepadButtonsDown("Y");
this.gamepadButtonsDown(this.settingsMap.get("gamepad_harddrop")); // hard drop
this.gamepadButtonsDown(this.settingsMap.get("gamepad_hold")); // hold
this.gamepadButtonsDown(this.settingsMap.get("gamepad_rotateccw")); // rotate counter
this.gamepadButtonsDown(this.settingsMap.get("gamepad_rotate")); // rotate cwise
this.gamepadButtonsDown(this.settingsMap.get("gamepad_pophold")); // Pop hold stack
this.gamepadButtonsDown(this.settingsMap.get("gamepad_reset")); // reset
return; return;
@ -465,9 +492,9 @@ var UserInputs = {
processGamepadDPad() processGamepadDPad()
{ {
this.gamepadDPadDown("DPad-Left"); this.gamepadDPadDown(this.settingsMap.get("gamepad_left")); // shift left
this.gamepadDPadDown("DPad-Right"); this.gamepadDPadDown(this.settingsMap.get("gamepad_right")); // shift right
this.gamepadDPadDown("DPad-Down"); this.gamepadDPadDown(this.settingsMap.get("gamepad_down")); // down
return; return;
}, },
@ -506,8 +533,8 @@ var UserInputs = {
// Direction Pad // Direction Pad
gamepadDPadDown(finds) { gamepadDPadDown(finds) {
var DAS = 65.0; var DAS = parseInt(this.settingsMap.get("gamepad_das")); //65.0;
var ARR = 20.0; var ARR = parseInt(this.settingsMap.get("gamepad_arr")); //20.0;
var isContained = this.gpButtons.includes(finds); var isContained = this.gpButtons.includes(finds);
var isPrevContained = this.prevGpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds);
@ -537,14 +564,14 @@ var UserInputs = {
return; return;
}, },
processKeys() { processKeys() {
this.processKeyDown(32); // Space this.processKeyDown(parseInt(this.settingsMap.get("keyboard_harddrop"))); //32); // Space - hard drop
this.processKeyDown(88); // X this.processKeyDown(parseInt(this.settingsMap.get("keyboard_rotate"))); //88); // X - rotate
this.processKeyDown(90); // Z this.processKeyDown(parseInt(this.settingsMap.get("keyboard_rotateccw"))); //90); // Z - rotateccw
this.processKeyDown(16); // shift this.processKeyDown(parseInt(this.settingsMap.get("keyboard_hold"))); //16); // shift - push hold stack
this.processKeyDown(17); // ctrl this.processKeyDown(parseInt(this.settingsMap.get("keyboard_pophold"))); // ctrl - pop hold stack
this.processKeyDown(81); // q this.processKeyDown(parseInt(this.settingsMap.get("keyboard_background"))); // q - turn off background
this.processKeyDown(82); // r this.processKeyDown(parseInt(this.settingsMap.get("keyboard_reset"))); // r - reset
this.processKeyDown(67); // c //this.processKeyDown(this.settingsMap.get("keyboard_hold"))); // c - pop hold stack
}, },
// keyboard keys z,x,space // keyboard keys z,x,space
@ -581,14 +608,14 @@ var UserInputs = {
}, },
processKeyShift() { processKeyShift() {
this.processKeyboardArrowKeys(39); // right this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_left"))); //39); // right
this.processKeyboardArrowKeys(37); // left this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_right"))); //37); // left
this.processKeyboardArrowKeys(40); // down this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_down"))); // down
}, },
// Direction arrows // Direction arrows
processKeyboardArrowKeys(key) { processKeyboardArrowKeys(key) {
var DAS = 65.0; var DAS = parseInt(this.settingsMap.get("keyboard_das")); //65.0;
var ARR = 20.0; var ARR = parseInt(this.settingsMap.get("keyboard_arr")); //20.0;
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) { if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
@ -616,8 +643,8 @@ var UserInputs = {
}, },
keyDown(event) { keyDown(event) {
// Disable space scrolling etc if (! ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8))
event.preventDefault(); event.preventDefault();
this.keyboardKeys[event.keyCode] = true; this.keyboardKeys[event.keyCode] = true;
this.isKeyBoardKeyDown = true; this.isKeyBoardKeyDown = true;
@ -661,12 +688,33 @@ var UserInputs = {
inputqueue: [], inputqueue: [],
gamepadQueue: [], gamepadQueue: [],
ticks: 0 ticks: 0,
// todo: change to human readable
settingsList: ["init",
"keyboard_das", "keyboard_arr", "keyboard_harddrop", "keyboard_hold",
"keyboard_left", "keyboard_right", "keyboard_rotateccw", "keyboard_rotate",
"keyboard_down", "keyboard_pophold", "keyboard_reset", "keyboard_background",
"gamepad_das", "gamepad_arr", "gamepad_harddrop", "gamepad_hold",
"gamepad_left", "gamepad_right", "gamepad_rotateccw", "gamepad_rotate",
"gamepad_down","gamepad_pophold", "gamepad_reset", "gamepad_background",
"path", "SameSite"],
settingsDefault: ["true",
"65.0", "20.0", "32", "16",
"37", "39", "90", "88",
"40", "17", "82", "81",
"65.0", "10.0", "RB", "LB",
"DPad-Left", "DPad-Right", "A", "B",
"DPad-Down", "DPad-Up", "Back", "",
"=/", "Strict"],
settingsMap: []
}; };
module.exports = UserInputs; module.exports = UserInputs;
// export UserInputs; // export UserInputs;
},{"./gamepad.js":3}],5:[function(require,module,exports){ },{"./gamepad.js":3,"./utils.js":8}],5:[function(require,module,exports){
var utils = require('./utils.js'); var utils = require('./utils.js');
var consts = require('./consts.js'); var consts = require('./consts.js');
var shapes = require('./shapes.js'); var shapes = require('./shapes.js');
@ -825,7 +873,7 @@ Tetris.prototype = {
views.init(this.id, cfg.maxWidth, cfg.maxHeight); views.init(this.id, cfg.maxWidth, cfg.maxHeight);
canvas.init(views.scene, views.preview, views.hold); canvas.init(views.scene, views.preview, views.hold);
inputs.init(); inputs.init();
this.createSettings();
// if true no openers. just random tetrinos // if true no openers. just random tetrinos
this.isFreePlay = true; this.isFreePlay = true;
this.currentOpener = 0; this.currentOpener = 0;
@ -859,6 +907,30 @@ Tetris.prototype = {
this.currentOpener = 2; this.currentOpener = 2;
this._restartHandler(); this._restartHandler();
},
createSettings: function () {
var list = document.getElementById("settings");
var settings = inputs.settingsList;
settings.forEach(function(item) {
var option = document.createElement('option');
option.text = item;
option.id = item;
list.add(option);
});
},
updateSettingTextBox: function() {
console.log(document.getElementById("setting_value").value = inputs.settingsDefault[document.getElementById("settings").selectedIndex-1]);
},
setSettings: function() {
//inputs.settingsDefault[document.getElementById("settings").selectedIndex-1] = document.getElementById("setting_value").value;
var newVal = document.getElementById("setting_value").value;
utils.setCookie(inputs.settingsList[document.getElementById("settings").selectedIndex-1], newVal, 30);
inputs.settingsMap.set(inputs.settingsList[document.getElementById("settings").selectedIndex-1], newVal);
//console.log("settings " + inputs.settingsList[document.getElementById("settings").selectedIndex-1] + " " + newVal);
}, },
//Reset game //Reset game
reset: function() { reset: function() {
@ -2488,6 +2560,28 @@ module.exports.getShape = getShape;
var exports = module.exports = {}; var exports = module.exports = {};
var setCookie = function(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
};
var getCookie = function(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
};
var $ = function(id){ var $ = function(id){
return document.getElementById(id); return document.getElementById(id);
}; };
@ -2602,6 +2696,8 @@ exports.$ = $;
exports.extend = extend; exports.extend = extend;
exports.proxy = proxy; exports.proxy = proxy;
exports.deepClone = deepClone; exports.deepClone = deepClone;
exports.setCookie = setCookie;
exports.getCookie = getCookie;
// export $; // export $;
// export extend; // export extend;
// export proxy; // export proxy;

View File

@ -36,7 +36,7 @@
<!--insert shadertoy background--> <!--insert shadertoy background-->
<!--https://www.shadertoy.com/embed/wttfW2?gui=&t=10&paused=false&muted=false--> <!--https://www.shadertoy.com/embed/wttfW2?gui=&t=10&paused=false&muted=false-->
<!--
<div id="divbg"> <div id="divbg">
<iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/WldfWX?gui=&paused=false&muted=false" ></iframe> <iframe id="bg" width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/WldfWX?gui=&paused=false&muted=false" ></iframe>
<script> <script>
@ -48,7 +48,7 @@ document.getElementById("bg").removeAttribute("tabIndex");
document.getElementById("divbg").removeAttribute("tabIndex"); document.getElementById("divbg").removeAttribute("tabIndex");
</script> </script>
</div> </div>
-->
<div id="tetris"> <div id="tetris">
<canvas id="scene"></canvas> <canvas id="scene"></canvas>
@ -99,7 +99,7 @@ document.getElementById("divbg").removeAttribute("tabIndex");
</ul> </ul>
--> -->
<ul style="font-size:16px;color:dodgerblue;text-align:left;" > <ul style="font-size:16px;color:dodgerblue;text-align:left;" >
<ul style="font-size:13px;color:powderblue;text-align:left;padding-left:1em;" id="setPCOpenersVar">Perfect Clear Openers: <ul style="font-size:13px;color:dodgerblue;text-align:left;padding-left:1em;" id="setPCOpenersVar">Perfect Clear Openers:
<li style="font-size:12px;padding-left:1em;"><a href="#" id="setStdPCOpenerVar">The Standard PC Opener </a></li> <li style="font-size:12px;padding-left:1em;"><a href="#" id="setStdPCOpenerVar">The Standard PC Opener </a></li>
<li style="font-size:12px;padding-left:1em;"><a href="#" id="setSecondPCVar">Second Perfect Clear </a></li> <li style="font-size:12px;padding-left:1em;"><a href="#" id="setSecondPCVar">Second Perfect Clear </a></li>
<li style="font-size:12px;padding-left:1em;"><a href="#" id="setLoJVar">Either L or J </a></li> <li style="font-size:12px;padding-left:1em;"><a href="#" id="setLoJVar">Either L or J </a></li>
@ -128,6 +128,16 @@ document.getElementById("divbg").removeAttribute("tabIndex");
<h1 id="linesInfo">Lines: <br><span id="lines" >0</span></h1> <h1 id="linesInfo">Lines: <br><span id="lines" >0</span></h1>
<div id="rewardInfo" class="invisible">+<span id="reward">0</span></div> <div id="rewardInfo" class="invisible">+<span id="reward">0</span></div>
<canvas id="preview"></canvas> <canvas id="preview"></canvas>
<br>
<select style="width:80px;font-size:13px;background:black;color:dodgerblue;text-align:left;" id="settings" name="setting">
<option selected="">Settings:</option>
</select>
<input style="width:80px;font-size:13px;background:black;color:dodgerblue;text-align:left;" type="text" id="setting_value">
<input id="submitsetting" type="submit">
</div> </div>
</div> </div>
</div> </div>
@ -141,7 +151,8 @@ document.getElementById("divbg").removeAttribute("tabIndex");
document.getElementById("setFreePlay").addEventListener("click", function() { tetrion.setFreePlay(); } ); document.getElementById("setFreePlay").addEventListener("click", function() { tetrion.setFreePlay(); } );
document.getElementById("setTKIFonzieVar").addEventListener("click", function() { tetrion.setTKIFonzieVar(); } ); document.getElementById("setTKIFonzieVar").addEventListener("click", function() { tetrion.setTKIFonzieVar(); } );
document.getElementById("setDTCannonVar").addEventListener("click", function() { tetrion.setDTCannonVar(); } ); document.getElementById("setDTCannonVar").addEventListener("click", function() { tetrion.setDTCannonVar(); } );
document.getElementById("settings").addEventListener("change", function() { tetrion.updateSettingTextBox(); } );
document.getElementById("submitsetting").addEventListener("click", function() { tetrion.setSettings(); } );
tetrion.start(); tetrion.start();
})(); })();
</script> </script>

View File

@ -1,8 +1,29 @@
var gamepad = require('./gamepad.js'); var gamepad = require('./gamepad.js');
var utils = require('./utils.js');
// import * as gamepad from './gamepad.js'; // import * as gamepad from './gamepad.js';
var UserInputs = { var UserInputs = {
init() { init() {
this.settingsMap = new Map();
var options = "";
// var init = utils.getCookie("init");
// if(init == "")
for(var i in this.settingsList)
utils.setCookie(this.settingsList[i], this.settingsDefault[i], 30); // cookies expire in 30 days
// else
// for(var i in this.settingsList)
// this.settingsDefault[i] = utils.getCookie(this.settingsList[i]);
for(var i in this.settingsList)
this.settingsMap.set(this.settingsList[i], this.settingsDefault[i]);
//document.getElementById("setting").innerHTML = settings;
document.addEventListener('keydown', this.keyDown.bind(this)); document.addEventListener('keydown', this.keyDown.bind(this));
document.addEventListener('keyup', this.keyUp.bind(this)); document.addEventListener('keyup', this.keyUp.bind(this));
}, },
@ -25,15 +46,21 @@ var UserInputs = {
}, },
processGamepadInput() { processGamepadInput() {
this.gamepadButtonsDown("RB"); // this.gamepadButtonsDown("RB"); // hard drop
this.gamepadButtonsDown("LB"); // this.gamepadButtonsDown("LB"); // hold
this.gamepadButtonsDown("A"); // this.gamepadButtonsDown("A"); // rotate counter
this.gamepadButtonsDown("B"); // this.gamepadButtonsDown("B"); // rotate cwise
this.gamepadButtonsDown("DPad-Up"); // this.gamepadButtonsDown("DPad-Up"); // Pop hold stack
this.gamepadButtonsDown("Back"); // this.gamepadButtonsDown("Back"); // reset
//this.gamepadButtonsDown("X"); //this.gamepadButtonsDown("X");
//this.gamepadButtonsDown("Y"); //this.gamepadButtonsDown("Y");
this.gamepadButtonsDown(this.settingsMap.get("gamepad_harddrop")); // hard drop
this.gamepadButtonsDown(this.settingsMap.get("gamepad_hold")); // hold
this.gamepadButtonsDown(this.settingsMap.get("gamepad_rotateccw")); // rotate counter
this.gamepadButtonsDown(this.settingsMap.get("gamepad_rotate")); // rotate cwise
this.gamepadButtonsDown(this.settingsMap.get("gamepad_pophold")); // Pop hold stack
this.gamepadButtonsDown(this.settingsMap.get("gamepad_reset")); // reset
return; return;
@ -41,9 +68,9 @@ var UserInputs = {
processGamepadDPad() processGamepadDPad()
{ {
this.gamepadDPadDown("DPad-Left"); this.gamepadDPadDown(this.settingsMap.get("gamepad_left")); // shift left
this.gamepadDPadDown("DPad-Right"); this.gamepadDPadDown(this.settingsMap.get("gamepad_right")); // shift right
this.gamepadDPadDown("DPad-Down"); this.gamepadDPadDown(this.settingsMap.get("gamepad_down")); // down
return; return;
}, },
@ -82,8 +109,8 @@ var UserInputs = {
// Direction Pad // Direction Pad
gamepadDPadDown(finds) { gamepadDPadDown(finds) {
var DAS = 65.0; var DAS = parseInt(this.settingsMap.get("gamepad_das")); //65.0;
var ARR = 20.0; var ARR = parseInt(this.settingsMap.get("gamepad_arr")); //20.0;
var isContained = this.gpButtons.includes(finds); var isContained = this.gpButtons.includes(finds);
var isPrevContained = this.prevGpButtons.includes(finds); var isPrevContained = this.prevGpButtons.includes(finds);
@ -113,14 +140,14 @@ var UserInputs = {
return; return;
}, },
processKeys() { processKeys() {
this.processKeyDown(32); // Space this.processKeyDown(parseInt(this.settingsMap.get("keyboard_harddrop"))); //32); // Space - hard drop
this.processKeyDown(88); // X this.processKeyDown(parseInt(this.settingsMap.get("keyboard_rotate"))); //88); // X - rotate
this.processKeyDown(90); // Z this.processKeyDown(parseInt(this.settingsMap.get("keyboard_rotateccw"))); //90); // Z - rotateccw
this.processKeyDown(16); // shift this.processKeyDown(parseInt(this.settingsMap.get("keyboard_hold"))); //16); // shift - push hold stack
this.processKeyDown(17); // ctrl this.processKeyDown(parseInt(this.settingsMap.get("keyboard_pophold"))); // ctrl - pop hold stack
this.processKeyDown(81); // q this.processKeyDown(parseInt(this.settingsMap.get("keyboard_background"))); // q - turn off background
this.processKeyDown(82); // r this.processKeyDown(parseInt(this.settingsMap.get("keyboard_reset"))); // r - reset
this.processKeyDown(67); // c //this.processKeyDown(this.settingsMap.get("keyboard_hold"))); // c - pop hold stack
}, },
// keyboard keys z,x,space // keyboard keys z,x,space
@ -157,14 +184,14 @@ var UserInputs = {
}, },
processKeyShift() { processKeyShift() {
this.processKeyboardArrowKeys(39); // right this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_left"))); //39); // right
this.processKeyboardArrowKeys(37); // left this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_right"))); //37); // left
this.processKeyboardArrowKeys(40); // down this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_down"))); // down
}, },
// Direction arrows // Direction arrows
processKeyboardArrowKeys(key) { processKeyboardArrowKeys(key) {
var DAS = 65.0; var DAS = parseInt(this.settingsMap.get("keyboard_das")); //65.0;
var ARR = 20.0; var ARR = parseInt(this.settingsMap.get("keyboard_arr")); //20.0;
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) { if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
@ -192,8 +219,8 @@ var UserInputs = {
}, },
keyDown(event) { keyDown(event) {
// Disable space scrolling etc if (! ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8))
event.preventDefault(); event.preventDefault();
this.keyboardKeys[event.keyCode] = true; this.keyboardKeys[event.keyCode] = true;
this.isKeyBoardKeyDown = true; this.isKeyBoardKeyDown = true;
@ -237,7 +264,28 @@ var UserInputs = {
inputqueue: [], inputqueue: [],
gamepadQueue: [], gamepadQueue: [],
ticks: 0 ticks: 0,
// todo: change to human readable
settingsList: ["init",
"keyboard_das", "keyboard_arr", "keyboard_harddrop", "keyboard_hold",
"keyboard_left", "keyboard_right", "keyboard_rotateccw", "keyboard_rotate",
"keyboard_down", "keyboard_pophold", "keyboard_reset", "keyboard_background",
"gamepad_das", "gamepad_arr", "gamepad_harddrop", "gamepad_hold",
"gamepad_left", "gamepad_right", "gamepad_rotateccw", "gamepad_rotate",
"gamepad_down","gamepad_pophold", "gamepad_reset", "gamepad_background",
"path", "SameSite"],
settingsDefault: ["true",
"65.0", "20.0", "32", "16",
"37", "39", "90", "88",
"40", "17", "82", "81",
"65.0", "10.0", "RB", "LB",
"DPad-Left", "DPad-Right", "A", "B",
"DPad-Down", "DPad-Up", "Back", "",
"=/", "Strict"],
settingsMap: []
}; };
module.exports = UserInputs; module.exports = UserInputs;

View File

@ -156,7 +156,7 @@ Tetris.prototype = {
views.init(this.id, cfg.maxWidth, cfg.maxHeight); views.init(this.id, cfg.maxWidth, cfg.maxHeight);
canvas.init(views.scene, views.preview, views.hold); canvas.init(views.scene, views.preview, views.hold);
inputs.init(); inputs.init();
this.createSettings();
// if true no openers. just random tetrinos // if true no openers. just random tetrinos
this.isFreePlay = true; this.isFreePlay = true;
this.currentOpener = 0; this.currentOpener = 0;
@ -190,6 +190,30 @@ Tetris.prototype = {
this.currentOpener = 2; this.currentOpener = 2;
this._restartHandler(); this._restartHandler();
},
createSettings: function () {
var list = document.getElementById("settings");
var settings = inputs.settingsList;
settings.forEach(function(item) {
var option = document.createElement('option');
option.text = item;
option.id = item;
list.add(option);
});
},
updateSettingTextBox: function() {
console.log(document.getElementById("setting_value").value = inputs.settingsDefault[document.getElementById("settings").selectedIndex-1]);
},
setSettings: function() {
//inputs.settingsDefault[document.getElementById("settings").selectedIndex-1] = document.getElementById("setting_value").value;
var newVal = document.getElementById("setting_value").value;
utils.setCookie(inputs.settingsList[document.getElementById("settings").selectedIndex-1], newVal, 30);
inputs.settingsMap.set(inputs.settingsList[document.getElementById("settings").selectedIndex-1], newVal);
//console.log("settings " + inputs.settingsList[document.getElementById("settings").selectedIndex-1] + " " + newVal);
}, },
//Reset game //Reset game
reset: function() { reset: function() {

View File

@ -1,6 +1,28 @@
var exports = module.exports = {}; var exports = module.exports = {};
var setCookie = function(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
};
var getCookie = function(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
};
var $ = function(id){ var $ = function(id){
return document.getElementById(id); return document.getElementById(id);
}; };
@ -115,6 +137,8 @@ exports.$ = $;
exports.extend = extend; exports.extend = extend;
exports.proxy = proxy; exports.proxy = proxy;
exports.deepClone = deepClone; exports.deepClone = deepClone;
exports.setCookie = setCookie;
exports.getCookie = getCookie;
// export $; // export $;
// export extend; // export extend;
// export proxy; // export proxy;