{{- /* SFCraft 合成配方组件 两种用法: 1) 九格直填: a1..c3 为 3x3 合成格, out 为输出格 2) pattern 别名模式(提供 pattern 时优先): pattern="a a a\nb b b\nc c c" 行间用 \n(必须写在一行内), 也可用空格或 ; 分隔, 共 9 个 token a="diamond" b="stick" c="" 每个 token 对应一个同名参数, 值为物品 id token 也可以直接写物品 id, 如 pattern="diamond stick ." "." 表示空格子 - 值为物品 id, 留空表示空格子; 名称后可加 ":数量" 显示堆叠数, 例如 a1="stick:2" - 贴图由 partials/sfcraft/item-texture.html 自动解析并缓存, 无需手工准备 - caption 参数可选, 显示在组件下方 */ -}} {{- $table := resources.Get "table.png" -}} {{- $slots := slice (dict "key" "a1" "cls" "grid" "x" "13.75%" "y" "20%") (dict "key" "a2" "cls" "grid" "x" "25%" "y" "20%") (dict "key" "a3" "cls" "grid" "x" "36.25%" "y" "20%") (dict "key" "b1" "cls" "grid" "x" "13.75%" "y" "42.5%") (dict "key" "b2" "cls" "grid" "x" "25%" "y" "42.5%") (dict "key" "b3" "cls" "grid" "x" "36.25%" "y" "42.5%") (dict "key" "c1" "cls" "grid" "x" "13.75%" "y" "65%") (dict "key" "c2" "cls" "grid" "x" "25%" "y" "65%") (dict "key" "c3" "cls" "grid" "x" "36.25%" "y" "65%") (dict "key" "out" "cls" "out" "x" "70%" "y" "37.5%") -}} {{- $ctx := . -}} {{- $pattern := $ctx.Get "pattern" -}} {{- $tokens := slice -}} {{- if $pattern -}} {{- $flat := replace (replace (replace (replace $pattern "\\n" " ") ";" " ") "\n" " ") "\r" " " -}} {{- range split (trim $flat " ") " " -}} {{- if ne . "" -}}{{- $tokens = $tokens | append . -}}{{- end -}} {{- end -}} {{- end -}} {{- /* 每页只输出一次样式 */ -}} {{- if not (.Page.Store.Get "sfc_crafting_css") -}} {{- .Page.Store.Set "sfc_crafting_css" true -}} {{- with resources.Get "css/sfcraft-crafting.css" -}} {{- end -}} {{- end -}} {{- if and $pattern (ne (len $tokens) 9) -}}
crafting 的 pattern 需要恰好 9 个 token(3 行 × 3 列),当前是 {{ len $tokens }} 个。 请检查 pattern="a a a\nb b b\nc c c" 的写法。
{{- else -}}
{{- range $i, $slot := $slots -}} {{- $val := "" -}} {{- if eq $slot.key "out" -}} {{- $val = trim ($ctx.Get "out") " " -}} {{- else if $pattern -}} {{- $token := "" -}} {{- if lt $i (len $tokens) -}}{{- $token = index $tokens $i -}}{{- end -}} {{- if and (ne $token "") (ne $token ".") -}} {{- $v := trim ($ctx.Get $token) " " -}} {{- if eq $v "" -}} {{- if findRE "^[a-z0-9_]+$" $token -}}{{- $v = $token -}}{{- end -}} {{- end -}} {{- $val = $v -}} {{- end -}} {{- else -}} {{- $val = trim ($ctx.Get $slot.key) " " -}} {{- end -}} {{- /* "." 表示空格子, 无论它写在 pattern 里还是写成别名的值 */ -}} {{- if eq $val "." -}}{{- $val = "" -}}{{- end -}} {{- partial "sfcraft/crafting-slot.html" (dict "val" $val "cls" $slot.cls "x" $slot.x "y" $slot.y "page" $ctx.Page ) -}} {{- end -}} {{- with $ctx.Get "caption" -}}
{{ . }}
{{- end -}}
{{- end -}}