@ -19,9 +19,6 @@
* THE SOFTWARE .
* THE SOFTWARE .
* /
* /
/* We don't want localstorage variables 'optimised' to different identifiers*/
/*jshint -W069 */
( function ( window , document ) {
( function ( window , document ) {
"use strict" ;
"use strict" ;
@ -106,7 +103,7 @@ class HuesCore {
/ * c a l l b a c k s e t t i n g s u p d a t e d ( )
/ * c a l l b a c k s e t t i n g s u p d a t e d ( )
*
*
* Called when settings are updated and should be re - read from localStorage
* Called when settings are updated and should be re - read from the settings object
* /
* /
settingsupdated : [ ]
settingsupdated : [ ]
} ;
} ;
@ -131,25 +128,27 @@ class HuesCore {
this . colourIndex = 0x3f ;
this . colourIndex = 0x3f ;
this . colours = HuesCore . oldColours ;
this . colours = HuesCore . oldColours ;
this . isFullAuto = true ;
this . invert = false ;
this . invert = false ;
this . loopCount = 0 ;
this . loopCount = 0 ;
this . doBuildup = true ;
this . doBuildup = true ;
this . userInterface = null ;
this . userInterface = null ;
this . uiArray = [ ] ;
this . uiArray = [ ] ;
this . settings = new HuesSettings ( defaults ) ;
zip . workerScriptsPath = this . settings . workersPath ;
// What's our root element?
// What's our root element?
this . root = null ;
this . root = null ;
if ( ! defaults . root ) {
if ( ! this . setting s. root ) {
this . root = document . body ;
this . root = document . body ;
} else if ( typeof default s. root === "string" ) {
} else if ( typeof this . setting s. root === "string" ) {
if ( default s. root && document . getElementById ( default s. root ) ) {
if ( this . setting s. root && document . getElementById ( this . setting s. root ) ) {
this . root = document . getElementById ( default s. root ) ;
this . root = document . getElementById ( this . setting s. root ) ;
} else {
} else {
this . root = document . body ;
this . root = document . body ;
}
}
} else { // been given an element
} else { // been given an element
this . root = default s. root ;
this . root = this . setting s. root ;
}
}
this . root . classList . add ( "hues-root" ) ;
this . root . classList . add ( "hues-root" ) ;
// Special case for full page Hues
// Special case for full page Hues
@ -159,7 +158,7 @@ class HuesCore {
// Yes, we do indeed have Javascript
// Yes, we do indeed have Javascript
this . root . innerHTML = "" ;
this . root . innerHTML = "" ;
this . makePreloader ( this . root , defaults ) ;
this . makePreloader ( this . root ) ;
window . onerror = ( msg , url , line , col , error ) => {
window . onerror = ( msg , url , line , col , error ) => {
this . error ( msg ) ;
this . error ( msg ) ;
@ -167,21 +166,16 @@ class HuesCore {
return false ;
return false ;
} ;
} ;
this . settings = new HuesSettings ( defaults ) ;
this . window = new HuesWindow ( this . root , this . settings ) ;
// Update with merged defaults
defaults = this . settings . defaults ;
zip . workerScriptsPath = defaults . workersPath ;
this . window = new HuesWindow ( this . root , defaults ) ;
console . log ( "0x40 Hues v" + this . versionStr + " - start your engines!" ) ;
console . log ( "0x40 Hues v" + this . versionStr + " - start your engines!" ) ;
this . resourceManager = new Resources ( this , this . window ) ;
this . resourceManager = new Resources ( this , this . window ) ;
this . editor = new HuesEditor ( this , this . window ) ;
this . editor = new HuesEditor ( this , this . window ) ;
this . settings . initUI ( this . window ) ;
this . settings . initUI ( this . window ) ;
populateHuesInfo ( this . versionStr , this . window , default s) ;
populateHuesInfo ( this . versionStr , this . window , this . setting s) ;
this . window . selectTab ( default s. firstWindow , true ) ;
this . window . selectTab ( this . setting s. firstWindow , true ) ;
let ui = document . createElement ( "div" ) ;
let ui = document . createElement ( "div" ) ;
ui . className = "hues-ui" ;
ui . className = "hues-ui" ;
@ -189,7 +183,7 @@ class HuesCore {
this . uiArray . push ( new RetroUI ( ui ) , new WeedUI ( ui ) , new ModernUI ( ui ) ,
this . uiArray . push ( new RetroUI ( ui ) , new WeedUI ( ui ) , new ModernUI ( ui ) ,
new XmasUI ( ui ) , new HalloweenUI ( ui ) , new MinimalUI ( ui ) ) ;
new XmasUI ( ui ) , new HalloweenUI ( ui ) , new MinimalUI ( ui ) ) ;
this . autoSong = localStorage [ "autoSong" ] ;
this . autoSong = this . settings . autoSong ;
this . visualiser = document . createElement ( "canvas" ) ;
this . visualiser = document . createElement ( "canvas" ) ;
this . visualiser . className = "hues-visualiser" ;
this . visualiser . className = "hues-visualiser" ;
@ -199,10 +193,10 @@ class HuesCore {
this . soundManager = new SoundManager ( this ) ;
this . soundManager = new SoundManager ( this ) ;
this . soundManager . init ( ) . then ( ( ) => {
this . soundManager . init ( ) . then ( ( ) => {
if ( ! this . soundManager . locked && localStorage [ "skipPreloader" ] == "on" ) {
if ( ! this . soundManager . locked && this . settings . skipPreloader == "on" ) {
return null ;
return null ;
} else {
} else {
return this . resourceManager . getSizes ( default s. respacks ) ;
return this . resourceManager . getSizes ( this . setting s. respacks ) ;
}
}
} ) . then ( sizes => {
} ) . then ( sizes => {
if ( sizes === null ) {
if ( sizes === null ) {
@ -238,12 +232,14 @@ class HuesCore {
this . setColour ( this . colourIndex ) ;
this . setColour ( this . colourIndex ) ;
this . animationLoop ( ) ;
this . animationLoop ( ) ;
if ( default s. load ) {
if ( this . setting s. load ) {
return this . resourceManager . addAll ( default s. respacks , progress => {
return this . resourceManager . addAll ( this . setting s. respacks , progress => {
this . preloader . style . backgroundPosition = ( 100 - progress * 100 ) + "% 0%" ;
this . preloader . style . backgroundPosition = ( 100 - progress * 100 ) + "% 0%" ;
let scale = Math . floor ( progress * defaults . preloadMax ) ;
let scale = Math . floor ( progress * this . settings . preloadMax ) ;
let padding = defaults . preloadMax . toString ( defaults . preloadBase ) . length ;
let padding = this . settings . preloadMax . toString ( this . settings . preloadBase ) . length ;
this . preloadMsg . textContent = defaults . preloadPrefix + ( Array ( padding ) . join ( "0" ) + scale . toString ( defaults . preloadBase ) ) . slice ( - padding ) ;
this . preloadMsg . textContent = this . settings . preloadPrefix +
( Array ( padding ) . join ( "0" ) +
scale . toString ( this . settings . preloadBase ) ) . slice ( - padding ) ;
} ) ;
} ) ;
} else {
} else {
this . preloader . style . display = "none" ;
this . preloader . style . display = "none" ;
@ -252,14 +248,14 @@ class HuesCore {
} ) . then ( ( ) => {
} ) . then ( ( ) => {
this . preloader . classList . add ( "hues-preloader--loaded" ) ;
this . preloader . classList . add ( "hues-preloader--loaded" ) ;
this . callEventListeners ( "loaded" ) ;
this . callEventListeners ( "loaded" ) ;
if ( default s. firstImage ) {
if ( this . setting s. firstImage ) {
this . setImageByName ( default s. firstImage ) ;
this . setImageByName ( this . setting s. firstImage ) ;
} else {
} else {
this . setImage ( 0 ) ;
this . setImage ( 0 ) ;
}
}
if ( default s. autoplay ) {
if ( this . setting s. autoplay ) {
if ( default s. firstSong ) {
if ( this . setting s. firstSong ) {
this . setSongByName ( default s. firstSong ) ;
this . setSongByName ( this . setting s. firstSong ) ;
} else {
} else {
this . setSong ( 0 ) ;
this . setSong ( 0 ) ;
}
}
@ -268,7 +264,7 @@ class HuesCore {
this . error ( error ) ;
this . error ( error ) ;
} ) ;
} ) ;
if ( ! default s. disableKeyboard ) {
if ( ! this . setting s. disableKeyboard ) {
document . addEventListener ( "keydown" , e => {
document . addEventListener ( "keydown" , e => {
e = e || window . event ;
e = e || window . event ;
if ( e . defaultPrevented ) {
if ( e . defaultPrevented ) {
@ -316,15 +312,15 @@ class HuesCore {
}
}
}
}
makePreloader ( root , defaults ) {
makePreloader ( root ) {
this . preloader = document . createElement ( "div" ) ;
this . preloader = document . createElement ( "div" ) ;
this . preloader . className = "hues-preloader" ;
this . preloader . className = "hues-preloader" ;
root . appendChild ( this . preloader ) ;
root . appendChild ( this . preloader ) ;
if ( default s. preloadTitle ) {
if ( this . setting s. preloadTitle ) {
this . preloadTitle = document . createElement ( "div" ) ;
this . preloadTitle = document . createElement ( "div" ) ;
this . preloadTitle . className = "hues-preloader__title" ;
this . preloadTitle . className = "hues-preloader__title" ;
this . preloadTitle . textContent = default s. preloadTitle ;
this . preloadTitle . textContent = this . setting s. preloadTitle ;
this . preloader . appendChild ( this . preloadTitle ) ;
this . preloader . appendChild ( this . preloadTitle ) ;
}
}
@ -343,7 +339,7 @@ class HuesCore {
}
}
updateVisualiser ( ) {
updateVisualiser ( ) {
if ( localStorage [ "visualiser" ] != "on" ) {
if ( this . settings . visualiser != "on" ) {
return ;
return ;
}
}
@ -509,7 +505,7 @@ class HuesCore {
this . callEventListeners ( "newsong" , this . currentSong ) ;
this . callEventListeners ( "newsong" , this . currentSong ) ;
this . loopCount = 0 ;
this . loopCount = 0 ;
if ( this . currentSong . buildup ) {
if ( this . currentSong . buildup ) {
switch ( localStorage [ "playBuildups" ] ) {
switch ( this . settings . playBuildups ) {
case "off" :
case "off" :
this . currentSong . buildupPlayed = true ;
this . currentSong . buildupPlayed = true ;
this . doBuildup = false ;
this . doBuildup = false ;
@ -606,16 +602,16 @@ class HuesCore {
onLoop ( ) {
onLoop ( ) {
this . loopCount ++ ;
this . loopCount ++ ;
switch ( localStorage [ "autoSong" ] ) {
switch ( this . settings . autoSong ) {
case "loop" :
case "loop" :
console . log ( "Checking loops" ) ;
console . log ( "Checking loops" ) ;
if ( this . loopCount >= localStorage [ "autoSongDelay" ] ) {
if ( this . loopCount >= this . settings . autoSongDelay ) {
this . doAutoSong ( ) ;
this . doAutoSong ( ) ;
}
}
break ;
break ;
case "time" :
case "time" :
console . log ( "Checking times" ) ;
console . log ( "Checking times" ) ;
if ( this . soundManager . loopLength * this . loopCount >= localStorage [ "autoSongDelay" ] * 60 ) {
if ( this . soundManager . loopLength * this . loopCount >= this . settings . autoSongDelay * 60 ) {
this . doAutoSong ( ) ;
this . doAutoSong ( ) ;
}
}
break ;
break ;
@ -627,12 +623,12 @@ class HuesCore {
if ( this . resourceManager . enabledSongs . length < 2 ) {
if ( this . resourceManager . enabledSongs . length < 2 ) {
return ; // don't move if there's nothing to move to
return ; // don't move if there's nothing to move to
}
}
if ( localStorage [ "autoSongShuffle" ] == "on" ) {
if ( this . settings . autoSongShuffle == "on" ) {
func = this . randomSong ;
func = this . randomSong ;
} else {
} else {
func = this . nextSong ;
func = this . nextSong ;
}
}
if ( localStorage [ "autoSongFadeout" ] == "on" ) {
if ( this . settings . autoSongFadeout == "on" ) {
this . soundManager . fadeOut ( ( ) => {
this . soundManager . fadeOut ( ( ) => {
func . call ( this ) ;
func . call ( this ) ;
} ) ;
} ) ;
@ -651,13 +647,13 @@ class HuesCore {
resetAudio ( ) {
resetAudio ( ) {
this . beatIndex = 0 ;
this . beatIndex = 0 ;
this . songDataUpdated ( ) ;
this . songDataUpdated ( ) ;
if ( localStorage [ "visualiser" ] == "on" ) {
if ( this . settings . visualiser == "on" ) {
this . soundManager . initVisualiser ( this . visualiser . width / 2 ) ;
this . soundManager . initVisualiser ( this . visualiser . width / 2 ) ;
}
}
}
}
randomImage ( ) {
randomImage ( ) {
if ( localStorage [ "shuffleImages" ] == "on" ) {
if ( this . settings . shuffleImages == "on" ) {
let len = this . resourceManager . enabledImages . length ;
let len = this . resourceManager . enabledImages . length ;
let index = Math . floor ( Math . random ( ) * len ) ;
let index = Math . floor ( Math . random ( ) * len ) ;
if ( ( index == this . imageIndex || this . lastImageArray . indexOf ( index ) != - 1 ) && len > 1 ) {
if ( ( index == this . imageIndex || this . lastImageArray . indexOf ( index ) != - 1 ) && len > 1 ) {
@ -780,12 +776,12 @@ class HuesCore {
this . randomColour ( ) ;
this . randomColour ( ) ;
break ;
break ;
case '*' :
case '*' :
if ( this . isF ullAuto) {
if ( this . settings . f ullAuto) {
this . randomImage ( ) ;
this . randomImage ( ) ;
}
}
break ;
break ;
case '=' :
case '=' :
if ( this . isF ullAuto) {
if ( this . settings . f ullAuto) {
this . randomImage ( ) ;
this . randomImage ( ) ;
}
}
/* falls through */
/* falls through */
@ -806,7 +802,7 @@ class HuesCore {
this . renderer . doSlice ( this . getBeatLength ( ) , this . charsToNextBeat ( ) , true , true ) ;
this . renderer . doSlice ( this . getBeatLength ( ) , this . charsToNextBeat ( ) , true , true ) ;
break ;
break ;
case 'I' :
case 'I' :
if ( this . isF ullAuto) {
if ( this . settings . f ullAuto) {
this . randomImage ( ) ;
this . randomImage ( ) ;
}
}
/* falls through */
/* falls through */
@ -819,7 +815,7 @@ class HuesCore {
}
}
if ( [ "." , "+" , "¤" , ":" , "*" , "X" , "O" , "~" , "=" , "i" , "I" , "s" , "v" , "#" ] . indexOf ( beat ) == - 1 ) {
if ( [ "." , "+" , "¤" , ":" , "*" , "X" , "O" , "~" , "=" , "i" , "I" , "s" , "v" , "#" ] . indexOf ( beat ) == - 1 ) {
this . randomColour ( ) ;
this . randomColour ( ) ;
if ( this . isF ullAuto) {
if ( this . settings . f ullAuto) {
this . randomImage ( ) ;
this . randomImage ( ) ;
}
}
}
}
@ -866,14 +862,14 @@ class HuesCore {
}
}
setIsFullAuto ( auto ) {
setIsFullAuto ( auto ) {
this . isF ullAuto = auto ;
this . settings . f ullAuto = auto ;
if ( this . userInterface ) {
if ( this . userInterface ) {
this . callEventListeners ( "newmode" , this . isF ullAuto) ;
this . callEventListeners ( "newmode" , this . settings . f ullAuto) ;
}
}
}
}
toggleFullAuto ( ) {
toggleFullAuto ( ) {
this . setIsFullAuto ( ! this . isF ullAuto) ;
this . setIsFullAuto ( ! this . settings . f ullAuto) ;
}
}
setInvert ( invert ) {
setInvert ( invert ) {
@ -897,7 +893,7 @@ class HuesCore {
}
}
this . userInterface = this . uiArray [ index ] ;
this . userInterface = this . uiArray [ index ] ;
this . userInterface . connectCore ( this ) ;
this . userInterface . connectCore ( this ) ;
this . callEventListeners ( "newmode" , this . isF ullAuto) ;
this . callEventListeners ( "newmode" , this . settings . f ullAuto) ;
this . callEventListeners ( "newsong" , this . currentSong ) ;
this . callEventListeners ( "newsong" , this . currentSong ) ;
this . callEventListeners ( "newimage" , this . currentImage ) ;
this . callEventListeners ( "newimage" , this . currentImage ) ;
this . callEventListeners ( "newcolour" , this . colours [ this . colourIndex ] , false ) ;
this . callEventListeners ( "newcolour" , this . colours [ this . colourIndex ] , false ) ;
@ -908,7 +904,7 @@ class HuesCore {
settingsUpdated ( ) {
settingsUpdated ( ) {
this . callEventListeners ( "settingsupdated" ) ;
this . callEventListeners ( "settingsupdated" ) ;
switch ( localStorage [ "currentUI" ] ) {
switch ( this . settings . currentUI ) {
case "retro" :
case "retro" :
this . changeUI ( 0 ) ;
this . changeUI ( 0 ) ;
break ;
break ;
@ -928,7 +924,7 @@ class HuesCore {
this . changeUI ( 5 ) ;
this . changeUI ( 5 ) ;
break ;
break ;
}
}
switch ( localStorage [ "colourSet" ] ) {
switch ( this . settings . colourSet ) {
case "normal" :
case "normal" :
this . colours = HuesCore . oldColours ;
this . colours = HuesCore . oldColours ;
break ;
break ;
@ -939,7 +935,7 @@ class HuesCore {
this . colours = HuesCore . weedColours ;
this . colours = HuesCore . weedColours ;
break ;
break ;
}
}
switch ( localStorage [ "blackoutUI" ] ) {
switch ( this . settings . blackoutUI ) {
case "off" :
case "off" :
this . userInterface . show ( ) ;
this . userInterface . show ( ) ;
break ;
break ;
@ -949,7 +945,7 @@ class HuesCore {
}
}
break ;
break ;
}
}
switch ( localStorage [ "visualiser" ] ) {
switch ( this . settings . visualiser ) {
case "off" :
case "off" :
this . visualiser . classList . add ( "hidden" ) ;
this . visualiser . classList . add ( "hidden" ) ;
break ;
break ;
@ -960,11 +956,11 @@ class HuesCore {
}
}
break ;
break ;
}
}
if ( this . autoSong == "off" && localStorage [ "autoSong" ] != "off" ) {
if ( this . autoSong == "off" && this . settings . autoSong != "off" ) {
console . log ( "Resetting loopCount since AutoSong was enabled" ) ;
console . log ( "Resetting loopCount since AutoSong was enabled" ) ;
this . loopCount = 0 ;
this . loopCount = 0 ;
}
}
this . autoSong = localStorage [ "autoSong" ] ;
this . autoSong = this . settings . autoSong ;
}
}
enabledChanged ( ) {
enabledChanged ( ) {
@ -1012,7 +1008,7 @@ class HuesCore {
this . previousSong ( ) ;
this . previousSong ( ) ;
break ;
break ;
case 70 : // F
case 70 : // F
this . setIsFullAuto ( ! this . isFullAuto ) ;
this . toggleFullAuto ( ) ;
break ;
break ;
case 109 : // NUMPAD_SUBTRACT
case 109 : // NUMPAD_SUBTRACT
case 189 : // MINUS
case 189 : // MINUS