dfpyre 0.8.18__tar.gz → 0.8.19__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dfpyre might be problematic. Click here for more details.
- {dfpyre-0.8.18 → dfpyre-0.8.19}/PKG-INFO +1 -1
- {dfpyre-0.8.18 → dfpyre-0.8.19}/dfpyre/actiondump.py +1 -1
- {dfpyre-0.8.18 → dfpyre-0.8.19}/dfpyre/scriptgen.py +31 -20
- {dfpyre-0.8.18 → dfpyre-0.8.19}/pyproject.toml +1 -1
- {dfpyre-0.8.18 → dfpyre-0.8.19}/LICENSE +0 -0
- {dfpyre-0.8.18 → dfpyre-0.8.19}/README.md +0 -0
- {dfpyre-0.8.18 → dfpyre-0.8.19}/dfpyre/__init__.py +0 -0
- {dfpyre-0.8.18 → dfpyre-0.8.19}/dfpyre/action_literals.py +0 -0
- {dfpyre-0.8.18 → dfpyre-0.8.19}/dfpyre/data/actiondump_min.json +0 -0
- {dfpyre-0.8.18 → dfpyre-0.8.19}/dfpyre/items.py +0 -0
- {dfpyre-0.8.18 → dfpyre-0.8.19}/dfpyre/pyre.py +0 -0
- {dfpyre-0.8.18 → dfpyre-0.8.19}/dfpyre/style.py +0 -0
- {dfpyre-0.8.18 → dfpyre-0.8.19}/dfpyre/util.py +0 -0
|
@@ -97,7 +97,7 @@ def parse_actiondump() -> ActiondumpResult:
|
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
def get_default_tags(codeblock_type: str|None, codeblock_action: str|None) -> dict[str, str]:
|
|
100
|
-
if codeblock_type
|
|
100
|
+
if not codeblock_type or not codeblock_action:
|
|
101
101
|
return {}
|
|
102
102
|
return {t['name']: t['default'] for t in CODEBLOCK_DATA[codeblock_type][codeblock_action]['tags']}
|
|
103
103
|
|
|
@@ -56,7 +56,15 @@ def item_to_string(class_name: str, i: Item, slot_argument: str):
|
|
|
56
56
|
return f'{class_name}.from_snbt("""{snbt_string}""")'
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
def
|
|
59
|
+
def escape(s: str) -> str:
|
|
60
|
+
return s.replace('\n', '\\n').replace("\'", "\\'")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def str_literal(s: str) -> str:
|
|
64
|
+
return "'" + escape(s) + "'"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def argument_item_to_string(flags: GeneratorFlags, arg_item: object) -> str:
|
|
60
68
|
class_name = arg_item.__class__.__name__
|
|
61
69
|
has_slot = arg_item.slot is not None and flags.preserve_slots
|
|
62
70
|
slot_argument = f', slot={arg_item.slot}' if has_slot else ''
|
|
@@ -65,18 +73,18 @@ def argument_item_to_string(flags: GeneratorFlags, arg_item: object) -> str:
|
|
|
65
73
|
return item_to_string(class_name, arg_item, slot_argument)
|
|
66
74
|
|
|
67
75
|
if isinstance(arg_item, String):
|
|
68
|
-
|
|
76
|
+
literal = str_literal(arg_item.value)
|
|
69
77
|
if not has_slot and flags.literal_shorthand:
|
|
70
|
-
return
|
|
71
|
-
return f"{class_name}(
|
|
78
|
+
return literal
|
|
79
|
+
return f"{class_name}({literal}{slot_argument})"
|
|
72
80
|
|
|
73
81
|
if isinstance(arg_item, Text):
|
|
74
|
-
|
|
75
|
-
return f"{class_name}('{
|
|
82
|
+
literal = str_literal(arg_item.value)
|
|
83
|
+
return f"{class_name}('{literal}'{slot_argument})"
|
|
76
84
|
|
|
77
85
|
if isinstance(arg_item, Number):
|
|
78
86
|
if not is_number(str(arg_item.value)): # Probably a math expression
|
|
79
|
-
return f"{class_name}(
|
|
87
|
+
return f"{class_name}({str_literal(arg_item.value)}{slot_argument})"
|
|
80
88
|
if not has_slot and flags.literal_shorthand:
|
|
81
89
|
return str(arg_item.value)
|
|
82
90
|
return f'{class_name}({arg_item.value}{slot_argument})'
|
|
@@ -90,29 +98,31 @@ def argument_item_to_string(flags: GeneratorFlags, arg_item: object) -> str:
|
|
|
90
98
|
return f'{class_name}({", ".join(str(c) for c in loc_components)}{slot_argument})'
|
|
91
99
|
|
|
92
100
|
if isinstance(arg_item, Variable):
|
|
101
|
+
name = escape(arg_item.name)
|
|
93
102
|
if not has_slot and flags.var_shorthand:
|
|
94
|
-
return f"'${VAR_SCOPES[arg_item.scope]} {
|
|
103
|
+
return f"'${VAR_SCOPES[arg_item.scope]} {name}'"
|
|
95
104
|
if arg_item.scope == 'unsaved':
|
|
96
|
-
return f"{class_name}('{
|
|
97
|
-
return f"{class_name}('{
|
|
105
|
+
return f"{class_name}('{name}'{slot_argument})"
|
|
106
|
+
return f"{class_name}('{name}', '{arg_item.scope}'{slot_argument})"
|
|
98
107
|
|
|
99
108
|
if isinstance(arg_item, Sound):
|
|
100
|
-
return f"{class_name}(
|
|
109
|
+
return f"{class_name}({str_literal(arg_item.name)}, {arg_item.pitch}, {arg_item.vol}{slot_argument})"
|
|
101
110
|
|
|
102
111
|
if isinstance(arg_item, Particle):
|
|
103
112
|
return f'{class_name}({arg_item.particle_data})'
|
|
104
113
|
|
|
105
114
|
if isinstance(arg_item, Potion):
|
|
106
|
-
return f"{class_name}(
|
|
115
|
+
return f"{class_name}({str_literal(arg_item.name)}, {arg_item.dur}, {arg_item.amp}{slot_argument})"
|
|
107
116
|
|
|
108
117
|
if isinstance(arg_item, GameValue):
|
|
118
|
+
name = str_literal(arg_item.name)
|
|
109
119
|
if arg_item.target == 'Default':
|
|
110
|
-
return f"{class_name}(
|
|
111
|
-
return f"{class_name}(
|
|
120
|
+
return f"{class_name}({name}{slot_argument})"
|
|
121
|
+
return f"{class_name}({name}, '{arg_item.target}'{slot_argument})"
|
|
112
122
|
|
|
113
123
|
if isinstance(arg_item, Parameter):
|
|
114
124
|
param_type_class_name = arg_item.param_type.__class__.__name__
|
|
115
|
-
param_args = [
|
|
125
|
+
param_args = [str_literal(arg_item.name), f'{param_type_class_name}.{arg_item.param_type.name}']
|
|
116
126
|
if arg_item.plural:
|
|
117
127
|
param_args.append('plural=True')
|
|
118
128
|
if arg_item.optional:
|
|
@@ -120,9 +130,9 @@ def argument_item_to_string(flags: GeneratorFlags, arg_item: object) -> str:
|
|
|
120
130
|
if arg_item.default_value is not None:
|
|
121
131
|
param_args.append(f'default_value={argument_item_to_string(flags, arg_item.default_value)}')
|
|
122
132
|
if arg_item.description:
|
|
123
|
-
param_args.append(f"description=
|
|
133
|
+
param_args.append(f"description={str_literal(arg_item.description)}")
|
|
124
134
|
if arg_item.note:
|
|
125
|
-
param_args.append(f"note=
|
|
135
|
+
param_args.append(f"note={str_literal(arg_item.note)}")
|
|
126
136
|
return f'{class_name}({", ".join(param_args)}{slot_argument})'
|
|
127
137
|
|
|
128
138
|
if isinstance(arg_item, Vector):
|
|
@@ -153,7 +163,8 @@ def generate_script(template, flags: GeneratorFlags) -> str:
|
|
|
153
163
|
script_lines.append(IMPORT_STATEMENT + '\n')
|
|
154
164
|
|
|
155
165
|
def remove_comma_from_last_line():
|
|
156
|
-
|
|
166
|
+
if script_lines[-1].endswith(','):
|
|
167
|
+
script_lines[-1] = script_lines[-1][:-1]
|
|
157
168
|
|
|
158
169
|
def get_var_assignment_snippet() -> str:
|
|
159
170
|
first_block_data = template.codeblocks[0].data
|
|
@@ -186,7 +197,7 @@ def generate_script(template, flags: GeneratorFlags) -> str:
|
|
|
186
197
|
|
|
187
198
|
# Set function or process name if necessary
|
|
188
199
|
if codeblock.action_name == 'dynamic':
|
|
189
|
-
function_args[0] =
|
|
200
|
+
function_args[0] = str_literal(codeblock.data["data"])
|
|
190
201
|
|
|
191
202
|
# Convert argument objects to valid Python strings
|
|
192
203
|
codeblock_args = [argument_item_to_string(flags, i) for i in codeblock.args]
|
|
@@ -212,7 +223,7 @@ def generate_script(template, flags: GeneratorFlags) -> str:
|
|
|
212
223
|
if codeblock.data.get('attribute') == 'NOT':
|
|
213
224
|
function_args.append('inverted=True')
|
|
214
225
|
|
|
215
|
-
# Create and add the
|
|
226
|
+
# Create and add the line
|
|
216
227
|
if codeblock.type in CONTAINER_CODEBLOCKS:
|
|
217
228
|
if codeblock.type == 'else':
|
|
218
229
|
line = f'{function_name}(['
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|