-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgrab_every_damn_entity.py
108 lines (95 loc) · 3.55 KB
/
grab_every_damn_entity.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
#!/usr/bin/python
"""
Go through and place all entities from a folder into a scene
Chris Sprance
Entrada interactive
"""
# glob looks through files in a smart way
import general
import fnmatch
import os
from BeautifulSoup import BeautifulSoup as BS
class EntityGrabber(object):
"""
Grabs entities from a folder and places them in the sandbox editor
This is because a lot of time you need to test a lot of items and dragging them by hand blows!
On Script Activation it will Open a file dialog and ask you to choose a folder full of entities you would like to spawn
These xml files will be scanned for there item names and that will be used to spawn items in a short distance
from each other and then select them all so you can quickly shift click to place the lot of items
"""
def __init__(self):
super(EntityGrabber, self).__init__()
# general.clear_selection()
self.folder = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
"..",
"..",
"GameSDK",
"Scripts",
"Entities",
"Items",
"XML",
)
)
print(self.folder)
self.file_type = "*.xml"
self.items = list()
self.item_names = list() # a list of ItemNames from xml files
self.xml_files = list() # a list of a xml file paths
self.exclude_list = self.get_excluded_files()
def get_all_damn_xmls(self):
"""gets all the xmls files from a self.folder recursively"""
for root, dirnames, filenames in os.walk(self.folder):
for filename in fnmatch.filter(filenames, self.file_type):
self.xml_files.append(os.path.join(root, filename))
def get_names_from_xml(self):
"""gets all the item names from self.xml_files"""
for xml in self.xml_files:
with open(os.path.normpath(xml), "r") as f:
soup = BS(f.readline())
self.item_names.append(soup.find("item")["name"])
def add_xmls(self):
"""spawn in each of our items from self.item_names and then select them"""
num_cols = 25
x = 0
num_added = 0
for idx, item in enumerate(self.item_names):
if idx % num_cols == 0:
x += 1
if item not in self.exclude_list:
self.items.append(
general.new_object("Entity", item, "", x, idx % num_cols, 0)
)
num_added += 1
else:
idx -= 1
print(
"Added %s CGF Files to the map. Thanks for adding every damn entity!"
% num_added
)
# clear the selection and add the new items to the selection
def start(self):
"""main process to run after instantiating class"""
# find all the damn cgfs
self.get_all_damn_xmls()
# get the names from the xml
self.get_names_from_xml()
# add them all to the map
self.add_xmls()
general.select_objects(self.items)
@staticmethod
def get_excluded_files():
with open(
os.path.join(
os.path.dirname(os.path.realpath(__file__)), "excluded_entities.txt"
),
"r",
) as f:
return f.read().splitlines()
def main():
eg = EntityGrabber()
eg.start()
# run the program
if __name__ == "__main__":
main()