pacman-contribution-graph 1.0.14 → 2.0.0
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/README.md +59 -9
- package/dist/pacman-contribution-graph.min.js +1 -1
- package/package.json +44 -26
- package/.prettierrc +0 -8
- package/.vscode/extensions.json +0 -5
- package/.vscode/settings.json +0 -6
- package/assets/packman-demo.png +0 -0
- package/dist/pacman-contribution-graph.js +0 -1776
- package/dist/pacman-contribution-graph.js.map +0 -1
- package/embeded/canvas.html +0 -41
- package/github-action/action.yml +0 -16
- package/github-action/dist/index.js +0 -26901
- package/github-action/package.json +0 -14
- package/github-action/pnpm-lock.yaml +0 -77
- package/github-action/src/index.js +0 -47
- package/index.html +0 -528
- package/pacman.abozanona.me/index.js +0 -47
- package/pacman.abozanona.me/package.json +0 -8
- package/server/api/contributions/route.ts.z +0 -31
- package/server/page.zts.z +0 -13
- package/src/assets/images/ghosts/blinky.png +0 -0
- package/src/assets/images/ghosts/clyde.png +0 -0
- package/src/assets/images/ghosts/inky.png +0 -0
- package/src/assets/images/ghosts/pinky.png +0 -0
- package/src/assets/images/ghosts/scared.png +0 -0
- package/src/assets/sounds/pacman_beginning.wav +0 -0
- package/src/assets/sounds/pacman_chomp.wav +0 -0
- package/src/assets/sounds/pacman_death.wav +0 -0
- package/src/assets/sounds/pacman_eatghost.wav +0 -0
- package/src/canvas.ts +0 -244
- package/src/constants.ts +0 -102
- package/src/game.ts +0 -231
- package/src/grid.ts +0 -127
- package/src/index.ts +0 -48
- package/src/movement/ghosts-movement.ts +0 -183
- package/src/movement/movement-utils.ts +0 -40
- package/src/movement/pacman-movement.ts +0 -230
- package/src/music-player.ts +0 -119
- package/src/store.ts +0 -23
- package/src/svg.ts +0 -254
- package/src/types.ts +0 -78
- package/src/utils.ts +0 -81
- package/tsconfig.json +0 -11
- package/webpack.common.js +0 -19
- package/webpack.dev.js +0 -23
- package/webpack.prod.js +0 -18
|
@@ -1,1776 +0,0 @@
|
|
|
1
|
-
/******/ var __webpack_modules__ = ({
|
|
2
|
-
|
|
3
|
-
/***/ "./src/canvas.ts":
|
|
4
|
-
/*!***********************!*\
|
|
5
|
-
!*** ./src/canvas.ts ***!
|
|
6
|
-
\***********************/
|
|
7
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
8
|
-
|
|
9
|
-
__webpack_require__.r(__webpack_exports__);
|
|
10
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
11
|
-
/* harmony export */ Canvas: () => (/* binding */ Canvas)
|
|
12
|
-
/* harmony export */ });
|
|
13
|
-
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
|
|
14
|
-
/* harmony import */ var _music_player__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./music-player */ "./src/music-player.ts");
|
|
15
|
-
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const resizeCanvas = (store) => {
|
|
20
|
-
const canvasWidth = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
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
|
|
22
|
-
store.config.canvas.width = canvasWidth;
|
|
23
|
-
store.config.canvas.height = canvasHeight;
|
|
24
|
-
};
|
|
25
|
-
const drawGrid = (store) => {
|
|
26
|
-
const ctx = store.config.canvas.getContext('2d');
|
|
27
|
-
ctx.fillStyle = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).gridBackground;
|
|
28
|
-
ctx.fillRect(0, 0, store.config.canvas.width, store.config.canvas.height);
|
|
29
|
-
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; x++) {
|
|
30
|
-
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT; y++) {
|
|
31
|
-
const intensity = store.grid[x][y].intensity;
|
|
32
|
-
if (intensity > 0) {
|
|
33
|
-
const adjustedIntensity = intensity < 0.2 ? 0.3 : intensity;
|
|
34
|
-
const color = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.hexToRGBA(_utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).contributionBoxColor, adjustedIntensity);
|
|
35
|
-
ctx.fillStyle = color;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
ctx.fillStyle = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).emptyContributionBoxColor;
|
|
39
|
-
}
|
|
40
|
-
ctx.beginPath();
|
|
41
|
-
store.config.canvas
|
|
42
|
-
.getContext('2d')
|
|
43
|
-
.roundRect(x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE), y * (_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);
|
|
44
|
-
ctx.fill();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
ctx.fillStyle = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).wallColor;
|
|
48
|
-
for (let x = 0; x <= _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; x++) {
|
|
49
|
-
for (let y = 0; y <= _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT; y++) {
|
|
50
|
-
// Draw horizontal walls
|
|
51
|
-
if (_constants__WEBPACK_IMPORTED_MODULE_0__.WALLS.horizontal[x][y].active) {
|
|
52
|
-
ctx.fillRect(x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) - _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE, y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) - _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE + 15, _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE, _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
53
|
-
// // TODO: For debug only
|
|
54
|
-
// ctx.fillStyle = '#000';
|
|
55
|
-
// ctx.fillText(WALLS.horizontal[x][y].id, x * (GAP_SIZE + CELL_SIZE), y * (GAP_SIZE + CELL_SIZE));
|
|
56
|
-
}
|
|
57
|
-
// Draw vertical walls
|
|
58
|
-
if (_constants__WEBPACK_IMPORTED_MODULE_0__.WALLS.vertical[x][y].active) {
|
|
59
|
-
ctx.fillRect(x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) - _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE, y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) - _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE + 15, _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE, _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
60
|
-
// // TODO: For debug only
|
|
61
|
-
// ctx.fillStyle = '#000';
|
|
62
|
-
// ctx.fillText(WALLS.vertical[x][y].id, x * (GAP_SIZE + CELL_SIZE), (y + 1) * (GAP_SIZE + CELL_SIZE));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
ctx.fillStyle = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).textColor;
|
|
67
|
-
ctx.font = '10px Arial';
|
|
68
|
-
ctx.textAlign = 'center';
|
|
69
|
-
let lastMonth = '';
|
|
70
|
-
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; x++) {
|
|
71
|
-
if (store.monthLabels[x] !== lastMonth) {
|
|
72
|
-
const xPos = x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
73
|
-
ctx.fillText(store.monthLabels[x], xPos, 10);
|
|
74
|
-
lastMonth = store.monthLabels[x];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const drawPacman = (store) => {
|
|
79
|
-
const ctx = store.config.canvas.getContext('2d');
|
|
80
|
-
const x = 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;
|
|
81
|
-
const y = 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 + 15;
|
|
82
|
-
const radius = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
83
|
-
// Change Pac-Man's color to red if he's on power-up, dead, else yellow
|
|
84
|
-
if (store.pacman.deadRemainingDuration) {
|
|
85
|
-
ctx.fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_DEAD;
|
|
86
|
-
}
|
|
87
|
-
else if (store.pacman.powerupRemainingDuration) {
|
|
88
|
-
ctx.fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_POWERUP;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
ctx.fillStyle = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR;
|
|
92
|
-
}
|
|
93
|
-
const mouthAngle = store.pacmanMouthOpen ? 0.35 * Math.PI : 0.1 * Math.PI;
|
|
94
|
-
let startAngle, endAngle;
|
|
95
|
-
switch (store.pacman.direction) {
|
|
96
|
-
case 'up':
|
|
97
|
-
startAngle = 1.5 * Math.PI + mouthAngle;
|
|
98
|
-
endAngle = 1.5 * Math.PI - mouthAngle;
|
|
99
|
-
break;
|
|
100
|
-
case 'down':
|
|
101
|
-
startAngle = 0.5 * Math.PI + mouthAngle;
|
|
102
|
-
endAngle = 0.5 * Math.PI - mouthAngle;
|
|
103
|
-
break;
|
|
104
|
-
case 'left':
|
|
105
|
-
startAngle = Math.PI + mouthAngle;
|
|
106
|
-
endAngle = Math.PI - mouthAngle;
|
|
107
|
-
break;
|
|
108
|
-
case 'right':
|
|
109
|
-
default:
|
|
110
|
-
startAngle = 0 + mouthAngle;
|
|
111
|
-
endAngle = 2 * Math.PI - mouthAngle;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
ctx.beginPath();
|
|
115
|
-
ctx.arc(x, y, radius, startAngle, endAngle);
|
|
116
|
-
ctx.lineTo(x, y);
|
|
117
|
-
ctx.fill();
|
|
118
|
-
};
|
|
119
|
-
const preloadedImages = {};
|
|
120
|
-
const getLoadedImage = (key, imgDate) => {
|
|
121
|
-
if (!preloadedImages[key]) {
|
|
122
|
-
const image = new Image();
|
|
123
|
-
image.src = imgDate;
|
|
124
|
-
preloadedImages[key] = image;
|
|
125
|
-
}
|
|
126
|
-
return preloadedImages[key];
|
|
127
|
-
};
|
|
128
|
-
const drawGhosts = (store) => {
|
|
129
|
-
store.ghosts.forEach((ghost) => {
|
|
130
|
-
const x = ghost.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
131
|
-
const y = ghost.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
|
|
132
|
-
const size = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE;
|
|
133
|
-
const ctx = store.config.canvas.getContext('2d');
|
|
134
|
-
if (ghost.scared) {
|
|
135
|
-
ctx.drawImage(getLoadedImage('scared', _constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['scared'].imgDate), x, y, size, size);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
ctx.drawImage(getLoadedImage(ghost.name, _constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS[ghost.name].imgDate), x, y, size, size);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
const renderGameOver = (store) => {
|
|
143
|
-
const ctx = store.config.canvas.getContext('2d');
|
|
144
|
-
ctx.fillStyle = _utils__WEBPACK_IMPORTED_MODULE_2__.Utils.getCurrentTheme(store).textColor;
|
|
145
|
-
ctx.font = '20px Arial';
|
|
146
|
-
ctx.textAlign = 'center';
|
|
147
|
-
ctx.fillText('Game Over', store.config.canvas.width / 2, store.config.canvas.height / 2);
|
|
148
|
-
};
|
|
149
|
-
const drawSoundController = (store) => {
|
|
150
|
-
if (!store.config.enableSounds) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const ctx = store.config.canvas.getContext('2d');
|
|
154
|
-
const width = 30, height = 30, left = store.config.canvas.width - width - 10, top = 10;
|
|
155
|
-
ctx.fillStyle = `rgba(0, 0, 0, ${_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted ? 0.3 : 0.5})`;
|
|
156
|
-
ctx.beginPath();
|
|
157
|
-
ctx.moveTo(left + 10, top + 10);
|
|
158
|
-
ctx.lineTo(left + 20, top + 5);
|
|
159
|
-
ctx.lineTo(left + 20, top + 25);
|
|
160
|
-
ctx.lineTo(left + 10, top + 20);
|
|
161
|
-
ctx.closePath();
|
|
162
|
-
ctx.fill();
|
|
163
|
-
if (!_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted) {
|
|
164
|
-
ctx.strokeStyle = `rgba(0, 0, 0, 0.4)`;
|
|
165
|
-
ctx.lineWidth = 2;
|
|
166
|
-
// First wave
|
|
167
|
-
ctx.beginPath();
|
|
168
|
-
ctx.arc(left + 25, top + 15, 5, 0, Math.PI * 2);
|
|
169
|
-
ctx.stroke();
|
|
170
|
-
// Second wave
|
|
171
|
-
ctx.beginPath();
|
|
172
|
-
ctx.arc(left + 25, top + 15, 8, 0, Math.PI * 2);
|
|
173
|
-
ctx.stroke();
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
// Mute line
|
|
177
|
-
ctx.strokeStyle = 'rgba(255, 0, 0, 0.6)';
|
|
178
|
-
ctx.lineWidth = 3;
|
|
179
|
-
ctx.beginPath();
|
|
180
|
-
ctx.moveTo(left + 25, top + 5);
|
|
181
|
-
ctx.lineTo(left + 5, top + 25);
|
|
182
|
-
ctx.stroke();
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
const listenToSoundController = (store) => {
|
|
186
|
-
if (!store.config.enableSounds) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
store.config.canvas.addEventListener('click', function (event) {
|
|
190
|
-
const rect = store.config.canvas.getBoundingClientRect();
|
|
191
|
-
const x = event.clientX - rect.left, y = event.clientY - rect.top;
|
|
192
|
-
const width = 30, height = 30, left = store.config.canvas.width - width - 10, top = 10;
|
|
193
|
-
if (x >= left && x <= left + this.width && y >= top && y <= top + this.height) {
|
|
194
|
-
if (_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().isMuted) {
|
|
195
|
-
_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().unmute();
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
_music_player__WEBPACK_IMPORTED_MODULE_1__.MusicPlayer.getInstance().mute();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
const Canvas = {
|
|
204
|
-
resizeCanvas,
|
|
205
|
-
drawGrid,
|
|
206
|
-
drawPacman,
|
|
207
|
-
drawGhosts,
|
|
208
|
-
renderGameOver,
|
|
209
|
-
drawSoundController,
|
|
210
|
-
listenToSoundController
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
/***/ }),
|
|
215
|
-
|
|
216
|
-
/***/ "./src/constants.ts":
|
|
217
|
-
/*!**************************!*\
|
|
218
|
-
!*** ./src/constants.ts ***!
|
|
219
|
-
\**************************/
|
|
220
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
221
|
-
|
|
222
|
-
__webpack_require__.r(__webpack_exports__);
|
|
223
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
224
|
-
/* harmony export */ CELL_SIZE: () => (/* binding */ CELL_SIZE),
|
|
225
|
-
/* harmony export */ DELTA_TIME: () => (/* binding */ DELTA_TIME),
|
|
226
|
-
/* harmony export */ GAME_THEMES: () => (/* binding */ GAME_THEMES),
|
|
227
|
-
/* harmony export */ GAP_SIZE: () => (/* binding */ GAP_SIZE),
|
|
228
|
-
/* harmony export */ GHOSTS: () => (/* binding */ GHOSTS),
|
|
229
|
-
/* harmony export */ GHOST_NAMES: () => (/* binding */ GHOST_NAMES),
|
|
230
|
-
/* harmony export */ GRID_HEIGHT: () => (/* binding */ GRID_HEIGHT),
|
|
231
|
-
/* harmony export */ GRID_WIDTH: () => (/* binding */ GRID_WIDTH),
|
|
232
|
-
/* harmony export */ MONTHS: () => (/* binding */ MONTHS),
|
|
233
|
-
/* harmony export */ PACMAN_COLOR: () => (/* binding */ PACMAN_COLOR),
|
|
234
|
-
/* harmony export */ PACMAN_COLOR_DEAD: () => (/* binding */ PACMAN_COLOR_DEAD),
|
|
235
|
-
/* harmony export */ PACMAN_COLOR_POWERUP: () => (/* binding */ PACMAN_COLOR_POWERUP),
|
|
236
|
-
/* harmony export */ PACMAN_DEATH_DURATION: () => (/* binding */ PACMAN_DEATH_DURATION),
|
|
237
|
-
/* harmony export */ PACMAN_POWERUP_DURATION: () => (/* binding */ PACMAN_POWERUP_DURATION),
|
|
238
|
-
/* harmony export */ WALLS: () => (/* binding */ WALLS),
|
|
239
|
-
/* harmony export */ hasWall: () => (/* binding */ hasWall),
|
|
240
|
-
/* harmony export */ setWall: () => (/* binding */ setWall)
|
|
241
|
-
/* harmony export */ });
|
|
242
|
-
const CELL_SIZE = 20;
|
|
243
|
-
const GAP_SIZE = 2;
|
|
244
|
-
const GRID_WIDTH = 52;
|
|
245
|
-
const GRID_HEIGHT = 7;
|
|
246
|
-
const PACMAN_COLOR = 'yellow';
|
|
247
|
-
const PACMAN_COLOR_POWERUP = 'red';
|
|
248
|
-
const PACMAN_COLOR_DEAD = '#80808064';
|
|
249
|
-
const GHOST_NAMES = ['blinky', 'clyde', 'inky', 'pinky'];
|
|
250
|
-
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
251
|
-
const DELTA_TIME = 200;
|
|
252
|
-
const PACMAN_DEATH_DURATION = 10;
|
|
253
|
-
const PACMAN_POWERUP_DURATION = 15;
|
|
254
|
-
const GAME_THEMES = {
|
|
255
|
-
github: {
|
|
256
|
-
textColor: '#586069',
|
|
257
|
-
gridBackground: '#ffffff',
|
|
258
|
-
contributionBoxColor: '#9be9a8',
|
|
259
|
-
emptyContributionBoxColor: '#ebedf0',
|
|
260
|
-
wallColor: '#000000'
|
|
261
|
-
},
|
|
262
|
-
'github-dark': {
|
|
263
|
-
textColor: '#8b949e',
|
|
264
|
-
gridBackground: '#0d1117',
|
|
265
|
-
contributionBoxColor: '#26a641',
|
|
266
|
-
emptyContributionBoxColor: '#161b22',
|
|
267
|
-
wallColor: '#FFFFFF'
|
|
268
|
-
},
|
|
269
|
-
gitlab: {
|
|
270
|
-
textColor: '#626167',
|
|
271
|
-
gridBackground: '#ffffff',
|
|
272
|
-
contributionBoxColor: '#7992f5',
|
|
273
|
-
emptyContributionBoxColor: '#ececef',
|
|
274
|
-
wallColor: '#000000'
|
|
275
|
-
},
|
|
276
|
-
'gitlab-dark': {
|
|
277
|
-
textColor: '#999999',
|
|
278
|
-
gridBackground: '#1f1f1f',
|
|
279
|
-
contributionBoxColor: '#2e7db1',
|
|
280
|
-
emptyContributionBoxColor: '#2d2d2d',
|
|
281
|
-
wallColor: '#FFFFFF'
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
const GHOSTS = {
|
|
285
|
-
blinky: {
|
|
286
|
-
imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAfUlEQVQ4T+2TUQ7AIAhDy/0PzQIRAqxmLtnn/DJPWypBAVkKKOMCyOQN7IRElLrcnIrDLNK4wVtxNbkb6Hq+jOcSbim6QVzKEstkw92gxVeFrMpqokix4wA+NvCOnvfArvcEbHoe2G9QmmhDMUc65p3xYC6q3zQPxtdl3NgF5QpL/b/rs3IAAAAASUVORK5CYIIA'
|
|
287
|
-
},
|
|
288
|
-
clyde: {
|
|
289
|
-
imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAgUlEQVQ4T+2T0Q6AIAhFLx9sH1MfTIPCAeLKrcd8PHqP4JBQLN7BFacNlHkAs+AQcqIueBs2mVWjgtWwl4yCdrd/pHYLLlVEgR2yK0wy4SoI5TcGXU4wM+AEJQfwsUCuXngDOR4rqKbngf0C94gyFHmkbd4rbkxD/pv2jfR1Ky7sBNrzXbHpnBX+AAAAAElFTkSuQmCC'
|
|
290
|
-
},
|
|
291
|
-
inky: {
|
|
292
|
-
imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAg0lEQVQ4T+WTWxKAIAhFuQvK/a+jFoT5QAVxypn+6vMEx6sDIO/jk12OAMs1WDVOXV3UBW+bRVbTFMFu8yCZBExH/g26VHCXI0AJpKgdUCUrTlkwxE+FECdzS7HiJemXgvyeO29gE7jD8wDVFX4vSLNtR1q2z+OVlaZxTaXYrq7HbxYBS8VgMVrqzkEAAAAASUVORK5CYIIA'
|
|
293
|
-
},
|
|
294
|
-
pinky: {
|
|
295
|
-
imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAhklEQVQ4T+2T0Q2AIAwF281wC50Qt9DNagoptqVESfyUz4N3vJCCECxaD4o47gt6bsAo2IWUqAnehkUmbYpgNqwlvSCnur+dtnnAuYUVyCGJimTAi8DUzwmwOoGI7hYjDgAfC/jqiTfg47ZBND0P7BeoR+Sh8CMt8x5xYSWkv2nbcF834swuA/9u49Yy5bgAAAAASUVORK5CYIIA'
|
|
296
|
-
},
|
|
297
|
-
scared: {
|
|
298
|
-
imgDate: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAeUlEQVQ4T82TUQ6AMAhD7UX0/sdyF0GREVmDmTN+bH9r6Bs0A0t2VpFULwDrrfBkZFcA3YC3ZodViAFGzQHyP0B2w2NrB0/1AoDbHwLoQ5/nrw1OBuD5e/crbM9Aiz35njHWzpSB/m3+0r40mV41M8U19WJe3Uw/tQOKt08pUUbBEQAAAABJRU5ErkJgggAA'
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
const WALLS = {
|
|
302
|
-
horizontal: Array(GRID_WIDTH + 1)
|
|
303
|
-
.fill(null)
|
|
304
|
-
.map(() => Array(GRID_HEIGHT + 1).fill({ active: false, id: '' })),
|
|
305
|
-
vertical: Array(GRID_WIDTH + 1)
|
|
306
|
-
.fill(null)
|
|
307
|
-
.map(() => Array(GRID_HEIGHT + 1).fill({ active: false, id: '' }))
|
|
308
|
-
};
|
|
309
|
-
const setWall = (x, y, direction, lineId) => {
|
|
310
|
-
if (direction === 'horizontal') {
|
|
311
|
-
if (x >= 0 && x < WALLS.horizontal.length && y >= 0 && y < WALLS.horizontal[0].length) {
|
|
312
|
-
WALLS.horizontal[x][y] = { active: true, id: lineId };
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
if (x >= 0 && x < WALLS.vertical.length && y >= 0 && y < WALLS.vertical[0].length) {
|
|
317
|
-
WALLS.vertical[x][y] = { active: true, id: lineId };
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
const hasWall = (x, y, direction) => {
|
|
322
|
-
switch (direction) {
|
|
323
|
-
case 'up':
|
|
324
|
-
return WALLS.horizontal[x][y].active;
|
|
325
|
-
case 'down':
|
|
326
|
-
return WALLS.horizontal[x + 1][y].active;
|
|
327
|
-
case 'left':
|
|
328
|
-
return WALLS.vertical[x][y].active;
|
|
329
|
-
case 'right':
|
|
330
|
-
return WALLS.vertical[x][y + 1].active;
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
/***/ }),
|
|
336
|
-
|
|
337
|
-
/***/ "./src/game.ts":
|
|
338
|
-
/*!*********************!*\
|
|
339
|
-
!*** ./src/game.ts ***!
|
|
340
|
-
\*********************/
|
|
341
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
342
|
-
|
|
343
|
-
__webpack_require__.r(__webpack_exports__);
|
|
344
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
345
|
-
/* harmony export */ Game: () => (/* binding */ Game)
|
|
346
|
-
/* harmony export */ });
|
|
347
|
-
/* harmony import */ var _canvas__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./canvas */ "./src/canvas.ts");
|
|
348
|
-
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
|
|
349
|
-
/* harmony import */ var _movement_ghosts_movement__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./movement/ghosts-movement */ "./src/movement/ghosts-movement.ts");
|
|
350
|
-
/* harmony import */ var _movement_pacman_movement__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./movement/pacman-movement */ "./src/movement/pacman-movement.ts");
|
|
351
|
-
/* harmony import */ var _music_player__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./music-player */ "./src/music-player.ts");
|
|
352
|
-
/* harmony import */ var _svg__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./svg */ "./src/svg.ts");
|
|
353
|
-
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
354
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
355
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
356
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
357
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
358
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
359
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
360
|
-
});
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const initializeGrid = (store) => {
|
|
369
|
-
store.pacman.points = 0;
|
|
370
|
-
store.pacman.totalPoints = 0;
|
|
371
|
-
store.grid = Array.from({ length: _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH }, () => Array.from({ length: _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT }, () => ({ commitsCount: 0, intensity: 0 })));
|
|
372
|
-
store.monthLabels = Array(_constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH).fill('');
|
|
373
|
-
let maxCommits = 1;
|
|
374
|
-
const now = new Date();
|
|
375
|
-
const startOfCurrentWeek = new Date(now);
|
|
376
|
-
startOfCurrentWeek.setDate(now.getDate() - now.getDay());
|
|
377
|
-
store.contributions.forEach((contribution) => {
|
|
378
|
-
const contributionDate = new Date(contribution.date);
|
|
379
|
-
const dayOfWeek = contributionDate.getDay();
|
|
380
|
-
const weeksAgo = Math.floor((+startOfCurrentWeek - +contributionDate) / (1000 * 60 * 60 * 24 * 7));
|
|
381
|
-
if (weeksAgo >= 0 && weeksAgo < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH && dayOfWeek >= 0 && dayOfWeek < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT) {
|
|
382
|
-
store.grid[_constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH - 1 - weeksAgo][dayOfWeek] = { commitsCount: contribution.count, intensity: 0 };
|
|
383
|
-
if (contribution.count > maxCommits)
|
|
384
|
-
maxCommits = contribution.count;
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH; x++) {
|
|
388
|
-
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT; y++) {
|
|
389
|
-
if (store.grid[x][y].commitsCount > 0) {
|
|
390
|
-
store.grid[x][y].intensity = store.grid[x][y].commitsCount / maxCommits;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH; x++) {
|
|
395
|
-
const weeksAgo = _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH - 1 - x;
|
|
396
|
-
const columnDate = new Date(startOfCurrentWeek);
|
|
397
|
-
columnDate.setDate(columnDate.getDate() - weeksAgo * 7);
|
|
398
|
-
store.monthLabels[x] = _constants__WEBPACK_IMPORTED_MODULE_1__.MONTHS[columnDate.getMonth()];
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
const placePacman = (store) => {
|
|
402
|
-
store.pacman = {
|
|
403
|
-
x: 0,
|
|
404
|
-
y: 0,
|
|
405
|
-
direction: 'right',
|
|
406
|
-
points: 0,
|
|
407
|
-
totalPoints: 0,
|
|
408
|
-
deadRemainingDuration: 0,
|
|
409
|
-
powerupRemainingDuration: 0,
|
|
410
|
-
recentPositions: []
|
|
411
|
-
};
|
|
412
|
-
if (store.config.outputFormat == 'canvas')
|
|
413
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawPacman(store);
|
|
414
|
-
};
|
|
415
|
-
const placeGhosts = (store) => {
|
|
416
|
-
store.ghosts = [];
|
|
417
|
-
// Center gjosts in mid grid
|
|
418
|
-
store.ghosts.push({ x: 23, y: 3, name: _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_NAMES[0], scared: false, target: undefined });
|
|
419
|
-
store.ghosts.push({ x: 24, y: 3, name: _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_NAMES[1], scared: false, target: undefined });
|
|
420
|
-
store.ghosts.push({ x: 27, y: 3, name: _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_NAMES[2], scared: false, target: undefined });
|
|
421
|
-
store.ghosts.push({ x: 28, y: 3, name: _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_NAMES[3], scared: false, target: undefined });
|
|
422
|
-
if (store.config.outputFormat == 'canvas')
|
|
423
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGhosts(store);
|
|
424
|
-
};
|
|
425
|
-
const stopGame = (store) => __awaiter(void 0, void 0, void 0, function* () {
|
|
426
|
-
clearInterval(store.gameInterval);
|
|
427
|
-
});
|
|
428
|
-
const startGame = (store) => __awaiter(void 0, void 0, void 0, function* () {
|
|
429
|
-
if (store.config.outputFormat == 'canvas') {
|
|
430
|
-
store.config.canvas = store.config.canvas;
|
|
431
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.resizeCanvas(store);
|
|
432
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.listenToSoundController(store);
|
|
433
|
-
}
|
|
434
|
-
store.frameCount = 0;
|
|
435
|
-
store.ghosts.forEach((ghost) => (ghost.scared = false));
|
|
436
|
-
initializeGrid(store);
|
|
437
|
-
if (store.config.outputFormat == 'canvas')
|
|
438
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGrid(store);
|
|
439
|
-
if (store.config.outputFormat == 'canvas') {
|
|
440
|
-
if (!store.config.enableSounds) {
|
|
441
|
-
_music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance().mute();
|
|
442
|
-
}
|
|
443
|
-
yield _music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance().preloadSounds();
|
|
444
|
-
_music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance().startDefaultSound();
|
|
445
|
-
yield _music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance().play(_music_player__WEBPACK_IMPORTED_MODULE_4__.Sound.BEGINNING);
|
|
446
|
-
}
|
|
447
|
-
const remainingCells = () => store.grid.some((row) => row.some((cell) => cell.intensity > 0));
|
|
448
|
-
if (remainingCells()) {
|
|
449
|
-
placePacman(store);
|
|
450
|
-
placeGhosts(store);
|
|
451
|
-
}
|
|
452
|
-
if (store.config.outputFormat == 'svg') {
|
|
453
|
-
while (remainingCells()) {
|
|
454
|
-
yield updateGame(store);
|
|
455
|
-
}
|
|
456
|
-
// One more time to generate svg
|
|
457
|
-
yield updateGame(store);
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
460
|
-
clearInterval(store.gameInterval);
|
|
461
|
-
store.gameInterval = setInterval(() => __awaiter(void 0, void 0, void 0, function* () { return yield updateGame(store); }), _constants__WEBPACK_IMPORTED_MODULE_1__.DELTA_TIME);
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
const updateGame = (store) => __awaiter(void 0, void 0, void 0, function* () {
|
|
465
|
-
store.frameCount++;
|
|
466
|
-
if (store.frameCount % store.config.gameSpeed !== 0) {
|
|
467
|
-
store.gameHistory.push({
|
|
468
|
-
pacman: Object.assign({}, store.pacman),
|
|
469
|
-
ghosts: store.ghosts.map((ghost) => (Object.assign({}, ghost))),
|
|
470
|
-
grid: store.grid.map((row) => [...row.map((col) => col.intensity)])
|
|
471
|
-
});
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
if (store.pacman.deadRemainingDuration) {
|
|
475
|
-
store.pacman.deadRemainingDuration--;
|
|
476
|
-
if (!store.pacman.deadRemainingDuration) {
|
|
477
|
-
// IT'S ALIVE!
|
|
478
|
-
placeGhosts(store);
|
|
479
|
-
if (store.config.outputFormat == 'canvas')
|
|
480
|
-
_music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance()
|
|
481
|
-
.play(_music_player__WEBPACK_IMPORTED_MODULE_4__.Sound.GAME_OVER)
|
|
482
|
-
.then(() => _music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance().startDefaultSound());
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
if (store.pacman.powerupRemainingDuration) {
|
|
486
|
-
store.pacman.powerupRemainingDuration--;
|
|
487
|
-
if (!store.pacman.powerupRemainingDuration) {
|
|
488
|
-
store.ghosts.forEach((ghost) => (ghost.scared = false));
|
|
489
|
-
store.pacman.points = 0;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
const remainingCells = store.grid.some((row) => row.some((cell) => cell.intensity > 0));
|
|
493
|
-
if (!remainingCells) {
|
|
494
|
-
if (store.config.outputFormat == 'canvas') {
|
|
495
|
-
clearInterval(store.gameInterval);
|
|
496
|
-
if (store.config.outputFormat == 'canvas') {
|
|
497
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.renderGameOver(store);
|
|
498
|
-
_music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance()
|
|
499
|
-
.play(_music_player__WEBPACK_IMPORTED_MODULE_4__.Sound.BEGINNING)
|
|
500
|
-
.then(() => _music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance().stopDefaultSound());
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
if (store.config.outputFormat == 'svg') {
|
|
504
|
-
const animatedSVG = _svg__WEBPACK_IMPORTED_MODULE_5__.SVG.generateAnimatedSVG(store);
|
|
505
|
-
store.config.svgCallback(animatedSVG);
|
|
506
|
-
}
|
|
507
|
-
store.config.gameOverCallback();
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
_movement_pacman_movement__WEBPACK_IMPORTED_MODULE_3__.PacmanMovement.movePacman(store);
|
|
511
|
-
checkCollisions(store);
|
|
512
|
-
if (!store.pacman.deadRemainingDuration) {
|
|
513
|
-
_movement_ghosts_movement__WEBPACK_IMPORTED_MODULE_2__.GhostsMovement.moveGhosts(store);
|
|
514
|
-
checkCollisions(store);
|
|
515
|
-
}
|
|
516
|
-
store.pacmanMouthOpen = !store.pacmanMouthOpen;
|
|
517
|
-
store.gameHistory.push({
|
|
518
|
-
pacman: Object.assign({}, store.pacman),
|
|
519
|
-
ghosts: store.ghosts.map((ghost) => (Object.assign({}, ghost))),
|
|
520
|
-
grid: store.grid.map((row) => [...row.map((col) => col.intensity)])
|
|
521
|
-
});
|
|
522
|
-
if (store.config.outputFormat == 'canvas')
|
|
523
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGrid(store);
|
|
524
|
-
if (store.config.outputFormat == 'canvas')
|
|
525
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawPacman(store);
|
|
526
|
-
if (store.config.outputFormat == 'canvas')
|
|
527
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawGhosts(store);
|
|
528
|
-
if (store.config.outputFormat == 'canvas')
|
|
529
|
-
_canvas__WEBPACK_IMPORTED_MODULE_0__.Canvas.drawSoundController(store);
|
|
530
|
-
});
|
|
531
|
-
const checkCollisions = (store) => {
|
|
532
|
-
if (store.pacman.deadRemainingDuration)
|
|
533
|
-
return;
|
|
534
|
-
store.ghosts.forEach((ghost, index) => {
|
|
535
|
-
if (ghost.x === store.pacman.x && ghost.y === store.pacman.y) {
|
|
536
|
-
if (store.pacman.powerupRemainingDuration && ghost.scared) {
|
|
537
|
-
respawnGhost(store, index);
|
|
538
|
-
store.pacman.points += 10;
|
|
539
|
-
if (store.config.outputFormat == 'canvas') {
|
|
540
|
-
_music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance().play(_music_player__WEBPACK_IMPORTED_MODULE_4__.Sound.EAT_GHOST);
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
else {
|
|
544
|
-
store.pacman.points = 0;
|
|
545
|
-
store.pacman.powerupRemainingDuration = 0;
|
|
546
|
-
store.pacman.deadRemainingDuration = _constants__WEBPACK_IMPORTED_MODULE_1__.PACMAN_DEATH_DURATION;
|
|
547
|
-
if (store.config.outputFormat == 'canvas') {
|
|
548
|
-
_music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance()
|
|
549
|
-
.play(_music_player__WEBPACK_IMPORTED_MODULE_4__.Sound.GAME_OVER)
|
|
550
|
-
.then(() => _music_player__WEBPACK_IMPORTED_MODULE_4__.MusicPlayer.getInstance().stopDefaultSound());
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
};
|
|
556
|
-
const respawnGhost = (store, ghostIndex) => {
|
|
557
|
-
let x, y;
|
|
558
|
-
do {
|
|
559
|
-
x = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_WIDTH);
|
|
560
|
-
y = Math.floor(Math.random() * _constants__WEBPACK_IMPORTED_MODULE_1__.GRID_HEIGHT);
|
|
561
|
-
} while ((Math.abs(x - store.pacman.x) <= 2 && Math.abs(y - store.pacman.y) <= 2) || store.grid[x][y].intensity === 0);
|
|
562
|
-
store.ghosts[ghostIndex] = {
|
|
563
|
-
x,
|
|
564
|
-
y,
|
|
565
|
-
name: _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_NAMES[ghostIndex % _constants__WEBPACK_IMPORTED_MODULE_1__.GHOST_NAMES.length],
|
|
566
|
-
scared: false,
|
|
567
|
-
target: undefined
|
|
568
|
-
};
|
|
569
|
-
};
|
|
570
|
-
const Game = {
|
|
571
|
-
startGame,
|
|
572
|
-
stopGame
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
/***/ }),
|
|
577
|
-
|
|
578
|
-
/***/ "./src/grid.ts":
|
|
579
|
-
/*!*********************!*\
|
|
580
|
-
!*** ./src/grid.ts ***!
|
|
581
|
-
\*********************/
|
|
582
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
583
|
-
|
|
584
|
-
__webpack_require__.r(__webpack_exports__);
|
|
585
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
586
|
-
/* harmony export */ Grid: () => (/* binding */ Grid)
|
|
587
|
-
/* harmony export */ });
|
|
588
|
-
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
|
|
589
|
-
|
|
590
|
-
const setSymmetricWall = (x, y, direction, sym, lineId) => {
|
|
591
|
-
if (direction == 'horizontal') {
|
|
592
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(x, y, 'horizontal', lineId);
|
|
593
|
-
if (sym == 'x') {
|
|
594
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(_constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH - x - 1, y, 'horizontal', lineId);
|
|
595
|
-
}
|
|
596
|
-
else if (sym == 'y') {
|
|
597
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(x, _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - y, 'horizontal', lineId);
|
|
598
|
-
}
|
|
599
|
-
else if (sym == 'xy') {
|
|
600
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(_constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH - x - 1, y, 'horizontal', lineId);
|
|
601
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(x, _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - y, 'horizontal', lineId);
|
|
602
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(_constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH - x - 1, _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - y, 'horizontal', lineId);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
else {
|
|
606
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(x, y, 'vertical', lineId);
|
|
607
|
-
if (sym == 'x') {
|
|
608
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(_constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH - x, y, 'vertical', lineId);
|
|
609
|
-
}
|
|
610
|
-
else if (sym == 'y') {
|
|
611
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(x, _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - y - 1, 'vertical', lineId);
|
|
612
|
-
}
|
|
613
|
-
else if (sym == 'xy') {
|
|
614
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(_constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH - x, y, 'vertical', lineId);
|
|
615
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(x, _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - y - 1, 'vertical', lineId);
|
|
616
|
-
(0,_constants__WEBPACK_IMPORTED_MODULE_0__.setWall)(_constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH - x, _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - y - 1, 'vertical', lineId);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
const buildWalls = () => {
|
|
621
|
-
// Left and right wings
|
|
622
|
-
// L1
|
|
623
|
-
setSymmetricWall(0, 2, 'horizontal', 'xy', 'L1');
|
|
624
|
-
setSymmetricWall(1, 2, 'horizontal', 'xy', 'L1');
|
|
625
|
-
// L2
|
|
626
|
-
setSymmetricWall(4, 0, 'vertical', 'x', 'L2');
|
|
627
|
-
setSymmetricWall(4, 1, 'vertical', 'x', 'L2');
|
|
628
|
-
setSymmetricWall(4, 2, 'vertical', 'x', 'L2');
|
|
629
|
-
setSymmetricWall(4, 3, 'vertical', 'x', 'L2');
|
|
630
|
-
setSymmetricWall(4, 4, 'vertical', 'x', 'L2');
|
|
631
|
-
// L3
|
|
632
|
-
setSymmetricWall(3, 3, 'horizontal', 'x', 'L3');
|
|
633
|
-
setSymmetricWall(2, 3, 'horizontal', 'x', 'L3');
|
|
634
|
-
// L4
|
|
635
|
-
setSymmetricWall(4, 5, 'horizontal', 'x', 'L4');
|
|
636
|
-
// L5
|
|
637
|
-
setSymmetricWall(6, 4, 'vertical', 'x', 'L5');
|
|
638
|
-
setSymmetricWall(6, 3, 'vertical', 'x', 'L5');
|
|
639
|
-
setSymmetricWall(6, 2, 'vertical', 'x', 'L5');
|
|
640
|
-
// L6
|
|
641
|
-
setSymmetricWall(6, 2, 'horizontal', 'x', 'L6');
|
|
642
|
-
setSymmetricWall(7, 2, 'horizontal', 'x', 'L6');
|
|
643
|
-
setSymmetricWall(8, 2, 'horizontal', 'x', 'L6');
|
|
644
|
-
setSymmetricWall(9, 2, 'horizontal', 'x', 'L6');
|
|
645
|
-
// L7
|
|
646
|
-
setSymmetricWall(13, 2, 'horizontal', 'xy', 'L7');
|
|
647
|
-
setSymmetricWall(14, 2, 'horizontal', 'xy', 'L7');
|
|
648
|
-
setSymmetricWall(15, 2, 'horizontal', 'xy', 'L7');
|
|
649
|
-
setSymmetricWall(16, 2, 'horizontal', 'xy', 'L7');
|
|
650
|
-
setSymmetricWall(17, 2, 'horizontal', 'xy', 'L7');
|
|
651
|
-
setSymmetricWall(18, 2, 'horizontal', 'xy', 'L7');
|
|
652
|
-
// L8
|
|
653
|
-
setSymmetricWall(16, 2, 'vertical', 'xy', 'L8');
|
|
654
|
-
// L9
|
|
655
|
-
setSymmetricWall(8, 1, 'horizontal', 'x', 'L9');
|
|
656
|
-
setSymmetricWall(9, 1, 'horizontal', 'x', 'L9');
|
|
657
|
-
setSymmetricWall(10, 1, 'horizontal', 'x', 'L9');
|
|
658
|
-
setSymmetricWall(11, 1, 'horizontal', 'x', 'L9');
|
|
659
|
-
// L10
|
|
660
|
-
setSymmetricWall(12, 1, 'vertical', 'x', 'L10');
|
|
661
|
-
setSymmetricWall(12, 3, 'vertical', 'x', 'L10');
|
|
662
|
-
// L11
|
|
663
|
-
setSymmetricWall(11, 4, 'horizontal', 'x', 'L11');
|
|
664
|
-
setSymmetricWall(10, 4, 'horizontal', 'x', 'L11');
|
|
665
|
-
setSymmetricWall(9, 4, 'horizontal', 'x', 'L11');
|
|
666
|
-
setSymmetricWall(8, 4, 'horizontal', 'x', 'L11');
|
|
667
|
-
// L12
|
|
668
|
-
setSymmetricWall(8, 4, 'vertical', 'x', 'L12');
|
|
669
|
-
setSymmetricWall(8, 5, 'vertical', 'x', 'L12');
|
|
670
|
-
setSymmetricWall(8, 6, 'vertical', 'x', 'L12');
|
|
671
|
-
// L13
|
|
672
|
-
setSymmetricWall(23, 2, 'horizontal', 'x', 'L13');
|
|
673
|
-
setSymmetricWall(24, 2, 'horizontal', 'x', 'L13');
|
|
674
|
-
setSymmetricWall(23, 4, 'horizontal', 'x', 'L13');
|
|
675
|
-
setSymmetricWall(24, 4, 'horizontal', 'x', 'L13');
|
|
676
|
-
setSymmetricWall(25, 4, 'horizontal', 'x', 'L13');
|
|
677
|
-
// L14
|
|
678
|
-
setSymmetricWall(23, 2, 'vertical', 'x', 'L14');
|
|
679
|
-
setSymmetricWall(23, 3, 'vertical', 'x', 'L14');
|
|
680
|
-
// L15
|
|
681
|
-
setSymmetricWall(26, 4, 'vertical', 'x', 'L15');
|
|
682
|
-
setSymmetricWall(26, 5, 'vertical', 'x', 'L15');
|
|
683
|
-
// L16
|
|
684
|
-
setSymmetricWall(23, 6, 'horizontal', 'x', 'L16');
|
|
685
|
-
setSymmetricWall(24, 6, 'horizontal', 'x', 'L16');
|
|
686
|
-
setSymmetricWall(25, 6, 'horizontal', 'x', 'L16');
|
|
687
|
-
// L17
|
|
688
|
-
setSymmetricWall(26, 0, 'vertical', 'x', 'L17');
|
|
689
|
-
// L18
|
|
690
|
-
setSymmetricWall(24, 1, 'vertical', 'x', 'L18');
|
|
691
|
-
setSymmetricWall(23, 1, 'horizontal', 'x', 'L18');
|
|
692
|
-
setSymmetricWall(22, 1, 'horizontal', 'x', 'L18');
|
|
693
|
-
setSymmetricWall(21, 1, 'horizontal', 'x', 'L18');
|
|
694
|
-
setSymmetricWall(21, 1, 'vertical', 'x', 'L18');
|
|
695
|
-
setSymmetricWall(21, 2, 'vertical', 'x', 'L18');
|
|
696
|
-
setSymmetricWall(21, 3, 'vertical', 'x', 'L18');
|
|
697
|
-
setSymmetricWall(20, 4, 'horizontal', 'x', 'L18');
|
|
698
|
-
setSymmetricWall(19, 4, 'horizontal', 'x', 'L18');
|
|
699
|
-
setSymmetricWall(19, 3, 'vertical', 'x', 'L18');
|
|
700
|
-
setSymmetricWall(18, 3, 'horizontal', 'x', 'L18');
|
|
701
|
-
// L19
|
|
702
|
-
setSymmetricWall(22, 5, 'vertical', 'x', 'L19');
|
|
703
|
-
setSymmetricWall(21, 5, 'horizontal', 'x', 'L19');
|
|
704
|
-
setSymmetricWall(20, 5, 'horizontal', 'x', 'L19');
|
|
705
|
-
setSymmetricWall(20, 5, 'vertical', 'x', 'L19');
|
|
706
|
-
// L20
|
|
707
|
-
setSymmetricWall(1, 6, 'horizontal', 'x', 'L20');
|
|
708
|
-
setSymmetricWall(2, 6, 'horizontal', 'x', 'L20');
|
|
709
|
-
setSymmetricWall(3, 5, 'vertical', 'x', 'L20');
|
|
710
|
-
setSymmetricWall(3, 4, 'vertical', 'x', 'L20');
|
|
711
|
-
// L21
|
|
712
|
-
setSymmetricWall(5, 6, 'horizontal', 'x', 'L21');
|
|
713
|
-
setSymmetricWall(6, 6, 'horizontal', 'x', 'L21');
|
|
714
|
-
};
|
|
715
|
-
const Grid = {
|
|
716
|
-
buildWalls
|
|
717
|
-
};
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
/***/ }),
|
|
721
|
-
|
|
722
|
-
/***/ "./src/movement/ghosts-movement.ts":
|
|
723
|
-
/*!*****************************************!*\
|
|
724
|
-
!*** ./src/movement/ghosts-movement.ts ***!
|
|
725
|
-
\*****************************************/
|
|
726
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
727
|
-
|
|
728
|
-
__webpack_require__.r(__webpack_exports__);
|
|
729
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
730
|
-
/* harmony export */ GhostsMovement: () => (/* binding */ GhostsMovement)
|
|
731
|
-
/* harmony export */ });
|
|
732
|
-
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants.ts");
|
|
733
|
-
/* harmony import */ var _movement_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./movement-utils */ "./src/movement/movement-utils.ts");
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
const moveGhosts = (store) => {
|
|
737
|
-
store.ghosts.forEach((ghost) => {
|
|
738
|
-
if (ghost.scared || Math.random() < 0.15) {
|
|
739
|
-
moveScaredGhost(ghost, store);
|
|
740
|
-
}
|
|
741
|
-
else {
|
|
742
|
-
moveGhostWithPersonality(ghost, store);
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
};
|
|
746
|
-
// When scared, ghosts move randomly but with some intelligence
|
|
747
|
-
const moveScaredGhost = (ghost, store) => {
|
|
748
|
-
if (!ghost.target || (ghost.x === ghost.target.x && ghost.y === ghost.target.y)) {
|
|
749
|
-
ghost.target = getRandomDestination(ghost.x, ghost.y);
|
|
750
|
-
}
|
|
751
|
-
const validMoves = _movement_utils__WEBPACK_IMPORTED_MODULE_1__.MovementUtils.getValidMoves(ghost.x, ghost.y);
|
|
752
|
-
if (validMoves.length === 0)
|
|
753
|
-
return;
|
|
754
|
-
// Move toward target but with some randomness to appear "scared"
|
|
755
|
-
const dx = ghost.target.x - ghost.x;
|
|
756
|
-
const dy = ghost.target.y - ghost.y;
|
|
757
|
-
// Filter moves that generally go toward the target
|
|
758
|
-
let possibleMoves = validMoves.filter((move) => {
|
|
759
|
-
const moveX = move[0];
|
|
760
|
-
const moveY = move[1];
|
|
761
|
-
return (dx > 0 && moveX > 0) || (dx < 0 && moveX < 0) || (dy > 0 && moveY > 0) || (dy < 0 && moveY < 0);
|
|
762
|
-
});
|
|
763
|
-
// If no valid moves toward target, use any valid move
|
|
764
|
-
if (possibleMoves.length === 0) {
|
|
765
|
-
possibleMoves = validMoves;
|
|
766
|
-
}
|
|
767
|
-
// Choose a random move from the possible moves
|
|
768
|
-
const [moveX, moveY] = possibleMoves[Math.floor(Math.random() * possibleMoves.length)];
|
|
769
|
-
// If Pacman has power-up, ghosts move slower
|
|
770
|
-
if (store.pacman.powerupRemainingDuration && Math.random() < 0.5)
|
|
771
|
-
return;
|
|
772
|
-
ghost.x += moveX;
|
|
773
|
-
ghost.y += moveY;
|
|
774
|
-
};
|
|
775
|
-
// Move ghost according to its personality
|
|
776
|
-
const moveGhostWithPersonality = (ghost, store) => {
|
|
777
|
-
const target = calculateGhostTarget(ghost, store);
|
|
778
|
-
ghost.target = target;
|
|
779
|
-
const nextMove = BFSTargetLocation(ghost.x, ghost.y, target.x, target.y);
|
|
780
|
-
if (nextMove) {
|
|
781
|
-
ghost.x = nextMove.x;
|
|
782
|
-
ghost.y = nextMove.y;
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
// Find the next position to move to using BFS
|
|
786
|
-
const BFSTargetLocation = (startX, startY, targetX, targetY) => {
|
|
787
|
-
// If we're already at the target, no need to move
|
|
788
|
-
if (startX === targetX && startY === targetY)
|
|
789
|
-
return null;
|
|
790
|
-
const queue = [{ x: startX, y: startY, path: [] }];
|
|
791
|
-
const visited = new Set();
|
|
792
|
-
visited.add(`${startX},${startY}`);
|
|
793
|
-
while (queue.length > 0) {
|
|
794
|
-
const current = queue.shift();
|
|
795
|
-
const { x, y, path } = current;
|
|
796
|
-
const validMoves = _movement_utils__WEBPACK_IMPORTED_MODULE_1__.MovementUtils.getValidMoves(x, y);
|
|
797
|
-
for (const [dx, dy] of validMoves) {
|
|
798
|
-
const newX = x + dx;
|
|
799
|
-
const newY = y + dy;
|
|
800
|
-
const key = `${newX},${newY}`;
|
|
801
|
-
if (visited.has(key))
|
|
802
|
-
continue;
|
|
803
|
-
visited.add(key);
|
|
804
|
-
const newPath = [...path, { x: newX, y: newY }];
|
|
805
|
-
if (newX === targetX && newY === targetY) {
|
|
806
|
-
return newPath.length > 0 ? newPath[0] : null;
|
|
807
|
-
}
|
|
808
|
-
queue.push({ x: newX, y: newY, path: newPath });
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
// If no path found, no need to move
|
|
812
|
-
return null;
|
|
813
|
-
};
|
|
814
|
-
// Calculate ghost target based on personality
|
|
815
|
-
const calculateGhostTarget = (ghost, store) => {
|
|
816
|
-
const { pacman } = store;
|
|
817
|
-
let pacDirection = [0, 0];
|
|
818
|
-
switch (ghost.name) {
|
|
819
|
-
case 'blinky': // Red ghost - directly targets Pacman
|
|
820
|
-
return { x: pacman.x, y: pacman.y };
|
|
821
|
-
case 'pinky': // Pink ghost - targets 4 spaces ahead of Pacman
|
|
822
|
-
pacDirection = getPacmanDirection(store);
|
|
823
|
-
const lookAhead = 4;
|
|
824
|
-
let fourAhead = {
|
|
825
|
-
x: pacman.x + pacDirection[0] * lookAhead,
|
|
826
|
-
y: pacman.y + pacDirection[1] * lookAhead
|
|
827
|
-
};
|
|
828
|
-
fourAhead.x = Math.min(Math.max(fourAhead.x, 0), _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH - 1);
|
|
829
|
-
fourAhead.y = Math.min(Math.max(fourAhead.y, 0), _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - 1);
|
|
830
|
-
return fourAhead;
|
|
831
|
-
case 'inky': // Blue ghost - complex targeting based on Blinky's position
|
|
832
|
-
const blinky = store.ghosts.find((g) => g.name === 'blinky');
|
|
833
|
-
pacDirection = getPacmanDirection(store);
|
|
834
|
-
// Target is 2 spaces ahead of Pacman
|
|
835
|
-
let twoAhead = {
|
|
836
|
-
x: pacman.x + pacDirection[0] * 2,
|
|
837
|
-
y: pacman.y + pacDirection[1] * 2
|
|
838
|
-
};
|
|
839
|
-
// Then double the vector from Blinky to that position
|
|
840
|
-
if (blinky) {
|
|
841
|
-
twoAhead = {
|
|
842
|
-
x: twoAhead.x + (twoAhead.x - blinky.x),
|
|
843
|
-
y: twoAhead.y + (twoAhead.y - blinky.y)
|
|
844
|
-
};
|
|
845
|
-
}
|
|
846
|
-
twoAhead.x = Math.min(Math.max(twoAhead.x, 0), _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH - 1);
|
|
847
|
-
twoAhead.y = Math.min(Math.max(twoAhead.y, 0), _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - 1);
|
|
848
|
-
return twoAhead;
|
|
849
|
-
case 'clyde': // Orange ghost - targets Pacman when far, runs away when close
|
|
850
|
-
const distanceToPacman = _movement_utils__WEBPACK_IMPORTED_MODULE_1__.MovementUtils.calculateDistance(ghost.x, ghost.y, pacman.x, pacman.y);
|
|
851
|
-
if (distanceToPacman > 8) {
|
|
852
|
-
return { x: pacman.x, y: pacman.y };
|
|
853
|
-
}
|
|
854
|
-
else {
|
|
855
|
-
return { x: 0, y: _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - 1 };
|
|
856
|
-
}
|
|
857
|
-
default:
|
|
858
|
-
// Default behavior targets Pacman directly
|
|
859
|
-
return { x: pacman.x, y: pacman.y };
|
|
860
|
-
}
|
|
861
|
-
};
|
|
862
|
-
const getPacmanDirection = (store) => {
|
|
863
|
-
switch (store.pacman.direction) {
|
|
864
|
-
case 'right':
|
|
865
|
-
return [1, 0];
|
|
866
|
-
case 'left':
|
|
867
|
-
return [-1, 0];
|
|
868
|
-
case 'up':
|
|
869
|
-
return [0, -1];
|
|
870
|
-
case 'down':
|
|
871
|
-
return [0, 1];
|
|
872
|
-
default:
|
|
873
|
-
return [0, 0];
|
|
874
|
-
}
|
|
875
|
-
};
|
|
876
|
-
// Get a random destination for scared ghosts
|
|
877
|
-
const getRandomDestination = (x, y) => {
|
|
878
|
-
const maxDistance = 8;
|
|
879
|
-
const randomX = x + Math.floor(Math.random() * (2 * maxDistance + 1)) - maxDistance;
|
|
880
|
-
const randomY = y + Math.floor(Math.random() * (2 * maxDistance + 1)) - maxDistance;
|
|
881
|
-
return {
|
|
882
|
-
x: Math.max(0, Math.min(randomX, _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH - 1)),
|
|
883
|
-
y: Math.max(0, Math.min(randomY, _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT - 1))
|
|
884
|
-
};
|
|
885
|
-
};
|
|
886
|
-
const GhostsMovement = {
|
|
887
|
-
moveGhosts
|
|
888
|
-
};
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
/***/ }),
|
|
892
|
-
|
|
893
|
-
/***/ "./src/movement/movement-utils.ts":
|
|
894
|
-
/*!****************************************!*\
|
|
895
|
-
!*** ./src/movement/movement-utils.ts ***!
|
|
896
|
-
\****************************************/
|
|
897
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
898
|
-
|
|
899
|
-
__webpack_require__.r(__webpack_exports__);
|
|
900
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
901
|
-
/* harmony export */ MovementUtils: () => (/* binding */ MovementUtils)
|
|
902
|
-
/* harmony export */ });
|
|
903
|
-
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants.ts");
|
|
904
|
-
|
|
905
|
-
// Check for walls and grid edges
|
|
906
|
-
const getValidMoves = (x, y) => {
|
|
907
|
-
const directions = [
|
|
908
|
-
[-1, 0],
|
|
909
|
-
[1, 0],
|
|
910
|
-
[0, -1],
|
|
911
|
-
[0, 1] // down
|
|
912
|
-
];
|
|
913
|
-
return directions.filter(([dx, dy]) => {
|
|
914
|
-
const newX = x + dx;
|
|
915
|
-
const newY = y + dy;
|
|
916
|
-
if (newX < 0 || newX >= _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH || newY < 0 || newY >= _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT) {
|
|
917
|
-
return false;
|
|
918
|
-
}
|
|
919
|
-
if (dx === -1) {
|
|
920
|
-
return !_constants__WEBPACK_IMPORTED_MODULE_0__.WALLS.vertical[x][y].active;
|
|
921
|
-
}
|
|
922
|
-
else if (dx === 1) {
|
|
923
|
-
return !_constants__WEBPACK_IMPORTED_MODULE_0__.WALLS.vertical[x + 1][y].active;
|
|
924
|
-
}
|
|
925
|
-
else if (dy === -1) {
|
|
926
|
-
return !_constants__WEBPACK_IMPORTED_MODULE_0__.WALLS.horizontal[x][y].active;
|
|
927
|
-
}
|
|
928
|
-
else if (dy === 1) {
|
|
929
|
-
return !_constants__WEBPACK_IMPORTED_MODULE_0__.WALLS.horizontal[x][y + 1].active;
|
|
930
|
-
}
|
|
931
|
-
return true;
|
|
932
|
-
});
|
|
933
|
-
};
|
|
934
|
-
const calculateDistance = (x1, y1, x2, y2) => {
|
|
935
|
-
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
|
936
|
-
};
|
|
937
|
-
const MovementUtils = {
|
|
938
|
-
getValidMoves,
|
|
939
|
-
calculateDistance
|
|
940
|
-
};
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
/***/ }),
|
|
944
|
-
|
|
945
|
-
/***/ "./src/movement/pacman-movement.ts":
|
|
946
|
-
/*!*****************************************!*\
|
|
947
|
-
!*** ./src/movement/pacman-movement.ts ***!
|
|
948
|
-
\*****************************************/
|
|
949
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
950
|
-
|
|
951
|
-
__webpack_require__.r(__webpack_exports__);
|
|
952
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
953
|
-
/* harmony export */ PacmanMovement: () => (/* binding */ PacmanMovement)
|
|
954
|
-
/* harmony export */ });
|
|
955
|
-
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants.ts");
|
|
956
|
-
/* harmony import */ var _movement_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./movement-utils */ "./src/movement/movement-utils.ts");
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
const RECENT_POSITIONS_LIMIT = 5;
|
|
960
|
-
const movePacman = (store) => {
|
|
961
|
-
if (store.pacman.deadRemainingDuration) {
|
|
962
|
-
return;
|
|
963
|
-
}
|
|
964
|
-
const hasPowerup = !!store.pacman.powerupRemainingDuration;
|
|
965
|
-
const scaredGhosts = store.ghosts.filter((ghost) => ghost.scared);
|
|
966
|
-
let targetPosition;
|
|
967
|
-
if (hasPowerup && scaredGhosts.length > 0) {
|
|
968
|
-
const ghostPosition = findClosestScaredGhost(store);
|
|
969
|
-
if (ghostPosition) {
|
|
970
|
-
targetPosition = ghostPosition;
|
|
971
|
-
}
|
|
972
|
-
else {
|
|
973
|
-
targetPosition = findOptimalTarget(store);
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
else if (store.pacman.target) {
|
|
977
|
-
if (store.pacman.target.x == store.pacman.x && store.pacman.target.y == store.pacman.y) {
|
|
978
|
-
targetPosition = findOptimalTarget(store);
|
|
979
|
-
store.pacman.target = { x: targetPosition === null || targetPosition === void 0 ? void 0 : targetPosition.x, y: targetPosition === null || targetPosition === void 0 ? void 0 : targetPosition.y };
|
|
980
|
-
}
|
|
981
|
-
else {
|
|
982
|
-
targetPosition = store.pacman.target;
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
else {
|
|
986
|
-
targetPosition = findOptimalTarget(store);
|
|
987
|
-
store.pacman.target = { x: targetPosition === null || targetPosition === void 0 ? void 0 : targetPosition.x, y: targetPosition === null || targetPosition === void 0 ? void 0 : targetPosition.y };
|
|
988
|
-
}
|
|
989
|
-
const nextPosition = calculateOptimalPath(store, targetPosition);
|
|
990
|
-
if (nextPosition) {
|
|
991
|
-
updatePacmanPosition(store, nextPosition);
|
|
992
|
-
}
|
|
993
|
-
else {
|
|
994
|
-
makeDesperationMove(store);
|
|
995
|
-
}
|
|
996
|
-
checkAndEatPoint(store);
|
|
997
|
-
};
|
|
998
|
-
const findClosestScaredGhost = (store) => {
|
|
999
|
-
const scaredGhosts = store.ghosts.filter((ghost) => ghost.scared);
|
|
1000
|
-
if (scaredGhosts.length === 0)
|
|
1001
|
-
return null;
|
|
1002
|
-
return scaredGhosts.reduce((closest, ghost) => {
|
|
1003
|
-
const distance = _movement_utils__WEBPACK_IMPORTED_MODULE_1__.MovementUtils.calculateDistance(ghost.x, ghost.y, store.pacman.x, store.pacman.y);
|
|
1004
|
-
return distance < closest.distance ? { x: ghost.x, y: ghost.y, distance } : closest;
|
|
1005
|
-
}, { x: store.pacman.x, y: store.pacman.y, distance: Infinity });
|
|
1006
|
-
};
|
|
1007
|
-
const findOptimalTarget = (store) => {
|
|
1008
|
-
let pointCells = [];
|
|
1009
|
-
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; x++) {
|
|
1010
|
-
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT; y++) {
|
|
1011
|
-
if (store.grid[x][y].intensity > 0) {
|
|
1012
|
-
const distance = _movement_utils__WEBPACK_IMPORTED_MODULE_1__.MovementUtils.calculateDistance(x, y, store.pacman.x, store.pacman.y);
|
|
1013
|
-
const value = store.grid[x][y].intensity / (distance + 1);
|
|
1014
|
-
pointCells.push({ x, y, value });
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
pointCells.sort((a, b) => b.value - a.value);
|
|
1019
|
-
return pointCells[0];
|
|
1020
|
-
};
|
|
1021
|
-
const calculateOptimalPath = (store, target) => {
|
|
1022
|
-
var _a;
|
|
1023
|
-
const queue = [
|
|
1024
|
-
{ x: store.pacman.x, y: store.pacman.y, path: [], score: 0 }
|
|
1025
|
-
];
|
|
1026
|
-
const visited = new Set();
|
|
1027
|
-
visited.add(`${store.pacman.x},${store.pacman.y}`);
|
|
1028
|
-
const dangerMap = createDangerMap(store);
|
|
1029
|
-
while (queue.length > 0) {
|
|
1030
|
-
queue.sort((a, b) => b.score - a.score);
|
|
1031
|
-
const current = queue.shift();
|
|
1032
|
-
const { x, y, path } = current;
|
|
1033
|
-
if (x === target.x && y === target.y) {
|
|
1034
|
-
return path.length > 0 ? path[0] : null;
|
|
1035
|
-
}
|
|
1036
|
-
const validMoves = _movement_utils__WEBPACK_IMPORTED_MODULE_1__.MovementUtils.getValidMoves(x, y);
|
|
1037
|
-
for (const [dx, dy] of validMoves) {
|
|
1038
|
-
const newX = x + dx;
|
|
1039
|
-
const newY = y + dy;
|
|
1040
|
-
const key = `${newX},${newY}`;
|
|
1041
|
-
if (!visited.has(key)) {
|
|
1042
|
-
const newPath = [...path, { x: newX, y: newY }];
|
|
1043
|
-
const danger = dangerMap.get(key) || 0;
|
|
1044
|
-
const pointValue = store.grid[newX][newY].intensity;
|
|
1045
|
-
const distanceToTarget = _movement_utils__WEBPACK_IMPORTED_MODULE_1__.MovementUtils.calculateDistance(newX, newY, target.x, target.y);
|
|
1046
|
-
let revisitPenalty = 0;
|
|
1047
|
-
if ((_a = store.pacman.recentPositions) === null || _a === void 0 ? void 0 : _a.includes(key)) {
|
|
1048
|
-
revisitPenalty += 100; // Penalize recently visited positions
|
|
1049
|
-
}
|
|
1050
|
-
queue.push({
|
|
1051
|
-
x: newX,
|
|
1052
|
-
y: newY,
|
|
1053
|
-
path: newPath,
|
|
1054
|
-
score: pointValue - danger - distanceToTarget / 10 - revisitPenalty
|
|
1055
|
-
});
|
|
1056
|
-
visited.add(key);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
return null;
|
|
1061
|
-
};
|
|
1062
|
-
const createDangerMap = (store) => {
|
|
1063
|
-
const dangerMap = new Map();
|
|
1064
|
-
const hasPowerup = !!store.pacman.powerupRemainingDuration;
|
|
1065
|
-
store.ghosts.forEach((ghost) => {
|
|
1066
|
-
if (ghost.scared)
|
|
1067
|
-
return;
|
|
1068
|
-
for (let dx = -5; dx <= 5; dx++) {
|
|
1069
|
-
for (let dy = -5; dy <= 5; dy++) {
|
|
1070
|
-
const x = ghost.x + dx;
|
|
1071
|
-
const y = ghost.y + dy;
|
|
1072
|
-
if (x >= 0 && x < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH && y >= 0 && y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT) {
|
|
1073
|
-
const key = `${x},${y}`;
|
|
1074
|
-
const distance = Math.abs(dx) + Math.abs(dy);
|
|
1075
|
-
const dangerValue = 15 - distance;
|
|
1076
|
-
if (dangerValue > 0) {
|
|
1077
|
-
const currentDanger = dangerMap.get(key) || 0;
|
|
1078
|
-
dangerMap.set(key, Math.max(currentDanger, dangerValue));
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1084
|
-
if (hasPowerup) {
|
|
1085
|
-
for (const [key, value] of dangerMap.entries()) {
|
|
1086
|
-
dangerMap.set(key, value / 5);
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
return dangerMap;
|
|
1090
|
-
};
|
|
1091
|
-
const makeDesperationMove = (store) => {
|
|
1092
|
-
const validMoves = _movement_utils__WEBPACK_IMPORTED_MODULE_1__.MovementUtils.getValidMoves(store.pacman.x, store.pacman.y);
|
|
1093
|
-
if (validMoves.length === 0)
|
|
1094
|
-
return;
|
|
1095
|
-
const safestMove = validMoves.reduce((safest, [dx, dy]) => {
|
|
1096
|
-
const newX = store.pacman.x + dx;
|
|
1097
|
-
const newY = store.pacman.y + dy;
|
|
1098
|
-
let minGhostDistance = Infinity;
|
|
1099
|
-
store.ghosts.forEach((ghost) => {
|
|
1100
|
-
if (!ghost.scared) {
|
|
1101
|
-
const distance = _movement_utils__WEBPACK_IMPORTED_MODULE_1__.MovementUtils.calculateDistance(ghost.x, ghost.y, newX, newY);
|
|
1102
|
-
minGhostDistance = Math.min(minGhostDistance, distance);
|
|
1103
|
-
}
|
|
1104
|
-
});
|
|
1105
|
-
return minGhostDistance > safest.distance ? { dx, dy, distance: minGhostDistance } : safest;
|
|
1106
|
-
}, { dx: 0, dy: 0, distance: -Infinity });
|
|
1107
|
-
const newX = store.pacman.x + safestMove.dx;
|
|
1108
|
-
const newY = store.pacman.y + safestMove.dy;
|
|
1109
|
-
updatePacmanPosition(store, { x: newX, y: newY });
|
|
1110
|
-
};
|
|
1111
|
-
const updatePacmanPosition = (store, position) => {
|
|
1112
|
-
var _a;
|
|
1113
|
-
(_a = store.pacman).recentPositions || (_a.recentPositions = []);
|
|
1114
|
-
store.pacman.recentPositions.push(`${position.x},${position.y}`);
|
|
1115
|
-
if (store.pacman.recentPositions.length > RECENT_POSITIONS_LIMIT) {
|
|
1116
|
-
store.pacman.recentPositions.shift();
|
|
1117
|
-
}
|
|
1118
|
-
const dx = position.x - store.pacman.x;
|
|
1119
|
-
const dy = position.y - store.pacman.y;
|
|
1120
|
-
if (dx > 0)
|
|
1121
|
-
store.pacman.direction = 'right';
|
|
1122
|
-
else if (dx < 0)
|
|
1123
|
-
store.pacman.direction = 'left';
|
|
1124
|
-
else if (dy > 0)
|
|
1125
|
-
store.pacman.direction = 'down';
|
|
1126
|
-
else if (dy < 0)
|
|
1127
|
-
store.pacman.direction = 'up';
|
|
1128
|
-
store.pacman.x = position.x;
|
|
1129
|
-
store.pacman.y = position.y;
|
|
1130
|
-
};
|
|
1131
|
-
const checkAndEatPoint = (store) => {
|
|
1132
|
-
if (store.grid[store.pacman.x][store.pacman.y].intensity > 0) {
|
|
1133
|
-
store.pacman.totalPoints += store.grid[store.pacman.x][store.pacman.y].commitsCount;
|
|
1134
|
-
store.pacman.points++;
|
|
1135
|
-
store.config.pointsIncreasedCallback(store.pacman.totalPoints);
|
|
1136
|
-
store.grid[store.pacman.x][store.pacman.y].intensity = 0;
|
|
1137
|
-
if (store.pacman.points >= 10)
|
|
1138
|
-
activatePowerUp(store);
|
|
1139
|
-
}
|
|
1140
|
-
};
|
|
1141
|
-
const activatePowerUp = (store) => {
|
|
1142
|
-
store.pacman.powerupRemainingDuration = _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_POWERUP_DURATION;
|
|
1143
|
-
store.ghosts.forEach((ghost) => (ghost.scared = true));
|
|
1144
|
-
};
|
|
1145
|
-
const PacmanMovement = {
|
|
1146
|
-
movePacman
|
|
1147
|
-
};
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
/***/ }),
|
|
1151
|
-
|
|
1152
|
-
/***/ "./src/music-player.ts":
|
|
1153
|
-
/*!*****************************!*\
|
|
1154
|
-
!*** ./src/music-player.ts ***!
|
|
1155
|
-
\*****************************/
|
|
1156
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1157
|
-
|
|
1158
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1159
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1160
|
-
/* harmony export */ MusicPlayer: () => (/* binding */ MusicPlayer),
|
|
1161
|
-
/* harmony export */ Sound: () => (/* binding */ Sound)
|
|
1162
|
-
/* harmony export */ });
|
|
1163
|
-
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1164
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1165
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1166
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1167
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1168
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1169
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1170
|
-
});
|
|
1171
|
-
};
|
|
1172
|
-
var Sound;
|
|
1173
|
-
(function (Sound) {
|
|
1174
|
-
Sound["DEFAULT"] = "https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_chomp.wav";
|
|
1175
|
-
Sound["BEGINNING"] = "https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_beginning.wav";
|
|
1176
|
-
Sound["GAME_OVER"] = "https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_death.wav";
|
|
1177
|
-
Sound["EAT_GHOST"] = "https://cdn.jsdelivr.net/npm/pacman-contribution-graph/src/assets/sounds/pacman_eatghost.wav";
|
|
1178
|
-
})(Sound || (Sound = {}));
|
|
1179
|
-
class MusicPlayer {
|
|
1180
|
-
constructor() {
|
|
1181
|
-
this.sounds = new Map();
|
|
1182
|
-
this.currentSource = null;
|
|
1183
|
-
this.defaultSource = null;
|
|
1184
|
-
this.isMuted = false;
|
|
1185
|
-
this.audioContext = new AudioContext();
|
|
1186
|
-
}
|
|
1187
|
-
static getInstance() {
|
|
1188
|
-
if (!MusicPlayer.instance) {
|
|
1189
|
-
MusicPlayer.instance = new MusicPlayer();
|
|
1190
|
-
}
|
|
1191
|
-
return MusicPlayer.instance;
|
|
1192
|
-
}
|
|
1193
|
-
preloadSounds() {
|
|
1194
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1195
|
-
for (const sound of Object.values(Sound)) {
|
|
1196
|
-
const response = yield fetch(sound);
|
|
1197
|
-
const arrayBuffer = yield response.arrayBuffer();
|
|
1198
|
-
const audioBuffer = yield this.audioContext.decodeAudioData(arrayBuffer);
|
|
1199
|
-
this.sounds.set(sound, audioBuffer);
|
|
1200
|
-
}
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
|
-
play(sound) {
|
|
1204
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1205
|
-
if (this.isMuted) {
|
|
1206
|
-
return;
|
|
1207
|
-
}
|
|
1208
|
-
if (this.currentSource) {
|
|
1209
|
-
try {
|
|
1210
|
-
this.currentSource.stop();
|
|
1211
|
-
}
|
|
1212
|
-
catch (ex) { }
|
|
1213
|
-
}
|
|
1214
|
-
const buffer = this.sounds.get(sound);
|
|
1215
|
-
if (!buffer) {
|
|
1216
|
-
console.error(`Sound ${sound} not found`);
|
|
1217
|
-
return;
|
|
1218
|
-
}
|
|
1219
|
-
this.currentSource = this.audioContext.createBufferSource();
|
|
1220
|
-
this.currentSource.buffer = buffer;
|
|
1221
|
-
this.currentSource.connect(this.audioContext.destination);
|
|
1222
|
-
if (!this.isMuted) {
|
|
1223
|
-
this.currentSource.start();
|
|
1224
|
-
}
|
|
1225
|
-
return new Promise((resolve) => {
|
|
1226
|
-
this.currentSource.onended = () => {
|
|
1227
|
-
this.currentSource = null;
|
|
1228
|
-
resolve();
|
|
1229
|
-
};
|
|
1230
|
-
});
|
|
1231
|
-
});
|
|
1232
|
-
}
|
|
1233
|
-
startDefaultSound() {
|
|
1234
|
-
if (this.defaultSource) {
|
|
1235
|
-
try {
|
|
1236
|
-
this.defaultSource.stop();
|
|
1237
|
-
}
|
|
1238
|
-
catch (ex) { }
|
|
1239
|
-
}
|
|
1240
|
-
const buffer = this.sounds.get(Sound.DEFAULT);
|
|
1241
|
-
if (!buffer) {
|
|
1242
|
-
console.error('Default sound not found');
|
|
1243
|
-
return;
|
|
1244
|
-
}
|
|
1245
|
-
this.defaultSource = this.audioContext.createBufferSource();
|
|
1246
|
-
this.defaultSource.buffer = buffer;
|
|
1247
|
-
this.defaultSource.loop = true;
|
|
1248
|
-
this.defaultSource.connect(this.audioContext.destination);
|
|
1249
|
-
if (!this.isMuted) {
|
|
1250
|
-
this.defaultSource.start();
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
stopDefaultSound() {
|
|
1254
|
-
if (this.defaultSource) {
|
|
1255
|
-
try {
|
|
1256
|
-
this.defaultSource.stop();
|
|
1257
|
-
}
|
|
1258
|
-
catch (ex) { }
|
|
1259
|
-
this.defaultSource = null;
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
mute() {
|
|
1263
|
-
this.isMuted = true;
|
|
1264
|
-
if (this.currentSource) {
|
|
1265
|
-
this.currentSource.disconnect();
|
|
1266
|
-
}
|
|
1267
|
-
if (this.defaultSource) {
|
|
1268
|
-
this.defaultSource.disconnect();
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
unmute() {
|
|
1272
|
-
this.isMuted = false;
|
|
1273
|
-
if (this.currentSource) {
|
|
1274
|
-
this.currentSource.connect(this.audioContext.destination);
|
|
1275
|
-
}
|
|
1276
|
-
if (this.defaultSource) {
|
|
1277
|
-
this.defaultSource.connect(this.audioContext.destination);
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
/***/ }),
|
|
1284
|
-
|
|
1285
|
-
/***/ "./src/store.ts":
|
|
1286
|
-
/*!**********************!*\
|
|
1287
|
-
!*** ./src/store.ts ***!
|
|
1288
|
-
\**********************/
|
|
1289
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1290
|
-
|
|
1291
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1292
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1293
|
-
/* harmony export */ Store: () => (/* binding */ Store)
|
|
1294
|
-
/* harmony export */ });
|
|
1295
|
-
const Store = {
|
|
1296
|
-
frameCount: 0,
|
|
1297
|
-
contributions: [],
|
|
1298
|
-
pacman: {
|
|
1299
|
-
x: 0,
|
|
1300
|
-
y: 0,
|
|
1301
|
-
direction: 'right',
|
|
1302
|
-
points: 0,
|
|
1303
|
-
totalPoints: 0,
|
|
1304
|
-
deadRemainingDuration: 0,
|
|
1305
|
-
powerupRemainingDuration: 0,
|
|
1306
|
-
recentPositions: []
|
|
1307
|
-
},
|
|
1308
|
-
ghosts: [],
|
|
1309
|
-
grid: [],
|
|
1310
|
-
monthLabels: [],
|
|
1311
|
-
pacmanMouthOpen: true,
|
|
1312
|
-
gameInterval: 0,
|
|
1313
|
-
gameHistory: [],
|
|
1314
|
-
config: undefined
|
|
1315
|
-
};
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
/***/ }),
|
|
1319
|
-
|
|
1320
|
-
/***/ "./src/svg.ts":
|
|
1321
|
-
/*!********************!*\
|
|
1322
|
-
!*** ./src/svg.ts ***!
|
|
1323
|
-
\********************/
|
|
1324
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1325
|
-
|
|
1326
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1327
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1328
|
-
/* harmony export */ SVG: () => (/* binding */ SVG)
|
|
1329
|
-
/* harmony export */ });
|
|
1330
|
-
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
|
|
1331
|
-
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
const generateAnimatedSVG = (store) => {
|
|
1335
|
-
const svgWidth = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
1336
|
-
const svgHeight = _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 20;
|
|
1337
|
-
let svg = `<svg width="${svgWidth}" height="${svgHeight}" xmlns="http://www.w3.org/2000/svg">`;
|
|
1338
|
-
svg += `<desc>Generated with https://github.com/abozanona/pacman-contribution-graph on ${new Date()}</desc>`;
|
|
1339
|
-
svg += `<rect width="100%" height="100%" fill="${_utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).gridBackground}"/>`;
|
|
1340
|
-
svg += generateGhostsPredefinition();
|
|
1341
|
-
// Month labels
|
|
1342
|
-
let lastMonth = '';
|
|
1343
|
-
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; y++) {
|
|
1344
|
-
if (store.monthLabels[y] !== lastMonth) {
|
|
1345
|
-
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;
|
|
1346
|
-
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>`;
|
|
1347
|
-
lastMonth = store.monthLabels[y];
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
// Grid
|
|
1351
|
-
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; x++) {
|
|
1352
|
-
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT; y++) {
|
|
1353
|
-
const cellX = x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
1354
|
-
const cellY = y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
|
|
1355
|
-
const cellColorAnimation = generateChangingValuesAnimation(store, generateCellColorValues(store, x, y));
|
|
1356
|
-
svg += `<rect id="c-${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="${_utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).emptyContributionBoxColor}">
|
|
1357
|
-
<animate attributeName="fill" dur="${store.gameHistory.length * _constants__WEBPACK_IMPORTED_MODULE_0__.DELTA_TIME}ms" repeatCount="indefinite"
|
|
1358
|
-
values="${cellColorAnimation.values}"
|
|
1359
|
-
keyTimes="${cellColorAnimation.keyTimes}"/>
|
|
1360
|
-
</rect>`;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
// Walls
|
|
1364
|
-
for (let x = 0; x < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_WIDTH; x++) {
|
|
1365
|
-
for (let y = 0; y < _constants__WEBPACK_IMPORTED_MODULE_0__.GRID_HEIGHT; y++) {
|
|
1366
|
-
if (_constants__WEBPACK_IMPORTED_MODULE_0__.WALLS.horizontal[x][y].active) {
|
|
1367
|
-
svg += `<rect id="wh-${x}-${y}" x="${x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) - _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE}" y="${y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) - _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE + 15}" width="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE}" height="${_constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE}" rx="5" fill="${_utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).wallColor}"></rect>`;
|
|
1368
|
-
}
|
|
1369
|
-
if (_constants__WEBPACK_IMPORTED_MODULE_0__.WALLS.vertical[x][y].active) {
|
|
1370
|
-
svg += `<rect id="wv-${x}-${y}" x="${x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) - _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE}" y="${y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) - _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE + 15}" width="${_constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE}" height="${_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE}" rx="5" fill="${_utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).wallColor}"></rect>`;
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
|
-
// Pacman
|
|
1375
|
-
const pacmanColorAnimation = generateChangingValuesAnimation(store, generatePacManColors(store));
|
|
1376
|
-
const pacmanPositionAnimation = generateChangingValuesAnimation(store, generatePacManPositions(store));
|
|
1377
|
-
const pacmanRotationAnimation = generateChangingValuesAnimation(store, generatePacManRotations(store));
|
|
1378
|
-
svg += `<path id="pacman" d="${generatePacManPath(0.55)}"
|
|
1379
|
-
>
|
|
1380
|
-
<animate attributeName="fill" dur="${store.gameHistory.length * _constants__WEBPACK_IMPORTED_MODULE_0__.DELTA_TIME}ms" repeatCount="indefinite"
|
|
1381
|
-
keyTimes="${pacmanColorAnimation.keyTimes}"
|
|
1382
|
-
values="${pacmanColorAnimation.values}"/>
|
|
1383
|
-
<animateTransform attributeName="transform" type="translate" dur="${store.gameHistory.length * _constants__WEBPACK_IMPORTED_MODULE_0__.DELTA_TIME}ms" repeatCount="indefinite"
|
|
1384
|
-
keyTimes="${pacmanPositionAnimation.keyTimes}"
|
|
1385
|
-
values="${pacmanPositionAnimation.values}"
|
|
1386
|
-
additive="sum"/>
|
|
1387
|
-
<animateTransform attributeName="transform" type="rotate" dur="${store.gameHistory.length * _constants__WEBPACK_IMPORTED_MODULE_0__.DELTA_TIME}ms" repeatCount="indefinite"
|
|
1388
|
-
keyTimes="${pacmanRotationAnimation.keyTimes}"
|
|
1389
|
-
values="${pacmanRotationAnimation.values}"
|
|
1390
|
-
additive="sum"/>
|
|
1391
|
-
<animate attributeName="d" dur="0.5s" repeatCount="indefinite"
|
|
1392
|
-
values="${generatePacManPath(0.55)};${generatePacManPath(0.05)};${generatePacManPath(0.55)}"/>
|
|
1393
|
-
</path>`;
|
|
1394
|
-
// Ghosts
|
|
1395
|
-
store.ghosts.forEach((ghost, index) => {
|
|
1396
|
-
const ghostPositionAnimation = generateChangingValuesAnimation(store, generateGhostPositions(store, index));
|
|
1397
|
-
const ghostColorAnimation = generateChangingValuesAnimation(store, generateGhostColors(store, index));
|
|
1398
|
-
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}">
|
|
1399
|
-
<animateTransform attributeName="transform" type="translate" dur="${store.gameHistory.length * _constants__WEBPACK_IMPORTED_MODULE_0__.DELTA_TIME}ms" repeatCount="indefinite"
|
|
1400
|
-
keyTimes="${ghostPositionAnimation.keyTimes}"
|
|
1401
|
-
values="${ghostPositionAnimation.values}"/>
|
|
1402
|
-
<animate attributeName="href" dur="${store.gameHistory.length * _constants__WEBPACK_IMPORTED_MODULE_0__.DELTA_TIME}ms" repeatCount="indefinite"
|
|
1403
|
-
keyTimes="${ghostColorAnimation.keyTimes}"
|
|
1404
|
-
values="${ghostColorAnimation.values}"/>
|
|
1405
|
-
</use>`;
|
|
1406
|
-
});
|
|
1407
|
-
svg += '</svg>';
|
|
1408
|
-
return svg;
|
|
1409
|
-
};
|
|
1410
|
-
const generatePacManPath = (mouthAngle) => {
|
|
1411
|
-
const radius = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
1412
|
-
const startAngle = mouthAngle;
|
|
1413
|
-
const endAngle = 2 * Math.PI - mouthAngle;
|
|
1414
|
-
return `M ${radius},${radius}
|
|
1415
|
-
L ${radius + radius * Math.cos(startAngle)},${radius + radius * Math.sin(startAngle)}
|
|
1416
|
-
A ${radius},${radius} 0 1,1 ${radius + radius * Math.cos(endAngle)},${radius + radius * Math.sin(endAngle)}
|
|
1417
|
-
Z`;
|
|
1418
|
-
};
|
|
1419
|
-
const generatePacManPositions = (store) => {
|
|
1420
|
-
return store.gameHistory.map((state) => {
|
|
1421
|
-
const x = state.pacman.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
1422
|
-
const y = state.pacman.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
|
|
1423
|
-
return `${x},${y}`;
|
|
1424
|
-
});
|
|
1425
|
-
};
|
|
1426
|
-
const generatePacManRotations = (store) => {
|
|
1427
|
-
const pivit = _constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE / 2;
|
|
1428
|
-
return store.gameHistory.map((state) => {
|
|
1429
|
-
switch (state.pacman.direction) {
|
|
1430
|
-
case 'right':
|
|
1431
|
-
return `0 ${pivit} ${pivit}`;
|
|
1432
|
-
case 'left':
|
|
1433
|
-
return `180 ${pivit} ${pivit}`;
|
|
1434
|
-
case 'up':
|
|
1435
|
-
return `270 ${pivit} ${pivit}`;
|
|
1436
|
-
case 'down':
|
|
1437
|
-
return `90 ${pivit} ${pivit}`;
|
|
1438
|
-
default:
|
|
1439
|
-
return `0 ${pivit} ${pivit}`;
|
|
1440
|
-
}
|
|
1441
|
-
});
|
|
1442
|
-
};
|
|
1443
|
-
const generatePacManColors = (store) => {
|
|
1444
|
-
return store.gameHistory.map((state) => {
|
|
1445
|
-
if (state.pacman.deadRemainingDuration) {
|
|
1446
|
-
return _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_DEAD;
|
|
1447
|
-
}
|
|
1448
|
-
else if (state.pacman.powerupRemainingDuration) {
|
|
1449
|
-
return _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR_POWERUP;
|
|
1450
|
-
}
|
|
1451
|
-
else {
|
|
1452
|
-
return _constants__WEBPACK_IMPORTED_MODULE_0__.PACMAN_COLOR;
|
|
1453
|
-
}
|
|
1454
|
-
});
|
|
1455
|
-
};
|
|
1456
|
-
const generateCellColorValues = (store, x, y) => {
|
|
1457
|
-
return store.gameHistory.map((state) => {
|
|
1458
|
-
const intensity = state.grid[x][y];
|
|
1459
|
-
if (intensity > 0) {
|
|
1460
|
-
const adjustedIntensity = intensity < 0.2 ? 0.3 : intensity;
|
|
1461
|
-
return _utils__WEBPACK_IMPORTED_MODULE_1__.Utils.hexToHexAlpha(_utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).contributionBoxColor, adjustedIntensity);
|
|
1462
|
-
}
|
|
1463
|
-
else {
|
|
1464
|
-
return _utils__WEBPACK_IMPORTED_MODULE_1__.Utils.getCurrentTheme(store).emptyContributionBoxColor;
|
|
1465
|
-
}
|
|
1466
|
-
});
|
|
1467
|
-
};
|
|
1468
|
-
const generateGhostPositions = (store, ghostIndex) => {
|
|
1469
|
-
return store.gameHistory.map((state) => {
|
|
1470
|
-
const ghost = state.ghosts[ghostIndex];
|
|
1471
|
-
const x = ghost.x * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE);
|
|
1472
|
-
const y = ghost.y * (_constants__WEBPACK_IMPORTED_MODULE_0__.CELL_SIZE + _constants__WEBPACK_IMPORTED_MODULE_0__.GAP_SIZE) + 15;
|
|
1473
|
-
return `${x},${y}`;
|
|
1474
|
-
});
|
|
1475
|
-
};
|
|
1476
|
-
const generateGhostColors = (store, ghostIndex) => {
|
|
1477
|
-
return store.gameHistory.map((state) => {
|
|
1478
|
-
const ghost = state.ghosts[ghostIndex];
|
|
1479
|
-
return '#' + (ghost.scared ? ghostShort('scared') : ghostShort(ghost.name));
|
|
1480
|
-
});
|
|
1481
|
-
};
|
|
1482
|
-
const generateGhostsPredefinition = () => {
|
|
1483
|
-
return `<defs>
|
|
1484
|
-
<symbol id="${ghostShort('blinky')}" viewBox="0 0 100 100">
|
|
1485
|
-
<image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['blinky'].imgDate}" width="100" height="100"/>
|
|
1486
|
-
</symbol>
|
|
1487
|
-
<symbol id="${ghostShort('clyde')}" viewBox="0 0 100 100">
|
|
1488
|
-
<image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['clyde'].imgDate}" width="100" height="100"/>
|
|
1489
|
-
</symbol>
|
|
1490
|
-
<symbol id="${ghostShort('inky')}" viewBox="0 0 100 100">
|
|
1491
|
-
<image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['inky'].imgDate}" width="100" height="100"/>
|
|
1492
|
-
</symbol>
|
|
1493
|
-
<symbol id="${ghostShort('pinky')}" viewBox="0 0 100 100">
|
|
1494
|
-
<image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['pinky'].imgDate}" width="100" height="100"/>
|
|
1495
|
-
</symbol>
|
|
1496
|
-
<symbol id="${ghostShort('scared')}" viewBox="0 0 100 100">
|
|
1497
|
-
<image href="${_constants__WEBPACK_IMPORTED_MODULE_0__.GHOSTS['scared'].imgDate}" width="100" height="100"/>
|
|
1498
|
-
</symbol>
|
|
1499
|
-
</defs>`;
|
|
1500
|
-
};
|
|
1501
|
-
const ghostShort = (ghostName) => {
|
|
1502
|
-
switch (ghostName) {
|
|
1503
|
-
case 'blinky':
|
|
1504
|
-
return 'gb';
|
|
1505
|
-
case 'clyde':
|
|
1506
|
-
return 'gc';
|
|
1507
|
-
case 'inky':
|
|
1508
|
-
return 'gi';
|
|
1509
|
-
case 'pinky':
|
|
1510
|
-
return 'gp';
|
|
1511
|
-
case 'scared':
|
|
1512
|
-
return 'gs';
|
|
1513
|
-
default:
|
|
1514
|
-
return ghostName;
|
|
1515
|
-
}
|
|
1516
|
-
};
|
|
1517
|
-
const generateChangingValuesAnimation = (store, changingValues) => {
|
|
1518
|
-
if (store.gameHistory.length !== changingValues.length) {
|
|
1519
|
-
throw new Error('The length of changingValues must match the length of gameHistory');
|
|
1520
|
-
}
|
|
1521
|
-
const totalFrames = store.gameHistory.length;
|
|
1522
|
-
let keyTimes = [];
|
|
1523
|
-
let values = [];
|
|
1524
|
-
let lastValue = null;
|
|
1525
|
-
let lastIndex = null;
|
|
1526
|
-
changingValues.forEach((currentValue, index) => {
|
|
1527
|
-
if (currentValue !== lastValue) {
|
|
1528
|
-
if (lastValue !== null && lastIndex !== null && index - 1 !== lastIndex) {
|
|
1529
|
-
// Add a keyframe right before the value change
|
|
1530
|
-
keyTimes.push(Number(((index - 0.000001) / (totalFrames - 1)).toFixed(6)));
|
|
1531
|
-
values.push(lastValue);
|
|
1532
|
-
}
|
|
1533
|
-
// Add the new value keyframe
|
|
1534
|
-
keyTimes.push(Number((index / (totalFrames - 1)).toFixed(6)));
|
|
1535
|
-
values.push(currentValue);
|
|
1536
|
-
lastValue = currentValue;
|
|
1537
|
-
lastIndex = index;
|
|
1538
|
-
}
|
|
1539
|
-
});
|
|
1540
|
-
// Ensure the last frame is always included
|
|
1541
|
-
if (keyTimes[keyTimes.length - 1] !== 1) {
|
|
1542
|
-
keyTimes.push(1);
|
|
1543
|
-
values.push(lastValue);
|
|
1544
|
-
}
|
|
1545
|
-
return {
|
|
1546
|
-
keyTimes: keyTimes.join(';'),
|
|
1547
|
-
values: values.join(';')
|
|
1548
|
-
};
|
|
1549
|
-
};
|
|
1550
|
-
const SVG = {
|
|
1551
|
-
generateAnimatedSVG
|
|
1552
|
-
};
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
/***/ }),
|
|
1556
|
-
|
|
1557
|
-
/***/ "./src/utils.ts":
|
|
1558
|
-
/*!**********************!*\
|
|
1559
|
-
!*** ./src/utils.ts ***!
|
|
1560
|
-
\**********************/
|
|
1561
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
1562
|
-
|
|
1563
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1564
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1565
|
-
/* harmony export */ Utils: () => (/* binding */ Utils)
|
|
1566
|
-
/* harmony export */ });
|
|
1567
|
-
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
|
|
1568
|
-
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1569
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1570
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1571
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1572
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1573
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1574
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1575
|
-
});
|
|
1576
|
-
};
|
|
1577
|
-
|
|
1578
|
-
const getGitlabContribution = (store) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1579
|
-
// const response = await fetch(`https://gitlab.com/users/${username}/calendar.json`);
|
|
1580
|
-
const response = yield fetch(`https://v0-new-project-q1hhrdodoye-abozanona-gmailcoms-projects.vercel.app/api/contributions?username=${store.config.username}`);
|
|
1581
|
-
const contributionsList = yield response.json();
|
|
1582
|
-
return Object.entries(contributionsList).map(([date, count]) => ({
|
|
1583
|
-
date: new Date(date),
|
|
1584
|
-
count: Number(count)
|
|
1585
|
-
}));
|
|
1586
|
-
});
|
|
1587
|
-
const getGithubContribution = (store) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1588
|
-
var _a;
|
|
1589
|
-
const commits = [];
|
|
1590
|
-
let isComplete = false;
|
|
1591
|
-
let page = 1;
|
|
1592
|
-
// TODO: Consider using GraphQL endpoint when user has an access token?
|
|
1593
|
-
do {
|
|
1594
|
-
try {
|
|
1595
|
-
const headers = {};
|
|
1596
|
-
if ((_a = store.config.githubSettings) === null || _a === void 0 ? void 0 : _a.accessToken) {
|
|
1597
|
-
headers['Authorization'] = 'Bearer ' + store.config.githubSettings.accessToken;
|
|
1598
|
-
}
|
|
1599
|
-
const response = yield fetch(`https://api.github.com/search/commits?q=author:${store.config.username}&sort=author-date&order=desc&page=${page}&per_page=1000`, {
|
|
1600
|
-
headers
|
|
1601
|
-
});
|
|
1602
|
-
const contributionsList = yield response.json();
|
|
1603
|
-
isComplete = contributionsList.items.length === 0;
|
|
1604
|
-
commits.push(...contributionsList.items);
|
|
1605
|
-
page++;
|
|
1606
|
-
}
|
|
1607
|
-
catch (ex) {
|
|
1608
|
-
isComplete = true;
|
|
1609
|
-
}
|
|
1610
|
-
} while (!isComplete);
|
|
1611
|
-
return Array.from(commits
|
|
1612
|
-
.reduce((map, item) => {
|
|
1613
|
-
const dateString = item.commit.committer.date.split('T')[0];
|
|
1614
|
-
const date = new Date(dateString);
|
|
1615
|
-
const count = (map.get(dateString) || { count: 0 }).count + 1;
|
|
1616
|
-
return map.set(dateString, { date, count });
|
|
1617
|
-
}, new Map())
|
|
1618
|
-
.values());
|
|
1619
|
-
});
|
|
1620
|
-
const getCurrentTheme = (store) => {
|
|
1621
|
-
var _a;
|
|
1622
|
-
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'];
|
|
1623
|
-
};
|
|
1624
|
-
const hexToRGBA = (hex, alpha) => {
|
|
1625
|
-
const r = parseInt(hex.slice(1, 3), 16);
|
|
1626
|
-
const g = parseInt(hex.slice(3, 5), 16);
|
|
1627
|
-
const b = parseInt(hex.slice(5, 7), 16);
|
|
1628
|
-
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
1629
|
-
};
|
|
1630
|
-
const hexToHexAlpha = (hex, alpha) => {
|
|
1631
|
-
hex = hex.replace(/^#/, '');
|
|
1632
|
-
if (hex.length === 3) {
|
|
1633
|
-
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
|
|
1634
|
-
}
|
|
1635
|
-
const alphaHex = Math.round(alpha * 255)
|
|
1636
|
-
.toString(16)
|
|
1637
|
-
.padStart(2, '0');
|
|
1638
|
-
return `#${hex}${alphaHex}`;
|
|
1639
|
-
};
|
|
1640
|
-
const Utils = {
|
|
1641
|
-
getGitlabContribution,
|
|
1642
|
-
getGithubContribution,
|
|
1643
|
-
getCurrentTheme,
|
|
1644
|
-
hexToRGBA,
|
|
1645
|
-
hexToHexAlpha
|
|
1646
|
-
};
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
/***/ })
|
|
1650
|
-
|
|
1651
|
-
/******/ });
|
|
1652
|
-
/************************************************************************/
|
|
1653
|
-
/******/ // The module cache
|
|
1654
|
-
/******/ var __webpack_module_cache__ = {};
|
|
1655
|
-
/******/
|
|
1656
|
-
/******/ // The require function
|
|
1657
|
-
/******/ function __webpack_require__(moduleId) {
|
|
1658
|
-
/******/ // Check if module is in cache
|
|
1659
|
-
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
1660
|
-
/******/ if (cachedModule !== undefined) {
|
|
1661
|
-
/******/ return cachedModule.exports;
|
|
1662
|
-
/******/ }
|
|
1663
|
-
/******/ // Create a new module (and put it into the cache)
|
|
1664
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
1665
|
-
/******/ // no module.id needed
|
|
1666
|
-
/******/ // no module.loaded needed
|
|
1667
|
-
/******/ exports: {}
|
|
1668
|
-
/******/ };
|
|
1669
|
-
/******/
|
|
1670
|
-
/******/ // Execute the module function
|
|
1671
|
-
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
1672
|
-
/******/
|
|
1673
|
-
/******/ // Return the exports of the module
|
|
1674
|
-
/******/ return module.exports;
|
|
1675
|
-
/******/ }
|
|
1676
|
-
/******/
|
|
1677
|
-
/************************************************************************/
|
|
1678
|
-
/******/ /* webpack/runtime/define property getters */
|
|
1679
|
-
/******/ (() => {
|
|
1680
|
-
/******/ // define getter functions for harmony exports
|
|
1681
|
-
/******/ __webpack_require__.d = (exports, definition) => {
|
|
1682
|
-
/******/ for(var key in definition) {
|
|
1683
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
1684
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
1685
|
-
/******/ }
|
|
1686
|
-
/******/ }
|
|
1687
|
-
/******/ };
|
|
1688
|
-
/******/ })();
|
|
1689
|
-
/******/
|
|
1690
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
1691
|
-
/******/ (() => {
|
|
1692
|
-
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
1693
|
-
/******/ })();
|
|
1694
|
-
/******/
|
|
1695
|
-
/******/ /* webpack/runtime/make namespace object */
|
|
1696
|
-
/******/ (() => {
|
|
1697
|
-
/******/ // define __esModule on exports
|
|
1698
|
-
/******/ __webpack_require__.r = (exports) => {
|
|
1699
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
1700
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1701
|
-
/******/ }
|
|
1702
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
1703
|
-
/******/ };
|
|
1704
|
-
/******/ })();
|
|
1705
|
-
/******/
|
|
1706
|
-
/************************************************************************/
|
|
1707
|
-
var __webpack_exports__ = {};
|
|
1708
|
-
// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
|
|
1709
|
-
(() => {
|
|
1710
|
-
/*!**********************!*\
|
|
1711
|
-
!*** ./src/index.ts ***!
|
|
1712
|
-
\**********************/
|
|
1713
|
-
__webpack_require__.r(__webpack_exports__);
|
|
1714
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
1715
|
-
/* harmony export */ PacmanRenderer: () => (/* binding */ PacmanRenderer)
|
|
1716
|
-
/* harmony export */ });
|
|
1717
|
-
/* harmony import */ var _game__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./game */ "./src/game.ts");
|
|
1718
|
-
/* harmony import */ var _grid__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./grid */ "./src/grid.ts");
|
|
1719
|
-
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./store */ "./src/store.ts");
|
|
1720
|
-
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
|
|
1721
|
-
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
1722
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1723
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1724
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1725
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1726
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1727
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1728
|
-
});
|
|
1729
|
-
};
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
class PacmanRenderer {
|
|
1735
|
-
constructor(conf) {
|
|
1736
|
-
this.store = structuredClone(_store__WEBPACK_IMPORTED_MODULE_2__.Store);
|
|
1737
|
-
this.conf = Object.assign({}, conf);
|
|
1738
|
-
_grid__WEBPACK_IMPORTED_MODULE_1__.Grid.buildWalls();
|
|
1739
|
-
}
|
|
1740
|
-
start() {
|
|
1741
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1742
|
-
const defaultConfing = {
|
|
1743
|
-
platform: 'github',
|
|
1744
|
-
username: '',
|
|
1745
|
-
canvas: undefined,
|
|
1746
|
-
outputFormat: 'svg',
|
|
1747
|
-
svgCallback: (_) => { },
|
|
1748
|
-
gameOverCallback: () => () => { },
|
|
1749
|
-
gameTheme: 'github',
|
|
1750
|
-
gameSpeed: 1,
|
|
1751
|
-
enableSounds: false,
|
|
1752
|
-
pointsIncreasedCallback: (_) => { }
|
|
1753
|
-
};
|
|
1754
|
-
this.store.config = Object.assign(Object.assign({}, defaultConfing), this.conf);
|
|
1755
|
-
switch (this.conf.platform) {
|
|
1756
|
-
case 'gitlab':
|
|
1757
|
-
this.store.contributions = yield _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getGitlabContribution(this.store);
|
|
1758
|
-
break;
|
|
1759
|
-
case 'github':
|
|
1760
|
-
this.store.contributions = yield _utils__WEBPACK_IMPORTED_MODULE_3__.Utils.getGithubContribution(this.store);
|
|
1761
|
-
break;
|
|
1762
|
-
}
|
|
1763
|
-
_game__WEBPACK_IMPORTED_MODULE_0__.Game.startGame(this.store);
|
|
1764
|
-
});
|
|
1765
|
-
}
|
|
1766
|
-
stop() {
|
|
1767
|
-
_game__WEBPACK_IMPORTED_MODULE_0__.Game.stopGame(this.store);
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
|
|
1771
|
-
})();
|
|
1772
|
-
|
|
1773
|
-
var __webpack_exports__PacmanRenderer = __webpack_exports__.PacmanRenderer;
|
|
1774
|
-
export { __webpack_exports__PacmanRenderer as PacmanRenderer };
|
|
1775
|
-
|
|
1776
|
-
//# sourceMappingURL=pacman-contribution-graph.js.map
|