2026-09-30 03:06:43 +02:00
""" Aetheria ' s Blender-side view of one ship file: a typed HullData record and the ShipAuthoring visual it names.
2026-09-26 18:14:36 +02:00
2026-09-30 03:06:43 +02:00
The schemas and authority live in Aetheria ' s C# HullData and ShipAuthoring types. This module edits the hull ' s grid
and hardpoints and the visual ' s lines, and preserves the C# schema catalog and every slot it does not edit. Brokkr
supplies the Blender host and CultLib Python dependency path .
2026-09-26 18:14:36 +02:00
"""
from __future__ import annotations
import sys
2026-09-26 19:23:01 +02:00
import hashlib
2026-09-26 18:14:36 +02:00
from dataclasses import replace
from datetime import datetime , timezone
from pathlib import Path
2026-09-30 03:06:43 +02:00
from typing import Any , NamedTuple
2026-09-26 18:14:36 +02:00
SCHEMA = " aetheria.ship_authoring "
2026-09-30 03:06:43 +02:00
HULL_SCHEMA = " aetheria.hulldata "
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
# MessagePack slots of the C# types, which own them (ShipAuthoring, ItemData.Shape, HullData.Hardpoints,
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
# HardpointData). RETIRED_HULL_SLOT is the ShipAuthoring key that held the embedded hull before S1; no member owns it now. ShipSchemaPinTests in tests/Aetheria.Shared.Tests fails when any number or name below
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
# disagrees with those types' [Key] attributes, so a renumbered or added member cannot drift silently.
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
RETIRED_HULL_SLOT = 1
2026-10-03 17:07:10 +02:00
MODEL_ASSET_SLOT = 2 # ShipAuthoring.ModelAsset
ANCHORS_SLOT = 3 # ShipAuthoring.Anchors
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
SCHEMATIC_LINES_SLOT = 4 # ShipAuthoring.SchematicLines
HULL_SHAPE_SLOT = 5 # ItemData.Shape
HULL_HARDPOINTS_SLOT = 23 # HullData.Hardpoints
# HardpointData member names in slot order; a hardpoint row is one value per name, and any slot past the last
# name belongs to a later schema and is carried through untouched.
HARDPOINT_MEMBERS = ( " Type " , " Position " , " Shape " , " Transform " , " Rotation " , " Armor " , " FiringArc " )
2026-10-03 17:07:10 +02:00
# ShipAnchor member names in slot order; as for hardpoints, slots past the last name are carried through by anchor Id.
ANCHOR_MEMBERS = ( " Id " , " Role " , " ModelNodeId " , " ParentId " , " Order " )
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
# Enum member names in value order (HardpointType, ItemRotation).
HARDPOINT_TYPE_NAMES = ( " Hull " , " Tool " , " Thermal " , " Thruster " , " WarpDrive " , " Reactor " , " Radiator " ,
Delete the aether drive: behaviour, union 12, hardpoint type, aggregates, settings, presenters, prefab
AetherDriveData and AetherDrive, Union(12) (now a retired-do-not-reuse comment, as 26 is),
HardpointType.AetherDrive (last member, nothing shifts), Ship's drive sets, aggregates and
Axis write, the five request-field rows, GameplaySettings Aether multipliers, ShipInstance's
drive particles, SchematicDisplay's RPM display and AetherDriveUi, the undock refusal's drive
clause, the drive prefab and material, and AetherDb's drive roles and brownout row. The
design is kept at parked/aether-drive.
Adds EveryShippedShipHullHasATopSpeed. ARPG.unity still holds stale serialized references to
the removed SchematicDisplay fields and the RPM Display object; the next commit removes them.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-08 14:04:28 +02:00
" Shield " , " Sensors " , " Energy " , " Ballistic " , " Launcher " , " ControlModule " )
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
ROTATION_NAMES = ( " None " , " CounterClockwise " , " Reversed " , " Clockwise " )
2026-10-10 09:49:39 +02:00
# ShipAuthoringStore.RequireShipId's rule, mirrored so New Ship refuses before it touches anything; ShipSchemaPinTests
# pins both constants and valid_ship_id to the C# rule.
SHIP_ID_CHARS = " abcdefghijklmnopqrstuvwxyz0123456789._- "
RESERVED_SHIP_IDS = ( " con " , " prn " , " aux " , " nul " , " com1 " , " com2 " , " com3 " , " com4 " , " com5 " , " com6 " , " com7 " , " com8 " , " com9 " ,
" lpt1 " , " lpt2 " , " lpt3 " , " lpt4 " , " lpt5 " , " lpt6 " , " lpt7 " , " lpt8 " , " lpt9 " )
def valid_ship_id ( ship_id : str ) - > bool :
""" True when ShipAuthoringStore.RequireShipId would accept the ID: lower-case ASCII letters, digits, dots,
underscores and hyphens , starting with a letter or digit , not ending in a dot , and whose stem before the first dot
is not a Windows device name . """
return ( bool ( ship_id ) and ship_id [ 0 ] not in " ._- " and all ( c in SHIP_ID_CHARS for c in ship_id )
and not ship_id . endswith ( " . " ) and ship_id . split ( " . " ) [ 0 ] not in RESERVED_SHIP_IDS )
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
def decode_hardpoint ( row : list [ Any ] ) - > dict [ str , Any ] :
return dict ( zip ( HARDPOINT_MEMBERS , row ) )
def encode_hardpoint ( * * fields : Any ) - > list [ Any ] :
if set ( fields ) != set ( HARDPOINT_MEMBERS ) :
raise ValueError ( f " A hardpoint row needs exactly { ' , ' . join ( HARDPOINT_MEMBERS ) } " )
return [ fields [ name ] for name in HARDPOINT_MEMBERS ]
2026-09-26 18:14:36 +02:00
def _libraries ( cultlib_packages : str ) :
source = Path ( cultlib_packages ) / " cultcache-py " / " src "
if source . exists ( ) and str ( source ) not in sys . path :
sys . path . insert ( 0 , str ( source ) )
import cultcache_py # type: ignore
import msgpack # type: ignore
return cultcache_py , msgpack
2026-09-30 03:06:43 +02:00
class Record ( NamedTuple ) :
envelope : Any
body : list
class ShipFile ( NamedTuple ) :
store : Any
ship : Record # the ShipAuthoring visual
hull : Record # the HullData it belongs to
msgpack : Any
def read ( path : str , cultlib_packages : str ) - > ShipFile :
2026-09-26 18:14:36 +02:00
cultcache , msgpack = _libraries ( cultlib_packages )
store = cultcache . SingleFileMessagePackBackingStore ( path )
envelopes = store . pull_all ( )
ships = [ envelope for envelope in envelopes if envelope . type == SCHEMA ]
2026-09-30 03:06:43 +02:00
hulls = [ envelope for envelope in envelopes if envelope . type == HULL_SCHEMA ]
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
# Before S1 the hull lived inside the ship record. Saving such a file would preserve the stale hull under a ship that
# no longer reads it, so it is refused before anything else is said about its shape.
for envelope in ships :
body = msgpack . unpackb ( envelope . payload , raw = False )
if isinstance ( body , list ) and len ( body ) > RETIRED_HULL_SLOT and body [ RETIRED_HULL_SLOT ] is not None :
raise ValueError (
2026-10-10 09:49:39 +02:00
f " The ship file has a legacy embedded hull at retired key { RETIRED_HULL_SLOT } of the { SCHEMA } record; "
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
f " migrate it into its own { HULL_SCHEMA } record that names the visual, and drop key { RETIRED_HULL_SLOT } " )
2026-09-30 03:06:43 +02:00
if len ( envelopes ) != 2 or len ( ships ) != 1 or len ( hulls ) != 1 :
2026-10-10 09:49:39 +02:00
raise ValueError ( f " The ship file must hold exactly one { SCHEMA } record and one { HULL_SCHEMA } record " )
2026-09-30 03:06:43 +02:00
bodies = [ ]
for envelope in ( ships [ 0 ] , hulls [ 0 ] ) :
body = msgpack . unpackb ( envelope . payload , raw = False )
if not isinstance ( body , list ) :
2026-10-10 09:49:39 +02:00
raise ValueError ( f " The ship file has an incompatible { envelope . type } payload " )
2026-09-30 03:06:43 +02:00
bodies . append ( Record ( envelope , body ) )
ship , hull = bodies
if len ( ship . body ) < SCHEMATIC_LINES_SLOT + 1 :
2026-10-10 09:49:39 +02:00
raise ValueError ( f " The ship file has an incompatible { SCHEMA } payload " )
2026-09-30 03:06:43 +02:00
return ShipFile ( store , ship , hull , msgpack )
def _stamped ( record : Record , msgpack : Any ) :
return replace (
record . envelope ,
payload = msgpack . packb ( record . body , use_bin_type = True ) ,
stored_at = datetime . now ( timezone . utc ) . isoformat ( ) ,
)
2026-09-26 18:14:36 +02:00
def replace_lines ( path : str , cultlib_packages : str , lines : list [ list [ Any ] ] ) - > int :
2026-09-30 03:06:43 +02:00
file = read ( path , cultlib_packages )
2026-09-26 18:14:36 +02:00
if not lines :
raise ValueError ( " No Grease Pencil strokes were captured; the ship record was not changed " )
2026-09-30 03:06:43 +02:00
file . ship . body [ SCHEMATIC_LINES_SLOT ] = lines
file . store . push ( _stamped ( file . ship , file . msgpack ) )
2026-09-26 18:14:36 +02:00
return len ( lines )
2026-10-03 17:07:10 +02:00
def replace_visual ( path : str , cultlib_packages : str , expected_id : str , model_asset : str ,
anchors : list [ list [ Any ] ] ) - > int :
""" Writes the visual ' s model asset and anchor list (ShipAuthoring slots 2 and 3) and nothing else. Each anchor row is
ANCHOR_MEMBERS in order ; the slots past Order that the same anchor Id carried before are appended to it unchanged . """
file = read ( path , cultlib_packages )
if file . ship . body [ 0 ] != expected_id :
raise ValueError ( " The bound ship ID changed; rebind the collection " )
known = len ( ANCHOR_MEMBERS )
ids = set ( )
for anchor in anchors :
if len ( anchor ) != known :
raise ValueError ( f " Each anchor row needs exactly { ' , ' . join ( ANCHOR_MEMBERS ) } " )
anchor_id = anchor [ 0 ]
if not isinstance ( anchor_id , str ) or not anchor_id . strip ( ) :
raise ValueError ( " Every anchor needs an ID " )
if anchor_id in ids :
2026-10-10 09:49:39 +02:00
raise ValueError ( " An anchor ID is used twice " )
2026-10-03 17:07:10 +02:00
ids . add ( anchor_id )
previous = file . ship . body [ ANCHORS_SLOT ] if len ( file . ship . body ) > ANCHORS_SLOT else None
later = { row [ 0 ] : row [ known : ] for row in previous or [ ]
if isinstance ( row , list ) and len ( row ) > known and isinstance ( row [ 0 ] , str ) }
file . ship . body [ MODEL_ASSET_SLOT ] = model_asset
file . ship . body [ ANCHORS_SLOT ] = [ list ( anchor ) + later . get ( anchor [ 0 ] , [ ] ) for anchor in anchors ]
file . store . push ( _stamped ( file . ship , file . msgpack ) )
return len ( anchors )
2026-09-30 03:06:43 +02:00
def _hull_body ( file : ShipFile ) - > list :
if len ( file . hull . body ) < = HULL_HARDPOINTS_SLOT :
2026-09-26 19:23:01 +02:00
raise ValueError ( " Ship hull has an incompatible typed payload " )
2026-09-30 03:06:43 +02:00
return file . hull . body
def read_layout ( path : str , cultlib_packages : str ) :
file = read ( path , cultlib_packages )
hull = _hull_body ( file )
2026-10-10 09:49:39 +02:00
return hull [ HULL_SHAPE_SLOT ] [ 0 ] , hull [ HULL_HARDPOINTS_SLOT ] , layout_revision ( hull [ HULL_SHAPE_SLOT ] [ 0 ] , hull [ HULL_HARDPOINTS_SLOT ] )
2026-09-26 19:23:01 +02:00
2026-10-10 09:49:39 +02:00
def layout_revision ( shape : list [ Any ] , hardpoints : list [ list [ Any ] ] ) - > str :
""" The revision of a layout: a hash of its shape ([width, height, cells]) and hardpoint rows as the file stores
them . replace_layout returns it , Load records it , and Package compares the layout buffer ' s against the file ' s . """
import msgpack # type: ignore
return hashlib . sha256 ( msgpack . packb ( [ [ shape ] , hardpoints ] , use_bin_type = True ) ) . hexdigest ( )
2026-09-26 19:23:01 +02:00
def replace_layout ( path : str , cultlib_packages : str , expected_id : str , expected_revision : str ,
shape : list [ Any ] , hardpoints : list [ list [ Any ] ] ) - > str :
2026-09-30 03:06:43 +02:00
file = read ( path , cultlib_packages )
if file . ship . body [ 0 ] != expected_id :
2026-09-26 19:23:01 +02:00
raise ValueError ( " The bound ship ID changed; reload its layout " )
2026-09-30 03:06:43 +02:00
hull = _hull_body ( file )
2026-10-10 09:49:39 +02:00
if layout_revision ( hull [ HULL_SHAPE_SLOT ] [ 0 ] , hull [ HULL_HARDPOINTS_SLOT ] ) != expected_revision :
2026-09-26 19:23:01 +02:00
raise ValueError ( " The .cc layout changed since Load; reload before saving " )
width , height , cells = shape
if not ( 1 < = width < = 32 and 1 < = height < = 32 and len ( cells ) == width * height ) :
raise ValueError ( " Hull grid must be 1..32 cells wide and high with one value per cell " )
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
if not all ( type ( cell ) is bool for cell in cells ) :
raise ValueError ( " Hull grid cells must be booleans " )
2026-09-26 19:23:01 +02:00
if not any ( cells ) :
raise ValueError ( " Hull grid needs an occupied cell " )
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
known = len ( HARDPOINT_MEMBERS )
previous = { decode_hardpoint ( hp ) [ " Transform " ] : hp [ known : ] for hp in hull [ HULL_HARDPOINTS_SLOT ]
if isinstance ( hp , list ) and len ( hp ) > known and isinstance ( decode_hardpoint ( hp ) [ " Transform " ] , str ) }
2026-09-26 19:23:01 +02:00
updated_hardpoints = [ ]
for hardpoint in hardpoints :
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
fields = decode_hardpoint ( hardpoint )
mount = fields . get ( " Transform " )
if len ( hardpoint ) != known or not isinstance ( mount , str ) or not mount :
raise ValueError ( f " Each hardpoint needs { known } typed fields and a stable mount ID " )
hp_width , hp_height , hp_cells = fields [ " Shape " ] [ 0 ]
Ship S1 fixes: refuse the retired embedded hull, one body per hull, closed validator gaps
Load reads the raw ship authoring payload and refuses a non-nil retired key 1 (the
pre-S1 embedded hull) naming the old shape, so a stale hull is no longer silently
ignored; ship_cc.py refuses the same file on read and therefore on every save.
A hull naming both a Unity prefab and a visual is refused by one predicate
(ShipAuthoringStore.RequireOneBody), called by Validate and by Compose over every hull
in the derived catalog, shipped ones included; a whitespace-only Prefab is unset. This
replaces the mod-ship-only "cannot name a Unity prefab" check.
The validator also refuses non-finite or negative hardpoint Armor and FiringArc, an
undefined HardpointType or ItemRotation, and an anchor Role outside the eight the
schema documents.
Load wraps MessagePack decode failures with the file path. Python replace_layout
refuses non-boolean layout and hardpoint-footprint cells.
Tests: exact Visual key comparison, HullData.Visual at key 32, a save refreshing
stored_at, plus one case per new refusal. HullData.Visual is now [Inspectable] like
Prefab (Unity editor only; not compiled here).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-09-30 06:18:20 +02:00
if not all ( type ( cell ) is bool for cell in hp_cells ) :
2026-10-10 09:49:39 +02:00
raise ValueError ( " Hardpoint footprint cells must be booleans " )
2026-09-26 19:23:01 +02:00
if not ( 1 < = hp_width < = 32 and 1 < = hp_height < = 32 and
len ( hp_cells ) == hp_width * hp_height and any ( hp_cells ) ) :
2026-10-10 09:49:39 +02:00
raise ValueError ( " A hardpoint has an invalid footprint " )
Give the Blender side tests and pin its hand-copied schema to C# (S-Soul F3)
ship_cc.py edited a ShipAuthoring record by bare slot numbers and hardpoint
positions (hp[3], hp[7:], raw[0..6]), and __init__.py copied the
HardpointType and ItemRotation enums by position. Nothing tested either
file and nothing tied the numbers to the C# [Key] attributes that own them.
- ship_cc.py names its schema facts once: the four record slots (each
commented with the C# member it mirrors), HARDPOINT_MEMBERS (HardpointData
member names in slot order), and the two enum name tuples. Hardpoint rows
are built and read through encode_hardpoint/decode_hardpoint; replace_layout
and the Blender operators no longer index a row by literal. __init__.py
builds its enum items from the tuples. The rotation label
"Counterclockwise" becomes "CounterClockwise", matching the C# member.
- tools/blender/tests/test_ship_cc.py (30 unittest cases, bpy-free, needs
CultLib's cultcache-py and msgpack): read, replace_lines, read_layout,
replace_layout (untouched slots and later-schema hardpoint slots preserved
by mount id, schema catalog preserved, every refusal leaves the file
byte-identical), the row codec, and capture_grease_pencil against stand-in
objects.
- ShipSchemaPinTests (C#, 7 cases) reads ship_cc.py and fails when a slot
constant, a HARDPOINT_MEMBERS name or position, or an enum name/value
disagrees with the C# types, and when a serialized ship no longer has the
nested array shapes the Python indexes (schematic [[w, h, cells]], cells
x-major, hardpoint transform and footprint positions).
Reading the slots from the file's schema catalog instead was rejected: the
catalog lists only document members, and Hull, Shape and HardpointData are
nested types it does not describe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:55:46 +02:00
updated_hardpoints . append ( hardpoint + previous . get ( mount , [ ] ) )
2026-09-26 19:23:01 +02:00
hull [ HULL_SHAPE_SLOT ] = [ shape ]
hull [ HULL_HARDPOINTS_SLOT ] = updated_hardpoints
2026-09-30 03:06:43 +02:00
file . store . push ( _stamped ( file . hull , file . msgpack ) )
2026-10-10 09:49:39 +02:00
return layout_revision ( hull [ HULL_SHAPE_SLOT ] [ 0 ] , hull [ HULL_HARDPOINTS_SLOT ] )
2026-09-26 19:23:01 +02:00
2026-09-26 18:14:36 +02:00
def capture_grease_pencil ( obj : Any , depsgraph : Any , frame_number : int , * , evaluated : bool = True ) - > list [ list [ Any ] ] :
if obj . type != " GREASEPENCIL " :
2026-10-10 09:49:39 +02:00
raise ValueError ( " The selected object is not a Grease Pencil object " )
2026-09-26 18:14:36 +02:00
source = obj . evaluated_get ( depsgraph ) if evaluated else obj
lines : list [ list [ Any ] ] = [ ]
for layer in source . data . layers :
frames = [ frame for frame in layer . frames if frame . frame_number < = frame_number ]
if not frames :
continue
frame = max ( frames , key = lambda candidate : candidate . frame_number )
for stroke in frame . drawing . strokes :
if len ( stroke . points ) < 2 :
continue
material = source . data . materials [ stroke . material_index ]
rgba = (
tuple ( material . grease_pencil . color )
if material and material . grease_pencil
else tuple ( material . diffuse_color ) if material else ( 1.0 , 1.0 , 1.0 , 1.0 )
)
points : list [ float ] = [ ]
radii : list [ float ] = [ ]
opacities : list [ float ] = [ ]
for point in stroke . points :
position = obj . matrix_world @ point . position
points . extend ( float ( value ) for value in position )
radii . append ( float ( point . radius ) )
opacities . append ( float ( point . opacity ) )
lines . append ( [
layer . name ,
material . name if material else " " ,
points ,
radii ,
opacities ,
bool ( stroke . cyclic ) ,
[ float ( value ) for value in rgba ] ,
] )
return lines