[add] first
This commit is contained in:
45
src/context/GameItemsContext.tsx
Normal file
45
src/context/GameItemsContext.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import { BusinessEnum } from "@/_BusinessTypeSetting/BusinessTypeSetting";
|
||||
import { IGameItems } from "@/types";
|
||||
import { LineTools } from "@/utils/LineTools";
|
||||
import { ReactNode, createContext, useContext, useState } from "react";
|
||||
|
||||
type GameItemsProviderProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
const GameItemsContext = createContext<IGameItems>(undefined);
|
||||
|
||||
export function useGameItems() {
|
||||
return useContext(GameItemsContext);
|
||||
}
|
||||
export let gameObj: IGameItems = null;
|
||||
|
||||
export function GameItemsProvider({ children }: GameItemsProviderProps) {
|
||||
const [gameId, setGameId] = useState<number>(null);
|
||||
|
||||
const game: IGameItems = gameObj = {
|
||||
onLoad,
|
||||
gameId,
|
||||
setGameId
|
||||
};
|
||||
|
||||
async function onLoad(serverType: BusinessEnum.ServerType) {
|
||||
await Promise.all([
|
||||
// // 設定執行環境
|
||||
// setBusinessType(),
|
||||
|
||||
// // 設定LineTools環境
|
||||
// await setLineTools(),
|
||||
]);
|
||||
}
|
||||
|
||||
/** 設定LineTools環境 */
|
||||
async function setLineTools() {
|
||||
await LineTools.onLoad();
|
||||
}
|
||||
|
||||
return (
|
||||
<GameItemsContext.Provider value={game}>
|
||||
{children}
|
||||
</GameItemsContext.Provider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user