diff --git a/core/src/index.ts b/core/src/index.ts index d7c8ed2..e0b6fb2 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -2,4 +2,5 @@ export * from './models/index' export * from './rtmt/index' export * from './theme/index' export * from './storage/storage' -export * from './localization/index' \ No newline at end of file +export * from './localization/index' +export * from './util/index' \ No newline at end of file diff --git a/mobile/src/util/ColorUtil.ts b/core/src/util/ColorUtil.ts similarity index 98% rename from mobile/src/util/ColorUtil.ts rename to core/src/util/ColorUtil.ts index 4a6c94b..0cf65ce 100644 --- a/mobile/src/util/ColorUtil.ts +++ b/core/src/util/ColorUtil.ts @@ -18,6 +18,7 @@ export function hexToRgb( hex: string, result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) ): number[] { + // TODO: fix later //@ts-ignore return result ? result.map((i) => parseInt(i, 16)).slice(1) : null; //returns [23, 14, 45] -> reformat if needed diff --git a/core/src/util/index.ts b/core/src/util/index.ts new file mode 100644 index 0000000..a096cdb --- /dev/null +++ b/core/src/util/index.ts @@ -0,0 +1 @@ +export * from './ColorUtil' \ No newline at end of file diff --git a/frontend/src/MancalaApp.tsx b/frontend/src/MancalaApp.tsx index 45ff32b..1354c35 100644 --- a/frontend/src/MancalaApp.tsx +++ b/frontend/src/MancalaApp.tsx @@ -11,7 +11,7 @@ import Home from './routes/Home'; import { initContext } from './context/context'; import { RTMTWS, ConnectionState } from '@mancala/core'; -import { getColorByBrightness } from './util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import { Theme } from '@mancala/core'; import LobyPage from './routes/LobyPage'; import PrivacyPage from './routes/PrivacyPage'; diff --git a/frontend/src/animation/PitAnimator.ts b/frontend/src/animation/PitAnimator.ts index a07faf7..c87717d 100644 --- a/frontend/src/animation/PitAnimator.ts +++ b/frontend/src/animation/PitAnimator.ts @@ -12,9 +12,8 @@ import { v4 } from "uuid"; import { Context } from "../context/context"; import BoardViewModelFactory from "../factory/BoardViewModelFactory"; import { PitViewModelFactory } from "../factory/PitViewModelFactory"; -import { Game } from "@mancala/core"; -import { Theme } from "../theme/Theme"; -import { getColorByBrightness } from "../util/ColorUtil"; +import { Game, Theme } from "@mancala/core"; +import { getColorByBrightness } from "@mancala/core"; import BoardViewModel from "../viewmodel/BoardViewModel"; const animationUpdateInterval = 300; diff --git a/frontend/src/components/Button.tsx b/frontend/src/components/Button.tsx index 620e3e1..105917e 100644 --- a/frontend/src/components/Button.tsx +++ b/frontend/src/components/Button.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import { FunctionComponent } from "react"; import { Context } from "../context/context"; -import { getColorByBrightness } from "../util/ColorUtil"; +import { getColorByBrightness } from "@mancala/core"; const Button: FunctionComponent<{ context: Context; diff --git a/frontend/src/components/InfoPanel.tsx b/frontend/src/components/InfoPanel.tsx index da7c2bc..d15c1d5 100644 --- a/frontend/src/components/InfoPanel.tsx +++ b/frontend/src/components/InfoPanel.tsx @@ -2,7 +2,7 @@ import * as React from "react"; import { FunctionComponent } from "react"; import { Context } from "../context/context"; import { Game, User } from "@mancala/core"; -import { getColorByBrightness } from "../util/ColorUtil"; +import { getColorByBrightness } from "@mancala/core"; import CircularPanel from "./CircularPanel"; import { useTranslation } from "react-i18next"; diff --git a/frontend/src/components/LoadingComponent.tsx b/frontend/src/components/LoadingComponent.tsx index 17ec903..ea0e15c 100644 --- a/frontend/src/components/LoadingComponent.tsx +++ b/frontend/src/components/LoadingComponent.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { FunctionComponent } from 'react'; import { Context } from '../context/context'; import { LoadingState } from "@mancala/core"; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import CircularPanel from './CircularPanel'; import { useTranslation } from 'react-i18next'; diff --git a/frontend/src/components/PageContainer.tsx b/frontend/src/components/PageContainer.tsx index 7d08f57..8740ee2 100644 --- a/frontend/src/components/PageContainer.tsx +++ b/frontend/src/components/PageContainer.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import { FunctionComponent } from "react"; -import { Theme } from "../theme/Theme"; +import { Theme } from "@mancala/core"; const PageContainer: FunctionComponent<{ theme: Theme }> = (props) => { return ( diff --git a/frontend/src/components/UserStatus.tsx b/frontend/src/components/UserStatus.tsx index 614e48c..c4f767c 100644 --- a/frontend/src/components/UserStatus.tsx +++ b/frontend/src/components/UserStatus.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { FunctionComponent } from 'react'; import { Context } from '../context/context'; import { User } from "@mancala/core"; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import Space from './Space'; import { useTranslation } from 'react-i18next'; diff --git a/frontend/src/components/board/StoreView.tsx b/frontend/src/components/board/StoreView.tsx index db5dd3d..a195096 100644 --- a/frontend/src/components/board/StoreView.tsx +++ b/frontend/src/components/board/StoreView.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import { FunctionComponent } from "react"; import { Context } from "../../context/context"; -import { getColorByBrightness } from "../../util/ColorUtil"; +import { getColorByBrightness } from "@mancala/core"; import Util from "../../util/Util"; import PitViewModel from "../../viewmodel/PitViewModel"; import StoneView from "./StoneView"; diff --git a/frontend/src/routes/GamePage.tsx b/frontend/src/routes/GamePage.tsx index 3db4aa0..4fd91df 100644 --- a/frontend/src/routes/GamePage.tsx +++ b/frontend/src/routes/GamePage.tsx @@ -22,7 +22,7 @@ import { Context } from '../context/context'; import useWindowDimensions from '../hooks/useWindowDimensions'; import { GameMove, LoadingState, Game, GameUsersConnectionInfo } from "@mancala/core"; import { Theme } from '@mancala/core'; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import BoardViewModel from '../viewmodel/BoardViewModel'; import Center from '../components/Center'; import notyf from '../util/Notyf'; diff --git a/frontend/src/routes/Home.tsx b/frontend/src/routes/Home.tsx index e219d52..09da876 100644 --- a/frontend/src/routes/Home.tsx +++ b/frontend/src/routes/Home.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import { FunctionComponent, useEffect, useState } from "react"; -import { getColorByBrightness } from "../util/ColorUtil"; +import { getColorByBrightness } from "@mancala/core"; import { Theme } from "@mancala/core"; import HeaderBar from "../components/headerbar/HeaderBar"; import PageContainer from "../components/PageContainer"; diff --git a/frontend/src/routes/LobyPage.tsx b/frontend/src/routes/LobyPage.tsx index b114688..94923a8 100644 --- a/frontend/src/routes/LobyPage.tsx +++ b/frontend/src/routes/LobyPage.tsx @@ -13,7 +13,7 @@ import Row from '../components/Row'; import { channel_cancel_new_game, channel_on_game_start } from '@mancala/core'; import { Context } from '../context/context'; import { Theme } from '@mancala/core'; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import Button from "../components/Button"; import { useTranslation } from 'react-i18next'; diff --git a/frontend/src/routes/PrivacyPage.tsx b/frontend/src/routes/PrivacyPage.tsx index 0170b48..a5096e0 100644 --- a/frontend/src/routes/PrivacyPage.tsx +++ b/frontend/src/routes/PrivacyPage.tsx @@ -9,7 +9,7 @@ import PageContainer from '../components/PageContainer'; import Row from '../components/Row'; import { Context } from '../context/context'; import { Theme } from '@mancala/core'; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import { useTranslation } from 'react-i18next'; const PrivacyPage: FunctionComponent<{ diff --git a/frontend/src/util/ColorUtil.ts b/frontend/src/util/ColorUtil.ts deleted file mode 100644 index b19a362..0000000 --- a/frontend/src/util/ColorUtil.ts +++ /dev/null @@ -1,31 +0,0 @@ - -export function getBrightness(r: number, g: number, b: number) { - return (r * 299 + g * 587 + b * 114) / 1000; -} - -export function getBrightnessFromHexColor(hexColor: string): number { - const [r, g, b] = hexToRgb(hexColor); - return getBrightness(r, g, b); -} - -// from https://www.codegrepper.com/code-examples/javascript/javascript+convert+color+string+to+rgb -export function rgbToHex(r: number, g: number, b: number): string { - return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1); -} - -// from https://www.codegrepper.com/code-examples/javascript/javascript+convert+color+string+to+rgb -export function hexToRgb( - hex: string, - result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) -): number[] { - return result ? result.map((i) => parseInt(i, 16)).slice(1) : null; - //returns [23, 14, 45] -> reformat if needed -} - -export function getColorByBrightness( - color: string, - lightColor: string, - darkColor: string -): string { - return getBrightnessFromHexColor(color) < 125 ? darkColor : lightColor; -} diff --git a/mobile/src/App.tsx b/mobile/src/App.tsx index 405b33b..0b96a68 100644 --- a/mobile/src/App.tsx +++ b/mobile/src/App.tsx @@ -15,7 +15,7 @@ import { NativeModules, I18nManager, Platform } from 'react-native' // https://github.com/uuidjs/uuid/issues/514#issuecomment-691475020 import 'react-native-get-random-values'; import HelpScreen from './screens/HelpScreen'; -import { getColorByBrightness } from './util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import { server } from './const/config'; const Stack = createNativeStackNavigator(); diff --git a/mobile/src/animation/PitAnimator.ts b/mobile/src/animation/PitAnimator.ts index 054aa38..bdbe700 100644 --- a/mobile/src/animation/PitAnimator.ts +++ b/mobile/src/animation/PitAnimator.ts @@ -12,9 +12,8 @@ import { v4 } from "uuid"; import { Context } from "../context/context"; import BoardViewModelFactory from "../factory/BoardViewModelFactory"; import { PitViewModelFactory } from "../factory/PitViewModelFactory"; -import { Game } from "@mancala/core"; -import { Theme } from "../theme/Theme"; -import { getColorByBrightness } from "../util/ColorUtil"; +import { Game, Theme } from "@mancala/core"; +import { getColorByBrightness } from "@mancala/core"; import BoardViewModel from "../viewmodel/BoardViewModel"; const animationUpdateInterval = 300; diff --git a/mobile/src/components/Button.tsx b/mobile/src/components/Button.tsx index 3cfa3bc..fb8a7a0 100644 --- a/mobile/src/components/Button.tsx +++ b/mobile/src/components/Button.tsx @@ -1,7 +1,7 @@ import * as React from "react"; import { FunctionComponent } from "react"; import { Context } from "../context/context"; -import { getColorByBrightness } from "../util/ColorUtil"; +import { getColorByBrightness } from "@mancala/core"; import { Pressable, View } from "react-native"; const Button: FunctionComponent<{ diff --git a/mobile/src/components/InfoPanel.tsx b/mobile/src/components/InfoPanel.tsx index 2aba88a..eb5680f 100644 --- a/mobile/src/components/InfoPanel.tsx +++ b/mobile/src/components/InfoPanel.tsx @@ -2,7 +2,7 @@ import * as React from "react"; import { FunctionComponent } from "react"; import { Context } from "../context/context"; import { Game, User} from "@mancala/core"; -import { getColorByBrightness } from "../util/ColorUtil"; +import { getColorByBrightness } from "@mancala/core"; import CircularPanel from "./CircularPanel"; import { useTranslation } from "react-i18next"; import { Text, View, ViewStyle } from "react-native"; diff --git a/mobile/src/components/LoadingComponent.tsx b/mobile/src/components/LoadingComponent.tsx index 3275a15..d53acbb 100644 --- a/mobile/src/components/LoadingComponent.tsx +++ b/mobile/src/components/LoadingComponent.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { FunctionComponent } from 'react'; import { Context } from '../context/context'; import { LoadingState } from "@mancala/core"; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import CircularPanel from './CircularPanel'; import { useTranslation } from 'react-i18next'; import { Text } from 'react-native'; diff --git a/mobile/src/components/PageContainer.tsx b/mobile/src/components/PageContainer.tsx index 5a3afbc..0d1fa76 100644 --- a/mobile/src/components/PageContainer.tsx +++ b/mobile/src/components/PageContainer.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import { FunctionComponent } from "react"; -import { Theme } from "../theme/Theme"; +import { Theme } from "@mancala/core"; import { Context } from "../context/context"; import { View } from "react-native"; diff --git a/mobile/src/components/UserStatus.tsx b/mobile/src/components/UserStatus.tsx index 24d8e65..e7a6dd6 100644 --- a/mobile/src/components/UserStatus.tsx +++ b/mobile/src/components/UserStatus.tsx @@ -2,9 +2,9 @@ import * as React from 'react'; import { FunctionComponent } from 'react'; import { Context } from '../context/context'; import { User } from "@mancala/core"; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import Space from './Space'; -import { Theme } from '../theme/Theme'; +import { Theme } from "@mancala/core"; import { StyleSheet, Text, View, ViewStyle } from 'react-native'; import { useTranslation } from 'react-i18next'; diff --git a/mobile/src/components/board/StoreView.tsx b/mobile/src/components/board/StoreView.tsx index 4f526cd..a1e5e51 100644 --- a/mobile/src/components/board/StoreView.tsx +++ b/mobile/src/components/board/StoreView.tsx @@ -1,10 +1,8 @@ import * as React from "react"; import { FunctionComponent } from "react"; import { Context } from "../../context/context"; -import { getColorByBrightness } from "../../util/ColorUtil"; -import Util from "../../util/Util"; +import { getColorByBrightness } from "@mancala/core"; import PitViewModel from "../../viewmodel/PitViewModel"; -import StoneView from "./StoneView"; import { Text, View, ViewStyle } from "react-native"; const StoreView: FunctionComponent<{ diff --git a/mobile/src/screens/GameScreen.tsx b/mobile/src/screens/GameScreen.tsx index 6854011..075900f 100644 --- a/mobile/src/screens/GameScreen.tsx +++ b/mobile/src/screens/GameScreen.tsx @@ -9,7 +9,7 @@ import { MancalaGame, Pit } from 'mancala.js'; import { v4 } from 'uuid'; import PitAnimator from '../animation/PitAnimator'; import { channel_on_game_update, channel_on_game_crashed, channel_on_game_user_leave, channel_on_user_connection_change, channel_listen_game_events, channel_unlisten_game_events, channel_leave_game, channel_game_move } from '@mancala/core'; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import Util from '../util/Util'; import Snackbar from 'react-native-snackbar'; import PageContainer from '../components/PageContainer'; diff --git a/mobile/src/screens/HomeScreen.tsx b/mobile/src/screens/HomeScreen.tsx index 47dbcd7..fc74379 100644 --- a/mobile/src/screens/HomeScreen.tsx +++ b/mobile/src/screens/HomeScreen.tsx @@ -5,7 +5,7 @@ import { HomeScreenProps } from '../types'; import CircularPanel from '../components/CircularPanel'; import { SvgXml } from 'react-native-svg'; import helpSvg from '../svg/help'; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; export function HomeScreen({ navigation, route }: HomeScreenProps) { diff --git a/mobile/src/screens/LobyScreen.tsx b/mobile/src/screens/LobyScreen.tsx index 4c52f3d..83faa6c 100644 --- a/mobile/src/screens/LobyScreen.tsx +++ b/mobile/src/screens/LobyScreen.tsx @@ -6,7 +6,7 @@ import { useEffect } from 'react'; import { CommonMancalaGame } from 'mancala.js'; import { channel_cancel_new_game, channel_on_game_start } from '@mancala/core'; import CircularPanel from '../components/CircularPanel'; -import { getColorByBrightness } from '../util/ColorUtil'; +import { getColorByBrightness } from "@mancala/core"; import { SvgXml } from 'react-native-svg'; import helpSvg from '../svg/help';