MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / GameConfigDialog

Function GameConfigDialog

src/renderer/components/GameConfigDialog.tsx:29–202  ·  view source on GitHub ↗
(props: GameConfigDialogProps)

Source from the content-addressed store, hash-verified

27}
28
29export function GameConfigDialog(props: GameConfigDialogProps) {
30 const [editorOpen, setEditorOpen] = React.useState(false);
31 const [configCopy, setConfigCopy] = React.useState<GameConfigEdit>();
32 const [copyIdx, setCopyIdx] = React.useState(0);
33 const [validMiddleware, setValidMiddleware] = React.useState<GameMiddlewareInfo[]>([]);
34
35 React.useEffect(() => {
36 window.Shared.back.request(BackIn.GET_VALID_MIDDLEWARE, props.info.game)
37 .then(setValidMiddleware);
38 }, []);
39
40 const openEditor = async (config: GameConfig, idx: number) => {
41 // Populate config schemas
42 const pairs = config.middleware.map(m => {
43 const pair: MiddlewareVersionPair = {
44 id: m.middlewareId,
45 version: m.version
46 };
47 return pair;
48 });
49 const schemas = await window.Shared.back.request(BackIn.GET_MIDDLEWARE_CONFIG_SCHEMAS, pairs);
50 const copy: GameConfigEdit = {
51 ...deepCopy(config),
52 schemas,
53 };
54 setConfigCopy(copy);
55 setCopyIdx(idx);
56 setEditorOpen(true);
57 };
58
59 const saveConfigCopy = async () => {
60 if (configCopy) {
61 await props.saveConfig(configCopy, copyIdx);
62 }
63 setEditorOpen(false);
64 };
65
66 const newConfig = React.useCallback(() => {
67 const config: GameConfigEdit = {
68 id: null,
69 gameId: props.info.game.id,
70 name: 'New Game Configuration',
71 owner: 'local',
72 middleware: [],
73 schemas: []
74 } as any as GameConfigEdit; // Hack to let ORM set ID
75
76 setConfigCopy(config);
77 setCopyIdx(props.info.configs.length);
78 setEditorOpen(true);
79 }, [props.info.configs.length, props.info.game.id]);
80
81 // Generate rows
82 const rows = React.useMemo(() => {
83 return props.info.configs.map((c, idx) => {
84 return (
85 <div className='game-config-dialog__config' key={idx}>
86 <div className='game-config-dialog__config-row'>

Callers

nothing calls this directly

Calls 3

openEditorFunction · 0.85
mapMethod · 0.65
requestMethod · 0.45

Tested by

no test coverage detected