|
| 1 | +# Importing Libraries |
| 2 | +from tkinter import * |
| 3 | +from random import * |
| 4 | +from math import * |
| 5 | +import os |
| 6 | +from tkinter import simpledialog |
| 7 | + |
| 8 | +class Element: |
| 9 | + def __init__(self, properties): |
| 10 | + self.properties = properties |
| 11 | + |
| 12 | +# Create The Create New Mod Function |
| 13 | +def createNewMod(): |
| 14 | + exit |
| 15 | + |
| 16 | +def create_file_from_template(template_path, new_file_path, replacements): |
| 17 | + with open(template_path, 'r') as template_file: |
| 18 | + template_content = template_file.read() |
| 19 | + |
| 20 | + # Perform replacements in the template content |
| 21 | + for key, value in replacements.items(): |
| 22 | + print(f"{key} : {value}") |
| 23 | + replace = eval(value) |
| 24 | + template_content = template_content.replace(key, replace) |
| 25 | + |
| 26 | + # Create the directory if it doesn't exist |
| 27 | + directory = os.path.dirname(new_file_path) |
| 28 | + if not os.path.exists(directory): |
| 29 | + os.makedirs(directory) |
| 30 | + |
| 31 | + with open(new_file_path, 'w') as new_file: |
| 32 | + new_file.write(template_content) |
| 33 | + |
| 34 | +def makeItem(): |
| 35 | + pass |
| 36 | + |
| 37 | +def stringReturn(name): |
| 38 | + return name |
| 39 | + |
| 40 | +class Mod: |
| 41 | + def __init__(self, name): |
| 42 | + self._name = name |
| 43 | + |
| 44 | + def name(self): |
| 45 | + return self._name |
| 46 | + |
| 47 | +def createElement(): |
| 48 | + toMake = canMake.get(ACTIVE) |
| 49 | + |
| 50 | + name = simpledialog.askstring('Text Input', 'Name without spaces:') |
| 51 | + |
| 52 | + tMod = Mod(name) |
| 53 | + |
| 54 | + replaces = {'<MOD>' : f'''"{mod}"''', '<NAME>' : f'''"{name}"'''} |
| 55 | + |
| 56 | + #for prop in elementTypes[toMake].properties: |
| 57 | + # exec(prop) |
| 58 | + |
| 59 | + if toMake == "item": |
| 60 | + global channel, noMelee, noUseGraphic, axe, hammer, pick, tileBoost, useStyle, damageType, useAnimation, sound, rarity, useTime, useAnimation, damage, knockback, crit, goldcost, autoReuse |
| 61 | + useStyles = ["Swing"] |
| 62 | + damageTypes = ["Melee"] |
| 63 | + rarities = ["Blue"] |
| 64 | + sounds = ["Item1"] |
| 65 | + |
| 66 | + useStyle = Listbox(root) |
| 67 | + for item in useStyles: |
| 68 | + useStyle.insert(END, item) |
| 69 | + useStyle.place(x=152, y=2) |
| 70 | + |
| 71 | + useTime = IntVar() |
| 72 | + useAnimation = IntVar() |
| 73 | + damage = IntVar() |
| 74 | + knockback = IntVar() |
| 75 | + crit = IntVar() |
| 76 | + goldcost = IntVar() |
| 77 | + axe = IntVar() |
| 78 | + hammer = IntVar() |
| 79 | + pick = IntVar() |
| 80 | + tileBoost = IntVar() |
| 81 | + |
| 82 | + Label(root, text="Use time").place(x = 152, y = 180) |
| 83 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=useTime).place(x=152, y=200) |
| 84 | + Label(root, text="Use animation").place(x = 302, y = 180) |
| 85 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=useAnimation).place(x=302, y=200) |
| 86 | + Label(root, text="Damage").place(x = 152, y = 230) |
| 87 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=damage).place(x=152, y=250) |
| 88 | + Label(root, text="Knockback").place(x = 302, y = 230) |
| 89 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=knockback).place(x=302, y=250) |
| 90 | + Label(root, text="Crit").place(x = 152, y = 280) |
| 91 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=crit).place(x=152, y=300) |
| 92 | + Label(root, text="Gold cost").place(x = 302, y = 280) |
| 93 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=goldcost).place(x=302, y=300) |
| 94 | + Label(root, text="Axe").place(x = 152, y = 330) |
| 95 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=axe).place(x=152, y=350) |
| 96 | + Label(root, text="Hammer").place(x = 302, y = 330) |
| 97 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=hammer).place(x=302, y=350) |
| 98 | + Label(root, text="Pick").place(x = 152, y = 380) |
| 99 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=pick).place(x=152, y=400) |
| 100 | + Label(root, text="Tile boost").place(x = 302, y = 380) |
| 101 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=tileBoost).place(x=302, y=400) |
| 102 | + |
| 103 | + damageType = Listbox(root) |
| 104 | + for item in damageTypes: |
| 105 | + damageType.insert(END, item) |
| 106 | + damageType.place(x=302, y=2) |
| 107 | + |
| 108 | + rarity = Listbox(root) |
| 109 | + |
| 110 | + for item in rarities: |
| 111 | + rarity.insert(END, item) |
| 112 | + rarity.place(x=452, y=2) |
| 113 | + |
| 114 | + sound = Listbox(root) |
| 115 | + for item in sounds: |
| 116 | + sound.insert(END, item) |
| 117 | + sound.place(x=602, y=2) |
| 118 | + |
| 119 | + autoReuse = BooleanVar() |
| 120 | + channel = BooleanVar() |
| 121 | + noMelee = BooleanVar() |
| 122 | + noUseGraphic = BooleanVar() |
| 123 | + |
| 124 | + replaces['<USESTYLE>'] = "useStyle.get(ACTIVE)" |
| 125 | + replaces['<USETIME>'] = "str(useTime.get())" |
| 126 | + replaces['<USEANIMATION>'] = "str(useAnimation.get())" |
| 127 | + replaces['<AUTOREUSE>'] = "str(autoReuse.get())" |
| 128 | + replaces['<DAMAGETYPE>'] = "damageType.get(ACTIVE)" |
| 129 | + replaces['<DAMAGE>'] = "str(damage.get())" |
| 130 | + replaces['<KNOCKBACK>'] = "str(knockback.get())" |
| 131 | + replaces['<CRIT>'] = "str(crit.get())" |
| 132 | + replaces['<GOLDCOST>'] = "str(goldcost.get())" |
| 133 | + replaces['<RARITY>'] = "rarity.get(ACTIVE)" |
| 134 | + replaces['<SOUND>'] = "sound.get(ACTIVE)" |
| 135 | + replaces['<AXE>'] = "str(axe.get())" |
| 136 | + replaces['<HAMMER>'] = "str(hammer.get())" |
| 137 | + replaces['<PICK>'] = "str(pick.get())" |
| 138 | + replaces['<TILEBOOST>'] = "str(tileBoost.get())" |
| 139 | + replaces['<CHANNEL>'] = "str(channel.get())" |
| 140 | + replaces['<NOMELEE>'] = "str(noMelee.get())" |
| 141 | + replaces['<NOUSEGRAPHIC>'] = "str(noUseGraphic.get())" |
| 142 | + |
| 143 | + Checkbutton(root, text="Auto reuse", variable=autoReuse).place(x=152, y=500) |
| 144 | + Checkbutton(root, text="Channel", variable=channel).place(x=302, y=500) |
| 145 | + Checkbutton(root, text="No melee", variable=noMelee).place(x=452, y=500) |
| 146 | + Checkbutton(root, text="No use graphic", variable=noUseGraphic).place(x=602, y=500) |
| 147 | + elif toMake == "tile": |
| 148 | + global solid, mergeDirt, blockLight, dust, mapr, mapg, mapb |
| 149 | + dusts = ["Stone"] |
| 150 | + |
| 151 | + dust = Listbox(root) |
| 152 | + for item in dusts: |
| 153 | + dust.insert(END, item) |
| 154 | + dust.place(x=152, y=2) |
| 155 | + |
| 156 | + mapr = IntVar() |
| 157 | + mapg = IntVar() |
| 158 | + mapb = IntVar() |
| 159 | + solid = BooleanVar() |
| 160 | + mergeDirt = BooleanVar() |
| 161 | + blockLight = BooleanVar() |
| 162 | + |
| 163 | + Label(root, text="Map R").place(x = 152, y = 180) |
| 164 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=mapr).place(x=152, y=200) |
| 165 | + Label(root, text="Map G").place(x = 302, y = 180) |
| 166 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=mapg).place(x=302, y=200) |
| 167 | + Label(root, text="Map B").place(x = 452, y = 180) |
| 168 | + Spinbox(root, from_=-2147483647, to=2147483647, textvariable=mapb).place(x=452, y=200) |
| 169 | + |
| 170 | + Checkbutton(root, text="Solid", variable=solid).place(x=152, y=500) |
| 171 | + Checkbutton(root, text="Merge dirt", variable=mergeDirt).place(x=302, y=500) |
| 172 | + Checkbutton(root, text="Block light", variable=blockLight).place(x=452, y=500) |
| 173 | + |
| 174 | + replaces['<SOLID>'] = "str(solid.get())" |
| 175 | + replaces['<MERGEDIRT>'] = "str(mergeDirt.get())" |
| 176 | + replaces['<BLOCKLIGHT>'] = "str(blockLight.get())" |
| 177 | + replaces['<DUST>'] = "dust.get(ACTIVE)" |
| 178 | + replaces['<MAPR>'] = "str(mapr.get())" |
| 179 | + replaces['<MAPG>'] = "str(mapg.get())" |
| 180 | + replaces['<MAPB>'] = "str(mapb.get())" |
| 181 | + |
| 182 | + print("eh") |
| 183 | + Button(root, text="Save", height = 1, width = 16, command = lambda: create_file_from_template(f"Templates/{toMake}.txt", f"{currentpath}\\{toMake.capitalize()}s\\{name}.cs", replaces)).place(x=152, y=450) |
| 184 | + |
| 185 | +def openWorkspace(modpath): |
| 186 | + global currentpath |
| 187 | + global root |
| 188 | + global sideFrame |
| 189 | + global mainFrame |
| 190 | + global canMake |
| 191 | + global make |
| 192 | + |
| 193 | + for widget in root.winfo_children(): |
| 194 | + widget.destroy() |
| 195 | + |
| 196 | + root.title(f"TCreator - {modpath}") |
| 197 | + |
| 198 | + currentpath = modpath |
| 199 | + |
| 200 | + sideFrame = Frame(root, width=150, height=600, bg="gray") |
| 201 | + mainFrame = Frame(root, width=850, height=600, bg="darkgray") |
| 202 | + sideFrame.grid(row = 0, column = 0) |
| 203 | + mainFrame.grid(row = 0, column = 1) |
| 204 | + |
| 205 | + canMake = Listbox(root) |
| 206 | + canMake.place(x=2, y=2) |
| 207 | + make = Button(root, text="Create", height = 1, width = 16, command=createElement) |
| 208 | + make.place(x=2, y=180) |
| 209 | + |
| 210 | + items = ['item', 'tile', 'npc', 'projectile', 'buff'] |
| 211 | + for item in items: |
| 212 | + canMake.insert(END, item) |
| 213 | + |
| 214 | +def list_folders(path): |
| 215 | + folders = [] |
| 216 | + for item in os.listdir(path): |
| 217 | + item_path = os.path.join(path, item) |
| 218 | + if os.path.isdir(item_path): |
| 219 | + folders.append(item) |
| 220 | + return folders |
| 221 | + |
| 222 | +# Create The Window |
| 223 | +root = Tk() |
| 224 | +root.title("TCreator - Start Menu") |
| 225 | +root.geometry("1000x600") |
| 226 | +root.resizable(0, 0) |
| 227 | + |
| 228 | +# Create The Side Frame |
| 229 | +sideFrame = Frame(root, width=300, height=600, bg="gray") |
| 230 | + |
| 231 | +# Create The Main Frame |
| 232 | +mainFrame = Frame(root, width=700, height=600, bg="darkgray") |
| 233 | + |
| 234 | +# Place Everything On The Grid |
| 235 | +sideFrame.grid(row = 0, column = 0) |
| 236 | +mainFrame.grid(row = 0, column = 1) |
| 237 | + |
| 238 | +# Create A List Of Mods |
| 239 | +settingsfile = open("settings.txt", "r+") |
| 240 | + |
| 241 | +for line in settingsfile: |
| 242 | + modlocation = line.strip() |
| 243 | + |
| 244 | +mods = list_folders(modlocation) |
| 245 | + |
| 246 | +currentpath = "" |
| 247 | + |
| 248 | +btny = 2 |
| 249 | + |
| 250 | +for mod in mods: |
| 251 | + Button(root, text=mod, height=1, width=41, command=lambda: openWorkspace(os.path.join(modlocation, mod))).place(x=2, y=btny) |
| 252 | + btny += 27 |
| 253 | + |
| 254 | +elementTypes = {"item" : Element(["replaces['<USESTYLE>'] = simpledialog.askstring('Text Input', 'Use style:')", |
| 255 | + "replaces['<USETIME>'] = simpledialog.askstring('Text Input', 'Use time:')", |
| 256 | + "replaces['<USEANIMATION>'] = simpledialog.askstring('Text Input', 'Use animation:')", |
| 257 | + "replaces['<AUTOREUSE>'] = (str(simpledialog.askstring('Text Input', 'Auto reuse:') == 1)).lower()", |
| 258 | + "replaces['<DAMAGETYPE>'] = simpledialog.askstring('Text Input', 'Damage type:')", |
| 259 | + "replaces['<DAMAGE>'] = simpledialog.askstring('Text Input', 'Damage:')", |
| 260 | + "replaces['<KNOCKBACK>'] = simpledialog.askstring('Text Input', 'Knockback:')", |
| 261 | + "replaces['<CRIT>'] = simpledialog.askstring('Text Input', 'Crit:')", |
| 262 | + "replaces['<GOLDCOST>'] = simpledialog.askstring('Text Input', 'Gold cost:')", |
| 263 | + "replaces['<RARITY>'] = simpledialog.askstring('Text Input', 'Rarity:')", |
| 264 | + "replaces['<SOUND>'] = simpledialog.askstring('Text Input', 'Sound:')"])} |
| 265 | + |
| 266 | +# Create The Menu Buttons |
| 267 | +createBtn = Button(root, text="Create New Mod", command=createNewMod).place(x=50, y=300) |
| 268 | + |
| 269 | +mainloop() |
| 270 | + |
0 commit comments