Merge pull request #5 from jhalitaksoy/feature/pit-selected-color
Feature/pit selected color
This commit is contained in:
commit
03f446a891
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mancala-frontend",
|
"name": "mancala-frontend",
|
||||||
"version": "0.1.3-beta.4",
|
"version": "0.1.3-beta.5",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
10
src/Home.tsx
10
src/Home.tsx
@ -17,6 +17,7 @@ import { CommonMancalaGame, MancalaGame, Pit } from "mancala.js";
|
|||||||
import { GameMove } from "./models/GameMove";
|
import { GameMove } from "./models/GameMove";
|
||||||
import PitAnimator from "./animation/PitAnimator";
|
import PitAnimator from "./animation/PitAnimator";
|
||||||
import BoardViewModel from "./viewmodel/BoardViewModel";
|
import BoardViewModel from "./viewmodel/BoardViewModel";
|
||||||
|
import { v4 } from "uuid";
|
||||||
|
|
||||||
type ConnectionState = "connecting" | "error" | "connected" | "reconnecting";
|
type ConnectionState = "connecting" | "error" | "connected" | "reconnecting";
|
||||||
|
|
||||||
@ -100,6 +101,7 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateBoardViewModel = (boardViewModel: BoardViewModel) => {
|
const updateBoardViewModel = (boardViewModel: BoardViewModel) => {
|
||||||
|
boardViewModel.id = v4();
|
||||||
setBoardId(boardViewModel.id);
|
setBoardId(boardViewModel.id);
|
||||||
setBoardViewModel(boardViewModel);
|
setBoardViewModel(boardViewModel);
|
||||||
};
|
};
|
||||||
@ -130,12 +132,20 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
|
|||||||
context.rtmt.sendMessage(channel_leave_game, {});
|
context.rtmt.sendMessage(channel_leave_game, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getBoardIndex = (index: number) => {
|
||||||
|
if (userKey === game.player2Id) return index + game.board.pits.length / 2;
|
||||||
|
return index;
|
||||||
|
};
|
||||||
|
|
||||||
const onHoleSelect = (index: number, pit: Pit) => {
|
const onHoleSelect = (index: number, pit: Pit) => {
|
||||||
//TODO : stoneCount comes from view model!
|
//TODO : stoneCount comes from view model!
|
||||||
if (pit.stoneCount === 0) {
|
if (pit.stoneCount === 0) {
|
||||||
//TODO : warn user
|
//TODO : warn user
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
boardViewModel.pits[getBoardIndex(index)].pitColor =
|
||||||
|
context.themeManager.theme.pitSelectedColor;
|
||||||
|
updateBoardViewModel(boardViewModel);
|
||||||
const gameMove: GameMove = { index: index };
|
const gameMove: GameMove = { index: index };
|
||||||
context.rtmt.sendMessage(channel_game_move, gameMove);
|
context.rtmt.sendMessage(channel_game_move, gameMove);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -38,7 +38,7 @@ export default class PitAnimator {
|
|||||||
public setNewGame(game: MancalaGame) {
|
public setNewGame(game: MancalaGame) {
|
||||||
this.reset();
|
this.reset();
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.updateBoardViewModel(this.getBoardViewModelFromGame(this.game));
|
this.onBoardViewModelUpdate?.(this.getBoardViewModelFromGame(this.game));
|
||||||
}
|
}
|
||||||
|
|
||||||
public setUpdatedGame(game: MancalaGame, forceClear = false) {
|
public setUpdatedGame(game: MancalaGame, forceClear = false) {
|
||||||
@ -69,12 +69,12 @@ export default class PitAnimator {
|
|||||||
onAnimate() {
|
onAnimate() {
|
||||||
if (this.animationIndex === this.currentHistoryItem.gameSteps.length) {
|
if (this.animationIndex === this.currentHistoryItem.gameSteps.length) {
|
||||||
this.clearCurrentInterval();
|
this.clearCurrentInterval();
|
||||||
this.updateBoardViewModel(this.getBoardViewModelFromGame(this.game));
|
this.onBoardViewModelUpdate?.(this.getBoardViewModelFromGame(this.game));
|
||||||
} else {
|
} else {
|
||||||
const gameStep = this.currentHistoryItem.gameSteps[this.animationIndex];
|
const gameStep = this.currentHistoryItem.gameSteps[this.animationIndex];
|
||||||
const index = this.game.board.getPitIndexCircularly(gameStep.index);
|
const index = this.game.board.getPitIndexCircularly(gameStep.index);
|
||||||
this.animatePit(index, this.oldBoardViewModel, gameStep);
|
this.animatePit(index, this.oldBoardViewModel, gameStep);
|
||||||
this.updateBoardViewModel(this.oldBoardViewModel);
|
this.onBoardViewModelUpdate?.(this.oldBoardViewModel);
|
||||||
}
|
}
|
||||||
this.animationIndex++;
|
this.animationIndex++;
|
||||||
}
|
}
|
||||||
@ -143,7 +143,9 @@ export default class PitAnimator {
|
|||||||
stopCurrentAnimation() {
|
stopCurrentAnimation() {
|
||||||
this.clearCurrentInterval();
|
this.clearCurrentInterval();
|
||||||
if (this.oldGame) {
|
if (this.oldGame) {
|
||||||
this.updateBoardViewModel(this.getBoardViewModelFromGame(this.oldGame));
|
this.onBoardViewModelUpdate?.(
|
||||||
|
this.getBoardViewModelFromGame(this.oldGame)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.resetAnimationState();
|
this.resetAnimationState();
|
||||||
}
|
}
|
||||||
@ -154,11 +156,6 @@ export default class PitAnimator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBoardViewModel(boardViewModel: BoardViewModel) {
|
|
||||||
boardViewModel.id = v4();
|
|
||||||
this.onBoardViewModelUpdate?.(boardViewModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getBoardViewModelFromGame(game: MancalaGame): BoardViewModel {
|
private getBoardViewModelFromGame(game: MancalaGame): BoardViewModel {
|
||||||
const pitViewModels = this.createPitViewModelsFromGame(game);
|
const pitViewModels = this.createPitViewModelsFromGame(game);
|
||||||
return BoardViewModelFactory.create(v4(), pitViewModels);
|
return BoardViewModelFactory.create(v4(), pitViewModels);
|
||||||
|
|||||||
@ -7,6 +7,7 @@ const defaultTheme: Theme = {
|
|||||||
storeColor: "#3FBAC2",
|
storeColor: "#3FBAC2",
|
||||||
storeColorWhenPlayerTurn: "#6cab94",
|
storeColorWhenPlayerTurn: "#6cab94",
|
||||||
holeColor: "#D3D4D8",
|
holeColor: "#D3D4D8",
|
||||||
|
pitSelectedColor: "#8837fa",
|
||||||
ballColor: "#393E46",
|
ballColor: "#393E46",
|
||||||
ballLightColor: "#393E46",
|
ballLightColor: "#393E46",
|
||||||
pitGameMoveAnimateColor: "#c9b43c",
|
pitGameMoveAnimateColor: "#c9b43c",
|
||||||
|
|||||||
@ -5,6 +5,7 @@ export type Theme = {
|
|||||||
storeColor: string;
|
storeColor: string;
|
||||||
storeColorWhenPlayerTurn: string;
|
storeColorWhenPlayerTurn: string;
|
||||||
holeColor: string;
|
holeColor: string;
|
||||||
|
pitSelectedColor: string;
|
||||||
ballColor: string;
|
ballColor: string;
|
||||||
ballLightColor: string;
|
ballLightColor: string;
|
||||||
pitGameMoveAnimateColor: string;
|
pitGameMoveAnimateColor: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user