Skip to content

Commit

Permalink
ensure proper scene namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
timhendriks93 committed May 16, 2024
1 parent 6584e4f commit 8089572
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions addon/ops/arduino_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def export(self, positions, filepath, context):
lines = self.join_by_chunk_size(commands, self.chunk_size)

if self.namespace:
content += f"\nnamespace {context.scene.name} {{\n"
scene_name = self.format_scene_name()
content += f"\nnamespace {scene_name} {{\n"

content += (
f"\nconst byte FPS = {fps};"
Expand All @@ -55,7 +56,7 @@ def export(self, positions, filepath, context):
content += f'const byte PROGMEM ANIMATION_DATA[LENGTH] = {{\n{lines}}};\n'

if self.namespace:
content += f"\n}} // namespace {context.scene.name}\n"
content += f"\n}} // namespace {scene_name}\n"

with open(filepath, 'w', encoding='utf-8') as file:
file.write(content)
Expand All @@ -73,3 +74,13 @@ def join_by_chunk_size(cls, iterable, chunk_size):
@classmethod
def format_hex(cls, byte):
return f'{byte:#04x}'

@classmethod
def format_scene_name(cls):
valid_chars = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_')
scene_name = ''.join(c if c in valid_chars else '_' for c in bpy.context.scene.name)

if scene_name[0].isdigit():
scene_name = '_' + scene_name

return scene_name

0 comments on commit 8089572

Please sign in to comment.