Skip to content

Commit 998464b

Browse files
committed
special funcs -> side effects
1 parent 0d2b4ba commit 998464b

File tree

5 files changed

+67
-45
lines changed

5 files changed

+67
-45
lines changed

games/game1-v2.3.0/ui/src/Board.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import "./index.css";
22

33
import { Trans } from "@lingui/macro";
44
import classNames from "classnames";
5-
import type { RollGame, RollGameState } from "game1-v2.3.0-game";
65

76
import type { UserId } from "@lefun/core";
87
import {
@@ -13,6 +12,8 @@ import {
1312
useUsername,
1413
} from "@lefun/ui";
1514

15+
import type { RollGame, RollGameState } from "game1-v2.3.0-game";
16+
1617
// Dice symbol characters
1718
const DICE = ["", "\u2680", "\u2681", "\u2682", "\u2683", "\u2684", "\u2685"];
1819

packages/dev-server/src/App.tsx

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { createRoot } from "react-dom/client";
1111
import { createStore as _createStore } from "zustand";
1212

1313
import type { Locale, MatchSettings, UserId, UsersState } from "@lefun/core";
14-
import { Game } from "@lefun/game";
14+
import { Game, MoveSideEffects } from "@lefun/game";
1515
import { setMakeMove, Store, storeContext } from "@lefun/ui";
1616

1717
import {
@@ -111,6 +111,31 @@ const BoardForPlayer = ({
111111
}
112112
}
113113

114+
const sideEffects: MoveSideEffects = {
115+
delayMove() {
116+
console.warn("delayMove not implemented yet");
117+
return { ts: 0 };
118+
},
119+
endMatch() {
120+
//
121+
},
122+
logPlayerStat() {
123+
//
124+
},
125+
logMatchStat() {
126+
//
127+
},
128+
turns: {
129+
begin() {
130+
console.warn("turns.begin not implemented");
131+
return { expiresAt: 0 };
132+
},
133+
end() {
134+
//
135+
},
136+
},
137+
};
138+
114139
if (executeNow) {
115140
// Optimistic update directly on the `store` of the player making the move.
116141
store.setState((state: MatchState) => {
@@ -121,28 +146,8 @@ const BoardForPlayer = ({
121146
board,
122147
playerboard,
123148
payload,
124-
delayMove: () => {
125-
console.warn("delayMove not implemented yet");
126-
return { ts: 0 };
127-
},
128-
turns: {
129-
begin() {
130-
console.warn("turns.begin() not implemented yet");
131-
return { expiresAt: 0 };
132-
},
133-
end() {
134-
console.warn("turns.end() not implemented yet");
135-
},
136-
},
137-
endMatch() {
138-
console.warn("endMatch not implemented");
139-
},
140-
logPlayerStat() {
141-
console.warn("logPlayerStat not implemented");
142-
},
143-
logMatchStat() {
144-
console.warn("logMatchStat not implemented");
145-
},
149+
_: sideEffects,
150+
...sideEffects,
146151
});
147152
});
148153
return newState;

packages/dev-server/src/match.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
User,
99
UserId,
1010
} from "@lefun/core";
11-
import { Game, GameStateBase, Random } from "@lefun/game";
11+
import { Game, GameStateBase, MoveSideEffects, Random } from "@lefun/game";
1212

1313
type State = {
1414
board: unknown;
@@ -155,6 +155,31 @@ class Match extends EventTarget {
155155
);
156156
patchesByUserId["spectator"] = [];
157157

158+
const sideEffects: MoveSideEffects = {
159+
delayMove() {
160+
console.warn("delayMove not implemented yet");
161+
return { ts: 0 };
162+
},
163+
endMatch() {
164+
console.warn("endMatch not implemented");
165+
},
166+
logPlayerStat() {
167+
console.warn("logPlayerStat not implemented");
168+
},
169+
logMatchStat() {
170+
console.warn("logMatchStat not implemented");
171+
},
172+
turns: {
173+
begin() {
174+
console.warn("turns.begin not implemented");
175+
return { expiresAt: 0 };
176+
},
177+
end() {
178+
console.warn("turns.end not implemented");
179+
},
180+
},
181+
};
182+
158183
if (executeNow) {
159184
// Also run `executeNow` on the local state.
160185
this.store.setState((state: State) => {
@@ -170,10 +195,8 @@ class Match extends EventTarget {
170195
userId,
171196
board,
172197
playerboard: playerboards[userId],
173-
delayMove: () => {
174-
console.warn("delayMove not implemented yet");
175-
return { ts: 0 };
176-
},
198+
_: sideEffects,
199+
...sideEffects,
177200
});
178201
},
179202
);
@@ -211,19 +234,8 @@ class Match extends EventTarget {
211234
gameData,
212235
random,
213236
ts: now,
214-
delayMove: () => {
215-
console.warn("delayMove not implemented yet");
216-
return { ts: 0 };
217-
},
218-
endMatch: () => {
219-
console.warn("todo implement endMatch");
220-
},
221-
itsYourTurn: () => {
222-
console.warn("todo implement itsYourTurn");
223-
},
224-
logStat: () => {
225-
console.warn("todo implement logStats");
226-
},
237+
_: sideEffects,
238+
...sideEffects,
227239
});
228240
},
229241
);

packages/game/src/gameDef.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export type LogMatchStat<MS extends GameStats> = (
103103
value: number,
104104
) => void;
105105

106-
export type SpecialFuncs<
106+
export type MoveSideEffects<
107107
PMT extends MoveTypesBase = MoveTypesBase,
108108
BMT extends MoveTypesBase = MoveTypesBase,
109109
PS extends GameStats = GameStats,
@@ -130,7 +130,8 @@ type ExecuteNowOptions<
130130
// Assume that the game developer has defined the playerboard if they're using it.
131131
playerboard: GS["PB"];
132132
payload: P;
133-
} & SpecialFuncs<PMT, BMT, PS, MS>;
133+
_: MoveSideEffects<PMT, BMT, PS, MS>;
134+
} & MoveSideEffects<PMT, BMT, PS, MS>;
134135

135136
export type ExecuteNow<
136137
GS extends GameStateBase = GameStateBase,
@@ -163,7 +164,8 @@ export type ExecuteOptions<
163164
ts: number;
164165
gameData: any;
165166
matchData?: any;
166-
} & SpecialFuncs<PMT, BMT, PS, MS>;
167+
_: MoveSideEffects<PMT, BMT, PS, MS>;
168+
} & MoveSideEffects<PMT, BMT, PS, MS>;
167169

168170
export type Execute<
169171
GS extends GameStateBase = GameStateBase,

packages/game/src/testing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ export class MatchTester<
679679
board,
680680
playerboard,
681681
payload,
682+
_: specialExecuteFuncs,
682683
...specialExecuteFuncs,
683684
});
684685
}
@@ -693,6 +694,7 @@ export class MatchTester<
693694
payload,
694695
random,
695696
ts: time,
697+
_: specialExecuteFuncs,
696698
...specialExecuteFuncs,
697699
});
698700
}

0 commit comments

Comments
 (0)