maidraw 0.9.5 → 0.10.1

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