-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmacrodata.js
More file actions
57 lines (52 loc) · 1.63 KB
/
macrodata.js
File metadata and controls
57 lines (52 loc) · 1.63 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const emptyBins = [
{WO: 0, FC: 0, DR: 0, MA: 0},
{WO: 0, FC: 0, DR: 0, MA: 0},
{WO: 0, FC: 0, DR: 0, MA: 0},
{WO: 0, FC: 0, DR: 0, MA: 0},
{WO: 0, FC: 0, DR: 0, MA: 0}
];
class MacrodataFile {
constructor() {
this.localStorageKey = 'hackx-data';
const file = JSON.parse(localStorage.getItem(this.localStorageKey)) ?? this.assignFile();
this.fileName = file.fileName;
this.storedBins = file.storedBins;
this.coordinates = file.coordinates;
}
assignFile() {
const names = HACKX_CONFIG.projectNames;
const allButPrevious = names.filter(f => f !== this.fileName);
const fileName = allButPrevious[Math.floor(Math.random() * allButPrevious.length)];
const coordinates = this.#generateCoordinates();
const macrodata = {
fileName,
storedBins: emptyBins,
coordinates
};
localStorage.setItem(this.localStorageKey, JSON.stringify(macrodata));
return macrodata;
}
updateProgress(bins) {
const updatedFile = {
fileName: this.fileName,
storedBins: bins,
coordinates: this.coordinates
};
localStorage.setItem(this.localStorageKey, JSON.stringify(updatedFile));
}
resetFile() {
localStorage.removeItem(this.localStorageKey);
const file = this.assignFile();
this.fileName = file.fileName;
this.storedBins = file.storedBins;
this.coordinates = file.coordinates;
}
#generateCoordinates() {
function randHex() {
return floor(random(0, 256)).toString(16).toUpperCase().padStart(2, '0');
}
let x = randHex() + randHex() + randHex();
let y = randHex() + randHex() + randHex();
return `0x${x} : 0x${y}`;
}
}