pacman-contribution-graph 1.0.0 → 1.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.
@@ -12,68 +12,66 @@ __webpack_require__.r(__webpack_exports__);
12
12
  /* harmony export */ });
13
13
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
14
14
  /* harmony import */ var _music_player__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./music-player */ "./src/music-player.ts");
15
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store */ "./src/store.ts");
16
- /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
17
-
15
+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
18
16
 
19
17
 
20
18
 
21
- const resizeCanvas = () => {
19
+ const resizeCanvas = (store) => {
22
20
  const canvasWidth = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
23
21
  const canvasHeight = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 20; // Adding some space for months on top
24
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width = canvasWidth;
25
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.height = canvasHeight;
22
+ store.config.canvas.width = canvasWidth;
23
+ store.config.canvas.height = canvasHeight;
26
24
  };
27
- const drawGrid = () => {
28
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getCurrentTheme().gridBackground;
29
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillRect(0, 0, _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width, _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.height);
25
+ const drawGrid = (store) => {
26
+ store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).gridBackground;
27
+ store.config.canvas.getContext('2d').fillRect(0, 0, store.config.canvas.width, store.config.canvas.height);
30
28
  for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT; x++) {
31
29
  for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; y++) {
32
- const intensity = _store__WEBPACK_IMPORTED_MODULE_2__.Store.grid[x][y];
30
+ const intensity = store.grid[x][y].intensity;
33
31
  if (intensity > 0) {
34
32
  const adjustedIntensity = intensity < 0.2 ? 0.3 : intensity;
35
- const color = _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.hexToRGBA(_utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getCurrentTheme().contributionBoxColor, adjustedIntensity);
36
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = color;
33
+ const color = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.hexToRGBA(_utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).contributionBoxColor, adjustedIntensity);
34
+ store.config.canvas.getContext('2d').fillStyle = color;
37
35
  }
38
36
  else {
39
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getCurrentTheme().emptyContributionBoxColor;
37
+ store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).emptyContributionBoxColor;
40
38
  }
41
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
42
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas
39
+ store.config.canvas.getContext('2d').beginPath();
40
+ store.config.canvas
43
41
  .getContext('2d')
44
42
  .roundRect(y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE), x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15, _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE, _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE, 5);
45
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
43
+ store.config.canvas.getContext('2d').fill();
46
44
  }
47
45
  }
48
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getCurrentTheme().textColor;
49
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').font = '10px Arial';
50
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').textAlign = 'center';
46
+ store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).textColor;
47
+ store.config.canvas.getContext('2d').font = '10px Arial';
48
+ store.config.canvas.getContext('2d').textAlign = 'center';
51
49
  let lastMonth = '';
52
50
  for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; y++) {
53
- if (_store__WEBPACK_IMPORTED_MODULE_2__.Store.monthLabels[y] !== lastMonth) {
51
+ if (store.monthLabels[y] !== lastMonth) {
54
52
  const xPos = y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
55
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillText(_store__WEBPACK_IMPORTED_MODULE_2__.Store.monthLabels[y], xPos, 10);
56
- lastMonth = _store__WEBPACK_IMPORTED_MODULE_2__.Store.monthLabels[y];
53
+ store.config.canvas.getContext('2d').fillText(store.monthLabels[y], xPos, 10);
54
+ lastMonth = store.monthLabels[y];
57
55
  }
58
56
  }
59
57
  };
60
- const drawPacman = () => {
61
- const x = _store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
62
- const y = _store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2 + 15;
58
+ const drawPacman = (store) => {
59
+ const x = store.pacman.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
60
+ const y = store.pacman.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2 + 15;
63
61
  const radius = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
64
62
  // Change Pac-Man's color to red if he's on power-up, dead, else yellow
65
- if (_store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.deadReaminingDuration) {
66
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_DEAD;
63
+ if (store.pacman.deadRemainingDuration) {
64
+ store.config.canvas.getContext('2d').fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_DEAD;
67
65
  }
68
- else if (_store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.powerupReaminingDuration) {
69
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_POWERUP;
66
+ else if (store.pacman.powerupRemainingDuration) {
67
+ store.config.canvas.getContext('2d').fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_POWERUP;
70
68
  }
71
69
  else {
72
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR;
70
+ store.config.canvas.getContext('2d').fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR;
73
71
  }
74
- const mouthAngle = _store__WEBPACK_IMPORTED_MODULE_2__.Store.pacmanMouthOpen ? 0.35 * Math.PI : 0.1 * Math.PI;
72
+ const mouthAngle = store.pacmanMouthOpen ? 0.35 * Math.PI : 0.1 * Math.PI;
75
73
  let startAngle, endAngle;
76
- switch (_store__WEBPACK_IMPORTED_MODULE_2__.Store.pacman.direction) {
74
+ switch (store.pacman.direction) {
77
75
  case 'up':
78
76
  startAngle = 1.5 * Math.PI + mouthAngle;
79
77
  endAngle = 1.5 * Math.PI - mouthAngle;
@@ -92,83 +90,74 @@ const drawPacman = () => {
92
90
  endAngle = 2 * Math.PI - mouthAngle;
93
91
  break;
94
92
  }
95
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
96
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x, y, radius, startAngle, endAngle);
97
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(x, y);
98
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
93
+ store.config.canvas.getContext('2d').beginPath();
94
+ store.config.canvas.getContext('2d').arc(x, y, radius, startAngle, endAngle);
95
+ store.config.canvas.getContext('2d').lineTo(x, y);
96
+ store.config.canvas.getContext('2d').fill();
99
97
  };
100
- const drawGhosts = () => {
101
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.ghosts.forEach((ghost) => {
102
- const x = ghost.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
103
- const y = ghost.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2 + 15;
104
- const radius = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
105
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = ghost.scared ? 'blue' : ghost.color;
106
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
107
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x, y, radius, 0, Math.PI);
108
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').rect(x - radius, y, radius * 2, radius);
109
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
110
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = 'white';
111
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
112
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x - radius / 3, y - radius / 3, radius / 4, 0, Math.PI * 2);
113
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x + radius / 3, y - radius / 3, radius / 4, 0, Math.PI * 2);
114
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
115
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = 'black';
116
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
117
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x - radius / 3, y - radius / 3, radius / 8, 0, Math.PI * 2);
118
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(x + radius / 3, y - radius / 3, radius / 8, 0, Math.PI * 2);
119
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
98
+ const drawGhosts = (store) => {
99
+ store.ghosts.forEach((ghost) => {
100
+ const x = ghost.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
101
+ const y = ghost.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
102
+ const size = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE;
103
+ const ctx = store.config.canvas.getContext('2d');
104
+ if (ghost.scared) {
105
+ ctx.drawImage(_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['scared'].img, x, y, size, size);
106
+ }
107
+ else {
108
+ ctx.drawImage(_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS[ghost.name].img, x, y, size, size);
109
+ }
120
110
  });
121
111
  };
122
- const renderGameOver = () => {
123
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = 'black';
124
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').font = '20px Arial';
125
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').textAlign = 'center';
126
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillText('Game Over', _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width / 2, _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.height / 2);
112
+ const renderGameOver = (store) => {
113
+ store.config.canvas.getContext('2d').fillStyle = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).textColor;
114
+ store.config.canvas.getContext('2d').font = '20px Arial';
115
+ store.config.canvas.getContext('2d').textAlign = 'center';
116
+ store.config.canvas.getContext('2d').fillText('Game Over', store.config.canvas.width / 2, store.config.canvas.height / 2);
127
117
  };
128
- const drawSoundController = () => {
129
- if (!_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.enableSounds) {
130
- console.log('vvvv');
118
+ const drawSoundController = (store) => {
119
+ if (!store.config.enableSounds) {
131
120
  return;
132
121
  }
133
- const width = 30, height = 30, left = _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width - width - 10, top = 10;
134
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fillStyle = `rgba(0, 0, 0, ${_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted ? 0.3 : 0.5})`;
135
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
136
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').moveTo(left + 10, top + 10);
137
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(left + 20, top + 5);
138
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(left + 20, top + 25);
139
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(left + 10, top + 20);
140
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').closePath();
141
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').fill();
122
+ const width = 30, height = 30, left = store.config.canvas.width - width - 10, top = 10;
123
+ store.config.canvas.getContext('2d').fillStyle = `rgba(0, 0, 0, ${_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted ? 0.3 : 0.5})`;
124
+ store.config.canvas.getContext('2d').beginPath();
125
+ store.config.canvas.getContext('2d').moveTo(left + 10, top + 10);
126
+ store.config.canvas.getContext('2d').lineTo(left + 20, top + 5);
127
+ store.config.canvas.getContext('2d').lineTo(left + 20, top + 25);
128
+ store.config.canvas.getContext('2d').lineTo(left + 10, top + 20);
129
+ store.config.canvas.getContext('2d').closePath();
130
+ store.config.canvas.getContext('2d').fill();
142
131
  if (!_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted) {
143
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').strokeStyle = `rgba(0, 0, 0, 0.4)`;
144
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineWidth = 2;
132
+ store.config.canvas.getContext('2d').strokeStyle = `rgba(0, 0, 0, 0.4)`;
133
+ store.config.canvas.getContext('2d').lineWidth = 2;
145
134
  // First wave
146
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
147
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(left + 25, top + 15, 5, 0, Math.PI * 2);
148
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').stroke();
135
+ store.config.canvas.getContext('2d').beginPath();
136
+ store.config.canvas.getContext('2d').arc(left + 25, top + 15, 5, 0, Math.PI * 2);
137
+ store.config.canvas.getContext('2d').stroke();
149
138
  // Second wave
150
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
151
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').arc(left + 25, top + 15, 8, 0, Math.PI * 2);
152
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').stroke();
139
+ store.config.canvas.getContext('2d').beginPath();
140
+ store.config.canvas.getContext('2d').arc(left + 25, top + 15, 8, 0, Math.PI * 2);
141
+ store.config.canvas.getContext('2d').stroke();
153
142
  }
154
143
  else {
155
144
  // Mute line
156
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').strokeStyle = 'rgba(255, 0, 0, 0.6)';
157
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineWidth = 3;
158
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').beginPath();
159
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').moveTo(left + 25, top + 5);
160
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').lineTo(left + 5, top + 25);
161
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getContext('2d').stroke();
145
+ store.config.canvas.getContext('2d').strokeStyle = 'rgba(255, 0, 0, 0.6)';
146
+ store.config.canvas.getContext('2d').lineWidth = 3;
147
+ store.config.canvas.getContext('2d').beginPath();
148
+ store.config.canvas.getContext('2d').moveTo(left + 25, top + 5);
149
+ store.config.canvas.getContext('2d').lineTo(left + 5, top + 25);
150
+ store.config.canvas.getContext('2d').stroke();
162
151
  }
163
152
  };
164
- const listenToSoundController = () => {
165
- if (!_store__WEBPACK_IMPORTED_MODULE_2__.Store.config.enableSounds) {
153
+ const listenToSoundController = (store) => {
154
+ if (!store.config.enableSounds) {
166
155
  return;
167
156
  }
168
- _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.addEventListener('click', function (event) {
169
- const rect = _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.getBoundingClientRect();
157
+ store.config.canvas.addEventListener('click', function (event) {
158
+ const rect = store.config.canvas.getBoundingClientRect();
170
159
  const x = event.clientX - rect.left, y = event.clientY - rect.top;
171
- const width = 30, height = 30, left = _store__WEBPACK_IMPORTED_MODULE_2__.Store.config.canvas.width - width - 10, top = 10;
160
+ const width = 30, height = 30, left = store.config.canvas.width - width - 10, top = 10;
172
161
  if (x >= left && x <= left + this.width && y >= top && y <= top + this.height) {
173
162
  if (_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted) {
174
163
  _music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().unmute();
@@ -204,7 +193,8 @@ __webpack_require__.r(__webpack_exports__);
204
193
  /* harmony export */ DELTA_TIME: () => (/* binding */ DELTA_TIME),
205
194
  /* harmony export */ GAME_THEMES: () => (/* binding */ GAME_THEMES),
206
195
  /* harmony export */ GAP_SIZE: () => (/* binding */ GAP_SIZE),
207
- /* harmony export */ GHOST_COLORS: () => (/* binding */ GHOST_COLORS),
196
+ /* harmony export */ GHOSTS: () => (/* binding */ GHOSTS),
197
+ /* harmony export */ GHOST_NAMES: () => (/* binding */ GHOST_NAMES),
208
198
  /* harmony export */ GRID_HEIGHT: () => (/* binding */ GRID_HEIGHT),
209
199
  /* harmony export */ GRID_WIDTH: () => (/* binding */ GRID_WIDTH),
210
200
  /* harmony export */ MONTHS: () => (/* binding */ MONTHS),
@@ -221,7 +211,7 @@ const GRID_HEIGHT = 7;
221
211
  const PACMAN_COLOR = 'yellow';
222
212
  const PACMAN_COLOR_POWERUP = 'red';
223
213
  const PACMAN_COLOR_DEAD = '#80808064';
224
- const GHOST_COLORS = ['red', 'pink', 'cyan', 'orange'];
214
+ const GHOST_NAMES = ['blinky', 'clyde', 'inky', 'pinky'];
225
215
  const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
226
216
  const DELTA_TIME = 250;
227
217
  const PACMAN_DEATH_DURATION = 10;
@@ -252,6 +242,28 @@ const GAME_THEMES = {
252
242
  emptyContributionBoxColor: '#2d2d2d'
253
243
  }
254
244
  };
245
+ const GHOSTS = {
246
+ blinky: {
247
+ imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAfUlEQVQ4T+2TUQ7AIAhDy/0PzQIRAqxmLtnn/DJPWypBAVkKKOMCyOQN7IRElLrcnIrDLNK4wVtxNbkb6Hq+jOcSbim6QVzKEstkw92gxVeFrMpqokix4wA+NvCOnvfArvcEbHoe2G9QmmhDMUc65p3xYC6q3zQPxtdl3NgF5QpL/b/rs3IAAAAASUVORK5CYIIA',
248
+ img: new Image()
249
+ },
250
+ clyde: {
251
+ imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAgUlEQVQ4T+2T0Q6AIAhFLx9sH1MfTIPCAeLKrcd8PHqP4JBQLN7BFacNlHkAs+AQcqIueBs2mVWjgtWwl4yCdrd/pHYLLlVEgR2yK0wy4SoI5TcGXU4wM+AEJQfwsUCuXngDOR4rqKbngf0C94gyFHmkbd4rbkxD/pv2jfR1Ky7sBNrzXbHpnBX+AAAAAElFTkSuQmCC',
252
+ img: new Image()
253
+ },
254
+ inky: {
255
+ imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAg0lEQVQ4T+WTWxKAIAhFuQvK/a+jFoT5QAVxypn+6vMEx6sDIO/jk12OAMs1WDVOXV3UBW+bRVbTFMFu8yCZBExH/g26VHCXI0AJpKgdUCUrTlkwxE+FECdzS7HiJemXgvyeO29gE7jD8wDVFX4vSLNtR1q2z+OVlaZxTaXYrq7HbxYBS8VgMVrqzkEAAAAASUVORK5CYIIA',
256
+ img: new Image()
257
+ },
258
+ pinky: {
259
+ imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAhklEQVQ4T+2T0Q2AIAwF281wC50Qt9DNagoptqVESfyUz4N3vJCCECxaD4o47gt6bsAo2IWUqAnehkUmbYpgNqwlvSCnur+dtnnAuYUVyCGJimTAi8DUzwmwOoGI7hYjDgAfC/jqiTfg47ZBND0P7BeoR+Sh8CMt8x5xYSWkv2nbcF834swuA/9u49Yy5bgAAAAASUVORK5CYIIA',
260
+ img: new Image()
261
+ },
262
+ scared: {
263
+ imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAeUlEQVQ4T82TUQ6AMAhD7UX0/sdyF0GREVmDmTN+bH9r6Bs0A0t2VpFULwDrrfBkZFcA3YC3ZodViAFGzQHyP0B2w2NrB0/1AoDbHwLoQ5/nrw1OBuD5e/crbM9Aiz35njHWzpSB/m3+0r40mV41M8U19WJe3Uw/tQOKt08pUUbBEQAAAABJRU5ErkJgggAA',
264
+ img: new Image()
265
+ }
266
+ };
255
267
 
256
268
 
257
269
  /***/ }),
@@ -269,8 +281,7 @@ __webpack_require__.r(__webpack_exports__);
269
281
  /* harmony import */ var _canvas__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./canvas */ "./src/canvas.ts");
270
282
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
271
283
  /* harmony import */ var _music_player__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./music-player */ "./src/music-player.ts");
272
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./store */ "./src/store.ts");
273
- /* harmony import */ var _svg__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./svg */ "./src/svg.ts");
284
+ /* harmony import */ var _svg__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./svg */ "./src/svg.ts");
274
285
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
275
286
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
276
287
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -284,28 +295,29 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
284
295
 
285
296
 
286
297
 
287
-
288
- const initializeGrid = () => {
289
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid = Array.from({ length: _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT }, () => Array.from({ length: _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH }, () => 0));
290
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.monthLabels = Array(_constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH).fill('');
298
+ const initializeGrid = (store) => {
299
+ store.pacman.points = 0;
300
+ store.pacman.totalPoints = 0;
301
+ store.grid = Array.from({ length: _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT }, () => Array.from({ length: _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH }, () => ({ commitsCount: 0, intensity: 0 })));
302
+ store.monthLabels = Array(_constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH).fill('');
291
303
  let maxCommits = 1;
292
304
  const now = new Date();
293
305
  const startOfCurrentWeek = new Date(now);
294
306
  startOfCurrentWeek.setDate(now.getDate() - now.getDay());
295
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.contributions.forEach((contribution) => {
307
+ store.contributions.forEach((contribution) => {
296
308
  const contributionDate = new Date(contribution.date);
297
309
  const dayOfWeek = contributionDate.getDay();
298
310
  const weeksAgo = Math.floor((+startOfCurrentWeek - +contributionDate) / (1000 * 60 * 60 * 24 * 7));
299
311
  if (weeksAgo >= 0 && weeksAgo < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH && dayOfWeek >= 0 && dayOfWeek < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT) {
300
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[dayOfWeek][_constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH - 1 - weeksAgo] = contribution.count;
312
+ store.grid[dayOfWeek][_constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH - 1 - weeksAgo] = { commitsCount: contribution.count, intensity: 0 };
301
313
  if (contribution.count > maxCommits)
302
314
  maxCommits = contribution.count;
303
315
  }
304
316
  });
305
317
  for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT; x++) {
306
318
  for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH; y++) {
307
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] > 0) {
308
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] = _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] / maxCommits;
319
+ if (store.grid[x][y].commitsCount > 0) {
320
+ store.grid[x][y].intensity = store.grid[x][y].commitsCount / maxCommits;
309
321
  }
310
322
  }
311
323
  }
@@ -313,156 +325,163 @@ const initializeGrid = () => {
313
325
  const weeksAgo = _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH - 1 - y;
314
326
  const columnDate = new Date(startOfCurrentWeek);
315
327
  columnDate.setDate(columnDate.getDate() - weeksAgo * 7);
316
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.monthLabels[y] = _constants__WEBPACK_IMPORTED_MODULE_1__.MONTHS[columnDate.getMonth()];
328
+ store.monthLabels[y] = _constants__WEBPACK_IMPORTED_MODULE_1__.MONTHS[columnDate.getMonth()];
317
329
  }
318
330
  };
319
- const placePacman = () => {
331
+ const placePacman = (store) => {
320
332
  let validCells = [];
321
333
  for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT; x++) {
322
334
  for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH; y++) {
323
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] > 0)
335
+ if (store.grid[x][y].intensity > 0)
324
336
  validCells.push({ x, y });
325
337
  }
326
338
  }
327
339
  if (validCells.length > 0) {
328
340
  const randomCell = validCells[Math.floor(Math.random() * validCells.length)];
329
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman = {
341
+ store.pacman = {
330
342
  x: randomCell.x,
331
343
  y: randomCell.y,
332
344
  direction: 'right',
333
345
  points: 0,
334
- deadReaminingDuration: 0,
335
- powerupReaminingDuration: 0
346
+ totalPoints: 0,
347
+ deadRemainingDuration: 0,
348
+ powerupRemainingDuration: 0
336
349
  };
337
350
  }
338
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
339
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawPacman();
351
+ if (store.config.outputFormat == 'canvas')
352
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawPacman(store);
340
353
  };
341
- const placeGhosts = () => {
342
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts = [];
343
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.scaredGhostsDestinations = [];
344
- // Create 4 ghosts
354
+ const placeGhosts = (store) => {
355
+ store.ghosts = [];
356
+ store.scaredGhostsDestinations = [];
345
357
  for (let i = 0; i < 4; i++) {
346
- const color = _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_COLORS[i % _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_COLORS.length];
347
358
  let x, y;
348
359
  do {
349
360
  x = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT);
350
361
  y = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH);
351
- } while (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] === 0);
352
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.push({ x, y, color, scared: false, target: undefined });
353
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.scaredGhostsDestinations.push({ x: 0, y: 0 });
362
+ } while (store.grid[x][y].intensity === 0);
363
+ store.ghosts.push({ x, y, name: _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_NAMES[i], scared: false, target: undefined });
364
+ store.scaredGhostsDestinations.push({ x: 0, y: 0 });
354
365
  }
355
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
356
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGhosts();
366
+ if (store.config.outputFormat == 'canvas')
367
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGhosts(store);
357
368
  };
358
- const startGame = () => __awaiter(void 0, void 0, void 0, function* () {
359
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
360
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.config.canvas = _store__WEBPACK_IMPORTED_MODULE_3__.Store.config.canvas;
361
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.resizeCanvas();
362
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.listenToSoundController();
369
+ const stopGame = (store) => __awaiter(void 0, void 0, void 0, function* () {
370
+ clearInterval(store.gameInterval);
371
+ });
372
+ const startGame = (store) => __awaiter(void 0, void 0, void 0, function* () {
373
+ if (store.config.outputFormat == 'canvas') {
374
+ store.config.canvas = store.config.canvas;
375
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.resizeCanvas(store);
376
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.listenToSoundController(store);
363
377
  }
364
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.frameCount = 0;
365
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost) => (ghost.scared = false));
366
- initializeGrid();
367
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
368
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGrid();
369
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
370
- if (!_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.enableSounds) {
378
+ store.frameCount = 0;
379
+ store.ghosts.forEach((ghost) => (ghost.scared = false));
380
+ initializeGrid(store);
381
+ if (store.config.outputFormat == 'canvas')
382
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGrid(store);
383
+ if (store.config.outputFormat == 'canvas') {
384
+ if (!store.config.enableSounds) {
371
385
  _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().mute();
372
386
  }
373
387
  yield _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().preloadSounds();
374
388
  _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().startDefaultSound();
375
389
  yield _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.BEGINNING);
376
390
  }
377
- placePacman();
378
- placeGhosts();
379
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'svg') {
380
- const remainingCells = () => _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid.some((row) => row.some((cell) => cell > 0));
391
+ placePacman(store);
392
+ placeGhosts(store);
393
+ _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.blinky.img.src = _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.blinky.imgDate;
394
+ _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.clyde.img.src = _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.clyde.imgDate;
395
+ _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.inky.img.src = _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.inky.imgDate;
396
+ _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.pinky.img.src = _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.pinky.imgDate;
397
+ _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.scared.img.src = _constants__WEBPACK_IMPORTED_MODULE_1__.GHOSTS.scared.imgDate;
398
+ if (store.config.outputFormat == 'svg') {
399
+ const remainingCells = () => store.grid.some((row) => row.some((cell) => cell.intensity > 0));
381
400
  while (remainingCells()) {
382
- yield updateGame();
401
+ yield updateGame(store);
383
402
  }
384
403
  // One more time to generate svg
385
- yield updateGame();
404
+ yield updateGame(store);
386
405
  }
387
406
  else {
388
- clearInterval(_store__WEBPACK_IMPORTED_MODULE_3__.Store.gameInterval);
389
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.gameInterval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () { return yield updateGame(); }), _constants__WEBPACK_IMPORTED_MODULE_1__.DELTA_TIME);
407
+ clearInterval(store.gameInterval);
408
+ store.gameInterval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () { return yield updateGame(store); }), _constants__WEBPACK_IMPORTED_MODULE_1__.DELTA_TIME);
390
409
  }
391
410
  });
392
- const updateGame = () => __awaiter(void 0, void 0, void 0, function* () {
393
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.frameCount++;
394
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.frameCount % _store__WEBPACK_IMPORTED_MODULE_3__.Store.config.gameSpeed !== 0) {
395
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.gameHistory.push({
396
- pacman: Object.assign({}, _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman),
397
- ghosts: _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.map((ghost) => (Object.assign({}, ghost))),
398
- grid: _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid.map((row) => [...row])
411
+ const updateGame = (store) => __awaiter(void 0, void 0, void 0, function* () {
412
+ store.frameCount++;
413
+ if (store.frameCount % store.config.gameSpeed !== 0) {
414
+ store.gameHistory.push({
415
+ pacman: Object.assign({}, store.pacman),
416
+ ghosts: store.ghosts.map((ghost) => (Object.assign({}, ghost))),
417
+ grid: store.grid.map((row) => [...row.map((col) => col.intensity)])
399
418
  });
400
419
  return;
401
420
  }
402
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration) {
403
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration--;
404
- if (!_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration) {
421
+ if (store.pacman.deadRemainingDuration) {
422
+ store.pacman.deadRemainingDuration--;
423
+ if (!store.pacman.deadRemainingDuration) {
405
424
  // IT'S ALIVE!
406
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
425
+ if (store.config.outputFormat == 'canvas')
407
426
  _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance()
408
427
  .play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.GAME_OVER)
409
428
  .then(() => _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().startDefaultSound());
410
429
  }
411
430
  }
412
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration) {
413
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration--;
414
- if (!_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration) {
415
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost) => (ghost.scared = false));
416
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points = 0;
431
+ if (store.pacman.powerupRemainingDuration) {
432
+ store.pacman.powerupRemainingDuration--;
433
+ if (!store.pacman.powerupRemainingDuration) {
434
+ store.ghosts.forEach((ghost) => (ghost.scared = false));
435
+ store.pacman.points = 0;
417
436
  }
418
437
  }
419
- const remainingCells = _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid.some((row) => row.some((cell) => cell > 0));
438
+ const remainingCells = store.grid.some((row) => row.some((cell) => cell.intensity > 0));
420
439
  if (!remainingCells) {
421
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
422
- clearInterval(_store__WEBPACK_IMPORTED_MODULE_3__.Store.gameInterval);
423
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
424
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.renderGameOver();
440
+ if (store.config.outputFormat == 'canvas') {
441
+ clearInterval(store.gameInterval);
442
+ if (store.config.outputFormat == 'canvas') {
443
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.renderGameOver(store);
425
444
  _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance()
426
445
  .play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.BEGINNING)
427
446
  .then(() => _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().stopDefaultSound());
428
447
  }
429
448
  }
430
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'svg') {
431
- const animatedSVG = _svg__WEBPACK_IMPORTED_MODULE_4__.SVG.generateAnimatedSVG();
449
+ if (store.config.outputFormat == 'svg') {
450
+ const animatedSVG = _svg__WEBPACK_IMPORTED_MODULE_3__.SVG.generateAnimatedSVG(store);
432
451
  const svgBlob = new Blob([animatedSVG], {
433
452
  type: 'image/svg+xml;charset=utf-8'
434
453
  });
435
454
  const svgUrl = URL.createObjectURL(svgBlob);
436
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.config.svgCallback(svgUrl);
455
+ store.config.svgCallback(svgUrl);
437
456
  }
438
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.config.gameOverCallback();
457
+ store.config.gameOverCallback();
439
458
  return;
440
459
  }
441
- movePacman();
442
- moveGhosts();
443
- checkCollisions();
444
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacmanMouthOpen = !_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacmanMouthOpen;
445
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.gameHistory.push({
446
- pacman: Object.assign({}, _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman),
447
- ghosts: _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.map((ghost) => (Object.assign({}, ghost))),
448
- grid: _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid.map((row) => [...row])
460
+ movePacman(store);
461
+ moveGhosts(store);
462
+ checkCollisions(store);
463
+ store.pacmanMouthOpen = !store.pacmanMouthOpen;
464
+ store.gameHistory.push({
465
+ pacman: Object.assign({}, store.pacman),
466
+ ghosts: store.ghosts.map((ghost) => (Object.assign({}, ghost))),
467
+ grid: store.grid.map((row) => [...row.map((col) => col.intensity)])
449
468
  });
450
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
451
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGrid();
452
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
453
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawPacman();
454
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
455
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGhosts();
456
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas')
457
- _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawSoundController();
469
+ if (store.config.outputFormat == 'canvas')
470
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGrid(store);
471
+ if (store.config.outputFormat == 'canvas')
472
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawPacman(store);
473
+ if (store.config.outputFormat == 'canvas')
474
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGhosts(store);
475
+ if (store.config.outputFormat == 'canvas')
476
+ _canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawSoundController(store);
458
477
  });
459
- const movePacman = () => {
460
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration) {
478
+ const movePacman = (store) => {
479
+ if (store.pacman.deadRemainingDuration) {
461
480
  return;
462
481
  }
463
482
  let targetCells = [];
464
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration) {
465
- targetCells = _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.map((ghost) => ({
483
+ if (store.pacman.powerupRemainingDuration) {
484
+ targetCells = store.ghosts.map((ghost) => ({
466
485
  x: ghost.x,
467
486
  y: ghost.y,
468
487
  distance: Infinity
@@ -471,7 +490,7 @@ const movePacman = () => {
471
490
  else {
472
491
  for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT; x++) {
473
492
  for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH; y++) {
474
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] > 0)
493
+ if (store.grid[x][y].intensity > 0)
475
494
  targetCells.push({ x, y, distance: Infinity });
476
495
  }
477
496
  }
@@ -479,28 +498,30 @@ const movePacman = () => {
479
498
  if (targetCells.length === 0)
480
499
  return;
481
500
  const closest = targetCells.reduce((closest, cell) => {
482
- const distance = Math.abs(cell.x - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x) + Math.abs(cell.y - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y);
501
+ const distance = Math.abs(cell.x - store.pacman.x) + Math.abs(cell.y - store.pacman.y);
483
502
  return distance < closest.distance ? Object.assign(Object.assign({}, cell), { distance }) : closest;
484
- }, { x: _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x, y: _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y, distance: Infinity });
485
- const dx = closest.x - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x;
486
- const dy = closest.y - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y;
503
+ }, { x: store.pacman.x, y: store.pacman.y, distance: Infinity });
504
+ const dx = closest.x - store.pacman.x;
505
+ const dy = closest.y - store.pacman.y;
487
506
  if (Math.abs(dx) > Math.abs(dy)) {
488
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x += Math.sign(dx);
489
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.direction = dx > 0 ? 'down' : 'up';
507
+ store.pacman.x += Math.sign(dx);
508
+ store.pacman.direction = dx > 0 ? 'down' : 'up';
490
509
  }
491
510
  else {
492
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y += Math.sign(dy);
493
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.direction = dy > 0 ? 'right' : 'left';
511
+ store.pacman.y += Math.sign(dy);
512
+ store.pacman.direction = dy > 0 ? 'right' : 'left';
494
513
  }
495
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x][_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y] > 0) {
496
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points += 1;
497
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x][_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y] = 0;
498
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points >= 30)
499
- activatePowerUp();
514
+ if (store.grid[store.pacman.x][store.pacman.y].intensity > 0) {
515
+ store.pacman.totalPoints += store.grid[store.pacman.x][store.pacman.y].commitsCount;
516
+ store.pacman.points++;
517
+ store.config.pointsIncreasedCallback(store.pacman.totalPoints);
518
+ store.grid[store.pacman.x][store.pacman.y].intensity = 0;
519
+ if (store.pacman.points >= 30)
520
+ activatePowerUp(store);
500
521
  }
501
522
  };
502
- const moveGhosts = () => {
503
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost, index) => {
523
+ const moveGhosts = (store) => {
524
+ store.ghosts.forEach((ghost, index) => {
504
525
  if (ghost.scared) {
505
526
  if (!ghost.target) {
506
527
  ghost.target = getRandomDestination(ghost.x, ghost.y);
@@ -528,7 +549,7 @@ const moveGhosts = () => {
528
549
  ];
529
550
  const [dx, dy] = directions[Math.floor(Math.random() * directions.length)];
530
551
  // If Pacman has the power-up, ghosts move slower (move every other frame)
531
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration && Math.random() < 0.5)
552
+ if (store.pacman.powerupRemainingDuration && Math.random() < 0.5)
532
553
  return;
533
554
  const newX = ghost.x + dx;
534
555
  const newY = ghost.y + dy;
@@ -548,23 +569,23 @@ const getRandomDestination = (x, y) => {
548
569
  y: Math.max(0, Math.min(randomY, _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH - 1))
549
570
  };
550
571
  };
551
- const checkCollisions = () => {
552
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration)
572
+ const checkCollisions = (store) => {
573
+ if (store.pacman.deadRemainingDuration)
553
574
  return;
554
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost, index) => {
555
- if (ghost.x === _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x && ghost.y === _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y) {
556
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration && ghost.scared) {
557
- respawnGhost(index);
558
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points += 10;
559
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
575
+ store.ghosts.forEach((ghost, index) => {
576
+ if (ghost.x === store.pacman.x && ghost.y === store.pacman.y) {
577
+ if (store.pacman.powerupRemainingDuration && ghost.scared) {
578
+ respawnGhost(store, index);
579
+ store.pacman.points += 10;
580
+ if (store.config.outputFormat == 'canvas') {
560
581
  _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.EAT_GHOST);
561
582
  }
562
583
  }
563
584
  else {
564
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.points = 0;
565
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration = 0;
566
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.deadReaminingDuration = _constants__WEBPACK_IMPORTED_MODULE_1__.PACMAN_DEATH_DURATION;
567
- if (_store__WEBPACK_IMPORTED_MODULE_3__.Store.config.outputFormat == 'canvas') {
585
+ store.pacman.points = 0;
586
+ store.pacman.powerupRemainingDuration = 0;
587
+ store.pacman.deadRemainingDuration = _constants__WEBPACK_IMPORTED_MODULE_1__.PACMAN_DEATH_DURATION;
588
+ if (store.config.outputFormat == 'canvas') {
568
589
  _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance()
569
590
  .play(_music_player__WEBPACK_IMPORTED_MODULE_2__.Sound.GAME_OVER)
570
591
  .then(() => _music_player__WEBPACK_IMPORTED_MODULE_2__.MusicPlayer.getInstance().stopDefaultSound());
@@ -573,26 +594,27 @@ const checkCollisions = () => {
573
594
  }
574
595
  });
575
596
  };
576
- const respawnGhost = (ghostIndex) => {
597
+ const respawnGhost = (store, ghostIndex) => {
577
598
  let x, y;
578
599
  do {
579
600
  x = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT);
580
601
  y = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH);
581
- } while ((Math.abs(x - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.x) <= 2 && Math.abs(y - _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.y) <= 2) || _store__WEBPACK_IMPORTED_MODULE_3__.Store.grid[x][y] === 0);
582
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts[ghostIndex] = {
602
+ } while ((Math.abs(x - store.pacman.x) <= 2 && Math.abs(y - store.pacman.y) <= 2) || store.grid[x][y].intensity === 0);
603
+ store.ghosts[ghostIndex] = {
583
604
  x,
584
605
  y,
585
- color: _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_COLORS[ghostIndex % _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_COLORS.length],
606
+ name: _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_NAMES[ghostIndex % _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_NAMES.length],
586
607
  scared: false,
587
608
  target: undefined
588
609
  };
589
610
  };
590
- const activatePowerUp = () => {
591
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.pacman.powerupReaminingDuration = _constants__WEBPACK_IMPORTED_MODULE_1__.PACMAN_POWERUP_DURATION;
592
- _store__WEBPACK_IMPORTED_MODULE_3__.Store.ghosts.forEach((ghost) => (ghost.scared = true));
611
+ const activatePowerUp = (store) => {
612
+ store.pacman.powerupRemainingDuration = _constants__WEBPACK_IMPORTED_MODULE_1__.PACMAN_POWERUP_DURATION;
613
+ store.ghosts.forEach((ghost) => (ghost.scared = true));
593
614
  };
594
615
  const Game = {
595
- startGame
616
+ startGame,
617
+ stopGame
596
618
  };
597
619
 
598
620
 
@@ -620,10 +642,10 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
620
642
  };
621
643
  var Sound;
622
644
  (function (Sound) {
623
- Sound["DEFAULT"] = "/src/assets/sounds/pacman_chomp.wav";
624
- Sound["BEGINNING"] = "/src/assets/sounds/pacman_beginning.wav";
625
- Sound["GAME_OVER"] = "/src/assets/sounds/pacman_death.wav";
626
- Sound["EAT_GHOST"] = "/src/assets/sounds/pacman_eatghost.wav";
645
+ Sound["DEFAULT"] = "https://cdn.jsdelivr.net/gh/abozanona/pacman-contribution-graph@1.0.2/src/assets/sounds/pacman_chomp.wav";
646
+ Sound["BEGINNING"] = "https://cdn.jsdelivr.net/gh/abozanona/pacman-contribution-graph@1.0.2/src/assets/sounds/pacman_beginning.wav";
647
+ Sound["GAME_OVER"] = "https://cdn.jsdelivr.net/gh/abozanona/pacman-contribution-graph@1.0.2/src/assets/sounds/pacman_death.wav";
648
+ Sound["EAT_GHOST"] = "https://cdn.jsdelivr.net/gh/abozanona/pacman-contribution-graph@1.0.2/src/assets/sounds/pacman_eatghost.wav";
627
649
  })(Sound || (Sound = {}));
628
650
  class MusicPlayer {
629
651
  constructor() {
@@ -655,7 +677,10 @@ class MusicPlayer {
655
677
  return;
656
678
  }
657
679
  if (this.currentSource) {
658
- this.currentSource.stop();
680
+ try {
681
+ this.currentSource.stop();
682
+ }
683
+ catch (ex) { }
659
684
  }
660
685
  const buffer = this.sounds.get(sound);
661
686
  if (!buffer) {
@@ -678,7 +703,10 @@ class MusicPlayer {
678
703
  }
679
704
  startDefaultSound() {
680
705
  if (this.defaultSource) {
681
- this.defaultSource.stop();
706
+ try {
707
+ this.defaultSource.stop();
708
+ }
709
+ catch (ex) { }
682
710
  }
683
711
  const buffer = this.sounds.get(Sound.DEFAULT);
684
712
  if (!buffer) {
@@ -695,7 +723,10 @@ class MusicPlayer {
695
723
  }
696
724
  stopDefaultSound() {
697
725
  if (this.defaultSource) {
698
- this.defaultSource.stop();
726
+ try {
727
+ this.defaultSource.stop();
728
+ }
729
+ catch (ex) { }
699
730
  this.defaultSource = null;
700
731
  }
701
732
  }
@@ -740,8 +771,9 @@ const Store = {
740
771
  y: 0,
741
772
  direction: 'right',
742
773
  points: 0,
743
- deadReaminingDuration: 0,
744
- powerupReaminingDuration: 0
774
+ totalPoints: 0,
775
+ deadRemainingDuration: 0,
776
+ powerupRemainingDuration: 0
745
777
  },
746
778
  ghosts: [],
747
779
  grid: [],
@@ -767,23 +799,22 @@ __webpack_require__.r(__webpack_exports__);
767
799
  /* harmony export */ SVG: () => (/* binding */ SVG)
768
800
  /* harmony export */ });
769
801
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
770
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/store.ts");
771
- /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
772
-
802
+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
773
803
 
774
804
 
775
- const generateAnimatedSVG = () => {
805
+ const generateAnimatedSVG = (store) => {
776
806
  const svgWidth = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
777
807
  const svgHeight = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 20;
778
808
  let svg = `<svg width="${svgWidth}" height="${svgHeight}" xmlns="http://www.w3.org/2000/svg">`;
779
- svg += `<rect width="100%" height="100%" fill="${_utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().gridBackground}"/>`;
809
+ svg += `<rect width="100%" height="100%" fill="${_utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).gridBackground}"/>`;
810
+ svg += generateGhostsPredefinition();
780
811
  // Month labels
781
812
  let lastMonth = '';
782
813
  for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; y++) {
783
- if (_store__WEBPACK_IMPORTED_MODULE_1__.Store.monthLabels[y] !== lastMonth) {
814
+ if (store.monthLabels[y] !== lastMonth) {
784
815
  const xPos = y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
785
- svg += `<text x="${xPos}" y="10" text-anchor="middle" font-size="10" fill="${_utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().textColor}">${_store__WEBPACK_IMPORTED_MODULE_1__.Store.monthLabels[y]}</text>`;
786
- lastMonth = _store__WEBPACK_IMPORTED_MODULE_1__.Store.monthLabels[y];
816
+ svg += `<text x="${xPos}" y="10" text-anchor="middle" font-size="10" fill="${_utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).textColor}">${store.monthLabels[y]}</text>`;
817
+ lastMonth = store.monthLabels[y];
787
818
  }
788
819
  }
789
820
  // Grid
@@ -791,59 +822,40 @@ const generateAnimatedSVG = () => {
791
822
  for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; y++) {
792
823
  const cellX = y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
793
824
  const cellY = x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
794
- const intensity = _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory[0].grid[x][y];
795
- const color = intensity > 0 ? getContributionColor(intensity) : _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().emptyContributionBoxColor;
825
+ const intensity = store.gameHistory[0].grid[x][y];
826
+ const color = intensity > 0 ? getContributionColor(store, intensity) : _utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).emptyContributionBoxColor;
796
827
  svg += `<rect id="cell-${x}-${y}" x="${cellX}" y="${cellY}" width="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE}" height="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE}" rx="5" fill="${color}">
797
- <animate attributeName="fill" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
798
- values="${generateCellColorValues(x, y)}"
799
- keyTimes="${generateKeyTimes()}"/>
828
+ <animate attributeName="fill" dur="${store.gameHistory.length * 300}ms" repeatCount="indefinite"
829
+ values="${generateCellColorValues(store, x, y)}"
830
+ keyTimes="${generateKeyTimes(store)}"/>
800
831
  </rect>`;
801
832
  }
802
833
  }
803
834
  // Pacman
804
835
  svg += `<path id="pacman" d="${generatePacManPath(0.35)}"
805
- transform="translate(${_store__WEBPACK_IMPORTED_MODULE_1__.Store.pacman.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE)}, ${_store__WEBPACK_IMPORTED_MODULE_1__.Store.pacman.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15})">
806
- <animate attributeName="fill" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
807
- keyTimes="${generateKeyTimes()}"
808
- values="${generatePacManColors()}"/>
809
- <animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
810
- keyTimes="${generateKeyTimes()}"
811
- values="${generatePacManPositions()}"/>
836
+ transform="translate(${store.pacman.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE)}, ${store.pacman.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15})">
837
+ <animate attributeName="fill" dur="${store.gameHistory.length * 300}ms" repeatCount="indefinite"
838
+ keyTimes="${generateKeyTimes(store)}"
839
+ values="${generatePacManColors(store)}"/>
840
+ <animateTransform attributeName="transform" type="translate" dur="${store.gameHistory.length * 300}ms" repeatCount="indefinite"
841
+ keyTimes="${generateKeyTimes(store)}"
842
+ values="${generatePacManPositions(store)}"/>
812
843
  <animate attributeName="d" dur="0.2s" repeatCount="indefinite"
813
844
  values="${generatePacManPath(0.25)};${generatePacManPath(0.05)};${generatePacManPath(0.25)}"/>
814
845
  </path>`;
815
846
  // Ghosts
816
- _store__WEBPACK_IMPORTED_MODULE_1__.Store.ghosts.forEach((ghost, index) => {
817
- svg += `<path id="ghost${index}" d="${generateGhostPath(_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2)}" fill="${ghost.color}">
818
- <animate attributeName="fill" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
819
- keyTimes="${generateKeyTimes()}"
820
- values="${generateGhostColors(index)}"/>
821
- <animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
822
- keyTimes="${generateKeyTimes()}"
823
- values="${generateGhostPositions(index)}"/>
824
- </path>
825
- <circle cx="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" cy="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" r="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 8}" fill="white">
826
- <animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
827
- keyTimes="${generateKeyTimes()}"
828
- values="${generateGhostPositions(index)}"/>
829
- </circle>
830
- <circle cx="${(_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE * 2) / 3}" cy="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" r="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 8}" fill="white">
831
- <animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
832
- keyTimes="${generateKeyTimes()}"
833
- values="${generateGhostPositions(index)}"/>
834
- </circle>
835
- <circle cx="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" cy="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" r="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 16}" fill="black">
836
- <animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
837
- keyTimes="${generateKeyTimes()}"
838
- values="${generateGhostPositions(index)}"/>
839
- </circle>
840
- <circle cx="${(_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE * 2) / 3}" cy="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 3}" r="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 16}" fill="black">
841
- <animateTransform attributeName="transform" type="translate" dur="${_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length * 300}ms" repeatCount="indefinite"
842
- keyTimes="${generateKeyTimes()}"
843
- values="${generateGhostPositions(index)}"/>
844
- </circle>`;
847
+ store.ghosts.forEach((ghost, index) => {
848
+ svg += `<use id="ghost${index}" width="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE}" height="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE}" href="#ghost-${ghost.name}">
849
+ <animateTransform attributeName="transform" type="translate" dur="${store.gameHistory.length * 300}ms" repeatCount="indefinite"
850
+ keyTimes="${generateKeyTimes(store)}"
851
+ values="${generateGhostPositions(store, index)}"/>
852
+ <animate attributeName="href" dur="${store.gameHistory.length * 300}ms" repeatCount="indefinite"
853
+ keyTimes="${generateKeyTimes(store)}"
854
+ values="${generateGhostColors(store, index)}"/>
855
+ </use>`;
845
856
  });
846
857
  svg += '</svg>';
858
+ // TODO: minify SVG
847
859
  return svg;
848
860
  };
849
861
  const generatePacManPath = (mouthAngle) => {
@@ -855,11 +867,11 @@ const generatePacManPath = (mouthAngle) => {
855
867
  A ${radius},${radius} 0 1,1 ${radius + radius * Math.cos(endAngle)},${radius + radius * Math.sin(endAngle)}
856
868
  Z`;
857
869
  };
858
- const generateKeyTimes = () => {
859
- return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.map((_, index) => index / (_store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory.length - 1)).join(';');
870
+ const generateKeyTimes = (store) => {
871
+ return store.gameHistory.map((_, index) => index / (store.gameHistory.length - 1)).join(';');
860
872
  };
861
- const generatePacManPositions = () => {
862
- return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
873
+ const generatePacManPositions = (store) => {
874
+ return store.gameHistory
863
875
  .map((state) => {
864
876
  const x = state.pacman.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
865
877
  const y = state.pacman.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
@@ -867,13 +879,13 @@ const generatePacManPositions = () => {
867
879
  })
868
880
  .join(';');
869
881
  };
870
- const generatePacManColors = () => {
871
- return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
882
+ const generatePacManColors = (store) => {
883
+ return store.gameHistory
872
884
  .map((state) => {
873
- if (state.pacman.deadReaminingDuration) {
885
+ if (state.pacman.deadRemainingDuration) {
874
886
  return _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_DEAD;
875
887
  }
876
- else if (state.pacman.powerupReaminingDuration) {
888
+ else if (state.pacman.powerupRemainingDuration) {
877
889
  return _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_POWERUP;
878
890
  }
879
891
  else {
@@ -882,20 +894,20 @@ const generatePacManColors = () => {
882
894
  })
883
895
  .join(';');
884
896
  };
885
- const generateCellColorValues = (x, y) => {
886
- return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
897
+ const generateCellColorValues = (store, x, y) => {
898
+ return store.gameHistory
887
899
  .map((state) => {
888
900
  const intensity = state.grid[x][y];
889
- return intensity > 0 ? getContributionColor(intensity) : _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().emptyContributionBoxColor;
901
+ return intensity > 0 ? getContributionColor(store, intensity) : _utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).emptyContributionBoxColor;
890
902
  })
891
903
  .join(';');
892
904
  };
893
- const getContributionColor = (intensity) => {
905
+ const getContributionColor = (store, intensity) => {
894
906
  const adjustedIntensity = intensity < 0.2 ? 0.3 : intensity;
895
- return _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.hexToRGBA(_utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme().contributionBoxColor, adjustedIntensity);
907
+ return _utils__WEBPACK_IMPORTED_MODULE_1__.Utils.hexToRGBA(_utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).contributionBoxColor, adjustedIntensity);
896
908
  };
897
- const generateGhostPositions = (ghostIndex) => {
898
- return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
909
+ const generateGhostPositions = (store, ghostIndex) => {
910
+ return store.gameHistory
899
911
  .map((state) => {
900
912
  const ghost = state.ghosts[ghostIndex];
901
913
  const x = ghost.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
@@ -904,25 +916,33 @@ const generateGhostPositions = (ghostIndex) => {
904
916
  })
905
917
  .join(';');
906
918
  };
907
- const generateGhostPath = (radius) => {
908
- return `M ${radius},${radius * 2}
909
- Q ${radius * 0.8},${radius * 1.5} ${radius * 0.5},${radius * 1.3}
910
- Q ${radius * 0.3},${radius * 1.1} 0,${radius}
911
- L 0,0
912
- L ${radius * 2},0
913
- L ${radius * 2},${radius}
914
- Q ${radius * 1.7},${radius * 1.1} ${radius * 1.5},${radius * 1.3}
915
- Q ${radius * 1.2},${radius * 1.5} ${radius},${radius * 2}
916
- Z`;
917
- };
918
- const generateGhostColors = (ghostIndex) => {
919
- return _store__WEBPACK_IMPORTED_MODULE_1__.Store.gameHistory
919
+ const generateGhostColors = (store, ghostIndex) => {
920
+ return store.gameHistory
920
921
  .map((state) => {
921
922
  const ghost = state.ghosts[ghostIndex];
922
- return ghost.scared ? 'blue' : ghost.color;
923
+ return ghost.scared ? '#scared' : '#' + ghost.name;
923
924
  })
924
925
  .join(';');
925
926
  };
927
+ const generateGhostsPredefinition = () => {
928
+ return `<defs>
929
+ <symbol id="blinky" viewBox="0 0 100 100">
930
+ <image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['blinky'].imgDate}" width="100" height="100"/>
931
+ </symbol>
932
+ <symbol id="clyde" viewBox="0 0 100 100">
933
+ <image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['clyde'].imgDate}" width="100" height="100"/>
934
+ </symbol>
935
+ <symbol id="inky" viewBox="0 0 100 100">
936
+ <image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['inky'].imgDate}" width="100" height="100"/>
937
+ </symbol>
938
+ <symbol id="pinky" viewBox="0 0 100 100">
939
+ <image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['pinky'].imgDate}" width="100" height="100"/>
940
+ </symbol>
941
+ <symbol id="scared" viewBox="0 0 100 100">
942
+ <image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['scared'].imgDate}" width="100" height="100"/>
943
+ </symbol>
944
+ </defs>`;
945
+ };
926
946
  const SVG = {
927
947
  generateAnimatedSVG
928
948
  };
@@ -941,7 +961,6 @@ __webpack_require__.r(__webpack_exports__);
941
961
  /* harmony export */ Utils: () => (/* binding */ Utils)
942
962
  /* harmony export */ });
943
963
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
944
- /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/store.ts");
945
964
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
946
965
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
947
966
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -952,9 +971,9 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
952
971
  });
953
972
  };
954
973
 
955
-
956
974
  const getGitlabContribution = (username) => __awaiter(void 0, void 0, void 0, function* () {
957
- const response = yield fetch(`https://gitlab.com/users/${username}/calendar.json`);
975
+ // const response = await fetch(`https://gitlab.com/users/${username}/calendar.json`);
976
+ const response = yield fetch(`https://v0-new-project-q1hhrdodoye-abozanona-gmailcoms-projects.vercel.app/api/contributions?username=${username}`);
958
977
  const contributionsList = yield response.json();
959
978
  return Object.entries(contributionsList).map(([date, count]) => ({
960
979
  date: new Date(date),
@@ -973,9 +992,9 @@ const getGithubContribution = (username) => __awaiter(void 0, void 0, void 0, fu
973
992
  }, new Map())
974
993
  .values());
975
994
  });
976
- const getCurrentTheme = () => {
995
+ const getCurrentTheme = (store) => {
977
996
  var _a;
978
- return (_a = _constants__WEBPACK_IMPORTED_MODULE_0__.GAME_THEMES[_store__WEBPACK_IMPORTED_MODULE_1__.Store.config.gameTheme]) !== null && _a !== void 0 ? _a : _constants__WEBPACK_IMPORTED_MODULE_0__.GAME_THEMES['github'];
997
+ return (_a = _constants__WEBPACK_IMPORTED_MODULE_0__.GAME_THEMES[store.config.gameTheme]) !== null && _a !== void 0 ? _a : _constants__WEBPACK_IMPORTED_MODULE_0__.GAME_THEMES['github'];
979
998
  };
980
999
  function hexToRGBA(hex, alpha) {
981
1000
  const r = parseInt(hex.slice(1, 3), 16);
@@ -1057,7 +1076,7 @@ var __webpack_exports__ = {};
1057
1076
  \**********************/
1058
1077
  __webpack_require__.r(__webpack_exports__);
1059
1078
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1060
- /* harmony export */ renderContributions: () => (/* binding */ renderContributions)
1079
+ /* harmony export */ PacmanRenderer: () => (/* binding */ PacmanRenderer)
1061
1080
  /* harmony export */ });
1062
1081
  /* harmony import */ var _game__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./game */ "./src/game.ts");
1063
1082
  /* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./store */ "./src/store.ts");
@@ -1074,33 +1093,45 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
1074
1093
 
1075
1094
 
1076
1095
 
1077
- const renderContributions = (conf) => __awaiter(void 0, void 0, void 0, function* () {
1078
- const defaultConfing = {
1079
- platform: 'github',
1080
- username: '',
1081
- canvas: undefined,
1082
- outputFormat: 'svg',
1083
- svgCallback: (_) => { },
1084
- gameOverCallback: () => () => { },
1085
- gameTheme: 'github',
1086
- gameSpeed: 1,
1087
- enableSounds: true
1088
- };
1089
- _store__WEBPACK_IMPORTED_MODULE_1__.Store.config = Object.assign(Object.assign({}, defaultConfing), conf);
1090
- switch (conf.platform) {
1091
- case 'gitlab':
1092
- _store__WEBPACK_IMPORTED_MODULE_1__.Store.contributions = yield _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getGitlabContribution(conf.username);
1093
- break;
1094
- case 'github':
1095
- _store__WEBPACK_IMPORTED_MODULE_1__.Store.contributions = yield _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getGithubContribution(conf.username);
1096
- break;
1096
+ class PacmanRenderer {
1097
+ constructor(conf) {
1098
+ this.store = Object.assign({}, _store__WEBPACK_IMPORTED_MODULE_1__.Store);
1099
+ this.conf = Object.assign({}, conf);
1097
1100
  }
1098
- _game__WEBPACK_IMPORTED_MODULE_0__.Game.startGame();
1099
- });
1101
+ start() {
1102
+ return __awaiter(this, void 0, void 0, function* () {
1103
+ const defaultConfing = {
1104
+ platform: 'github',
1105
+ username: '',
1106
+ canvas: undefined,
1107
+ outputFormat: 'svg',
1108
+ svgCallback: (_) => { },
1109
+ gameOverCallback: () => () => { },
1110
+ gameTheme: 'github',
1111
+ gameSpeed: 1,
1112
+ enableSounds: true,
1113
+ pointsIncreasedCallback: (_) => { }
1114
+ };
1115
+ this.store.config = Object.assign(Object.assign({}, defaultConfing), this.conf);
1116
+ switch (this.conf.platform) {
1117
+ case 'gitlab':
1118
+ this.store.contributions = yield _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getGitlabContribution(this.conf.username);
1119
+ break;
1120
+ case 'github':
1121
+ this.store.contributions = yield _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getGithubContribution(this.conf.username);
1122
+ break;
1123
+ }
1124
+ _game__WEBPACK_IMPORTED_MODULE_0__.Game.startGame(this.store);
1125
+ });
1126
+ }
1127
+ stop() {
1128
+ _game__WEBPACK_IMPORTED_MODULE_0__.Game.stopGame(this.store);
1129
+ }
1130
+ }
1100
1131
 
1101
1132
  })();
1102
1133
 
1103
- var __webpack_exports__renderContributions = __webpack_exports__.renderContributions;
1104
- export { __webpack_exports__renderContributions as renderContributions };
1134
+ var __webpack_exports__PacmanRenderer = __webpack_exports__.PacmanRenderer;
1135
+ export { __webpack_exports__PacmanRenderer as PacmanRenderer };
1105
1136
 
1106
1137
  //# sourceMappingURL=pacman-contribution-graph.js.map