Skip to content

Commit

Permalink
Add keyboard highlight support for Tutorial
Browse files Browse the repository at this point in the history
References #109
Also as a sidenote, we're still missing some mappings for some special keys, but for now they default to showing non highlighted hands
  • Loading branch information
francesar committed Aug 14, 2019
1 parent 2d6564f commit af8955c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 33 deletions.
20 changes: 13 additions & 7 deletions src/components/LeftHand.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 18 additions & 15 deletions src/components/RightHand.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions src/components/TutorialContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { OrderedMap } from 'immutable';
import styled from 'styled-components'

import LessonTutorialHandsKeyboard from './TutorialHandsKeyboard';
import {setHandsForKeyPressed} from '../services/keyboardHighlight';

import "../style/TutorialContent.css"

Expand Down Expand Up @@ -42,6 +43,8 @@ class LessonTutorialContent extends Component {

const totalLength = currentContent.length;

const {rightHandImg, leftHandImg} = setHandsForKeyPressed(currentKey);

this.closeModal=this.closeModal.bind(this);
this.modalCountdown = this.modalCountdown.bind(this)

Expand All @@ -67,7 +70,13 @@ class LessonTutorialContent extends Component {
finishTime: 0,
pauses: [],
time: 0,
modelCount: 5
modelCount: 5,

// Paths for images of hands
handPaths: {
rightHandImg,
leftHandImg
},
};
}

Expand Down Expand Up @@ -246,6 +255,9 @@ class LessonTutorialContent extends Component {

shouldShowModal = consecutiveIncorrectCount > 4;

// Set new hand img paths for next key
const {leftHandImg, rightHandImg} = setHandsForKeyPressed(newCurrentKey);

this.setState({
rows,
correct,
Expand All @@ -255,8 +267,12 @@ class LessonTutorialContent extends Component {
charPtr: newCharPtr,
groupPtr: newGroupPtr,
currentKey: newCurrentKey,
handPaths: {
rightHandImg,
leftHandImg
},
consecutiveIncorrectCount,
shouldShowModal
shouldShowModal,
});
};

Expand Down Expand Up @@ -370,7 +386,11 @@ class LessonTutorialContent extends Component {
<ModalCountDownDiv>{this.state.modelCount}</ModalCountDownDiv>
</Modal>
{ rows }
<LessonTutorialHandsKeyboard currentKey={currentKey}/>
<LessonTutorialHandsKeyboard
currentKey={currentKey}
leftHandImg={this.state.handPaths.leftHandImg}
rightHandImg={this.state.handPaths.rightHandImg}
/>
</div>
)
}
Expand Down
9 changes: 4 additions & 5 deletions src/components/TutorialHandsKeyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import LeftHand from './LeftHand';

import {setHandsForKeyPressed} from '../services/keyboardHighlight';

const LessonTutorialHandsKeyboard = ({ currentKey }) => {
const { leftHandImage, rightHandImage } = setHandsForKeyPressed(currentKey);
const LessonTutorialHandsKeyboard = ({ currentKey, leftHandImg, rightHandImg }) => {
return (
<div className="keyboard-hands row">
<LeftHand img={leftHandImage} />
<LeftHand img={leftHandImg} />
<Keyboard currentKey={currentKey} />
<RightHand img={rightHandImage} />
<RightHand img={rightHandImg} />
</div>
)
}

export default LessonTutorialHandsKeyboard;
export default LessonTutorialHandsKeyboard;
7 changes: 4 additions & 3 deletions src/services/keyboardHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ export function setHandsForKeyPressed(keyPressed) {
export function _setHandsForKeyPressed(keyPressed, imgs) {
// This should never happen since all possible keys should be
// registered in imgForCharacter
console.log('in', keyPressed);
if (!imgs.has(keyPressed)) {
return {leftHandImage:'', rightHandImage: ''};
return {leftHandImg:'', rightHandImg: ''};
}
const [leftHandImage, rightHandImage] = imgs.get(keyPressed);
return {leftHandImage, rightHandImage};
const [leftHandImg, rightHandImg] = imgs.get(keyPressed);
return {leftHandImg, rightHandImg};
};

// The value is an array whose 0 index is the
Expand Down

0 comments on commit af8955c

Please sign in to comment.