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