Skip to content

Commit 5543d64

Browse files
committed
Functions can now be defined with custom namespaces.
1 parent f5dc8be commit 5543d64

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

__pycache__/main.cpython-38.pyc

92 Bytes
Binary file not shown.

__pycache__/tags.cpython-38.pyc

-42 Bytes
Binary file not shown.

main.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ def implement(self):
151151
self.parentFunction.append("#" + self.text)
152152

153153
class Function:
154-
def __init__(self, name, desc):
154+
def __init__(self, namespace, name, desc):
155155
self.name = name
156+
self.namespace = namespace
156157
self.code = []
157158
Comment(desc, self).implement()
158159

@@ -169,10 +170,10 @@ def implement(self, filePath):
169170
defaultPackInfo = False
170171
useSnapshots = False
171172

172-
initFunction = Function("load", "This function is run when the datapack is loaded.")
173-
uninstallFunction = Function("uninstall", "Can be called to remove the pack and any trace it was ever installed")
174-
tickFunction = Function("tick", "This function is run every tick after this datapack is loaded.")
175-
customFunctions = {"test": Function("test", "this is a test.")}
173+
initFunction = Function(packId, "load", "This function is run when the datapack is loaded.")
174+
uninstallFunction = Function(packId, "uninstall", "Can be called to remove the pack and any trace it was ever installed")
175+
tickFunction = Function(packId, "tick", "This function is run every tick after this datapack is loaded.")
176+
customFunctions = {"test": Function("example_pack", "test", "this is a test.")}
176177

177178
def generateCode(code):
178179
#TODO: Convert each line of code to an instance of Statement or Variable that can then be converted to datapack form.
@@ -231,12 +232,14 @@ def main():
231232
initFunction.append(f'tellraw @a [{{"text":"The pack "}},{{"text":"\\"{packName}\\" ","color":"green","hoverEvent":{{"action":"show_text","contents":[{{"text":"{packId}\\n{packDesc}"}}]}}}},{{"text":"has been sucessfully (re)loaded."}}]')
232233
uninstallFunction.append(f'tellraw @a [{{"text":"The pack "}},{{"text":"\\"{packName}\\" ","color":"green","hoverEvent":{{"action":"show_text","contents":[{{"text":"{packId}\\n{packDesc}"}}]}}}},{{"text":"has been sucessfully unloaded."}}]')
233234

235+
os.makedirs(f".saved/data", exist_ok = True)
234236
print("Saving functions for use in tags")
235237
with open(".saved/data/functions.csv", "w+") as file:
236238
data = ["namespace,name",f"{packId},internal/load", f"{packId},internal/tick", f"{packId},uninstall"]
237239
for i in customFunctions:
238-
data.append(f"{packId},{i.name}")
240+
data.append(f"{customFunctions[i].namespace},{customFunctions[i].name}")
239241
file.write("\n".join(data))
242+
240243
print("Generating tag files")
241244
tags.start(packName, packId, packDesc)
242245

tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def inner(x):
253253

254254
if len(name_split) > 1:
255255
os.makedirs(f".saved/tags/{t}/{'/'.join(name_split[:len(name_split)-1])}", exist_ok=True)
256-
print(f".saved/tags/{t}/{'/'.join(name_split[:len(name_split)-1])}")
256+
#print(f".saved/tags/{t}/{'/'.join(name_split[:len(name_split)-1])}")
257257
with open(f".saved/tags/{t}/{name}.txt", "w+") as data:
258258
data.write("\n".join(result))
259259

0 commit comments

Comments
 (0)