difficulty ordering

This commit is contained in:
Kevin Ngo
2018-07-21 12:02:37 +02:00
parent 80f90b9d4c
commit 0183bc4743

View File

@@ -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;
}