Skip to content
Merged
Prev Previous commit
Next Next commit
[add] adds fake ghost for no replay scenario
  • Loading branch information
rickyeh committed Apr 12, 2016
commit 5098a54f22ec323b1c5f49fb130e08439b736c95
25 changes: 19 additions & 6 deletions client/containers/CodeGhost.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ class CodeGhost extends Component {
}
}

// Generates a fake ghost replay when there is no recording
generateFakeGhost() {
let fakeRecord = {};

let startTime = new Date().getTime();
let currentTime = new Date().getTime();

for (let i = 0; i < this.props.currentPuzzle.length; i++) {
fakeRecord[currentTime] = this.props.currentPuzzle.slice(0,i);
currentTime += Math.random() * (1000 - 100) + 100;
}

fakeRecord.duration = currentTime - startTime;

return fakeRecord;
}

componentDidUpdate() {
if (this.props.currentLanguage.language === 'py') {
this.editor.getSession().setMode("ace/mode/python");
Expand All @@ -111,12 +128,8 @@ class CodeGhost extends Component {
this.pendingGetRequest = false;

} else {
this.record = {
recording: {
'1': 'No replay loaded'
},
duration: 999999999999
};
this.record = this.generateFakeGhost();

this.pendingGetRequest = false;
}
this.previousLevel = this.props.currentLevel.currentLevel;
Expand Down