Skip to content

Commit

Permalink
[#57] Save solution result
Browse files Browse the repository at this point in the history
  • Loading branch information
humanamburu committed Aug 6, 2017
1 parent 53be83d commit 65f46e2
Show file tree
Hide file tree
Showing 5 changed files with 6,301 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/game/components/code-editor/code-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class CodeEditor extends Component {
CodeMirror.commands.autocomplete(editor, null, { completeSingle: false });
}

if (typeof this.props.onChange === 'function') {
if (typeof this.props.onChange === 'function' && !editor.getOption('readOnly')) {
this.props.onChange(value, event);
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/game/middleware/server-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const MESSAGE_NAME = ui.MESSAGE_NAME;

function formatStateMessage(message) {
const { roundCountdown, startCountdown, roundPhase, puzzle } = message;
const { puzzleIndex, puzzleCount, displayName, playerInput } = message;
const { puzzleIndex, puzzleCount, displayName, playerInput, solution } = message;

return {
round: {
Expand All @@ -26,6 +26,7 @@ function formatStateMessage(message) {
remaining: roundCountdown,
phase: roundPhase,
playerInput,
solution: solution ? Object.assign({}, solution) : null,
},
participant: {
displayName,
Expand Down
14 changes: 11 additions & 3 deletions app/game/reducers/current-round.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ const defaultState = {
playerInput: '',
};

function updateSolution(state, solution) {
return Object.assign({}, state, {
function formatSolution(solution) {
return {
solutionResult: solution.error || solution.result,
solutionTime: solution.time,
correct: solution.correct,
});
};
}

function updateSolution(state, solution) {
return Object.assign({}, state, formatSolution(solution));
}

function updateRound(state, round) {
Expand Down Expand Up @@ -115,6 +119,10 @@ function updateRoundState(state, roundState) {
round.expected = roundState.puzzle.expected || defaultState.expected;
}

if (roundState.solution) {
Object.assign(round, formatSolution(roundState.solution));
}

return Object.assign({}, state, round);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"dependencies": {
"codemirror": "^5.23.0",
"js-beautify": "^1.6.8",
"message-factory": "21-23/message-factory#v5.1.0",
"message-factory": "21-23/message-factory#v5.2.3",
"phoenix": "github:21-23/phoenix#v2.1.1",
"preact": "^7.1.0",
"preact-compat": "^3.16.0",
Expand Down
Loading

0 comments on commit 65f46e2

Please sign in to comment.