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.
Files changed (46) hide show
  1. package/README.md +59 -9
  2. package/dist/pacman-contribution-graph.min.js +1 -1
  3. package/package.json +44 -26
  4. package/.prettierrc +0 -8
  5. package/.vscode/extensions.json +0 -5
  6. package/.vscode/settings.json +0 -6
  7. package/assets/packman-demo.png +0 -0
  8. package/dist/pacman-contribution-graph.js +0 -1776
  9. package/dist/pacman-contribution-graph.js.map +0 -1
  10. package/embeded/canvas.html +0 -41
  11. package/github-action/action.yml +0 -16
  12. package/github-action/dist/index.js +0 -26901
  13. package/github-action/package.json +0 -14
  14. package/github-action/pnpm-lock.yaml +0 -77
  15. package/github-action/src/index.js +0 -47
  16. package/index.html +0 -528
  17. package/pacman.abozanona.me/index.js +0 -47
  18. package/pacman.abozanona.me/package.json +0 -8
  19. package/server/api/contributions/route.ts.z +0 -31
  20. package/server/page.zts.z +0 -13
  21. package/src/assets/images/ghosts/blinky.png +0 -0
  22. package/src/assets/images/ghosts/clyde.png +0 -0
  23. package/src/assets/images/ghosts/inky.png +0 -0
  24. package/src/assets/images/ghosts/pinky.png +0 -0
  25. package/src/assets/images/ghosts/scared.png +0 -0
  26. package/src/assets/sounds/pacman_beginning.wav +0 -0
  27. package/src/assets/sounds/pacman_chomp.wav +0 -0
  28. package/src/assets/sounds/pacman_death.wav +0 -0
  29. package/src/assets/sounds/pacman_eatghost.wav +0 -0
  30. package/src/canvas.ts +0 -244
  31. package/src/constants.ts +0 -102
  32. package/src/game.ts +0 -231
  33. package/src/grid.ts +0 -127
  34. package/src/index.ts +0 -48
  35. package/src/movement/ghosts-movement.ts +0 -183
  36. package/src/movement/movement-utils.ts +0 -40
  37. package/src/movement/pacman-movement.ts +0 -230
  38. package/src/music-player.ts +0 -119
  39. package/src/store.ts +0 -23
  40. package/src/svg.ts +0 -254
  41. package/src/types.ts +0 -78
  42. package/src/utils.ts +0 -81
  43. package/tsconfig.json +0 -11
  44. package/webpack.common.js +0 -19
  45. package/webpack.dev.js +0 -23
  46. package/webpack.prod.js +0 -18
@@ -1,14 +0,0 @@
1
- {
2
- "name": "@pacman-contribution-graph/action",
3
- "version": "1.0.0",
4
- "scripts": {
5
- "build": "ncc build src/index.js -o dist --external canvas"
6
- },
7
- "dependencies": {
8
- "@actions/core": "1.10.1",
9
- "pacman-contribution-graph": "^1.0.13"
10
- },
11
- "devDependencies": {
12
- "@vercel/ncc": "^0.38.3"
13
- }
14
- }
@@ -1,77 +0,0 @@
1
- lockfileVersion: '9.0'
2
-
3
- settings:
4
- autoInstallPeers: true
5
- excludeLinksFromLockfile: false
6
-
7
- importers:
8
-
9
- .:
10
- dependencies:
11
- '@actions/core':
12
- specifier: 1.10.1
13
- version: 1.10.1
14
- pacman-contribution-graph:
15
- specifier: ^1.0.13
16
- version: 1.0.13
17
- devDependencies:
18
- '@vercel/ncc':
19
- specifier: ^0.38.3
20
- version: 0.38.3
21
-
22
- packages:
23
-
24
- '@actions/core@1.10.1':
25
- resolution: {integrity: sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==}
26
-
27
- '@actions/http-client@2.2.3':
28
- resolution: {integrity: sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==}
29
-
30
- '@fastify/busboy@2.1.1':
31
- resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==}
32
- engines: {node: '>=14'}
33
-
34
- '@vercel/ncc@0.38.3':
35
- resolution: {integrity: sha512-rnK6hJBS6mwc+Bkab+PGPs9OiS0i/3kdTO+CkI8V0/VrW3vmz7O2Pxjw/owOlmo6PKEIxRSeZKv/kuL9itnpYA==}
36
- hasBin: true
37
-
38
- pacman-contribution-graph@1.0.13:
39
- resolution: {integrity: sha512-SuUau0TvS6yYtfqySWkTh73n9c3sD1+OGW49wlZBy7+y8L36NcvF1E9/02OR5eg5OUZ1k7PA+McbjjjK4u2APA==}
40
-
41
- tunnel@0.0.6:
42
- resolution: {integrity: sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==}
43
- engines: {node: '>=0.6.11 <=0.7.0 || >=0.7.3'}
44
-
45
- undici@5.28.5:
46
- resolution: {integrity: sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==}
47
- engines: {node: '>=14.0'}
48
-
49
- uuid@8.3.2:
50
- resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}
51
- hasBin: true
52
-
53
- snapshots:
54
-
55
- '@actions/core@1.10.1':
56
- dependencies:
57
- '@actions/http-client': 2.2.3
58
- uuid: 8.3.2
59
-
60
- '@actions/http-client@2.2.3':
61
- dependencies:
62
- tunnel: 0.0.6
63
- undici: 5.28.5
64
-
65
- '@fastify/busboy@2.1.1': {}
66
-
67
- '@vercel/ncc@0.38.3': {}
68
-
69
- pacman-contribution-graph@1.0.13: {}
70
-
71
- tunnel@0.0.6: {}
72
-
73
- undici@5.28.5:
74
- dependencies:
75
- '@fastify/busboy': 2.1.1
76
-
77
- uuid@8.3.2: {}
@@ -1,47 +0,0 @@
1
- import * as core from '@actions/core';
2
- import * as fs from 'fs';
3
- import { PacmanRenderer } from 'pacman-contribution-graph';
4
- import * as path from 'path';
5
-
6
- const generateSvg = async (userName, githubToken, theme) => {
7
- return new Promise((resolve, reject) => {
8
- const conf = {
9
- platform: "github",
10
- username: userName,
11
- outputFormat: "svg",
12
- gameSpeed: 1,
13
- gameTheme: theme,
14
- githubSettings: {
15
- accessToken: githubToken
16
- },
17
- svgCallback: (animatedSVG) => {
18
- resolve(animatedSVG);
19
- }
20
- }
21
-
22
- const pr = new PacmanRenderer(conf)
23
- pr.start()
24
- });
25
- }
26
-
27
- (async () => {
28
- try {
29
- let svgContent = ''
30
- const userName = core.getInput('github_user_name');
31
- const githubToken = core.getInput('github_token');
32
- // TODO: Check active users
33
- fetch("https://elec.abozanona.me/github-action-analytics.php?username=" + userName)
34
-
35
- svgContent = await generateSvg(userName, githubToken, "github")
36
- console.log(`💾 writing to dist/pacman-contribution-graph.svg`);
37
- fs.mkdirSync(path.dirname('dist/pacman-contribution-graph.svg'), { recursive: true });
38
- fs.writeFileSync('dist/pacman-contribution-graph.svg', svgContent);
39
-
40
- svgContent = await generateSvg(userName, githubToken, "github-dark")
41
- console.log(`💾 writing to dist/pacman-contribution-graph-dark.svg`);
42
- fs.mkdirSync(path.dirname('dist/pacman-contribution-graph-dark.svg'), { recursive: true });
43
- fs.writeFileSync('dist/pacman-contribution-graph-dark.svg', svgContent);
44
- } catch (e) {
45
- core.setFailed(`Action failed with "${e.message}"`);
46
- }
47
- })();
package/index.html DELETED
@@ -1,528 +0,0 @@
1
- <!doctype html>
2
- <html lang="en" dir="ltr">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <meta name="google-site-verification" content="ETILrgmBZ33RjlxJh-ybUFcIlIyKXyefMvxbxC6LmOU" />
7
- <title>Pac-Man Contributions Game</title>
8
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" />
9
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
10
- <style>
11
- body {
12
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
13
- line-height: 1.6;
14
- color: #333;
15
- padding-top: 60px;
16
- }
17
- .navbar {
18
- background-color: #24292e;
19
- }
20
- .navbar-brand,
21
- .nav-link {
22
- color: #ffffff !important;
23
- }
24
- .jumbotron {
25
- background-color: #f6f8fa;
26
- padding: 2rem;
27
- margin-bottom: 2rem;
28
- }
29
- #canvas,
30
- #svgholder {
31
- max-width: 100%;
32
- height: auto;
33
- }
34
- .section {
35
- margin-bottom: 3rem;
36
- }
37
- pre {
38
- background-color: #f6f8fa;
39
- border: 1px solid #e1e4e8;
40
- border-radius: 6px;
41
- padding: 16px;
42
- overflow: auto;
43
- }
44
- </style>
45
- </head>
46
- <body>
47
- <nav class="navbar navbar-expand-lg fixed-top">
48
- <div class="container">
49
- <a class="navbar-brand" href="https://abozanona.github.io/pacman-contribution-graph/">Pac-Man Contributions</a>
50
- <button
51
- class="navbar-toggler"
52
- type="button"
53
- data-bs-toggle="collapse"
54
- data-bs-target="#navbarNav"
55
- aria-controls="navbarNav"
56
- aria-expanded="false"
57
- aria-label="Toggle navigation"
58
- >
59
- <span class="navbar-toggler-icon"></span>
60
- </button>
61
- <div class="collapse navbar-collapse" id="navbarNav">
62
- <ul class="navbar-nav ms-auto">
63
- <li class="nav-item">
64
- <a class="nav-link" href="https://github.com/abozanona/pacman-contribution-graph/" target="_blank"
65
- ><i class="fab fa-github"></i> GitHub</a
66
- >
67
- </li>
68
- <li class="nav-item">
69
- <a class="nav-link" href="https://buymeacoffee.com/abozanona/" target="_blank"
70
- ><i class="fas fa-coffee"></i> Buy Me a Coffee</a
71
- >
72
- </li>
73
- <li class="nav-item">
74
- <a class="nav-link" href="https://abozanona.me/pacman-contribution-graph/" target="_blank"
75
- ><i class="fas fa-blog"></i> Blog</a
76
- >
77
- </li>
78
- </ul>
79
- </div>
80
- </div>
81
- </nav>
82
-
83
- <div class="container">
84
- <div class="jumbotron">
85
- <h1 class="display-4">Pac-Man Contributions Game</h1>
86
- <p class="lead">Turn your GitHub or GitLab contributions into an interactive Pac-Man game!</p>
87
- <hr class="my-4" />
88
- <p>
89
- This project allows you to visualize your contribution graph as a playable Pac-Man game. Set up your preferences,
90
- generate the game, and have fun while showcasing your coding activity.
91
- </p>
92
- </div>
93
-
94
- <div class="section">
95
- <h2>Game Configuration</h2>
96
- <div class="row">
97
- <div class="col-md-6">
98
- <div class="mb-3">
99
- <label for="platform" class="form-label">Platform</label>
100
- <select id="platform" class="form-select">
101
- <option value="github">GitHub</option>
102
- <option value="gitlab">GitLab</option>
103
- </select>
104
- </div>
105
- </div>
106
- <div class="col-md-6">
107
- <div class="mb-3">
108
- <label for="output" class="form-label">Output format</label>
109
- <select id="output" class="form-select">
110
- <option value="canvas">Canvas</option>
111
- <option value="svg">SVG</option>
112
- </select>
113
- </div>
114
- </div>
115
- </div>
116
- <div class="row">
117
- <div class="col-md-6">
118
- <div class="mb-3">
119
- <label for="username" class="form-label">Username:</label>
120
- <div class="input-group">
121
- <input type="text" id="username" class="form-control" placeholder="Enter Username" />
122
- <img
123
- id="userAvatar"
124
- src=""
125
- alt="User Avatar"
126
- class="img-thumbnail"
127
- style="display: none; width: 40px; height: 40px"
128
- />
129
- </div>
130
- <div id="userNotFound" class="text-danger" style="display: none">User not found</div>
131
- </div>
132
- </div>
133
- <div class="col-md-6">
134
- <div class="mb-3">
135
- <label for="theme" class="form-label">Theme:</label>
136
- <select id="theme" class="form-select">
137
- <option value="github">GitHub</option>
138
- <option value="github-dark">GitHub Dark</option>
139
- <option value="gitlab">GitLab</option>
140
- <option value="gitlab-dark">GitLab Dark</option>
141
- </select>
142
- </div>
143
- </div>
144
- </div>
145
- <div class="mb-5">
146
- <button class="btn btn-secondary mb-1" data-bs-toggle="collapse" data-bs-target="#additionalSettings">
147
- Toggle Additional Settings
148
- </button>
149
- <div id="additionalSettings" class="collapse">
150
- <div class="row">
151
- <div class="col-md-6">
152
- <div class="mb-3">
153
- <label for="enableSounds" class="form-label">Sounds:</label>
154
- <select id="enableSounds" class="form-select">
155
- <option value="disabled">Disabled</option>
156
- <option value="enabled">Enabled</option>
157
- </select>
158
- </div>
159
- </div>
160
- <div class="col-md-6">
161
- <div class="mb-3">
162
- <label for="gameSpeed" class="form-label">Game Speed:</label>
163
- <input type="range" class="form-range" id="gameSpeed" min="1" max="10" value="1" />
164
- <span id="gameSpeedValue">1</span>
165
- </div>
166
- </div>
167
- </div>
168
- <div class="row">
169
- <div class="col-md-6">
170
- <div class="mb-3">
171
- <label for="githubAccessToken" class="form-label"
172
- >Github Access Token(<a target="__blank" href="https://github.com/settings/tokens">Generate one</a
173
- >):
174
- </label>
175
- <input
176
- type="text"
177
- id="githubAccessToken"
178
- class="form-control"
179
- placeholder="Enter Github Access Token"
180
- />
181
- </div>
182
- </div>
183
- </div>
184
- </div>
185
- </div>
186
- <button id="generate" class="btn btn-primary">Generate</button> It might take a second or two
187
- </div>
188
-
189
- <div class="section">
190
- <h2>Game Output</h2>
191
- <canvas id="canvas"></canvas>
192
- <div id="svgContainer" style="display: none">
193
- <img id="svgholder" />
194
- <br />
195
- <button id="downloadSvg" class="btn btn-success mt-3" style="display: none">Download SVG</button>
196
- </div>
197
- <div>Commits count: <span id="points">0</span></div>
198
- </div>
199
-
200
- <div class="section">
201
- <h2>Configuration Options</h2>
202
- <table class="table table-striped table-hover">
203
- <thead>
204
- <tr>
205
- <th>Option</th>
206
- <th>Description</th>
207
- <th>Possible Values</th>
208
- </tr>
209
- </thead>
210
- <tbody>
211
- <tr>
212
- <td><code>platform</code></td>
213
- <td>The platform from which to fetch contribution data</td>
214
- <td><code>github</code>, <code>gitlab</code></td>
215
- </tr>
216
- <tr>
217
- <td><code>outputFormat</code></td>
218
- <td>The format of the game output</td>
219
- <td><code>canvas</code>, <code>svg</code></td>
220
- </tr>
221
- <tr>
222
- <td><code>canvas</code></td>
223
- <td>The canvas element in DOM to render Pacman game into</td>
224
- <td><code>typeof HTMLCanvasElement</code></td>
225
- </tr>
226
- <tr>
227
- <td><code>svgCallback</code></td>
228
- <td>A callback function that will get called when SVG picture is generated</td>
229
- <td><code>(animatedSVG: string) => void</code></td>
230
- </tr>
231
- <tr>
232
- <td><code>gameOverCallback</code></td>
233
- <td>A callback function that will get called when the game is over</td>
234
- <td><code>gameOverCallback: () => void;</code></td>
235
- </tr>
236
- <tr>
237
- <td><code>username</code></td>
238
- <td>The username of the account to fetch contributions from</td>
239
- <td>Any valid GitHub or GitLab username</td>
240
- </tr>
241
- <tr>
242
- <td><code>gameSpeed</code></td>
243
- <td>The speed of the Pac-Man character in the game</td>
244
- <td>1 (fastest) to 10 (slowest)</td>
245
- </tr>
246
- <tr>
247
- <td><code>gameTheme</code></td>
248
- <td>The visual theme of the game</td>
249
- <td><code>github</code>, <code>github-dark</code>, <code>gitlab</code>, <code>gitlab-dark</code></td>
250
- </tr>
251
- <tr>
252
- <td><code>enableSounds</code></td>
253
- <td>Enable or disable game sounds(only in canvas mode)</td>
254
- <td><code>true</code>, <code>false</code></td>
255
- </tr>
256
- </tbody>
257
- </table>
258
- </div>
259
-
260
- <div class="section">
261
- <h2>How to Use</h2>
262
- <h3>Method 1: NPM Package</h3>
263
- <pre><code>npm install pacman-contribution-graph
264
-
265
- import { PacmanRenderer } from 'pacman-contribution-graph';
266
-
267
- const pr = new PacmanRenderer({
268
- platform: 'github',
269
- username: 'yourusername',
270
- canvas: document.getElementById('canvas'),
271
- outputFormat: 'canvas',
272
- gameTheme: 'github'
273
- });
274
- pr.start();
275
- </code></pre>
276
-
277
- <h3>Method 2: Script loading</h3>
278
- <pre><code>&lt;script type="module"&gt;
279
- import { PacmanRenderer } from 'https://cdn.jsdelivr.net/npm/pacman-contribution-graph/dist/pacman-contribution-graph.min.js';
280
- const pr = new PacmanRenderer({
281
- platform: 'github',
282
- username: 'yourusername',
283
- canvas: document.getElementById('canvas'),
284
- outputFormat: 'canvas',
285
- gameTheme: 'github'
286
- });
287
- pr.start();
288
- &lt;/script&gt;</code></pre>
289
-
290
- <h3>Method 3: Iframe/Image Embedding</h3>
291
- <pre><code>
292
- &lt;!-- For canvas --&gt;
293
- <code>&lt;iframe src="https://abozanona.github.io/pacman-contribution-graph/embeded/canvas.html?username=yourusername&platform=github"
294
- width="800" height="600" frameborder="0"&gt;&lt;/iframe&gt;</code>
295
- &lt;!-- For SVG --&gt;
296
- <code>&lt;img src="https://pacman.abozanona.me?username=yourusername" /&gt;</code>
297
- </code></pre>
298
- </div>
299
-
300
- <h3>Method 4: Github Actions</h3>
301
- <ol>
302
- <li>Create a new repository with the same name as your github username</li>
303
- <li>
304
- Create <code>.github/workflows/main.yml</code> in your github repo with the following content
305
- <pre><code>name: generate pacman game
306
-
307
- on:
308
- schedule: # run automatically every 24 hours
309
- - cron: "0 */24 * * *"
310
- workflow_dispatch: # allows to manually run the job at any time
311
- push: # run on every push on the master branch
312
- branches:
313
- - main
314
-
315
- jobs:
316
- generate:
317
- permissions:
318
- contents: write
319
- runs-on: ubuntu-latest
320
- timeout-minutes: 5
321
-
322
- steps:
323
- - name: generate pacman-contribution-graph.svg
324
- uses: abozanona/pacman-contribution-graph@main
325
- with:
326
- github_user_name: ${{ github.repository_owner }}
327
-
328
- # push the content of <build_dir> to a branch
329
- # the content will be available at https://raw.githubusercontent.com/<github_user>/<repository>/<target_branch>/<file> , or as github page
330
- - name: push pacman-contribution-graph.svg to the output branch
331
- uses: crazy-max/ghaction-github-pages@v3.1.0
332
- with:
333
- target_branch: output
334
- build_dir: dist
335
- env:
336
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}</code></pre>
337
- </li>
338
- <li>Create <code>README.md</code> file in your github repo with the following content. Change `[USERNAME]` with your github username
339
- <pre><code>&lt;picture>
340
- &lt;source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/[USERNAME]/[USERNAME]/output/pacman-contribution-graph-dark.svg">
341
- &lt;source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/[USERNAME]/[USERNAME]/output/pacman-contribution-graph.svg">
342
- &lt;img alt="pacman contribution graph" src="https://raw.githubusercontent.com/[USERNAME]/[USERNAME]/output/pacman-contribution-graph.svg">
343
- &lt;/picture>
344
-
345
- _generated with [abozanona/pacman-contribution-graph](https://abozanona.github.io/pacman-contribution-graph/)_</code></pre></li>
346
- <li>That's it! You can also check my github repo <a target="__blank" href="https://github.com/abozanona/abozanona">@abozanona</a> for an example </li>
347
- </ol>
348
- </div>
349
-
350
- <footer class="bg-light py-3 mt-5 invisible">
351
- <div class="container text-center">
352
- <div>
353
- <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
354
- <span id="busuanzi_container_site_pv">Total visits: <span id="busuanzi_value_site_pv"></span></span>
355
- <span class="mx-2">|</span>
356
- <span id="busuanzi_container_site_uv">Unique visitors: <span id="busuanzi_value_site_uv"></span></span>
357
- </div>
358
- </div>
359
- </footer>
360
-
361
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
362
- <script type="module">
363
- import { PacmanRenderer } from './dist/pacman-contribution-graph.js';
364
-
365
- const generateButton = document.getElementById('generate');
366
- const usernameInput = document.getElementById('username');
367
- const platformSelect = document.getElementById('platform');
368
- const outputSelect = document.getElementById('output');
369
- const gameSpeedInput = document.getElementById('gameSpeed');
370
- const gameSpeedValue = document.getElementById('gameSpeedValue');
371
- const themeSelect = document.getElementById('theme');
372
- const enableSoundsSelect = document.getElementById('enableSounds');
373
- const canvas = document.getElementById('canvas');
374
- const svgContainer = document.getElementById('svgContainer');
375
- const svgHolder = document.getElementById('svgholder');
376
- const downloadSvgButton = document.getElementById('downloadSvg');
377
- const userAvatar = document.getElementById('userAvatar');
378
- const userNotFound = document.getElementById('userNotFound');
379
- const points = document.getElementById('points');
380
- const githubAccessToken = document.getElementById('githubAccessToken');
381
-
382
- generateButton.disabled = true;
383
-
384
- let currentSvgBlob = null;
385
-
386
- gameSpeedInput.addEventListener('input', () => {
387
- gameSpeedValue.textContent = gameSpeedInput.value;
388
- });
389
-
390
- usernameInput.addEventListener('input', debounce(checkUser, 500));
391
- platformSelect.addEventListener('input', debounce(checkUser, 500));
392
-
393
- function debounce(func, wait) {
394
- let timeout;
395
- return function executedFunction(...args) {
396
- const later = () => {
397
- clearTimeout(timeout);
398
- func(...args);
399
- };
400
- clearTimeout(timeout);
401
- timeout = setTimeout(later, wait);
402
- };
403
- }
404
-
405
- async function checkUser() {
406
- const username = usernameInput.value;
407
- const platform = platformSelect.value;
408
- if (!username) {
409
- userAvatar.style.display = 'none';
410
- userNotFound.style.display = 'none';
411
- generateButton.disabled = true;
412
- return;
413
- }
414
-
415
- if (platform == 'github') {
416
- try {
417
- const response = await fetch(`https://api.github.com/users/${username}`);
418
- if (response.ok) {
419
- const data = await response.json();
420
- userAvatar.src = data.avatar_url;
421
- userAvatar.style.display = 'inline';
422
- userNotFound.style.display = 'none';
423
- generateButton.disabled = false;
424
- } else {
425
- throw new Error('User not found');
426
- }
427
- } catch (error) {
428
- userAvatar.style.display = 'none';
429
- userNotFound.style.display = 'block';
430
- generateButton.disabled = true;
431
- }
432
- } else {
433
- try {
434
- const response = await fetch(`https://gitlab.com/api/v4/users?username=${username}`);
435
- if (response.ok) {
436
- const data = await response.json();
437
- if (!data.length) {
438
- throw new Error('User not found');
439
- }
440
- userAvatar.src = data[0].avatar_url;
441
- userAvatar.style.display = 'inline';
442
- userNotFound.style.display = 'none';
443
- generateButton.disabled = false;
444
- } else {
445
- throw new Error('User not found');
446
- }
447
- } catch (error) {
448
- userAvatar.style.display = 'none';
449
- userNotFound.style.display = 'block';
450
- generateButton.disabled = true;
451
- }
452
- }
453
- }
454
-
455
- let pr = undefined;
456
-
457
- generateButton.addEventListener('click', () => {
458
- const config = {
459
- platform: platformSelect.value,
460
- username: usernameInput.value,
461
- outputFormat: outputSelect.value,
462
- gameSpeed: parseInt(gameSpeedInput.value),
463
- gameTheme: themeSelect.value,
464
- enableSounds: enableSounds.value === 'enabled',
465
- githubSettings: {
466
- accessToken: githubAccessToken.value
467
- }
468
- };
469
-
470
- if (config.outputFormat === 'canvas') {
471
- canvas.style.display = 'block';
472
- svgContainer.style.display = 'none';
473
- downloadSvgButton.style.display = 'none';
474
- if (pr !== undefined) {
475
- pr.stop();
476
- }
477
- pr = new PacmanRenderer({
478
- ...config,
479
- canvas: canvas,
480
- gameOverCallback: () => {
481
- console.log('Game Over');
482
- },
483
- pointsIncreasedCallback: (pointsSum) => {
484
- points.innerText = pointsSum;
485
- }
486
- });
487
- pr.start();
488
- } else {
489
- canvas.style.display = 'none';
490
- svgContainer.style.display = 'block';
491
- downloadSvgButton.style.display = 'inline-block';
492
- if (pr !== undefined) {
493
- pr.stop();
494
- }
495
- pr = new PacmanRenderer({
496
- ...config,
497
- svgCallback: (animatedSVG) => {
498
- const svgBlob = new Blob([animatedSVG], {
499
- type: 'image/svg+xml;charset=utf-8'
500
- });
501
- const svgUrl = URL.createObjectURL(svgBlob);
502
- svgHolder.src = svgUrl;
503
- currentSvgBlob = svgUrl;
504
- },
505
- gameOverCallback: () => {
506
- console.log('Game Over');
507
- },
508
- pointsIncreasedCallback: (pointsSum) => {
509
- points.innerText = pointsSum;
510
- }
511
- });
512
- pr.start();
513
- }
514
- });
515
-
516
- downloadSvgButton.addEventListener('click', () => {
517
- if (currentSvgBlob) {
518
- const link = document.createElement('a');
519
- link.href = currentSvgBlob;
520
- link.download = 'pacman-contributions.svg';
521
- document.body.appendChild(link);
522
- link.click();
523
- document.body.removeChild(link);
524
- }
525
- });
526
- </script>
527
- </body>
528
- </html>