From e1c4eaa6a1e2c5bc54e3c967c1422981259e6a72 Mon Sep 17 00:00:00 2001 From: GameGeekGameBuilder <147017802+GameGeekGameBuilder@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:55:46 -0400 Subject: [PATCH 1/4] Update Main With Tile Loading.py --- TCreator/Main.py | 64 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/TCreator/Main.py b/TCreator/Main.py index a157f84..c3db0e5 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,48 @@ 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) + pattern = r'Item\.DefaultToPlaceableTile\(ModContent\.TileType' + match = re.search(pattern, content) - patternC = r'(?:Item|Tile)\.\w+\s+=\s+(.*?);' - matchesC = re.findall(patternC, content) - replaced_values = {} + replaced_values = {} - for matchC, matchV in zip(matchesC, matchesV): - replaced_values[f"<{str(matchV[0]).upper()}>"] = matchC + 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) + + tile_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 tile_values return replaced_values @@ -155,6 +191,9 @@ def button_click(self, item): if item.type == "item": print(f"{item.name}") 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 +429,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"] @@ -453,11 +497,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) From 86301edddccb53732a40690480e9b2324a696983 Mon Sep 17 00:00:00 2001 From: GameGeekGameBuilder <147017802+GameGeekGameBuilder@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:01:46 -0400 Subject: [PATCH 2/4] Update Main.py Fixed tile editing --- TCreator/Main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/TCreator/Main.py b/TCreator/Main.py index c3db0e5..325e0a8 100644 --- a/TCreator/Main.py +++ b/TCreator/Main.py @@ -469,6 +469,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) From 50c54a1981fb9c8ddd5130924d1ad9da3d2dfdf2 Mon Sep 17 00:00:00 2001 From: GameGeekGameBuilder <147017802+GameGeekGameBuilder@users.noreply.github.com> Date: Thu, 5 Oct 2023 00:05:56 -0400 Subject: [PATCH 3/4] Update Main.py Removed Unnecessary Semicolons --- TCreator/Main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TCreator/Main.py b/TCreator/Main.py index 325e0a8..e18a603 100644 --- a/TCreator/Main.py +++ b/TCreator/Main.py @@ -190,10 +190,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); + createElement(toMakeValue="'tile'", nameValue=f"'item.name'", extraData=item.values) def list_files_with_extension(directory, extension): if not os.path.exists(directory): From b2449b92ae93781c80f3f6bae177d12b081c10ca Mon Sep 17 00:00:00 2001 From: "Markus L. Tanner" <70599537+Darthsae@users.noreply.github.com> Date: Sat, 7 Oct 2023 19:37:17 -0400 Subject: [PATCH 4/4] Update Main.py --- TCreator/Main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TCreator/Main.py b/TCreator/Main.py index e18a603..951f0db 100644 --- a/TCreator/Main.py +++ b/TCreator/Main.py @@ -96,7 +96,7 @@ def get_replaced_values(file_path, file_type): matchDustType = re.search(patternDustType, content) matchMapEntry = re.search(patternMapEntry, content) - tile_values = { + 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, @@ -106,8 +106,6 @@ def get_replaced_values(file_path, file_type): 'map_color_b': matchMapEntry.group(1).split(',')[2] if matchMapEntry else None } - return tile_values - return replaced_values class ScrollableWindow(Frame):