1111
1212from __future__ import annotations
1313
14- import dataclasses
1514import typing
1615from collections .abc import Callable , Mapping , Sequence
1716from typing import Any , NamedTuple , Protocol
1817
1918from mhfu_port import behaviour , sequence
20- from mhfu_port .behaviour import KINDS , Behaviour , Block , MoveNode , Param , Path
19+ from mhfu_port .behaviour import KINDS , Block , MoveNode , Param , Path
2120from mhfu_port .manifest import Manifest , ManifestError
2221
2322from mhfu_studio .monster .document import PortDocument
2827IN , OUT = "in" , "out"
2928PLAY , WHILE , THEN = "play" , "while playing" , "then"
3029"""A move node's ports: the input, then the two outputs."""
31- BLOCK_W , MOVE_W = 280 , 380
32- """How far right of a block, or a move's node, the next column starts: a node's width and a gap."""
3330ROLE_TITLES = {
3431 "event" : "Events" ,
3532 "state" : "State" ,
@@ -146,8 +143,8 @@ def spots(m: Manifest) -> dict[str, Point]:
146143 """Where each move sits: its node's place, else a column right of everything placed, in
147144 sequence order so a chain sits together."""
148145 b = m .behaviour
149- clear = [blk .at [0 ] + BLOCK_W for blk in b .blocks .values ()]
150- clear += [n .at [0 ] + MOVE_W for n in b .moves .values ()]
146+ clear = [blk .at [0 ] + behaviour . COLUMN for blk in b .blocks .values ()]
147+ clear += [n .at [0 ] + behaviour . LEFT for n in b .moves .values ()]
151148 x = max (clear , default = float (behaviour .LEFT ))
152149 order = [n for steps in sequence .groups (m ).values () for n in steps ]
153150 return {
@@ -163,8 +160,8 @@ class Reading(NamedTuple):
163160 priority : dict [str , list [int ]]
164161 """Block id -> the 1-based places in `paths` of the paths that play from it."""
165162 loose : list [str ]
166- refused : dict [Path , str ]
167- """The paths `compile` refuses, and why ."""
163+ refused : dict [str , str ]
164+ """Block id -> why, for the blocks on a path `compile` refuses."""
168165 capped : str | None
169166 """Set when the paths outnumber the rules the seam holds."""
170167
@@ -174,7 +171,7 @@ def read(m: Manifest) -> Reading:
174171 priority : dict [str , list [int ]] = {}
175172 for k , p in enumerate (ps , 1 ):
176173 priority .setdefault (p .blocks [- 1 ], []).append (k )
177- return Reading (ps , priority , behaviour .loose (m ), refusals ( m , ps ), capped (m , ps ))
174+ return Reading (ps , priority , behaviour .loose (m ), behaviour . refused ( m ), capped (m , ps ))
178175
179176
180177def capped (m : Manifest , ps : Sequence [Path ] | None = None ) -> str | None :
@@ -183,31 +180,6 @@ def capped(m: Manifest, ps: Sequence[Path] | None = None) -> str | None:
183180 return f"{ n } paths, the seam holds { behaviour .SEAM_RULES } " if n > behaviour .SEAM_RULES else None
184181
185182
186- def refusals (m : Manifest , ps : Sequence [Path ] | None = None ) -> dict [Path , str ]:
187- """Why `compile` refuses each path it does, in its words: each path alone."""
188- out : dict [Path , str ] = {}
189- for p in behaviour .paths (m ) if ps is None else ps :
190- try :
191- behaviour .compile (_alone (m , p ))
192- except ManifestError as e :
193- out [p ] = str (e ).partition (": " )[2 ]
194- return out
195-
196-
197- def _alone (m : Manifest , p : Path ) -> Manifest :
198- """`m` with the graph cut down to the path `p`."""
199- b = m .behaviour
200- blocks = {}
201- for k , i in enumerate (p .blocks ):
202- last = k == len (p .blocks ) - 1
203- blk = b .blocks [i ]
204- blocks [i ] = dataclasses .replace (
205- blk , next = [] if last else [p .blocks [k + 1 ]], play = [p .play ] if last else []
206- )
207- moves = {} if p .during is None else {p .during : MoveNode (b .moves [p .during ].at , [p .blocks [0 ]])}
208- return dataclasses .replace (m , behaviour = Behaviour (blocks , moves ))
209-
210-
211183def part_options (m : Manifest , optional : bool ) -> list [tuple [str , int | None ]]:
212184 """The parts to pick from: the manifest's named ones, then `part k`; `any` for none."""
213185 named : dict [int , str ] = {}
@@ -472,8 +444,8 @@ def place(m: Manifest) -> None:
472444
473445
474446def spread (doc : Edits , kx : float = 1.5 , ky : float = 1.7 ) -> str :
475- """Every placed node's place scaled out from the origin: a graph laid on a tight grid (the
476- rules of a schema 1 file) stops overlapping, and which block is higher stays so ."""
447+ """Every placed node's place scaled out from the origin, so crowded nodes stop overlapping.
448+ A scale keeps the order of the canvas rows and columns, so every path's priority holds ."""
477449 b = doc .manifest .behaviour
478450
479451 def scale (m : Manifest ) -> None :
0 commit comments