powergrid-viewer 2.0.0 → 2.0.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/powergrid-viewer.umd.min.js +1 -1
- package/package.json +2 -2
- package/src/launch.ts +4 -2
- package/src/util/turn-buffer.ts +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powergrid-viewer",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/boardgamers/powergrid.git",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"vue": "^2.6.11",
|
|
19
19
|
"vue-class-component": "^7.2.3",
|
|
20
20
|
"vue-property-decorator": "^8.4.2",
|
|
21
|
-
"powergrid-engine": "2.0.
|
|
21
|
+
"powergrid-engine": "2.0.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/assert": "^1.4.7",
|
package/src/launch.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { GameState, Move } from 'powergrid-engine';
|
|
|
3
3
|
import Vue from 'vue';
|
|
4
4
|
import Game from './components/Game.vue';
|
|
5
5
|
import type { Preferences } from './types/ui-data';
|
|
6
|
+
import { shouldAdoptLogState } from './util/turn-buffer';
|
|
6
7
|
|
|
7
8
|
function launch(selector: string) {
|
|
8
9
|
let params: {
|
|
@@ -67,10 +68,11 @@ function launch(selector: string) {
|
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
if (logData?.data?.state) {
|
|
71
|
+
if (shouldAdoptLogState(logData?.data?.state)) {
|
|
71
72
|
// Move responses carry the (possibly tentative) resulting state. Tentative
|
|
72
73
|
// states are never persisted or broadcast by the platform — this is the
|
|
73
|
-
// only way they reach the acting player's viewer.
|
|
74
|
+
// only way they reach the acting player's viewer. Committed states are
|
|
75
|
+
// refetched; see shouldAdoptLogState for why adopting them is unsafe.
|
|
74
76
|
params.state = logData.data.state;
|
|
75
77
|
app.$forceUpdate();
|
|
76
78
|
} else {
|
package/src/util/turn-buffer.ts
CHANGED
|
@@ -11,6 +11,28 @@ import { move as engineMove } from 'powergrid-engine';
|
|
|
11
11
|
* how an incoming state relates to that buffer and how to preview the buffer locally.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Should a state arriving on the `gamelog` channel be applied directly, rather than
|
|
16
|
+
* refetched?
|
|
17
|
+
*
|
|
18
|
+
* Only while it is TENTATIVE. That is the single reason this channel exists: tentative
|
|
19
|
+
* states are never persisted or broadcast, so the move response is the only way one can
|
|
20
|
+
* reach the acting player's viewer.
|
|
21
|
+
*
|
|
22
|
+
* A committed state is refetched instead, exactly as it was before the tentative-turn
|
|
23
|
+
* model. The same `gamelog` channel also carries the plain log fetch, and
|
|
24
|
+
* `GET /gameplay/:id/log` is not logged-in: it resolves the player with `findIndex`,
|
|
25
|
+
* which yields -1 when there is no user, and `stripSecret` then blanks EVERY player's
|
|
26
|
+
* `availableMoves`. Adopting that state left the acting player looking at a fully
|
|
27
|
+
* rendered board with nothing clickable after a page refresh, recovering only by
|
|
28
|
+
* re-entering the game. `fetchState` asks a route that knows who is asking.
|
|
29
|
+
*/
|
|
30
|
+
export function shouldAdoptLogState(state?: GameState | null): boolean {
|
|
31
|
+
// Written without optional chaining on purpose: webpack 4's parser rejects `?.` in
|
|
32
|
+
// this module under the unit-test pipeline.
|
|
33
|
+
return !!state && state.newTurn === false;
|
|
34
|
+
}
|
|
35
|
+
|
|
14
36
|
/**
|
|
15
37
|
* Compare a move echoed in a log entry with a buffered one. The engine may annotate
|
|
16
38
|
* the logged copy (`usedPlantDiscount`, `fromSupply`), so only the identity fields
|