dfpyre 0.4.2__py3-none-any.whl → 0.10.5__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/__init__.py +3 -1
- dfpyre/core/actiondump.py +277 -0
- dfpyre/core/codeblock.py +207 -0
- dfpyre/core/items.py +580 -0
- dfpyre/core/template.py +220 -0
- dfpyre/data/actiondump_min.json +1 -0
- dfpyre/data/deprecated_actions.json +172 -0
- dfpyre/data/method_templates/action.txt +5 -0
- dfpyre/data/method_templates/conditional.txt +7 -0
- dfpyre/data/method_templates/event.txt +6 -0
- dfpyre/data/method_templates/notarget_action.txt +5 -0
- dfpyre/data/method_templates/notarget_conditional.txt +6 -0
- dfpyre/data/method_templates/repeat.txt +5 -0
- dfpyre/data/method_templates/repeat_while.txt +9 -0
- dfpyre/data/method_templates/select_obj_subaction.txt +8 -0
- dfpyre/export/action_classes.py +10891 -0
- dfpyre/export/block_functions.py +90 -0
- dfpyre/gen/action_class_data.py +203 -0
- dfpyre/gen/action_literals.py +20 -0
- dfpyre/scripts/action_gen.py +222 -0
- dfpyre/scripts/action_literal_gen.py +43 -0
- dfpyre/tool/scriptgen.py +274 -0
- dfpyre/tool/slice.py +199 -0
- dfpyre/util/style.py +23 -0
- dfpyre/util/util.py +65 -0
- dfpyre-0.10.5.dist-info/METADATA +64 -0
- dfpyre-0.10.5.dist-info/RECORD +29 -0
- {dfpyre-0.4.2.dist-info → dfpyre-0.10.5.dist-info}/WHEEL +1 -2
- {dfpyre-0.4.2.dist-info → dfpyre-0.10.5.dist-info/licenses}/LICENSE +21 -21
- dfpyre/data/data.json +0 -1
- dfpyre/items.py +0 -244
- dfpyre/pyre.py +0 -407
- dfpyre/style.py +0 -21
- dfpyre-0.4.2.dist-info/METADATA +0 -11
- dfpyre-0.4.2.dist-info/RECORD +0 -10
- dfpyre-0.4.2.dist-info/top_level.txt +0 -1
dfpyre/items.py
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Contains class definitions for code items.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from dfpyre.style import isAmpersandCoded, ampersandToMinimessage
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class item:
|
|
9
|
-
def __init__(self, itemID: str, count: int=1):
|
|
10
|
-
self.id = itemID
|
|
11
|
-
self.count = count
|
|
12
|
-
self.type = 'item'
|
|
13
|
-
|
|
14
|
-
def format(self, slot):
|
|
15
|
-
return dict({
|
|
16
|
-
"item": {
|
|
17
|
-
"id": "item",
|
|
18
|
-
"data": {
|
|
19
|
-
"item": f"{{DF_NBT:2586,id:\"{self.id}\",Count:{self.count}b}}"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"slot": slot
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class string:
|
|
27
|
-
def __init__(self, value: str):
|
|
28
|
-
self.value = value
|
|
29
|
-
self.type = 'txt'
|
|
30
|
-
|
|
31
|
-
def format(self, slot: int):
|
|
32
|
-
return {
|
|
33
|
-
"item": {
|
|
34
|
-
"id": "txt",
|
|
35
|
-
"data": {
|
|
36
|
-
"name": self.value
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"slot": slot
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
class text:
|
|
44
|
-
def __init__(self, value: str):
|
|
45
|
-
if isAmpersandCoded(value):
|
|
46
|
-
value = ampersandToMinimessage(value)
|
|
47
|
-
self.value = value
|
|
48
|
-
self.type = 'comp'
|
|
49
|
-
|
|
50
|
-
def format(self, slot: int):
|
|
51
|
-
return {
|
|
52
|
-
"item": {
|
|
53
|
-
"id": "comp",
|
|
54
|
-
"data": {
|
|
55
|
-
"name": self.value
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
"slot": slot
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class num:
|
|
63
|
-
def __init__(self, num: int|float):
|
|
64
|
-
self.value = num
|
|
65
|
-
self.type = 'num'
|
|
66
|
-
|
|
67
|
-
def format(self, slot: int):
|
|
68
|
-
return {
|
|
69
|
-
"item": {
|
|
70
|
-
"id": "num",
|
|
71
|
-
"data": {
|
|
72
|
-
"name": str(self.value)
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
"slot": slot
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
class loc:
|
|
80
|
-
def __init__(self, x: float=0, y: float=0, z: float=0, pitch: float=0, yaw: float=0):
|
|
81
|
-
self.x = float(x)
|
|
82
|
-
self.y = float(y)
|
|
83
|
-
self.z = float(z)
|
|
84
|
-
self.pitch = float(pitch)
|
|
85
|
-
self.yaw = float(yaw)
|
|
86
|
-
self.type = 'loc'
|
|
87
|
-
|
|
88
|
-
def format(self, slot: int):
|
|
89
|
-
return {
|
|
90
|
-
"item": {
|
|
91
|
-
"id": "loc",
|
|
92
|
-
"data": {
|
|
93
|
-
"isBlock": False,
|
|
94
|
-
"loc": {
|
|
95
|
-
"x": self.x,
|
|
96
|
-
"y": self.y,
|
|
97
|
-
"z": self.z,
|
|
98
|
-
"pitch": self.pitch,
|
|
99
|
-
"yaw": self.yaw
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
"slot": slot
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
class var:
|
|
108
|
-
def __init__(self, name: str, scope: str='unsaved'):
|
|
109
|
-
if scope == 'game':
|
|
110
|
-
scope = 'unsaved'
|
|
111
|
-
|
|
112
|
-
self.name = name
|
|
113
|
-
self.scope = scope
|
|
114
|
-
self.type = 'var'
|
|
115
|
-
|
|
116
|
-
def format(self, slot: int):
|
|
117
|
-
return {
|
|
118
|
-
"item": {
|
|
119
|
-
"id": "var",
|
|
120
|
-
"data": {
|
|
121
|
-
"name": self.name,
|
|
122
|
-
"scope": self.scope
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
"slot": slot
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
class sound:
|
|
130
|
-
def __init__(self, name: str, pitch: float=1.0, vol: float=2.0):
|
|
131
|
-
self.name = name
|
|
132
|
-
self.pitch = pitch
|
|
133
|
-
self.vol = vol
|
|
134
|
-
self.type = 'snd'
|
|
135
|
-
|
|
136
|
-
def format(self, slot: int):
|
|
137
|
-
return {
|
|
138
|
-
"item": {
|
|
139
|
-
"id": "snd",
|
|
140
|
-
"data": {
|
|
141
|
-
"sound": self.name,
|
|
142
|
-
"pitch": self.pitch,
|
|
143
|
-
"vol": self.vol
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
"slot": slot
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
class particle:
|
|
151
|
-
def __init__(self, name: str='Cloud', amount: int=1, horizontal: float=0.0, vertical: float=0.0,
|
|
152
|
-
x: float=1.0, y: float=0.0, z: float=0.0, motionVariation: float=100):
|
|
153
|
-
self.name = name
|
|
154
|
-
self.amount = amount
|
|
155
|
-
self.horizontal = horizontal
|
|
156
|
-
self.vertical = vertical
|
|
157
|
-
self.x = x
|
|
158
|
-
self.y = y
|
|
159
|
-
self.z = z
|
|
160
|
-
self.motionVariation = motionVariation
|
|
161
|
-
self.type = 'part'
|
|
162
|
-
|
|
163
|
-
def format(self, slot: int):
|
|
164
|
-
return {
|
|
165
|
-
"item": {
|
|
166
|
-
"id": "part",
|
|
167
|
-
"data": {
|
|
168
|
-
"particle": self.name,
|
|
169
|
-
"cluster": {
|
|
170
|
-
"amount": self.amount,
|
|
171
|
-
"horizontal": self.horizontal,
|
|
172
|
-
"vertical": self.vertical
|
|
173
|
-
},
|
|
174
|
-
"data": {
|
|
175
|
-
"x": self.x,
|
|
176
|
-
"y": self.y,
|
|
177
|
-
"z": self.z,
|
|
178
|
-
"motionVariation": self.motionVariation
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
"slot": slot
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
class potion:
|
|
187
|
-
def __init__(self, name: str, dur: int=1000000, amp: int=0):
|
|
188
|
-
self.name = name
|
|
189
|
-
self.dur = dur
|
|
190
|
-
self.amp = amp
|
|
191
|
-
self.type = 'pot'
|
|
192
|
-
|
|
193
|
-
def format(self, slot: int):
|
|
194
|
-
return {
|
|
195
|
-
"item": {
|
|
196
|
-
"id": "pot",
|
|
197
|
-
"data": {
|
|
198
|
-
"pot": self.name,
|
|
199
|
-
"dur": self.dur,
|
|
200
|
-
"amp": self.amp
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
"slot": slot
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
class gamevalue:
|
|
208
|
-
def __init__(self, name: str, target: str='Default'):
|
|
209
|
-
self.name = name
|
|
210
|
-
self.target = target
|
|
211
|
-
self.type = 'g_val'
|
|
212
|
-
|
|
213
|
-
def format(self, slot: int):
|
|
214
|
-
return {
|
|
215
|
-
"item": {
|
|
216
|
-
"id": "g_val",
|
|
217
|
-
"data": {
|
|
218
|
-
"type": self.name,
|
|
219
|
-
"target": self.target
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
"slot": slot
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
class vector:
|
|
227
|
-
def __init__(self, x: float=0.0, y: float=0.0, z: float=0.0):
|
|
228
|
-
self.x = float(x)
|
|
229
|
-
self.y = float(y)
|
|
230
|
-
self.z = float(z)
|
|
231
|
-
self.type = 'vec'
|
|
232
|
-
|
|
233
|
-
def format(self, slot: int):
|
|
234
|
-
return {
|
|
235
|
-
"item": {
|
|
236
|
-
"id": "vec",
|
|
237
|
-
"data": {
|
|
238
|
-
"x": self.x,
|
|
239
|
-
"y": self.y,
|
|
240
|
-
"z": self.z
|
|
241
|
-
}
|
|
242
|
-
},
|
|
243
|
-
"slot": slot
|
|
244
|
-
}
|
dfpyre/pyre.py
DELETED
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
A package for externally creating code templates for the DiamondFire Minecraft server.
|
|
3
|
-
|
|
4
|
-
By Amp
|
|
5
|
-
12/29/2023
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import base64
|
|
9
|
-
import gzip
|
|
10
|
-
import socket
|
|
11
|
-
import time
|
|
12
|
-
import json
|
|
13
|
-
import os
|
|
14
|
-
from difflib import get_close_matches
|
|
15
|
-
from typing import Tuple
|
|
16
|
-
from mcitemlib.itemlib import Item as NbtItem
|
|
17
|
-
from dfpyre.items import *
|
|
18
|
-
|
|
19
|
-
COL_WARN = '\x1b[33m'
|
|
20
|
-
COL_RESET = '\x1b[0m'
|
|
21
|
-
COL_SUCCESS = '\x1b[32m'
|
|
22
|
-
COL_ERROR = '\x1b[31m'
|
|
23
|
-
|
|
24
|
-
CODEBLOCK_DATA_PATH = os.path.join(os.path.dirname(__file__), 'data/data.json')
|
|
25
|
-
|
|
26
|
-
VARIABLE_TYPES = {'txt', 'comp', 'num', 'item', 'loc', 'var', 'snd', 'part', 'pot', 'g_val', 'vec'}
|
|
27
|
-
TEMPLATE_STARTERS = {'event', 'entity_event', 'func', 'process'}
|
|
28
|
-
|
|
29
|
-
TARGETS = {'Selection', 'Default', 'Killer', 'Damager', 'Shooter', 'Victim', 'AllPlayers', 'Projectile', 'AllEntities', 'AllMobs', 'LastEntity'}
|
|
30
|
-
TARGET_CODEBLOCKS = {'player_action', 'entity_action', 'if_player', 'if_entity'}
|
|
31
|
-
DEFAULT_TARGET = 'Selection' # ironically not 'Default'
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class CodeBlock:
|
|
35
|
-
def __init__(self, name: str, args: Tuple=(), target: str=DEFAULT_TARGET, data={}):
|
|
36
|
-
self.name = name
|
|
37
|
-
self.args = args
|
|
38
|
-
self.target = target
|
|
39
|
-
self.data = data
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def _warn(message):
|
|
43
|
-
print(f'{COL_WARN}! WARNING ! {message}{COL_RESET}')
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def _warnUnrecognizedName(codeblockType: str, codeblockName: str):
|
|
47
|
-
close = get_close_matches(codeblockName, TAGDATA[codeblockType].keys())
|
|
48
|
-
if close:
|
|
49
|
-
_warn(f'Code block name "{codeblockName}" not recognized. Did you mean "{close[0]}"?')
|
|
50
|
-
else:
|
|
51
|
-
_warn(f'Code block name "{codeblockName}" not recognized. Try spell checking or retyping without spaces.')
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _warnUnrecognizedTarget(target: str):
|
|
55
|
-
close = get_close_matches(target, TARGETS)
|
|
56
|
-
if close:
|
|
57
|
-
_warn(f'Target "{target}" not recognized. Did you mean "{close[0]}"?')
|
|
58
|
-
else:
|
|
59
|
-
_warn(f'Target "{target}" not recognized. Try spell checking or retyping without spaces.')
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def _loadCodeblockData() -> Tuple:
|
|
63
|
-
tagData = {}
|
|
64
|
-
if os.path.exists(CODEBLOCK_DATA_PATH):
|
|
65
|
-
with open(CODEBLOCK_DATA_PATH, 'r') as f:
|
|
66
|
-
tagData = json.load(f)
|
|
67
|
-
else:
|
|
68
|
-
_warn('data.json not found -- Item tags and error checking will not work.')
|
|
69
|
-
return ({}, set(), set())
|
|
70
|
-
|
|
71
|
-
del tagData['meta']
|
|
72
|
-
|
|
73
|
-
allNames = [x for l in [d.keys() for d in tagData.values()] for x in l] # flatten list
|
|
74
|
-
return (
|
|
75
|
-
tagData,
|
|
76
|
-
set(tagData['extras'].keys()),
|
|
77
|
-
set(allNames)
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
TAGDATA, TAGDATA_EXTRAS_KEYS, ALL_CODEBLOCK_NAMES = _loadCodeblockData()
|
|
81
|
-
|
|
82
|
-
def _addInverted(data, inverted):
|
|
83
|
-
"""
|
|
84
|
-
If inverted is true, add 'inverted': 'NOT' to data.
|
|
85
|
-
"""
|
|
86
|
-
if inverted:
|
|
87
|
-
data['inverted'] = 'NOT'
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def _convertDataTypes(args):
|
|
91
|
-
convertedArgs = []
|
|
92
|
-
for value in args:
|
|
93
|
-
if type(value) in {int, float}:
|
|
94
|
-
convertedArgs.append(num(value))
|
|
95
|
-
elif type(value) is str:
|
|
96
|
-
convertedArgs.append(text(value))
|
|
97
|
-
else:
|
|
98
|
-
convertedArgs.append(value)
|
|
99
|
-
return tuple(convertedArgs)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def _reformatCodeblockTags(tags, codeblockType: str, codeblockName: str):
|
|
103
|
-
"""
|
|
104
|
-
Turns data.json tag items into DiamondFire formatted tag items
|
|
105
|
-
"""
|
|
106
|
-
reformattedTags = []
|
|
107
|
-
for tagItem in tags:
|
|
108
|
-
newTagItem = {
|
|
109
|
-
'item': {
|
|
110
|
-
'id': 'bl_tag',
|
|
111
|
-
'data': {
|
|
112
|
-
'option': tagItem['option'],
|
|
113
|
-
'tag': tagItem['tag'],
|
|
114
|
-
'action': codeblockName,
|
|
115
|
-
'block': codeblockType
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
'slot': tagItem['slot']
|
|
119
|
-
}
|
|
120
|
-
reformattedTags.append(newTagItem)
|
|
121
|
-
return reformattedTags
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def _getCodeblockTags(codeblockType: str, codeblockName: str):
|
|
125
|
-
"""
|
|
126
|
-
Get tags for the specified codeblock type and name
|
|
127
|
-
"""
|
|
128
|
-
tags = None
|
|
129
|
-
if codeblockType in TAGDATA_EXTRAS_KEYS:
|
|
130
|
-
tags = TAGDATA['extras'][codeblockType]
|
|
131
|
-
else:
|
|
132
|
-
tags = TAGDATA[codeblockType].get(codeblockName)
|
|
133
|
-
return _reformatCodeblockTags(tags, codeblockType, codeblockName)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def _buildBlock(codeblock: CodeBlock, includeTags: bool):
|
|
137
|
-
"""
|
|
138
|
-
Builds a properly formatted block from a CodeBlock object.
|
|
139
|
-
"""
|
|
140
|
-
finalBlock = codeblock.data.copy()
|
|
141
|
-
codeblockType = codeblock.data.get('block')
|
|
142
|
-
|
|
143
|
-
# add target if necessary ('Selection' is the default when 'target' is blank)
|
|
144
|
-
if codeblockType in TARGET_CODEBLOCKS and codeblock.target != DEFAULT_TARGET:
|
|
145
|
-
if codeblock.target not in TARGETS:
|
|
146
|
-
_warnUnrecognizedTarget(codeblock.target)
|
|
147
|
-
else:
|
|
148
|
-
finalBlock['target'] = codeblock.target
|
|
149
|
-
|
|
150
|
-
# add items into args
|
|
151
|
-
finalArgs = [arg.format(slot) for slot, arg in enumerate(codeblock.args) if arg.type in VARIABLE_TYPES]
|
|
152
|
-
|
|
153
|
-
# check for unrecognized name, add tags
|
|
154
|
-
if codeblockType is not None: # for brackets
|
|
155
|
-
if codeblock.name not in ALL_CODEBLOCK_NAMES:
|
|
156
|
-
_warnUnrecognizedName(codeblockType, codeblock.name)
|
|
157
|
-
elif includeTags:
|
|
158
|
-
tags = _getCodeblockTags(codeblockType, codeblock.name)
|
|
159
|
-
if len(finalArgs) + len(tags) > 27:
|
|
160
|
-
finalArgs = finalArgs[:(27-len(tags))] # trim list if over 27 elements
|
|
161
|
-
finalArgs.extend(tags) # add tags to end
|
|
162
|
-
|
|
163
|
-
finalBlock['args'] = {'items': finalArgs}
|
|
164
|
-
return finalBlock
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
def _dfEncode(jsonString: str) -> str:
|
|
168
|
-
"""
|
|
169
|
-
Encodes a stringified json.
|
|
170
|
-
"""
|
|
171
|
-
encodedString = gzip.compress(jsonString.encode('utf-8'))
|
|
172
|
-
return base64.b64encode(encodedString).decode('utf-8')
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
def sendToDf(templateCode: str, name: str='Unnamed Template', author: str='pyre'):
|
|
176
|
-
"""
|
|
177
|
-
Sends a template to DiamondFire via recode item api.
|
|
178
|
-
|
|
179
|
-
:param str templateCode: The code for the template as a base64 string.
|
|
180
|
-
:param str name: The name of the template.
|
|
181
|
-
:param str author: The author of the template.
|
|
182
|
-
"""
|
|
183
|
-
templateItem = NbtItem('yellow_shulker_box')
|
|
184
|
-
templateItem.set_name(f'&x&f&f&5&c&0&0>> &x&f&f&c&7&0&0{name}')
|
|
185
|
-
templateItem.set_lore([
|
|
186
|
-
'&7This template was generated by &6pyre&7.',
|
|
187
|
-
'&7https://github.com/Amp63/pyre'
|
|
188
|
-
])
|
|
189
|
-
templateItem.set_tag('PublicBukkitValues', {'hypercube:codetemplatedata': f'{{"author":"{author}","name":"{name}","version": 1,"code":"{templateCode}"}}'}, raw=True)
|
|
190
|
-
|
|
191
|
-
data = {'type': 'nbt', 'source': f'pyre Template - {name}', 'data': templateItem.get_nbt()}
|
|
192
|
-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
193
|
-
try:
|
|
194
|
-
s.connect(('127.0.0.1', 31372))
|
|
195
|
-
except ConnectionRefusedError:
|
|
196
|
-
print(f"""{COL_ERROR}Could not connect to recode item API. Possible problems:
|
|
197
|
-
- Minecraft is not open
|
|
198
|
-
- Recode is not installed (get it here: https://modrinth.com/mod/recode or join the discord here: https://discord.gg/GWxWtcwA2C){COL_RESET}""")
|
|
199
|
-
s.close()
|
|
200
|
-
return
|
|
201
|
-
|
|
202
|
-
s.send((str(data) + '\n').encode('utf-8'))
|
|
203
|
-
received = json.loads(s.recv(1024).decode())
|
|
204
|
-
status = received['status']
|
|
205
|
-
if status == 'success':
|
|
206
|
-
print(f'{COL_SUCCESS}Template sent to client successfully.{COL_RESET}')
|
|
207
|
-
else:
|
|
208
|
-
error = received['error']
|
|
209
|
-
print(f'{COL_ERROR}Error sending template: {error}{COL_RESET}')
|
|
210
|
-
|
|
211
|
-
s.close()
|
|
212
|
-
time.sleep(0.5)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
class DFTemplate:
|
|
216
|
-
"""
|
|
217
|
-
Represents a DiamondFire code template.
|
|
218
|
-
"""
|
|
219
|
-
def __init__(self, name: str=None):
|
|
220
|
-
self.codeBlocks = []
|
|
221
|
-
self.closebracket = None
|
|
222
|
-
self.name = name
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
def _setTemplateName(self, firstBlock):
|
|
226
|
-
if self.name is not None:
|
|
227
|
-
return
|
|
228
|
-
if 'data' in firstBlock:
|
|
229
|
-
self.name = firstBlock['data']
|
|
230
|
-
else:
|
|
231
|
-
self.name = firstBlock['block'] + '_' + firstBlock['action']
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
def build(self, includeTags: bool=True) -> str:
|
|
235
|
-
"""
|
|
236
|
-
Build this template.
|
|
237
|
-
|
|
238
|
-
:return: String containing encoded template data.
|
|
239
|
-
"""
|
|
240
|
-
templateDictBlocks = [_buildBlock(codeblock, includeTags) for codeblock in self.codeBlocks]
|
|
241
|
-
templateDict = {'blocks': templateDictBlocks}
|
|
242
|
-
firstBlock = templateDictBlocks[0]
|
|
243
|
-
if firstBlock['block'] not in TEMPLATE_STARTERS:
|
|
244
|
-
_warn('Template does not start with an event, function, or process.')
|
|
245
|
-
|
|
246
|
-
self._setTemplateName(firstBlock)
|
|
247
|
-
|
|
248
|
-
print(f'{COL_SUCCESS}Template built successfully.{COL_RESET}')
|
|
249
|
-
|
|
250
|
-
jsonString = json.dumps(templateDict, separators=(',', ':'))
|
|
251
|
-
return _dfEncode(jsonString)
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
def buildAndSend(self, includeTags: bool=True):
|
|
255
|
-
"""
|
|
256
|
-
Builds this template and sends it to DiamondFire automatically.
|
|
257
|
-
"""
|
|
258
|
-
templateCode = self.build(includeTags)
|
|
259
|
-
sendToDf(templateCode, name=self.name)
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
def clear(self):
|
|
263
|
-
"""
|
|
264
|
-
Clears this template's data.
|
|
265
|
-
"""
|
|
266
|
-
self.__init__()
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
def _openbracket(self, btype: str='norm'):
|
|
270
|
-
bracket = CodeBlock('Bracket', data={'id': 'bracket', 'direct': 'open', 'type': btype})
|
|
271
|
-
self.codeBlocks.append(bracket)
|
|
272
|
-
self.closebracket = btype
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
# command methods
|
|
276
|
-
def playerEvent(self, name: str):
|
|
277
|
-
cmd = CodeBlock(name, data={'id': 'block', 'block': 'event', 'action': name})
|
|
278
|
-
self.codeBlocks.append(cmd)
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
def entityEvent(self, name: str):
|
|
282
|
-
cmd = CodeBlock(name, data={'id': 'block', 'block': 'entity_event', 'action': name})
|
|
283
|
-
self.codeBlocks.append(cmd)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
def function(self, name: str):
|
|
287
|
-
cmd = CodeBlock('function', data={'id': 'block', 'block': 'func', 'data': name})
|
|
288
|
-
self.codeBlocks.append(cmd)
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
def process(self, name: str):
|
|
292
|
-
cmd = CodeBlock('process', data={'id': 'block', 'block': 'process', 'data': name})
|
|
293
|
-
self.codeBlocks.append(cmd)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
def callFunction(self, name: str, parameters={}):
|
|
297
|
-
if parameters:
|
|
298
|
-
for key in parameters.keys():
|
|
299
|
-
self.setVariable('=', var(key, scope='local'), parameters[key])
|
|
300
|
-
|
|
301
|
-
cmd = CodeBlock('call_func', data={'id': 'block', 'block': 'call_func', 'data': name})
|
|
302
|
-
self.codeBlocks.append(cmd)
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
def startProcess(self, name: str):
|
|
306
|
-
cmd = CodeBlock('start_process', data={'id': 'block', 'block': 'start_process', 'data': name})
|
|
307
|
-
self.codeBlocks.append(cmd)
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
def playerAction(self, name: str, *args, target: str=DEFAULT_TARGET):
|
|
311
|
-
args = _convertDataTypes(args)
|
|
312
|
-
cmd = CodeBlock(name, args, target=target, data={'id': 'block', 'block': 'player_action', 'action': name})
|
|
313
|
-
self.codeBlocks.append(cmd)
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
def gameAction(self, name: str, *args):
|
|
317
|
-
args = _convertDataTypes(args)
|
|
318
|
-
cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'game_action', 'action': name})
|
|
319
|
-
self.codeBlocks.append(cmd)
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
def entityAction(self, name: str, *args, target: str=DEFAULT_TARGET):
|
|
323
|
-
args = _convertDataTypes(args)
|
|
324
|
-
cmd = CodeBlock(name, args, target=target, data={'id': 'block', 'block': 'entity_action', 'action': name})
|
|
325
|
-
self.codeBlocks.append(cmd)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
def ifPlayer(self, name: str, *args, target: str=DEFAULT_TARGET, inverted: bool=False):
|
|
329
|
-
args = _convertDataTypes(args)
|
|
330
|
-
data = {'id': 'block', 'block': 'if_player', 'action': name}
|
|
331
|
-
_addInverted(data, inverted)
|
|
332
|
-
cmd = CodeBlock(name, args, target=target, data=data)
|
|
333
|
-
self.codeBlocks.append(cmd)
|
|
334
|
-
self._openbracket()
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
def ifVariable(self, name: str, *args, inverted: bool=False):
|
|
338
|
-
args = _convertDataTypes(args)
|
|
339
|
-
data = {'id': 'block', 'block': 'if_var', 'action': name}
|
|
340
|
-
_addInverted(data, inverted)
|
|
341
|
-
cmd = CodeBlock(name, args, data=data)
|
|
342
|
-
self.codeBlocks.append(cmd)
|
|
343
|
-
self._openbracket()
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
def ifGame(self, name: str, *args, inverted: bool=False):
|
|
347
|
-
args = _convertDataTypes(args)
|
|
348
|
-
data = {'id': 'block', 'block': 'if_game', 'action': name}
|
|
349
|
-
_addInverted(data, inverted)
|
|
350
|
-
cmd = CodeBlock(name, args, data=data)
|
|
351
|
-
self.codeBlocks.append(cmd)
|
|
352
|
-
self._openbracket()
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
def ifEntity(self, name: str, *args, target: str=DEFAULT_TARGET, inverted: bool=False):
|
|
356
|
-
args = _convertDataTypes(args)
|
|
357
|
-
data = {'id': 'block', 'block': 'if_entity', 'action': name}
|
|
358
|
-
_addInverted(data, inverted)
|
|
359
|
-
cmd = CodeBlock(name, args, target=target, data=data)
|
|
360
|
-
self.codeBlocks.append(cmd)
|
|
361
|
-
self._openbracket()
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
def else_(self):
|
|
365
|
-
cmd = CodeBlock('else', data={'id': 'block', 'block': 'else'})
|
|
366
|
-
self.codeBlocks.append(cmd)
|
|
367
|
-
self._openbracket()
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
def repeat(self, name: str, *args, subAction: str=None):
|
|
371
|
-
args = _convertDataTypes(args)
|
|
372
|
-
data = {'id': 'block', 'block': 'repeat', 'action': name}
|
|
373
|
-
if subAction is not None:
|
|
374
|
-
data['subAction'] = subAction
|
|
375
|
-
cmd = CodeBlock(name, args, data=data)
|
|
376
|
-
self.codeBlocks.append(cmd)
|
|
377
|
-
self._openbracket('repeat')
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
def bracket(self, *args):
|
|
381
|
-
args = _convertDataTypes(args)
|
|
382
|
-
cmd = CodeBlock('Bracket', data={'id': 'bracket', 'direct': 'close', 'type': self.closebracket})
|
|
383
|
-
self.codeBlocks.append(cmd)
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
def control(self, name: str, *args):
|
|
387
|
-
args = _convertDataTypes(args)
|
|
388
|
-
cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'control', 'action': name})
|
|
389
|
-
self.codeBlocks.append(cmd)
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
def selectObject(self, name: str, *args):
|
|
393
|
-
args = _convertDataTypes(args)
|
|
394
|
-
cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'select_obj', 'action': name})
|
|
395
|
-
self.codeBlocks.append(cmd)
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
def setVariable(self, name: str, *args):
|
|
399
|
-
args = _convertDataTypes(args)
|
|
400
|
-
cmd = CodeBlock(name, args, data={'id': 'block', 'block': 'set_var', 'action': name})
|
|
401
|
-
self.codeBlocks.append(cmd)
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
def return_(self, returndata={}):
|
|
405
|
-
for key in returndata:
|
|
406
|
-
self.setVariable('=', var(key, scope='local'), returndata[key])
|
|
407
|
-
self.control('Return')
|
dfpyre/style.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
from mcitemlib.style import *
|
|
2
|
-
|
|
3
|
-
def isAmpersandCoded(s: str) -> bool:
|
|
4
|
-
return bool(re.match(STYLE_CODE_REGEX, s))
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def ampersandToMinimessage(ampersand_code: str) -> str:
|
|
8
|
-
ampersand_code = ampersand_code.replace('&r', '<reset>') # bad but should work most of the time
|
|
9
|
-
styledString = StyledString.from_codes(ampersand_code)
|
|
10
|
-
formattedStringList = []
|
|
11
|
-
for substring in styledString.substrings:
|
|
12
|
-
formattedSubstringList = []
|
|
13
|
-
for styleType, value in substring.data.items():
|
|
14
|
-
if styleType in FORMAT_CODES.values() and value:
|
|
15
|
-
formattedSubstringList.append(f'<{styleType}>')
|
|
16
|
-
if styleType == 'color':
|
|
17
|
-
formattedSubstringList.append(f'<{value}>')
|
|
18
|
-
|
|
19
|
-
formattedSubstringList.append(substring.data['text'])
|
|
20
|
-
formattedStringList.append(''.join(formattedSubstringList))
|
|
21
|
-
return ''.join(formattedStringList)
|
dfpyre-0.4.2.dist-info/METADATA
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: dfpyre
|
|
3
|
-
Version: 0.4.2
|
|
4
|
-
Summary: A package for externally creating code templates for the DiamondFire Minecraft server.
|
|
5
|
-
Home-page: https://github.com/Amp63/pyre
|
|
6
|
-
Author: Amp
|
|
7
|
-
License: MIT
|
|
8
|
-
Keywords: diamondfire,minecraft
|
|
9
|
-
License-File: LICENSE
|
|
10
|
-
Requires-Dist: mcitemlib
|
|
11
|
-
|
dfpyre-0.4.2.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
dfpyre/__init__.py,sha256=apPsSxJ1Tztfl71MoORoSmDfX7LyKLYlLwOGeLQUitw,25
|
|
2
|
-
dfpyre/items.py,sha256=O3B-lrC9-BTpYAIcnVs-_DjLZOCdm9Ee5WKgNwVI3A0,6029
|
|
3
|
-
dfpyre/pyre.py,sha256=a0UtHn4ILbIYX3DlFtXcVNC7hXjhIU1Rk9n4RIcqTdY,14312
|
|
4
|
-
dfpyre/style.py,sha256=cCrhhC39ob-Kze8ju0Ts-gPCTMKMXDdtFnMsdaSwWVA,921
|
|
5
|
-
dfpyre/data/data.json,sha256=id4Af6otc9BHO8abEQPsfRPUpeZ4NDJTd5npige5NmM,30469
|
|
6
|
-
dfpyre-0.4.2.dist-info/LICENSE,sha256=0-CM8JuXeqwgv7oyGD6sW2vYc_GTZse7nBEMC_p9-QE,1081
|
|
7
|
-
dfpyre-0.4.2.dist-info/METADATA,sha256=ZfACceERYJlzUpQ5i37q376HMlJ5WRTxR6Hwl-Xuip8,303
|
|
8
|
-
dfpyre-0.4.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
9
|
-
dfpyre-0.4.2.dist-info/top_level.txt,sha256=dZ1DRJpW80nu8PH9ax__cNrin1XxVV6UcdCkT7kHktA,7
|
|
10
|
-
dfpyre-0.4.2.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dfpyre
|