{{- /* 合成表中的一个格子 入参: val 格子内容, "物品id" 或 "物品id:数量", 空字符串表示空格子 cls "grid" (九宫格) 或 "out" (输出格) x, y 在合成表底图上的定位 page 所在页面, 仅用于报错定位 */ -}} {{- $val := .val -}} {{- $item := "" -}} {{- $count := 0 -}} {{- if $val -}} {{- $parts := split $val ":" -}} {{- $item = index $parts 0 -}} {{- if gt (len $parts) 1 -}} {{- $count = int (index $parts 1) -}} {{- end -}} {{- end -}} {{- $img := false -}} {{- if $item -}} {{- /* 以 id 为 key, 同一物品每次构建只解析一次 */ -}} {{- $texture := partialCached "sfcraft/item-texture.html" (dict "id" $item) $item -}} {{- $img = $texture.image -}} {{- if ne $texture.status "ok" -}} {{- $where := printf "%s 引用的物品 %q" .page.Path $item -}} {{- $onMissing := (site.Params.itemTextures | default dict).onMissing | default "error" -}} {{- if eq $texture.status "degraded" -}} {{- /* 离线 / 限流 / 上游异常: 结论不可靠, 只告警, 不阻断构建 */ -}} {{- warnf "%s 贴图解析失败, 已降级为占位符: %s" $where $texture.detail -}} {{- else if eq $onMissing "error" -}} {{- errorf "%s 没有对应贴图。请检查 id 拼写, 或把贴图放进 assets/items/%s.png" $where $item -}} {{- else if eq $onMissing "warn" -}} {{- warnf "%s 没有对应贴图" $where -}} {{- end -}} {{- end -}} {{- end -}}
{{- if $img -}} {{ $item }} {{- if gt $count 1 -}} {{ $count }} {{- end -}} {{- else if $item -}} ? {{- end -}}