-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.py
100 lines (82 loc) · 3.95 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from configparser import ConfigParser
from pathlib import Path
import random as rand
"""
Description of available settings in `config.ini`:
[noise] noise related settings
scale:
octaves:
persistence:
lacunarity:
[filters]
land_bias: Float number that adjusts how much land there is. Can
be set to negative to decrease amount of land. Defaults
to 0.0. Recommended range is -0.25 to 0.25
path: Empty or ommitted will result in a random choice which
is recommended if you are generating lots of images and
want variety.
Relative directory to desired filter. This filter is
subtracted from the heigthmap after it is generated
with noise.
weight: A multiplier to control how much effect the filter has.
[output]
show: True (default) or False. Controls whether image is
opened after the program is run.
dir: Name of file or path relative to the root directory for
saving outputs. Default is maps.
save_color_img:
Defaults to True. Controls whether or not the color
image derived from the height image is saved to the
directory defined here.
save_height_img:
Defaults to True. Controls whether or not the height
image that is generated from noise is saved to the
directory defined here.
save_config: True (default) or False. Controls whether or not the
.ini config is saved after the program runs
save_stats: True (default) or False. Controls whether or not the
.json stats file is saved after the program runs
"""
class Config:
PATH = ('.')
CONFIG_FILE = 'src/config.ini'
IMG = {'x': 2048, 'y': 1024}
SEED = rand.randint(1,100000)
ELEVATION_RANGE = (0, 5000)
def __init__(self):
self.parser = ConfigParser()
self.img = self.IMG
self.seed = self.SEED
self.elevation_range = self.ELEVATION_RANGE
self.noise = {}
self.filters = {}
self.output = {}
self.init()
def init(self):
self.parser.read(self.CONFIG_FILE)
self.load_ini()
def load_ini(self):
# noise
self.noise['scale'] = self.parser.getint('noise', 'scale', fallback=200)
self.noise['octaves'] = self.parser.getint('noise', 'octaves', fallback=5)
self.noise['persistence'] = self.parser.getfloat('noise', 'persistence', fallback=0.5)
self.noise['lacunarity'] = self.parser.getfloat('noise', 'lacunarity', fallback=2.0)
# filters
self.filters['land_bias'] = self.parser.getfloat('filters', 'land_bias', fallback=0.0)
self.filters['path'] = self.parser.get('filters', 'path', fallback=self.get_rand_file())
self.filters['weight'] = self.parser.getfloat('filters', 'weight', fallback=0.67)
# output
self.output['dir'] = self.parser.get('output', 'dir', fallback="maps")
self.output['save_color_img'] = self.parser.getboolean('output', 'save_color_img', fallback=True)
self.output['save_height_img'] = self.parser.getboolean('output', 'save_height_img', fallback=True)
self.output['save_config'] = self.parser.getboolean('output', 'save_config', fallback=True)
self.output['save_stats'] = self.parser.getboolean('output', 'save_stats', fallback=True)
def get_rand_file(self):
p = Path('filters')
return rand.choice(list(p.glob("**/*")))
def _save_to(self, path):
with open(f'{path}', 'w') as f:
self.parser.write(f)
if __name__ == "__main__":
c = Config()
print(c.get_rand_file())