-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodlist.js
More file actions
80 lines (58 loc) · 2.63 KB
/
modlist.js
File metadata and controls
80 lines (58 loc) · 2.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Mod } from './mod.js'
import { ModReport } from './modreport.js'
export class Modlist {
constructor(modListJSONString) {
this.modListArray = []
const modListJsonObject = JSON.parse(modListJSONString)
for (let modJSONObject of modListJsonObject) {
this.modListArray.push(new Mod(
modJSONObject['name'],
modJSONObject['url'],
modJSONObject['version'],
modJSONObject['authors']?.[0] ?? "", // Again, we only consider the first author
modJSONObject['version']
))
}
}
compare(modList) {
let modReports = []
const secondModListArray = modList.getModListArray()
this.modListArray.forEach((mod) => {
let modFound = false
for (let secondModListMod of secondModListArray) {
const bitmask = mod.compare(secondModListMod)
if (bitmask & Mod.BIT_NAME) continue // This is an entirely different mod, we can skip checking the rest
if (bitmask & Mod.BIT_VERSION) {
modReports.push(new ModReport(ModReport.MOD_VERSION_MISMATCH, mod, secondModListMod.getModVersion()))
modFound = true // The mod IS there, it just has a different version
continue
}
if (bitmask & Mod.BIT_FILENAME) { // Ideally this never happens because the version is also likely different
modReports.push(new ModReport(ModReport.MOD_FILENAME_MISMATCH, mod, secondModListMod.getModFilename()))
modFound = true
continue
}
modFound = true // If this part of the code is reached, it means that all the fields are identical (no bits set)
break
}
if (!modFound) modReports.push(new ModReport(ModReport.MOD_MISSING, mod))
})
for (let secondModListMod of secondModListArray) {
let correspondingModFound = false
for (let mod of this.modListArray) {
const bitmask = secondModListMod.compare(mod)
if (!(bitmask & Mod.BIT_NAME)
&& !(bitmask & Mod.BIT_URL)
&& !(bitmask & Mod.BIT_AUTHOR)) {
correspondingModFound = true
break
}
}
if (!correspondingModFound) modReports.push(new ModReport(ModReport.MOD_UNEXPECTED, secondModListMod))
}
return modReports
}
getModListArray() {
return this.modListArray
}
}