Check if user set a prop library path when importing a BattleMap

This commit is contained in:
Pyogenics
2025-04-11 13:24:43 +01:00
parent 4851dec975
commit 1fc2856e84

View File

@@ -31,6 +31,7 @@ from .BattleMap import BattleMap
from .BattleMapBlenderImporter import BattleMapBlenderImporter from .BattleMapBlenderImporter import BattleMapBlenderImporter
from .LightmapData import LightmapData from .LightmapData import LightmapData
from os.path import isdir
from time import time from time import time
''' '''
@@ -39,7 +40,7 @@ Addon preferences
class Preferences(AddonPreferences): class Preferences(AddonPreferences):
bl_idname = __package__ bl_idname = __package__
propLibrarySourcePath: StringProperty(name="Prop library source path", subtype='FILE_PATH') propLibrarySourcePath: StringProperty(name="Prop library source path", subtype='DIR_PATH')
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
@@ -74,7 +75,7 @@ class ImportA3D(Operator, ImportHelper):
objects = [] objects = []
for file in self.files: for file in self.files:
filepath = self.directory + file.name filepath = f"{self.directory}/{file.name}"
# Read the file # Read the file
print(f"Reading A3D data from {filepath}") print(f"Reading A3D data from {filepath}")
modelData = A3D() modelData = A3D()
@@ -122,7 +123,6 @@ class ImportBattleMap(Operator, ImportHelper):
def execute(self, context): def execute(self, context):
print(f"Reading BattleMap data from {self.filepath}") print(f"Reading BattleMap data from {self.filepath}")
importStartTime = time() importStartTime = time()
# lightmapdata files only exist for remaster maps # lightmapdata files only exist for remaster maps
@@ -134,12 +134,15 @@ class ImportBattleMap(Operator, ImportHelper):
print("Couldn't open lightmapdata file, ignoring") print("Couldn't open lightmapdata file, ignoring")
self.import_lightmapdata = False self.import_lightmapdata = False
# read map data
mapData = BattleMap() mapData = BattleMap()
with open(self.filepath, "rb") as file: with open(self.filepath, "rb") as file:
mapData.read(file) mapData.read(file)
# Import data into blender # Import data into blender
preferences = context.preferences.addons[__package__].preferences # TODO: check if this is set before proceeding preferences = context.preferences.addons[__package__].preferences
if not isdir(preferences.propLibrarySourcePath):
raise RuntimeError("Please set a valid prop library folder in addon properties!")
mapImporter = BattleMapBlenderImporter(mapData, lightmapData, preferences.propLibrarySourcePath, self.map_scale_factor, self.import_static_geom, self.import_collision_geom, self.import_spawn_points, self.import_lightmapdata) mapImporter = BattleMapBlenderImporter(mapData, lightmapData, preferences.propLibrarySourcePath, self.map_scale_factor, self.import_static_geom, self.import_collision_geom, self.import_spawn_points, self.import_lightmapdata)
objects = mapImporter.importData() objects = mapImporter.importData()