Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/components/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export interface GridProps {
editMode: boolean;
frozen: boolean;

// Clue lookup
clues: {across: string[]; down: string[]}; //figure out type

// callbacks
onChangeDirection(): void;
onSetSelected(cellCoords: CellCoords): void;
Expand Down Expand Up @@ -119,7 +122,31 @@ export default class Grid extends React.PureComponent<GridProps> {
};

handleRightClick = (r: number, c: number) => {
this.props.onPing && this.props.onPing(r, c);
const {direction} = this.props;
const clueNumber = this.grid.getParent(r, c, direction);
const answer = this.grid.isWordRevealed(direction, clueNumber);
const clue = this.props.clues[direction][clueNumber];
if (answer !== '') {
window.open(`https://www.google.com/search?q=${answer}+${clue}`, '_blank');
window.focus();
} else {
this.props.onPing && this.props.onPing(r, c);
}
};

lookUpWordMeaning = (r: number, c: number) => {
const {direction} = this.props;
const clueNumber = this.grid.getParent(r, c, direction);
const answer = this.grid.isWordRevealed(direction);
const clue = '';

if (answer !== '') {
window.open(
`https://www.google.com/search?q=${answer},
'_blank`
);
window.focus();
}
};

getAllSquares() {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ export default class Player extends Component {
onChangeDirection: this._changeDirection,
pickups,
frozen,
clues,
};

const clueProps = {
Expand Down Expand Up @@ -566,7 +567,7 @@ export default class Player extends Component {
</div>

<div className={`player--main--left--grid${frozen ? ' frozen' : ''} blurable`}>
<Grid ref="grid" {...gridProps} />
<Grid ref="grid" {...gridProps} clues={clues} />
</div>
</div>

Expand Down
30 changes: 29 additions & 1 deletion src/lib/wrappers/GridWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export default class GridWrapper {
const _r = r;
const _c = c;
let {noWraparound = false, skipFirst = false} = options;

while (this.isWriteable(r, c)) {
if (!this.isFilled(r, c)) {
if (!skipFirst) {
Expand Down Expand Up @@ -185,6 +184,31 @@ export default class GridWrapper {
return !this.hasEmptyCells(clueRoot.r, clueRoot.c, direction);
}

getRevealedWord(r, c, direction, answer = '') {
while (this.isWriteable(r, c)) {
if (!this.isFilled(r, c)) {
return '';
}
if (this.isRevealed(r, c)) {
answer += this.grid[r][c].value;
} else {
return '';
}
if (direction === 'across') {
c += 1;
} else {
r += 1;
}
}
return answer;
}

isWordRevealed(direction, number) {
if (number === 0) return '';
const clueRoot = this.getCellByNumber(number);
return this.getRevealedWord(clueRoot.r, clueRoot.c, direction);
}

getNextClue(clueNumber, direction, clues, backwards, parallel) {
clueNumber = parallel ? this.parallelMap[direction][clueNumber] : clueNumber;
const add = backwards ? -1 : 1;
Expand Down Expand Up @@ -280,6 +304,10 @@ export default class GridWrapper {
return !this.grid[r][c].black;
}

isRevealed(r, c) {
return this.grid[r][c].revealed;
}

isWriteable(r, c) {
return this.isInBounds(r, c) && this.isWhite(r, c);
}
Expand Down