powergrid-viewer 2.0.0 → 2.0.2
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/components/Game.vue +24 -3
- 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.2",
|
|
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.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/assert": "^1.4.7",
|
package/src/components/Game.vue
CHANGED
|
@@ -838,9 +838,16 @@ export default class Game extends Vue {
|
|
|
838
838
|
return;
|
|
839
839
|
}
|
|
840
840
|
if (this.G.phase == Phase.Resources && !this.canPowerAllPlants(player)) {
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
841
|
+
// India's resource market is restrictive (per-step price caps,
|
|
842
|
+
// price tiers, one purchase at a time), so a player often can't
|
|
843
|
+
// buy enough even when trying. Only warn there when they bought
|
|
844
|
+
// nothing this turn — buying some but not enough is a deliberate
|
|
845
|
+
// choice, not a slip.
|
|
846
|
+
if (this.G.map.name !== 'India' || !this.playerBoughtResourceThisTurn()) {
|
|
847
|
+
this.confirmMessage = 'Are you sure you want to skip buying resources without enough to power all your plants?';
|
|
848
|
+
this.confirmVisible = true;
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
844
851
|
}
|
|
845
852
|
|
|
846
853
|
if (
|
|
@@ -1411,6 +1418,20 @@ export default class Game extends Vue {
|
|
|
1411
1418
|
return true;
|
|
1412
1419
|
}
|
|
1413
1420
|
|
|
1421
|
+
// Whether this player has bought at least one resource during their current
|
|
1422
|
+
// resource-buying turn — i.e. the consecutive run of their own moves at the tail
|
|
1423
|
+
// of the log includes a BuyResource. (In the Resources phase only the current
|
|
1424
|
+
// player acts, so their turn is exactly that tail run.)
|
|
1425
|
+
playerBoughtResourceThisTurn(): boolean {
|
|
1426
|
+
const log = this.G!.log;
|
|
1427
|
+
for (let i = log.length - 1; i >= 0; i--) {
|
|
1428
|
+
const entry = log[i];
|
|
1429
|
+
if (entry.type !== 'move' || entry.player !== this.player) return false;
|
|
1430
|
+
if (entry.move.name === MoveName.BuyResource) return true;
|
|
1431
|
+
}
|
|
1432
|
+
return false;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1414
1435
|
toggleSound() {
|
|
1415
1436
|
const newSound = !this.preferences.sound;
|
|
1416
1437
|
|
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
|