-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-arena.js
More file actions
43 lines (37 loc) · 1.17 KB
/
Copy pathcheck-arena.js
File metadata and controls
43 lines (37 loc) · 1.17 KB
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
const sharp = require('sharp');
const _ = require('lodash');
const fs = require('fs');
sharp.cache(false);
const areaColorsJson = fs.readFileSync('arena-color.json');
const areaColors = JSON.parse(areaColorsJson.toString());
const isArenaConfirm = async (filename) => {
const image = sharp(filename);
const panel = await image.extract({
left: 0,
top: 510,
width: 1073,
height: 300,
});
const buffer = await image.toFormat('jpg').raw().toBuffer()
const colors = [];
for (let i = 0; i < buffer.length; i+=4) {
colors.push([buffer[i], buffer[i+1], buffer[i+2]]);
}
let same = 0;
for (let i = 0; i < colors.length; i++) {
const newColor = (
areaColors[i][0] - colors[i][0] + areaColors[i][1] - colors[i][1] + areaColors[i][2] - colors[i][2]
);
if (newColor < 1) {
same += 1;
}
}
const percentage = same / colors.length;
return percentage > 0.98;
}
const test = async () => {
console.log(await isArenaConfirm('example/arena/current.png'));
console.log(await isArenaConfirm('example/arena/level-up-3.png'));
console.log(await isArenaConfirm('example/arena/Screenshot_1666965174.png'));
}
module.exports = {isArenaConfirm}