summaryrefslogtreecommitdiff
path: root/src/client/cold-storage.ts
blob: 1bee2313fa288541fcffb616b83240f35e738e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 常にメモリにロードしておく必要がないような設定情報を保管するストレージ

const PREFIX = 'miux:';

export const defaultDeviceSettings = {
	sound_masterVolume: 0.3,
	sound_note: { type: 'syuilo/down', volume: 1 },
	sound_noteMy: { type: 'syuilo/up', volume: 1 },
	sound_notification: { type: 'syuilo/pope2', volume: 1 },
	sound_chat: { type: 'syuilo/pope1', volume: 1 },
	sound_chatBg: { type: 'syuilo/waon', volume: 1 },
	sound_antenna: { type: 'syuilo/triple', volume: 1 },
	sound_channel: { type: 'syuilo/square-pico', volume: 1 },
	sound_reversiPutBlack: { type: 'syuilo/kick', volume: 0.3 },
	sound_reversiPutWhite: { type: 'syuilo/snare', volume: 0.3 },
};

export const device = {
	get<T extends keyof typeof defaultDeviceSettings>(key: T): typeof defaultDeviceSettings[T] {
		// TODO: indexedDBにする
		//       ただしその際はnullチェックではなくキー存在チェックにしないとダメ
		//       (indexedDBはnullを保存できるため、ユーザーが意図してnullを格納した可能性がある)
		const value = localStorage.getItem(PREFIX + key);
		if (value == null) {
			return defaultDeviceSettings[key];
		} else {
			return JSON.parse(value);
		}
	},

	set(key: keyof typeof defaultDeviceSettings, value: any): any {
		localStorage.setItem(PREFIX + key, JSON.stringify(value));
	},
};