-
Notifications
You must be signed in to change notification settings - Fork 54
/
transformWarframe.mjs
64 lines (58 loc) 路 1.96 KB
/
transformWarframe.mjs
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
import getColors from 'get-image-colors';
import { image as getImage } from 'image-downloader';
import transformPolarity from './transformPolarity.mjs';
const mapColors = async (oldFrame, imageUrl) => {
if (!imageUrl) return 0;
try {
const options = {
url: imageUrl,
dest: `tmp/tmp-${oldFrame.Name}.png`,
};
const { image } = await getImage(options);
const colors = await getColors(image, 'image/png');
return typeof colors !== 'undefined' ? colors[0].hex().replace('#', '0x') : 0xff0000;
} catch (e) {
if (process.env.DEBUG) console.error(e);
return 0;
}
};
/**
* Transform wikia lua weapons into usable standardized json
* @param {Object} oldFrame old warframe in lua format
* @param {Record<string, unknown>} imageUrls name-url pairs
* @param {Record<string, Object>} blueprints blueprint objects
* @returns {Promise<WikiaWarframe>}
*/
export default async (oldFrame, imageUrls, blueprints) => {
let newFrame;
if (!oldFrame || !oldFrame.Name) {
return undefined;
}
try {
const { AuraPolarity, Conclave, Image, Mastery, Polarities, Sprint, Introduced, Sex, Vaulted } = oldFrame;
const { Name } = oldFrame;
newFrame = {
name: Name,
url: `https://warframe.fandom.com/wiki/${encodeURIComponent(
Name.replace(/\s/g, '_').replace('_Prime', '/Prime')
)}`,
auraPolarity: AuraPolarity,
conclave: Conclave,
mr: Mastery || 0,
polarities: Polarities,
sprint: Sprint,
introduced: Introduced,
sex: Sex,
vaulted: Vaulted || undefined,
thumbnail: imageUrls?.[Image],
color: parseInt(await mapColors(oldFrame, imageUrls?.[Image]), 16),
marketCost: blueprints[Name] && blueprints[Name].MarketCost,
bpCost: blueprints[Name] && blueprints[Name].BPCost,
};
newFrame = transformPolarity(oldFrame, newFrame);
} catch (error) {
console.error(`Error parsing ${oldFrame.Name}`);
console.error(error);
}
return newFrame;
};