maidraw 0.7.13 → 0.7.15

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 (40) hide show
  1. package/assets/themes/maimai/best50/cn/2024Landscape/manifest.json +1 -10
  2. package/assets/themes/maimai/best50/cn/2024Portrait/manifest.json +18 -9
  3. package/assets/themes/maimai/best50/jp/buddiesLandscape/manifest.json +2 -11
  4. package/assets/themes/maimai/best50/jp/buddiesPlusLandscape/manifest.json +2 -11
  5. package/assets/themes/maimai/best50/jp/buddiesPlusPortrait/manifest.json +18 -9
  6. package/assets/themes/maimai/best50/jp/buddiesPortrait/manifest.json +18 -9
  7. package/assets/themes/maimai/best50/jp/finaleLandscape/manifest.json +2 -11
  8. package/assets/themes/maimai/best50/jp/finalePortrait/manifest.json +18 -9
  9. package/assets/themes/maimai/best50/jp/prismLandscape/manifest.json +1 -10
  10. package/assets/themes/maimai/best50/jp/prismPlusLandscape/manifest.json +2 -11
  11. package/assets/themes/maimai/best50/jp/prismPlusPortrait/manifest.json +19 -11
  12. package/assets/themes/maimai/best50/jp/prismPortrait/manifest.json +18 -9
  13. package/assets/themes/maimai/best50/salt/2026landscape/manifest.json +3 -12
  14. package/dist/mai/best50/index.js +2 -0
  15. package/dist/mai/best50/index.js.map +1 -1
  16. package/dist/mai/chart/database.js +5 -4
  17. package/dist/mai/chart/database.js.map +1 -1
  18. package/dist/mai/chart/index.js +8 -10
  19. package/dist/mai/chart/index.js.map +1 -1
  20. package/dist/mai/index.d.ts +2 -0
  21. package/dist/mai/index.js +2 -0
  22. package/dist/mai/index.js.map +1 -1
  23. package/dist/mai/level50/index.d.ts +28 -0
  24. package/dist/mai/level50/index.js +774 -0
  25. package/dist/mai/level50/index.js.map +1 -0
  26. package/dist/mai/lib/divingFish/index.d.ts +3 -0
  27. package/dist/mai/lib/divingFish/index.js +3 -0
  28. package/dist/mai/lib/divingFish/index.js.map +1 -1
  29. package/dist/mai/lib/index.d.ts +3 -0
  30. package/dist/mai/lib/index.js.map +1 -1
  31. package/dist/mai/lib/kamaiTachi/index.d.ts +4 -0
  32. package/dist/mai/lib/kamaiTachi/index.js +35 -0
  33. package/dist/mai/lib/kamaiTachi/index.js.map +1 -1
  34. package/dist/mai/lib/lxns/index.d.ts +3 -0
  35. package/dist/mai/lib/lxns/index.js +3 -0
  36. package/dist/mai/lib/lxns/index.js.map +1 -1
  37. package/dist/mai/lib/maishift/index.d.ts +3 -0
  38. package/dist/mai/lib/maishift/index.js +3 -0
  39. package/dist/mai/lib/maishift/index.js.map +1 -1
  40. package/package.json +1 -1
@@ -0,0 +1,774 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Level50 = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const upath_1 = __importDefault(require("upath"));
9
+ const canvas_1 = require("canvas");
10
+ const color_1 = __importDefault(require("color"));
11
+ const sharp_1 = __importDefault(require("sharp"));
12
+ const glob_1 = require("glob");
13
+ const chart_1 = require("../chart");
14
+ const string_template_1 = __importDefault(require("string-template"));
15
+ const util_1 = require("../../lib/util");
16
+ const type_1 = require("../type");
17
+ const best50_1 = require("../best50");
18
+ class Level50 {
19
+ static DEFAULT_THEME = "jp-prism-landscape";
20
+ static get assetsPath() {
21
+ return upath_1.default.join(__dirname, "..", "..", "..", "assets");
22
+ }
23
+ static themes = {};
24
+ static hasTheme(name) {
25
+ return !!this.themes[name];
26
+ }
27
+ static {
28
+ const manifests = (0, glob_1.globSync)(upath_1.default.join(this.assetsPath, "themes", "maimai", "**", "manifest.json"));
29
+ for (const manifestPath of manifests) {
30
+ const manifest = JSON.parse(fs_1.default.readFileSync(manifestPath, "utf-8"));
31
+ if (this.validateManifest(manifest, upath_1.default.dirname(manifestPath))) {
32
+ this.themes[manifest.name] = upath_1.default.dirname(manifestPath);
33
+ }
34
+ }
35
+ const loadThemeResult = this.loadTheme(this.DEFAULT_THEME);
36
+ if (!loadThemeResult) {
37
+ console.error("Failed to load default theme.");
38
+ }
39
+ (0, canvas_1.registerFont)(upath_1.default.join(this.assetsPath, "fonts", "gen-jyuu-gothic", "GenJyuuGothic-Bold.ttf"), {
40
+ family: "standard-font-title-jp",
41
+ });
42
+ (0, canvas_1.registerFont)(upath_1.default.join(this.assetsPath, "fonts", "comfortaa", "Comfortaa-Bold.ttf"), {
43
+ family: "standard-font-title-latin",
44
+ weight: "regular",
45
+ });
46
+ (0, canvas_1.registerFont)(upath_1.default.join(this.assetsPath, "fonts", "seurat-db", "FOT-Seurat Pro DB.otf"), {
47
+ family: "standard-font-username",
48
+ weight: "regular",
49
+ });
50
+ }
51
+ static validateManifest(payload, path) {
52
+ function isFileExist(p) {
53
+ if (isString(p))
54
+ return fs_1.default.existsSync(upath_1.default.join(path, p));
55
+ else
56
+ return false;
57
+ }
58
+ function isOneOf(p, ...args) {
59
+ return args.includes(p);
60
+ }
61
+ function isString(p) {
62
+ return typeof p == "string";
63
+ }
64
+ function isNumber(p) {
65
+ return typeof p == "number";
66
+ }
67
+ function isArray(p) {
68
+ return Array.isArray(p);
69
+ }
70
+ function isObject(p) {
71
+ return typeof p == "object";
72
+ }
73
+ function isHexColor(p) {
74
+ if (isString(p))
75
+ return /^(?:#[0-9A-F]{6}|#[0-9A-F]{8})$/i.test(p);
76
+ else
77
+ return false;
78
+ }
79
+ function isUndefined(p) {
80
+ return typeof p == "undefined";
81
+ }
82
+ function isBoolean(p) {
83
+ return typeof p == "boolean";
84
+ }
85
+ if (isString(payload.displayName) &&
86
+ isString(payload.name) &&
87
+ isNumber(payload.width) &&
88
+ isNumber(payload.height) &&
89
+ isObject(payload.sprites) &&
90
+ isObject(payload.sprites.achievement) &&
91
+ isFileExist(payload.sprites.achievement.d) &&
92
+ isFileExist(payload.sprites.achievement.c) &&
93
+ isFileExist(payload.sprites.achievement.b) &&
94
+ isFileExist(payload.sprites.achievement.bb) &&
95
+ isFileExist(payload.sprites.achievement.bbb) &&
96
+ isFileExist(payload.sprites.achievement.a) &&
97
+ isFileExist(payload.sprites.achievement.aa) &&
98
+ isFileExist(payload.sprites.achievement.aaa) &&
99
+ isFileExist(payload.sprites.achievement.s) &&
100
+ isFileExist(payload.sprites.achievement.sp) &&
101
+ isFileExist(payload.sprites.achievement.ss) &&
102
+ isFileExist(payload.sprites.achievement.ssp) &&
103
+ isFileExist(payload.sprites.achievement.sss) &&
104
+ isFileExist(payload.sprites.achievement.sssp) &&
105
+ isObject(payload.sprites.mode) &&
106
+ isFileExist(payload.sprites.mode.standard) &&
107
+ isFileExist(payload.sprites.mode.dx) &&
108
+ isObject(payload.sprites.milestone) &&
109
+ isFileExist(payload.sprites.milestone.ap) &&
110
+ isFileExist(payload.sprites.milestone.app) &&
111
+ isFileExist(payload.sprites.milestone.fc) &&
112
+ isFileExist(payload.sprites.milestone.fcp) &&
113
+ isFileExist(payload.sprites.milestone.fdx) &&
114
+ isFileExist(payload.sprites.milestone.fdxp) &&
115
+ isFileExist(payload.sprites.milestone.fs) &&
116
+ isFileExist(payload.sprites.milestone.fsp) &&
117
+ isFileExist(payload.sprites.milestone.sync) &&
118
+ isFileExist(payload.sprites.milestone.none) &&
119
+ isObject(payload.sprites.dxRating) &&
120
+ isFileExist(payload.sprites.dxRating.white) &&
121
+ isFileExist(payload.sprites.dxRating.blue) &&
122
+ isFileExist(payload.sprites.dxRating.green) &&
123
+ isFileExist(payload.sprites.dxRating.yellow) &&
124
+ isFileExist(payload.sprites.dxRating.red) &&
125
+ isFileExist(payload.sprites.dxRating.purple) &&
126
+ isFileExist(payload.sprites.dxRating.bronze) &&
127
+ isFileExist(payload.sprites.dxRating.silver) &&
128
+ isFileExist(payload.sprites.dxRating.gold) &&
129
+ isFileExist(payload.sprites.dxRating.platinum) &&
130
+ isFileExist(payload.sprites.dxRating.rainbow) &&
131
+ isObject(payload.sprites.profile) &&
132
+ isFileExist(payload.sprites.profile.icon) &&
133
+ isFileExist(payload.sprites.profile.nameplate) &&
134
+ isFileExist(payload.sprites.dxRatingNumberMap) &&
135
+ isArray(payload.elements)) {
136
+ for (const element of payload.elements) {
137
+ if (isNumber(element.x) && isNumber(element.y)) {
138
+ switch (element.type) {
139
+ case "image": {
140
+ if (isNumber(element.width) &&
141
+ isNumber(element.height) &&
142
+ isFileExist(element.path)) {
143
+ continue;
144
+ }
145
+ else
146
+ return false;
147
+ }
148
+ case "score-grid": {
149
+ if (isOneOf(element.region, "old", "new") &&
150
+ isNumber(element.horizontalSize) &&
151
+ isNumber(element.verticalSize) &&
152
+ isNumber(element.index) &&
153
+ isObject(element.scoreBubble) &&
154
+ isNumber(element.scoreBubble.width) &&
155
+ isNumber(element.scoreBubble.height) &&
156
+ isNumber(element.scoreBubble.margin) &&
157
+ isNumber(element.scoreBubble.gap) &&
158
+ isObject(element.scoreBubble.color) &&
159
+ isHexColor(element.scoreBubble.color.basic) &&
160
+ isHexColor(element.scoreBubble.color.advanced) &&
161
+ isHexColor(element.scoreBubble.color.expert) &&
162
+ isHexColor(element.scoreBubble.color.master) &&
163
+ isHexColor(element.scoreBubble.color.remaster) &&
164
+ isHexColor(element.scoreBubble.color.utage)) {
165
+ continue;
166
+ }
167
+ else
168
+ return false;
169
+ }
170
+ case "profile": {
171
+ if (isNumber(element.height)) {
172
+ continue;
173
+ }
174
+ else
175
+ return false;
176
+ }
177
+ case "text": {
178
+ if (isNumber(element.size) &&
179
+ isString(element.content) &&
180
+ (isUndefined(element.width) ||
181
+ isNumber(element.width)) &&
182
+ (isUndefined(element.height) ||
183
+ isNumber(element.height)) &&
184
+ (isUndefined(element.linebreak) ||
185
+ isBoolean(element.linebreak)) &&
186
+ (isUndefined(element.align) ||
187
+ isOneOf(element.align, "left", "center", "right")) &&
188
+ (isUndefined(element.color) ||
189
+ isString(element.color)) &&
190
+ (isUndefined(element.borderColor) ||
191
+ isString(element.borderColor)) &&
192
+ (isUndefined(element.font) ||
193
+ isString(element.font))) {
194
+ continue;
195
+ }
196
+ else
197
+ return false;
198
+ }
199
+ default:
200
+ return false;
201
+ }
202
+ }
203
+ }
204
+ return true;
205
+ }
206
+ else
207
+ return false;
208
+ }
209
+ static primaryTheme = null;
210
+ static loadTheme(path) {
211
+ const theme = this.getTheme(path);
212
+ if (theme) {
213
+ this.primaryTheme = theme;
214
+ return true;
215
+ }
216
+ else
217
+ return false;
218
+ }
219
+ static getTheme(path) {
220
+ if (!fs_1.default.existsSync(upath_1.default.join(path, "manifest.json"))) {
221
+ path = this.themes[path] ?? "";
222
+ }
223
+ else
224
+ path = upath_1.default.join(this.assetsPath, path);
225
+ if (fs_1.default.existsSync(upath_1.default.join(path, "manifest.json"))) {
226
+ const manifest = JSON.parse(fs_1.default.readFileSync(upath_1.default.join(path, "manifest.json"), "utf-8"));
227
+ if (this.validateManifest(manifest, path)) {
228
+ return { manifest, path };
229
+ }
230
+ }
231
+ return null;
232
+ }
233
+ static getThemeFile(path, themePath) {
234
+ if (typeof path == "string" &&
235
+ fs_1.default.existsSync(upath_1.default.join(themePath ?? this.primaryTheme?.path, path)))
236
+ return fs_1.default.readFileSync(upath_1.default.join(themePath ?? this.primaryTheme?.path, path));
237
+ else
238
+ return Buffer.from([]);
239
+ }
240
+ /* Begin Draw Tools*/
241
+ static async drawImageModule(ctx, theme, element) {
242
+ const img = new canvas_1.Image();
243
+ img.src = this.getThemeFile(element.path, theme.path);
244
+ ctx.drawImage(img, element.x, element.y, element.width, element.height);
245
+ }
246
+ static async drawScoreGridModule(ctx, theme, element, score, index, x, y) {
247
+ let curColor = "#FFFFFF";
248
+ switch (score.chart.difficulty) {
249
+ case type_1.EDifficulty.BASIC:
250
+ curColor = element.scoreBubble.color.basic;
251
+ break;
252
+ case type_1.EDifficulty.ADVANCED:
253
+ curColor = element.scoreBubble.color.advanced;
254
+ break;
255
+ case type_1.EDifficulty.EXPERT:
256
+ curColor = element.scoreBubble.color.expert;
257
+ break;
258
+ case type_1.EDifficulty.MASTER:
259
+ curColor = element.scoreBubble.color.master;
260
+ break;
261
+ case type_1.EDifficulty.REMASTER:
262
+ curColor = element.scoreBubble.color.remaster;
263
+ break;
264
+ case type_1.EDifficulty.UTAGE:
265
+ curColor = element.scoreBubble.color.utage;
266
+ break;
267
+ }
268
+ /** Begin Card Draw */
269
+ ctx.save();
270
+ ctx.fillStyle = new color_1.default(curColor).lighten(0.4).hexa();
271
+ ctx.beginPath();
272
+ ctx.roundRect(x, y, element.scoreBubble.width, element.scoreBubble.height, (element.scoreBubble.height * 0.806) / 7);
273
+ ctx.strokeStyle = new color_1.default(curColor).darken(0.3).hexa();
274
+ ctx.lineWidth = element.scoreBubble.margin / 4;
275
+ ctx.stroke();
276
+ ctx.fill();
277
+ ctx.beginPath();
278
+ ctx.roundRect(x, y, element.scoreBubble.width, element.scoreBubble.height, (element.scoreBubble.height * 0.806) / 7);
279
+ ctx.clip();
280
+ /** Begin Main Content Draw */
281
+ {
282
+ ctx.save();
283
+ ctx.beginPath();
284
+ ctx.roundRect(x, y, element.scoreBubble.width, element.scoreBubble.height * 0.742, (element.scoreBubble.height * 0.806) / 7);
285
+ ctx.clip();
286
+ ctx.fillStyle = curColor;
287
+ ctx.fill();
288
+ const jacketSize = Math.min(element.scoreBubble.width, element.scoreBubble.height * 0.742);
289
+ const jacketMaskGrad = ctx.createLinearGradient(x + jacketSize / 2, y + jacketSize / 2, x + jacketSize, y + jacketSize / 2);
290
+ jacketMaskGrad.addColorStop(0, new color_1.default(curColor).alpha(0).hexa());
291
+ jacketMaskGrad.addColorStop(0.25, new color_1.default(curColor).alpha(0.2).hexa());
292
+ jacketMaskGrad.addColorStop(1, new color_1.default(curColor).alpha(1).hexa());
293
+ const jacketMaskGradDark = ctx.createLinearGradient(x + jacketSize / 2, y + jacketSize / 2, x + jacketSize, y + jacketSize / 2);
294
+ jacketMaskGradDark.addColorStop(0, new color_1.default(curColor).darken(0.3).alpha(0).hexa());
295
+ jacketMaskGradDark.addColorStop(0.25, new color_1.default(curColor).darken(0.3).alpha(0.2).hexa());
296
+ jacketMaskGradDark.addColorStop(1, new color_1.default(curColor).darken(0.3).alpha(1).hexa());
297
+ /** Begin Jacket Draw*/
298
+ let jacket = await chart_1.Chart.Database.fecthJacket(score.chart.id);
299
+ if (!jacket)
300
+ jacket = await chart_1.Chart.Database.fecthJacket(0);
301
+ if (jacket) {
302
+ const img = new canvas_1.Image();
303
+ img.src = jacket;
304
+ ctx.drawImage(img, x, y, jacketSize, jacketSize);
305
+ }
306
+ else {
307
+ ctx.fillStyle = "#b6ffab";
308
+ ctx.fillRect(x, y, jacketSize, jacketSize);
309
+ }
310
+ /** End Jacket Draw*/
311
+ /** Begin Jacket Gradient Mask Draw*/ {
312
+ ctx.fillStyle = jacketMaskGrad;
313
+ ctx.fillRect(x + jacketSize / 2, y, (jacketSize * 3) / 4, jacketSize);
314
+ } /** End Jacket Gradient Mask Draw*/
315
+ ctx.beginPath();
316
+ ctx.roundRect(x + element.scoreBubble.margin, y + element.scoreBubble.margin, element.scoreBubble.width - element.scoreBubble.margin * 2, element.scoreBubble.height * 0.806 -
317
+ element.scoreBubble.margin * 2, (element.scoreBubble.height * 0.806 -
318
+ element.scoreBubble.margin * 2) /
319
+ 7);
320
+ /** Begin Title Draw */ {
321
+ util_1.Util.drawText(ctx, score.chart.name, x + (jacketSize * 7) / 8, y +
322
+ element.scoreBubble.margin +
323
+ element.scoreBubble.height * 0.806 * 0.144, element.scoreBubble.height * 0.806 * 0.144, element.scoreBubble.height * 0.806 * 0.04, element.scoreBubble.width -
324
+ (jacketSize * 7) / 8 -
325
+ element.scoreBubble.margin, "left", "white", jacketMaskGradDark);
326
+ } /** End Title Draw */
327
+ /** Begin Separation Line Draw */ {
328
+ ctx.beginPath();
329
+ ctx.roundRect(x + (jacketSize * 13) / 16, y +
330
+ element.scoreBubble.margin +
331
+ element.scoreBubble.height * 0.806 * (0.144 + 0.072), element.scoreBubble.width -
332
+ (jacketSize * 13) / 16 -
333
+ element.scoreBubble.margin * 2, element.scoreBubble.height * 0.806 * 0.02, element.scoreBubble.height * 0.806 * 0.16);
334
+ ctx.fillStyle = jacketMaskGradDark;
335
+ ctx.fill();
336
+ } /** End Separation Line Draw */
337
+ /** Begin Achievement Rate Draw */
338
+ util_1.Util.drawText(ctx, `${score.achievement.toFixed(4)}%`, x -
339
+ element.scoreBubble.margin -
340
+ element.scoreBubble.height * 0.806 * 0.02 +
341
+ element.scoreBubble.width, y +
342
+ element.scoreBubble.margin +
343
+ element.scoreBubble.height *
344
+ 0.806 *
345
+ (0.144 + 0.144 + 0.208 - 0.04), element.scoreBubble.height * 0.806 * 0.208, element.scoreBubble.height * 0.806 * 0.04, Infinity, "right", "white", new color_1.default(curColor).darken(0.3).hexa());
346
+ /** End Achievement Rate Draw */
347
+ /** Begin Achievement Rank Draw */
348
+ {
349
+ let rankImg;
350
+ switch (score.achievementRank) {
351
+ case best50_1.Best50.EAchievementTypes.D:
352
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.d, theme.path);
353
+ break;
354
+ case best50_1.Best50.EAchievementTypes.C:
355
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.c, theme.path);
356
+ break;
357
+ case best50_1.Best50.EAchievementTypes.B:
358
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.b, theme.path);
359
+ break;
360
+ case best50_1.Best50.EAchievementTypes.BB:
361
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.bb, theme.path);
362
+ break;
363
+ case best50_1.Best50.EAchievementTypes.BBB:
364
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.bbb, theme.path);
365
+ break;
366
+ case best50_1.Best50.EAchievementTypes.A:
367
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.a, theme.path);
368
+ break;
369
+ case best50_1.Best50.EAchievementTypes.AA:
370
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.aa, theme.path);
371
+ break;
372
+ case best50_1.Best50.EAchievementTypes.AAA:
373
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.aaa, theme.path);
374
+ break;
375
+ case best50_1.Best50.EAchievementTypes.S:
376
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.s, theme.path);
377
+ break;
378
+ case best50_1.Best50.EAchievementTypes.SP:
379
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.sp, theme.path);
380
+ break;
381
+ case best50_1.Best50.EAchievementTypes.SS:
382
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.ss, theme.path);
383
+ break;
384
+ case best50_1.Best50.EAchievementTypes.SSP:
385
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.ssp, theme.path);
386
+ break;
387
+ case best50_1.Best50.EAchievementTypes.SSS:
388
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.sss, theme.path);
389
+ break;
390
+ default:
391
+ rankImg = this.getThemeFile(theme.manifest.sprites.achievement.sssp, theme.path);
392
+ }
393
+ const img = new canvas_1.Image();
394
+ img.src = rankImg;
395
+ ctx.drawImage(img, x + jacketSize, y +
396
+ element.scoreBubble.margin +
397
+ element.scoreBubble.height *
398
+ 0.806 *
399
+ (0.144 + 0.144 + 0.208 + 0.02), element.scoreBubble.height * 0.806 * 0.3 * 2.133, element.scoreBubble.height * 0.806 * 0.3);
400
+ }
401
+ /** End Achievement Rank Draw */
402
+ /** Begin Milestone Draw */
403
+ {
404
+ let comboImg, syncImg;
405
+ switch (score.combo) {
406
+ case best50_1.Best50.EComboTypes.NONE:
407
+ comboImg = this.getThemeFile(theme.manifest.sprites.milestone.none, theme.path);
408
+ break;
409
+ case best50_1.Best50.EComboTypes.FULL_COMBO:
410
+ comboImg = this.getThemeFile(theme.manifest.sprites.milestone.fc, theme.path);
411
+ break;
412
+ case best50_1.Best50.EComboTypes.FULL_COMBO_PLUS:
413
+ comboImg = this.getThemeFile(theme.manifest.sprites.milestone.fcp, theme.path);
414
+ break;
415
+ case best50_1.Best50.EComboTypes.ALL_PERFECT:
416
+ comboImg = this.getThemeFile(theme.manifest.sprites.milestone.ap, theme.path);
417
+ break;
418
+ case best50_1.Best50.EComboTypes.ALL_PERFECT_PLUS:
419
+ comboImg = this.getThemeFile(theme.manifest.sprites.milestone.app, theme.path);
420
+ break;
421
+ }
422
+ switch (score.sync) {
423
+ case best50_1.Best50.ESyncTypes.NONE:
424
+ syncImg = this.getThemeFile(theme.manifest.sprites.milestone.none, theme.path);
425
+ break;
426
+ case best50_1.Best50.ESyncTypes.SYNC_PLAY:
427
+ syncImg = this.getThemeFile(theme.manifest.sprites.milestone.sync, theme.path);
428
+ break;
429
+ case best50_1.Best50.ESyncTypes.FULL_SYNC:
430
+ syncImg = this.getThemeFile(theme.manifest.sprites.milestone.fs, theme.path);
431
+ break;
432
+ case best50_1.Best50.ESyncTypes.FULL_SYNC_PLUS:
433
+ syncImg = this.getThemeFile(theme.manifest.sprites.milestone.fsp, theme.path);
434
+ break;
435
+ case best50_1.Best50.ESyncTypes.FULL_SYNC_DX:
436
+ syncImg = this.getThemeFile(theme.manifest.sprites.milestone.fdx, theme.path);
437
+ break;
438
+ case best50_1.Best50.ESyncTypes.FULL_SYNC_DX_PLUS:
439
+ syncImg = this.getThemeFile(theme.manifest.sprites.milestone.fdxp, theme.path);
440
+ break;
441
+ }
442
+ const combo = new canvas_1.Image();
443
+ combo.src = comboImg;
444
+ ctx.drawImage(combo, x +
445
+ (jacketSize * 7) / 8 +
446
+ element.scoreBubble.height *
447
+ 0.806 *
448
+ (0.32 * 2.133 + 0.06), y +
449
+ element.scoreBubble.margin +
450
+ element.scoreBubble.height *
451
+ 0.806 *
452
+ (0.144 + 0.144 + 0.208 + 0.01), element.scoreBubble.height * 0.806 * 0.32, element.scoreBubble.height * 0.806 * 0.32);
453
+ const sync = new canvas_1.Image();
454
+ sync.src = syncImg;
455
+ ctx.drawImage(sync, x +
456
+ (jacketSize * 7) / 8 +
457
+ element.scoreBubble.height *
458
+ 0.806 *
459
+ (0.32 * 2.133 + 0.04 + 0.32), y +
460
+ element.scoreBubble.margin +
461
+ element.scoreBubble.height *
462
+ 0.806 *
463
+ (0.144 + 0.144 + 0.208 + 0.01), element.scoreBubble.height * 0.806 * 0.32, element.scoreBubble.height * 0.806 * 0.32);
464
+ }
465
+ /** End Milestone Draw */
466
+ /** Begin Chart Mode Draw */
467
+ {
468
+ const mode = new canvas_1.Image();
469
+ const chartModeBadgeImg = this.getThemeFile(score.chart.id > 10000
470
+ ? theme.manifest.sprites.mode.dx
471
+ : theme.manifest.sprites.mode.standard, theme.path);
472
+ const { width, height } = await (0, sharp_1.default)(chartModeBadgeImg).metadata();
473
+ const aspectRatio = (width ?? 0) / (height ?? 1) || 3;
474
+ mode.src = chartModeBadgeImg;
475
+ const drawHeight = (jacketSize * 6) / 8;
476
+ ctx.drawImage(mode, x + ((jacketSize * 7) / 8 - drawHeight) / 2, y +
477
+ element.scoreBubble.margin +
478
+ element.scoreBubble.height * 0.806 * 0.02, drawHeight, drawHeight / aspectRatio);
479
+ }
480
+ /** End Chart Mode Draw */
481
+ /** Begin Bests Index Draw */
482
+ {
483
+ util_1.Util.drawText(ctx, `#${index + 1}`, x + element.scoreBubble.margin * 2, y + jacketSize - element.scoreBubble.margin * 2, element.scoreBubble.height * 0.806 * 0.128, element.scoreBubble.height * 0.806 * 0.04, Infinity, "left", "white", new color_1.default(curColor).darken(0.3).hexa());
484
+ }
485
+ /** End Bests Index Draw */
486
+ ctx.restore();
487
+ }
488
+ /** End Main Content Draw */
489
+ /** Begin Difficulty & DX Rating Draw */
490
+ {
491
+ util_1.Util.drawText(ctx, `${score.chart.level.toFixed(1)} ↑${score.dxRating.toFixed(0)}`, x + element.scoreBubble.margin * 2, y + element.scoreBubble.height * (0.806 + (1 - 0.806) / 2), element.scoreBubble.height * 0.806 * 0.128, element.scoreBubble.height * 0.806 * 0.04, Infinity, "left", "white", new color_1.default(curColor).darken(0.3).hexa());
492
+ if (score.dxScore >= 0 && score.chart.maxDxScore > 0) {
493
+ util_1.Util.drawText(ctx, `${score.dxScore}/${score.chart.maxDxScore}`, x +
494
+ element.scoreBubble.width -
495
+ element.scoreBubble.margin * 2, y + element.scoreBubble.height * (0.806 + (1 - 0.806) / 2), element.scoreBubble.height * 0.806 * 0.128, element.scoreBubble.height * 0.806 * 0.04, Infinity, "right", "white", new color_1.default(curColor).darken(0.3).hexa());
496
+ }
497
+ }
498
+ /** End Difficulty & DX Rating Draw */
499
+ ctx.restore();
500
+ /** End Card Draw */
501
+ }
502
+ static async drawProfileModule(ctx, theme, element, username, rating, profilePicture) {
503
+ const nameplate = new canvas_1.Image();
504
+ nameplate.src = this.getThemeFile(theme.manifest.sprites.profile.nameplate, theme.path);
505
+ ctx.drawImage(nameplate, element.x, element.y, element.height * 6.207, element.height);
506
+ /* Begin Profile Picture Draw */
507
+ {
508
+ ctx.save();
509
+ ctx.beginPath();
510
+ ctx.roundRect(element.x + element.height * 0.064, element.y + element.height * 0.064, element.height * 0.872, element.height * 0.872, (element.height * 0.872) / 16);
511
+ ctx.clip();
512
+ ctx.fillStyle = "white";
513
+ ctx.fill();
514
+ const icon = new canvas_1.Image();
515
+ try {
516
+ (0, sharp_1.default)(profilePicture);
517
+ }
518
+ catch {
519
+ // Unknown profile picture binary
520
+ profilePicture = undefined;
521
+ }
522
+ const pfp = profilePicture ||
523
+ this.getThemeFile(theme.manifest.sprites.profile.icon, theme.path);
524
+ const { dominant } = await (0, sharp_1.default)(pfp).stats();
525
+ icon.src = await (0, sharp_1.default)(pfp).png().toBuffer();
526
+ const cropSize = Math.min(icon.width, icon.height);
527
+ ctx.drawImage(icon, (icon.width - cropSize) / 2, (icon.height - cropSize) / 2, cropSize, cropSize, element.x + element.height * 0.064, element.y + element.height * 0.064, element.height * 0.872, element.height * 0.872);
528
+ if (profilePicture) {
529
+ ctx.beginPath();
530
+ ctx.roundRect(element.x + element.height * 0.064, element.y + element.height * 0.064, element.height * 0.872, element.height * 0.872, (element.height * 0.872) / 16);
531
+ ctx.strokeStyle = color_1.default.rgb(dominant).darken(0.3).hex();
532
+ ctx.lineWidth = element.height / 30;
533
+ ctx.stroke();
534
+ }
535
+ ctx.restore();
536
+ }
537
+ /* End Profile Picture Draw */
538
+ /* Begin DX Rating Draw */
539
+ {
540
+ const dxRating = new canvas_1.Image();
541
+ let dxRatingImg;
542
+ switch (true) {
543
+ case rating >= 15000: {
544
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.rainbow, theme.path);
545
+ break;
546
+ }
547
+ case rating >= 14500: {
548
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.platinum, theme.path);
549
+ break;
550
+ }
551
+ case rating >= 14000: {
552
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.gold, theme.path);
553
+ break;
554
+ }
555
+ case rating >= 13000: {
556
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.silver, theme.path);
557
+ break;
558
+ }
559
+ case rating >= 12000: {
560
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.bronze, theme.path);
561
+ break;
562
+ }
563
+ case rating >= 10000: {
564
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.purple, theme.path);
565
+ break;
566
+ }
567
+ case rating >= 8000: {
568
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.red, theme.path);
569
+ break;
570
+ }
571
+ case rating >= 6000: {
572
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.yellow, theme.path);
573
+ break;
574
+ }
575
+ case rating >= 4000: {
576
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.green, theme.path);
577
+ break;
578
+ }
579
+ case rating >= 2000: {
580
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.blue, theme.path);
581
+ break;
582
+ }
583
+ default: {
584
+ dxRatingImg = this.getThemeFile(theme.manifest.sprites.dxRating.white, theme.path);
585
+ break;
586
+ }
587
+ }
588
+ dxRating.src = dxRatingImg;
589
+ ctx.drawImage(dxRating, element.x + element.height, element.y + element.height * 0.064, (element.height / 3) * 5.108, element.height / 3);
590
+ }
591
+ /* End DX Rating Draw */
592
+ /* Begin Username Draw */
593
+ {
594
+ ctx.beginPath();
595
+ ctx.roundRect(element.x + element.height * (1 + 1 / 32), element.y + element.height * (0.064 + 0.333 + 1 / 32), ((element.height / 3) * 5.108 * 6) / 5, (element.height * 7) / 24, element.height / 20);
596
+ ctx.fillStyle = "white";
597
+ ctx.strokeStyle = color_1.default.rgb(180, 180, 180).hex();
598
+ ctx.lineWidth = element.height / 32;
599
+ ctx.stroke();
600
+ ctx.fill();
601
+ const ratingImgBuffer = await this.getRatingNumber(rating, theme);
602
+ if (ratingImgBuffer) {
603
+ const { width, height } = await (0, sharp_1.default)(ratingImgBuffer).metadata();
604
+ if (width && height) {
605
+ const aspectRatio = width / height;
606
+ const image = new canvas_1.Image();
607
+ image.src = ratingImgBuffer;
608
+ const drawHeight = (element.height * 7) / 32;
609
+ ctx.drawImage(image, element.x + element.height * 1.785, element.y + element.height * 0.12, drawHeight * aspectRatio * 0.8, drawHeight);
610
+ }
611
+ }
612
+ util_1.Util.drawText(ctx, util_1.Util.HalfFullWidthConvert.toFullWidth(username), element.x + element.height * (1 + 1 / 16), element.y + element.height * (0.064 + 0.333 + 1 / 4), (element.height * 1) / 6, 0, ((element.height / 3) * 5.108 * 6) / 5, "left", "black", "black", "standard-font-username");
613
+ }
614
+ /* End Username Draw*/
615
+ }
616
+ static async drawTextModule(ctx, theme, element, variables = {}) {
617
+ let naiveLines = (0, string_template_1.default)(element.content, variables).split("\n");
618
+ let lines = [];
619
+ if (element.linebreak) {
620
+ for (let originalContent of naiveLines) {
621
+ while (originalContent.length) {
622
+ const line = util_1.Util.findMaxFitString(ctx, originalContent, element.width || Infinity, "");
623
+ originalContent = originalContent.replace(line, "").trim();
624
+ lines.push(line.trim());
625
+ }
626
+ }
627
+ }
628
+ else {
629
+ for (const originalContent of naiveLines) {
630
+ lines.push(util_1.Util.findMaxFitString(ctx, originalContent, element.width || Infinity));
631
+ }
632
+ }
633
+ for (let i = 0; i < lines.length; ++i) {
634
+ const line = lines[i];
635
+ util_1.Util.drawText(ctx, line, element.x, element.y + i * element.size * 1.3, element.size, element.size / 3.5, element.width || Infinity, element.align, element.color || "#FFFFFF", element.borderColor
636
+ ? element.borderColor
637
+ : color_1.default.rgb(element.color || "#FFFFFF")
638
+ .darken(0.3)
639
+ .hex(), element.font, element.linebreak ? "" : "...");
640
+ }
641
+ }
642
+ /* End Draw Tools*/
643
+ static async draw(name, rating, scores, level, page, options) {
644
+ const newScores = scores.slice(0, 15);
645
+ const oldScores = scores.slice(15, 50);
646
+ let currentTheme = this.primaryTheme;
647
+ if (options?.theme) {
648
+ const theme = this.getTheme(options.theme);
649
+ if (theme) {
650
+ currentTheme = theme;
651
+ }
652
+ }
653
+ if (currentTheme) {
654
+ await chart_1.Chart.Database.cacheJackets(scores.map((v) => v.chart.id));
655
+ const canvas = new canvas_1.Canvas(currentTheme.manifest.width * (options?.scale ?? 1), currentTheme.manifest.height * (options?.scale ?? 1));
656
+ const ctx = canvas.getContext("2d");
657
+ if (options?.scale)
658
+ ctx.scale(options.scale, options.scale);
659
+ ctx.imageSmoothingEnabled = true;
660
+ for (const element of currentTheme.manifest.elements) {
661
+ switch (element.type) {
662
+ case "image": {
663
+ await this.drawImageModule(ctx, currentTheme, element);
664
+ break;
665
+ }
666
+ case "score-grid": {
667
+ for (let y = element.y, index = element.index, i = 0; i < element.verticalSize; ++i,
668
+ y +=
669
+ element.scoreBubble.height +
670
+ element.scoreBubble.gap) {
671
+ for (let x = element.x, j = 0; j < element.horizontalSize; ++j,
672
+ ++index,
673
+ x +=
674
+ element.scoreBubble.width +
675
+ element.scoreBubble.gap) {
676
+ let curScore;
677
+ if (element.region == "new")
678
+ curScore = newScores[index];
679
+ else
680
+ curScore = oldScores[index];
681
+ if (curScore) {
682
+ await this.drawScoreGridModule(ctx, currentTheme, element, curScore, (page - 1) * 50 +
683
+ (element.region == "old"
684
+ ? index + 15
685
+ : index), x, y);
686
+ }
687
+ }
688
+ }
689
+ break;
690
+ }
691
+ case "profile": {
692
+ await this.drawProfileModule(ctx, currentTheme, element, name, rating, options?.profilePicture);
693
+ break;
694
+ }
695
+ case "text": {
696
+ function getTextLevel(level, border) {
697
+ const realBorder = Math.floor(level) + border * 0.1;
698
+ if (level < realBorder)
699
+ return Math.floor(level).toFixed(0);
700
+ else
701
+ return Math.floor(level).toFixed(0) + "+";
702
+ }
703
+ await this.drawTextModule(ctx, currentTheme, element, {
704
+ username: util_1.Util.HalfFullWidthConvert.toFullWidth(name),
705
+ rating: rating.toFixed(0),
706
+ level50Title: `Top Scores From Lv. ${getTextLevel(level, 6)}`,
707
+ level50Subtitle: `(Showing scores from ${(page - 1) * 50 + 1} to ${page * 50})`,
708
+ });
709
+ break;
710
+ }
711
+ }
712
+ }
713
+ return canvas.toBuffer();
714
+ }
715
+ else
716
+ return null;
717
+ }
718
+ static async drawWithScoreSource(source, username, level, page, options) {
719
+ const profile = await source.getPlayerInfo(username);
720
+ const score = await source.getPlayerLevel50(username, level, page);
721
+ if (!profile || !score)
722
+ return null;
723
+ return this.draw(profile.name, profile.rating, score, level, page, {
724
+ ...options,
725
+ profilePicture: options?.profilePicture === null
726
+ ? undefined
727
+ : options?.profilePicture ||
728
+ (await source.getPlayerProfilePicture(username)) ||
729
+ undefined,
730
+ });
731
+ }
732
+ static async getRatingNumber(num, theme) {
733
+ async function getRaingDigit(map, digit, unitWidth, unitHeight) {
734
+ digit = Math.floor(digit % 10);
735
+ return await (0, sharp_1.default)(map)
736
+ .extract({
737
+ left: (digit % 4) * unitWidth,
738
+ top: Math.floor(digit / 4) * unitHeight,
739
+ width: unitWidth,
740
+ height: unitHeight,
741
+ })
742
+ .toBuffer();
743
+ }
744
+ if (theme.manifest) {
745
+ const map = this.getThemeFile(theme.manifest.sprites.dxRatingNumberMap, theme.path);
746
+ const { width, height } = await (0, sharp_1.default)(map).metadata();
747
+ if (!(width && height))
748
+ return null;
749
+ const unitWidth = width / 4, unitHeight = height / 4;
750
+ let digits = [];
751
+ while (num > 0) {
752
+ digits.push(await getRaingDigit(map, num % 10, unitWidth, unitHeight));
753
+ num = Math.floor(num / 10);
754
+ }
755
+ while (digits.length < 5)
756
+ digits.push(null);
757
+ digits = digits.reverse();
758
+ const canvas = new canvas_1.Canvas(unitWidth * digits.length, unitHeight);
759
+ const ctx = canvas.getContext("2d");
760
+ for (let i = 0; i < digits.length; ++i) {
761
+ const curDigit = digits[i];
762
+ if (!curDigit)
763
+ continue;
764
+ const img = new canvas_1.Image();
765
+ img.src = curDigit;
766
+ ctx.drawImage(img, unitWidth * i * 0.88, 0);
767
+ }
768
+ return canvas.toBuffer();
769
+ }
770
+ return null;
771
+ }
772
+ }
773
+ exports.Level50 = Level50;
774
+ //# sourceMappingURL=index.js.map