forked from shadorki/vrc-owo-suit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
76 lines (68 loc) · 2.57 KB
/
config.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
import params
import os
import json
def merge_dicts(dict1, dict2):
""" Recursively merges dict2 into dict1 """
if not isinstance(dict1, dict) or not isinstance(dict2, dict):
return dict2
for k in dict2:
if k in dict1:
dict1[k] = merge_dicts(dict1[k], dict2[k])
else:
dict1[k] = dict2[k]
return dict1
class Config:
def __init__(self):
self.APP_NAME = 'VRChatOWOSuit'
self.default_config = {
"use_oscquery": True,
"server_port": 9001,
"owo_ip": "",
"should_detect_ip": True,
"should_connect_on_startup": False,
"frequency": 100,
"intensities": {
params.owo_suit_Pectoral_L: 60,
params.owo_suit_Pectoral_R: 60,
params.owo_suit_Abdominal_L: 60,
params.owo_suit_Abdominal_R: 60,
params.owo_suit_Arm_L: 60,
params.owo_suit_Arm_R: 60,
params.owo_suit_Dorsal_L: 60,
params.owo_suit_Dorsal_R: 60,
params.owo_suit_Lumbar_L: 60,
params.owo_suit_Lumbar_R: 60,
}
}
self.current_config = None
def get_by_key(self, key: str):
return self.current_config.get(key)
def update(self, key: str, nextValue):
if (key in self.current_config):
self.current_config[key] = nextValue
def read_config_from_disk(self):
appdata_path = os.environ.get('LOCALAPPDATA')
app_directory = os.path.join(appdata_path, self.APP_NAME)
os.makedirs(app_directory, exist_ok=True)
config_path = os.path.join(app_directory, 'config.json')
if os.path.exists(config_path):
with open(config_path, 'r') as file:
data = json.load(file)
data = merge_dicts(self.default_config, data)
return data
else:
with open(config_path, 'w') as file:
json.dump(self.default_config, file, indent=4)
return self.default_config
def write_config_to_disk(self):
if self.current_config == None:
return
appdata_path = os.environ.get('LOCALAPPDATA')
app_directory = os.path.join(appdata_path, self.APP_NAME)
os.makedirs(app_directory, exist_ok=True)
config_path = os.path.join(app_directory, 'config.json')
with open(config_path, 'w') as file:
json.dump(self.current_config, file, indent=4)
def init(self):
self.current_config = self.read_config_from_disk()