(funbox: FunboxName, nosave?: boolean)
| 153 | } |
| 154 | |
| 155 | export function toggleFunbox(funbox: FunboxName, nosave?: boolean): boolean { |
| 156 | if (TestState.isActive && Config.funbox.includes("no_quit")) { |
| 157 | showNoticeNotification( |
| 158 | "No quit funbox is active. Please finish the test.", |
| 159 | { |
| 160 | important: true, |
| 161 | }, |
| 162 | ); |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | const funboxCheck = canSetFunboxWithConfig(funbox, Config); |
| 167 | if (!funboxCheck.ok) { |
| 168 | const errorStrings = funboxCheck.errors.map( |
| 169 | (e) => |
| 170 | `${capitalizeFirstLetter( |
| 171 | camelCaseToWords(e.key), |
| 172 | )} cannot be set to ${String(e.value)}.`, |
| 173 | ); |
| 174 | showNoticeNotification( |
| 175 | `You can't enable ${escapeHTML(funbox.replace(/_/g, " "))}:<br />${errorStrings.map((s) => escapeHTML(s)).join("<br />")}`, |
| 176 | { durationMs: 5000, useInnerHtml: true }, |
| 177 | ); |
| 178 | return false; |
| 179 | } |
| 180 | |
| 181 | const previousValue = Config.funbox; |
| 182 | |
| 183 | let newConfig: FunboxName[] = Config.funbox; |
| 184 | |
| 185 | if (newConfig.includes(funbox)) { |
| 186 | newConfig = newConfig.filter((it) => it !== funbox); |
| 187 | } else { |
| 188 | newConfig = [...newConfig, funbox].sort(); |
| 189 | } |
| 190 | |
| 191 | if (!isConfigValueValid("funbox", newConfig, ConfigSchemas.FunboxSchema)) { |
| 192 | return false; |
| 193 | } |
| 194 | |
| 195 | Config.funbox = newConfig; |
| 196 | saveToLocalStorage("funbox", nosave); |
| 197 | configEvent.dispatch({ |
| 198 | key: "funbox", |
| 199 | newValue: Config.funbox, |
| 200 | nosave, |
| 201 | previousValue, |
| 202 | }); |
| 203 | |
| 204 | setConfigStore("funbox", newConfig); |
| 205 | |
| 206 | return true; |
| 207 | } |
no test coverage detected