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

Function launchCb

src/back/GameLauncher.ts:173–211  ·  view source on GitHub ↗
(launchInfo: GameLaunchInfo)

Source from the content-addressed store, hash-verified

171 }
172 // Launch game callback
173 const launchCb = async (launchInfo: GameLaunchInfo): Promise<void> => {
174 /**
175 * Order
176 * - API listeners
177 * - Middleware
178 * - Handle game data params
179 */
180 await onWillEvent.fire(launchInfo)
181 .then(async () => {
182 // Handle middleware
183 if (launchInfo.activeConfig) {
184 log.info(logSource, `Using Game Configuration: ${launchInfo.activeConfig.name}`);
185 for (const middlewareConfig of launchInfo.activeConfig.middleware) {
186 // Find middleware in registry
187 const middleware = opts.state.registry.middlewares.get(middlewareConfig.middlewareId);
188 if (!middleware) {
189 throw `Middleware not found (${middlewareConfig.middlewareId})`;
190 }
191 try {
192 launchInfo = await Promise.resolve(middleware.execute(launchInfo, middlewareConfig));
193 } catch (err) {
194 throw `Failed to execute middleware (${middlewareConfig.middlewareId}) - ${err}`;
195 }
196 // @TODO - Validate launch info
197 }
198 log.info(logSource, 'Applied Game Configuration Successfully.');
199 }
200 await handleGameDataParams(opts, serverOverride, launchInfo.activeData ? launchInfo.activeData : undefined);
201 const command: string = createCommand(launchInfo.launchInfo);
202 const managedProc = opts.runGame(launchInfo);
203 log.info(logSource,`Launch Game "${opts.game.title}" (PID: ${managedProc.getPid()}) [\n`+
204 ` applicationPath: "${launchInfo.launchInfo.gamePath}",\n`+
205 ` launchCommand: "${metadataLaunchCommand}",\n`+
206 ` command: "${command}" ]`);
207 })
208 .catch((error) => {
209 log.info('Game Launcher', `Game Launch Aborted: ${error}`);
210 });
211 };
212 // Launch game
213 const metadataAppPath = gameData ? gameData.applicationPath : opts.game.legacyApplicationPath;
214 const metadataLaunchCommand = gameData ? gameData.launchCommand : opts.game.legacyLaunchCommand;

Callers 1

launchGameFunction · 0.85

Calls 6

handleGameDataParamsFunction · 0.85
getMethod · 0.80
getPidMethod · 0.80
createCommandFunction · 0.70
fireMethod · 0.65
executeMethod · 0.65

Tested by

no test coverage detected