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