1919from collections .abc import Collection , Mapping
2020from dataclasses import dataclass , field
2121
22+ from mhfu import inject
2223from mhfu .entries import ENTRY_BANK , PART_STREAMS
2324from mhp_formats .anim import AnimPack
2425
3132ENTRIES = {75 : 123 }
3233"""Executor entries per host species: the rows of its overlay's descriptor table (em75: dumped
3334live). An unknown host gets one bank, or up to the last entry its own pack fills."""
34- LIB = "lib"
35- """Where `require` finds a library, under the framework's mods directory."""
35+ LIB = inject .LIB
3636
3737
3838class LayoutError (manifest .ManifestError ):
@@ -249,20 +249,27 @@ def names(m: manifest.Manifest, layout: Layout) -> dict[int, str]:
249249
250250def module_name (m : manifest .Manifest ) -> str :
251251 """The Lua module `mhfu_port`'s `P.define` requires for the port's clips."""
252- return f"{ m .port .name } _clips.lua"
252+ return inject .port_module (m .port .name , "clips" )
253+
254+
255+ def turns_module_name (m : manifest .Manifest ) -> str :
256+ """The Lua module with the port's turn curves, which no mod needs: moves carry their own."""
257+ return inject .port_module (m .port .name , "turns" )
253258
254259
255260_IDENT = re .compile (r"[A-Za-z_][A-Za-z0-9_]*" )
256- TURNS = "_turns"
257- """The clips module's key for `Layout.turns`; no clip may take the name."""
261+
262+
263+ def _source (m : manifest .Manifest ) -> str :
264+ return f"ports/{ m .path .name } " if m .path is not None else f"the { m .port .name } manifest"
258265
259266
260267def lua (m : manifest .Manifest , layout : Layout ) -> str :
261268 """The module: each clip's name -> its executor entry, and the MHP3rd id it holds."""
262- src = f"ports/{ m .path .name } " if m .path is not None else f"the { m .port .name } manifest"
263269 named = names (m , layout )
264270 out = [
265- f"-- { module_name (m )} , GENERATED by mhfu-port from { src } : { len (layout .entries )} clips of" ,
271+ f"-- { module_name (m )} , GENERATED by mhfu-port from { _source (m )} : { len (layout .entries )} "
272+ " clips of" ,
266273 f"-- MHP3rd file { m .source .anim } by executor entry. Do not edit: rebuild. mhfu_port's" ,
267274 "-- P.define reads it as the port's clips (name -> entry)." ,
268275 "return {" ,
@@ -271,16 +278,22 @@ def lua(m: manifest.Manifest, layout: Layout) -> str:
271278 name = named .get (e )
272279 if name is None :
273280 continue
274- if name == TURNS :
275- raise LayoutError (f"clip name { TURNS } is the module's own key" )
276281 key = name if _IDENT .fullmatch (name ) else f'["{ name } "]'
277282 out .append (f" { key } = { e } , -- MHP3rd { cid } " )
278- if layout .turns :
279- out .append (
280- f" -- entry -> YAW while it plays: 4 hex digits (0x10000 a turn) every { KEY_STEP } "
281- " clip frames, the last at its end"
282- )
283- out .append (f" { TURNS } = {{" )
284- out += [f' [{ e } ] = "{ t .lua ()} ",' for e , t in sorted (layout .turns .items ())]
285- out .append (" }," )
286283 return "\n " .join ([* out , "}" , "" ])
284+
285+
286+ def turns_lua (m : manifest .Manifest , layout : Layout ) -> str :
287+ """The turns module: entry -> YAW while it plays. `mhfu move play --curve` reads it."""
288+ return "\n " .join (
289+ [
290+ f"-- { turns_module_name (m )} , GENERATED by mhfu-port from { _source (m )} : entry -> YAW"
291+ " while it plays," ,
292+ f"-- 4 hex digits (0x10000 a turn) every { KEY_STEP } clip frames, the last at its end."
293+ " Do not edit: rebuild." ,
294+ "return {" ,
295+ * (f' [{ e } ] = "{ t .lua ()} ",' for e , t in sorted (layout .turns .items ())),
296+ "}" ,
297+ "" ,
298+ ]
299+ )
0 commit comments