Skip to content

Commit 93aaa9c

Browse files
authored
Merge pull request #72 from MrClock8163/dev
v2.4.1
2 parents 0398697 + 95744bf commit 93aaa9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+642
-603
lines changed

Arma3ObjectBuilder/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## [v2.4.1](https://github.com/MrClock8163/Arma3ObjectBuilder/releases/tag/v2.4.1) (Blender 2.90 -> 4.2)
4+
5+
### Changes
6+
7+
- internal handling of the P3D data was simplified and improved
8+
- internal code structure and dependencies were cleaned up
9+
- improved add-on reloading
10+
11+
### Fixed
12+
13+
- named properties were not properly lowercased with the Force Lowercase export option during P3D export
14+
- animation action property classes were not properly unregistered when the add-on was deactivated or reloaded
15+
316
## [v2.4.0](https://github.com/MrClock8163/Arma3ObjectBuilder/releases/tag/v2.4.0) (Blender 2.90 -> 4.2)
417

518
### Added

Arma3ObjectBuilder/__init__.py

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,56 @@
22
"name": "Arma 3 Object Builder",
33
"description": "Collection of tools for editing Arma 3 content",
44
"author": "MrClock (present add-on), Hans-Joerg \"Alwarren\" Frieden (original ArmaToolbox add-on)",
5-
"version": (2, 4, 0),
5+
"version": (2, 4, 1),
66
"blender": (2, 90, 0),
77
"location": "Object Builder panels",
8-
"warning": "",
8+
"warning": "Development",
99
"doc_url": "https://mrcmodding.gitbook.io/arma-3-object-builder/home",
1010
"tracker_url": "https://github.com/MrClock8163/Arma3ObjectBuilder/issues",
1111
"category": "Import-Export"
1212
}
1313

1414

15+
import os
16+
1517
if "bpy" in locals():
16-
import importlib
18+
from importlib import reload
1719

18-
importlib.reload(props)
19-
importlib.reload(ui)
20-
importlib.reload(flagutils)
21-
22-
else:
23-
from . import props
24-
from . import ui
25-
from .utilities import flags as flagutils
20+
if "utilities" in locals():
21+
reload(utilities)
22+
if "io" in locals():
23+
reload(io)
24+
if "props" in locals():
25+
reload(props)
26+
if "ui" in locals():
27+
reload(ui)
2628

2729
import bpy
2830

2931

32+
addon_prefs = None
33+
addon_dir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
34+
addon_icons = {}
35+
36+
def get_icon(name):
37+
icon = 0
38+
try:
39+
icon = addon_icons[addon_prefs.icon_theme.lower()][name].icon_id
40+
except Exception:
41+
pass
42+
43+
return icon
44+
45+
def get_prefs():
46+
return addon_prefs
47+
48+
49+
from . import utilities
50+
from . import io
51+
from . import props
52+
from . import ui
53+
54+
3055
def outliner_enable_update(self, context):
3156
if self.outliner == 'ENABLED' and ui.tool_outliner.depsgraph_update_post_handler not in bpy.app.handlers.depsgraph_update_post:
3257
bpy.app.handlers.depsgraph_update_post.append(ui.tool_outliner.depsgraph_update_post_handler)
@@ -52,8 +77,7 @@ def execute(self, context):
5277
from winreg import OpenKey, QueryValueEx, HKEY_CURRENT_USER
5378
key = OpenKey(HKEY_CURRENT_USER, r"software\bohemia interactive\arma 3 tools")
5479
value, _type = QueryValueEx(key, "path")
55-
prefs = context.preferences.addons[__package__].preferences
56-
prefs.a3_tools = value
80+
addon_prefs.a3_tools = value
5781

5882
except Exception:
5983
self.report({'ERROR'}, "The Arma 3 Tools installation could not be found, it has to be set manually")
@@ -124,13 +148,13 @@ def poll(cls, context):
124148

125149
def invoke(self, context, event):
126150
prefs = context.preferences.addons[__package__].preferences
127-
flagutils.set_flag_vertex(self, prefs.flag_vertex)
151+
utilities.flags.set_flag_vertex(self, prefs.flag_vertex)
128152

129153
return context.window_manager.invoke_props_dialog(self)
130154

131155
def execute(self, context):
132156
prefs = context.preferences.addons[__package__].preferences
133-
prefs.flag_vertex = flagutils.get_flag_vertex(self)
157+
prefs.flag_vertex = utilities.flags.get_flag_vertex(self)
134158

135159
return {'FINISHED'}
136160

@@ -176,13 +200,13 @@ def poll(cls, context):
176200

177201
def invoke(self, context, event):
178202
prefs = context.preferences.addons[__package__].preferences
179-
flagutils.set_flag_face(self, prefs.flag_face)
203+
utilities.flags.set_flag_face(self, prefs.flag_face)
180204

181205
return context.window_manager.invoke_props_dialog(self)
182206

183207
def execute(self, context):
184208
prefs = context.preferences.addons[__package__].preferences
185-
prefs.flag_face = flagutils.get_flag_face(self)
209+
prefs.flag_face = utilities.flags.get_flag_face(self)
186210

187211
return {'FINISHED'}
188212

@@ -345,30 +369,54 @@ def draw(self, context):
345369
)
346370

347371

372+
def register_icons():
373+
import bpy.utils.previews
374+
375+
themes_dir = os.path.join(addon_dir, "icons")
376+
for theme in os.listdir(themes_dir):
377+
theme_icons = bpy.utils.previews.new()
378+
379+
icons_dir = os.path.join(themes_dir, theme)
380+
for filename in os.listdir(icons_dir):
381+
theme_icons.load(os.path.splitext(os.path.basename(filename))[0].lower(), os.path.join(icons_dir, filename), 'IMAGE')
382+
383+
addon_icons[theme.lower()] = theme_icons
384+
385+
386+
def unregister_icons():
387+
import bpy.utils.previews
388+
389+
for icon in addon_icons.values():
390+
bpy.utils.previews.remove(icon)
391+
392+
addon_icons.clear()
393+
394+
348395
def register():
349396
from bpy.utils import register_class
350-
from .utilities import generic
351-
397+
352398
print("Registering Arma 3 Object Builder ( '" + __package__ + "' )")
353399

354400
for cls in classes:
355401
register_class(cls)
356402

403+
global addon_prefs
404+
addon_prefs = bpy.context.preferences.addons[__package__].preferences
405+
357406
for mod in modules:
358407
mod.register()
359408

360-
generic.register_icons()
361-
409+
register_icons()
410+
362411
print("Register done")
363412

364413

365414
def unregister():
366415
from bpy.utils import unregister_class
367-
from .utilities import generic
368416

369417
print("Unregistering Arma 3 Object Builder ( '" + __package__ + "' )")
370418

371-
generic.unregister_icons()
419+
unregister_icons()
372420

373421
for mod in reversed(modules):
374422
mod.unregister()

Arma3ObjectBuilder/blender_manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type = "add-on"
55
id = "Arma3ObjectBuilder"
66
name = "Arma 3 Object Builder"
77
tagline = "Comprehensive add-on for modding Arma 3"
8-
version = "2.4.0"
8+
version = "2.4.1"
99
blender_version_min = "4.2.0"
1010
website = "https://mrcmodding.gitbook.io/arma-3-object-builder/home"
1111
tags = ["Import-Export", "Game Engine", "Object"]

Arma3ObjectBuilder/io/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,46 @@
1+
if "binary_handler" in locals():
2+
from importlib import reload
3+
4+
if "binary_handler" in locals():
5+
reload(binary_handler)
6+
if "compression" in locals():
7+
reload(compression)
8+
if "data_asc" in locals():
9+
reload(data_asc)
10+
if "data_p3d" in locals():
11+
reload(data_p3d)
12+
if "data_rap" in locals():
13+
reload(data_rap)
14+
if "data_rtm" in locals():
15+
reload(data_rtm)
16+
if "data_tbcsv" in locals():
17+
reload(data_tbcsv)
18+
if "export_asc" in locals():
19+
reload(export_asc)
20+
if "export_mcfg" in locals():
21+
reload(export_mcfg)
22+
if "export_p3d" in locals():
23+
reload(export_p3d)
24+
if "export_rtm" in locals():
25+
reload(export_rtm)
26+
if "export_tbcsv" in locals():
27+
reload(export_tbcsv)
28+
if "import_armature" in locals():
29+
reload(import_armature)
30+
if "import_asc" in locals():
31+
reload(import_asc)
32+
if "import_mcfg" in locals():
33+
reload(import_mcfg)
34+
if "import_p3d" in locals():
35+
reload(import_p3d)
36+
if "import_rtm" in locals():
37+
reload(import_rtm)
38+
if "import_tbcsv" in locals():
39+
reload(import_tbcsv)
40+
41+
142
from . import binary_handler
43+
from . import compression
244
from . import data_asc
345
from . import data_p3d
446
from . import data_rap
@@ -8,8 +50,10 @@
850
from . import export_mcfg
951
from . import export_p3d
1052
from . import export_rtm
53+
from . import export_tbcsv
1154
from . import import_armature
1255
from . import import_asc
1356
from . import import_mcfg
1457
from . import import_p3d
1558
from . import import_rtm
59+
from . import import_tbcsv

Arma3ObjectBuilder/io/binary_handler.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55

66
import struct
7+
import functools
8+
import itertools
79

810

911
def read_byte(file):
@@ -76,33 +78,21 @@ def read_char(file, count = 1):
7678
# In theory all strings in BI files should be strictly ASCII,
7779
# but on the off chance that a corrupt character is present, the method would fail.
7880
# Therefore using UTF-8 decoding is more robust, and gives the same result for valid ASCII values.
81+
# https://stackoverflow.com/a/32775270
7982
def read_asciiz(file):
80-
res = b''
81-
82-
while True:
83-
a = file.read(1)
84-
if a == b'\x00' or a == b'':
85-
break
86-
87-
res += a
88-
89-
return res.decode('utf8', errors="replace")
83+
eof = iter(functools.partial(file.read, 1), "")
84+
return b"".join(itertools.takewhile(b"\x00".__ne__, eof)).decode('utf8', errors="replace")
9085

9186
def read_asciiz_field(file, field_len):
9287
field = file.read(field_len)
9388
if len(field) < field_len:
9489
raise EOFError("ASCIIZ field ran into unexpected EOF")
9590

96-
result = bytearray()
97-
for value in field:
98-
if value == 0:
99-
break
100-
101-
result.append(value)
102-
else:
91+
parts = field.split(b"\x00")
92+
if len(parts) < 2:
10393
raise ValueError("ASCIIZ field length overflow")
10494

105-
return result.decode('utf8', errors="replace")
95+
return parts[0].decode('utf8', errors="replace")
10696

10797
def read_lascii(file):
10898
length = read_byte(file)

0 commit comments

Comments
 (0)