Commit 91b32484 authored by Matthew Odle's avatar Matthew Odle

convert menu texts from arrays to objects

parent c8722292
......@@ -31,9 +31,7 @@ mainMenu = {
},
},
},
text : {
entries : [],
},
text : {},
init : function() {
this.setLeaderboardTexts();
},
......@@ -45,17 +43,18 @@ mainMenu = {
if (!leaderboards) {
return;
};
this.text.entries = [];
this.text = {};
let entriesSoFar = 0;
let text = '';
supporting.fieldToCompare = 'score';
leaderboards.sort(supporting.compare).forEach((entry, index) => {
entriesSoFar = this.text.entries.length;
entriesSoFar = Object.keys(this.text).length;
text = entry.initials + ': ' + entry.score;
if (index < 10) {
this.text.entries.push(this.buildEntry(text, entriesSoFar));
this.text[entry.initials + entry.score] = this.buildEntry(text, entriesSoFar);
};
});
// console.log(this.text.entries);
},
buildEntry : function(text, count) {
return {
......
......@@ -108,7 +108,7 @@ menus = {
if (screen.update) {
screen.update();
};
this.drawTexts(menus.title);
this.drawTexts(menus.commonTexts);
this.drawEntries(screen.entries);
if (screen.order) {
this.setMenuOrder(screen.order);
......@@ -171,7 +171,8 @@ menus = {
this.selectionMarker.update();
},
drawTexts : function(texts) {
texts.entries.forEach((entry, index) => {
Object.keys(texts).forEach((key, index) => {
let entry = texts[key];
if (!entry.component) {
entry.component = this.buildDefaultComponent();
};
......@@ -210,16 +211,12 @@ menus = {
},
setGamepadText : function() {
let gamepadsEnabled = controls.gamepad.enabledGamepadIndices.size;
let playerActivateEntries = this.screens.playerActivate.text.entries;
playerActivateEntries[2].text = "Active gamepads: " + gamepadsEnabled;
if (gamepadsEnabled > 0) {
entry = playerActivateEntries[3];
game.activePlayers = 1;
entry.text = entry.base + 'ACTIVE';
};
if (gamepadsEnabled > 1) {
entry = playerActivateEntries[4];
game.activePlayers = 2;
let playerActivateEntries = this.screens.playerActivate.text;
playerActivateEntries.gamepadCount.text = "Active gamepads: " + gamepadsEnabled;
if (gamepadsEnabled) {
game.activePlayers = gamepadsEnabled;
let key = 'player' + gamepadsEnabled + 'Check';
entry = playerActivateEntries[key];
entry.text = entry.base + 'ACTIVE';
};
},
......
......@@ -11,15 +11,12 @@ var menuDefaults = {
};
var menusProps = {
title : {
entries : [
{
name : 'title',
text : 'CENTIPEDE!',
yAdjust : -100,
fontSize : '50px',
},
],
commonTexts : {
title : {
text : 'CENTIPEDE!',
yAdjust : -100,
fontSize : '50px',
},
},
show : {
initials : false,
......@@ -99,19 +96,17 @@ var menusProps = {
},
},
text : {
entries : [
{
text : 'Dear cheater,',
},
{
text : 'Scores will not be recorded',
xAdjust : 20,
},
{
text : 'if any of these are set',
xAdjust : 20,
},
],
first : {
text : 'Dear cheater,',
},
second : {
text : 'Scores will not be recorded',
xAdjust : 20,
},
third : {
text : 'if any of these are set',
xAdjust : 20,
},
},
},
instructions : {
......@@ -125,14 +120,12 @@ var menusProps = {
},
},
text : {
entries : [
{
text : 'WASD : move',
},
{
text : 'arrow keys or shift : shoot',
},
],
move : {
text : 'WASD : move',
},
shoot : {
text : 'arrow keys or shift : shoot',
},
},
},
playerActivate : {
......@@ -168,29 +161,27 @@ var menusProps = {
},
},
text : {
entries : [
{
text : '2 player mode requires gamepads',
},
{
text : 'because laziness',
},
{
first : {
text : '2 player mode requires gamepads',
},
second : {
text : 'because laziness',
},
gamepadCount : {
text : 'Active gamepads: 0',
xAdjust : 50,
yAdjust : 50,
},
{
base : 'Player 1: ',
xAdjust : 50,
yAdjust : 100,
},
{
base : 'Player 2: ',
xAdjust : 50,
yAdjust : 100,
},
],
},
player1Check : {
base : 'Player 1: ',
xAdjust : 50,
yAdjust : 100,
},
player2Check : {
base : 'Player 2: ',
xAdjust : 50,
yAdjust : 100,
},
},
},
playerSelect : {
......@@ -225,11 +216,9 @@ var menusProps = {
},
},
text : {
entries : [
{
text : 'Player Select',
},
],
first : {
text : 'Player Select',
},
},
},
settings : {
......@@ -273,11 +262,9 @@ var menusProps = {
},
},
text : {
entries : [
{
text : 'Settings Are Thither',
},
],
first : {
text : 'Settings Are Thither',
},
},
},
},
......
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