dfpyre 0.7.11__py3-none-any.whl → 0.8.0__py3-none-any.whl
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/items.py +70 -47
- dfpyre/pyre.py +215 -219
- dfpyre/scriptgen.py +61 -39
- dfpyre/util.py +11 -0
- {dfpyre-0.7.11.dist-info → dfpyre-0.8.0.dist-info}/METADATA +150 -158
- dfpyre-0.8.0.dist-info/RECORD +12 -0
- dfpyre-0.7.11.dist-info/RECORD +0 -12
- {dfpyre-0.7.11.dist-info → dfpyre-0.8.0.dist-info}/LICENSE +0 -0
- {dfpyre-0.7.11.dist-info → dfpyre-0.8.0.dist-info}/WHEEL +0 -0
dfpyre/items.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""
|
|
2
|
-
|
|
2
|
+
Class definitions for code items.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
from enum import Enum
|
|
@@ -10,18 +10,20 @@ from dfpyre.util import PyreException, warn
|
|
|
10
10
|
from mcitemlib.itemlib import Item as NbtItem
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
NUMBER_REGEX = r'
|
|
14
|
-
|
|
13
|
+
NUMBER_REGEX = r'^-?\d*\.?\d+$'
|
|
14
|
+
VAR_SHORTHAND_REGEX = r'^\$([gsli]) (.+)$'
|
|
15
15
|
VAR_SCOPES = {'g': 'unsaved', 's': 'saved', 'l': 'local', 'i': 'line'}
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def convert_argument(arg: Any):
|
|
19
19
|
if type(arg) in {int, float}:
|
|
20
|
-
return
|
|
20
|
+
return Number(arg)
|
|
21
21
|
elif isinstance(arg, str):
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
shorthand_match: re.Match = re.match(VAR_SHORTHAND_REGEX, arg)
|
|
23
|
+
if shorthand_match:
|
|
24
|
+
scope = VAR_SCOPES[shorthand_match.group(1)]
|
|
25
|
+
return Variable(shorthand_match.group(2), scope)
|
|
26
|
+
return Text(arg)
|
|
25
27
|
return arg
|
|
26
28
|
|
|
27
29
|
|
|
@@ -30,7 +32,7 @@ def _add_slot(d: dict, slot: int|None):
|
|
|
30
32
|
d['slot'] = slot
|
|
31
33
|
|
|
32
34
|
|
|
33
|
-
class
|
|
35
|
+
class Item(NbtItem):
|
|
34
36
|
"""
|
|
35
37
|
Represents a Minecraft item.
|
|
36
38
|
"""
|
|
@@ -45,7 +47,7 @@ class item(NbtItem):
|
|
|
45
47
|
return f'{self.__class__.__name__}({self.get_id()}, {self.get_count()})'
|
|
46
48
|
|
|
47
49
|
|
|
48
|
-
class
|
|
50
|
+
class String:
|
|
49
51
|
"""
|
|
50
52
|
Represents a DiamondFire string object. (`txt`)
|
|
51
53
|
"""
|
|
@@ -61,9 +63,11 @@ class string:
|
|
|
61
63
|
|
|
62
64
|
def __repr__(self) -> str:
|
|
63
65
|
return f'{self.__class__.__name__}("{self.value}")'
|
|
66
|
+
|
|
67
|
+
Str = String # String alias
|
|
64
68
|
|
|
65
69
|
|
|
66
|
-
class
|
|
70
|
+
class Text:
|
|
67
71
|
"""
|
|
68
72
|
Represents a DiamondFire styled text object (`comp`)
|
|
69
73
|
"""
|
|
@@ -83,7 +87,7 @@ class text:
|
|
|
83
87
|
return f'{self.__class__.__name__}("{self.value}")'
|
|
84
88
|
|
|
85
89
|
|
|
86
|
-
class
|
|
90
|
+
class Number:
|
|
87
91
|
"""
|
|
88
92
|
Represents a DiamondFire number object.
|
|
89
93
|
"""
|
|
@@ -100,8 +104,10 @@ class num:
|
|
|
100
104
|
def __repr__(self) -> str:
|
|
101
105
|
return f'{self.__class__.__name__}({self.value})'
|
|
102
106
|
|
|
107
|
+
Num = Number # Number alias
|
|
108
|
+
|
|
103
109
|
|
|
104
|
-
class
|
|
110
|
+
class Location:
|
|
105
111
|
"""
|
|
106
112
|
Represents a DiamondFire location object.
|
|
107
113
|
"""
|
|
@@ -134,15 +140,20 @@ class loc:
|
|
|
134
140
|
def __repr__(self) -> str:
|
|
135
141
|
return f'{self.__class__.__name__}({self.x}, {self.y}, {self.z}, {self.pitch}, {self.yaw})'
|
|
136
142
|
|
|
143
|
+
Loc = Location # Location alias
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
|
|
146
|
+
class Variable:
|
|
139
147
|
"""
|
|
140
148
|
Represents a DiamondFire variable object.
|
|
141
149
|
"""
|
|
142
150
|
type = 'var'
|
|
143
151
|
|
|
144
|
-
def __init__(self, name: str, scope: Literal['unsaved', 'saved', 'local', 'line']='unsaved'):
|
|
152
|
+
def __init__(self, name: str, scope: Literal['unsaved', 'game', 'saved', 'local', 'line']='unsaved'):
|
|
145
153
|
self.name = name
|
|
154
|
+
|
|
155
|
+
if scope == 'game':
|
|
156
|
+
scope = 'unsaved'
|
|
146
157
|
self.scope = scope
|
|
147
158
|
|
|
148
159
|
def format(self, slot: int|None):
|
|
@@ -153,8 +164,10 @@ class var:
|
|
|
153
164
|
def __repr__(self) -> str:
|
|
154
165
|
return f'{self.__class__.__name__}({self.scope}, "{self.name}")'
|
|
155
166
|
|
|
167
|
+
Var = Variable # Variable alias
|
|
156
168
|
|
|
157
|
-
|
|
169
|
+
|
|
170
|
+
class Sound:
|
|
158
171
|
"""
|
|
159
172
|
Represents a DiamondFire sound object.
|
|
160
173
|
"""
|
|
@@ -173,8 +186,10 @@ class sound:
|
|
|
173
186
|
def __repr__(self) -> str:
|
|
174
187
|
return f'{self.__class__.__name__}(pitch: {self.pitch}, volume: {self.vol})'
|
|
175
188
|
|
|
189
|
+
Snd = Sound # Sound alias
|
|
190
|
+
|
|
176
191
|
|
|
177
|
-
class
|
|
192
|
+
class Particle:
|
|
178
193
|
"""
|
|
179
194
|
Represents a DiamondFire particle object.
|
|
180
195
|
"""
|
|
@@ -191,7 +206,7 @@ class particle:
|
|
|
191
206
|
return f'{self.__class__.__name__}({self.particle_data})'
|
|
192
207
|
|
|
193
208
|
|
|
194
|
-
class
|
|
209
|
+
class Potion:
|
|
195
210
|
"""
|
|
196
211
|
Represents a DiamondFire potion object.
|
|
197
212
|
"""
|
|
@@ -210,8 +225,10 @@ class potion:
|
|
|
210
225
|
def __repr__(self) -> str:
|
|
211
226
|
return f'{self.__class__.__name__}(effect: {self.name}, duration: {self.dur}, amplifier: {self.amp})'
|
|
212
227
|
|
|
228
|
+
Pot = Potion # Potion alias
|
|
229
|
+
|
|
213
230
|
|
|
214
|
-
class
|
|
231
|
+
class GameValue:
|
|
215
232
|
"""
|
|
216
233
|
Represents a DiamondFire game value object.
|
|
217
234
|
"""
|
|
@@ -230,7 +247,7 @@ class gamevalue:
|
|
|
230
247
|
return f'{self.__class__.__name__}({self.name}, target: {self.target})'
|
|
231
248
|
|
|
232
249
|
|
|
233
|
-
class
|
|
250
|
+
class Vector:
|
|
234
251
|
"""
|
|
235
252
|
Represents a DiamondFire vector object.
|
|
236
253
|
"""
|
|
@@ -249,6 +266,8 @@ class vector:
|
|
|
249
266
|
def __repr__(self) -> str:
|
|
250
267
|
return f'{self.__class__.__name__}({self.x}, {self.y}, {self.z})'
|
|
251
268
|
|
|
269
|
+
Vec = Vector # Vector alias
|
|
270
|
+
|
|
252
271
|
|
|
253
272
|
PARAMETER_TYPE_LOOKUP = ['txt', 'comp', 'num', 'loc', 'vec', 'snd', 'part', 'pot', 'item', 'any', 'var', 'list', 'dict']
|
|
254
273
|
|
|
@@ -270,7 +289,7 @@ class ParameterType(Enum):
|
|
|
270
289
|
def get_string_value(self) -> str:
|
|
271
290
|
return PARAMETER_TYPE_LOOKUP[self.value]
|
|
272
291
|
|
|
273
|
-
class
|
|
292
|
+
class Parameter:
|
|
274
293
|
"""
|
|
275
294
|
Represents a DiamondFire parameter object.
|
|
276
295
|
"""
|
|
@@ -316,58 +335,62 @@ class parameter:
|
|
|
316
335
|
return f'{self.__class__.__name__}({self.name}, type: {raw_type})'
|
|
317
336
|
|
|
318
337
|
|
|
319
|
-
def _some_or(value: Any, none_value: Any):
|
|
320
|
-
"""
|
|
321
|
-
Returns `none_value` if `value` is None, otherwise returns `value`.
|
|
322
|
-
"""
|
|
323
|
-
if value is None:
|
|
324
|
-
return none_value
|
|
325
|
-
return value
|
|
326
|
-
|
|
327
|
-
|
|
328
338
|
def item_from_dict(item_dict: dict) -> object:
|
|
329
339
|
item_id = item_dict['id']
|
|
330
340
|
item_data = item_dict['data']
|
|
331
341
|
|
|
332
342
|
if item_id == 'item':
|
|
333
|
-
return
|
|
343
|
+
return Item.from_nbt(item_data['item'])
|
|
344
|
+
|
|
334
345
|
elif item_id == 'txt':
|
|
335
|
-
return
|
|
346
|
+
return String(item_data['name'])
|
|
347
|
+
|
|
336
348
|
elif item_id == 'comp':
|
|
337
|
-
return
|
|
349
|
+
return Text(item_data['name'])
|
|
350
|
+
|
|
338
351
|
elif item_id == 'num':
|
|
339
352
|
num_value = item_data['name']
|
|
340
353
|
if re.match(NUMBER_REGEX, num_value):
|
|
341
354
|
num_value = float(item_data['name'])
|
|
342
355
|
if num_value % 1 == 0:
|
|
343
356
|
num_value = int(num_value)
|
|
344
|
-
return
|
|
345
|
-
return
|
|
357
|
+
return Number(num_value)
|
|
358
|
+
return Number(num_value)
|
|
359
|
+
|
|
346
360
|
elif item_id == 'loc':
|
|
347
361
|
item_loc = item_data['loc']
|
|
348
|
-
return
|
|
362
|
+
return Location(item_loc['x'], item_loc['y'], item_loc['z'], item_loc['pitch'], item_loc['yaw'])
|
|
363
|
+
|
|
349
364
|
elif item_id == 'var':
|
|
350
|
-
return
|
|
365
|
+
return Variable(item_data['name'], item_data['scope'])
|
|
366
|
+
|
|
351
367
|
elif item_id == 'snd':
|
|
352
|
-
return
|
|
368
|
+
return Sound(item_data['sound'], item_data['pitch'], item_data['vol'])
|
|
369
|
+
|
|
353
370
|
elif item_id == 'part':
|
|
354
|
-
return
|
|
371
|
+
return Particle(item_data)
|
|
372
|
+
|
|
355
373
|
elif item_id == 'pot':
|
|
356
|
-
return
|
|
374
|
+
return Potion(item_data['pot'], item_data['dur'], item_data['amp'])
|
|
375
|
+
|
|
357
376
|
elif item_id == 'g_val':
|
|
358
|
-
return
|
|
377
|
+
return GameValue(item_data['type'], item_data['target'])
|
|
378
|
+
|
|
359
379
|
elif item_id == 'vec':
|
|
360
|
-
return
|
|
380
|
+
return Vector(item_data['x'], item_data['y'], item_data['z'])
|
|
381
|
+
|
|
361
382
|
elif item_id == 'pn_el':
|
|
362
|
-
description =
|
|
363
|
-
note =
|
|
383
|
+
description = item_data.get('description') or ''
|
|
384
|
+
note = item_data.get('note') or ''
|
|
364
385
|
param_type = ParameterType(PARAMETER_TYPE_LOOKUP.index(item_data['type']))
|
|
365
386
|
if item_data['optional']:
|
|
366
387
|
if 'default_value' in item_data:
|
|
367
|
-
return
|
|
368
|
-
return
|
|
369
|
-
return
|
|
370
|
-
|
|
388
|
+
return Parameter(item_data['name'], param_type, item_data['plural'], True, description, note, item_from_dict(item_data['default_value']))
|
|
389
|
+
return Parameter(item_data['name'], param_type, item_data['plural'], True, description, note)
|
|
390
|
+
return Parameter(item_data['name'], param_type, item_data['plural'], False, description, note)
|
|
391
|
+
|
|
392
|
+
elif item_id in {'bl_tag', 'hint'}: # Ignore tags and hints
|
|
371
393
|
return
|
|
394
|
+
|
|
372
395
|
else:
|
|
373
396
|
raise PyreException(f'Unrecognized item id `{item_id}`')
|