Skip to content

Commit 75a3322

Browse files
committed
handle option reordering
1 parent eaed965 commit 75a3322

2 files changed

Lines changed: 51 additions & 22 deletions

File tree

scripts/execute.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,44 @@
77
def validate_header_option(line):
88
return ParsedOption(line).validate(HEADER_OPTIONS)
99

10+
def handle_header_line(line, deferral_list):
11+
option = ParsedOption(line)
12+
if option.validate(HEADER_OPTIONS):
13+
if option.scope(HEADER_OPTIONS) == 'player':
14+
deferral_list.append(line)
15+
return ''
16+
else:
17+
return line
18+
return ''
19+
1020
def generate_simc_input(profiles: list[Profile]):
1121
for profile in profiles:
1222
profile.validate()
1323

1424
profile.params = []
25+
deferred_options = []
26+
push_deferred_options = False
1527
with open(profile) as handle:
1628
header = True
1729
for line in handle.readlines():
1830
line = line.strip()
1931
if not len(line):
2032
continue
21-
if line[0] == '#':
22-
if header and validate_header_option(line[1:].strip()):
23-
line = line[1:].strip()
24-
else:
25-
line = ''
33+
if line[0] == '#' and header:
34+
line = handle_header_line(line[1:].strip(), deferred_options)
35+
elif line[0] == '#' and not header:
36+
line = ''
2637
else:
38+
option = ParsedOption(line)
39+
if option.validate_class(profile) and option.validate_class_value(profile):
40+
push_deferred_options = True
2741
header = False
2842

2943
if line != '':
3044
profile.params.append(line)
45+
if push_deferred_options:
46+
profile.params += deferred_options
47+
deferred_options = []
3148

3249
def run_sim(binary: Path, profiles: list[str], prefix: list[str], suffix: list[str] = []):
3350
proc = subprocess.Popen([binary] + prefix + profiles + suffix, stdout=sys.stdout, stderr=sys.stderr)

scripts/shared.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,27 @@ class Option:
2424
ignore_value: bool
2525
values: list[str]
2626
case_sensitive: bool
27+
scope: str
2728

28-
def __init__(self, key, values=[], ignore_value=False, case_sensitive=True):
29+
def __init__(self, key, values=[], ignore_value=False, case_sensitive=True, scope='player'):
2930
self.key = key
3031
self.values = values
3132
self.ignore_value = ignore_value
3233
self.case_sensitive = case_sensitive
34+
self.scope = scope
3335

3436
def __eq__(self, other: ParsedOption):
35-
if self.key != other.key:
36-
return False
37-
if self.ignore_value:
38-
return True
39-
if self.case_sensitive:
40-
return other.value in self.values
41-
else:
42-
return other.value.lower() in self.values
37+
if isinstance(other, ParsedOption):
38+
if self.key != other.key:
39+
return False
40+
if self.ignore_value:
41+
return True
42+
if self.case_sensitive:
43+
return other.value in self.values
44+
else:
45+
return other.value.lower() in self.values
46+
assert False
47+
return False
4348

4449
class Options:
4550
options: list[Option]
@@ -52,6 +57,10 @@ def __init__(self, *options):
5257
def __contains__(self, other):
5358
return other in self.options
5459

60+
def __iter__(self):
61+
for option in self.options:
62+
yield option
63+
5564
# class (handled separately as value depends on filename)
5665
SIMC_OPTIONS = Options(
5766
Option('level', ['90']),
@@ -96,14 +105,14 @@ def __contains__(self, other):
96105
Option('warlock.default_pet', ['sayaad', 'succubus', 'incubus', 'felguard']),
97106
)
98107
HEADER_OPTIONS = Options(
99-
Option('desired_targets', ignore_value=True),
100-
Option('fight_style', ['patchwerk', 'castingpatchwerk', 'dungeonslice']),
101-
Option('source', ['default']),
102-
Option('potion', ignore_value=True),
103-
Option('flask', ignore_value=True),
104-
Option('food', ignore_value=True),
105-
Option('augmentation', ignore_value=True),
106-
Option('temporary_enchant', ignore_value=True),
108+
Option('desired_targets', ignore_value=True, scope='sim'),
109+
Option('fight_style', ['patchwerk', 'castingpatchwerk', 'dungeonslice'], scope='sim'),
110+
Option('source', ['default'], scope='player'),
111+
Option('potion', ignore_value=True, scope='player'),
112+
Option('flask', ignore_value=True, scope='player'),
113+
Option('food', ignore_value=True, scope='player'),
114+
Option('augmentation', ignore_value=True, scope='player'),
115+
Option('temporary_enchant', ignore_value=True, scope='player'),
107116
)
108117

109118
class Profile:
@@ -197,6 +206,9 @@ def __str__(self):
197206
return f'Invalid Option {self.key}'
198207
return f'{self.key}{self.operator}{self.value}'
199208

209+
def scope(self, options: Options):
210+
return next((o for o in options if o == self)).scope
211+
200212
def validate_class(self, profile: Profile):
201213
class_name, _, _ = profile.path_parts()
202214
return self.parsed and self.key == class_name

0 commit comments

Comments
 (0)