置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:GF utils

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
  1. --[=[
  2. 此模块包含[[少女前线]]相关模板使用的工具函数。
  3. ]=]
  4. local ugsub = mw.ustring.gsub
  5. local format = string.format
  6. local utils = {}
  7. --- 为星级添加颜色。
  8. function utils.colored_rarity(frame)
  9. local arg = assert(frame.args[1], '未提供参数')
  10. local rarity_color = {
  11. '#865c7d', '#777777', '#33566f', '#7b813f', '#a7753b', '#ad4229'
  12. }
  13. -- 3 -> '<span style="...">★★★</span>'
  14. -- 9 -> nil
  15. local function make_colored_rarity(rarity)
  16. local color = rarity_color[rarity]
  17. if not color then return nil end
  18. return format('<span style="color:%s">%s</span>', color, ('★'):rep(rarity))
  19. end
  20. -- '3' -> <span style="...">★★★</span>
  21. -- '9' -> '9'
  22. local function colorize_number(str)
  23. return make_colored_rarity(tonumber(str)) or str
  24. end
  25. -- '★★★' -> <span style="...">★★★</span>
  26. -- '★★★★★★★★★' -> '★★★★★★★★★'
  27. local function colorize_star(start, str, stop)
  28. return make_colored_rarity(stop - start) or str
  29. end
  30. local out = arg:match('^%s*(.-)%s*$') -- 去首尾空白
  31. out = out:gsub('%s*→%s*', ' → '):gsub('%s*->%s*', ' → ') -- 调整箭头
  32. out = ugsub(out, '()(★+)()', colorize_star)
  33. out = out:gsub('%d+', colorize_number)
  34. return out
  35. end
  36. return utils