maidraw 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/themes/maimai/salt/2026landscape/image/background.png +0 -0
- package/assets/themes/maimai/salt/2026landscape/image/logo.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/a.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/aa.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/aaa.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/b.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/bb.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/bbb.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/c.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/d.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/s.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/ss.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/sss.png +0 -0
- package/assets/themes/ongeki/common/refresh/achievement/sssp.png +0 -0
- package/assets/themes/ongeki/common/refresh/jp/background.png +0 -0
- package/assets/themes/ongeki/common/refresh/jp/logo.png +0 -0
- package/assets/themes/ongeki/common/versionless/emote.png +0 -0
- package/assets/themes/ongeki/common/versionless/icon.png +0 -0
- package/assets/themes/ongeki/common/versionless/milestone/ab.png +0 -0
- package/assets/themes/ongeki/common/versionless/milestone/abp.png +0 -0
- package/assets/themes/ongeki/common/versionless/milestone/fb.png +0 -0
- package/assets/themes/ongeki/common/versionless/milestone/fc.png +0 -0
- package/assets/themes/ongeki/common/versionless/numberMap.png +0 -0
- package/assets/themes/ongeki/common/versionless/userplateAF2025.png +0 -0
- package/assets/themes/ongeki/common/versionless/userplateIchigeki.png +0 -0
- package/assets/themes/ongeki/common/versionless/void.png +0 -0
- package/assets/themes/ongeki/jp/refreshLandscape/classic/manifest.json +203 -0
- package/assets/themes/ongeki/jp/refreshLandscape/refresh/manifest.json +170 -0
- package/dist/chu/bests/best50.d.ts +4 -2
- package/dist/chu/bests/best50.js +27 -2
- package/dist/chu/bests/best50.js.map +1 -1
- package/dist/chu/bests/lib/index.js +12 -4
- package/dist/chu/bests/lib/index.js.map +1 -1
- package/dist/chu/chart/index.d.ts +3 -3
- package/dist/chu/chart/index.js +28 -5
- package/dist/chu/chart/index.js.map +1 -1
- package/dist/chu/index.d.ts +6 -4
- package/dist/chu/index.js +29 -4
- package/dist/chu/index.js.map +1 -1
- package/dist/geki/bests/best50.d.ts +37 -0
- package/dist/geki/bests/best50.js +876 -0
- package/dist/geki/bests/best50.js.map +1 -0
- package/dist/geki/bests/index.d.ts +1 -0
- package/dist/geki/bests/index.js +6 -0
- package/dist/geki/bests/index.js.map +1 -0
- package/dist/geki/bests/lib/index.d.ts +34 -0
- package/dist/geki/bests/lib/index.js +68 -0
- package/dist/geki/bests/lib/index.js.map +1 -0
- package/dist/geki/bests/lib/kamaiTachi/index.d.ts +207 -0
- package/dist/geki/bests/lib/kamaiTachi/index.js +508 -0
- package/dist/geki/bests/lib/kamaiTachi/index.js.map +1 -0
- package/dist/geki/bests/type.d.ts +122 -0
- package/dist/geki/bests/type.js +3 -0
- package/dist/geki/bests/type.js.map +1 -0
- package/dist/geki/chart/database.d.ts +9 -0
- package/dist/geki/chart/database.js +66 -0
- package/dist/geki/chart/database.js.map +1 -0
- package/dist/geki/chart/index.d.ts +4 -0
- package/dist/geki/chart/index.js +32 -0
- package/dist/geki/chart/index.js.map +1 -0
- package/dist/geki/index.d.ts +10 -0
- package/dist/geki/index.js +70 -0
- package/dist/geki/index.js.map +1 -0
- package/dist/geki/type.d.ts +51 -0
- package/dist/geki/type.js +39 -0
- package/dist/geki/type.js.map +1 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +32 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/cache.js +3 -2
- package/dist/lib/cache.js.map +1 -1
- package/dist/mai/best50/index.d.ts +8 -6
- package/dist/mai/best50/index.js +31 -6
- package/dist/mai/best50/index.js.map +1 -1
- package/dist/mai/best50/lib/index.js +12 -4
- package/dist/mai/best50/lib/index.js.map +1 -1
- package/dist/mai/chart/index.d.ts +3 -3
- package/dist/mai/chart/index.js +28 -5
- package/dist/mai/chart/index.js.map +1 -1
- package/dist/mai/index.d.ts +6 -4
- package/dist/mai/index.js +29 -4
- package/dist/mai/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,876 @@
|
|
|
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
|
+
class HalfFullWidthConvert {
|
|
41
|
+
static charsets = {
|
|
42
|
+
latin: { halfRE: /[!-~]/g, fullRE: /[!-~]/g, delta: 0xfee0 },
|
|
43
|
+
hangul1: { halfRE: /[ᄀ-ᄒ]/g, fullRE: /[ᆨ-ᇂ]/g, delta: -0xedf9 },
|
|
44
|
+
hangul2: { halfRE: /[ᅡ-ᅵ]/g, fullRE: /[ᅡ-ᅵ]/g, delta: -0xee61 },
|
|
45
|
+
kana: {
|
|
46
|
+
delta: 0,
|
|
47
|
+
half: "。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚",
|
|
48
|
+
full: "。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシ" +
|
|
49
|
+
"スセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゛゜",
|
|
50
|
+
},
|
|
51
|
+
extras: {
|
|
52
|
+
delta: 0,
|
|
53
|
+
half: "¢£¬¯¦¥₩\u0020|←↑→↓■°",
|
|
54
|
+
full: "¢£¬ ̄¦¥₩\u3000│←↑→↓■○",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
static toFull = (set) => (c) => set.delta
|
|
59
|
+
? String.fromCharCode(c.charCodeAt(0) + set.delta)
|
|
60
|
+
: [...set.full][[...set.half].indexOf(c)];
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
static toHalf = (set) => (c) => set.delta
|
|
63
|
+
? String.fromCharCode(c.charCodeAt(0) - set.delta)
|
|
64
|
+
: [...set.half][[...set.full].indexOf(c)];
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
static re = (set, way) => set[way + "RE"] || new RegExp("[" + set[way] + "]", "g");
|
|
67
|
+
static sets = Object.values(this.charsets);
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
static toFullWidth = (str0) => this.sets.reduce((str, set) => str.replace(this.re(set, "half"), this.toFull(set)), str0);
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
static toHalfWidth = (str0) => this.sets.reduce((str, set) => str.replace(this.re(set, "full"), this.toHalf(set)), str0);
|
|
72
|
+
}
|
|
73
|
+
class Best50 {
|
|
74
|
+
static DEFAULT_THEME = "jp-refresh-landscape-refresh";
|
|
75
|
+
static primaryTheme = null;
|
|
76
|
+
static loadTheme(path) {
|
|
77
|
+
const theme = this.getTheme(path);
|
|
78
|
+
if (theme) {
|
|
79
|
+
this.primaryTheme = theme;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
else
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
static get assetsPath() {
|
|
86
|
+
return upath_1.default.join(__dirname, "..", "..", "..", "assets");
|
|
87
|
+
}
|
|
88
|
+
static themes = {};
|
|
89
|
+
static hasTheme(name) {
|
|
90
|
+
return !!this.themes[name];
|
|
91
|
+
}
|
|
92
|
+
static {
|
|
93
|
+
const manifests = (0, glob_1.globSync)(upath_1.default.join(this.assetsPath, "themes", "ongeki", "**", "manifest.json"));
|
|
94
|
+
for (const manifestPath of manifests) {
|
|
95
|
+
const manifest = JSON.parse(fs_1.default.readFileSync(manifestPath, "utf-8"));
|
|
96
|
+
if (this.validateManifest(manifest, upath_1.default.dirname(manifestPath))) {
|
|
97
|
+
this.themes[manifest.name] = upath_1.default.dirname(manifestPath);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const loadThemeResult = this.loadTheme(this.DEFAULT_THEME);
|
|
101
|
+
if (!loadThemeResult) {
|
|
102
|
+
console.error("Failed to load default theme.");
|
|
103
|
+
}
|
|
104
|
+
(0, canvas_1.registerFont)(upath_1.default.join(this.assetsPath, "fonts", "gen-jyuu-gothic", "GenJyuuGothic-Bold.ttf"), {
|
|
105
|
+
family: "standard-font-title-jp",
|
|
106
|
+
});
|
|
107
|
+
(0, canvas_1.registerFont)(upath_1.default.join(this.assetsPath, "fonts", "comfortaa", "Comfortaa-Bold.ttf"), {
|
|
108
|
+
family: "standard-font-title-latin",
|
|
109
|
+
weight: "regular",
|
|
110
|
+
});
|
|
111
|
+
(0, canvas_1.registerFont)(upath_1.default.join(this.assetsPath, "fonts", "seurat-db", "FOT-Seurat Pro DB.otf"), {
|
|
112
|
+
family: "standard-font-username",
|
|
113
|
+
weight: "regular",
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
static validateManifest(payload, path) {
|
|
117
|
+
function isFileExist(p) {
|
|
118
|
+
if (isString(p))
|
|
119
|
+
return fs_1.default.existsSync(upath_1.default.join(path, p));
|
|
120
|
+
else
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
function isOneOf(p, ...args) {
|
|
124
|
+
return args.includes(p);
|
|
125
|
+
}
|
|
126
|
+
function isString(p) {
|
|
127
|
+
return typeof p == "string";
|
|
128
|
+
}
|
|
129
|
+
function isNumber(p) {
|
|
130
|
+
return typeof p == "number";
|
|
131
|
+
}
|
|
132
|
+
function isArray(p) {
|
|
133
|
+
return Array.isArray(p);
|
|
134
|
+
}
|
|
135
|
+
function isObject(p) {
|
|
136
|
+
return typeof p == "object";
|
|
137
|
+
}
|
|
138
|
+
function isHexColor(p) {
|
|
139
|
+
if (isString(p))
|
|
140
|
+
return /^(?:#[0-9A-F]{6}|#[0-9A-F]{8})$/i.test(p);
|
|
141
|
+
else
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
function isUndefined(p) {
|
|
145
|
+
return typeof p == "undefined";
|
|
146
|
+
}
|
|
147
|
+
function isBoolean(p) {
|
|
148
|
+
return typeof p == "boolean";
|
|
149
|
+
}
|
|
150
|
+
if (isString(payload.displayName) &&
|
|
151
|
+
isString(payload.name) &&
|
|
152
|
+
isNumber(payload.width) &&
|
|
153
|
+
isNumber(payload.height) &&
|
|
154
|
+
isObject(payload.sprites) &&
|
|
155
|
+
isObject(payload.sprites.achievement) &&
|
|
156
|
+
isFileExist(payload.sprites.achievement.d) &&
|
|
157
|
+
isFileExist(payload.sprites.achievement.c) &&
|
|
158
|
+
isFileExist(payload.sprites.achievement.b) &&
|
|
159
|
+
isFileExist(payload.sprites.achievement.bb) &&
|
|
160
|
+
isFileExist(payload.sprites.achievement.bbb) &&
|
|
161
|
+
isFileExist(payload.sprites.achievement.a) &&
|
|
162
|
+
isFileExist(payload.sprites.achievement.aa) &&
|
|
163
|
+
isFileExist(payload.sprites.achievement.aaa) &&
|
|
164
|
+
isFileExist(payload.sprites.achievement.s) &&
|
|
165
|
+
isFileExist(payload.sprites.achievement.ss) &&
|
|
166
|
+
isFileExist(payload.sprites.achievement.sss) &&
|
|
167
|
+
isFileExist(payload.sprites.achievement.sssp) &&
|
|
168
|
+
isObject(payload.sprites.milestone) &&
|
|
169
|
+
isFileExist(payload.sprites.milestone.ab) &&
|
|
170
|
+
isFileExist(payload.sprites.milestone.abp) &&
|
|
171
|
+
isFileExist(payload.sprites.milestone.fc) &&
|
|
172
|
+
isFileExist(payload.sprites.milestone.fb) &&
|
|
173
|
+
isFileExist(payload.sprites.milestone.none) &&
|
|
174
|
+
isObject(payload.sprites.profile) &&
|
|
175
|
+
isFileExist(payload.sprites.profile.icon) &&
|
|
176
|
+
isFileExist(payload.sprites.profile.userplate) &&
|
|
177
|
+
isFileExist(payload.sprites.ratingNumberMap) &&
|
|
178
|
+
isArray(payload.elements)) {
|
|
179
|
+
for (const element of payload.elements) {
|
|
180
|
+
if (isNumber(element.x) && isNumber(element.y)) {
|
|
181
|
+
switch (element.type) {
|
|
182
|
+
case "image": {
|
|
183
|
+
if (isNumber(element.width) &&
|
|
184
|
+
isNumber(element.height) &&
|
|
185
|
+
isFileExist(element.path)) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
else
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
case "score-grid": {
|
|
192
|
+
if (isOneOf(element.region, "recent", "old", "new") &&
|
|
193
|
+
isNumber(element.horizontalSize) &&
|
|
194
|
+
isNumber(element.verticalSize) &&
|
|
195
|
+
isNumber(element.index) &&
|
|
196
|
+
isObject(element.scoreBubble) &&
|
|
197
|
+
isNumber(element.scoreBubble.width) &&
|
|
198
|
+
isNumber(element.scoreBubble.height) &&
|
|
199
|
+
isNumber(element.scoreBubble.margin) &&
|
|
200
|
+
(isNumber(element.scoreBubble.gap) ||
|
|
201
|
+
(isObject(element.scoreBubble.gap) &&
|
|
202
|
+
isNumber(element.scoreBubble.gap.x) &&
|
|
203
|
+
element.scoreBubble.gap.y)) &&
|
|
204
|
+
isObject(element.scoreBubble.color) &&
|
|
205
|
+
isHexColor(element.scoreBubble.color.basic) &&
|
|
206
|
+
isHexColor(element.scoreBubble.color.advanced) &&
|
|
207
|
+
isHexColor(element.scoreBubble.color.expert) &&
|
|
208
|
+
isHexColor(element.scoreBubble.color.master) &&
|
|
209
|
+
isHexColor(element.scoreBubble.color.lunatic)) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
else
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
case "profile": {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
case "text": {
|
|
219
|
+
if (isNumber(element.size) &&
|
|
220
|
+
isString(element.content) &&
|
|
221
|
+
(isUndefined(element.width) ||
|
|
222
|
+
isNumber(element.width)) &&
|
|
223
|
+
(isUndefined(element.height) ||
|
|
224
|
+
isNumber(element.height)) &&
|
|
225
|
+
(isUndefined(element.linebreak) ||
|
|
226
|
+
isBoolean(element.linebreak)) &&
|
|
227
|
+
(isUndefined(element.align) ||
|
|
228
|
+
isOneOf(element.align, "left", "center", "right")) &&
|
|
229
|
+
(isUndefined(element.color) ||
|
|
230
|
+
isString(element.color)) &&
|
|
231
|
+
(isUndefined(element.borderColor) ||
|
|
232
|
+
isString(element.borderColor)) &&
|
|
233
|
+
(isUndefined(element.font) ||
|
|
234
|
+
isString(element.font))) {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
else
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
default:
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
else
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
static getTheme(path) {
|
|
251
|
+
if (!fs_1.default.existsSync(upath_1.default.join(this.assetsPath, path, "manifest.json"))) {
|
|
252
|
+
path = this.themes[path] ?? "";
|
|
253
|
+
}
|
|
254
|
+
else
|
|
255
|
+
path = upath_1.default.join(this.assetsPath, path);
|
|
256
|
+
if (fs_1.default.existsSync(upath_1.default.join(path, "manifest.json"))) {
|
|
257
|
+
const manifest = JSON.parse(fs_1.default.readFileSync(upath_1.default.join(path, "manifest.json"), "utf-8"));
|
|
258
|
+
if (this.validateManifest(manifest, path)) {
|
|
259
|
+
return { manifest, path };
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
static getThemeFile(path, themePath) {
|
|
265
|
+
if (typeof path == "string" &&
|
|
266
|
+
fs_1.default.existsSync(upath_1.default.join(themePath ?? this.primaryTheme?.path, path)))
|
|
267
|
+
return fs_1.default.readFileSync(upath_1.default.join(themePath ?? this.primaryTheme?.path, path));
|
|
268
|
+
else
|
|
269
|
+
return Buffer.from([]);
|
|
270
|
+
}
|
|
271
|
+
/* Begin Draw Tools*/
|
|
272
|
+
static findMaxFitString(ctx, original, maxWidth, lineBreakSuffix = "...") {
|
|
273
|
+
const metrics = ctx.measureText(original);
|
|
274
|
+
if (metrics.width <= maxWidth)
|
|
275
|
+
return original;
|
|
276
|
+
for (let i = 1; i < original.length; ++i) {
|
|
277
|
+
let cur = original.slice(0, original.length - i);
|
|
278
|
+
if (ctx.measureText(cur + lineBreakSuffix).width <= maxWidth) {
|
|
279
|
+
while (cur[cur.length - 1] == " ") {
|
|
280
|
+
cur = cur.substring(0, cur.length - 1);
|
|
281
|
+
}
|
|
282
|
+
return cur.trim() + lineBreakSuffix;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return original;
|
|
286
|
+
}
|
|
287
|
+
static drawText(ctx, str, x, y, fontSize,
|
|
288
|
+
/**
|
|
289
|
+
* Line width of the text stroke.
|
|
290
|
+
*/
|
|
291
|
+
linewidth,
|
|
292
|
+
/**
|
|
293
|
+
* Max width of the text block.
|
|
294
|
+
*/
|
|
295
|
+
maxWidth, textAlign = "left", mainColor = "white", borderColor = "black", font = `"standard-font-title-latin", "standard-font-title-jp"`, lineBreakSuffix = "...") {
|
|
296
|
+
ctx.font = `${fontSize}px ${font}`;
|
|
297
|
+
str = this.findMaxFitString(ctx, str, maxWidth, lineBreakSuffix);
|
|
298
|
+
if (linewidth > 0) {
|
|
299
|
+
ctx.strokeStyle = borderColor;
|
|
300
|
+
ctx.lineWidth = linewidth;
|
|
301
|
+
ctx.lineCap = "round";
|
|
302
|
+
ctx.lineJoin = "round";
|
|
303
|
+
ctx.textAlign = textAlign;
|
|
304
|
+
ctx.strokeText(str, x, y);
|
|
305
|
+
}
|
|
306
|
+
ctx.fillStyle = mainColor;
|
|
307
|
+
ctx.font = `${fontSize}px ${font}`;
|
|
308
|
+
ctx.textAlign = textAlign;
|
|
309
|
+
ctx.fillText(str, x, y);
|
|
310
|
+
if (linewidth > 0) {
|
|
311
|
+
ctx.strokeStyle = mainColor;
|
|
312
|
+
ctx.lineWidth = linewidth / 8;
|
|
313
|
+
ctx.lineCap = "round";
|
|
314
|
+
ctx.lineJoin = "round";
|
|
315
|
+
ctx.font = `${fontSize}px ${font}`;
|
|
316
|
+
ctx.textAlign = textAlign;
|
|
317
|
+
ctx.strokeText(str, x, y);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
static async drawImageModule(ctx, theme, element) {
|
|
321
|
+
const img = new canvas_1.Image();
|
|
322
|
+
img.src = this.getThemeFile(element.path, theme.path);
|
|
323
|
+
ctx.drawImage(img, element.x, element.y, element.width, element.height);
|
|
324
|
+
}
|
|
325
|
+
static async drawScoreGridModule(ctx, theme, element, score, index, x, y) {
|
|
326
|
+
let curColor = "#FFFFFF";
|
|
327
|
+
switch (score.chart.difficulty) {
|
|
328
|
+
case type_1.EDifficulty.BASIC:
|
|
329
|
+
curColor = element.scoreBubble.color.basic;
|
|
330
|
+
break;
|
|
331
|
+
case type_1.EDifficulty.ADVANCED:
|
|
332
|
+
curColor = element.scoreBubble.color.advanced;
|
|
333
|
+
break;
|
|
334
|
+
case type_1.EDifficulty.EXPERT:
|
|
335
|
+
curColor = element.scoreBubble.color.expert;
|
|
336
|
+
break;
|
|
337
|
+
case type_1.EDifficulty.MASTER:
|
|
338
|
+
curColor = element.scoreBubble.color.master;
|
|
339
|
+
break;
|
|
340
|
+
case type_1.EDifficulty.LUNATIC:
|
|
341
|
+
curColor = element.scoreBubble.color.lunatic;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
/** Begin Card Draw */
|
|
345
|
+
ctx.save();
|
|
346
|
+
ctx.fillStyle = new color_1.default(curColor).lighten(0.4).hexa();
|
|
347
|
+
ctx.beginPath();
|
|
348
|
+
ctx.roundRect(x, y, element.scoreBubble.width, element.scoreBubble.height, (element.scoreBubble.height * 0.806) / 7);
|
|
349
|
+
ctx.strokeStyle = new color_1.default(curColor).darken(0.3).hexa();
|
|
350
|
+
ctx.lineWidth = element.scoreBubble.margin / 4;
|
|
351
|
+
ctx.stroke();
|
|
352
|
+
ctx.fill();
|
|
353
|
+
ctx.beginPath();
|
|
354
|
+
ctx.roundRect(x, y, element.scoreBubble.width, element.scoreBubble.height, (element.scoreBubble.height * 0.806) / 7);
|
|
355
|
+
ctx.clip();
|
|
356
|
+
/** Begin Main Content Draw */
|
|
357
|
+
{
|
|
358
|
+
ctx.save();
|
|
359
|
+
ctx.beginPath();
|
|
360
|
+
ctx.roundRect(x, y, element.scoreBubble.width, element.scoreBubble.height * 0.742, (element.scoreBubble.height * 0.806) / 7);
|
|
361
|
+
ctx.clip();
|
|
362
|
+
ctx.fillStyle = curColor;
|
|
363
|
+
ctx.fill();
|
|
364
|
+
const jacketSize = Math.min(element.scoreBubble.width, element.scoreBubble.height * 0.742);
|
|
365
|
+
const jacketMaskGrad = ctx.createLinearGradient(x + jacketSize / 2, y + jacketSize / 2, x + jacketSize, y + jacketSize / 2);
|
|
366
|
+
jacketMaskGrad.addColorStop(0, new color_1.default(curColor).alpha(0).hexa());
|
|
367
|
+
jacketMaskGrad.addColorStop(0.25, new color_1.default(curColor).alpha(0.2).hexa());
|
|
368
|
+
jacketMaskGrad.addColorStop(1, new color_1.default(curColor).alpha(1).hexa());
|
|
369
|
+
const jacketMaskGradDark = ctx.createLinearGradient(x + jacketSize / 2, y + jacketSize / 2, x + jacketSize, y + jacketSize / 2);
|
|
370
|
+
jacketMaskGradDark.addColorStop(0, new color_1.default(curColor).darken(0.3).alpha(0).hexa());
|
|
371
|
+
jacketMaskGradDark.addColorStop(0.25, new color_1.default(curColor).darken(0.3).alpha(0.2).hexa());
|
|
372
|
+
jacketMaskGradDark.addColorStop(1, new color_1.default(curColor).darken(0.3).alpha(1).hexa());
|
|
373
|
+
/** Begin Jacket Draw*/
|
|
374
|
+
let jacket = await chart_1.Chart.Database.fecthJacket(score.chart.id);
|
|
375
|
+
if (!jacket)
|
|
376
|
+
jacket = await chart_1.Chart.Database.fecthJacket(0);
|
|
377
|
+
if (jacket) {
|
|
378
|
+
const img = new canvas_1.Image();
|
|
379
|
+
img.src = jacket;
|
|
380
|
+
ctx.drawImage(img, x, y, jacketSize, jacketSize);
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
ctx.fillStyle = "#b6ffab";
|
|
384
|
+
ctx.fillRect(x, y, jacketSize, jacketSize);
|
|
385
|
+
}
|
|
386
|
+
/** End Jacket Draw*/
|
|
387
|
+
/** Begin Jacket Gradient Mask Draw*/ {
|
|
388
|
+
ctx.fillStyle = jacketMaskGrad;
|
|
389
|
+
ctx.fillRect(x + jacketSize / 2, y, (jacketSize * 3) / 4, jacketSize);
|
|
390
|
+
} /** End Jacket Gradient Mask Draw*/
|
|
391
|
+
ctx.beginPath();
|
|
392
|
+
ctx.roundRect(x + element.scoreBubble.margin, y + element.scoreBubble.margin, element.scoreBubble.width - element.scoreBubble.margin * 2, element.scoreBubble.height * 0.806 -
|
|
393
|
+
element.scoreBubble.margin * 2, (element.scoreBubble.height * 0.806 -
|
|
394
|
+
element.scoreBubble.margin * 2) /
|
|
395
|
+
7);
|
|
396
|
+
/** Begin Title Draw */ {
|
|
397
|
+
this.drawText(ctx, score.chart.name, x + (jacketSize * 7) / 8, y +
|
|
398
|
+
element.scoreBubble.margin +
|
|
399
|
+
element.scoreBubble.height * 0.806 * 0.144, element.scoreBubble.height * 0.806 * 0.144, element.scoreBubble.height * 0.806 * 0.04, element.scoreBubble.width -
|
|
400
|
+
(jacketSize * 7) / 8 -
|
|
401
|
+
element.scoreBubble.margin, "left", "white", jacketMaskGradDark);
|
|
402
|
+
} /** End Title Draw */
|
|
403
|
+
/** Begin Separation Line Draw */ {
|
|
404
|
+
ctx.beginPath();
|
|
405
|
+
ctx.roundRect(x + (jacketSize * 13) / 16, y +
|
|
406
|
+
element.scoreBubble.margin +
|
|
407
|
+
element.scoreBubble.height * 0.806 * (0.144 + 0.072), element.scoreBubble.width -
|
|
408
|
+
(jacketSize * 13) / 16 -
|
|
409
|
+
element.scoreBubble.margin * 2, element.scoreBubble.height * 0.806 * 0.02, element.scoreBubble.height * 0.806 * 0.16);
|
|
410
|
+
ctx.fillStyle = jacketMaskGradDark;
|
|
411
|
+
ctx.fill();
|
|
412
|
+
} /** End Separation Line Draw */
|
|
413
|
+
/** Begin Achievement Rate Draw */
|
|
414
|
+
this.drawText(ctx, score.score.toFixed(0), x -
|
|
415
|
+
element.scoreBubble.margin -
|
|
416
|
+
element.scoreBubble.height * 0.806 * 0.02 +
|
|
417
|
+
element.scoreBubble.width, y +
|
|
418
|
+
element.scoreBubble.margin +
|
|
419
|
+
element.scoreBubble.height *
|
|
420
|
+
0.806 *
|
|
421
|
+
(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());
|
|
422
|
+
/** End Achievement Rate Draw */
|
|
423
|
+
/** Begin Achievement Rank Draw */
|
|
424
|
+
{
|
|
425
|
+
let rankImg;
|
|
426
|
+
switch (score.rank) {
|
|
427
|
+
case type_1.EAchievementTypes.D:
|
|
428
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.d, theme.path);
|
|
429
|
+
break;
|
|
430
|
+
case type_1.EAchievementTypes.C:
|
|
431
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.c, theme.path);
|
|
432
|
+
break;
|
|
433
|
+
case type_1.EAchievementTypes.B:
|
|
434
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.b, theme.path);
|
|
435
|
+
break;
|
|
436
|
+
case type_1.EAchievementTypes.BB:
|
|
437
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.bb, theme.path);
|
|
438
|
+
break;
|
|
439
|
+
case type_1.EAchievementTypes.BBB:
|
|
440
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.bbb, theme.path);
|
|
441
|
+
break;
|
|
442
|
+
case type_1.EAchievementTypes.A:
|
|
443
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.a, theme.path);
|
|
444
|
+
break;
|
|
445
|
+
case type_1.EAchievementTypes.AA:
|
|
446
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.aa, theme.path);
|
|
447
|
+
break;
|
|
448
|
+
case type_1.EAchievementTypes.AAA:
|
|
449
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.aaa, theme.path);
|
|
450
|
+
break;
|
|
451
|
+
case type_1.EAchievementTypes.S:
|
|
452
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.s, theme.path);
|
|
453
|
+
break;
|
|
454
|
+
case type_1.EAchievementTypes.SS:
|
|
455
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.ss, theme.path);
|
|
456
|
+
break;
|
|
457
|
+
case type_1.EAchievementTypes.SSS:
|
|
458
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.sss, theme.path);
|
|
459
|
+
break;
|
|
460
|
+
default:
|
|
461
|
+
rankImg = this.getThemeFile(theme.manifest.sprites.achievement.sssp, theme.path);
|
|
462
|
+
}
|
|
463
|
+
const img = new canvas_1.Image();
|
|
464
|
+
img.src = rankImg;
|
|
465
|
+
ctx.drawImage(img, x + jacketSize * (31 / 32), y +
|
|
466
|
+
element.scoreBubble.margin +
|
|
467
|
+
element.scoreBubble.height * 0.835 * 0.22, element.scoreBubble.height * 0.835 * 0.24 * 2, element.scoreBubble.height * 0.835 * 0.24);
|
|
468
|
+
}
|
|
469
|
+
/** End Achievement Rank Draw */
|
|
470
|
+
/** Begin Milestone Draw */
|
|
471
|
+
{
|
|
472
|
+
let comboImg;
|
|
473
|
+
switch (score.combo) {
|
|
474
|
+
case type_1.EComboTypes.NONE:
|
|
475
|
+
comboImg = this.getThemeFile(theme.manifest.sprites.milestone.none, theme.path);
|
|
476
|
+
break;
|
|
477
|
+
case type_1.EComboTypes.FULL_COMBO:
|
|
478
|
+
comboImg = this.getThemeFile(theme.manifest.sprites.milestone.fc, theme.path);
|
|
479
|
+
break;
|
|
480
|
+
case type_1.EComboTypes.ALL_BREAK:
|
|
481
|
+
comboImg = this.getThemeFile(theme.manifest.sprites.milestone.ab, theme.path);
|
|
482
|
+
break;
|
|
483
|
+
case type_1.EComboTypes.ALL_BREAK_PLUS:
|
|
484
|
+
comboImg = this.getThemeFile(theme.manifest.sprites.milestone.abp, theme.path);
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
let bellImg;
|
|
488
|
+
switch (score.bell) {
|
|
489
|
+
case type_1.EBellTypes.NONE:
|
|
490
|
+
bellImg = this.getThemeFile(theme.manifest.sprites.milestone.none, theme.path);
|
|
491
|
+
break;
|
|
492
|
+
case type_1.EBellTypes.FULL_BELL:
|
|
493
|
+
bellImg = this.getThemeFile(theme.manifest.sprites.milestone.fb, theme.path);
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
const comboWidth = element.scoreBubble.height * 0.806 * 0.24 * 3;
|
|
497
|
+
const comboBackground = comboWidth * 0.9;
|
|
498
|
+
const comboBgRatio = 64 / 272;
|
|
499
|
+
const sizeDiff = comboWidth - comboBackground;
|
|
500
|
+
ctx.fillStyle = "#e8eaec";
|
|
501
|
+
ctx.roundRect(x +
|
|
502
|
+
sizeDiff / 2 +
|
|
503
|
+
element.scoreBubble.width -
|
|
504
|
+
element.scoreBubble.margin -
|
|
505
|
+
comboWidth, y +
|
|
506
|
+
jacketSize -
|
|
507
|
+
(sizeDiff / 2) * comboBgRatio -
|
|
508
|
+
element.scoreBubble.margin -
|
|
509
|
+
comboWidth * comboBgRatio, comboBackground, comboBackground * comboBgRatio, (comboBackground * comboBgRatio) / 2);
|
|
510
|
+
ctx.fill();
|
|
511
|
+
ctx.roundRect(x +
|
|
512
|
+
sizeDiff / 2 +
|
|
513
|
+
element.scoreBubble.width -
|
|
514
|
+
1.5 * element.scoreBubble.margin -
|
|
515
|
+
2 * comboWidth, y +
|
|
516
|
+
jacketSize -
|
|
517
|
+
(sizeDiff / 2) * comboBgRatio -
|
|
518
|
+
element.scoreBubble.margin -
|
|
519
|
+
comboWidth * comboBgRatio, comboBackground, comboBackground * comboBgRatio, (comboBackground * comboBgRatio) / 2);
|
|
520
|
+
ctx.fill();
|
|
521
|
+
const combo = new canvas_1.Image();
|
|
522
|
+
combo.src = comboImg;
|
|
523
|
+
const bell = new canvas_1.Image();
|
|
524
|
+
bell.src = bellImg;
|
|
525
|
+
ctx.drawImage(bell, x +
|
|
526
|
+
element.scoreBubble.width -
|
|
527
|
+
element.scoreBubble.margin -
|
|
528
|
+
comboWidth, y +
|
|
529
|
+
jacketSize -
|
|
530
|
+
element.scoreBubble.margin -
|
|
531
|
+
comboWidth * (84 / 290), comboWidth, comboWidth * (84 / 290));
|
|
532
|
+
ctx.drawImage(combo, x +
|
|
533
|
+
element.scoreBubble.width -
|
|
534
|
+
1.5 * element.scoreBubble.margin -
|
|
535
|
+
2 * comboWidth, y +
|
|
536
|
+
jacketSize -
|
|
537
|
+
element.scoreBubble.margin -
|
|
538
|
+
comboWidth * (84 / 290), comboWidth, comboWidth * (84 / 290));
|
|
539
|
+
}
|
|
540
|
+
/** End Milestone Draw */
|
|
541
|
+
/** Begin Bests Index Draw */
|
|
542
|
+
{
|
|
543
|
+
this.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());
|
|
544
|
+
}
|
|
545
|
+
/** End Bests Index Draw */
|
|
546
|
+
ctx.restore();
|
|
547
|
+
}
|
|
548
|
+
/** End Main Content Draw */
|
|
549
|
+
/** Begin Difficulty & Rating Draw */
|
|
550
|
+
{
|
|
551
|
+
this.drawText(ctx, `${score.chart.level.toFixed(1)} ↑${score.rating.toFixed(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());
|
|
552
|
+
if (score.platinumScore && score.chart.maxPlatinumScore)
|
|
553
|
+
this.drawText(ctx, `${score.platinumScore}/${score.chart.maxPlatinumScore}`, x +
|
|
554
|
+
element.scoreBubble.width -
|
|
555
|
+
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());
|
|
556
|
+
else {
|
|
557
|
+
if (!score.platinumScore)
|
|
558
|
+
console.log(`${score.chart.name} plat, ${score.platinumScore}`);
|
|
559
|
+
if (!score.chart.maxPlatinumScore)
|
|
560
|
+
console.log(`${score.chart.name} max, ${score.platinumScore}`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
/** End Difficulty & Rating Draw */
|
|
564
|
+
ctx.restore();
|
|
565
|
+
/** End Card Draw */
|
|
566
|
+
}
|
|
567
|
+
static async drawProfileModule(ctx, theme, element, username, rating, profilePicture) {
|
|
568
|
+
try {
|
|
569
|
+
const userplate = (0, sharp_1.default)(this.getThemeFile(theme.manifest.sprites.profile.userplate, theme.path));
|
|
570
|
+
const upper = await userplate
|
|
571
|
+
.resize({
|
|
572
|
+
width: 1080,
|
|
573
|
+
height: 166,
|
|
574
|
+
fit: "cover",
|
|
575
|
+
position: "top",
|
|
576
|
+
})
|
|
577
|
+
.png()
|
|
578
|
+
.toBuffer();
|
|
579
|
+
const lower = await userplate
|
|
580
|
+
.resize({
|
|
581
|
+
width: 1080,
|
|
582
|
+
height: 130,
|
|
583
|
+
fit: "cover",
|
|
584
|
+
position: "bottom",
|
|
585
|
+
})
|
|
586
|
+
.png()
|
|
587
|
+
.toBuffer();
|
|
588
|
+
const upperImage = new canvas_1.Image();
|
|
589
|
+
const lowerImage = new canvas_1.Image();
|
|
590
|
+
upperImage.src = upper;
|
|
591
|
+
lowerImage.src = lower;
|
|
592
|
+
ctx.drawImage(upperImage, element.x, element.y, theme.manifest.width, theme.manifest.width * (166 / 1080));
|
|
593
|
+
ctx.drawImage(lowerImage, element.x, element.y +
|
|
594
|
+
theme.manifest.height -
|
|
595
|
+
theme.manifest.width * (130 / 1080), theme.manifest.width, theme.manifest.width * (130 / 1080));
|
|
596
|
+
}
|
|
597
|
+
catch { }
|
|
598
|
+
/* Begin Profile Picture Draw */
|
|
599
|
+
{
|
|
600
|
+
ctx.save();
|
|
601
|
+
ctx.beginPath();
|
|
602
|
+
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, [
|
|
603
|
+
0,
|
|
604
|
+
theme.manifest.width * (7 / 32) * 0.05,
|
|
605
|
+
theme.manifest.width * (7 / 32) * 0.05,
|
|
606
|
+
0,
|
|
607
|
+
]);
|
|
608
|
+
ctx.clip();
|
|
609
|
+
ctx.fillStyle = "white";
|
|
610
|
+
ctx.fill();
|
|
611
|
+
const icon = new canvas_1.Image();
|
|
612
|
+
try {
|
|
613
|
+
(0, sharp_1.default)(profilePicture);
|
|
614
|
+
}
|
|
615
|
+
catch {
|
|
616
|
+
// Unknown profile picture binary
|
|
617
|
+
profilePicture = undefined;
|
|
618
|
+
}
|
|
619
|
+
const pfp = profilePicture ||
|
|
620
|
+
this.getThemeFile(theme.manifest.sprites.profile.icon, theme.path);
|
|
621
|
+
const { dominant } = await (0, sharp_1.default)(pfp).stats();
|
|
622
|
+
icon.src = await (0, sharp_1.default)(pfp).png().toBuffer();
|
|
623
|
+
const cropSize = Math.min(icon.width, icon.height);
|
|
624
|
+
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);
|
|
625
|
+
if (profilePicture) {
|
|
626
|
+
ctx.beginPath();
|
|
627
|
+
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, [
|
|
628
|
+
0,
|
|
629
|
+
theme.manifest.width * (7 / 32) * 0.05,
|
|
630
|
+
theme.manifest.width * (7 / 32) * 0.05,
|
|
631
|
+
0,
|
|
632
|
+
]);
|
|
633
|
+
ctx.strokeStyle = color_1.default.rgb(dominant).darken(0.3).hex();
|
|
634
|
+
ctx.lineWidth = (theme.manifest.width * (7 / 32)) / 128;
|
|
635
|
+
ctx.stroke();
|
|
636
|
+
}
|
|
637
|
+
ctx.restore();
|
|
638
|
+
}
|
|
639
|
+
/* End Profile Picture Draw */
|
|
640
|
+
/* Begin Username Draw */
|
|
641
|
+
{
|
|
642
|
+
ctx.beginPath();
|
|
643
|
+
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, [
|
|
644
|
+
theme.manifest.width * (7 / 32) * 0.05,
|
|
645
|
+
0,
|
|
646
|
+
0,
|
|
647
|
+
theme.manifest.width * (7 / 32) * 0.05,
|
|
648
|
+
]);
|
|
649
|
+
ctx.fillStyle = "rgba(255, 255, 255, 0.45)";
|
|
650
|
+
ctx.fill();
|
|
651
|
+
// const ratingImgBuffer = await this.getRatingNumber(rating, theme);
|
|
652
|
+
// if (ratingImgBuffer) {
|
|
653
|
+
// const { width, height } =
|
|
654
|
+
// await sharp(ratingImgBuffer).metadata();
|
|
655
|
+
// if (width && height) {
|
|
656
|
+
// const aspectRatio = width / height;
|
|
657
|
+
// const image = new Image();
|
|
658
|
+
// image.src = ratingImgBuffer;
|
|
659
|
+
// const drawHeight = (theme.manifest.width * (7/32) * 7) / 32;
|
|
660
|
+
// ctx.drawImage(
|
|
661
|
+
// image,
|
|
662
|
+
// element.x + theme.manifest.width * (7/32) * 2.0,
|
|
663
|
+
// element.y + theme.manifest.width * (7/32) * 0.3,
|
|
664
|
+
// drawHeight * aspectRatio * 0.8,
|
|
665
|
+
// drawHeight
|
|
666
|
+
// );
|
|
667
|
+
// }
|
|
668
|
+
// }
|
|
669
|
+
this.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");
|
|
670
|
+
this.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");
|
|
671
|
+
this.drawText(ctx, 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");
|
|
672
|
+
this.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");
|
|
673
|
+
this.drawText(ctx, rating.toFixed(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");
|
|
674
|
+
}
|
|
675
|
+
/* End Username Draw*/
|
|
676
|
+
}
|
|
677
|
+
static async drawTextModule(ctx, theme, element, variables = {}) {
|
|
678
|
+
let naiveLines = (0, string_template_1.default)(element.content, variables).split("\n");
|
|
679
|
+
let lines = [];
|
|
680
|
+
if (element.linebreak) {
|
|
681
|
+
for (let originalContent of naiveLines) {
|
|
682
|
+
while (originalContent.length) {
|
|
683
|
+
const line = this.findMaxFitString(ctx, originalContent, element.width || Infinity, "");
|
|
684
|
+
originalContent = originalContent.replace(line, "").trim();
|
|
685
|
+
lines.push(line.trim());
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
for (const originalContent of naiveLines) {
|
|
691
|
+
lines.push(this.findMaxFitString(ctx, originalContent, element.width || Infinity));
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
for (let i = 0; i < lines.length; ++i) {
|
|
695
|
+
const line = lines[i];
|
|
696
|
+
this.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
|
|
697
|
+
? element.borderColor
|
|
698
|
+
: color_1.default.rgb(element.color || "#FFFFFF")
|
|
699
|
+
.darken(0.3)
|
|
700
|
+
.hex(), element.font, element.linebreak ? "" : "...");
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
/* End Draw Tools*/
|
|
704
|
+
static async draw(name, rating, newScores, oldScores, recentOrPlatinumScores, options = { type: "refresh" }) {
|
|
705
|
+
let currentTheme = this.primaryTheme;
|
|
706
|
+
if (options?.theme) {
|
|
707
|
+
let theme = this.getTheme(options.theme + "-" + options.type);
|
|
708
|
+
if (theme) {
|
|
709
|
+
currentTheme = theme;
|
|
710
|
+
}
|
|
711
|
+
theme = this.getTheme(options.theme);
|
|
712
|
+
if (theme) {
|
|
713
|
+
currentTheme = theme;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
if (currentTheme) {
|
|
717
|
+
await chart_1.Chart.Database.cacheJackets([
|
|
718
|
+
...newScores.map((v) => v.chart.id),
|
|
719
|
+
...oldScores.map((v) => v.chart.id),
|
|
720
|
+
]);
|
|
721
|
+
const canvas = new canvas_1.Canvas(currentTheme.manifest.width * (options?.scale ?? 1), currentTheme.manifest.height * (options?.scale ?? 1));
|
|
722
|
+
const ctx = canvas.getContext("2d");
|
|
723
|
+
if (options?.scale)
|
|
724
|
+
ctx.scale(options.scale, options.scale);
|
|
725
|
+
ctx.imageSmoothingEnabled = true;
|
|
726
|
+
for (const element of currentTheme.manifest.elements) {
|
|
727
|
+
switch (element.type) {
|
|
728
|
+
case "image": {
|
|
729
|
+
await this.drawImageModule(ctx, currentTheme, element);
|
|
730
|
+
break;
|
|
731
|
+
}
|
|
732
|
+
case "score-grid": {
|
|
733
|
+
const gapx = typeof element.scoreBubble.gap == "number"
|
|
734
|
+
? element.scoreBubble.gap
|
|
735
|
+
: element.scoreBubble.gap.x;
|
|
736
|
+
const gapy = typeof element.scoreBubble.gap == "number"
|
|
737
|
+
? element.scoreBubble.gap
|
|
738
|
+
: element.scoreBubble.gap.y;
|
|
739
|
+
for (let y = element.y, index = element.index, i = 0; i < element.verticalSize; ++i, y += element.scoreBubble.height + gapy) {
|
|
740
|
+
for (let x = element.x, j = 0; j < element.horizontalSize; ++j,
|
|
741
|
+
++index,
|
|
742
|
+
x += element.scoreBubble.width + gapx) {
|
|
743
|
+
let curScore;
|
|
744
|
+
if (element.region == "new")
|
|
745
|
+
curScore = newScores[index];
|
|
746
|
+
else if (element.region == "old")
|
|
747
|
+
curScore = oldScores[index];
|
|
748
|
+
else
|
|
749
|
+
curScore = recentOrPlatinumScores[index];
|
|
750
|
+
if (curScore) {
|
|
751
|
+
await this.drawScoreGridModule(ctx, currentTheme, element, curScore, index, x, y);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
case "profile": {
|
|
758
|
+
await this.drawProfileModule(ctx, currentTheme, element, name, rating, options?.profilePicture);
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
case "text": {
|
|
762
|
+
function getNaiveRating(length) {
|
|
763
|
+
const bestScores = options?.bestScores;
|
|
764
|
+
if (!bestScores)
|
|
765
|
+
return 0;
|
|
766
|
+
return getRatingAvg(bestScores.slice(0, length), length);
|
|
767
|
+
}
|
|
768
|
+
function getRatingAvg(scores, length) {
|
|
769
|
+
if (scores.length <= 0)
|
|
770
|
+
return 0;
|
|
771
|
+
return (scores
|
|
772
|
+
.slice(0, length)
|
|
773
|
+
.map((v) => v.rating)
|
|
774
|
+
.reduce((sum, v) => (sum += v)) / length);
|
|
775
|
+
}
|
|
776
|
+
await this.drawTextModule(ctx, currentTheme, element, {
|
|
777
|
+
username: HalfFullWidthConvert.toFullWidth(name),
|
|
778
|
+
rating: rating.toFixed(2),
|
|
779
|
+
naiveBest45: getNaiveRating(45).toFixed(2),
|
|
780
|
+
newScoreRatingAvg: getRatingAvg(newScores, options.type == "refresh" ? 10 : 15).toFixed(2),
|
|
781
|
+
oldScoreRatingAvg: getRatingAvg(oldScores, options.type == "refresh" ? 50 : 30).toFixed(2),
|
|
782
|
+
recentOrPlatinumScoreAvg: getRatingAvg(recentOrPlatinumScores, options.type == "refresh" ? 50 : 10).toFixed(2),
|
|
783
|
+
});
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return canvas.toBuffer();
|
|
789
|
+
}
|
|
790
|
+
else
|
|
791
|
+
return null;
|
|
792
|
+
}
|
|
793
|
+
static async drawWithScoreSource(source, username, options = { type: "refresh" }) {
|
|
794
|
+
const profile = await source.getPlayerInfo(username, options.type);
|
|
795
|
+
if (!profile)
|
|
796
|
+
return null;
|
|
797
|
+
let newScores, oldScores, recentOrPlatinumScores, bestScores;
|
|
798
|
+
if (options.type == "refresh") {
|
|
799
|
+
const score = await source.getPlayerBest60(username);
|
|
800
|
+
if (!score)
|
|
801
|
+
return null;
|
|
802
|
+
newScores = score.new;
|
|
803
|
+
oldScores = score.old;
|
|
804
|
+
recentOrPlatinumScores = score.plat;
|
|
805
|
+
bestScores = score.best;
|
|
806
|
+
}
|
|
807
|
+
else if (options.type == "classic") {
|
|
808
|
+
const score = await source.getPlayerBest55(username);
|
|
809
|
+
if (!score)
|
|
810
|
+
return null;
|
|
811
|
+
recentOrPlatinumScores = score.recent;
|
|
812
|
+
newScores = score.new;
|
|
813
|
+
oldScores = score.old;
|
|
814
|
+
bestScores = score.best;
|
|
815
|
+
}
|
|
816
|
+
else
|
|
817
|
+
return null;
|
|
818
|
+
return this.draw(profile.name, profile.rating, newScores, oldScores, recentOrPlatinumScores, {
|
|
819
|
+
...options,
|
|
820
|
+
profilePicture: options?.profilePicture === null
|
|
821
|
+
? undefined
|
|
822
|
+
: options?.profilePicture ||
|
|
823
|
+
(await source.getPlayerProfilePicture(username)) ||
|
|
824
|
+
undefined,
|
|
825
|
+
bestScores,
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
static async getRatingNumber(num, theme) {
|
|
829
|
+
async function getRaingDigit(map, digit, unitWidth, unitHeight) {
|
|
830
|
+
digit = Math.floor(digit % 10);
|
|
831
|
+
return await (0, sharp_1.default)(map)
|
|
832
|
+
.extract({
|
|
833
|
+
left: (digit % 4) * unitWidth,
|
|
834
|
+
top: Math.floor(digit / 4) * unitHeight,
|
|
835
|
+
width: unitWidth,
|
|
836
|
+
height: unitHeight,
|
|
837
|
+
})
|
|
838
|
+
.toBuffer();
|
|
839
|
+
}
|
|
840
|
+
if (theme.manifest) {
|
|
841
|
+
const map = this.getThemeFile(theme.manifest.sprites.ratingNumberMap, theme.path);
|
|
842
|
+
const { width, height } = await (0, sharp_1.default)(map).metadata();
|
|
843
|
+
if (!(width && height))
|
|
844
|
+
return null;
|
|
845
|
+
const unitWidth = width / 4, unitHeight = height / 4;
|
|
846
|
+
let digits = [];
|
|
847
|
+
while (num != Math.floor(num)) {
|
|
848
|
+
num *= 10;
|
|
849
|
+
}
|
|
850
|
+
while (num > 0) {
|
|
851
|
+
digits.push(await getRaingDigit(map, num % 10, unitWidth, unitHeight));
|
|
852
|
+
num = Math.floor(num / 10);
|
|
853
|
+
}
|
|
854
|
+
while (digits.length < 5)
|
|
855
|
+
digits.push(null);
|
|
856
|
+
digits = digits.reverse();
|
|
857
|
+
const canvas = new canvas_1.Canvas(unitWidth * digits.length, unitHeight);
|
|
858
|
+
const ctx = canvas.getContext("2d");
|
|
859
|
+
for (let i = 0; i < digits.length; ++i) {
|
|
860
|
+
const curDigit = digits[i];
|
|
861
|
+
if (!curDigit)
|
|
862
|
+
continue;
|
|
863
|
+
const img = new canvas_1.Image();
|
|
864
|
+
img.src = curDigit;
|
|
865
|
+
ctx.drawImage(img, unitWidth * i * 0.88, 0);
|
|
866
|
+
}
|
|
867
|
+
return canvas.toBuffer();
|
|
868
|
+
}
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
exports.Best50 = Best50;
|
|
873
|
+
(function (Best50) {
|
|
874
|
+
Best50.KamaiTachi = kamaiTachi.KamaiTachi;
|
|
875
|
+
})(Best50 || (exports.Best50 = Best50 = {}));
|
|
876
|
+
//# sourceMappingURL=best50.js.map
|