Commit 49402815 authored by Matthew Odle's avatar Matthew Odle

update initials menu

parent 5a09c3f9
......@@ -15,7 +15,7 @@ var metrics = {
// this.score = new Component(scoreParams);
// this.score.value = 0;
this.score.player1 = new Component(scoreParams);
this.score.player1.value = 0;
this.score.player1.value = 10;
scoreParams.x = 200;
this.score.player2 = new Component(scoreParams);
this.score.player2.value = 0;
......
......@@ -2,9 +2,9 @@ var init = {
run : function() {
console.log('init the things, yo');
knobsAndLevers.init();
templates.init();
menus.init();
game.init();
templates.init();
metrics.init();
spiders.init();
dom.init();
......
......@@ -93,10 +93,15 @@ var knobsAndLevers = {
this.args.width = configs.general.gridSquareSideLength * 0.75;
this.args.height = configs.general.gridSquareSideLength * 0.75;
this.args.y = -configs.canvas.height / 10;
this.interval = supporting.clone(configs.game.interval);
},
},
game : {
playerCollisionsEnabled : true,
interval : {
min : 0,
max : 0,
},
sounds : {
value : true,
default : true,
......@@ -268,6 +273,7 @@ var knobsAndLevers = {
this.args.width = configs.general.gridSquareSideLength;
this.args.height = configs.general.gridSquareSideLength * 0.5;
this.args.x = 1;
this.interval = supporting.clone(configs.game.interval);
},
},
text : {
......@@ -327,6 +333,7 @@ var knobsAndLevers = {
this.initialInterval = supporting.getRandom(this.interval.min, this.interval.max);
this.args.width = configs.general.gridSquareSideLength * 1.5;
this.args.height = configs.general.gridSquareSideLength;
this.interval = supporting.clone(configs.game.interval);
},
},
};
......@@ -2,7 +2,9 @@ menus = {
leaderboards : undefined,
currentSelection : undefined,
init : function() {
menusProps.init();
Object.assign(this, menusProps);
console.log(templates.marker);
this.selectionMarker = Object.assign({}, templates.marker);
console.log('menus initialized');
},
......@@ -12,7 +14,7 @@ menus = {
reset : function() {
game.gameOver = false;
this.init();
this.screens.initials.text.entries[2].text = '';
// this.screens.initials.text.entries[2].text = '';
this.display(metrics.lastScore ? 'initials' : 'main');
},
display : function(menu) {
......@@ -46,24 +48,49 @@ menus = {
};
},
manageInitials : function() {
this.setInitialsMenuEntries();
this.timeSinceMenuMove += 1;
this.shiftListOrder(this.screens.initials.options);
let initialsText = this.screens.initials.text.entries[2].text;
this.screens.initials.text.entries[1].text = 'your score: ' + metrics.lastScore;
if (initialsText.length >= 3) {
main.saveScore(initialsText);
metrics.lastScore = 0;
this.reset();
if (!this.currentSelection.entry || this.timeSinceMenuMove < this.minTimeToMove) {
return;
};
if (!this.currentSelection.entry.options) {
let initialsEntries = this.screens.initials.entries;
initialsEntries.previous.text = 'DONE';
initialsEntries.previous.xAdjust = 175;
initialsEntries.previouser.text = 'DONE';
initialsEntries.previouser.xAdjust = 175;
initialsEntries.next.text = 'DONE';
initialsEntries.next.xAdjust = 175;
initialsEntries.nexter.text = 'DONE';
initialsEntries.nexter.xAdjust = 175;
return;
};
this.screens.initials.text.entries[1].text = 'your score ' + metrics.lastScore;
this.shiftListOrder(this.currentSelection.entry.options);
let order = this.currentSelection.entry.options.slice();
let initialsEntries = this.screens.initials.entries;
initialsEntries.previous.text = order.pop();
initialsEntries.previouser.text = order.pop();
initialsEntries[this.currentSelection.name].text = order.shift();
initialsEntries.next.text = order.shift();
initialsEntries.nexter.text = order.shift();
let toAdjust = this.currentSelection.entry.xAdjust;
initialsEntries.previouser.xAdjust = initialsEntries.previouser.defaultXAdjust + (toAdjust ? toAdjust : 0);
initialsEntries.previous.xAdjust = initialsEntries.previous.defaultXAdjust + (toAdjust ? toAdjust : 0);
initialsEntries.next.xAdjust = initialsEntries.next.defaultXAdjust + (toAdjust ? toAdjust : 0);
initialsEntries.nexter.xAdjust = initialsEntries.nexter.defaultXAdjust + (toAdjust ? toAdjust : 0);
},
setInitialsMenuEntries : function() {
let order = this.screens.initials.options.slice();
this.screens.initials.entries.previous.text = order.pop();
this.screens.initials.entries.previouser.text = order.pop();
this.screens.initials.entries.current.text = order.shift();
this.screens.initials.entries.next.text = order.shift();
this.screens.initials.entries.nexter.text = order.shift();
selectNextInitial : function() {
let list = this.screens.initials.order;
let direction = controls.checkMenuDirection();
if (['left'].includes(direction)) {
list.unshift(list.pop());
} else if (['right'].includes(direction)) {
list.push(list.shift());
};
this.timeSinceMenuMove = 0;
},
getCurrentScreen : function() {
let activeScreen = supporting.getFirstTruthy(this.show);
......@@ -99,22 +126,22 @@ menus = {
},
setMenuOrder : function(order) {
this.timeSinceMenuMove += 1;
this.shiftListOrder(order);
if (this.timeSinceMenuMove > this.minTimeToMove) {
this.shiftListOrder(order);
};
this.currentSelection.name = order[0];
},
shiftListOrder : function(list) {
if (this.timeSinceMenuMove < this.minTimeToMove) {
return;
};
let direction = controls.checkMenuDirection();
if (list.length > 1) {
if (direction == "up") {
if (['up'].includes(direction)) {
this.timeSinceMenuMove = 0;
list.unshift(list.pop());
} else if (direction == "down") {
} else if (['down'].includes(direction)) {
list.push(list.shift());
this.timeSinceMenuMove = 0;
};
};
this.timeSinceMenuMove = 0;
},
drawEntries : function(entries) {
Object.keys(entries).forEach((entry, index) => {
......@@ -123,7 +150,7 @@ menus = {
menuElement.component = this.buildDefaultComponent();
};
menuElement.component.x = menuDefaults.entries.x + (menuElement.xAdjust ? menuElement.xAdjust : 0);
menuElement.component.y = menuDefaults.entries.y + menuDefaults.yDivider * index;
menuElement.component.y = menuDefaults.entries.y + (menuElement.yAdjust ? menuElement.yAdjust : 0) + menuDefaults.yDivider * index;
menuElement.component.text = menuElement.text;
if (menuElement.fontSize) {
menuElement.component.fontSize = menuElement.fontSize;
......@@ -133,6 +160,7 @@ menus = {
};
if (this.currentSelection.name == entry && !menuElement.noSelection) {
this.currentSelection.entry = menuElement;
this.currentSelection.color = this.selectedEntryColor;
};
menuElement.component.update();
});
......@@ -162,14 +190,25 @@ menus = {
buildDefaultComponent : function() {
return new Component(knobsAndLevers.text.baseParams);
},
checkForSelection : function() {
checkForSubmit : function() {
this.timeSinceSelection += 1;
if (
this.timeSinceSelection > this.minTimeToSelect
&&
(controls.keyboard.flowControlButtonPressed() || controls.menuSelect())
controls.submitIsPressed()
&&
this.currentSelection.entry.submit
) {
this.currentSelection.entry.action();
};
},
checkForSelection : function() {
this.timeSinceSelection += 1;
if (this.timeSinceSelection > this.minTimeToSelect) {
if (controls.menuSelect()) {
this.currentSelection.entry.action();
} else if (controls.submitIsPressed() && this.currentSelection.entry.submit) {
this.currentSelection.entry.submit();
};
};
},
addInitials : function(initial) {
......
......@@ -11,6 +11,9 @@ var menuDefaults = {
};
var menusProps = {
init : function() {
this.screens.initials.init();
},
title : {
entries : [
{
......@@ -22,6 +25,7 @@ var menusProps = {
],
},
show : {
// TODO set main to true to load main menu
initials : false,
cheats : false,
main : true,
......@@ -32,8 +36,8 @@ var menusProps = {
},
timeSinceSelection : 100,
timeSinceMenuMove : 100,
minTimeToSelect : 90,
minTimeToMove : 30,
minTimeToSelect : 50,
minTimeToMove : 70,
currentSelection : {
name : '',
entry : undefined,
......@@ -116,43 +120,101 @@ var menusProps = {
},
initials : {
ignoreMarker : true,
order : ['current'],
options : ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
order : ['left', 'middle', 'right', 'submit'],
options : ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
entries : {
previouser : {
noSelection: true,
fontSize : '15px',
xAdjust : -60,
defaultXAdjust : 7,
xAdjust : 7,
yAdjust : -10,
color : 'darkgrey',
},
previous : {
noSelection: true,
xAdjust : -30,
defaultXAdjust : 5,
xAdjust : 5,
yAdjust : -10,
color : 'grey',
},
current : {
left : {
text : 'A',
fontSize : '30px',
action : function() {
menus.addInitials(this.text);
let order = menus.screens.initials.order;
menus.selectNextInitial();
menus.display('initials');
},
},
middle : {
text : 'A',
fontSize : '30px',
xAdjust : 40,
yAdjust : -25,
action : function() {
menus.selectNextInitial();
menus.display('initials');
},
},
right : {
text : 'A',
fontSize : '30px',
xAdjust : 80,
yAdjust : -50,
action : function() {
menus.selectNextInitial();
menus.display('initials');
},
},
next : {
noSelection: true,
xAdjust : -30,
yAdjust : -10,
defaultXAdjust : 5,
xAdjust : 5,
yAdjust : -50,
color : 'grey',
},
nexter : {
noSelection: true,
fontSize : '15px',
xAdjust : -60,
yAdjust : -10,
defaultXAdjust : 7,
xAdjust : 7,
yAdjust : -50,
color : 'darkgrey',
},
submit : {
text : 'Done',
fontSize : '30px',
xAdjust : 175,
yAdjust : -125,
submit : function() {
main.saveScore(menus.screens.initials.getEntries());
menus.display('main');
},
action : function() {
menus.selectNextInitial();
menus.display('initials');
},
},
},
getEntries : function() {
let entries = '';
['left', 'middle', 'right'].forEach(entry => entries += this.entries[entry].text);
return entries;
},
init : function() {
this.entries.left.options = this.options.slice();
this.entries.middle.options = this.options.slice();
this.entries.right.options = this.options.slice();
},
text : {
entries : [
......@@ -168,13 +230,6 @@ var menusProps = {
yAdjust : 50,
fontSize : '20px',
},
{
name : 'entered',
text : '',
yAdjust : menuDefaults.entries.y - menuDefaults.text.y,
xAdjust : 235,
fontSize : '30px',
},
],
},
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment