-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_manager.py
169 lines (127 loc) · 6.79 KB
/
mod_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from ast import Str
import os
from re import T
import shutil
from index import create_workshop_image
parent_dir = "./Mods/"
from PIL import Image
import tempfile
import time
def check_if_mod_exists(name):
for folder_name in os.listdir("./Mods/"):
if folder_name.lower() == name.lower():
return True
return False
def delete_god_portrait(file_path):
if os.path.exists(file_path):
os.remove(file_path)
def create_new_portrait_image(ui_type, god_name, user_image, image_x, image_y, image_width, image_height, current_mod_opened, current_civilization):
print(int(image_x), int(image_y), int(image_width), int(image_height))
if ui_type == "_ui_gods":
card_size = int(image_width), int(image_height)
img = Image.new('RGBA', (256, 256))
cb = Image.open("./GodPortraitFrames/"+"ui_god_"+current_civilization+".png")
ci = Image.open(user_image)
ci = ci.resize(card_size)
mask = Image.open("./GodPortraitFrames/"+"ci_mask.tga").convert("RGBA")
character_image = Image.new('RGBA', (256, 256))
character_image.paste(ci, (int(image_x), int(image_y)))
character_image.paste(character_image, mask)
img.paste(character_image, (0, 0), mask)
img.paste(cb, (0, 0), cb)
img.save("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 256x256.tga")
mi = Image.open("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 256x256.tga")
mi = mi.resize((128, 128))
mi.save("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 128x128.tga")
si = Image.open("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 256x256.tga")
si = si.resize((64, 64))
si.save("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 64x64.tga")
si = Image.open("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 256x256.tga")
si = si.resize((32, 32))
si.save("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 32x32.tga")
return ("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 256x256.tga")
if ui_type == "_major_gods":
card_size = int(image_width), int(image_height)
img = Image.new('RGBA', (64, 64))
cb = Image.open("./GodPortraitFrames/"+"blank_icon.png")
ci = Image.open(user_image)
ci = ci.resize(card_size)
img.paste(ci, (int(image_x), int(image_y)))
img.paste(cb, (0, 0), cb)
img.save("./Mods/"+current_mod_opened+"/textures/icons/improvement "+god_name+" icon.tga")
img.save("./Mods/"+current_mod_opened+"/textures/icons/god major "+god_name+" icons 64.tga")
return ("./Mods/"+current_mod_opened+"/textures/icons/god major "+god_name+" icons 64.tga")
if ui_type == "_minor_gods":
card_size = int(image_width), int(image_height)
img = Image.new('RGBA', (256, 256))
cb = Image.open("./GodPortraitFrames/"+current_civilization+"_card_background.png")
ci = Image.open(user_image)
ci = ci.resize(card_size)
img.paste(ci, (int(image_x), int(image_y)))
img.paste(cb, (0, 0), cb)
img.save("./Mods/"+current_mod_opened+"/textures/god minor portrait "+current_civilization.lower()+" "+god_name+".tga")
return ("./Mods/"+current_mod_opened+"/textures/god minor portrait "+current_civilization.lower()+" "+god_name+".tga")
#"./Mods/atlantean_portraits_replacer/textures\ui\ui god gaia 256x256.tga"
def get_god_portrait_as_png(current_mod_opened, god_name, god_type, current_civilization):
#print("./Mods/"+current_mod_opened+"/textures/"+"ui/"+"ui god "+god_name +" 256x256.tga")
if (god_type == "_ui_gods"):
if os.path.exists(("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 256x256.tga")) == True:
return("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god_name+" 256x256.tga")
else:
return ("./GodPortraitFrames/"+"ui_god_"+current_civilization+".png")
if (god_type == "_major_gods"):
if os.path.exists(("./Mods/"+current_mod_opened+"/textures/icons/god major "+god_name+" icons 64.tga")) == True:
return("./Mods/"+current_mod_opened+"/textures/icons/god major "+god_name+" icons 64.tga")
else:
return ("./GodPortraitFrames/"+"blank_icon.png")
if (god_type == "_minor_gods"):
if os.path.exists(("./Mods/"+current_mod_opened+"/textures/god minor portrait "+current_civilization.lower()+" "+god_name+".tga")) == True:
return("./Mods/"+current_mod_opened+"/textures/god minor portrait "+current_civilization.lower()+" "+god_name+".tga")
else:
return ("./GodPortraitFrames/"+current_civilization+"_card_background.png")
def create_new_mod_folder(name):
if check_if_mod_exists(name) == False and name != "":
#create parent mod folder
path = os.path.join(parent_dir, name)
os.mkdir(path)
create_read_publishinfo_file(name)
#print(parent_dir, name + "textures")
#create texture folder
path = os.path.join(parent_dir, name + "/textures")
os.mkdir(path)
#add icons folder to texures
path = os.path.join(parent_dir, name + "/textures/icons")
os.mkdir(path)
#add ui to textures
path = os.path.join(parent_dir, name + "/textures/ui")
os.mkdir(path)
create_workshop_image(name)
def delete_mod(path):
shutil.rmtree(path, ignore_errors=True)
def get_all_current_mods():
mods = []
for folder_name in os.listdir("./Mods/"):
#print(folder_name)
mods.append({"name": folder_name, "path": ('./Mods/'+folder_name)})
return mods
def create_read_publishinfo_file(mod_name):
if check_if_mod_exists(mod_name) == True:
f = open(('./Mods/'+mod_name+"/_publishinfo.txt"),"w+")
f.write("Visibility=Public\n")
f.write("Description=\n")
f.close
def get_read_publishinfo_file_description(mod_name):
if check_if_mod_exists(mod_name) == True:
f = open(('./Mods/'+mod_name+"/_publishinfo.txt"),"r")
content = f.read()
#print(content.replace("Visibility=Public", "").replace("Description=", ""))
return content.replace("Visibility=Public", "").replace("Description=", "")
def update_publishinfo_file_description(mod_name, description):
#print(mod_name, description)
file = open(('./Mods/'+mod_name+"/_publishinfo.txt"),"r+")
file.truncate(0)
file.close()
f = open(('./Mods/'+mod_name+"/_publishinfo.txt"),"w+")
f.write("Visibility=Public\n")
f.write("Description="+description.strip()+"\n")
f.close