powergrid-viewer 1.5.4

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.
Files changed (57) hide show
  1. package/README.md +35 -0
  2. package/dist/img/help.ba7779cc.svg +1 -0
  3. package/dist/img/log.04ef6981.svg +1 -0
  4. package/dist/img/pass.da9065dc.svg +3 -0
  5. package/dist/img/rules.64f9aae5.svg +28 -0
  6. package/dist/img/sound-off.72ada995.svg +3 -0
  7. package/dist/img/sound-on.c55edd90.svg +3 -0
  8. package/dist/img/undo.208666d2.svg +3 -0
  9. package/dist/media/notification.55fa47dd.ogg +0 -0
  10. package/dist/media/notification.ac905963.mp3 +0 -0
  11. package/dist/media/piece-drop.eef5f607.mp3 +0 -0
  12. package/dist/powergrid-viewer.css +1 -0
  13. package/dist/powergrid-viewer.umd.min.js +35 -0
  14. package/package.json +49 -0
  15. package/src/audio/notification.mp3 +0 -0
  16. package/src/audio/notification.ogg +0 -0
  17. package/src/audio/piece-drop.mp3 +0 -0
  18. package/src/components/Calculator.vue +62 -0
  19. package/src/components/Game.vue +1354 -0
  20. package/src/components/PlayerBoard.vue +230 -0
  21. package/src/components/boards/CityCount.vue +82 -0
  22. package/src/components/boards/Map.vue +196 -0
  23. package/src/components/boards/PlayerOrder.vue +68 -0
  24. package/src/components/boards/PowerPlantMarket.vue +184 -0
  25. package/src/components/boards/Resources.vue +446 -0
  26. package/src/components/buttons/Button.vue +26 -0
  27. package/src/components/buttons/HelpButton.vue +18 -0
  28. package/src/components/buttons/LogButton.vue +15 -0
  29. package/src/components/buttons/PassButton.vue +18 -0
  30. package/src/components/buttons/RulesButton.vue +14 -0
  31. package/src/components/buttons/SoundButton.vue +18 -0
  32. package/src/components/buttons/UndoButton.vue +17 -0
  33. package/src/components/buttons/index.js +9 -0
  34. package/src/components/pieces/Card.vue +131 -0
  35. package/src/components/pieces/Coal.vue +40 -0
  36. package/src/components/pieces/Garbage.vue +40 -0
  37. package/src/components/pieces/House.vue +51 -0
  38. package/src/components/pieces/Hybrid.vue +37 -0
  39. package/src/components/pieces/Oil.vue +40 -0
  40. package/src/components/pieces/Piece.vue +104 -0
  41. package/src/components/pieces/Uranium.vue +32 -0
  42. package/src/components/pieces/index.js +10 -0
  43. package/src/icons/help.svg +1 -0
  44. package/src/icons/log.svg +1 -0
  45. package/src/icons/pass.svg +3 -0
  46. package/src/icons/rules.svg +28 -0
  47. package/src/icons/sound-off.svg +3 -0
  48. package/src/icons/sound-on.svg +3 -0
  49. package/src/icons/undo.svg +3 -0
  50. package/src/launch.ts +87 -0
  51. package/src/main.ts +3 -0
  52. package/src/self-contained.ts +97 -0
  53. package/src/shims-tsx.d.ts +13 -0
  54. package/src/shims-vue.d.ts +4 -0
  55. package/src/types/ui-data.ts +34 -0
  56. package/src/wrapper.ts +8 -0
  57. package/tsconfig.json +23 -0
package/src/launch.ts ADDED
@@ -0,0 +1,87 @@
1
+ import { EventEmitter } from 'events';
2
+ import type { GameState, Move } from 'powergrid-engine';
3
+ import Vue from 'vue';
4
+ import Game from './components/Game.vue';
5
+ import type { Preferences } from './types/ui-data';
6
+
7
+ function launch(selector: string) {
8
+ let params: {
9
+ state: null | GameState;
10
+ player?: number;
11
+ emitter: EventEmitter;
12
+ preferences: Preferences;
13
+ avatars: string[];
14
+ } = {
15
+ state: null,
16
+ emitter: new EventEmitter(),
17
+ preferences: {
18
+ sound: true,
19
+ disableHelp: false,
20
+ adjustPlayerOrder: false,
21
+ undoWholeTurn: true,
22
+ fitToScreen: true,
23
+ },
24
+ avatars: [],
25
+ };
26
+
27
+ const app = new Vue({
28
+ render: (h) => h(Game, { props: params }, []),
29
+ }).$mount(selector);
30
+
31
+ const item: EventEmitter = new EventEmitter();
32
+ let replaying = false;
33
+
34
+ params.emitter.on('move', (move: Move) => item.emit('move', move));
35
+ params.emitter.on('fetchState', () => item.emit('fetchState'));
36
+ params.emitter.on('addLog', (data: string[]) => item.emit('addLog', data));
37
+ params.emitter.on('replaceLog', (data: string[]) => item.emit('replaceLog', data));
38
+ params.emitter.on('replay:info', (info: { start: number; current: number; end: number }) =>
39
+ item.emit('replay:info', info)
40
+ );
41
+ params.emitter.on('update:preference', (data: { name: string; value: any }) =>
42
+ item.emit('update:preference', data)
43
+ );
44
+ item.addListener('avatars', (data) => {
45
+ params.avatars = data;
46
+ app.$forceUpdate();
47
+ });
48
+
49
+ item.addListener('state', (data) => {
50
+ params.state = data;
51
+ app.$forceUpdate();
52
+ app.$nextTick().then(() => item.emit('ready'));
53
+ });
54
+ item.addListener('state:updated', () => item.emit('fetchState'));
55
+ item.addListener('player', (data) => {
56
+ params.player = data.index;
57
+ app.$forceUpdate();
58
+ });
59
+ item.addListener('preferences', (data) => {
60
+ params.preferences = { ...params.preferences, ...data };
61
+ app.$forceUpdate();
62
+ });
63
+ item.addListener('gamelog', (_) => {
64
+ if (replaying) {
65
+ return;
66
+ }
67
+
68
+ item.emit('fetchState');
69
+ });
70
+
71
+ item.addListener('replay:start', () => {
72
+ params.emitter.emit('replayStart');
73
+ replaying = true;
74
+ });
75
+ item.addListener('replay:to', (info) => {
76
+ params.emitter.emit('replayTo', info);
77
+ });
78
+ item.addListener('replay:end', () => {
79
+ params.emitter.emit('replayEnd');
80
+ replaying = false;
81
+ item.emit('fetchState');
82
+ });
83
+
84
+ return item;
85
+ }
86
+
87
+ export default launch;
package/src/main.ts ADDED
@@ -0,0 +1,3 @@
1
+ import launchSelfContained from './self-contained';
2
+
3
+ launchSelfContained();
@@ -0,0 +1,97 @@
1
+ import { cloneDeep } from 'lodash';
2
+ import { move as execMove, Move, Phase, setup, stripSecret } from 'powergrid-engine';
3
+ import { moveAI } from 'powergrid-engine/src/engine';
4
+ import launch from './launch';
5
+
6
+ const delayBase = 0;
7
+
8
+ function launchSelfContained(selector = '#app') {
9
+ const strip = true;
10
+
11
+ const emitter = launch(selector);
12
+
13
+ let gameState = setup(3, { map: 'Brazil', variant: 'original', showMoney: true, randomizeMap: true }, '3');
14
+
15
+ // gameState.map.viewBox = [1480, 1060];
16
+ // gameState.map.playerOrderPosition = [1160, 140];
17
+ // gameState.map.cityCountPosition = [0, 0];
18
+ // gameState.map.powerPlantMarketPosition = [745, 0];
19
+ // gameState.map.mapPosition = [0, 100];
20
+ // gameState.map.buttonsPosition = [1305, 0];
21
+ // gameState.map.playerBoardsPosition = [1105, 200];
22
+ // gameState.map.roundInfoPosition = [20, 590];
23
+ // gameState.map.supplyPosition = [0, 720];
24
+
25
+ // gameState.map.adjustRatio = [1, 1];
26
+ // gameState.map.cities = gameState.map.cities.map(city => ({
27
+ // ...city,
28
+ // x: city.x * gameState.map.adjustRatio![0],
29
+ // y: city.y * gameState.map.adjustRatio![1]
30
+ // }));
31
+
32
+ // gameState.map.cities = gameState.map.cities.map(city => ({
33
+ // ...city,
34
+ // x: city.y,
35
+ // y: 600 - city.x
36
+ // }));
37
+
38
+ for (let i = 0; i < gameState.players.length; i++) {
39
+ gameState.players[i].name = `Player ${i + 1}`;
40
+ }
41
+
42
+ let playerIndex = 1;
43
+
44
+ for (const player of gameState.players) {
45
+ if (player.id != playerIndex) player.isAI = true;
46
+ }
47
+
48
+ emitter.on('move', async (move: Move) => {
49
+ setTimeout(() => {
50
+ console.log('move received', move);
51
+ gameState = execMove(gameState, move, playerIndex);
52
+ console.log('new game state', gameState);
53
+
54
+ emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
55
+
56
+ let delay = delayBase;
57
+ const moveAIAux = () => {
58
+ if (gameState.players.some((pl) => pl.isAI && pl.availableMoves)) {
59
+ gameState = moveAI(
60
+ gameState,
61
+ gameState.players.findIndex((pl) => pl.isAI && pl.availableMoves)
62
+ );
63
+ let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
64
+ console.log('new game state', newState);
65
+ emitter.emit('state', newState);
66
+ setTimeout(moveAIAux, gameState.phase == Phase.Bureaucracy ? delay : 0);
67
+ }
68
+ };
69
+
70
+ setTimeout(moveAIAux, gameState.phase == Phase.Bureaucracy ? delay : 0);
71
+
72
+ console.log('available moves', gameState.players[playerIndex].availableMoves);
73
+ }, 100);
74
+ });
75
+
76
+ emitter.on('fetchState', () => {
77
+ emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
78
+ });
79
+
80
+ emitter.emit('player', { index: playerIndex });
81
+ emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
82
+
83
+ let delay = delayBase;
84
+ while (gameState.players.some((pl) => pl.isAI && pl.availableMoves)) {
85
+ gameState = moveAI(
86
+ gameState,
87
+ gameState.players.findIndex((pl) => pl.isAI && pl.availableMoves)
88
+ );
89
+ let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
90
+ setTimeout(() => emitter.emit('state', newState), delay);
91
+ delay += delayBase;
92
+ }
93
+
94
+ console.log('available moves', gameState.players[playerIndex].availableMoves);
95
+ }
96
+
97
+ export default launchSelfContained;
@@ -0,0 +1,13 @@
1
+ import Vue, { VNode } from 'vue';
2
+
3
+ declare global {
4
+ namespace JSX {
5
+ // tslint:disable no-empty-interface
6
+ interface Element extends VNode {}
7
+ // tslint:disable no-empty-interface
8
+ interface ElementClass extends Vue {}
9
+ interface IntrinsicElements {
10
+ [elem: string]: any;
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,4 @@
1
+ declare module '*.vue' {
2
+ import Vue from 'vue';
3
+ export default Vue;
4
+ }
@@ -0,0 +1,34 @@
1
+ import { PowerPlant } from 'powergrid-engine/src/gamestate';
2
+
3
+ export interface UIData {
4
+ waitingAnimations: number;
5
+ }
6
+
7
+ export type Preferences = {
8
+ sound: boolean;
9
+ disableHelp: boolean;
10
+ adjustPlayerOrder: boolean;
11
+ undoWholeTurn: boolean;
12
+ fitToScreen: boolean;
13
+ };
14
+
15
+ export interface Piece {
16
+ id: string;
17
+ x: number;
18
+ y: number;
19
+ owner?: number;
20
+ ownerName?: string;
21
+ color?: string;
22
+ powerPlant?: PowerPlant;
23
+ transparent?: boolean;
24
+ }
25
+
26
+ export enum PieceType {
27
+ House,
28
+ Card,
29
+ Coal,
30
+ Oil,
31
+ Garbage,
32
+ Uranium,
33
+ Hybrid,
34
+ }
package/src/wrapper.ts ADDED
@@ -0,0 +1,8 @@
1
+ // Import vue component
2
+ import launch from './launch';
3
+
4
+ if (typeof window !== 'undefined') {
5
+ (window as any).powergrid = { launch };
6
+ }
7
+
8
+ export default launch;
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "esnext",
5
+ "strict": true,
6
+ "jsx": "preserve",
7
+ "importHelpers": true,
8
+ "moduleResolution": "node",
9
+ "experimentalDecorators": true,
10
+ "esModuleInterop": true,
11
+ "allowSyntheticDefaultImports": true,
12
+ "noImplicitAny": false,
13
+ "sourceMap": true,
14
+ "baseUrl": ".",
15
+ "types": ["webpack-env", "mocha", "chai"],
16
+ "paths": {
17
+ "@/*": ["src/*"]
18
+ },
19
+ "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
20
+ },
21
+ "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
22
+ "exclude": ["node_modules"]
23
+ }