Skip to content

Commit

Permalink
fix: differentiate prod and dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
anan474 committed May 24, 2024
1 parent b908a3f commit 46a6832
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
3 changes: 0 additions & 3 deletions docs/vocs.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,5 @@ export default defineConfig({
resolve: {
alias: [resolver],
},
server: {
hmr: false,
},
},
});
59 changes: 37 additions & 22 deletions hera/hooks/useClientGameAction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Action, MutateActionResponseFn } from '@deities/apollo/Action.tsx';
import { ActionResponse } from '@deities/apollo/ActionResponse.tsx';
import encodeGameActionResponse from '@deities/apollo/actions/encodeGameActionResponse.tsx';
import executeGameAction from '@deities/apollo/actions/executeGameAction.tsx';
import {
decodeEffects,
Effects,
Expand All @@ -24,15 +25,14 @@ import {
import { PlainMap } from '@deities/athena/map/PlainMap.tsx';
import MapData from '@deities/athena/MapData.tsx';
import { getHiddenLabels } from '@deities/athena/WinConditions.tsx';
import AIRegistry from '@deities/dionysus/AIRegistry.tsx';
import onGameEnd from '@deities/hermes/game/onGameEnd.tsx';
import toClientGame, {
ClientGame,
} from '@deities/hermes/game/toClientGame.tsx';
import { useCallback } from 'react';
import EvaluationWorker from '../editor/workers/evaluation?worker';

Check failure on line 34 in hera/hooks/useClientGameAction.tsx

View workflow job for this annotation

GitHub Actions / action (22, ubuntu-latest)

Unable to resolve path to module '../editor/workers/evaluation?worker'

var worker = new EvaluationWorker();

const ActionError = (action: Action) =>
new Error(`Map: Error executing remote '${action.type}' action.`);

Expand Down Expand Up @@ -62,27 +62,42 @@ export default function useClientGameAction(
}

try {
const [
encodedActionResponse,
plainMap,
encodedGameState,
encodedEffects,
] = await new Promise<
[EncodedActionResponse, PlainMap, EncodedGameState, EncodedEffects]
>((resolve) => {
worker.postMessage([
map.toJSON(),
encodeEffects(game.effects),
action,
mutateAction,
]);
worker.onmessage = (event) => resolve(event.data);
});
// In production run evaluation using async worker,
// Not supported in development mode yet, see : https://github.com/vitejs/vite/issues/5396
if (import.meta.env.PROD) {
var worker = new EvaluationWorker();

Check failure on line 68 in hera/hooks/useClientGameAction.tsx

View workflow job for this annotation

GitHub Actions / action (22, ubuntu-latest)

Unexpected var, use let or const instead
const [
encodedActionResponse,
plainMap,
encodedGameState,
encodedEffects,
] = await new Promise<
[EncodedActionResponse, PlainMap, EncodedGameState, EncodedEffects]
>((resolve) => {
worker.postMessage([
map.toJSON(),
encodeEffects(game.effects),
action,
mutateAction,
]);
worker.onmessage = (event) => resolve(event.data);
});

actionResponse = decodeActionResponse(encodedActionResponse);
initialActiveMap = MapData.fromObject(plainMap);
gameState = decodeGameState(encodedGameState);
newEffects = decodeEffects(encodedEffects);
actionResponse = decodeActionResponse(encodedActionResponse);
initialActiveMap = MapData.fromObject(plainMap);
gameState = decodeGameState(encodedGameState);
newEffects = decodeEffects(encodedEffects);
} else {
[actionResponse, initialActiveMap, gameState, newEffects] =
executeGameAction(
map,
vision,
game.effects,
action,
AIRegistry,
mutateAction,
) || [null, null, null];
}
} catch (error) {
return Promise.reject(

Check failure on line 102 in hera/hooks/useClientGameAction.tsx

View workflow job for this annotation

GitHub Actions / action (22, ubuntu-latest)

Prefer `throw error` over `return Promise.reject(error)`
process.env.NODE_ENV === 'development' ? error : ActionError(action),
Expand Down

0 comments on commit 46a6832

Please sign in to comment.