57 lines
1.6 kB
1
import { SettingsSection, Settings as SettingsType } from "@moonlight-mod/types/coreExtensions/settings";
2
3
export const Settings: SettingsType = {
4
ourSections: [],
5
sectionNames: [],
6
sectionMenuItems: {},
7
8
addSection: (section, label, element, color = null, pos, notice) => {
9
const data: SettingsSection = {
10
section,
11
label,
12
color,
13
element,
14
pos: pos ?? -4,
15
notice: notice
16
};
17
18
Settings.ourSections.push(data);
19
Settings.sectionNames.push(section);
20
return data;
21
},
22
addSectionMenuItems(section, ...newItems) {
23
const data = Settings.ourSections.find((x) => x.section === section);
24
if (!data || !("element" in data)) throw new Error(`Could not find section "${section}"`);
25
(Settings.sectionMenuItems[section] ??= []).push(...newItems);
26
data._moonlight_submenu ??= () => Settings.sectionMenuItems[section];
27
},
28
29
addDivider: (pos = null) => {
30
Settings.ourSections.push({
31
section: "DIVIDER",
32
pos: pos === null ? -4 : pos
33
});
34
},
35
36
addHeader: function (label, pos = null) {
37
Settings.ourSections.push({
38
section: "HEADER",
39
label: label,
40
pos: pos === null ? -4 : pos
41
});
42
},
43
44
_mutateSections: (sections) => {
45
for (const section of Settings.ourSections) {
46
// Discord's `pos` only supports numbers, so lets call the function to get the position.
47
if (typeof section.pos === "function") {
48
section.pos = section.pos(sections);
49
}
50
sections.splice(section.pos < 0 ? sections.length + section.pos : section.pos, 0, section);
51
}
52
53
return sections;
54
}
55
};
56
57
export default Settings;
58