@uzuhq/code-cli 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev-server/game-room.js +36 -16
- package/package.json +1 -1
|
@@ -162,7 +162,10 @@ export class GameRoom {
|
|
|
162
162
|
return;
|
|
163
163
|
this.seed = Date.now() & 0xffffffff;
|
|
164
164
|
this.random = new SeededRandomImpl(this.seed);
|
|
165
|
-
this.gameState = this.logic.setup(
|
|
165
|
+
this.gameState = this.logic.setup({
|
|
166
|
+
seats: this.seats,
|
|
167
|
+
ctx: { random: this.random, now: Date.now() },
|
|
168
|
+
});
|
|
166
169
|
this.stateInitialized = true;
|
|
167
170
|
this.tickCount = 0;
|
|
168
171
|
this.seq = 0;
|
|
@@ -209,14 +212,17 @@ export class GameRoom {
|
|
|
209
212
|
const tickNow = Date.now();
|
|
210
213
|
const tickDraft = new ScheduleDraft(tickNow, (a) => this.hasAction(a));
|
|
211
214
|
try {
|
|
212
|
-
this.logic.update(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
this.logic.update({
|
|
216
|
+
state: this.gameState,
|
|
217
|
+
ctx: {
|
|
218
|
+
random: this.random,
|
|
219
|
+
tick: this.tickCount,
|
|
220
|
+
now: tickNow,
|
|
221
|
+
schedule: (o) => tickDraft.schedule(o),
|
|
222
|
+
unschedule: (k) => tickDraft.unschedule(k),
|
|
223
|
+
emit,
|
|
224
|
+
playerInputs: this.playerInputs,
|
|
225
|
+
},
|
|
220
226
|
});
|
|
221
227
|
}
|
|
222
228
|
catch (err) {
|
|
@@ -385,14 +391,25 @@ export class GameRoom {
|
|
|
385
391
|
try {
|
|
386
392
|
// 決定的な部分を先に走らせ、serverActions がその結果を見られるようにする。
|
|
387
393
|
if (plain && !legacyServerOnly) {
|
|
388
|
-
plain(
|
|
394
|
+
plain({
|
|
395
|
+
state: this.gameState,
|
|
396
|
+
payload: payload ?? {},
|
|
397
|
+
playerId: senderId,
|
|
398
|
+
ctx: { now, emit, ...scheduleCtx },
|
|
399
|
+
});
|
|
389
400
|
}
|
|
390
401
|
if (serverHandler) {
|
|
391
|
-
await serverHandler(
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
402
|
+
await serverHandler({
|
|
403
|
+
state: this.gameState,
|
|
404
|
+
payload: payload ?? {},
|
|
405
|
+
playerId: senderId,
|
|
406
|
+
ctx: {
|
|
407
|
+
tick: this.tickCount,
|
|
408
|
+
random: this.random ?? new SeededRandomImpl(this.seed),
|
|
409
|
+
now,
|
|
410
|
+
emit: serverEmit,
|
|
411
|
+
...scheduleCtx,
|
|
412
|
+
},
|
|
396
413
|
});
|
|
397
414
|
}
|
|
398
415
|
}
|
|
@@ -540,7 +557,10 @@ export class GameRoom {
|
|
|
540
557
|
this.seed = opts.seed;
|
|
541
558
|
}
|
|
542
559
|
this.random = new SeededRandomImpl(this.seed);
|
|
543
|
-
this.gameState = this.logic.setup(
|
|
560
|
+
this.gameState = this.logic.setup({
|
|
561
|
+
seats: this.seats,
|
|
562
|
+
ctx: { random: this.random, now: Date.now() },
|
|
563
|
+
});
|
|
544
564
|
this.tickCount = 0;
|
|
545
565
|
// reset は新規ゲーム = 実行可能状態を意味するので pause も解除する。
|
|
546
566
|
this.tickPaused = false;
|