-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path__init__.py
177 lines (144 loc) · 6.11 KB
/
__init__.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
171
172
173
174
175
176
177
bl_info = {
"name": "PoP map",
"author": "Sphere",
"version": (0, 3),
"blender": (4, 0, 0),
"location": "File > Import > PoP map",
"description": "Import PoP map",
"category": "Import"}
import bpy
import bpy.ops
import bpy_extras
import os
from bpy.props import StringProperty, BoolProperty
from io_scene_pop import popmap
class ImportPopWow(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
bl_idname = "import_scene.popwow"
bl_label = "Import PoP wow"
bl_description = "Opens decompressed .bin files and imports the " \
"contained map."
bl_options = {'UNDO'}
filename_ext = ".dec"
filter_glob: StringProperty(default="*.dec", options={'HIDDEN'})
filepath: StringProperty(name="File path")
def error(self, msg):
self.report({'ERROR'}, msg)
def execute(self, context):
if "wow" in self.filepath:
wow_hashes = popmap.create_wowlist(os.path.dirname(
self.filepath))
popmap.import_wow(self.filepath, context, False, wow_hashes)
return {'FINISHED'}
else:
self.report({'ERROR'}, "Selected file does not contain 'wow'!")
return {'CANCELLED'}
class ImportPopWows(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
bl_idname = "import_scene.popmaps"
bl_label = "Import PoP wows"
bl_options = {'UNDO'}
filename_ext = ""
filter_glob: StringProperty(default="", options={'HIDDEN'})
directory: StringProperty(subtype='DIR_PATH')
textures_only: BoolProperty(name="Textures only",
description="Whether to import only the "
"textures")
def execute(self, context):
wow_hashes = popmap.create_wowlist(self.directory)
for file in os.listdir(self.directory):
path = os.path.join(self.directory, file)
if (os.path.isfile(path) and path.endswith(".dec") and
"wow" in path):
try:
popmap.import_wow(path, context, self.textures_only,
wow_hashes)
except:
raise RuntimeError("Error while importing '" + file +
"'!")
return {'FINISHED'}
class ImportPopWol(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
bl_idname = "import_scene.popwol"
bl_label = "Import PoP wol"
bl_description = "Opens decompressed .bin files and imports the " \
"contained maps."
bl_options = {'UNDO'}
filename_ext = ".dec"
filter_glob: StringProperty(default="*.dec", options={'HIDDEN'})
filepath: StringProperty(name="File path")
def error(self, msg):
self.report({'ERROR'}, msg)
def execute(self, context):
if "wol" in self.filepath:
wow_hashes = popmap.create_wowlist(os.path.dirname(
self.filepath))
popmap.import_wol(self.filepath, context, wow_hashes)
return {'FINISHED'}
else:
self.report({'ERROR'}, "Selected file does not contain 'wol'!")
return {'CANCELLED'}
class ImportPopCurrWol(bpy.types.Operator):
bl_idname = "import_scene.popcurrwol"
bl_label = "Import current wol"
bl_description = "Import the wol of the currently selected trigger."
bl_options = {'UNDO'}
def error(self, msg):
self.report({'ERROR'}, msg)
def execute(self, context):
if "wol_to_load" in context.active_object:
path = context.active_object["wol_to_load"]
# delete everything
bpy.ops.object.mode_set(mode='OBJECT')
for object in context.scene.objects:
object.hide_set(False)
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
wow_hashes = popmap.create_wowlist(os.path.dirname(path))
popmap.import_wol(path, context, wow_hashes)
return {'FINISHED'}
else:
self.report({'ERROR'}, "The selected object is not a valid "
"loading trigger!")
return {'CANCELLED'}
class POP_PT_pop_panel(bpy.types.Panel):
"""A Custom Panel in the Viewport Toolbar"""
bl_label = "PoP Tools"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
def draw(self, context):
layout = self.layout
object = context.active_object
if object and ("out_of_file" in object):
row = layout.row()
row.label(text="Object is from file:")
row = layout.row()
row.label(text="'" + object["out_of_file"] + ".dec'")
if "wol_to_load" in object:
layout.separator()
row = layout.row()
row.label(text="This trigger loads:")
row = layout.row()
row.label(text="'" +
os.path.basename(object["wol_to_load"]) + "'")
row = layout.row()
row.operator("import_scene.popcurrwol",
text="Activate Trigger")
def menu_import(self, context):
self.layout.operator(ImportPopWol.bl_idname, text="PoP wol")
self.layout.operator(ImportPopWow.bl_idname, text="PoP wow")
self.layout.operator(ImportPopWows.bl_idname, text="PoP wows")
def register():
bpy.utils.register_class(ImportPopWow)
bpy.utils.register_class(ImportPopWows)
bpy.utils.register_class(ImportPopWol)
bpy.utils.register_class(ImportPopCurrWol)
bpy.utils.register_class(POP_PT_pop_panel)
bpy.types.TOPBAR_MT_file_import.append(menu_import)
def unregister():
bpy.utils.unregister_class(ImportPopWow)
bpy.utils.unregister_class(ImportPopWows)
bpy.utils.unregister_class(ImportPopWol)
bpy.utils.unregister_class(ImportPopCurrWol)
bpy.utils.unregister_class(POP_PT_pop_panel)
bpy.types.TOPBAR_MT_file_import.remove(menu_import)
if __name__ == "__main__":
unregister()
register()