[refactor] move models to core package
This commit is contained in:
parent
6c2b15070d
commit
597bb708f1
@ -1,5 +1,6 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { Game } from "../models/Game";
|
import { Game } from "@mancala/core";
|
||||||
|
import { BackendGame } from "../models/Game";
|
||||||
const crashFolder = "./crashes";
|
const crashFolder = "./crashes";
|
||||||
export class GameCrashManager {
|
export class GameCrashManager {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
@ -22,7 +23,7 @@ export class GameCrashManager {
|
|||||||
return `${year}-${month}-${date}-${hours}:${minutes}:${seconds}:${miliSeconds}`;
|
return `${year}-${month}-${date}-${hours}:${minutes}:${seconds}:${miliSeconds}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static logGameCrash(error: Error, game: Game): string {
|
public static logGameCrash(error: Error, game: BackendGame): string {
|
||||||
this.createCrashFolderIfNotExist();
|
this.createCrashFolderIfNotExist();
|
||||||
const crash = {
|
const crash = {
|
||||||
message: error.message,
|
message: error.message,
|
||||||
|
|||||||
@ -15,10 +15,11 @@ import {
|
|||||||
channel_on_user_connection_change,
|
channel_on_user_connection_change,
|
||||||
channel_unlisten_game_events
|
channel_unlisten_game_events
|
||||||
} from "@mancala/core";
|
} from "@mancala/core";
|
||||||
import { GameMove } from "../models/GameMove";
|
import { GameMove } from "@mancala/core";
|
||||||
import { GameCrashManager } from "./GameCrashManager";
|
import { GameCrashManager } from "./GameCrashManager";
|
||||||
import { MatchMaker } from "../matchmaker/MatchMaker";
|
import { MatchMaker } from "../matchmaker/MatchMaker";
|
||||||
import { Game, GameUsersConnectionInfo } from "../models/Game";
|
import { GameUsersConnectionInfo } from "@mancala/core";
|
||||||
|
import { BackendGame } from "../models/Game";
|
||||||
|
|
||||||
export class GameManager {
|
export class GameManager {
|
||||||
gameStore: GameStore;
|
gameStore: GameStore;
|
||||||
@ -82,7 +83,7 @@ export class GameManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private onGameError(game: Game, error: any) {
|
private onGameError(game: BackendGame, error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const crashFileName = GameCrashManager.logGameCrash(error, game);
|
const crashFileName = GameCrashManager.logGameCrash(error, game);
|
||||||
console.info(`Game crash saved to file : ${crashFileName}`);
|
console.info(`Game crash saved to file : ${crashFileName}`);
|
||||||
@ -118,18 +119,18 @@ export class GameManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkUserIdisPlayer(game: Game, userId: string): boolean {
|
private checkUserIdisPlayer(game: BackendGame, userId: string): boolean {
|
||||||
return game.mancalaGame.player1Id === userId || game.mancalaGame.player2Id === userId;
|
return game.mancalaGame.player1Id === userId || game.mancalaGame.player2Id === userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private sendMessageToPlayersAndSpectators(game: Game, channel: string, message: Object) {
|
private sendMessageToPlayersAndSpectators(game: BackendGame, channel: string, message: Object) {
|
||||||
const sendMessage = (userId: string) => this.rtmt.sendMessage(userId, channel, message);
|
const sendMessage = (userId: string) => this.rtmt.sendMessage(userId, channel, message);
|
||||||
sendMessage(game.mancalaGame.player1Id);
|
sendMessage(game.mancalaGame.player1Id);
|
||||||
sendMessage(game.mancalaGame.player2Id);
|
sendMessage(game.mancalaGame.player2Id);
|
||||||
game.spectatorIds.forEach((spectatorId) => sendMessage(spectatorId));
|
game.spectatorIds.forEach((spectatorId) => sendMessage(spectatorId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private onGameEnd(game: Game) {
|
private onGameEnd(game: BackendGame) {
|
||||||
this.deleteGame(game);
|
this.deleteGame(game);
|
||||||
game.spectatorIds = [];
|
game.spectatorIds = [];
|
||||||
}
|
}
|
||||||
@ -143,12 +144,12 @@ export class GameManager {
|
|||||||
|
|
||||||
public fireOnPlayerConnected(playerId: string) { }
|
public fireOnPlayerConnected(playerId: string) { }
|
||||||
|
|
||||||
public createMancalaGame(userKey1: string, userKey2: string): Game {
|
public createMancalaGame(userKey1: string, userKey2: string): BackendGame {
|
||||||
const mancalaGame = new CommonMancalaGame(generateKey(), userKey1, userKey2);
|
const mancalaGame = new CommonMancalaGame(generateKey(), userKey1, userKey2);
|
||||||
const random = Math.random();
|
const random = Math.random();
|
||||||
mancalaGame.turnPlayerId = random > 0.5 ? userKey1 : userKey2;
|
mancalaGame.turnPlayerId = random > 0.5 ? userKey1 : userKey2;
|
||||||
|
|
||||||
const game: Game = {
|
const game: BackendGame = {
|
||||||
id: mancalaGame.id,
|
id: mancalaGame.id,
|
||||||
mancalaGame,
|
mancalaGame,
|
||||||
gameUsersConnectionInfo: this.getGameUsersConnectionInfoFromUsers(mancalaGame.player1Id, mancalaGame.player2Id),
|
gameUsersConnectionInfo: this.getGameUsersConnectionInfoFromUsers(mancalaGame.player1Id, mancalaGame.player2Id),
|
||||||
@ -161,7 +162,7 @@ export class GameManager {
|
|||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getGameUsersConnectionInfo(game: Game): GameUsersConnectionInfo {
|
public getGameUsersConnectionInfo(game: BackendGame): GameUsersConnectionInfo {
|
||||||
return this.getGameUsersConnectionInfoFromUsers(game.mancalaGame.player1Id, game.mancalaGame.player2Id);
|
return this.getGameUsersConnectionInfoFromUsers(game.mancalaGame.player1Id, game.mancalaGame.player2Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,18 +175,18 @@ export class GameManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public startGame(game: Game) {
|
public startGame(game: BackendGame) {
|
||||||
this.sendMessageToPlayersAndSpectators(game, channel_on_game_start, game);
|
this.sendMessageToPlayersAndSpectators(game, channel_on_game_start, game);
|
||||||
this.sendUserConnectionInfo(game);
|
this.sendUserConnectionInfo(game);
|
||||||
this.sendUserConnectionInfo(game);
|
this.sendUserConnectionInfo(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
public sendUserConnectionInfo(game: Game) {
|
public sendUserConnectionInfo(game: BackendGame) {
|
||||||
const gameUsersConnectionInfo = this.getGameUsersConnectionInfo(game);
|
const gameUsersConnectionInfo = this.getGameUsersConnectionInfo(game);
|
||||||
this.sendMessageToPlayersAndSpectators(game, channel_on_user_connection_change, gameUsersConnectionInfo);
|
this.sendMessageToPlayersAndSpectators(game, channel_on_user_connection_change, gameUsersConnectionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public deleteGame(game: Game) {
|
public deleteGame(game: BackendGame) {
|
||||||
if (game) {
|
if (game) {
|
||||||
this.gameStore.removeGameByPlayer(game.mancalaGame.player1Id);
|
this.gameStore.removeGameByPlayer(game.mancalaGame.player1Id);
|
||||||
this.gameStore.removeGameByPlayer(game.mancalaGame.player2Id);
|
this.gameStore.removeGameByPlayer(game.mancalaGame.player2Id);
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
import { Game } from "../../models/Game";
|
import { Game } from "@mancala/core";
|
||||||
|
import { BackendGame } from "../../models/Game";
|
||||||
|
|
||||||
export interface GameStore {
|
export interface GameStore {
|
||||||
get(id: string): Game | undefined;
|
get(id: string): BackendGame | undefined;
|
||||||
set(id: string, game: Game): void;
|
set(id: string, game: BackendGame): void;
|
||||||
remove(id: string): void;
|
remove(id: string): void;
|
||||||
|
|
||||||
setGameIdByUser(userId: string, gameId: string): void;
|
setGameIdByUser(userId: string, gameId: string): void;
|
||||||
getGameIdByUser(userId: string): string | undefined;
|
getGameIdByUser(userId: string): string | undefined;
|
||||||
removeGameIdByPlayer(userId: string): void;
|
removeGameIdByPlayer(userId: string): void;
|
||||||
|
|
||||||
setGameByUser(userId: string, game: Game): void;
|
setGameByUser(userId: string, game: BackendGame): void;
|
||||||
getGameByUser(userId: string): Game | undefined;
|
getGameByUser(userId: string): BackendGame | undefined;
|
||||||
removeGameByPlayer(userId: string): void;
|
removeGameByPlayer(userId: string): void;
|
||||||
|
|
||||||
getSpeactatingGameIdsByUser(userId: string): string[]
|
getSpeactatingGameIdsByUser(userId: string): string[]
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
import { Game } from "../../models/Game";
|
|
||||||
import { GameStore } from "./GameStore";
|
import { GameStore } from "./GameStore";
|
||||||
|
import { BackendGame } from "../../models/Game";
|
||||||
|
|
||||||
export class GameStoreImpl implements GameStore {
|
export class GameStoreImpl implements GameStore {
|
||||||
gameStore: Map<string, Game> = new Map<string, Game>()
|
gameStore: Map<string, BackendGame> = new Map<string, BackendGame>()
|
||||||
userGameMap: Map<string, string> = new Map<string, string>()
|
userGameMap: Map<string, string> = new Map<string, string>()
|
||||||
|
|
||||||
get(id: string): Game | undefined {
|
get(id: string): BackendGame | undefined {
|
||||||
return this.gameStore.get(id);
|
return this.gameStore.get(id);
|
||||||
}
|
}
|
||||||
set(id: string, game: Game): void {
|
set(id: string, game: BackendGame): void {
|
||||||
this.gameStore.set(id, game);
|
this.gameStore.set(id, game);
|
||||||
}
|
}
|
||||||
remove(id: string): void {
|
remove(id: string): void {
|
||||||
@ -25,10 +25,10 @@ export class GameStoreImpl implements GameStore {
|
|||||||
this.userGameMap.delete(userId);
|
this.userGameMap.delete(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
setGameByUser(userId: string, game: Game): void {
|
setGameByUser(userId: string, game: BackendGame): void {
|
||||||
this.setGameIdByUser(userId, game.id);
|
this.setGameIdByUser(userId, game.id);
|
||||||
}
|
}
|
||||||
getGameByUser(userId: string): Game | undefined {
|
getGameByUser(userId: string): BackendGame | undefined {
|
||||||
const gameId = this.getGameIdByUser(userId);
|
const gameId = this.getGameIdByUser(userId);
|
||||||
return gameId && this.gameStore.get(gameId) || undefined;
|
return gameId && this.gameStore.get(gameId) || undefined;
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ export class GameStoreImpl implements GameStore {
|
|||||||
getSpeactatingGameIdsByUser(userId: string): string[] {
|
getSpeactatingGameIdsByUser(userId: string): string[] {
|
||||||
const speactatingGameIds = [];
|
const speactatingGameIds = [];
|
||||||
for (const gameId in this.gameStore.keys()) {
|
for (const gameId in this.gameStore.keys()) {
|
||||||
const game = this.gameStore.get(gameId) as Game;
|
const game = this.gameStore.get(gameId) as BackendGame;
|
||||||
const isSpectator = game.spectatorIds.find((value) => value === userId);
|
const isSpectator = game.spectatorIds.find((value) => value === userId);
|
||||||
isSpectator && speactatingGameIds.push(game.id);
|
isSpectator && speactatingGameIds.push(game.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,5 @@
|
|||||||
import { MancalaGame } from "mancala.js";
|
import { Game } from "@mancala/core";
|
||||||
import { UserConnectionInfo } from "./UserConnectionInfo";
|
|
||||||
|
|
||||||
export interface Game {
|
export interface BackendGame extends Game {
|
||||||
id: string;
|
|
||||||
mancalaGame: MancalaGame;
|
|
||||||
gameUsersConnectionInfo: GameUsersConnectionInfo;
|
|
||||||
spectatorIds: string[];
|
spectatorIds: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GameUsersConnectionInfo {
|
|
||||||
user1ConnectionInfo: UserConnectionInfo;
|
|
||||||
user2ConnectionInfo: UserConnectionInfo;
|
|
||||||
}
|
|
||||||
@ -14,6 +14,9 @@
|
|||||||
},
|
},
|
||||||
"author": "Halit Aksoy",
|
"author": "Halit Aksoy",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"mancala.js": "^0.0.2-beta.3"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.4.1",
|
"@types/jest": "^27.4.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
export * from './rtmt/channel_names'
|
export * from './rtmt/channel_names'
|
||||||
|
export * from './models/index'
|
||||||
5
core/src/models/index.ts
Normal file
5
core/src/models/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export * from './Game'
|
||||||
|
export * from './GameMove'
|
||||||
|
export * from './LoadingState'
|
||||||
|
export * from './User'
|
||||||
|
export * from './UserConnectionInfo'
|
||||||
@ -2329,6 +2329,11 @@ makeerror@1.0.12:
|
|||||||
dependencies:
|
dependencies:
|
||||||
tmpl "1.0.5"
|
tmpl "1.0.5"
|
||||||
|
|
||||||
|
mancala.js@^0.0.2-beta.3:
|
||||||
|
version "0.0.2-beta.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/mancala.js/-/mancala.js-0.0.2-beta.3.tgz#78edfa220e1a7172351a07f255eb81180845226a"
|
||||||
|
integrity sha512-LPmQ/VT4/JWFdp/YSB7k63zK7GyflApyh4M26t23a9uXFRSpBcWSePtNFpHU/xY2+1gVjlbOwQjup2QW3Tue7w==
|
||||||
|
|
||||||
merge-stream@^2.0.0:
|
merge-stream@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz"
|
resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz"
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import { v4 } from "uuid";
|
|||||||
import { Context } from "../context/context";
|
import { Context } from "../context/context";
|
||||||
import BoardViewModelFactory from "../factory/BoardViewModelFactory";
|
import BoardViewModelFactory from "../factory/BoardViewModelFactory";
|
||||||
import { PitViewModelFactory } from "../factory/PitViewModelFactory";
|
import { PitViewModelFactory } from "../factory/PitViewModelFactory";
|
||||||
import { Game } from "../models/Game";
|
import { Game } from "@mancala/core";
|
||||||
import { Theme } from "../theme/Theme";
|
import { Theme } from "../theme/Theme";
|
||||||
import { getColorByBrightness } from "../util/ColorUtil";
|
import { getColorByBrightness } from "../util/ColorUtil";
|
||||||
import BoardViewModel from "../viewmodel/BoardViewModel";
|
import BoardViewModel from "../viewmodel/BoardViewModel";
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { FunctionComponent } from "react";
|
import { FunctionComponent } from "react";
|
||||||
import { Context } from "../context/context";
|
import { Context } from "../context/context";
|
||||||
import { Game } from "../models/Game";
|
import { Game, User } from "@mancala/core";
|
||||||
import { User } from "../models/User";
|
|
||||||
import { getColorByBrightness } from "../util/ColorUtil";
|
import { getColorByBrightness } from "../util/ColorUtil";
|
||||||
import CircularPanel from "./CircularPanel";
|
import CircularPanel from "./CircularPanel";
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { FunctionComponent } from 'react';
|
import { FunctionComponent } from 'react';
|
||||||
import { Context } from '../context/context';
|
import { Context } from '../context/context';
|
||||||
import { LoadingState } from '../models/LoadingState';
|
import { LoadingState } from "@mancala/core";
|
||||||
import { getColorByBrightness } from '../util/ColorUtil';
|
import { getColorByBrightness } from '../util/ColorUtil';
|
||||||
import CircularPanel from './CircularPanel';
|
import CircularPanel from './CircularPanel';
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { FunctionComponent } from 'react';
|
import { FunctionComponent } from 'react';
|
||||||
import { Context } from '../context/context';
|
import { Context } from '../context/context';
|
||||||
import { User } from '../models/User';
|
import { User } from "@mancala/core";
|
||||||
import { getColorByBrightness } from '../util/ColorUtil';
|
import { getColorByBrightness } from '../util/ColorUtil';
|
||||||
import Space from './Space';
|
import Space from './Space';
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import BoardViewModel from "../../viewmodel/BoardViewModel";
|
|||||||
import PitViewModel from "../../viewmodel/PitViewModel";
|
import PitViewModel from "../../viewmodel/PitViewModel";
|
||||||
import PitView from "./PitView";
|
import PitView from "./PitView";
|
||||||
import StoreView from "./StoreView";
|
import StoreView from "./StoreView";
|
||||||
import { Game } from "../../models/Game";
|
import { Game } from "@mancala/core";
|
||||||
import { Pit } from "mancala.js";
|
import { Pit } from "mancala.js";
|
||||||
|
|
||||||
const BoardView: FunctionComponent<{
|
const BoardView: FunctionComponent<{
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
export interface GameMove {
|
|
||||||
index: number;
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
export interface User {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
isOnline: boolean;
|
|
||||||
isAnonymous: boolean;
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
export interface UserConnectionInfo {
|
|
||||||
userId: string;
|
|
||||||
isOnline: boolean;
|
|
||||||
}
|
|
||||||
@ -20,13 +20,11 @@ import UserStatus from '../components/UserStatus';
|
|||||||
import { channel_on_game_update, channel_on_game_crashed, channel_on_game_user_leave, channel_on_user_connection_change, channel_leave_game, channel_game_move, channel_listen_game_events, channel_unlisten_game_events } from '@mancala/core';
|
import { channel_on_game_update, channel_on_game_crashed, channel_on_game_user_leave, channel_on_user_connection_change, channel_leave_game, channel_game_move, channel_listen_game_events, channel_unlisten_game_events } from '@mancala/core';
|
||||||
import { Context } from '../context/context';
|
import { Context } from '../context/context';
|
||||||
import useWindowDimensions from '../hooks/useWindowDimensions';
|
import useWindowDimensions from '../hooks/useWindowDimensions';
|
||||||
import { GameMove } from '../models/GameMove';
|
import { GameMove, LoadingState, Game, GameUsersConnectionInfo } from "@mancala/core";
|
||||||
import { LoadingState } from '../models/LoadingState';
|
|
||||||
import { Theme } from '../theme/Theme';
|
import { Theme } from '../theme/Theme';
|
||||||
import { getColorByBrightness } from '../util/ColorUtil';
|
import { getColorByBrightness } from '../util/ColorUtil';
|
||||||
import BoardViewModel from '../viewmodel/BoardViewModel';
|
import BoardViewModel from '../viewmodel/BoardViewModel';
|
||||||
import Center from '../components/Center';
|
import Center from '../components/Center';
|
||||||
import { Game, GameUsersConnectionInfo } from '../models/Game';
|
|
||||||
import notyf from '../util/Notyf';
|
import notyf from '../util/Notyf';
|
||||||
import swal from 'sweetalert';
|
import swal from 'sweetalert';
|
||||||
import Util from '../util/Util';
|
import Util from '../util/Util';
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { CommonMancalaGame, MancalaGame } from "mancala.js";
|
import { MancalaGame } from "mancala.js";
|
||||||
import { Game } from "../models/Game";
|
import { Game } from "@mancala/core";
|
||||||
import { HttpService } from "../service/HttpService";
|
import { HttpService } from "../service/HttpService";
|
||||||
|
|
||||||
export interface GameStore {
|
export interface GameStore {
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import { v4 } from "uuid";
|
|||||||
import { Context } from "../context/context";
|
import { Context } from "../context/context";
|
||||||
import BoardViewModelFactory from "../factory/BoardViewModelFactory";
|
import BoardViewModelFactory from "../factory/BoardViewModelFactory";
|
||||||
import { PitViewModelFactory } from "../factory/PitViewModelFactory";
|
import { PitViewModelFactory } from "../factory/PitViewModelFactory";
|
||||||
import { Game } from "../models/Game";
|
import { Game } from "@mancala/core";
|
||||||
import { Theme } from "../theme/Theme";
|
import { Theme } from "../theme/Theme";
|
||||||
import { getColorByBrightness } from "../util/ColorUtil";
|
import { getColorByBrightness } from "../util/ColorUtil";
|
||||||
import BoardViewModel from "../viewmodel/BoardViewModel";
|
import BoardViewModel from "../viewmodel/BoardViewModel";
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { FunctionComponent } from "react";
|
import { FunctionComponent } from "react";
|
||||||
import { Context } from "../context/context";
|
import { Context } from "../context/context";
|
||||||
import { Game } from "../models/Game";
|
import { Game, User} from "@mancala/core";
|
||||||
import { User } from "../models/User";
|
|
||||||
import { getColorByBrightness } from "../util/ColorUtil";
|
import { getColorByBrightness } from "../util/ColorUtil";
|
||||||
import CircularPanel from "./CircularPanel";
|
import CircularPanel from "./CircularPanel";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { FunctionComponent } from 'react';
|
import { FunctionComponent } from 'react';
|
||||||
import { Context } from '../context/context';
|
import { Context } from '../context/context';
|
||||||
import { LoadingState } from '../models/LoadingState';
|
import { LoadingState } from "@mancala/core";
|
||||||
import { getColorByBrightness } from '../util/ColorUtil';
|
import { getColorByBrightness } from '../util/ColorUtil';
|
||||||
import CircularPanel from './CircularPanel';
|
import CircularPanel from './CircularPanel';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { FunctionComponent } from 'react';
|
import { FunctionComponent } from 'react';
|
||||||
import { Context } from '../context/context';
|
import { Context } from '../context/context';
|
||||||
import { User } from '../models/User';
|
import { User } from "@mancala/core";
|
||||||
import { getColorByBrightness } from '../util/ColorUtil';
|
import { getColorByBrightness } from '../util/ColorUtil';
|
||||||
import Space from './Space';
|
import Space from './Space';
|
||||||
import { Theme } from '../theme/Theme';
|
import { Theme } from '../theme/Theme';
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import BoardViewModel from "../../viewmodel/BoardViewModel";
|
|||||||
import PitViewModel from "../../viewmodel/PitViewModel";
|
import PitViewModel from "../../viewmodel/PitViewModel";
|
||||||
import PitView from "./PitView";
|
import PitView from "./PitView";
|
||||||
import StoreView from "./StoreView";
|
import StoreView from "./StoreView";
|
||||||
import { Game } from "../../models/Game";
|
import { Game } from "@mancala/core";
|
||||||
import { Pit } from "mancala.js";
|
import { Pit } from "mancala.js";
|
||||||
import { View, Dimensions } from "react-native";
|
import { View, Dimensions } from "react-native";
|
||||||
import StoneView from "./StoneView";
|
import StoneView from "./StoneView";
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
import { MancalaGame } from "mancala.js";
|
|
||||||
import { UserConnectionInfo } from "./UserConnectionInfo";
|
|
||||||
|
|
||||||
export interface Game {
|
|
||||||
id: string;
|
|
||||||
mancalaGame: MancalaGame;
|
|
||||||
gameUsersConnectionInfo: GameUsersConnectionInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GameUsersConnectionInfo {
|
|
||||||
user1ConnectionInfo: UserConnectionInfo;
|
|
||||||
user2ConnectionInfo: UserConnectionInfo;
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
export interface GameMove {
|
|
||||||
index: number;
|
|
||||||
}
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
export type LoadingStateType = "unset" | "loading" | "loaded" | "error";
|
|
||||||
|
|
||||||
export class LoadingState<T> {
|
|
||||||
state: LoadingStateType;
|
|
||||||
|
|
||||||
errorMessage?: string;
|
|
||||||
|
|
||||||
value?: T;
|
|
||||||
|
|
||||||
constructor(props: { state?: LoadingStateType, errorMessage?: string, value?: T }) {
|
|
||||||
this.state = props.state ? props.state : "unset";
|
|
||||||
this.errorMessage = props.errorMessage;
|
|
||||||
this.value = props.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Unset<T>() {
|
|
||||||
return new LoadingState<T>({ state: "unset" });
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Loading<T>() {
|
|
||||||
return new LoadingState<T>({ state: "loading" });
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Error<T>(props: { errorMessage: string }) {
|
|
||||||
const { errorMessage } = props;
|
|
||||||
return new LoadingState<T>({ state: "error", errorMessage });
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Loaded<T>(props: { value?: T }) {
|
|
||||||
const { value } = props;
|
|
||||||
return new LoadingState<T>({ state: "loaded", value });
|
|
||||||
}
|
|
||||||
|
|
||||||
public isUnset() : boolean {
|
|
||||||
return this.state === "unset";
|
|
||||||
}
|
|
||||||
public isLoading() : boolean {
|
|
||||||
return this.state === "loading";
|
|
||||||
}
|
|
||||||
public isError() : boolean {
|
|
||||||
return this.state === "error";
|
|
||||||
}
|
|
||||||
public isLoaded() : boolean {
|
|
||||||
return this.state === "loaded";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
export interface User {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
isOnline: boolean;
|
|
||||||
isAnonymous: boolean;
|
|
||||||
}
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
export interface UserConnectionInfo {
|
|
||||||
userId: string;
|
|
||||||
isOnline: boolean;
|
|
||||||
}
|
|
||||||
@ -3,14 +3,12 @@ import { View, Text, useWindowDimensions, Alert, Pressable } from 'react-native'
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { GameScreenProps } from '../types';
|
import { GameScreenProps } from '../types';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Game, GameUsersConnectionInfo } from '../models/Game';
|
import { Game, GameUsersConnectionInfo, GameMove, LoadingState } from "@mancala/core";
|
||||||
import BoardViewModel from '../viewmodel/BoardViewModel';
|
import BoardViewModel from '../viewmodel/BoardViewModel';
|
||||||
import { MancalaGame, Pit } from 'mancala.js';
|
import { MancalaGame, Pit } from 'mancala.js';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import PitAnimator from '../animation/PitAnimator';
|
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 { 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 { GameMove } from '../models/GameMove';
|
|
||||||
import { LoadingState } from '../models/LoadingState';
|
|
||||||
import { getColorByBrightness } from '../util/ColorUtil';
|
import { getColorByBrightness } from '../util/ColorUtil';
|
||||||
import Util from '../util/Util';
|
import Util from '../util/Util';
|
||||||
import Snackbar from 'react-native-snackbar';
|
import Snackbar from 'react-native-snackbar';
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { CommonMancalaGame, MancalaGame } from "mancala.js";
|
import { MancalaGame } from "mancala.js";
|
||||||
import { Game } from "../models/Game";
|
import { Game } from "@mancala/core";
|
||||||
import { HttpService } from "../service/HttpService";
|
import { HttpService } from "../service/HttpService";
|
||||||
|
|
||||||
export interface GameStore {
|
export interface GameStore {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user