diff --git a/package.json b/package.json index 9201418..0a7d6c9 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,8 @@ "author": "", "license": "ISC", "dependencies": { + "@szhsin/react-menu": "^3.0.2", + "@types/": "szhsin/react-menu", "@types/uuid": "^8.3.4", "mancala.js": "^0.0.2-beta.2", "react": "^17.0.2", diff --git a/src/Home.tsx b/src/Home.tsx index c102865..109c9ca 100644 --- a/src/Home.tsx +++ b/src/Home.tsx @@ -18,6 +18,10 @@ import { GameMove } from "./models/GameMove"; import PitAnimator from "./animation/PitAnimator"; import BoardViewModel from "./viewmodel/BoardViewModel"; import { v4 } from "uuid"; +import { Menu, MenuButton, MenuItem } from "@szhsin/react-menu"; +import "@szhsin/react-menu/dist/index.css"; +import "@szhsin/react-menu/dist/transitions/slide.css"; +import { getColorByLuminance } from "./util/ColorUtil"; type ConnectionState = "connecting" | "error" | "connected" | "reconnecting"; @@ -116,6 +120,12 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { }; }, []); + React.useEffect(() => { + context.themeManager.onThemeChange = () => { + updateBoardViewModel(pitAnimator.getBoardViewModelFromGame(game)); + }; + }, [boardViewModel]); + const resetGameState = () => { setGame(undefined); setCrashMessage(undefined); @@ -185,7 +195,11 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => { } return <>; }; - + const menuTextColor = getColorByLuminance( + context.themeManager.theme.appBarBgColor, + context.themeManager.theme.primary, + context.themeManager.theme.primaryLight + ); return (
= ({ initial = 0 }) => { }} >

{context.texts.Mancala}

-
+
+
+ light_mode + } + transition + align="end" + > + {context.themeManager.themes.map((theme) => { + return ( + (context.themeManager.theme = theme)} + > +
+ {theme.name} +
+ ); + })} +
+
{renderNewGameButton()} {game && !userKeyWhoLeave && diff --git a/src/animation/PitAnimator.ts b/src/animation/PitAnimator.ts index 3e912a7..d9c28fc 100644 --- a/src/animation/PitAnimator.ts +++ b/src/animation/PitAnimator.ts @@ -162,7 +162,7 @@ export default class PitAnimator { } } - private getBoardViewModelFromGame(game: MancalaGame): BoardViewModel { + public getBoardViewModelFromGame(game: MancalaGame): BoardViewModel { const pitViewModels = this.createPitViewModelsFromGame(game); return BoardViewModelFactory.create(v4(), pitViewModels); } diff --git a/src/context.tsx b/src/context.tsx index 140c840..0fd4cc5 100644 --- a/src/context.tsx +++ b/src/context.tsx @@ -2,7 +2,6 @@ import { Texts, TrTr } from "./const/texts"; import { RTMT } from "./rtmt/rtmt"; import { RTMTWS } from "./rtmt/rtmt_websocket"; import { UserKeyStore, UserKeyStoreImpl } from "./store/key_store"; -import defaultTheme from "./theme/DefaultTheme"; import ThemeManager from "./theme/ThemeManager"; export type Context = { @@ -16,7 +15,7 @@ export const initContext = () => { const rtmt = new RTMTWS(); const userKeyStore = new UserKeyStoreImpl(); const texts = TrTr; - const themeManager = new ThemeManager(defaultTheme); + const themeManager = new ThemeManager(); return { rtmt: rtmt, userKeyStore: userKeyStore, diff --git a/src/index.html b/src/index.html index cf30955..e6ca5a9 100644 --- a/src/index.html +++ b/src/index.html @@ -11,6 +11,8 @@ +