Skip to content

Commit

Permalink
sound settings music language store local
Browse files Browse the repository at this point in the history
  • Loading branch information
eguneys committed Dec 24, 2023
1 parent 93c835b commit b24d0c7
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .hintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": [
"development"
],
"hints": {
}
}
1 change: 1 addition & 0 deletions content/trans/en.trans
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ about=about
language=language
color_theme=color theme
sounds=sounds
music=music
pink=pink
blue=blue
orange=orange
Expand Down
1 change: 1 addition & 0 deletions content/trans/tr.trans
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ about=hakkında
language=dil
color_theme=renk teması
sounds=sesler
music=müzik
pink=pembe
blue=mavi
orange=turuncu
Expand Down
Binary file added public/music/SoundBox-music.wav
Binary file not shown.
22 changes: 20 additions & 2 deletions src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1928,20 +1928,38 @@ class GeneralSettings extends Play {
*/


let sound_settings = ['on', 'off']
let sound_setting = this.make(DropdownSetting, Vec2.make(40, h * 1), {
name: 'sounds',
items: ['on', 'off'],
selected_index: 0,
selected_index: GeneralStore.sound ? 0: 1,
on_selected(i: number) {
console.log(i)
GeneralStore.sound = sound_settings[i] === 'on'
}
})


let music_settings = ['on', 'off']
let music_setting = this.make(DropdownSetting, Vec2.make(40, h * 2), {
name: 'music',
items: ['on', 'off'],
selected_index: GeneralStore.music ? 0: 1,
on_selected(i: number) {
GeneralStore.music = music_settings[i] === 'on'
if (!GeneralStore.music) {
Sound.stop_music()
}
}
})





this.make_box(language_setting, true)
//this.make_box(theme_setting)
this.make_box(sound_setting)
this.make_box(music_setting)

this.height = h * 3 + 500

Expand Down
5 changes: 5 additions & 0 deletions src/solitaire_game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ export class SolitaireGame extends Play {
this.back_res = back_res
this._collect_pov()
})



Sound.music('main')

}

_release_cancel_drag() {
Expand Down
28 changes: 28 additions & 0 deletions src/sound.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GeneralStore } from "./store"


function load_audio(path: string): HTMLMediaElement {
Expand All @@ -15,6 +16,8 @@ class Sound {

audios!: Record<string, Array<HTMLMediaElement>>

musics!: Record<string, HTMLMediaElement>

load = async () => {


Expand All @@ -23,9 +26,18 @@ class Sound {
load_audio(`./audio/${name}.wav`))
)

this.musics = {}

this.musics['main'] = load_audio('./music/SoundBox-music.wav')

}

play(name: string) {

if (!GeneralStore.sound) {
return;
}

let audios = this.audios[name]

let audio = audios.pop()!
Expand All @@ -34,6 +46,22 @@ class Sound {
audio.play()
}

stop_music() {

this.musics['main'].pause()
}

music(name: string) {

if (!GeneralStore.music) {
return
}

let audio = this.musics[name]
audio.loop = true
audio.play()
}

}


Expand Down
44 changes: 43 additions & 1 deletion src/store.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Language } from './trans'
import { TurningLimit, TurningCards } from 'lsolitaire'

import { StoredJsonProp, storedJsonProp } from './storage'

export let limit_settings: Array<TurningLimit> = ['nolimit', 'threepass', 'onepass']
export let cards_settings: Array<TurningCards> = ['threecards', 'onecard']


class SolitaireStore {

get cards() {
Expand All @@ -24,13 +27,52 @@ class SolitaireStore {

class GeneralStore {


get music() {
return this._music()
}

set music(_: boolean) {
this._music(_)
}

_music: StoredJsonProp<boolean>




get sound() {
return this._sound()
}

set sound(_: boolean) {
this._sound(_)
}

_sound: StoredJsonProp<boolean>




get language() {
return 'en'
return this._language()
}

set language(_: Language) {
this._language(_)
}

_language: StoredJsonProp<Language>

constructor() {

let def_language: Language = 'en'

this._language = storedJsonProp('language', () => def_language)

this._sound = storedJsonProp('sound', () => true)
this._music = storedJsonProp('music', () => true)
}
}

let solitaire = new SolitaireStore()
Expand Down

0 comments on commit b24d0c7

Please sign in to comment.