Package: her art's takeover leaves no retired hull lines in the .cc (state decides the source; the slot is cleared)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
87dc0f013f
commit
dab415ad87
3 changed files with 34 additions and 5 deletions
|
|
@ -23,7 +23,7 @@ import numpy
|
|||
from mathutils import Matrix, Vector
|
||||
|
||||
from . import hull_grid, hull_source
|
||||
from .ship_cc import (HARDPOINT_MEMBERS, HARDPOINT_TYPE_NAMES, ROTATION_NAMES, capture_grease_pencil, decode_hardpoint,
|
||||
from .ship_cc import (HARDPOINT_MEMBERS, HARDPOINT_TYPE_NAMES, ROTATION_NAMES, capture_grease_pencil, clear_lines, decode_hardpoint,
|
||||
encode_hardpoint, layout_revision, read, read_hull_type, read_layout, replace_layout, replace_lines,
|
||||
product_makers, replace_visual, valid_ship_id)
|
||||
|
||||
|
|
@ -1639,9 +1639,10 @@ def _build_hull_source(context, collection):
|
|||
|
||||
def _schematic_lines(context, collection):
|
||||
"""The ShipAuthoring.SchematicLines rows Package and Capture write, and the only source of them: her Grease Pencil
|
||||
object if the collection has one (two or more are refused), else the lines Build recorded from the hull source's kit,
|
||||
mapped through Ship Root's matrix_world (so after _frame_ship, the frame her strokes are captured in), else None and
|
||||
the slot is left as it is."""
|
||||
object if the collection has one (two or more are refused), else the lines Build recorded from the hull source's kit
|
||||
while the hull is still Build's (not _hull_state art), mapped through Ship Root's matrix_world (so after _frame_ship,
|
||||
the frame her strokes are captured in), else None and the slot is left as it is. Package alone clears the slot, at
|
||||
the moment her art takes over."""
|
||||
pencils = [obj for obj in collection.all_objects if obj.type == "GREASEPENCIL"]
|
||||
if len(pencils) > 1:
|
||||
raise ValueError("Keep one Grease Pencil object: it is the ship's schematic")
|
||||
|
|
@ -1650,7 +1651,7 @@ def _schematic_lines(context, collection):
|
|||
return capture_grease_pencil(pencils[0], context.evaluated_depsgraph_get(), scene.frame_current,
|
||||
evaluated=scene.aetheria_capture_evaluated_lines)
|
||||
record = collection.get(HULL_LINES)
|
||||
if record is None:
|
||||
if record is None or _hull_state(collection) == HULL_ART: # her art took over: Build's lines are a retired hull's
|
||||
return None
|
||||
root = _ship_root(collection)
|
||||
world = root.matrix_world if root is not None else Matrix.Identity(4)
|
||||
|
|
@ -1773,6 +1774,8 @@ class AETHERIA_OT_package_ship(bpy.types.Operator):
|
|||
lines = _schematic_lines(context, collection)
|
||||
if lines is not None:
|
||||
replace_lines(path, cultlib, lines)
|
||||
elif _hull_state(collection) == HULL_ART: # the lines in the slot are the retired hull's, not hers
|
||||
clear_lines(path, cultlib)
|
||||
code, message = _aetherdb(context, "validate", path, ship_cc=path)
|
||||
except _EXPECTED as exc:
|
||||
scene.aetheria_package_report = f"Package failed: {_failure_text(exc)}"
|
||||
|
|
|
|||
|
|
@ -179,6 +179,16 @@ def replace_lines(path: str, cultlib_packages: str, lines: list[list[Any]]) -> i
|
|||
return len(lines)
|
||||
|
||||
|
||||
def clear_lines(path: str, cultlib_packages: str) -> int:
|
||||
"""Empties the line slot and nothing else; returns how many lines it held. replace_lines refuses an empty capture so a
|
||||
failed capture never wipes a ship; this is the one deliberate way to leave a ship without lines."""
|
||||
file = read(path, cultlib_packages)
|
||||
held = len(file.ship.body[SCHEMATIC_LINES_SLOT] or [])
|
||||
file.ship.body[SCHEMATIC_LINES_SLOT] = []
|
||||
file.store.push(_stamped(file.ship, file.msgpack))
|
||||
return held
|
||||
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -344,6 +344,22 @@ class ReplaceLinesTests(ShipFileCase):
|
|||
if slot != ship_cc.SCHEMATIC_LINES_SLOT:
|
||||
self.assertEqual(before[slot], after[slot], f"slot {slot} changed")
|
||||
|
||||
def test_clear_lines_empties_only_the_line_slot(self):
|
||||
ship_cc.replace_lines(self.path, PACKAGES, LINES)
|
||||
before = self.ship()
|
||||
self.assertEqual(len(LINES), ship_cc.clear_lines(self.path, PACKAGES))
|
||||
after = self.ship()
|
||||
self.assertEqual([], after[ship_cc.SCHEMATIC_LINES_SLOT])
|
||||
for slot in range(len(before)):
|
||||
if slot != ship_cc.SCHEMATIC_LINES_SLOT:
|
||||
self.assertEqual(before[slot], after[slot], f"slot {slot} changed")
|
||||
|
||||
def test_replace_lines_still_refuses_an_empty_capture(self):
|
||||
ship_cc.replace_lines(self.path, PACKAGES, LINES)
|
||||
with self.assertRaises(ValueError):
|
||||
ship_cc.replace_lines(self.path, PACKAGES, [])
|
||||
self.assertEqual(LINES, self.ship()[ship_cc.SCHEMATIC_LINES_SLOT])
|
||||
|
||||
def test_a_save_refreshes_the_stored_at_of_the_record_it_writes_and_only_that_one(self):
|
||||
stale = "2000-01-01T00:00:00+00:00"
|
||||
envelopes = self.envelopes()
|
||||
|
|
|
|||
Loading…
Reference in a new issue