mirror of
https://github.com/Dasemu/vnpipe.git
synced 2026-11-26 07:16:23 +00:00
Merge branch 'fix/sprite-overlap' into development
This commit is contained in:
commit
4c76255981
3 files changed
+52
-2
No files matched your search
+29
-2
@@ -45,6 +45,9 @@ EMOTIONS = (
|
||||
"ecstatic",
|
||||
)
|
||||
POSITIONS = ("left", "right", "center") # order in which --from-parsed assigns positions
|
||||
# Stage slots tried, in order, when a character's position is already taken by another sprite;
|
||||
# the two inner slots only come into play with four or more sprites on stage.
|
||||
SLOTS = ("left", "right", "center", "left_mid", "right_mid")
|
||||
TRANSITIONS = {
|
||||
"dissolve": "dissolve",
|
||||
"fade": "fade",
|
||||
@@ -532,6 +535,7 @@ class SceneWriter:
|
||||
if cid not in desired:
|
||||
desired.append(cid)
|
||||
changed = self.hide_sprites([c for c in list(self.shown) if c not in desired])
|
||||
moved = self.assign_slots(desired)
|
||||
for cid in desired:
|
||||
expressions = self.work.cast[cid].get("expressions", {})
|
||||
neutral = expressions.get("neutral", "neutral")
|
||||
@@ -539,13 +543,36 @@ class SceneWriter:
|
||||
expression = expressions.get(ann["emotion"], neutral)
|
||||
else:
|
||||
expression = self.shown.get(cid, neutral)
|
||||
if self.shown.get(cid) != expression:
|
||||
if self.shown.get(cid) != expression or cid in moved:
|
||||
self.emit(f"show {cid} {expression} at vn_{self.positions[cid]}")
|
||||
self.shown[cid] = expression
|
||||
changed = True
|
||||
if changed:
|
||||
if moved:
|
||||
self.emit("with vn_move")
|
||||
elif changed:
|
||||
self.emit("with dissolve")
|
||||
|
||||
def assign_slots(self, desired: list[str]) -> set[str]:
|
||||
"""Give every sprite on stage its own slot; return the shown sprites that had to move.
|
||||
|
||||
Sprites already on stage claim their slots first (in the order they appeared), so a
|
||||
newcomer whose annotated position is taken gets the first free slot instead of being
|
||||
drawn on top of someone else."""
|
||||
order = [c for c in self.shown if c in desired] + [
|
||||
c for c in desired if c not in self.shown
|
||||
]
|
||||
taken: set[str] = set()
|
||||
moved: set[str] = set()
|
||||
for cid in order:
|
||||
slot = self.positions[cid]
|
||||
if slot in taken:
|
||||
slot = next((s for s in SLOTS if s not in taken), slot)
|
||||
if cid in self.shown:
|
||||
moved.add(cid)
|
||||
self.positions[cid] = slot
|
||||
taken.add(slot)
|
||||
return moved
|
||||
|
||||
# -- scene ---------------------------------------------------------------------------
|
||||
|
||||
def render(self) -> list[str]:
|
||||
|
||||
@@ -13,6 +13,13 @@ transform vn_center:
|
||||
transform vn_right:
|
||||
xalign 0.85 yalign 1.0
|
||||
|
||||
## Extra slots for crowded scenes (four or more sprites).
|
||||
transform vn_left_mid:
|
||||
xalign 0.32 yalign 1.0
|
||||
|
||||
transform vn_right_mid:
|
||||
xalign 0.68 yalign 1.0
|
||||
|
||||
transform tint_none:
|
||||
matrixcolor IdentityMatrix()
|
||||
|
||||
|
||||
@@ -575,3 +575,19 @@ def test_reading_comfort_defaults(project):
|
||||
assert "default preferences.text_cps = 40" in options
|
||||
assert "default preferences.afm_time = 15" in options
|
||||
assert "define config.has_music = True" in options
|
||||
|
||||
|
||||
def test_newcomer_never_overlaps(work, annotated):
|
||||
ann = json.loads(json.dumps(annotated))
|
||||
for line in ann["scenes"][1]["lines"]: # everyone annotated at the same position
|
||||
for entry in line["ann"]["on_stage"]:
|
||||
entry["position"] = "left"
|
||||
block = scene_block(renpy_gen.render_script(work, ann), "talk")
|
||||
slots: dict[str, str] = {}
|
||||
for ln in block:
|
||||
if ln.startswith("show ") and " at vn_" in ln and not ln.startswith("show layer"):
|
||||
slots[ln.split()[1]] = ln.rsplit("vn_", 1)[1]
|
||||
elif ln.startswith("hide "):
|
||||
slots.pop(ln.split()[1], None)
|
||||
assert len(set(slots.values())) == len(slots), ln
|
||||
assert len(slots) >= 1
|
||||
Reference in new issue
Block a user