-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 게임 설정을 단일 JSON으로 관리하는 newUserSetting 생성
- Loading branch information
Showing
4 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { KEY_GAME_SETTINGS } from '@constants/localStorage.constant'; | ||
|
||
import { bgm, setMasterVolume, sfx } from './audio'; | ||
import { storage } from './storage'; | ||
|
||
class NewUserSettings { | ||
private settings: { | ||
hapticEnabled: boolean; | ||
volumeMaster: number; | ||
volumeBGM: number; | ||
volumeSFX: number; | ||
}; | ||
|
||
constructor() { | ||
this.settings = this.loadSettings(); | ||
setMasterVolume(this.getMasterVolume()); | ||
bgm.setVolume(this.getBgmVolume()); | ||
sfx.setVolume(this.getSfxVolume()); | ||
} | ||
|
||
private loadSettings() { | ||
return storage.getObject(KEY_GAME_SETTINGS) ?? this.getDefaultSettings(); | ||
} | ||
|
||
private getDefaultSettings() { | ||
return { | ||
hapticEnabled: true, | ||
volumeMaster: 0.38, | ||
volumeBGM: 0.83, | ||
volumeSFX: 0.83, | ||
}; | ||
} | ||
|
||
private saveSettings() { | ||
storage.setObject(KEY_GAME_SETTINGS, this.settings); | ||
} | ||
|
||
/** 전체 사운드 볼륨을 가져옵니다. */ | ||
public getMasterVolume() { | ||
return this.settings.volumeMaster; | ||
} | ||
|
||
/** 전체 사운드 볼륨을 설정합니다. */ | ||
public setMasterVolume(value: number) { | ||
setMasterVolume(value); | ||
this.settings.volumeMaster = value; | ||
this.saveSettings(); | ||
} | ||
|
||
/** 배경 음악 볼륨을 가져옵니다. */ | ||
public getBgmVolume() { | ||
return this.settings.volumeBGM; | ||
} | ||
|
||
/** 배경 음악 볼륨을 설정합니다. */ | ||
public setBgmVolume(value: number) { | ||
bgm.setVolume(value); | ||
this.settings.volumeBGM = value; | ||
this.saveSettings(); | ||
} | ||
|
||
/** 효과음 볼륨을 가져옵니다. */ | ||
public getSfxVolume() { | ||
return this.settings.volumeSFX; | ||
} | ||
|
||
/** 효과음 볼륨을 설정합니다. */ | ||
public setSfxVolume(value: number) { | ||
sfx.setVolume(value); | ||
this.settings.volumeSFX = value; | ||
this.saveSettings(); | ||
} | ||
|
||
/** 햅틱 활성화 여부를 설정합니다. */ | ||
public setHapticEnabled(value: boolean) { | ||
this.settings.hapticEnabled = value; | ||
this.saveSettings(); | ||
} | ||
|
||
/** 햅틱 활성화 여부를 가져옵니다. */ | ||
public getHapticEnabled() { | ||
return this.settings.hapticEnabled; | ||
} | ||
} | ||
|
||
/** 공유된 사용자 설정 인스턴스 */ | ||
export const newUserSettings = new NewUserSettings(); |