|
6 | 6 | from tkinter import simpledialog |
7 | 7 | from PIL import Image |
8 | 8 |
|
| 9 | +class FileTypes: |
| 10 | + Tile = 0 |
| 11 | + Item = 1 |
| 12 | + NPC = 2 |
| 13 | + Projectile = 3 |
| 14 | + Dust = 4 |
| 15 | + Buff = 5 |
| 16 | + |
9 | 17 | def get_image_dimensions(image_path, width=True, height=True): |
10 | 18 | print(width) |
11 | 19 | print(height) |
@@ -57,20 +65,46 @@ def extract_number_from_string(string): |
57 | 65 | else: |
58 | 66 | return None |
59 | 67 |
|
60 | | -def get_replaced_values(file_path): |
| 68 | +def get_replaced_values(file_path, file_type): |
61 | 69 | with open(file_path, 'r') as file: |
62 | 70 | content = file.read() |
63 | 71 |
|
64 | | - patternV = r'(\w+)\s+=\s+(.*?);' |
65 | | - matchesV = re.findall(patternV, content) |
| 72 | + if file_type == FileTypes.Item: |
| 73 | + patternV = r'(\w+)\s+=\s+(.*?);' |
| 74 | + matchesV = re.findall(patternV, content) |
66 | 75 |
|
67 | | - patternC = r'(?:Item|Tile)\.\w+\s+=\s+(.*?);' |
68 | | - matchesC = re.findall(patternC, content) |
| 76 | + patternC = r'(?:Item|Tile)\.\w+\s+=\s+(.*?);' |
| 77 | + matchesC = re.findall(patternC, content) |
| 78 | + pattern = r'Item\.DefaultToPlaceableTile\(ModContent\.TileType<Tiles\.(\w+)>' |
| 79 | + match = re.search(pattern, content) |
69 | 80 |
|
70 | | - replaced_values = {} |
71 | 81 |
|
72 | | - for matchC, matchV in zip(matchesC, matchesV): |
73 | | - replaced_values[f"<{str(matchV[0]).upper()}>"] = matchC |
| 82 | + replaced_values = {} |
| 83 | + |
| 84 | + for matchC, matchV in zip(matchesC, matchesV): |
| 85 | + replaced_values[f"<{str(matchV[0]).upper()}>"] = matchC |
| 86 | + elif file_type == FileTypes.Tile: |
| 87 | + patternSolid = r'Main\.tileSolid\[Type\]\s+=\s+(.*?);' |
| 88 | + patternMergeDirt = r'Main\.tileMergeDirt\[Type\]\s+=\s+(.*?);' |
| 89 | + patternBlockLight = r'Main\.tileBlockLight\[Type\]\s+=\s+(.*?);' |
| 90 | + patternDustType = r'DustType\s+=\s+(.*?);' |
| 91 | + patternMapEntry = r'AddMapEntry\(new Color\((.*?)\)\);' |
| 92 | + |
| 93 | + matchSolid = re.search(patternSolid, content) |
| 94 | + matchMergeDirt = re.search(patternMergeDirt, content) |
| 95 | + matchBlockLight = re.search(patternBlockLight, content) |
| 96 | + matchDustType = re.search(patternDustType, content) |
| 97 | + matchMapEntry = re.search(patternMapEntry, content) |
| 98 | + |
| 99 | + replaced_values = { |
| 100 | + 'solid': matchSolid.group(1) if matchSolid else None, |
| 101 | + 'merge_dirt': matchMergeDirt.group(1) if matchMergeDirt else None, |
| 102 | + 'block_light': matchBlockLight.group(1) if matchBlockLight else None, |
| 103 | + 'dust_type': matchDustType.group(1) if matchDustType else None, |
| 104 | + 'map_color_r': matchMapEntry.group(1).split(',')[0] if matchMapEntry else None, |
| 105 | + 'map_color_g': matchMapEntry.group(1).split(',')[1] if matchMapEntry else None, |
| 106 | + 'map_color_b': matchMapEntry.group(1).split(',')[2] if matchMapEntry else None |
| 107 | + } |
74 | 108 |
|
75 | 109 | return replaced_values |
76 | 110 |
|
@@ -154,7 +188,10 @@ def button_click(self, item): |
154 | 188 | extras.append(item.values[val]) |
155 | 189 | if item.type == "item": |
156 | 190 | print(f"{item.name}") |
157 | | - createElement(toMakeValue="'item'", nameValue=f"'{item.name}'", extraData=item.values); |
| 191 | + createElement(toMakeValue="'item'", nameValue=f"'{item.name}'", extraData=item.values) |
| 192 | + elif item.type == "tile": |
| 193 | + print(f"{item.name}") |
| 194 | + createElement(toMakeValue="'tile'", nameValue=f"'item.name'", extraData=item.values) |
158 | 195 |
|
159 | 196 | def list_files_with_extension(directory, extension): |
160 | 197 | if not os.path.exists(directory): |
@@ -390,6 +427,11 @@ def createElement(toMakeValue="canMake.get(ACTIVE)", nameValue="simpledialog.ask |
390 | 427 | defense.set(int(extraData["<DEFENSE>"])) |
391 | 428 | except: |
392 | 429 | pass |
| 430 | + try: |
| 431 | + doTile.set(True) |
| 432 | + tile.set(extraData["TileToPlace"]) |
| 433 | + except: |
| 434 | + pass |
393 | 435 | elif toMake == "tile": |
394 | 436 | global solid, mergeDirt, blockLight, dust, mapr, mapg, mapb |
395 | 437 | dusts = ["DustID.Stone"] |
@@ -425,6 +467,32 @@ def createElement(toMakeValue="canMake.get(ACTIVE)", nameValue="simpledialog.ask |
425 | 467 | replaces['<MAPG>'] = "str(mapg.get())" |
426 | 468 | replaces['<MAPB>'] = "str(mapb.get())" |
427 | 469 |
|
| 470 | + if not extraData == None: |
| 471 | + try: |
| 472 | + solid.set(bool(extraData["solid"] == "true")) |
| 473 | + except: |
| 474 | + pass |
| 475 | + try: |
| 476 | + mergeDirt.set(bool(extraData["merge_dirt"] == "true")) |
| 477 | + except: |
| 478 | + pass |
| 479 | + try: |
| 480 | + blockLight.set(bool(extraData["block_light"] == "true")) |
| 481 | + except: |
| 482 | + pass |
| 483 | + try: |
| 484 | + mapr.set(int(extraData["map_color_r"])) |
| 485 | + except: |
| 486 | + pass |
| 487 | + try: |
| 488 | + mapg.set(int(extraData["map_color_g"])) |
| 489 | + except: |
| 490 | + pass |
| 491 | + try: |
| 492 | + mapb.set(int(extraData["map_color_b"])) |
| 493 | + except: |
| 494 | + pass |
| 495 | + |
428 | 496 | #print("eh") |
429 | 497 | 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) |
430 | 498 |
|
@@ -453,11 +521,11 @@ def openWorkspace(modpath, mod): |
453 | 521 | tiles = list_files_with_extension(currentpath+"/Tiles", ".cs") |
454 | 522 |
|
455 | 523 | for item in items: |
456 | | - toadd.append(ElementData("item", get_replaced_values(currentpath + "\\Items\\" + item + ".cs"), item)) |
| 524 | + toadd.append(ElementData("item", get_replaced_values(currentpath + "\\Items\\" + item + ".cs", FileTypes.Item), item)) |
457 | 525 | #print(item) |
458 | 526 |
|
459 | 527 | for tile in tiles: |
460 | | - toadd.append(ElementData("tile", get_replaced_values(currentpath + "\\Tiles\\" + tile + ".cs"), tile)) |
| 528 | + toadd.append(ElementData("tile", get_replaced_values(currentpath + "\\Tiles\\" + tile + ".cs", FileTypes.Tile), tile)) |
461 | 529 | #print(tile) |
462 | 530 |
|
463 | 531 | sideFrame = Frame(root, width=150, height=600, bg=secondaryThemeColor) |
|
0 commit comments