forked from mathewbyrne/ev-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
64 lines (51 loc) · 1.68 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
import json
import os
DEFAULT_TRACKER_FILENAME = '.ev-tracker'
DEFAULT_TRACKER_PATH = os.path.expanduser(os.path.join('~', DEFAULT_TRACKER_FILENAME))
CONFIG_FILENAME = 'config.json'
class Config(object):
def __init__(self):
self.filename = None
self.generation = 9
self.is_bdsp = False
def double_power_items_effort(self):
return self.generation > 6 and not self.is_bdsp
def smart_iv_cap(self):
return self.generation > 6
def berry_reduction_cuts_to_100(self):
return self.generation == 4
def ignore_pokerus(self):
return self.generation == 9
@classmethod
def from_json(cls, filename):
config = cls()
try:
fp = open(CONFIG_FILENAME, 'r')
data = json.load(fp)
if filename is None and 'filename' in data:
config.filename = data['filename']
elif filename is None:
config.filename = DEFAULT_TRACKER_PATH
else:
config.filename = filename
if 'generation' in data:
config.generation = data['generation']
if 'is_bdsp' in data:
config.is_bdsp = data['is_bdsp']
except IOError:
if filename is None:
config.filename = DEFAULT_TRACKER_PATH
else:
config.filename = filename
return config
@staticmethod
def to_json(config):
fp = open(CONFIG_FILENAME, 'w')
data = {
'filename': config.filename,
'generation': config.generation,
'is_bdsp': config.is_bdsp,
}
json.dump(data, fp)
fp.close()
instance: Config