powergrid-viewer 2.0.9 → 2.0.10
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/package.json
CHANGED
package/src/components/Game.vue
CHANGED
|
@@ -766,6 +766,7 @@ import { LogMove } from 'powergrid-engine/src/log';
|
|
|
766
766
|
import { Phase, playerTimeUsed, PowerPlant, PowerPlantType, ResourceType } from 'powergrid-engine/src/gamestate';
|
|
767
767
|
import { City } from 'powergrid-engine/src/maps';
|
|
768
768
|
import { formatDuration } from '../util/time';
|
|
769
|
+
import { playerOrderForDisplay } from '../util/player-order';
|
|
769
770
|
|
|
770
771
|
// Portrait layout: the rows the scene is broken into, top to bottom. Slots on
|
|
771
772
|
// the same row sit side by side and share one scale. Names map to the `slotX`
|
|
@@ -2355,19 +2356,7 @@ export default class Game extends Vue {
|
|
|
2355
2356
|
}
|
|
2356
2357
|
|
|
2357
2358
|
get adjustedPlayerOrder() {
|
|
2358
|
-
|
|
2359
|
-
return [];
|
|
2360
|
-
}
|
|
2361
|
-
|
|
2362
|
-
if (!this.preferences.adjustPlayerOrder) {
|
|
2363
|
-
return this.G.players.map((_p, i) => i); // 0 1 2 3 ...
|
|
2364
|
-
}
|
|
2365
|
-
|
|
2366
|
-
if (this.G.phase == Phase.Auction) {
|
|
2367
|
-
return this.G.playerOrder;
|
|
2368
|
-
}
|
|
2369
|
-
|
|
2370
|
-
return this.G.playerOrder.reverse();
|
|
2359
|
+
return playerOrderForDisplay(this.G, this.preferences.adjustPlayerOrder);
|
|
2371
2360
|
}
|
|
2372
2361
|
|
|
2373
2362
|
getResourceResupply() {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// `Phase` comes from the package root (the built `dist`), never from
|
|
2
|
+
// `powergrid-engine/src/gamestate`: webpack 4 parses the engine SOURCE for the
|
|
3
|
+
// unit-test bundle and dies on its `??`. Game.vue can import the source because the
|
|
4
|
+
// app build does not; a file with a spec beside it cannot.
|
|
5
|
+
import type { GameState } from 'powergrid-engine';
|
|
6
|
+
import { Phase } from 'powergrid-engine';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The order the player boards are stacked in (`Game.vue`'s `adjustedPlayerOrder`).
|
|
10
|
+
*
|
|
11
|
+
* Two different orders sit on this board and they are easy to confuse -- the issue
|
|
12
|
+
* that produced this file (#141) was exactly that confusion:
|
|
13
|
+
*
|
|
14
|
+
* - TABLE order: where a player sits. Fixed for the whole game. This is what the
|
|
15
|
+
* boards show when the preference is off, and it is why bidding "out of turn
|
|
16
|
+
* order" is usually not a bug at all.
|
|
17
|
+
* - TURN order (`G.playerOrder`): recomputed every round from cities and largest
|
|
18
|
+
* plant. The auction runs down it; resources and building run back UP it.
|
|
19
|
+
*
|
|
20
|
+
* Kept out of the component so it can be tested against a real engine state, the
|
|
21
|
+
* same way `util/resource-rows.ts` is -- and because the component version could not
|
|
22
|
+
* be tested at all, which is how it stayed wrong.
|
|
23
|
+
*
|
|
24
|
+
* Written without optional chaining: webpack 4 parses the unit-test bundle and
|
|
25
|
+
* rejects `?.` (same note as `util/turn-buffer.ts`).
|
|
26
|
+
*/
|
|
27
|
+
export function playerOrderForDisplay(G: GameState | null | undefined, adjustPlayerOrder: boolean): number[] {
|
|
28
|
+
if (!G) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!adjustPlayerOrder) {
|
|
33
|
+
return G.players.map((_p, i) => i); // 0 1 2 3 ...
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Copy before reversing. `Array.reverse` works in place, so reading the order off
|
|
37
|
+
// the state used to rewrite it -- see `player-order.spec.ts`. The engine already
|
|
38
|
+
// spreads before it reverses, in both places it walks the order backwards.
|
|
39
|
+
if (G.phase == Phase.Auction) {
|
|
40
|
+
return [...G.playerOrder];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return [...G.playerOrder].reverse();
|
|
44
|
+
}
|