dfpyre 0.4.6__py3-none-any.whl → 0.5.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/pyre.py CHANGED
@@ -7,9 +7,6 @@ By Amp
7
7
 
8
8
  import base64
9
9
  import gzip
10
- import socket
11
- import websocket
12
- import time
13
10
  import json
14
11
  import os
15
12
  from difflib import get_close_matches
@@ -51,7 +48,7 @@ class Target(Enum):
51
48
  ALL_MOBS = 9
52
49
  LAST_ENTITY = 10
53
50
 
54
- def getStringValue(self):
51
+ def get_string_value(self):
55
52
  return TARGETS[self.value]
56
53
 
57
54
  DEFAULT_TARGET = Target.SELECTION
@@ -69,35 +66,35 @@ def _warn(message):
69
66
  print(f'{COL_WARN}! WARNING ! {message}{COL_RESET}')
70
67
 
71
68
 
72
- def _warnUnrecognizedName(codeblockType: str, codeblockName: str):
73
- close = get_close_matches(codeblockName, TAGDATA[codeblockType].keys())
69
+ def _warn_unrecognized_name(codeblock_type: str, codeblock_name: str):
70
+ close = get_close_matches(codeblock_name, TAGDATA[codeblock_type].keys())
74
71
  if close:
75
- _warn(f'Code block name "{codeblockName}" not recognized. Did you mean "{close[0]}"?')
72
+ _warn(f'Code block name "{codeblock_name}" not recognized. Did you mean "{close[0]}"?')
76
73
  else:
77
- _warn(f'Code block name "{codeblockName}" not recognized. Try spell checking or retyping without spaces.')
74
+ _warn(f'Code block name "{codeblock_name}" not recognized. Try spell checking or retyping without spaces.')
78
75
 
79
76
 
80
- def _loadCodeblockData() -> Tuple:
81
- tagData = {}
77
+ def _load_codeblock_data() -> Tuple:
78
+ tag_data = {}
82
79
  if os.path.exists(CODEBLOCK_DATA_PATH):
83
80
  with open(CODEBLOCK_DATA_PATH, 'r') as f:
84
- tagData = json.load(f)
81
+ tag_data = json.load(f)
85
82
  else:
86
83
  _warn('data.json not found -- Item tags and error checking will not work.')
87
84
  return ({}, set(), set())
88
85
 
89
- del tagData['meta']
86
+ del tag_data['meta']
90
87
 
91
- allNames = [x for l in [d.keys() for d in tagData.values()] for x in l] # flatten list
88
+ all_names = [x for l in [d.keys() for d in tag_data.values()] for x in l] # flatten list
92
89
  return (
93
- tagData,
94
- set(tagData['extras'].keys()),
95
- set(allNames)
90
+ tag_data,
91
+ set(tag_data['extras'].keys()),
92
+ set(all_names)
96
93
  )
97
94
 
98
- TAGDATA, TAGDATA_EXTRAS_KEYS, ALL_CODEBLOCK_NAMES = _loadCodeblockData()
95
+ TAGDATA, TAGDATA_EXTRAS_KEYS, ALL_CODEBLOCK_NAMES = _load_codeblock_data()
99
96
 
100
- def _addInverted(data, inverted):
97
+ def _add_inverted(data, inverted):
101
98
  """
102
99
  If inverted is true, add 'inverted': 'NOT' to data.
103
100
  """
@@ -105,86 +102,86 @@ def _addInverted(data, inverted):
105
102
  data['inverted'] = 'NOT'
106
103
 
107
104
 
108
- def _convertDataTypes(args):
109
- convertedArgs = []
105
+ def _convert_data_types(args):
106
+ converted_args = []
110
107
  for value in args:
111
108
  if type(value) in {int, float}:
112
- convertedArgs.append(num(value))
109
+ converted_args.append(num(value))
113
110
  elif type(value) is str:
114
111
  if value[0] == VAR_SHORTHAND_CHAR and value[1] in VAR_SCOPES:
115
- varObject = var(value[2:], VAR_SCOPES[value[1]])
116
- convertedArgs.append(varObject)
112
+ var_object = var(value[2:], VAR_SCOPES[value[1]])
113
+ converted_args.append(var_object)
117
114
  else:
118
- convertedArgs.append(text(value))
115
+ converted_args.append(text(value))
119
116
  else:
120
- convertedArgs.append(value)
121
- return tuple(convertedArgs)
117
+ converted_args.append(value)
118
+ return tuple(converted_args)
122
119
 
123
120
 
124
- def _reformatCodeblockTags(tags, codeblockType: str, codeblockName: str):
121
+ def _reformat_codeblock_tags(tags, codeblock_type: str, codeblock_name: str):
125
122
  """
126
123
  Turns data.json tag items into DiamondFire formatted tag items
127
124
  """
128
- reformattedTags = []
129
- for tagItem in tags:
130
- actionValue = codeblockName if 'action' not in tagItem else tagItem['action']
131
- newTagItem = {
125
+ reformatted_tags = []
126
+ for tag_item in tags:
127
+ action_value = codeblock_name if 'action' not in tag_item else tag_item['action']
128
+ new_tag_item = {
132
129
  'item': {
133
130
  'id': 'bl_tag',
134
131
  'data': {
135
- 'option': tagItem['option'],
136
- 'tag': tagItem['tag'],
137
- 'action': actionValue,
138
- 'block': codeblockType
132
+ 'option': tag_item['option'],
133
+ 'tag': tag_item['tag'],
134
+ 'action': action_value,
135
+ 'block': codeblock_type
139
136
  }
140
137
  },
141
- 'slot': tagItem['slot']
138
+ 'slot': tag_item['slot']
142
139
  }
143
- reformattedTags.append(newTagItem)
144
- return reformattedTags
140
+ reformatted_tags.append(new_tag_item)
141
+ return reformatted_tags
145
142
 
146
143
 
147
- def _getCodeblockTags(codeblockType: str, codeblockName: str):
144
+ def _get_codeblock_tags(codeblock_type: str, codeblock_name: str):
148
145
  """
149
146
  Get tags for the specified codeblock type and name
150
147
  """
151
148
  tags = None
152
- if codeblockType in TAGDATA_EXTRAS_KEYS:
153
- tags = TAGDATA['extras'][codeblockType]
149
+ if codeblock_type in TAGDATA_EXTRAS_KEYS:
150
+ tags = TAGDATA['extras'][codeblock_type]
154
151
  else:
155
- tags = TAGDATA[codeblockType].get(codeblockName)
156
- return _reformatCodeblockTags(tags, codeblockType, codeblockName)
152
+ tags = TAGDATA[codeblock_type].get(codeblock_name)
153
+ return _reformat_codeblock_tags(tags, codeblock_type, codeblock_name)
157
154
 
158
155
 
159
- def _buildBlock(codeblock: CodeBlock, includeTags: bool):
156
+ def _build_block(codeblock: CodeBlock, include_tags: bool):
160
157
  """
161
158
  Builds a properly formatted block from a CodeBlock object.
162
159
  """
163
- finalBlock = codeblock.data.copy()
164
- codeblockType = codeblock.data.get('block')
160
+ final_block = codeblock.data.copy()
161
+ codeblock_type = codeblock.data.get('block')
165
162
 
166
163
  # add target if necessary ('Selection' is the default when 'target' is blank)
167
- if codeblockType in TARGET_CODEBLOCKS and codeblock.target != DEFAULT_TARGET:
168
- finalBlock['target'] = codeblock.target.getStringValue()
164
+ if codeblock_type in TARGET_CODEBLOCKS and codeblock.target != DEFAULT_TARGET:
165
+ final_block['target'] = codeblock.target.get_string_value()
169
166
 
170
167
  # add items into args
171
- finalArgs = [arg.format(slot) for slot, arg in enumerate(codeblock.args) if arg.type in VARIABLE_TYPES]
168
+ final_args = [arg.format(slot) for slot, arg in enumerate(codeblock.args) if arg.type in VARIABLE_TYPES]
172
169
 
173
170
  # check for unrecognized name, add tags
174
- if codeblockType is not None: # for brackets
175
- if codeblockType not in TAGDATA_EXTRAS_KEYS and codeblock.name not in ALL_CODEBLOCK_NAMES:
176
- _warnUnrecognizedName(codeblockType, codeblock.name)
177
- elif includeTags:
178
- tags = _getCodeblockTags(codeblockType, codeblock.name)
179
- if len(finalArgs) + len(tags) > 27:
180
- finalArgs = finalArgs[:(27-len(tags))] # trim list if over 27 elements
181
- finalArgs.extend(tags) # add tags to end
171
+ if codeblock_type is not None: # for brackets
172
+ if codeblock_type not in TAGDATA_EXTRAS_KEYS and codeblock.name not in ALL_CODEBLOCK_NAMES:
173
+ _warn_unrecognized_name(codeblock_type, codeblock.name)
174
+ elif include_tags:
175
+ tags = _get_codeblock_tags(codeblock_type, codeblock.name)
176
+ if len(final_args) + len(tags) > 27:
177
+ final_args = final_args[:(27-len(tags))] # trim list if over 27 elements
178
+ final_args.extend(tags) # add tags to end
182
179
 
183
- finalBlock['args'] = {'items': finalArgs}
184
- return finalBlock
180
+ final_block['args'] = {'items': final_args}
181
+ return final_block
185
182
 
186
183
 
187
- def _dfEncode(jsonString: str) -> str:
184
+ def _df_encode(jsonString: str) -> str:
188
185
  """
189
186
  Encodes a stringified json.
190
187
  """
@@ -192,12 +189,12 @@ def _dfEncode(jsonString: str) -> str:
192
189
  return base64.b64encode(encodedString).decode('utf-8')
193
190
 
194
191
 
195
- def getTemplateItem(templateCode: str, name: str, author: str) -> NbtItem:
192
+ def _get_template_item(template_code: str, name: str, author: str) -> NbtItem:
196
193
  now = datetime.datetime.now()
197
194
 
198
- templateItem = NbtItem('yellow_shulker_box')
199
- templateItem.set_name(f'&x&f&f&5&c&0&0>> &x&f&f&c&7&0&0{name}')
200
- templateItem.set_lore([
195
+ template_item = NbtItem('yellow_shulker_box')
196
+ template_item.set_name(f'&x&f&f&5&c&0&0>> &x&f&f&c&7&0&0{name}')
197
+ template_item.set_lore([
201
198
  f'&8Author: {author}',
202
199
  f'&8Date: {now.strftime("%Y-%m-%d")}',
203
200
  '',
@@ -205,81 +202,13 @@ def getTemplateItem(templateCode: str, name: str, author: str) -> NbtItem:
205
202
  '&7https://github.com/Amp63/pyre'
206
203
  ])
207
204
 
208
- pbvTag = {
209
- 'hypercube:codetemplatedata': f'{{"author":"{author}","name":"{name}","version": 1,"code":"{templateCode}"}}',
205
+ pbv_tag = {
206
+ 'hypercube:codetemplatedata': f'{{"author":"{author}","name":"{name}","version": 1,"code":"{template_code}"}}',
210
207
  'hypercube:pyre_creation_timestamp': now.timestamp()
211
208
  }
212
- templateItem.set_tag('PublicBukkitValues', pbvTag, raw=True)
209
+ template_item.set_tag('PublicBukkitValues', pbv_tag, raw=True)
213
210
 
214
- return templateItem
215
-
216
-
217
- def sendRecode(templateCode: str, name: str='Unnamed Template', author: str='pyre') -> int:
218
- """
219
- Sends a template to DiamondFire via recode item api.
220
-
221
- :param str templateCode: The code for the template as a base64 string.
222
- :param str name: The name of the template.
223
- :param str author: The author of the template.
224
-
225
- :return: status code
226
- - `0` = Success
227
- - `1` = Connection refused
228
- - `2` = Other socket error
229
- """
230
-
231
- templateItem = getTemplateItem(templateCode, name, author)
232
- data = {'type': 'nbt', 'source': f'pyre Template - {name}', 'data': templateItem.get_nbt()}
233
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
234
- try:
235
- s.connect(('127.0.0.1', 31372))
236
- except ConnectionRefusedError:
237
- print(f"""{COL_ERROR}Could not connect to recode item API. Possible problems:
238
- - Minecraft is not open
239
- - Recode is not installed (get it here: https://modrinth.com/mod/recode or join the discord here: https://discord.gg/GWxWtcwA2C){COL_RESET}""")
240
- s.close()
241
- return 1
242
-
243
- s.send((str(data) + '\n').encode('utf-8'))
244
- received = json.loads(s.recv(1024).decode())
245
- status = received['status']
246
- s.close()
247
- time.sleep(0.5)
248
-
249
- if status == 'success':
250
- print(f'{COL_SUCCESS}Template sent to client successfully.{COL_RESET}')
251
- return 0
252
- error = received['error']
253
- print(f'{COL_ERROR}Error sending template: {error}{COL_RESET}')
254
- return 2
255
-
256
-
257
- def sendCodeClient(templateCode: str, name: str='Unnamed Template', author: str='pyre') -> int:
258
- try:
259
- ws = websocket.WebSocket()
260
- ws.connect(CODECLIENT_URL)
261
- print(f'{COL_SUCCESS}Connected. {COL_WARN}Please run /auth in game.{COL_RESET}')
262
-
263
- ws.recv() # auth response
264
-
265
- templateItem = getTemplateItem(templateCode, name, author)
266
- command = f'give {templateItem.get_nbt()}'
267
- ws.send(command)
268
- ws.close()
269
-
270
- print(f'{COL_SUCCESS}Template sent to client successfully.{COL_RESET}')
271
- return 0
272
-
273
- except Exception as e:
274
- if isinstance(e, ConnectionRefusedError):
275
- print(f'{COL_ERROR}Could not connect to CodeClient API. Possible problems:')
276
- print(f' - Minecraft is not open')
277
- print(f' - CodeClient is not installed (get it here: https://modrinth.com/mod/codeclient)')
278
- print(f' - CodeClient API is not enabled (enable it in CodeClient general settings)')
279
- return 1
280
-
281
- print(f'Connection failed: {e}')
282
- return 2
211
+ return template_item
283
212
 
284
213
 
285
214
  class DFTemplate:
@@ -287,56 +216,53 @@ class DFTemplate:
287
216
  Represents a DiamondFire code template.
288
217
  """
289
218
  def __init__(self, name: str=None, author: str='pyre'):
290
- self.codeBlocks: List[CodeBlock] = []
219
+ self.codeblocks: List[CodeBlock] = []
291
220
  self.closebracket = None
292
221
  self.name = name
293
222
  self.author = author
294
223
 
295
224
 
296
- def _setTemplateName(self, firstBlock):
225
+ def _set_template_name(self, first_block):
297
226
  if self.name is not None:
298
227
  return
299
- if 'data' in firstBlock:
300
- self.name = firstBlock['data']
228
+ if 'data' in first_block:
229
+ self.name = first_block['data']
301
230
  if not self.name:
302
231
  self.name = 'Unnamed Template'
303
232
  else:
304
- self.name = firstBlock['block'] + '_' + firstBlock['action']
233
+ self.name = first_block['block'] + '_' + first_block['action']
305
234
 
306
235
 
307
- def build(self, includeTags: bool=True) -> str:
236
+ def build(self, include_tags: bool=True) -> str:
308
237
  """
309
238
  Build this template.
310
239
 
311
240
  :param bool includeTags: If True, include item tags in code blocks. Otherwise omit them.
312
241
  :return: String containing encoded template data.
313
242
  """
314
- templateDictBlocks = [_buildBlock(codeblock, includeTags) for codeblock in self.codeBlocks]
315
- templateDict = {'blocks': templateDictBlocks}
316
- firstBlock = templateDictBlocks[0]
317
- if firstBlock['block'] not in TEMPLATE_STARTERS:
243
+ template_dict_blocks = [_build_block(codeblock, include_tags) for codeblock in self.codeblocks]
244
+ template_dict = {'blocks': template_dict_blocks}
245
+ first_block = template_dict_blocks[0]
246
+ if first_block['block'] not in TEMPLATE_STARTERS:
318
247
  _warn('Template does not start with an event, function, or process.')
319
248
 
320
- self._setTemplateName(firstBlock)
249
+ self._set_template_name(first_block)
321
250
 
322
251
  print(f'{COL_SUCCESS}Template built successfully.{COL_RESET}')
323
252
 
324
- jsonString = json.dumps(templateDict, separators=(',', ':'))
325
- return _dfEncode(jsonString)
253
+ json_string = json.dumps(template_dict, separators=(',', ':'))
254
+ return _df_encode(json_string)
326
255
 
327
256
 
328
- def buildAndSend(self, sendMethod: Literal['recode', 'codeclient']='recode', includeTags: bool=True) -> int:
257
+ def build_and_send(self, method: Literal['recode', 'codeclient'], includeTags: bool=True) -> int:
329
258
  """
330
259
  Builds this template and sends it to DiamondFire automatically.
331
260
 
332
261
  :param bool includeTags: If True, include item tags in code blocks. Otherwise omit them.
333
262
  """
334
263
  templateCode = self.build(includeTags)
335
- if sendMethod == 'recode':
336
- return sendRecode(templateCode, name=self.name, author=self.author)
337
- if sendMethod == 'codeclient':
338
- return sendCodeClient(templateCode, name=self.name, author=self.author)
339
- return -1
264
+ templateItem = _get_template_item(templateCode, self.name, self.author)
265
+ return templateItem.send_to_minecraft(method)
340
266
 
341
267
 
342
268
  def clear(self):
@@ -348,132 +274,132 @@ class DFTemplate:
348
274
 
349
275
  def _openbracket(self, btype: Literal['norm', 'repeat']='norm'):
350
276
  bracket = CodeBlock('Bracket', data={'id': 'bracket', 'direct': 'open', 'type': btype})
351
- self.codeBlocks.append(bracket)
277
+ self.codeblocks.append(bracket)
352
278
  self.closebracket = btype
353
279
 
354
280
 
355
281
  # command methods
356
- def playerEvent(self, name: str):
282
+ def player_event(self, name: str):
357
283
  cmd = CodeBlock(name, data={'id': 'block', 'block': 'event', 'action': name})
358
- self.codeBlocks.append(cmd)
284
+ self.codeblocks.append(cmd)
359
285
 
360
286
 
361
- def entityEvent(self, name: str):
287
+ def entity_event(self, name: str):
362
288
  cmd = CodeBlock(name, data={'id': 'block', 'block': 'entity_event', 'action': name})
363
- self.codeBlocks.append(cmd)
289
+ self.codeblocks.append(cmd)
364
290
 
365
291
 
366
292
  def function(self, name: str, *args):
367
- args = _convertDataTypes(args)
293
+ args = _convert_data_types(args)
368
294
  cmd = CodeBlock('function', args, data={'id': 'block', 'block': 'func', 'data': name})
369
- self.codeBlocks.append(cmd)
295
+ self.codeblocks.append(cmd)
370
296
 
371
297
 
372
298
  def process(self, name: str):
373
299
  cmd = CodeBlock('process', data={'id': 'block', 'block': 'process', 'data': name})
374
- self.codeBlocks.append(cmd)
300
+ self.codeblocks.append(cmd)
375
301
 
376
302
 
377
- def callFunction(self, name: str, *args):
378
- args = _convertDataTypes(args)
303
+ def call_function(self, name: str, *args):
304
+ args = _convert_data_types(args)
379
305
  cmd = CodeBlock('call_func', args, data={'id': 'block', 'block': 'call_func', 'data': name})
380
- self.codeBlocks.append(cmd)
306
+ self.codeblocks.append(cmd)
381
307
 
382
308
 
383
- def startProcess(self, name: str):
309
+ def start_process(self, name: str):
384
310
  cmd = CodeBlock('start_process', data={'id': 'block', 'block': 'start_process', 'data': name})
385
- self.codeBlocks.append(cmd)
311
+ self.codeblocks.append(cmd)
386
312
 
387
313
 
388
- def playerAction(self, name: str, *args, target: Target=DEFAULT_TARGET):
389
- args = _convertDataTypes(args)
314
+ def player_action(self, name: str, *args, target: Target=DEFAULT_TARGET):
315
+ args = _convert_data_types(args)
390
316
  cmd = CodeBlock(name, args, target=target, data={'id': 'block', 'block': 'player_action', 'action': name})
391
- self.codeBlocks.append(cmd)
317
+ self.codeblocks.append(cmd)
392
318
 
393
319
 
394
- def gameAction(self, name: str, *args):
395
- args = _convertDataTypes(args)
320
+ def game_action(self, name: str, *args):
321
+ args = _convert_data_types(args)
396
322
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'game_action', 'action': name})
397
- self.codeBlocks.append(cmd)
323
+ self.codeblocks.append(cmd)
398
324
 
399
325
 
400
- def entityAction(self, name: str, *args, target: Target=DEFAULT_TARGET):
401
- args = _convertDataTypes(args)
326
+ def entity_action(self, name: str, *args, target: Target=DEFAULT_TARGET):
327
+ args = _convert_data_types(args)
402
328
  cmd = CodeBlock(name, args, target=target, data={'id': 'block', 'block': 'entity_action', 'action': name})
403
- self.codeBlocks.append(cmd)
329
+ self.codeblocks.append(cmd)
404
330
 
405
331
 
406
- def ifPlayer(self, name: str, *args, target: Target=DEFAULT_TARGET, inverted: bool=False):
407
- args = _convertDataTypes(args)
332
+ def if_player(self, name: str, *args, target: Target=DEFAULT_TARGET, inverted: bool=False):
333
+ args = _convert_data_types(args)
408
334
  data = {'id': 'block', 'block': 'if_player', 'action': name}
409
- _addInverted(data, inverted)
335
+ _add_inverted(data, inverted)
410
336
  cmd = CodeBlock(name, args, target=target, data=data)
411
- self.codeBlocks.append(cmd)
337
+ self.codeblocks.append(cmd)
412
338
  self._openbracket()
413
339
 
414
340
 
415
- def ifVariable(self, name: str, *args, inverted: bool=False):
416
- args = _convertDataTypes(args)
341
+ def if_variable(self, name: str, *args, inverted: bool=False):
342
+ args = _convert_data_types(args)
417
343
  data = {'id': 'block', 'block': 'if_var', 'action': name}
418
- _addInverted(data, inverted)
344
+ _add_inverted(data, inverted)
419
345
  cmd = CodeBlock(name, args, data=data)
420
- self.codeBlocks.append(cmd)
346
+ self.codeblocks.append(cmd)
421
347
  self._openbracket()
422
348
 
423
349
 
424
- def ifGame(self, name: str, *args, inverted: bool=False):
425
- args = _convertDataTypes(args)
350
+ def if_game(self, name: str, *args, inverted: bool=False):
351
+ args = _convert_data_types(args)
426
352
  data = {'id': 'block', 'block': 'if_game', 'action': name}
427
- _addInverted(data, inverted)
353
+ _add_inverted(data, inverted)
428
354
  cmd = CodeBlock(name, args, data=data)
429
- self.codeBlocks.append(cmd)
355
+ self.codeblocks.append(cmd)
430
356
  self._openbracket()
431
357
 
432
358
 
433
- def ifEntity(self, name: str, *args, target: Target=DEFAULT_TARGET, inverted: bool=False):
434
- args = _convertDataTypes(args)
359
+ def if_entity(self, name: str, *args, target: Target=DEFAULT_TARGET, inverted: bool=False):
360
+ args = _convert_data_types(args)
435
361
  data = {'id': 'block', 'block': 'if_entity', 'action': name}
436
- _addInverted(data, inverted)
362
+ _add_inverted(data, inverted)
437
363
  cmd = CodeBlock(name, args, target=target, data=data)
438
- self.codeBlocks.append(cmd)
364
+ self.codeblocks.append(cmd)
439
365
  self._openbracket()
440
366
 
441
367
 
442
368
  def else_(self):
443
369
  cmd = CodeBlock('else', data={'id': 'block', 'block': 'else'})
444
- self.codeBlocks.append(cmd)
370
+ self.codeblocks.append(cmd)
445
371
  self._openbracket()
446
372
 
447
373
 
448
- def repeat(self, name: str, *args, subAction: str=None):
449
- args = _convertDataTypes(args)
374
+ def repeat(self, name: str, *args, sub_action: str=None):
375
+ args = _convert_data_types(args)
450
376
  data = {'id': 'block', 'block': 'repeat', 'action': name}
451
- if subAction is not None:
452
- data['subAction'] = subAction
377
+ if sub_action is not None:
378
+ data['subAction'] = sub_action
453
379
  cmd = CodeBlock(name, args, data=data)
454
- self.codeBlocks.append(cmd)
380
+ self.codeblocks.append(cmd)
455
381
  self._openbracket('repeat')
456
382
 
457
383
 
458
384
  def bracket(self, *args):
459
- args = _convertDataTypes(args)
385
+ args = _convert_data_types(args)
460
386
  cmd = CodeBlock('Bracket', data={'id': 'bracket', 'direct': 'close', 'type': self.closebracket})
461
- self.codeBlocks.append(cmd)
387
+ self.codeblocks.append(cmd)
462
388
 
463
389
 
464
390
  def control(self, name: str, *args):
465
- args = _convertDataTypes(args)
391
+ args = _convert_data_types(args)
466
392
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'control', 'action': name})
467
- self.codeBlocks.append(cmd)
393
+ self.codeblocks.append(cmd)
468
394
 
469
395
 
470
- def selectObject(self, name: str, *args):
471
- args = _convertDataTypes(args)
396
+ def select_object(self, name: str, *args):
397
+ args = _convert_data_types(args)
472
398
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'select_obj', 'action': name})
473
- self.codeBlocks.append(cmd)
399
+ self.codeblocks.append(cmd)
474
400
 
475
401
 
476
- def setVariable(self, name: str, *args):
477
- args = _convertDataTypes(args)
402
+ def set_variable(self, name: str, *args):
403
+ args = _convert_data_types(args)
478
404
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'set_var', 'action': name})
479
- self.codeBlocks.append(cmd)
405
+ self.codeblocks.append(cmd)
dfpyre/style.py CHANGED
@@ -1,22 +1,22 @@
1
1
  import re
2
2
  from mcitemlib.style import STYLE_CODE_REGEX, FORMAT_CODES, StyledString
3
3
 
4
- def isAmpersandCoded(s: str) -> bool:
4
+ def is_ampersand_coded(s: str) -> bool:
5
5
  return bool(re.match(STYLE_CODE_REGEX, s))
6
6
 
7
7
 
8
- def ampersandToMinimessage(ampersand_code: str) -> str:
8
+ def ampersand_to_minimessage(ampersand_code: str) -> str:
9
9
  ampersand_code = ampersand_code.replace('&r', '<reset>') # bad but should work most of the time
10
- styledString = StyledString.from_codes(ampersand_code)
11
- formattedStringList = []
12
- for substring in styledString.substrings:
13
- formattedSubstringList = []
14
- for styleType, value in substring.data.items():
15
- if styleType in FORMAT_CODES.values() and value:
16
- formattedSubstringList.append(f'<{styleType}>')
17
- if styleType == 'color':
18
- formattedSubstringList.append(f'<{value}>')
10
+ styled_string = StyledString.from_codes(ampersand_code)
11
+ formatted_string_list = []
12
+ for substring in styled_string.substrings:
13
+ formatted_substring_list = []
14
+ for style_type, value in substring.data.items():
15
+ if style_type in FORMAT_CODES.values() and value:
16
+ formatted_substring_list.append(f'<{style_type}>')
17
+ if style_type == 'color':
18
+ formatted_substring_list.append(f'<{value}>')
19
19
 
20
- formattedSubstringList.append(substring.data['text'])
21
- formattedStringList.append(''.join(formattedSubstringList))
22
- return ''.join(formattedStringList)
20
+ formatted_substring_list.append(substring.data['text'])
21
+ formatted_string_list.append(''.join(formatted_substring_list))
22
+ return ''.join(formatted_string_list)