From 0183bc474374b81bc769ccacfd2c7714d951370b Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Sat, 21 Jul 2018 12:02:37 +0200 Subject: [PATCH] difficulty ordering --- src/state/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/state/index.js b/src/state/index.js index eaeac66..6a664ce 100644 --- a/src/state/index.js +++ b/src/state/index.js @@ -65,17 +65,17 @@ AFRAME.registerState({ let challengeData = challengeDataStore[id]; Object.assign(state.menuSelectedChallenge, challengeData); + // Populate difficulty options. state.menuDifficulties.length = 0; for (let i = 0; i < challengeData.difficulties.length; i++) { state.menuDifficulties.push(challengeData.difficulties[i]); } + state.menuDifficulties.sort(difficultyComparator); + // Default to easiest difficulty. + state.menuSelectedChallenge.difficulty = state.menuDifficulties[0]; state.menuSelectedChallenge.image = utils.getS3FileUrl(id, 'image.jpg'); state.menuSelectedChallenge.downloadsText = `${challengeData.downloads} Plays`; - - // Choose first difficulty. - // TODO: Default and order by easiest to hardest. - state.menuSelectedChallenge.difficulty = state.menuDifficulties[0]; }, menudifficultyselect: (state, difficulty) => { @@ -193,3 +193,12 @@ function truncate (str, length) { } return str; } + +const DIFFICULTIES = ['Easy', 'Normal', 'Hard', 'Expert', 'ExpertPlus']; +function difficultyComparator (a, b) { + const aIndex = DIFFICULTIES.indexOf(a); + const bIndex = DIFFICULTIES.indexOf(b); + if (aIndex < bIndex) { return -1; } + if (aIndex > bIndex) { return 1; } + return 0; +}