pull/1/head
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%;
}
/* 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{
background: #000000;
margin:0;

156
dist/tetrion.js vendored
View File

@ -423,10 +423,31 @@ module.exports = gamepadAPI;
// export gamepadAPI;
},{}],4:[function(require,module,exports){
var gamepad = require('./gamepad.js');
var utils = require('./utils.js');
// import * as gamepad from './gamepad.js';
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('keyup', this.keyUp.bind(this));
},
@ -449,15 +470,21 @@ var UserInputs = {
},
processGamepadInput() {
this.gamepadButtonsDown("RB");
this.gamepadButtonsDown("LB");
this.gamepadButtonsDown("A");
this.gamepadButtonsDown("B");
this.gamepadButtonsDown("DPad-Up");
this.gamepadButtonsDown("Back");
// this.gamepadButtonsDown("RB"); // hard drop
// this.gamepadButtonsDown("LB"); // hold
// this.gamepadButtonsDown("A"); // rotate counter
// this.gamepadButtonsDown("B"); // rotate cwise
// this.gamepadButtonsDown("DPad-Up"); // Pop hold stack
// this.gamepadButtonsDown("Back"); // reset
//this.gamepadButtonsDown("X");
//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;
@ -465,9 +492,9 @@ var UserInputs = {
processGamepadDPad()
{
this.gamepadDPadDown("DPad-Left");
this.gamepadDPadDown("DPad-Right");
this.gamepadDPadDown("DPad-Down");
this.gamepadDPadDown(this.settingsMap.get("gamepad_left")); // shift left
this.gamepadDPadDown(this.settingsMap.get("gamepad_right")); // shift right
this.gamepadDPadDown(this.settingsMap.get("gamepad_down")); // down
return;
},
@ -506,8 +533,8 @@ var UserInputs = {
// Direction Pad
gamepadDPadDown(finds) {
var DAS = 65.0;
var ARR = 20.0;
var DAS = parseInt(this.settingsMap.get("gamepad_das")); //65.0;
var ARR = parseInt(this.settingsMap.get("gamepad_arr")); //20.0;
var isContained = this.gpButtons.includes(finds);
var isPrevContained = this.prevGpButtons.includes(finds);
@ -537,14 +564,14 @@ var UserInputs = {
return;
},
processKeys() {
this.processKeyDown(32); // Space
this.processKeyDown(88); // X
this.processKeyDown(90); // Z
this.processKeyDown(16); // shift
this.processKeyDown(17); // ctrl
this.processKeyDown(81); // q
this.processKeyDown(82); // r
this.processKeyDown(67); // c
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_harddrop"))); //32); // Space - hard drop
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_rotate"))); //88); // X - rotate
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_rotateccw"))); //90); // Z - rotateccw
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_hold"))); //16); // shift - push hold stack
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_pophold"))); // ctrl - pop hold stack
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_background"))); // q - turn off background
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_reset"))); // r - reset
//this.processKeyDown(this.settingsMap.get("keyboard_hold"))); // c - pop hold stack
},
// keyboard keys z,x,space
@ -581,14 +608,14 @@ var UserInputs = {
},
processKeyShift() {
this.processKeyboardArrowKeys(39); // right
this.processKeyboardArrowKeys(37); // left
this.processKeyboardArrowKeys(40); // down
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_left"))); //39); // right
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_right"))); //37); // left
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_down"))); // down
},
// Direction arrows
processKeyboardArrowKeys(key) {
var DAS = 65.0;
var ARR = 20.0;
var DAS = parseInt(this.settingsMap.get("keyboard_das")); //65.0;
var ARR = parseInt(this.settingsMap.get("keyboard_arr")); //20.0;
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
@ -616,8 +643,8 @@ var UserInputs = {
},
keyDown(event) {
// Disable space scrolling etc
event.preventDefault();
if (! ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8))
event.preventDefault();
this.keyboardKeys[event.keyCode] = true;
this.isKeyBoardKeyDown = true;
@ -661,12 +688,33 @@ var UserInputs = {
inputqueue: [],
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;
// 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 consts = require('./consts.js');
var shapes = require('./shapes.js');
@ -825,7 +873,7 @@ Tetris.prototype = {
views.init(this.id, cfg.maxWidth, cfg.maxHeight);
canvas.init(views.scene, views.preview, views.hold);
inputs.init();
this.createSettings();
// if true no openers. just random tetrinos
this.isFreePlay = true;
this.currentOpener = 0;
@ -859,6 +907,30 @@ Tetris.prototype = {
this.currentOpener = 2;
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: function() {
@ -2488,6 +2560,28 @@ module.exports.getShape = getShape;
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){
return document.getElementById(id);
};
@ -2602,6 +2696,8 @@ exports.$ = $;
exports.extend = extend;
exports.proxy = proxy;
exports.deepClone = deepClone;
exports.setCookie = setCookie;
exports.getCookie = getCookie;
// export $;
// export extend;
// export proxy;

View File

@ -36,7 +36,7 @@
<!--insert shadertoy background-->
<!--https://www.shadertoy.com/embed/wttfW2?gui=&t=10&paused=false&muted=false-->
<!--
<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>
<script>
@ -48,7 +48,7 @@ document.getElementById("bg").removeAttribute("tabIndex");
document.getElementById("divbg").removeAttribute("tabIndex");
</script>
</div>
-->
<div id="tetris">
<canvas id="scene"></canvas>
@ -99,7 +99,7 @@ document.getElementById("divbg").removeAttribute("tabIndex");
</ul>
-->
<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="setSecondPCVar">Second Perfect Clear </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>
<div id="rewardInfo" class="invisible">+<span id="reward">0</span></div>
<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>
@ -141,7 +151,8 @@ document.getElementById("divbg").removeAttribute("tabIndex");
document.getElementById("setFreePlay").addEventListener("click", function() { tetrion.setFreePlay(); } );
document.getElementById("setTKIFonzieVar").addEventListener("click", function() { tetrion.setTKIFonzieVar(); } );
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();
})();
</script>

View File

@ -1,8 +1,29 @@
var gamepad = require('./gamepad.js');
var utils = require('./utils.js');
// import * as gamepad from './gamepad.js';
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('keyup', this.keyUp.bind(this));
},
@ -25,15 +46,21 @@ var UserInputs = {
},
processGamepadInput() {
this.gamepadButtonsDown("RB");
this.gamepadButtonsDown("LB");
this.gamepadButtonsDown("A");
this.gamepadButtonsDown("B");
this.gamepadButtonsDown("DPad-Up");
this.gamepadButtonsDown("Back");
// this.gamepadButtonsDown("RB"); // hard drop
// this.gamepadButtonsDown("LB"); // hold
// this.gamepadButtonsDown("A"); // rotate counter
// this.gamepadButtonsDown("B"); // rotate cwise
// this.gamepadButtonsDown("DPad-Up"); // Pop hold stack
// this.gamepadButtonsDown("Back"); // reset
//this.gamepadButtonsDown("X");
//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;
@ -41,9 +68,9 @@ var UserInputs = {
processGamepadDPad()
{
this.gamepadDPadDown("DPad-Left");
this.gamepadDPadDown("DPad-Right");
this.gamepadDPadDown("DPad-Down");
this.gamepadDPadDown(this.settingsMap.get("gamepad_left")); // shift left
this.gamepadDPadDown(this.settingsMap.get("gamepad_right")); // shift right
this.gamepadDPadDown(this.settingsMap.get("gamepad_down")); // down
return;
},
@ -82,8 +109,8 @@ var UserInputs = {
// Direction Pad
gamepadDPadDown(finds) {
var DAS = 65.0;
var ARR = 20.0;
var DAS = parseInt(this.settingsMap.get("gamepad_das")); //65.0;
var ARR = parseInt(this.settingsMap.get("gamepad_arr")); //20.0;
var isContained = this.gpButtons.includes(finds);
var isPrevContained = this.prevGpButtons.includes(finds);
@ -113,14 +140,14 @@ var UserInputs = {
return;
},
processKeys() {
this.processKeyDown(32); // Space
this.processKeyDown(88); // X
this.processKeyDown(90); // Z
this.processKeyDown(16); // shift
this.processKeyDown(17); // ctrl
this.processKeyDown(81); // q
this.processKeyDown(82); // r
this.processKeyDown(67); // c
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_harddrop"))); //32); // Space - hard drop
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_rotate"))); //88); // X - rotate
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_rotateccw"))); //90); // Z - rotateccw
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_hold"))); //16); // shift - push hold stack
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_pophold"))); // ctrl - pop hold stack
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_background"))); // q - turn off background
this.processKeyDown(parseInt(this.settingsMap.get("keyboard_reset"))); // r - reset
//this.processKeyDown(this.settingsMap.get("keyboard_hold"))); // c - pop hold stack
},
// keyboard keys z,x,space
@ -157,14 +184,14 @@ var UserInputs = {
},
processKeyShift() {
this.processKeyboardArrowKeys(39); // right
this.processKeyboardArrowKeys(37); // left
this.processKeyboardArrowKeys(40); // down
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_left"))); //39); // right
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_right"))); //37); // left
this.processKeyboardArrowKeys(parseInt(this.settingsMap.get("keyboard_down"))); // down
},
// Direction arrows
processKeyboardArrowKeys(key) {
var DAS = 65.0;
var ARR = 20.0;
var DAS = parseInt(this.settingsMap.get("keyboard_das")); //65.0;
var ARR = parseInt(this.settingsMap.get("keyboard_arr")); //20.0;
if(this.prevKeyboardKeys[key] != this.keyboardKeys[key]) {
@ -192,8 +219,8 @@ var UserInputs = {
},
keyDown(event) {
// Disable space scrolling etc
event.preventDefault();
if (! ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105) || event.keyCode == 8))
event.preventDefault();
this.keyboardKeys[event.keyCode] = true;
this.isKeyBoardKeyDown = true;
@ -237,7 +264,28 @@ var UserInputs = {
inputqueue: [],
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;

View File

@ -156,7 +156,7 @@ Tetris.prototype = {
views.init(this.id, cfg.maxWidth, cfg.maxHeight);
canvas.init(views.scene, views.preview, views.hold);
inputs.init();
this.createSettings();
// if true no openers. just random tetrinos
this.isFreePlay = true;
this.currentOpener = 0;
@ -190,6 +190,30 @@ Tetris.prototype = {
this.currentOpener = 2;
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: function() {

View File

@ -1,6 +1,28 @@
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){
return document.getElementById(id);
};
@ -115,6 +137,8 @@ exports.$ = $;
exports.extend = extend;
exports.proxy = proxy;
exports.deepClone = deepClone;
exports.setCookie = setCookie;
exports.getCookie = getCookie;
// export $;
// export extend;
// export proxy;