Module:Sandbox/Leranjun/MinecraftSkin

< Module:Sandbox‎ | Leranjun
Lih讨论 | 贡献2022年9月23日 (五) 09:55的版本 (搬运自萌娘百科的同名条目)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

{{MinecraftSkin/Auto}}的另一种实现方式。

模板代码在User:Leranjun/archive/MinecraftSkin

  1. local p = {}
  2. function p.main(frame)
  3. -- Frames per second: 24
  4. local FPS = tonumber(frame.args.FPS)
  5. -- Animation duration: 1s
  6. local DUR = 1
  7. -- Initial delay (for loading): 1.5s
  8. local DEL = 1.5
  9. -- <img src="https://render.namemc.com/skin/3d/body.png?skin={{{skin}}}&model={{{model}}}&theta={{{theta}}}&phi={{{phi}}}&time={{{time}}}&width={{{width}}}&height={{{height}}}"/>
  10. local skin = tostring(frame.args.skin)
  11. local model = tostring(frame.args.model)
  12. local theta = tostring(frame.args.theta)
  13. local phi = tostring(frame.args.phi)
  14. local width = tostring(frame.args.width)
  15. local height = tostring(frame.args.height)
  16. if (width == "") then
  17. if (height == "") then
  18. width = "40"
  19. height = "80"
  20. else
  21. width = tostring(tonumber(height) / 2)
  22. end
  23. else
  24. if (height == "") then
  25. height = tostring(tonumber(width) * 2)
  26. end
  27. end
  28. local r =
  29. mw.html.create("div"):addClass("lr-mc"):css("width", width .. "px"):css("height", height .. "px"):css(
  30. "pointer-events",
  31. "none"
  32. ):css("user-select", "none")
  33. for timee = 1, 360, (360 / FPS / DUR) do
  34. local imgSrc =
  35. string.format(
  36. "https://render.namemc.com/skin/3d/body.png?skin=%s&model=%s&theta=%s&phi=%s&time=%s&width=%s&height=%s",
  37. skin,
  38. model,
  39. theta,
  40. phi,
  41. timee,
  42. width,
  43. height
  44. )
  45. local imgDelay = tostring(DEL + (1 / FPS) * ((timee - 1) / (360 / FPS / DUR))) .. "s"
  46. local curImg = mw.html.create("img"):attr("src", imgSrc)
  47. local imgWrapper = mw.html.create("div"):css("animation-delay", imgDelay):node(tostring(curImg))
  48. r:node(tostring(imgWrapper))
  49. end
  50. return tostring(r)
  51. end
  52. return p
返回顶部
页面反馈