Skip to content

Commit 621d693

Browse files
committed
Rename "lines_tokens" to "children"
1 parent 6f700bc commit 621d693

File tree

5 files changed

+36
-37
lines changed

5 files changed

+36
-37
lines changed

Python/ini_converting/ini_parser.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ def get_parsed_tokens(tokens, parsed=None, token_idx=None, depth=0):
1515
while token_idx[0] < len(tokens):
1616
token = tokens[token_idx[0]]
1717

18-
if state == "newline" and token["type"] == "EXTRA":
19-
parsed[-1].append( { "type": "extra", "content": token["content"] } )
20-
token_idx[0] += 1
21-
elif state == "newline" and token["type"] == "NEWLINES":
22-
parsed[-1].append( { "type": "extra", "content": token["content"] } )
23-
token_idx[0] += 1
24-
25-
elif state == "newline" and token["type"] == "TABS" and is_deeper(depth, token):
18+
# if state == "newline" and token["type"] == "EXTRA":
19+
# parsed[-1].append( { "type": "extra", "content": token["content"] } )
20+
# token_idx[0] += 1
21+
# elif state == "newline" and token["type"] == "NEWLINES":
22+
# parsed[-1].append( { "type": "extra", "content": token["content"] } )
23+
# token_idx[0] += 1
24+
25+
if state == "newline" and token["type"] == "TABS" and is_deeper(depth, token):
2626
children = { "type": "children", "content": [] }
2727
parsed[-1].append(children)
2828
get_parsed_tokens(tokens, children["content"], token_idx, depth + 1)

Python/ini_converting/ini_rules.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,32 @@ def apply_rules_on_ini_cst(parsed_subset):
2727
def apply_rules_on_sections(parsed_subset):
2828
for section in parsed_subset:
2929
for token in section:
30-
if token["type"] == "lines_tokens":
31-
lines_tokens = token["content"]
30+
if token["type"] == "children":
31+
children = token["content"]
3232

3333
# TODO: Remove contains_property_shallowly() and write out what they do in this function
34-
if contains_property_shallowly(lines_tokens, "MaxMass"):
35-
max_mass_to_max_inventory_mass(lines_tokens)
34+
if contains_property_shallowly(children, "MaxMass"):
35+
max_mass_to_max_inventory_mass(children)
3636

37-
iconfile_path = iconfile_path_to_thumbnail_generator(lines_tokens)
37+
iconfile_path = iconfile_path_to_thumbnail_generator(children)
3838

39-
for line_tokens in lines_tokens:
39+
for line_tokens in children:
4040
replace_property_and_value(line_tokens, "MinThrottleRange", "NegativeThrottleMultiplier", min_throttle_range_to_negative_throttle_multiplier)
4141
replace_property_and_value(line_tokens, "MaxThrottleRange", "PositiveThrottleMultiplier", max_throttle_range_to_positive_throttle_multiplier)
4242

4343
# TODO: Remove contains_property_and_value_shallowly() and write out what it does in this function
4444
# TODO: I don't remember whether this one works
4545
if contains_property_and_value_shallowly(section, "AddActor", "Leg"):
4646
for token in section:
47-
if token["type"] == "lines_tokens":
48-
lines_tokens = token["content"]
47+
if token["type"] == "children":
48+
children = token["content"]
4949

50-
max_length_to_offsets(lines_tokens)
50+
max_length_to_offsets(children)
5151

5252

53-
def contains_property_shallowly(lines_tokens, prop):
53+
def contains_property_shallowly(children, prop):
5454
""" This function deliberately doesn't check the section's contents recursively. """
55-
return [True for line_tokens in lines_tokens for token in line_tokens if token["type"] == "property" and token["content"] == prop] != []
55+
return [True for line_tokens in children for token in line_tokens if token["type"] == "property" and token["content"] == prop] != []
5656

5757

5858
def contains_property_and_value_shallowly(section, prop, value):
@@ -67,13 +67,13 @@ def contains_property_and_value_shallowly(section, prop, value):
6767
return contains_property and contains_value
6868

6969

70-
def max_mass_to_max_inventory_mass(lines_tokens):
70+
def max_mass_to_max_inventory_mass(children):
7171
""" MaxInventoryMass = MaxMass - Mass """
7272

7373
mass = 0 # The Mass is optionally defined in the INI file.
7474

7575
# TODO: Find a way to split these into subfunctions.
76-
for line_tokens in lines_tokens:
76+
for line_tokens in children:
7777
for token in line_tokens:
7878
if token["type"] == "property":
7979
if token["content"] == "Mass":
@@ -90,7 +90,7 @@ def max_mass_to_max_inventory_mass(lines_tokens):
9090

9191
max_inventory_mass = remove_excess_zeros(max_mass - mass)
9292

93-
for line_tokens in lines_tokens:
93+
for line_tokens in children:
9494
for token in line_tokens:
9595
if token["type"] == "property":
9696
if token["content"] == "MaxMass":
@@ -127,7 +127,7 @@ def max_throttle_range_to_positive_throttle_multiplier(old_value):
127127

128128

129129
# TODO: Refactor max_length_to_offsets and max_length_to_offsets_2
130-
def max_length_to_offsets(lines_tokens):
130+
def max_length_to_offsets(children):
131131
"""
132132
If the parent line is AddActor = Leg:
133133
MaxLength = old_value
@@ -140,18 +140,18 @@ def max_length_to_offsets(lines_tokens):
140140
Y = 0
141141
"""
142142

143-
for index, line_tokens in enumerate(lines_tokens):
143+
for index, line_tokens in enumerate(children):
144144
old_value = max_length_to_offsets_2(line_tokens)
145145

146146
if old_value != None:
147147
# print(index, old_value)
148148

149-
lines_tokens.insert(index + 1, [
149+
children.insert(index + 1, [
150150
{ "type": "extra", "content": "\t" },
151151
{ "type": "property", "content": "ExtendedOffset" },
152152
{ "type": "extra", "content": " "}, {"type": "extra", "content": "="}, {"type": "extra", "content": " "},
153153
{ "type": "value", "content": "Vector" },
154-
{ "type": "lines_tokens", "content": [
154+
{ "type": "children", "content": [
155155
[
156156
{ "type": "extra", "content": "\t\t" },
157157
{ "type": "property", "content": "X" },
@@ -179,7 +179,7 @@ def max_length_to_offsets_2(line_tokens):
179179
old_value = float(token_2["content"])
180180
token_2["content"] = "Vector"
181181

182-
line_tokens.append( { "type": "lines_tokens", "content": [
182+
line_tokens.append( { "type": "children", "content": [
183183
[
184184
{ "type": "extra", "content": "\t\t" },
185185
{ "type": "property", "content": "X" },
@@ -197,15 +197,15 @@ def max_length_to_offsets_2(line_tokens):
197197
return old_value
198198

199199

200-
def iconfile_path_to_thumbnail_generator(lines_tokens):
201-
for line_tokens in lines_tokens:
200+
def iconfile_path_to_thumbnail_generator(children):
201+
for line_tokens in children:
202202
if {"type": "property", "content": "IconFile"} in line_tokens and {"type": "value", "content": "ContentFile"} in line_tokens:
203203
for token in line_tokens:
204-
if token["type"] == "lines_tokens":
205-
sublines_tokens = token["content"]
206-
# print(sublines_tokens)
204+
if token["type"] == "children":
205+
subchildren = token["content"]
206+
# print(subchildren)
207207

208-
for subline_tokens in sublines_tokens:
208+
for subline_tokens in subchildren:
209209
if {"type": "property", "content": "FilePath"} in subline_tokens:
210210
# print(subline_tokens)
211211
for subtoken in subline_tokens:

Python/ini_converting/ini_writer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ def get_lines_from_dicts_recursively(line_tokens, lines):
1717

1818
line = ""
1919
for dictionary in line_tokens:
20-
if dictionary["type"] != "lines_tokens":
20+
if dictionary["type"] != "children":
2121
line += dictionary["content"]
2222
lines.append(line)
2323

2424
for dictionary in line_tokens:
25-
if dictionary["type"] == "lines_tokens":
25+
if dictionary["type"] == "children":
2626
for line_tokens in dictionary["content"]:
2727
get_lines_from_dicts_recursively(line_tokens, lines)

Python/lua_converting/lua_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# ->
2323
# [
2424
# { "type": "extra", "content": "local found = SceneMan:CastMORay(" },
25-
# { "type": "lines_tokens", "content": [
25+
# { "type": "children", "content": [
2626

2727
# ]},
2828
# { "type": "extra", "content": "\t" },

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
* Make sure that built exes don't run the tests every time they convert something.
2-
* Rename "lines_tokens" to "children"
32
* Check if commenting out "ini_rules.apply_rules_on_ini_cst(ini_cst)" in convert.py and some other lines results in outputted mod INI files being identical.

0 commit comments

Comments
 (0)