@@ -1970,12 +1970,9 @@ function keyCodeToHuman(keyCode) {
19701970
19711971
19721972function definePauseUI ( ) {
1973-
1974- // Create a container div for the settings
19751973 settingsContainer = createDiv ( ) ;
19761974 settingsContainer . class ( "container" ) ;
19771975 settingsContainer . style ( "position" , "absolute" ) ;
1978- // Style the container (similar to your CSS)
19791976 settingsContainer . style ( "font-family" , "Arial, sans-serif" ) ;
19801977 settingsContainer . style ( "margin" , "0 auto" ) ;
19811978 settingsContainer . style ( "width" , "300px" ) ;
@@ -1986,55 +1983,67 @@ function definePauseUI() {
19861983 settingsContainer . style ( "display" , "none" ) ;
19871984 settingsContainer . style ( "flex-direction" , "column" ) ;
19881985 settingsContainer . style ( "align-items" , "center" ) ;
1989- settingsContainer . style ( "z-index" , "998" )
1986+ settingsContainer . style ( "z-index" , "998" ) ;
19901987
1991- // Title
19921988 let title = createElement ( "h2" , "Settings" ) ;
19931989 title . parent ( settingsContainer ) ;
19941990
1995- // Create slider container
1996- let sliderContainer = createDiv ( ) ;
1997- sliderContainer . parent ( settingsContainer ) ;
1998- sliderContainer . style ( "margin" , "20px 0" ) ;
1999-
2000- // Label
2001- // Effects volume label with speaker emoji
2002- let volumeLabel = createElement ( "label" , "🔊 Volume:" ) ;
2003- volumeLabel . parent ( sliderContainer ) ;
2004- volumeLabel . style ( "font-size" , "16px" ) ;
2005- volumeLabel . style ( "margin-right" , "10px" ) ;
2006-
2007- // Music volume label with musical note emoji
2008- let musicVolLabel = createElement ( "label" , "🎵 Music:" ) ;
2009- musicVolLabel . parent ( sliderContainer ) ;
2010- musicVolLabel . style ( "font-size" , "16px" ) ;
2011- musicVolLabel . style ( "margin-right" , "10px" ) ;
2012-
2013- // Your sliders
2014- volumeSlider = createSlider ( 0 , 100 , 50 ) ;
2015- volumeSlider . style ( "width" , "150px" ) ;
2016- volumeSlider . parent ( sliderContainer ) ;
2017-
2018- musicVolumeSlider = createSlider ( 0 , 100 , 50 ) ;
2019- musicVolumeSlider . style ( "width" , "150px" ) ;
2020- musicVolumeSlider . parent ( sliderContainer ) ;
1991+ let sliderContainer = createDiv ( )
1992+ . parent ( settingsContainer )
1993+ . style ( "display" , "flex" )
1994+ . style ( "flex-direction" , "column" )
1995+ . style ( "gap" , "15px" )
1996+ . style ( "margin" , "20px 0" ) ;
1997+
1998+ let effectsRow = createDiv ( )
1999+ . parent ( sliderContainer )
2000+ . style ( "display" , "flex" )
2001+ . style ( "align-items" , "center" ) ;
2002+
2003+ let savedVolume = parseInt ( localStorage . getItem ( "volume" ) ) || 50 ;
2004+ let volumeLabel = createElement ( "label" , "🔊 Volume:" )
2005+ . parent ( effectsRow )
2006+ . style ( "font-size" , "16px" )
2007+ . style ( "margin-right" , "10px" ) ;
2008+
2009+ volumeSlider = createSlider ( 0 , 100 , savedVolume )
2010+ . parent ( effectsRow )
2011+ . style ( "width" , "150px" ) ;
2012+
2013+ volumeSlider . input ( ( ) => {
2014+ let v = volumeSlider . value ( ) ;
2015+ localStorage . setItem ( "volume" , v ) ;
2016+ Object . values ( soundDic ) . forEach ( entry => {
2017+ entry . sounds . slice ( 1 ) . forEach ( ( s , idx ) => {
2018+ s . setVolume ( ( ( idx + 1 ) / 20 ) * entry . volume * ( v / 100 ) ) ;
2019+ } ) ;
2020+ } ) ;
2021+ } ) ;
20212022
2023+ let musicRow = createDiv ( )
2024+ . parent ( sliderContainer )
2025+ . style ( "display" , "flex" )
2026+ . style ( "align-items" , "center" ) ;
20222027
2028+ let savedMusic = parseInt ( localStorage . getItem ( "musicVolume" ) ) || 50 ;
2029+ let musicVolLabel = createElement ( "label" , "🎵 Music:" )
2030+ . parent ( musicRow )
2031+ . style ( "font-size" , "16px" )
2032+ . style ( "margin-right" , "10px" ) ;
20232033
2024- // Retrieve saved volume from localStorage
2025- const savedVolume = localStorage . getItem ( "volume" ) ;
2026- if ( savedVolume ) {
2027- volumeSlider . value ( savedVolume ) ;
2028- }
2034+ musicVolumeSlider = createSlider ( 0 , 100 , savedMusic )
2035+ . parent ( musicRow )
2036+ . style ( "width" , "150px" ) ;
20292037
2030- const savedMusicVolume = localStorage . getItem ( "musicVolume" ) ;
2031- if ( savedVolume ) {
2032- musicVolumeSlider . value ( savedMusicVolume ) ;
2033- }
2038+ musicVolumeSlider . input ( ( ) => {
2039+ let mv = musicVolumeSlider . value ( ) ;
2040+ localStorage . setItem ( "musicVolume" , mv ) ;
2041+ if ( MusicPlayer ) MusicPlayer . setVolume ( ) ;
2042+ } ) ;
20342043
20352044 keyBind_Button = createButton ( "Key Bindings" ) ;
20362045 keyBind_Button . parent ( sliderContainer ) ;
2037- keyBind_Button . class ( "button" ) ; // For your reference, you can define .button in CSS if desired
2046+ keyBind_Button . class ( "button" ) ;
20382047 keyBind_Button . style ( "padding" , "10px" ) ;
20392048 keyBind_Button . style ( "margin-top" , "20px" ) ;
20402049 keyBind_Button . style ( "background-color" , "#444" ) ;
@@ -2050,87 +2059,69 @@ function definePauseUI() {
20502059
20512060 removeData_button = createButton ( "Remove Data" ) ;
20522061 removeData_button . parent ( sliderContainer ) ;
2053- removeData_button . class ( "button" ) ; // For your reference, you can define .button in CSS if desired
2062+ removeData_button . class ( "button" ) ;
20542063 removeData_button . style ( "padding" , "10px" ) ;
20552064 removeData_button . style ( "margin-top" , "20px" ) ;
20562065 removeData_button . style ( "background-color" , "#444" ) ;
20572066 removeData_button . style ( "border" , "none" ) ;
20582067 removeData_button . style ( "color" , "white" ) ;
20592068 removeData_button . style ( "border-radius" , "5px" ) ;
20602069 removeData_button . style ( "cursor" , "pointer" ) ;
2061-
20622070 removeData_button . mousePressed ( ( ) => {
2063- // Save volume setting to localStorage
2064- localStorage . clear ( )
2071+ localStorage . clear ( ) ;
20652072 } ) ;
20662073
2067- removeData_button . parent ( sliderContainer )
2068-
2069- // Save button
20702074 saveButton = createButton ( "Save" ) ;
2071- saveButton . class ( "button" ) ; // For your reference, you can define .button in CSS if desired
2075+ saveButton . class ( "button" ) ;
20722076 saveButton . style ( "padding" , "10px" ) ;
20732077 saveButton . style ( "margin-top" , "20px" ) ;
20742078 saveButton . style ( "background-color" , "#444" ) ;
20752079 saveButton . style ( "border" , "none" ) ;
20762080 saveButton . style ( "color" , "white" ) ;
20772081 saveButton . style ( "border-radius" , "5px" ) ;
20782082 saveButton . style ( "cursor" , "pointer" ) ;
2079-
20802083 saveButton . parent ( settingsContainer ) ;
2081- // Save button logic
20822084 saveButton . mousePressed ( ( ) => {
2083- // Save volume setting to localStorage
2084- console . log ( volumeSlider . value ( ) )
20852085 localStorage . setItem ( "volume" , volumeSlider . value ( ) ) ;
2086-
20872086 localStorage . setItem ( "musicVolume" , musicVolumeSlider . value ( ) ) ;
2088-
2089- // Update the volume of all sounds
2090- let keys = Object . keys ( soundDic ) ;
2091- for ( let i = 0 ; i < keys . length ; i ++ ) {
2092- for ( let j = 1 ; j < soundDic [ keys [ i ] ] . sounds . length ; j ++ ) {
2093- soundDic [ keys [ i ] ] . sounds [ j ] . setVolume ( ( j / 20 ) * soundDic [ keys [ i ] ] . volume * ( volumeSlider . value ( ) / 100 ) ) ;
2094- }
2095- }
2096-
2097- if ( MusicPlayer ) {
2098- MusicPlayer . setVolume ( )
2099- }
2100-
2101- // Save the key bindings to localStorage
2102- let keyBindings = { } ;
2103- keyBindings . upCode = Controls_move_Up_code ;
2104- keyBindings . upKey = Controls_Up_key ;
2105- keyBindings . leftCode = Controls_move_Left_code ;
2106- keyBindings . leftKey = Controls_Left_key ;
2107- keyBindings . downCode = Controls_move_Down_code ;
2108- keyBindings . downKey = Controls_Down_key ;
2109- keyBindings . rightCode = Controls_move_Right_code ;
2110- keyBindings . rightKey = Controls_Right_key ;
2111- keyBindings . interactCode = Controls_Interact_code ;
2112- keyBindings . interactKey = Controls_Interact_key ;
2113- keyBindings . invCode = Controls_Inventory_code ;
2114- keyBindings . invKey = Controls_Inventory_key ;
2115- keyBindings . craftCode = Controls_Crafting_code ;
2116- keyBindings . craftKey = Controls_Crafting_key ;
2117- keyBindings . pauseCode = Controls_Pause_code ;
2118- keyBindings . pauseKey = Controls_Pause_key ;
2119- keyBindings . moveHotBarRightCode = Controls_MoveHotBarRight_code ;
2120- keyBindings . moveHotBarRightKey = Controls_MoveHotBarRight_key ;
2121- keyBindings . moveHotBarLeftCode = Controls_MoveHotBarLeft_code ;
2122- keyBindings . moveHotBarLeftKey = Controls_MoveHotBarLeft_key ;
2123- keyBindings . buildCode = Controls_Build_code ;
2124- keyBindings . buildKey = Controls_Build_key ;
2125- keyBindings . spaceCode = Controls_Space_code ;
2126- keyBindings . spaceKey = Controls_Space_key ;
2087+ Object . keys ( soundDic ) . forEach ( key => {
2088+ soundDic [ key ] . sounds . slice ( 1 ) . forEach ( ( s , idx ) => {
2089+ s . setVolume ( ( ( idx + 1 ) / 20 ) * soundDic [ key ] . volume * ( volumeSlider . value ( ) / 100 ) ) ;
2090+ } ) ;
2091+ } ) ;
2092+ if ( MusicPlayer ) MusicPlayer . setVolume ( ) ;
2093+ let keyBindings = {
2094+ upCode : Controls_move_Up_code ,
2095+ upKey : Controls_Up_key ,
2096+ leftCode : Controls_move_Left_code ,
2097+ leftKey : Controls_Left_key ,
2098+ downCode : Controls_move_Down_code ,
2099+ downKey : Controls_Down_key ,
2100+ rightCode : Controls_move_Right_code ,
2101+ rightKey : Controls_Right_key ,
2102+ interactCode : Controls_Interact_code ,
2103+ interactKey : Controls_Interact_key ,
2104+ invCode : Controls_Inventory_code ,
2105+ invKey : Controls_Inventory_key ,
2106+ craftCode : Controls_Crafting_code ,
2107+ craftKey : Controls_Crafting_key ,
2108+ pauseCode : Controls_Pause_code ,
2109+ pauseKey : Controls_Pause_key ,
2110+ moveHotBarRightCode : Controls_MoveHotBarRight_code ,
2111+ moveHotBarRightKey : Controls_MoveHotBarRight_key ,
2112+ moveHotBarLeftCode : Controls_MoveHotBarLeft_code ,
2113+ moveHotBarLeftKey : Controls_MoveHotBarLeft_key ,
2114+ buildCode : Controls_Build_code ,
2115+ buildKey : Controls_Build_key ,
2116+ spaceCode : Controls_Space_code ,
2117+ spaceKey : Controls_Space_key
2118+ } ;
21272119 localStorage . setItem ( "keyBindings" , JSON . stringify ( keyBindings ) ) ;
2128-
2129- toggleSettings ( )
2120+ toggleSettings ( ) ;
21302121 } ) ;
21312122
21322123 pauseDiv = createDiv ( ) ;
2133- pauseDiv . class ( "container" )
2124+ pauseDiv . class ( "container" ) ;
21342125 pauseDiv . style ( "position" , "absolute" ) ;
21352126 pauseDiv . style ( "top" , "50%" ) ;
21362127 pauseDiv . style ( "left" , "50%" ) ;
@@ -2146,7 +2137,6 @@ function definePauseUI() {
21462137 pauseDiv . style ( "text-align" , "center" ) ;
21472138 pauseDiv . style ( "padding" , "20px" ) ;
21482139
2149-
21502140 let pauseTitle = createP ( "Paused" ) ;
21512141 pauseTitle . style ( "font-size" , "28px" ) ;
21522142 pauseTitle . style ( "font-weight" , "bold" ) ;
@@ -2178,6 +2168,7 @@ function definePauseUI() {
21782168
21792169
21802170
2171+
21812172var oldState = "" ;
21822173
21832174
0 commit comments