dfpyre 0.3.1__tar.gz → 0.3.3__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dfpyre
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: A package for externally creating code templates for the DiamondFire Minecraft server.
5
5
  Home-page: https://github.com/Amp63/pyre
6
6
  Author: Amp
@@ -20,7 +20,7 @@ COL_RESET = '\x1b[0m'
20
20
  COL_SUCCESS = '\x1b[32m'
21
21
  COL_ERROR = '\x1b[31m'
22
22
 
23
- CODEBLOCK_DATA_PATH = 'dfpyre/data/data.json'
23
+ CODEBLOCK_DATA_PATH = os.path.join(os.path.dirname(__file__), 'data/data.json')
24
24
 
25
25
  VARIABLE_TYPES = {'txt', 'num', 'item', 'loc', 'var', 'snd', 'part', 'pot', 'g_val', 'vec'}
26
26
  TEMPLATE_STARTERS = {'event', 'entity_event', 'func', 'process'}
@@ -46,16 +46,39 @@ def _loadCodeblockData():
46
46
 
47
47
  TAGDATA, TAGDATA_KEYS, TAGDATA_EXTRAS_KEYS = _loadCodeblockData()
48
48
 
49
- def sendToDf(templateCode: str, name: str='Unnamed Template'):
49
+ def sendToDf(templateCode: str, name: str='Unnamed Template', author: str='pyre'):
50
50
  """
51
51
  Sends a template to DiamondFire via recode item api.
52
52
 
53
- :param str templateCode: The code for the template in base64 format.
53
+ :param str templateCode: The code for the template as a base64 string.
54
54
  :param str name: The name of the template.
55
+ :param str author: The author of this template.
55
56
  """
57
+ templateData = f"""{{\
58
+ Count:1b,\
59
+ id:"minecraft:yellow_shulker_box",\
60
+ tag:{{\
61
+ display:{{\
62
+ Name:'{{"extra":[{{"italic":false,"color":"#FF5C00","text":">> "}},{{"italic":false,"color":"#FFC700","text":"{name}"}}],"text":""}}',\
63
+ Lore:[
64
+ '{{"extra":[{{"italic":false,"color":"gray","text":"This template was generated by "}},{{"italic":false,"color":"gold","text":"pyre"}},{{"italic":false,"color":"gray","text":"."}}],"text":""}}',\
65
+ '{{"extra":[{{"italic":false,"color":"gray","text":"https://github.com/Amp63/pyre"}},{{"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"gray","text":""}}],"text":""}}'\
66
+ ]\
67
+ }},\
68
+ PublicBukkitValues:{{\
69
+ "hypercube:codetemplatedata":'{{\
70
+ "author":"{author}",\
71
+ "name":"{name}",\
72
+ "version":1,\
73
+ "code":"{templateCode}"\
74
+ }}'\
75
+ }}\
76
+ }}\
77
+ }}\
78
+ """
56
79
  itemName = 'pyre Template - ' + name
57
- templateData = f"{{\"name\":\"{itemName}\",\"data\":\"{templateCode}\"}}"
58
- data = {"type": "template", "source": f"pyre - {name}","data": templateData}
80
+ data = {'type': 'nbt', 'source': itemName, 'data': templateData}
81
+
59
82
  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
60
83
  try:
61
84
  s.connect(('127.0.0.1', 31372))
@@ -64,7 +87,7 @@ def sendToDf(templateCode: str, name: str='Unnamed Template'):
64
87
  s.close()
65
88
  return
66
89
 
67
- s.send((str(data) + '\n').encode())
90
+ s.send((str(data) + '\n').encode('utf_8'))
68
91
  received = json.loads(s.recv(1024).decode())
69
92
  status = received['status']
70
93
  if status == 'success':
@@ -72,18 +95,28 @@ def sendToDf(templateCode: str, name: str='Unnamed Template'):
72
95
  else:
73
96
  error = received['error']
74
97
  print(f'{COL_ERROR}Error sending template: {error}{COL_RESET}')
98
+
75
99
  s.close()
76
100
  time.sleep(0.5)
77
101
 
78
102
 
103
+ class CodeBlock:
104
+ def __init__(self, name: str, *args, target: str='Default', data={}):
105
+ self.name = name
106
+ self.args = args
107
+ self.target = target
108
+ self.data = data
109
+
110
+
79
111
  class DFTemplate:
80
112
  """
81
113
  Represents a DiamondFire code template.
82
114
  """
83
- def __init__(self):
84
- self.commands = []
115
+ def __init__(self, name=None):
116
+ self.codeBlocks = []
85
117
  self.closebracket = None
86
118
  self.definedVars = {}
119
+ self.name = name
87
120
 
88
121
 
89
122
  def build(self) -> Tuple[str, str]:
@@ -93,7 +126,7 @@ class DFTemplate:
93
126
  :return: Tuple containing compressed template code and template name.
94
127
  """
95
128
  mainDict = {'blocks': []}
96
- for cmd in self.commands:
129
+ for cmd in self.codeBlocks:
97
130
  block = {'args': {'items': []}}
98
131
 
99
132
  # add keys from cmd.data
@@ -101,7 +134,7 @@ class DFTemplate:
101
134
  block[key] = cmd.data[key]
102
135
 
103
136
  # bracket data
104
- if cmd.data.get('direct') != None:
137
+ if cmd.data.get('direct') is not None:
105
138
  block['direct'] = cmd.data['direct']
106
139
  block['type'] = cmd.data['type']
107
140
 
@@ -146,8 +179,10 @@ class DFTemplate:
146
179
  print(f'{COL_SUCCESS}Template built successfully.{COL_RESET}')
147
180
 
148
181
  templateName = 'Unnamed'
149
- if not mainDict['blocks'][0]['block'] in TEMPLATE_STARTERS:
182
+ if mainDict['blocks'][0]['block'] not in TEMPLATE_STARTERS:
150
183
  _warn('Template does not start with an event, function, or process.')
184
+ elif self.name is not None:
185
+ templateName = self.name
151
186
  else:
152
187
  try:
153
188
  templateName = mainDict['blocks'][0]['block'] + '_' + mainDict['blocks'][0]['action']
@@ -194,29 +229,29 @@ class DFTemplate:
194
229
 
195
230
  def _openbracket(self, btype: str='norm'):
196
231
  bracket = CodeBlock('Bracket', data={'id': 'bracket', 'direct': 'open', 'type': btype})
197
- self.commands.append(bracket)
232
+ self.codeBlocks.append(bracket)
198
233
  self.closebracket = btype
199
234
 
200
235
 
201
236
  # command methods
202
237
  def playerEvent(self, name: str):
203
238
  cmd = CodeBlock(name, data={'id': 'block', 'block': 'event', 'action': name})
204
- self.commands.append(cmd)
239
+ self.codeBlocks.append(cmd)
205
240
 
206
241
 
207
242
  def entityEvent(self, name: str):
208
243
  cmd = CodeBlock(name, data={'id': 'block', 'block': 'entity_event', 'action': name})
209
- self.commands.append(cmd)
244
+ self.codeBlocks.append(cmd)
210
245
 
211
246
 
212
247
  def function(self, name: str):
213
248
  cmd = CodeBlock('function', data={'id': 'block', 'block': 'func', 'data': name})
214
- self.commands.append(cmd)
249
+ self.codeBlocks.append(cmd)
215
250
 
216
251
 
217
252
  def process(self, name: str):
218
253
  cmd = CodeBlock('process', data={'id': 'block', 'block': 'process', 'data': name})
219
- self.commands.append(cmd)
254
+ self.codeBlocks.append(cmd)
220
255
 
221
256
 
222
257
  def callFunction(self, name: str, parameters={}):
@@ -225,63 +260,63 @@ class DFTemplate:
225
260
  self.setVariable('=', var(key, scope='local'), parameters[key])
226
261
 
227
262
  cmd = CodeBlock('call_func', data={'id': 'block', 'block': 'call_func', 'data': name})
228
- self.commands.append(cmd)
263
+ self.codeBlocks.append(cmd)
229
264
 
230
265
 
231
266
  def startProcess(self, name: str):
232
267
  cmd = CodeBlock('start_process', data={'id': 'block', 'block': 'start_process', 'data': name})
233
- self.commands.append(cmd)
268
+ self.codeBlocks.append(cmd)
234
269
 
235
270
 
236
271
  def playerAction(self, name: str, *args, target: str='Default'):
237
272
  args = self._convertDataTypes(args)
238
273
  cmd = CodeBlock(name, args, target=target, data={'id': 'block', 'block': 'player_action', 'action': name})
239
- self.commands.append(cmd)
274
+ self.codeBlocks.append(cmd)
240
275
 
241
276
 
242
277
  def gameAction(self, name: str, *args):
243
278
  args = self._convertDataTypes(args)
244
279
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'game_action', 'action': name})
245
- self.commands.append(cmd)
280
+ self.codeBlocks.append(cmd)
246
281
 
247
282
 
248
283
  def entityAction(self, name: str, *args):
249
284
  args = self._convertDataTypes(args)
250
285
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'entity_action', 'action': name})
251
- self.commands.append(cmd)
286
+ self.codeBlocks.append(cmd)
252
287
 
253
288
 
254
289
  def ifPlayer(self, name: str, *args, target: str='Default'):
255
290
  args = self._convertDataTypes(args)
256
291
  cmd = CodeBlock(name, args, target=target, data={'id': 'block', 'block': 'if_player', 'action': name})
257
- self.commands.append(cmd)
292
+ self.codeBlocks.append(cmd)
258
293
  self._openbracket()
259
294
 
260
295
 
261
296
  def ifVariable(self, name: str, *args):
262
297
  args = self._convertDataTypes(args)
263
298
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'if_var', 'action': name})
264
- self.commands.append(cmd)
299
+ self.codeBlocks.append(cmd)
265
300
  self._openbracket()
266
301
 
267
302
 
268
303
  def ifGame(self, name: str, *args):
269
304
  args = self._convertDataTypes(args)
270
305
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'if_game', 'action': name})
271
- self.commands.append(cmd)
306
+ self.codeBlocks.append(cmd)
272
307
  self._openbracket()
273
308
 
274
309
 
275
310
  def ifEntity(self, name: str, *args):
276
311
  args = self._convertDataTypes(args)
277
312
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'if_entity', 'action': name})
278
- self.commands.append(cmd)
313
+ self.codeBlocks.append(cmd)
279
314
  self._openbracket()
280
315
 
281
316
 
282
317
  def else_(self):
283
318
  cmd = CodeBlock('else', data={'id': 'block', 'block': 'else'})
284
- self.commands.append(cmd)
319
+ self.codeBlocks.append(cmd)
285
320
  self._openbracket()
286
321
 
287
322
 
@@ -291,35 +326,34 @@ class DFTemplate:
291
326
  if subAction is not None:
292
327
  data['subAction'] = subAction
293
328
  cmd = CodeBlock(name, args, data=data)
294
- self.commands.append(cmd)
329
+ self.codeBlocks.append(cmd)
295
330
  self._openbracket('repeat')
296
331
 
297
332
 
298
333
  def bracket(self, *args):
299
334
  args = self._convertDataTypes(args)
300
335
  cmd = CodeBlock('Bracket', data={'id': 'bracket', 'direct': 'close', 'type': self.closebracket})
301
- self.commands.append(cmd)
336
+ self.codeBlocks.append(cmd)
302
337
 
303
338
 
304
339
  def control(self, name: str, *args):
305
340
  args = self._convertDataTypes(args)
306
341
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'control', 'action': name})
307
- self.commands.append(cmd)
342
+ self.codeBlocks.append(cmd)
308
343
 
309
344
 
310
345
  def selectObject(self, name: str, *args):
311
346
  args = self._convertDataTypes(args)
312
347
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'select_obj', 'action': name})
313
- self.commands.append(cmd)
348
+ self.codeBlocks.append(cmd)
314
349
 
315
350
 
316
351
  def setVariable(self, name: str, *args):
317
352
  args = self._convertDataTypes(args)
318
353
  cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'set_var', 'action': name})
319
- self.commands.append(cmd)
354
+ self.codeBlocks.append(cmd)
320
355
 
321
356
 
322
- # extra methods
323
357
  def return_(self, returndata={}):
324
358
  for key in returndata:
325
359
  self.setVariable('=', var(key, scope='local'), returndata[key])
@@ -329,12 +363,4 @@ class DFTemplate:
329
363
  def define_(self, name: str, value=0, scope: str='unsaved', createSetVar: bool=True):
330
364
  if createSetVar:
331
365
  self.setVariable('=', var(name, scope=scope), value)
332
- self.definedVars[name] = var(name, scope=scope)
333
-
334
-
335
- class CodeBlock:
336
- def __init__(self, name: str, *args, target: str='Default', data={}):
337
- self.name = name
338
- self.args = args
339
- self.target = target
340
- self.data = data
366
+ self.definedVars[name] = var(name, scope=scope)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dfpyre
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: A package for externally creating code templates for the DiamondFire Minecraft server.
5
5
  Home-page: https://github.com/Amp63/pyre
6
6
  Author: Amp
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='dfpyre',
5
- version='0.3.1',
5
+ version='0.3.3',
6
6
  description='A package for externally creating code templates for the DiamondFire Minecraft server.',
7
7
  author='Amp',
8
8
  url='https://github.com/Amp63/pyre',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes