diff --git a/app/components/container.js b/app/components/container.js index 80f2107..d696539 100644 --- a/app/components/container.js +++ b/app/components/container.js @@ -62,15 +62,15 @@ export default class Container extends React.Component { }); } - handleLevelChange(levelId, name, value) { + handleLevelChange(levelIndex, name, value) { let levelsCopy = JSON.parse(JSON.stringify(this.state.levels)); if (name === "range") { - levelsCopy[levelId].start = value[0]; - levelsCopy[levelId].end = value[1]; + levelsCopy[levelIndex].start = value[0]; + levelsCopy[levelIndex].end = value[1]; } else { - levelsCopy[levelId][name] = value; + levelsCopy[levelIndex][name] = value; } this.setState({ @@ -163,7 +163,7 @@ export default class Container extends React.Component {
{ Object.keys(levels).map((levelId,_) => - +
diff --git a/app/utilities/defaults.js b/app/utilities/defaults.js index ec0243c..1c31d2a 100644 --- a/app/utilities/defaults.js +++ b/app/utilities/defaults.js @@ -26,14 +26,14 @@ export const createDefaultLevelsObject = (numLevels) => { const populatedLevels = {}; for (let i = 1; i <= numLevels; i++) { - const levelId = "level" + i; - - populatedLevels[levelId] = { - index: i, + populatedLevels[i] = { + level: i, start: defaultValues.time, end: defaultValues.time, branches: createDefaultBranchesObject() }; } + + console.log(populatedLevels); return populatedLevels; } \ No newline at end of file diff --git a/app/utilities/exportHelperFunctions.js b/app/utilities/exportHelperFunctions.js index 687a548..8369347 100644 --- a/app/utilities/exportHelperFunctions.js +++ b/app/utilities/exportHelperFunctions.js @@ -23,17 +23,32 @@ const traverseAndConvertToMilliseconds = (state, numFrames) => { } const trimStateAndCopy = (state) => { - Object.keys(state.levels).map( function(levelId,_) { + let levels = state.levels; - Object.keys(state.levels[levelId].branches).map( function(emotion,_) { + Object.keys(levels).map( function(levelId,_) { + + Object.keys(levels[levelId].branches).map( function(emotion,_) { - if (!state.levels[levelId].branches[emotion].enabled) { - state.levels[levelId].branches[emotion] = undefined; + if (!levels[levelId].branches[emotion].enabled) { + levels[levelId].branches[emotion] = undefined; } else { - state.levels[levelId].branches[emotion].enabled = undefined; + levels[levelId].branches[emotion].enabled = undefined; } }); }); + + + state.levels = arrayifyLevelsObject(levels); +} + +const arrayifyLevelsObject = (levels) => { + let levelsArray = new Array(Object.keys(levels).length); + + Object.keys(levels).map((levelIndex,_) => { + levelsArray[levelIndex-1] = levels[levelIndex]; + }); + + return levelsArray; } export const convertToMillisecondsAndTrimState = (state, numFrames) => {