blob: adf0bb78beb2cc03b61f3820ada89a4287cff25f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/**
* @param {string} slug
*
* @returns {(string|MonsterSlug|TechniqueSlug)}
*/
function slugToName (slug) {
const ucfirst = (str) => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
return slug
.split('_').map((item) => ucfirst(item)).join(' ')
.split('-').map((item) => ucfirst(item)).join(' ');
}
/**
* @param {string} color
*
* @returns {string}
*/
function standardizeColor (color) {
var ctx = document.createElement('canvas').getContext('2d');
ctx.fillStyle = color;
return ctx.fillStyle;
}
/**
* @param {...string} colors
*
* @returns {string} rgb
*/
function mixColors(...colors) {
let r = 0;
let g = 0;
let b = 0;
for (const color of colors) {
const [cr, cg, cb] = color.match(/\w\w/g).map((c) => parseInt(c, 16));
r += cr;
g += cg;
b += cb;
}
r = r / colors.length;
g = g / colors.length;
b = b / colors.length;
return `rgb(${r}, ${g}, ${b})`;
}
/**
* @returns {string}
*/
function randomString () {
return (Math.random() + 1).toString(36).substring(2);
}
/**
* @param {string} msgid
*/
function translate (msgid) {
return DB.translations[Memory.state.Settings.language][msgid];
}
/**
* @param {number} amount
*
* @returns {number}
*/
function convertToCurrencyBase (amount) {
const baseDecimalDiff = 2 - DB.currencies.map[Memory.state.Settings.currency].decimals;
return amount * Math.pow(10, baseDecimalDiff);
}
/**
* @param {number} price
*
* @returns {number}
*/
function formatPrice (price) {
return `${price} ${DB.currencies.map[Memory.state.Settings.currency].symbol}`;
}
|