Skip to content

Commit df08780

Browse files
committed
game.tsを分割して整理
1 parent 73ce72e commit df08780

11 files changed

Lines changed: 1276 additions & 1179 deletions

File tree

packages/web/src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { getUsers } from "./fetchAPI";
1212
import type { User } from "./component/Emulator";
1313
import { useApiPasswordContext } from "./common/api-password";
1414
import ApiPasswordDialog from "./component/ApiPasswordDialog";
15+
import options from "./options";
1516

1617
export default function App() {
1718
const [currentUser, setCurrentUser] = useState({
@@ -47,7 +48,7 @@ export default function App() {
4748
setIsApiPasswordDialogOpen(true);
4849
}}
4950
/>
50-
<Injection workspaceRef={workspaceRef} />
51+
<Injection workspaceRef={workspaceRef} options={options} />
5152
</Box>
5253
{password && (
5354
<>

packages/web/src/component/Emulator.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useRef } from "react";
2-
import Game from "./game";
3-
import type { Result } from "./game";
2+
import type { Result } from "./game/game";
3+
import TutorialGame from "./tutorial/tutorialGames";
4+
import Game from "./game/game";
45

56
export interface User {
67
name: string;
@@ -26,6 +27,7 @@ type EmulatorProps = {
2627
executionId: number; // エミュレーターそのものを更新するためのId
2728
handleStatuses: (statuses: Status[]) => void;
2829
onGameCompleted?: (result: Result) => void;
30+
gameModeId: number;
2931
};
3032

3133
export default function Emulator(props: EmulatorProps) {
@@ -38,19 +40,35 @@ export default function Emulator(props: EmulatorProps) {
3840
executionId,
3941
handleStatuses,
4042
onGameCompleted,
43+
gameModeId,
4144
} = props;
4245
const canvasRef = useRef<HTMLCanvasElement>(null);
43-
const gameRef = useRef<Game>();
46+
const gameRef = useRef<any>();
4447
useEffect(() => {
4548
if (!canvasRef.current) throw new Error();
46-
const game = new Game(users, canvasRef.current, (newStatuses: Status[]) => {
47-
handleStatuses(newStatuses);
48-
});
49+
let GameClass;
50+
switch (gameModeId) {
51+
case 0:
52+
GameClass = Game;
53+
break;
54+
case 1:
55+
GameClass = TutorialGame;
56+
break;
57+
default:
58+
GameClass = Game;
59+
}
60+
const game = new GameClass(
61+
users,
62+
canvasRef.current,
63+
(newStatuses: Status[]) => {
64+
handleStatuses(newStatuses);
65+
}
66+
);
4967
gameRef.current = game;
5068
return () => {
5169
game.destroy();
5270
};
53-
}, [users, executionId, handleStatuses]);
71+
}, [users, executionId, handleStatuses, gameModeId]);
5472
useEffect(() => {
5573
if (!gameRef.current) throw new Error();
5674
gameRef.current.onCompleted = (result: Result) => {

packages/web/src/component/Injection.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import Blockly from "blockly";
55
import Ja from "blockly/msg/ja";
66
import "../style.css";
77
import { Box } from "@mui/material";
8-
import options from "../options";
98
import modifyTranslation from "../modifyTranslation";
109

1110
/* eslint-disable @typescript-eslint/no-explicit-any */
@@ -16,9 +15,11 @@ import modifyTranslation from "../modifyTranslation";
1615

1716
export default function Injection(props: {
1817
workspaceRef: React.MutableRefObject<Blockly.WorkspaceSvg | undefined>;
18+
options: any;
1919
}) {
2020
const { workspaceRef } = props;
2121
const workspaceDivRef = useRef<HTMLDivElement>(null);
22+
const { options } = props;
2223
useEffect(() => {
2324
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2425
// @ts-ignore
@@ -28,7 +29,7 @@ export default function Injection(props: {
2829
return () => {
2930
workspace.dispose();
3031
};
31-
}, [workspaceRef]);
32+
}, [workspaceRef, options]);
3233

3334
return <Box ref={workspaceDivRef} sx={{ width: 1, height: 1 }} />;
3435
}

packages/web/src/component/TestPlay.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { grey } from "@mui/material/colors";
2929
import { HiOutlineScale } from "react-icons/hi";
3030
import Draggable from "react-draggable";
3131
import Emulator, { Status } from "./Emulator";
32-
import type { User } from "./game";
32+
import type { User } from "./game/game";
3333
import { getUsers } from "../fetchAPI";
3434

3535
interface EnemyDialogProps {
@@ -264,6 +264,7 @@ export default function TestPlay(props: TestPlayProps) {
264264
isPaused={isPaused}
265265
executionId={executionId}
266266
handleStatuses={setStatuses}
267+
gameModeId={0}
267268
/>
268269
) : (
269270
<Skeleton width="100%" height="auto" />

0 commit comments

Comments
 (0)