-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate_batch_icons.py
170 lines (139 loc) · 5.77 KB
/
create_batch_icons.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
170
"""
If this is borken for you it's because it's absolute paths. I'll work on that :)
This file contains code to create icons
you need two files
1. icon_todo.txt with a list of mtl and xml names to create icons for
object/path/to1.mtl,XmlItemName1
object/path/to2.mtl,XmlItemName2
object/path/to3.mtl,XmlItemName3
object/path/to4.mtl,XmlItemName4
2. icon_done.txt
log file of all created icons used to rename the last created icon
CLEAR THIS OUT BEFORE YOU START!
3. CLEAR OUT YOUR SCREENSHOTS FOLDER SO IT'S EMPTY!
CLEAR OUT D:\perforce\dev\user\screenshots
4. Open icon_level.cry
5. run icon_object_add.py and set the name of the Item you are creating or Group Category in the spawner
If you are retaking an icons grab the position of the items using icon_object_get.py and it will update the object
to the stored pose of the icon
6. Open python Scripts Panel
7. Click create_batch_icons.py until it tells you to stop clicking
8. Run the photoshop action - This automatically creates the icons in the correct spot
9. Add and commit icons added from photoshop action.
"""
import os
import time
import general
class IconBatcher(object):
"""Creates Icons"""
def __init__(self):
super(IconBatcher, self).__init__()
self.icon_file_todo = os.path.abspath(
os.path.join(os.path.dirname(__file__), "iconfile_todo.txt"))
self.icon_file_done = os.path.abspath(
os.path.join(os.path.dirname(__file__), "iconfile_done.txt"))
self.screenshot_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__),'..','..','user','screenshots'))
self.scrnsht_0 = os.path.abspath(
os.path.join(self.screenshot_dir, "screenshot0000.jpg"))
self.output_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__),'..','..','user','screenshots'))
self.xml = str()
self.mtl = str()
self.last_xml = str()
self.last_mtl = str()
self.first_shot = False
self.get_set_xml_mtl()
self.first_setup()
self.last_image = False
self.icon_img = str()
def first_setup(self):
# if the screenshot doesn't exist do some initial setup
if not os.path.exists(self.scrnsht_0):
self.first_shot = True
# create the first screenshot
self.take_shot()
# set the first material
self.set_mat()
# set the done file without removing the top linein todo
# self.write_mat()
else:
self.get_set_last_xml_mtl()
def clear_done_file(self):
print('clearing done file')
data = []
with open(self.icon_file_done, 'w') as fout:
fout.writelines(data)
def get_set_last_xml_mtl(self):
'''reads a icon_done and gets and sets the top mtl and xml from it'''
with open(self.icon_file_done, 'r') as f:
try:
mtl, xml = f.readline().rstrip().split(',')
self.last_xml = xml
self.last_mtl = mtl
except Exception as e:
self.last_xml = self.xml
self.last_mtl = self.mtl
def get_set_xml_mtl(self):
'''reads a file and gets and sets the top mtl and xml from it'''
try:
with open(self.icon_file_todo, 'r') as f:
mtl, xml = f.readline().rstrip().split(',')
self.xml = xml
self.mtl = mtl
except Exception as e:
self.last_image = True
general.message_box_ok('No More Icons Stop Clicking')
self.rename_last_image()
def rename_last_image(self):
self.get_set_last_xml_mtl()
os.rename(self.scrnsht_0, '%s\%s_48.jpg' % (self.screenshot_dir, self.last_xml))
self.last_image = True
def write_mat(self):
'''writes the self.mtl and self.xml to self.icon_file_done as self.mtl,self.xml'''
with open(self.icon_file_done, 'r+') as f:
content = f.read()
f.seek(0, 0)
line = '%s,%s' % (self.mtl, self.xml)
f.write(line.rstrip('\r\n') + '\n' + content)
def take_shot(self):
# take screenshot
time.sleep(0.05)
general.run_console('r_getScreenshot 1')
def set_mat(self):
general.set_custom_material('icon_object_shot', str(self.mtl))
def rename_image(self):
# renames self.scrnsht_0 to self.xml
try:
self.icon_img = '%s\%s_48.jpg' % (self.screenshot_dir, self.last_xml)
os.rename(self.scrnsht_0, self.icon_img)
self.process_image()
except Exception as e:
print (e)
os.remove(self.scrnsht_0)
def process_image(self):
print ('processing %s' % self.icon_img)
def remove_top_line(self):
with open(self.icon_file_todo, 'r') as fin:
data = fin.read().splitlines(True)
with open(self.icon_file_todo, 'w') as fout:
fout.writelines(data[1:])
def button_pressed(self):
'''this is called each time the button is pressed in the editor'''
if self.first_shot:
print ('Initial Set up')
else:
print (' renaming image for %s' % self.last_xml)
self.rename_image()
print ('applying %s to icon_object_shot' % self.mtl)
self.set_mat()
print ('creating image for %s' % self.xml)
self.take_shot()
print ('removing top line in todo')
self.remove_top_line()
self.write_mat()
def main():
ib = IconBatcher()
ib.button_pressed()
if __name__ == '__main__':
main()