Skip to content

Commit

Permalink
Merge pull request #467 from freefal/fixStageClock
Browse files Browse the repository at this point in the history
Fix stage clock
  • Loading branch information
veloce authored Oct 23, 2016
2 parents 91a98fe + 2a3855b commit 5b9df22
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
8 changes: 4 additions & 4 deletions project/src/js/ui/clock/clockView.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ function clockBody(ctrl) {
return (
<div className="clockContainer">
<div key="topClockTapArea" className={topClockClass} oncreate={h.ontouch(() => onClockTouch(ctrl, 'top'))}>
{ clock.topRemainingMoves ?
{ clock.topMoves && clock.topMoves() !== null ?
<div className="clockStageInfo">
<span>Moves remaining: {clock.topRemainingMoves ? clock.topRemainingMoves() : ''}</span>
<span>Moves remaining: {clock.topMoves()}</span>
</div> : null
}
<div className="clockTapAreaContent">
Expand All @@ -88,9 +88,9 @@ function clockBody(ctrl) {
{ bottomFlagged ? 'b' : formatTime(ctrl.clockType(), clock.bottomTime() / 1000) }
</span>
</div>
{ clock.bottomRemainingMoves ?
{ clock.bottomMoves && clock.bottomMoves() !== null ?
<div className="clockStageInfo">
<span>Moves remaining: {clock.bottomRemainingMoves ? clock.bottomRemainingMoves() : ''}</span>
<span>Moves remaining: {clock.bottomMoves()}</span>
</div> : null
}
</div>
Expand Down
46 changes: 17 additions & 29 deletions project/src/js/ui/clock/clocks/StageClock.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const MINUTE_MILLIS = 60 * 1000;
export default function StageClock(stages, increment) {
const topTime = m.prop(Number(stages[0].time) * MINUTE_MILLIS);
const bottomTime = m.prop(Number(stages[0].time) * MINUTE_MILLIS);
const topMoves = m.prop(0);
const bottomMoves = m.prop(0);
const topMoves = m.prop(Number(stages[0].moves));
const bottomMoves = m.prop(Number(stages[0].moves));
const topStage = m.prop(0);
const bottomStage = m.prop(0);
const activeSide = m.prop(null);
Expand Down Expand Up @@ -51,25 +51,33 @@ export default function StageClock(stages, increment) {

if (side === 'top') {
if (activeSide() === 'top') {
topMoves(topMoves() + 1);
if (topMoves())
topMoves(topMoves() - 1);
topTime(topTime() + increment);
if (topMoves() === Number(stages[topStage()].moves)) {
if (topMoves() === 0) {
topStage(topStage() + 1);
topTime(topTime() + Number(stages[topStage()].time) * MINUTE_MILLIS);
topMoves(0);
if (topStage() === (stages.length - 1))
topMoves(null);
else
topMoves(stages[topStage()].moves);
}
}
bottomTimestamp = performance.now();
activeSide('bottom');
}
else {
if (activeSide() === 'bottom') {
bottomMoves(bottomMoves() + 1);
if (bottomMoves())
bottomMoves(bottomMoves() - 1);
bottomTime(bottomTime() + increment);
if (bottomMoves() === Number(stages[bottomStage()].moves)) {
if (bottomMoves() === 0) {
bottomStage(bottomStage() + 1);
bottomTime(bottomTime() + Number(stages[bottomStage()].time) * MINUTE_MILLIS);
bottomMoves(0);
if (bottomStage() === (stages.length - 1))
bottomMoves(null);
else
bottomMoves(stages[bottomStage()].moves);
}
}
topTimestamp = performance.now();
Expand Down Expand Up @@ -99,24 +107,6 @@ export default function StageClock(stages, increment) {
}
}

function topRemainingMoves() {
if (stages[topStage()].moves) {
return Number(stages[topStage()].moves) - topMoves();
}
else {
return null;
}
}

function bottomRemainingMoves() {
if (stages[bottomStage()].moves) {
return Number(stages[bottomStage()].moves) - bottomMoves();
}
else {
return null;
}
}

return {
topTime,
bottomTime,
Expand All @@ -127,8 +117,6 @@ export default function StageClock(stages, increment) {
clockHit,
startStop,
topMoves,
bottomMoves,
topRemainingMoves,
bottomRemainingMoves
bottomMoves
};
}

0 comments on commit 5b9df22

Please sign in to comment.