Skip to content

Commit

Permalink
Create convertCodeToTile function (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsveron23 committed Aug 17, 2019
1 parent ed04004 commit e058fb0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/chess/core/mesurePosition.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import * as R from 'ramda'
import getCodeChanges from './getCodeChanges'
import { parseCode, convertTileToAxis } from '../helpers'

const convertCodeToTile = R.compose(
R.prop('tile'),
parseCode
)
import { convertCodeToTile, convertTileToAxis } from '../helpers'

/**
* Mesure position to be animated
Expand All @@ -16,9 +11,11 @@ const convertCodeToTile = R.compose(
*/
function mesurePosition (snapshot, prevSnapshot, width) {
const { nextCode, prevCode } = getCodeChanges(snapshot, prevSnapshot)

const nextTile = convertCodeToTile(nextCode)
const prevTile = convertCodeToTile(prevCode)
const { x: nextX, y: nextY } = convertTileToAxis(nextTile)

const prevTile = convertCodeToTile(prevCode)
const { x: prevX, y: prevY } = convertTileToAxis(prevTile)

return {
Expand Down
16 changes: 16 additions & 0 deletions src/chess/helpers/convertCodeToTile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as R from 'ramda'
import parseCode from './parseCode'

/**
* Convert code to tile
* @param {String} code
* @return {String}
*/
function convertCodeToTile (code) {
return R.compose(
R.prop('tile'),
parseCode
)(code)
}

export default convertCodeToTile
1 change: 1 addition & 0 deletions src/chess/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export { default as convertRankToY } from './convertRankToY'
export { default as convertSnapshotToTiles } from './convertSnapshotToTiles'
export { default as convertTileToAxis } from './convertTileToAxis'
export { default as convertAxisToTile } from './convertAxisToTile'
export { default as convertCodeToTile } from './convertCodeToTile'
export { default as replaceSnapshot } from './replaceSnapshot'
export { default as insertAxis } from './insertAxis'
export { default as createSnapshotRe } from './createSnapshotRe'
Expand Down
8 changes: 8 additions & 0 deletions src/chess/helpers/tests/convertCodeToTile.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import convertCodeToTile from '../convertCodeToTile'

describe('#convertCodeToTile', () => {
it('Convert code to tile', () => {
expect(convertCodeToTile('wPa7')).toEqual('a7')
expect(convertCodeToTile('bRh2')).toEqual('h2')
})
})

0 comments on commit e058fb0

Please sign in to comment.