import { SoundSettings } from './sound.service' ; import { Injectable } from '@angular/core' ; @ Injectable ( { providedIn : 'root' } ) export class LocalStorageService { saveCode ( levelTitle , code ) { localStorage . setItem ( levelTitle , code ) ; } loadCode ( levelTitle ) { if ( levelTitle in localStorage ) { return localStorage . getItem ( levelTitle ) ; } return '' ; } saveLevelSolved ( title ) { if ( 'levels' in localStorage ) { const levels = JSON . parse ( localStorage . getItem ( 'levels' ) ) ; levels . push ( title ) ; localStorage . setItem ( 'levels' , JSON . stringify ( levels ) ) ; } else { localStorage . setItem ( 'levels' , JSON . stringify ( [ title ] ) ) ; } } loadSolvedLevels ( ) { if ( 'levels' in localStorage ) { return JSON . parse ( localStorage . getItem ( 'levels' ) ) ; } return [ ] ; } saveLanguage ( language ) { localStorage . setItem ( 'language' , language ) ; } loadSelectedLanguage ( ) { if ( 'language' in localStorage ) { return localStorage . getItem ( 'language' ) ; } return '' ; } saveSoundSettings ( soundSettings ) { localStorage . setItem ( 'sound' , JSON . stringify ( soundSettings ) ) ; } loadSoundSettings ( ) { if ( 'sound' in localStorage ) { return JSON . parse ( localStorage . getItem ( 'sound' ) ) ; } return { imagePath : '/assets/images/sound-low.png' , volume : 0.1 , isMute : false } ; } clearAll ( ) { localStorage . clear ( ) ; } }