diff --git a/.hintrc b/.hintrc new file mode 100644 index 0000000..fab60f3 --- /dev/null +++ b/.hintrc @@ -0,0 +1,7 @@ +{ + "extends": [ + "development" + ], + "hints": { + } +} \ No newline at end of file diff --git a/content/trans/en.trans b/content/trans/en.trans index ea87b8f..0a9fcb0 100644 --- a/content/trans/en.trans +++ b/content/trans/en.trans @@ -6,6 +6,7 @@ about=about language=language color_theme=color theme sounds=sounds +music=music pink=pink blue=blue orange=orange diff --git a/content/trans/tr.trans b/content/trans/tr.trans index 152d766..18bbe19 100644 --- a/content/trans/tr.trans +++ b/content/trans/tr.trans @@ -6,6 +6,7 @@ about=hakkında language=dil color_theme=renk teması sounds=sesler +music=müzik pink=pembe blue=mavi orange=turuncu diff --git a/public/music/SoundBox-music.wav b/public/music/SoundBox-music.wav new file mode 100644 index 0000000..d95fffa Binary files /dev/null and b/public/music/SoundBox-music.wav differ diff --git a/src/game.ts b/src/game.ts index c49a4b6..b992fe9 100644 --- a/src/game.ts +++ b/src/game.ts @@ -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 diff --git a/src/solitaire_game.ts b/src/solitaire_game.ts index 97ed60b..f30df92 100644 --- a/src/solitaire_game.ts +++ b/src/solitaire_game.ts @@ -475,6 +475,11 @@ export class SolitaireGame extends Play { this.back_res = back_res this._collect_pov() }) + + + + Sound.music('main') + } _release_cancel_drag() { diff --git a/src/sound.ts b/src/sound.ts index 47813df..ac36bb7 100644 --- a/src/sound.ts +++ b/src/sound.ts @@ -1,3 +1,4 @@ +import { GeneralStore } from "./store" function load_audio(path: string): HTMLMediaElement { @@ -15,6 +16,8 @@ class Sound { audios!: Record> + musics!: Record + load = async () => { @@ -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()! @@ -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() + } + } diff --git a/src/store.ts b/src/store.ts index 51efde5..711021f 100644 --- a/src/store.ts +++ b/src/store.ts @@ -1,9 +1,12 @@ import { Language } from './trans' import { TurningLimit, TurningCards } from 'lsolitaire' +import { StoredJsonProp, storedJsonProp } from './storage' + export let limit_settings: Array = ['nolimit', 'threepass', 'onepass'] export let cards_settings: Array = ['threecards', 'onecard'] + class SolitaireStore { get cards() { @@ -24,13 +27,52 @@ class SolitaireStore { class GeneralStore { + + get music() { + return this._music() + } + + set music(_: boolean) { + this._music(_) + } + + _music: StoredJsonProp + + + + + get sound() { + return this._sound() + } + + set sound(_: boolean) { + this._sound(_) + } + + _sound: StoredJsonProp + + + + get language() { - return 'en' + return this._language() } set language(_: Language) { + this._language(_) } + _language: StoredJsonProp + + 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()