[add] 進機台
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import MainControlData from "@/Common/DataReceived/MainControlData";
|
||||
import MainControl from "@/Common/MainControl/MainControl";
|
||||
import BusinessTypeSetting, { BusinessEnum } from "@/_BusinessTypeSetting/BusinessTypeSetting";
|
||||
import { GameData } from "@/define/gameData";
|
||||
import { PlayerData } from "@/define/playerData";
|
||||
import { IGameItems } from "@/types";
|
||||
import { ReactNode, createContext, useContext, useState } from "react";
|
||||
@@ -15,21 +17,20 @@ export function useGameItems() {
|
||||
export let gameObj: IGameItems = null;
|
||||
|
||||
export function GameItemsProvider({ children }: GameItemsProviderProps) {
|
||||
const [gameId, setGameId] = useState<number>(null);
|
||||
const [player, setPlayer] = useState<PlayerData>({
|
||||
token: "",
|
||||
});
|
||||
const [player, setPlayer] = useState<PlayerData>(initPlayerData());
|
||||
const [gameData, setGameData] = useState<GameData>(initGameData());
|
||||
|
||||
const game: IGameItems = gameObj = {
|
||||
onLoad,
|
||||
gameId,
|
||||
setGameId,
|
||||
player,
|
||||
setPlayer
|
||||
setPlayer,
|
||||
gameData,
|
||||
setGameData
|
||||
};
|
||||
|
||||
async function onLoad(serverType: BusinessEnum.ServerType) {
|
||||
new MainControl();
|
||||
new MainControlData();
|
||||
await Promise.all([
|
||||
// 設定執行環境
|
||||
setBusinessType(serverType),
|
||||
@@ -88,3 +89,27 @@ export function GameItemsProvider({ children }: GameItemsProviderProps) {
|
||||
</GameItemsContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function initPlayerData(): PlayerData {
|
||||
return {
|
||||
token: undefined,
|
||||
aId: undefined,
|
||||
f: undefined,
|
||||
r: undefined,
|
||||
rf: undefined,
|
||||
name: undefined,
|
||||
a: undefined,
|
||||
m: 0,
|
||||
lp: undefined,
|
||||
tr: undefined,
|
||||
lct: undefined
|
||||
};
|
||||
}
|
||||
|
||||
function initGameData(): GameData {
|
||||
return {
|
||||
slotData: [],
|
||||
slotList: [],
|
||||
nowSlotId: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user