dfpyre 0.8.11__py3-none-any.whl → 0.8.13__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 CHANGED
@@ -454,6 +454,25 @@ class Parameter:
454
454
  return f'{self.__class__.__name__}({self.name}, type: {raw_type})'
455
455
 
456
456
 
457
+ class _Tag:
458
+ """
459
+ Represents a CodeBlock action tag.
460
+ """
461
+ type = 'bl_tag'
462
+
463
+ def __init__(self, tag_data: dict, slot: int | None=None):
464
+ self.tag_data = tag_data
465
+ self.slot = slot
466
+
467
+ def format(self, slot: int|None):
468
+ formatted_dict = {"item": {"id": self.type, "data": self.tag_data}}
469
+ _add_slot(formatted_dict, self.slot or slot)
470
+ return formatted_dict
471
+
472
+ def __repr__(self) -> str:
473
+ return f'{self.__class__.__name__}({self.tag_data})'
474
+
475
+
457
476
  def item_from_dict(item_dict: dict, preserve_item_slots: bool) -> Any:
458
477
  item_id = item_dict['item']['id']
459
478
  item_data = item_dict['item']['data']
@@ -507,12 +526,17 @@ def item_from_dict(item_dict: dict, preserve_item_slots: bool) -> Any:
507
526
  param_type = ParameterType(PARAMETER_TYPE_LOOKUP.index(item_data['type']))
508
527
  if item_data['optional']:
509
528
  if 'default_value' in item_data:
510
- default_value_item = item_from_dict(item_data['default_value'], preserve_item_slots)
529
+ default_value_dict = {'item': item_data['default_value'], 'slot': None}
530
+ default_value_item = item_from_dict(default_value_dict, preserve_item_slots)
511
531
  return Parameter(item_data['name'], param_type, item_data['plural'], True, description, note, default_value_item, item_slot)
512
532
  return Parameter(item_data['name'], param_type, item_data['plural'], True, description, note, slot=item_slot)
513
533
  return Parameter(item_data['name'], param_type, item_data['plural'], False, description, note, slot=item_slot)
514
534
 
515
- elif item_id in {'bl_tag', 'hint'}: # Ignore tags and hints
535
+ elif item_id == 'bl_tag':
536
+ if 'variable' in item_data:
537
+ return _Tag(item_data, item_slot)
538
+
539
+ elif item_id == 'hint': # Ignore hints
516
540
  return
517
541
 
518
542
  else:
dfpyre/pyre.py CHANGED
@@ -16,7 +16,7 @@ from dfpyre.actiondump import CODEBLOCK_DATA, get_default_tags
16
16
  from dfpyre.action_literals import *
17
17
 
18
18
 
19
- VARIABLE_TYPES = {'txt', 'comp', 'num', 'item', 'loc', 'var', 'snd', 'part', 'pot', 'g_val', 'vec', 'pn_el'}
19
+ VARIABLE_TYPES = {'txt', 'comp', 'num', 'item', 'loc', 'var', 'snd', 'part', 'pot', 'g_val', 'vec', 'pn_el', 'bl_tag'}
20
20
  TEMPLATE_STARTERS = {'event', 'entity_event', 'func', 'process'}
21
21
  DYNAMIC_CODEBLOCKS = {'func', 'process', 'call_func', 'start_process'}
22
22
 
@@ -118,13 +118,20 @@ class CodeBlock:
118
118
 
119
119
  # add items into args
120
120
  final_args = [arg.format(slot) for slot, arg in enumerate(self.args) if arg.type in VARIABLE_TYPES]
121
+ already_applied_tags: dict[str, dict] = {a['item']['data']['tag']: a for a in final_args if a['item']['id'] == 'bl_tag'}
121
122
 
122
123
  # check for unrecognized name, add tags
123
124
  if self.type not in {'bracket', 'else'}:
124
125
  if self.action_name not in CODEBLOCK_DATA[self.type]:
125
126
  _warn_unrecognized_name(self.type, self.action_name)
127
+
126
128
  elif include_tags:
127
129
  tags = _get_codeblock_tags(self.type, self.action_name, self.tags)
130
+ for i, tag_data in enumerate(tags):
131
+ already_applied_tag_data = already_applied_tags.get(tag_data['item']['data']['tag'])
132
+ if already_applied_tag_data is not None:
133
+ tags[i] = already_applied_tag_data
134
+
128
135
  if len(final_args) + len(tags) > 27:
129
136
  final_args = final_args[:(27-len(tags))] # trim list if over 27 elements
130
137
  final_args.extend(tags) # add tags to end
@@ -160,7 +167,7 @@ def _check_applied_tags(tags: list[dict], applied_tags: dict[str, str], codebloc
160
167
  return valid_tags
161
168
 
162
169
 
163
- def _reformat_codeblock_tags(tags: list[dict], codeblock_type: str, codeblock_action: str, applied_tags: dict[str, str]):
170
+ def _reformat_codeblock_tags(tags: list[dict], codeblock_type: str, codeblock_action: str, applied_tags: dict[str, str]) -> list[dict]:
164
171
  """
165
172
  Turns tag objects into DiamondFire formatted tag items.
166
173
  """
@@ -187,7 +194,7 @@ def _reformat_codeblock_tags(tags: list[dict], codeblock_type: str, codeblock_ac
187
194
  return reformatted_tags
188
195
 
189
196
 
190
- def _get_codeblock_tags(codeblock_type: str, codeblock_name: str, applied_tags: dict[str, str]):
197
+ def _get_codeblock_tags(codeblock_type: str, codeblock_name: str, applied_tags: dict[str, str]) -> list[dict]:
191
198
  """
192
199
  Get tags for the specified codeblock type and name.
193
200
  """
@@ -244,7 +251,7 @@ class DFTemplate:
244
251
 
245
252
 
246
253
  @staticmethod
247
- def from_code(template_code: str, preserve_item_slots: bool=False):
254
+ def from_code(template_code: str, preserve_item_slots: bool=True):
248
255
  """
249
256
  Create a template object from an existing template code.
250
257
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dfpyre
3
- Version: 0.8.11
3
+ Version: 0.8.13
4
4
  Summary: A package for creating and modifying code templates for the DiamondFire Minecraft server.
5
5
  Home-page: https://github.com/Amp63/pyre
6
6
  License: MIT
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
- Requires-Dist: mcitemlib (>=0.4.2,<0.5.0)
15
+ Requires-Dist: mcitemlib (>=0.4.3,<0.5.0)
16
16
  Project-URL: Repository, https://github.com/Amp63/pyre
17
17
  Description-Content-Type: text/markdown
18
18
 
@@ -2,12 +2,12 @@ dfpyre/__init__.py,sha256=apPsSxJ1Tztfl71MoORoSmDfX7LyKLYlLwOGeLQUitw,25
2
2
  dfpyre/action_literals.py,sha256=bwdLVDi2sU_4HUmvyOJtCguPOWJga_fQTPLtzPm4Mr4,52084
3
3
  dfpyre/actiondump.py,sha256=zsdvsfVk2eZ3-O_G_azB4SDsFWMRkuzkNf-gqUfOsYc,3401
4
4
  dfpyre/data/actiondump_min.json,sha256=a7Wvc_qBuzv-C_puidQ0vq7pYeM1oojeAimYpVykP_o,2478020
5
- dfpyre/items.py,sha256=UejWtUI7Enh3K_IS0XrrSAIlrDMHILXhnxBX_8-oF_k,16727
6
- dfpyre/pyre.py,sha256=-KFBI7DBG43EQnZVmc7oxuGbDw4JPVJih4NY6QncL5I,24981
5
+ dfpyre/items.py,sha256=GOUogkwm7TzgC4AmRem623BtGggxtFcgD2uTporNDgs,17409
6
+ dfpyre/pyre.py,sha256=iP7D8Bt36vRZp_gd_M7IgViWYHzSDdh2fT_sDLrAMso,25454
7
7
  dfpyre/scriptgen.py,sha256=uCG32PlOdcJJBBKn91458eMgP_Ml4K4-n2Fk3LN0T4g,8054
8
8
  dfpyre/style.py,sha256=mLW1CFvvi8_9fk8JaH10I5S4WI0YBdQIXHtI3G_4sR8,980
9
9
  dfpyre/util.py,sha256=Jt-gJjbBWvv2Q2HFxU09OUeLje2OZbB3nAvs87IuHqQ,807
10
- dfpyre-0.8.11.dist-info/LICENSE,sha256=_vuDskB0ja2c-Fgm7Gt8Q8cO9NsLNpZAVyvmZwX7E6o,1060
11
- dfpyre-0.8.11.dist-info/METADATA,sha256=LEApaIVksI6mxETBM3YkdAkDakaoFJZW028yp2Zlmyw,11949
12
- dfpyre-0.8.11.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
- dfpyre-0.8.11.dist-info/RECORD,,
10
+ dfpyre-0.8.13.dist-info/LICENSE,sha256=_vuDskB0ja2c-Fgm7Gt8Q8cO9NsLNpZAVyvmZwX7E6o,1060
11
+ dfpyre-0.8.13.dist-info/METADATA,sha256=bxATIPmf0x6MjjFgj_zQqmFTVq1rXotLQx8S22Eo1qs,11949
12
+ dfpyre-0.8.13.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
+ dfpyre-0.8.13.dist-info/RECORD,,