2023-01-14 18:30:06 -05:00
/* Helps make managing many dependencies easier */
2023-01-19 22:15:31 -05:00
// Version 1.0.1
// Update Description: Refresh quickfix
let _ _needRefresh = false ;
2023-01-14 18:30:06 -05:00
2023-01-19 22:15:31 -05:00
window . addEventListener ( "load" , e => {
if ( _ _needRefresh ) location . reload ( ) ;
} ) ;
2023-01-14 18:20:39 -05:00
/ *
* Requires that certain mods are installed for the callback to proceed .
* @ param { array } mods - The mods your mod depends on .
* @ param { function } callback - The callback to run when the dependencies are met .
* /
function requireMods ( mods , cal ) {
if ( _ _checkMods ( mods ) ) {
2023-01-14 18:30:06 -05:00
// The whole callback system remains from a feature that was nerfed soon before release. It will either be removed or taken advantage of in future versions.
2023-01-14 18:20:39 -05:00
cal ( ) ;
}
else {
_ _installMods ( mods ) ;
2023-01-19 22:15:31 -05:00
_ _needRefresh = true ;
2023-01-14 18:20:39 -05:00
}
}
/ *
* Fetches the name of any mods that are missing
* @ param { array } mods - The mods your mod depends on .
* @ returns { array } An array of missing mods .
* /
function _ _getMissingMods ( mods ) {
let missing = [ ] ;
for ( let i = 0 ; i < mods . length ; i ++ ) {
if ( enabledMods . includes ( mods [ i ] ) ) {
continue ;
}
missing . push ( mods [ i ] ) ;
}
return missing ;
}
/ *
* Checks if any mods are missing .
* @ param { array } mods - The mods your mod depends on .
* @ returns { boolean } True if any mods are missing .
* /
function _ _checkMods ( mods ) {
return _ _getMissingMods ( mods ) . length === 0 ;
}
function _ _installMods ( mods ) {
_ _getMissingMods ( mods ) . forEach ( mod => _ _installMod ( mod ) ) ;
}
function _ _installMod ( mod ) {
2023-01-19 22:15:31 -05:00
let mods = JSON . parse ( localStorage . getItem ( "enabledMods" ) || "[]" ) ;
2023-01-14 18:20:39 -05:00
mods . push ( mod ) ;
2023-01-19 22:15:31 -05:00
localStorage . setItem ( "enabledMods" , JSON . stringify ( mods ) ) ;
2023-01-14 18:20:39 -05:00
}
// Ensure it's available in the global scope
window . requireMods = requireMods ;