dfpyre 0.6.0__tar.gz → 0.6.1__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.6.0 → dfpyre-0.6.1}/PKG-INFO +1 -1
- {dfpyre-0.6.0 → dfpyre-0.6.1}/dfpyre/pyre.py +58 -56
- {dfpyre-0.6.0 → dfpyre-0.6.1}/dfpyre/scriptgen.py +6 -4
- {dfpyre-0.6.0 → dfpyre-0.6.1}/pyproject.toml +1 -1
- {dfpyre-0.6.0 → dfpyre-0.6.1}/LICENSE +0 -0
- {dfpyre-0.6.0 → dfpyre-0.6.1}/README.md +0 -0
- {dfpyre-0.6.0 → dfpyre-0.6.1}/dfpyre/__init__.py +0 -0
- {dfpyre-0.6.0 → dfpyre-0.6.1}/dfpyre/data/data.json +0 -0
- {dfpyre-0.6.0 → dfpyre-0.6.1}/dfpyre/items.py +0 -0
- {dfpyre-0.6.0 → dfpyre-0.6.1}/dfpyre/style.py +0 -0
|
@@ -226,8 +226,6 @@ def _get_template_item(template_code: str, name: str, author: str) -> NbtItem:
|
|
|
226
226
|
return template_item
|
|
227
227
|
|
|
228
228
|
|
|
229
|
-
# TODO:
|
|
230
|
-
# - add inserting codeblocks at any index
|
|
231
229
|
class DFTemplate:
|
|
232
230
|
"""
|
|
233
231
|
Represents a DiamondFire code template.
|
|
@@ -306,21 +304,19 @@ class DFTemplate:
|
|
|
306
304
|
|
|
307
305
|
self._set_template_name(first_block)
|
|
308
306
|
|
|
309
|
-
print(f'{COL_SUCCESS}Template built successfully.{COL_RESET}')
|
|
310
|
-
|
|
311
307
|
json_string = json.dumps(template_dict, separators=(',', ':'))
|
|
312
308
|
return _df_encode(json_string)
|
|
313
309
|
|
|
314
310
|
|
|
315
|
-
def build_and_send(self, method: Literal['recode', 'codeclient'],
|
|
311
|
+
def build_and_send(self, method: Literal['recode', 'codeclient'], include_tags: bool=True) -> int:
|
|
316
312
|
"""
|
|
317
313
|
Builds this template and sends it to DiamondFire automatically.
|
|
318
314
|
|
|
319
|
-
:param bool
|
|
315
|
+
:param bool include_tags: If True, include item tags in code blocks. Otherwise omit them.
|
|
320
316
|
"""
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
return
|
|
317
|
+
template_code = self.build(include_tags)
|
|
318
|
+
template_item = _get_template_item(template_code, self.name, self.author)
|
|
319
|
+
return template_item.send_to_minecraft(method, 'pyre')
|
|
324
320
|
|
|
325
321
|
|
|
326
322
|
def clear(self):
|
|
@@ -330,138 +326,144 @@ class DFTemplate:
|
|
|
330
326
|
self.__init__()
|
|
331
327
|
|
|
332
328
|
|
|
333
|
-
def
|
|
329
|
+
def _add_codeblock(self, codeblock: CodeBlock, index: int|None):
|
|
330
|
+
if index is None:
|
|
331
|
+
self.codeblocks.append(codeblock)
|
|
332
|
+
else:
|
|
333
|
+
self.codeblocks.insert(index, codeblock)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _openbracket(self, index: int|None, btype: Literal['norm', 'repeat']='norm'):
|
|
334
337
|
bracket = CodeBlock('bracket', data={'id': 'bracket', 'direct': 'open', 'type': btype})
|
|
335
|
-
self.
|
|
338
|
+
self._add_codeblock(bracket, index+1)
|
|
336
339
|
self.bracket_stack.append(btype)
|
|
337
340
|
|
|
338
341
|
|
|
339
342
|
# command methods
|
|
340
|
-
def player_event(self, name: str):
|
|
343
|
+
def player_event(self, name: str, index: int|None=None):
|
|
341
344
|
cmd = CodeBlock(name, data={'id': 'block', 'block': 'event', 'action': name})
|
|
342
|
-
self.
|
|
345
|
+
self._add_codeblock(cmd, index)
|
|
343
346
|
|
|
344
347
|
|
|
345
|
-
def entity_event(self, name: str):
|
|
348
|
+
def entity_event(self, name: str, index: int|None=None):
|
|
346
349
|
cmd = CodeBlock(name, data={'id': 'block', 'block': 'entity_event', 'action': name})
|
|
347
|
-
self.
|
|
350
|
+
self._add_codeblock(cmd, index)
|
|
348
351
|
|
|
349
352
|
|
|
350
|
-
def function(self, name: str, *args):
|
|
353
|
+
def function(self, name: str, *args, index: int|None=None):
|
|
351
354
|
args = _convert_data_types(args)
|
|
352
355
|
cmd = CodeBlock('func', args, data={'id': 'block', 'block': 'func', 'data': name})
|
|
353
|
-
self.
|
|
356
|
+
self._add_codeblock(cmd, index)
|
|
354
357
|
|
|
355
358
|
|
|
356
|
-
def process(self, name: str, *args):
|
|
359
|
+
def process(self, name: str, *args, index: int|None=None):
|
|
357
360
|
args = _convert_data_types(args)
|
|
358
361
|
cmd = CodeBlock('process', args, data={'id': 'block', 'block': 'process', 'data': name})
|
|
359
|
-
self.
|
|
362
|
+
self._add_codeblock(cmd, index)
|
|
360
363
|
|
|
361
364
|
|
|
362
|
-
def call_function(self, name: str, *args):
|
|
365
|
+
def call_function(self, name: str, *args, index: int|None=None):
|
|
363
366
|
args = _convert_data_types(args)
|
|
364
367
|
cmd = CodeBlock('call_func', args, data={'id': 'block', 'block': 'call_func', 'data': name})
|
|
365
|
-
self.
|
|
366
|
-
|
|
368
|
+
self._add_codeblock(cmd, index)
|
|
367
369
|
|
|
368
|
-
def start_process(self, name: str):
|
|
370
|
+
def start_process(self, name: str, index: int|None=None):
|
|
369
371
|
cmd = CodeBlock('start_process', data={'id': 'block', 'block': 'start_process', 'data': name})
|
|
370
|
-
self.
|
|
372
|
+
self._add_codeblock(cmd, index)
|
|
371
373
|
|
|
372
374
|
|
|
373
|
-
def player_action(self, name: str, *args, target: Target=DEFAULT_TARGET):
|
|
375
|
+
def player_action(self, name: str, *args, target: Target=DEFAULT_TARGET, index: int|None=None):
|
|
374
376
|
args = _convert_data_types(args)
|
|
375
377
|
cmd = CodeBlock(name, args, target=target, data={'id': 'block', 'block': 'player_action', 'action': name})
|
|
376
|
-
self.
|
|
378
|
+
self._add_codeblock(cmd, index)
|
|
377
379
|
|
|
378
380
|
|
|
379
|
-
def game_action(self, name: str, *args):
|
|
381
|
+
def game_action(self, name: str, *args, index: int|None=None):
|
|
380
382
|
args = _convert_data_types(args)
|
|
381
383
|
cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'game_action', 'action': name})
|
|
382
|
-
self.
|
|
384
|
+
self._add_codeblock(cmd, index)
|
|
383
385
|
|
|
384
386
|
|
|
385
|
-
def entity_action(self, name: str, *args, target: Target=DEFAULT_TARGET):
|
|
387
|
+
def entity_action(self, name: str, *args, target: Target=DEFAULT_TARGET, index: int|None=None):
|
|
386
388
|
args = _convert_data_types(args)
|
|
387
389
|
cmd = CodeBlock(name, args, target=target, data={'id': 'block', 'block': 'entity_action', 'action': name})
|
|
388
|
-
self.
|
|
390
|
+
self._add_codeblock(cmd, index)
|
|
389
391
|
|
|
390
392
|
|
|
391
|
-
def if_player(self, name: str, *args, target: Target=DEFAULT_TARGET, inverted: bool=False):
|
|
393
|
+
def if_player(self, name: str, *args, target: Target=DEFAULT_TARGET, inverted: bool=False, index: int|None=None):
|
|
392
394
|
args = _convert_data_types(args)
|
|
393
395
|
data = {'id': 'block', 'block': 'if_player', 'action': name}
|
|
394
396
|
_add_inverted(data, inverted)
|
|
395
397
|
cmd = CodeBlock(name, args, target=target, data=data)
|
|
396
|
-
self.
|
|
397
|
-
self._openbracket()
|
|
398
|
+
self._add_codeblock(cmd, index)
|
|
399
|
+
self._openbracket(index)
|
|
398
400
|
|
|
399
401
|
|
|
400
|
-
def if_variable(self, name: str, *args, inverted: bool=False):
|
|
402
|
+
def if_variable(self, name: str, *args, inverted: bool=False, index: int|None=None):
|
|
401
403
|
args = _convert_data_types(args)
|
|
402
404
|
data = {'id': 'block', 'block': 'if_var', 'action': name}
|
|
403
405
|
_add_inverted(data, inverted)
|
|
404
406
|
cmd = CodeBlock(name, args, data=data)
|
|
405
|
-
self.
|
|
406
|
-
self._openbracket()
|
|
407
|
+
self._add_codeblock(cmd, index)
|
|
408
|
+
self._openbracket(index)
|
|
407
409
|
|
|
408
410
|
|
|
409
|
-
def if_game(self, name: str, *args, inverted: bool=False):
|
|
411
|
+
def if_game(self, name: str, *args, inverted: bool=False, index: int|None=None):
|
|
410
412
|
args = _convert_data_types(args)
|
|
411
413
|
data = {'id': 'block', 'block': 'if_game', 'action': name}
|
|
412
414
|
_add_inverted(data, inverted)
|
|
413
415
|
cmd = CodeBlock(name, args, data=data)
|
|
414
|
-
self.
|
|
415
|
-
self._openbracket()
|
|
416
|
+
self._add_codeblock(cmd, index)
|
|
417
|
+
self._openbracket(index)
|
|
416
418
|
|
|
417
419
|
|
|
418
|
-
def if_entity(self, name: str, *args, target: Target=DEFAULT_TARGET, inverted: bool=False):
|
|
420
|
+
def if_entity(self, name: str, *args, target: Target=DEFAULT_TARGET, inverted: bool=False, index: int|None=None):
|
|
419
421
|
args = _convert_data_types(args)
|
|
420
422
|
data = {'id': 'block', 'block': 'if_entity', 'action': name}
|
|
421
423
|
_add_inverted(data, inverted)
|
|
422
424
|
cmd = CodeBlock(name, args, target=target, data=data)
|
|
423
|
-
self.
|
|
424
|
-
self._openbracket()
|
|
425
|
+
self._add_codeblock(cmd, index)
|
|
426
|
+
self._openbracket(index)
|
|
425
427
|
|
|
426
428
|
|
|
427
|
-
def else_(self):
|
|
429
|
+
def else_(self, index: int|None=None):
|
|
428
430
|
cmd = CodeBlock('else', data={'id': 'block', 'block': 'else'})
|
|
429
|
-
self.
|
|
430
|
-
self._openbracket()
|
|
431
|
+
self._add_codeblock(cmd, index)
|
|
432
|
+
self._openbracket(index)
|
|
431
433
|
|
|
432
434
|
|
|
433
|
-
def repeat(self, name: str, *args, sub_action: str=None):
|
|
435
|
+
def repeat(self, name: str, *args, sub_action: str=None, index: int|None=None):
|
|
434
436
|
args = _convert_data_types(args)
|
|
435
437
|
data = {'id': 'block', 'block': 'repeat', 'action': name}
|
|
436
438
|
if sub_action is not None:
|
|
437
439
|
data['subAction'] = sub_action
|
|
438
440
|
cmd = CodeBlock(name, args, data=data)
|
|
439
|
-
self.
|
|
440
|
-
self._openbracket('repeat')
|
|
441
|
+
self._add_codeblock(cmd, index)
|
|
442
|
+
self._openbracket(index, 'repeat')
|
|
441
443
|
|
|
442
444
|
|
|
443
|
-
def bracket(self, *args):
|
|
445
|
+
def bracket(self, *args, index: int|None=None):
|
|
444
446
|
args = _convert_data_types(args)
|
|
445
447
|
cmd = CodeBlock('bracket', data={'id': 'bracket', 'direct': 'close', 'type': self.bracket_stack.pop()})
|
|
446
|
-
self.
|
|
448
|
+
self._add_codeblock(cmd, index)
|
|
447
449
|
|
|
448
450
|
|
|
449
|
-
def control(self, name: str, *args):
|
|
451
|
+
def control(self, name: str, *args, index: int|None=None):
|
|
450
452
|
args = _convert_data_types(args)
|
|
451
453
|
cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'control', 'action': name})
|
|
452
|
-
self.
|
|
454
|
+
self._add_codeblock(cmd, index)
|
|
453
455
|
|
|
454
456
|
|
|
455
|
-
def select_object(self, name: str, *args):
|
|
457
|
+
def select_object(self, name: str, *args, index: int|None=None):
|
|
456
458
|
args = _convert_data_types(args)
|
|
457
459
|
cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'select_obj', 'action': name})
|
|
458
|
-
self.
|
|
460
|
+
self._add_codeblock(cmd, index)
|
|
459
461
|
|
|
460
462
|
|
|
461
|
-
def set_variable(self, name: str, *args):
|
|
463
|
+
def set_variable(self, name: str, *args, index: int|None=None):
|
|
462
464
|
args = _convert_data_types(args)
|
|
463
465
|
cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'set_var', 'action': name})
|
|
464
|
-
self.
|
|
466
|
+
self._add_codeblock(cmd, index)
|
|
465
467
|
|
|
466
468
|
|
|
467
469
|
def generate_script(self, output_path: str, indent_size: int=4, literal_shorthand: bool=True, var_shorthand: bool=False):
|
|
@@ -45,12 +45,14 @@ def argument_item_to_string(flags: GeneratorFlags, arg_item: object) -> str:
|
|
|
45
45
|
return f'{class_name}.from_nbt("""{arg_item.get_nbt()}""")'
|
|
46
46
|
|
|
47
47
|
if isinstance(arg_item, string):
|
|
48
|
-
|
|
48
|
+
value = arg_item.value.replace('\n', '\\n')
|
|
49
|
+
return f'{class_name}("{value}")'
|
|
49
50
|
|
|
50
51
|
if isinstance(arg_item, text):
|
|
52
|
+
value = arg_item.value.replace('\n', '\\n')
|
|
51
53
|
if flags.literal_shorthand:
|
|
52
|
-
return f'"{
|
|
53
|
-
return f'{class_name}("{
|
|
54
|
+
return f'"{value}"'
|
|
55
|
+
return f'{class_name}("{value}")'
|
|
54
56
|
|
|
55
57
|
if isinstance(arg_item, num):
|
|
56
58
|
if not re.match(NUMBER_REGEX, str(arg_item.value)):
|
|
@@ -136,7 +138,7 @@ def generate_script(template, flags: GeneratorFlags) -> str:
|
|
|
136
138
|
codeblock_args = [argument_item_to_string(flags, i) for i in codeblock.args]
|
|
137
139
|
if codeblock_args:
|
|
138
140
|
method_args.extend(codeblock_args)
|
|
139
|
-
if method_name in TARGET_CODEBLOCKS:
|
|
141
|
+
if method_name in TARGET_CODEBLOCKS and codeblock.target.name != 'SELECTION':
|
|
140
142
|
method_args.append(f'target=Target.{codeblock.target.name}')
|
|
141
143
|
|
|
142
144
|
line = f't.{method_name}({", ".join(method_args)})'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|