diff --git a/TCreator/Main.py b/TCreator/Main.py index a157f84..951f0db 100644 --- a/TCreator/Main.py +++ b/TCreator/Main.py @@ -6,6 +6,14 @@ from tkinter import simpledialog from PIL import Image +class FileTypes: + Tile = 0 + Item = 1 + NPC = 2 + Projectile = 3 + Dust = 4 + Buff = 5 + def get_image_dimensions(image_path, width=True, height=True): print(width) print(height) @@ -57,20 +65,46 @@ def extract_number_from_string(string): else: return None -def get_replaced_values(file_path): +def get_replaced_values(file_path, file_type): with open(file_path, 'r') as file: content = file.read() - patternV = r'(\w+)\s+=\s+(.*?);' - matchesV = re.findall(patternV, content) + if file_type == FileTypes.Item: + patternV = r'(\w+)\s+=\s+(.*?);' + matchesV = re.findall(patternV, content) - patternC = r'(?:Item|Tile)\.\w+\s+=\s+(.*?);' - matchesC = re.findall(patternC, content) + patternC = r'(?:Item|Tile)\.\w+\s+=\s+(.*?);' + matchesC = re.findall(patternC, content) + pattern = r'Item\.DefaultToPlaceableTile\(ModContent\.TileType' + match = re.search(pattern, content) - replaced_values = {} - for matchC, matchV in zip(matchesC, matchesV): - replaced_values[f"<{str(matchV[0]).upper()}>"] = matchC + replaced_values = {} + + for matchC, matchV in zip(matchesC, matchesV): + replaced_values[f"<{str(matchV[0]).upper()}>"] = matchC + elif file_type == FileTypes.Tile: + patternSolid = r'Main\.tileSolid\[Type\]\s+=\s+(.*?);' + patternMergeDirt = r'Main\.tileMergeDirt\[Type\]\s+=\s+(.*?);' + patternBlockLight = r'Main\.tileBlockLight\[Type\]\s+=\s+(.*?);' + patternDustType = r'DustType\s+=\s+(.*?);' + patternMapEntry = r'AddMapEntry\(new Color\((.*?)\)\);' + + matchSolid = re.search(patternSolid, content) + matchMergeDirt = re.search(patternMergeDirt, content) + matchBlockLight = re.search(patternBlockLight, content) + matchDustType = re.search(patternDustType, content) + matchMapEntry = re.search(patternMapEntry, content) + + replaced_values = { + 'solid': matchSolid.group(1) if matchSolid else None, + 'merge_dirt': matchMergeDirt.group(1) if matchMergeDirt else None, + 'block_light': matchBlockLight.group(1) if matchBlockLight else None, + 'dust_type': matchDustType.group(1) if matchDustType else None, + 'map_color_r': matchMapEntry.group(1).split(',')[0] if matchMapEntry else None, + 'map_color_g': matchMapEntry.group(1).split(',')[1] if matchMapEntry else None, + 'map_color_b': matchMapEntry.group(1).split(',')[2] if matchMapEntry else None + } return replaced_values @@ -154,7 +188,10 @@ def button_click(self, item): extras.append(item.values[val]) if item.type == "item": print(f"{item.name}") - createElement(toMakeValue="'item'", nameValue=f"'{item.name}'", extraData=item.values); + createElement(toMakeValue="'item'", nameValue=f"'{item.name}'", extraData=item.values) + elif item.type == "tile": + print(f"{item.name}") + createElement(toMakeValue="'tile'", nameValue=f"'item.name'", extraData=item.values) def list_files_with_extension(directory, extension): if not os.path.exists(directory): @@ -390,6 +427,11 @@ def createElement(toMakeValue="canMake.get(ACTIVE)", nameValue="simpledialog.ask defense.set(int(extraData[""])) except: pass + try: + doTile.set(True) + tile.set(extraData["TileToPlace"]) + except: + pass elif toMake == "tile": global solid, mergeDirt, blockLight, dust, mapr, mapg, mapb dusts = ["DustID.Stone"] @@ -425,6 +467,32 @@ def createElement(toMakeValue="canMake.get(ACTIVE)", nameValue="simpledialog.ask replaces[''] = "str(mapg.get())" replaces[''] = "str(mapb.get())" + if not extraData == None: + try: + solid.set(bool(extraData["solid"] == "true")) + except: + pass + try: + mergeDirt.set(bool(extraData["merge_dirt"] == "true")) + except: + pass + try: + blockLight.set(bool(extraData["block_light"] == "true")) + except: + pass + try: + mapr.set(int(extraData["map_color_r"])) + except: + pass + try: + mapg.set(int(extraData["map_color_g"])) + except: + pass + try: + mapb.set(int(extraData["map_color_b"])) + except: + pass + #print("eh") Button(root, text="Save", height = 1, width = 16, bg=accentColor, activebackground=highlightColor, command = lambda: create_file_from_template(f"Templates/{toMake}.txt", f"{currentpath}\\{toMake.capitalize()}s\\{name}.cs", replaces)).place(x=152, y=450) @@ -453,11 +521,11 @@ def openWorkspace(modpath, mod): tiles = list_files_with_extension(currentpath+"/Tiles", ".cs") for item in items: - toadd.append(ElementData("item", get_replaced_values(currentpath + "\\Items\\" + item + ".cs"), item)) + toadd.append(ElementData("item", get_replaced_values(currentpath + "\\Items\\" + item + ".cs", FileTypes.Item), item)) #print(item) for tile in tiles: - toadd.append(ElementData("tile", get_replaced_values(currentpath + "\\Tiles\\" + tile + ".cs"), tile)) + toadd.append(ElementData("tile", get_replaced_values(currentpath + "\\Tiles\\" + tile + ".cs", FileTypes.Tile), tile)) #print(tile) sideFrame = Frame(root, width=150, height=600, bg=secondaryThemeColor)