Module:Lore

From Risk of Rain 2 Wiki
Jump to navigation Jump to search

Lore stores details about Risk of Rain 2's logbook entries.

Documentation

Package items

lore.Lore(frame) (function)
Builds a single logbook lore entry based on in-game presentation.
Parameter: frame Frame object w/ the first argument being the item name (table)
Returns: HTML string of formatted logbook lore entry (string)
lore.AllLore() (function)
Builds all logbook lore entries based on in-game presentation.
Returns: HTML string of formatted logbook lore entries (string)


---	'''Lore''' stores details about Risk of Rain 2's logbook entries.
--	
--	@module		lore
--	@alias		p
--	@author		[[User:Paradoxzyx]]
--	@require	[[Module:Lore/Data]]
--	@release	stable
--<nowiki>
local p = {}

local data = require("Module:Lore/Data")
local all_lore = data.lore

---	Builds a single logbook lore entry based on in-game presentation.
--	@function		p.Lore
--	@param			{table} frame Frame object w/ the first argument being the item name
--	@return			{string} HTML string of formatted logbook lore entry
function p.Lore(frame)
  local name = frame.args[1] ~= "" and frame.args[1] or mw.title.getCurrentTitle().text
  local desc = all_lore[name].Desc
  desc = desc:gsub("^<style=cMono>\r?\n", "<style=cMono>"):gsub("^%s*(.-)%s*$", "%1"):gsub("<style=cMono>", "<span class=\"mono\">"):gsub("<\/style>", "</span>"):gsub("(==+)", "<span>%1</span>"):gsub("(%-%-+)", "<span>%1</span>"):gsub("\u(%x%x%x%x)", function(s) return mw.ustring.char(tonumber(s, 16)) end)
  local pre = mw.html.create("pre"):addClass("lore"):wikitext(desc)
  return pre:done()
end

---	Builds all logbook lore entries based on in-game presentation.
--	@function		p.AllLore
--	@return			{string} HTML string of formatted logbook lore entries
function p.AllLore()
  local all = {}
  local count = 0
  for name, lore in pairs(all_lore) do
    lore.Name = name
    if not all[lore.Type] then
    	all[lore.Type] = {}
    end
    table.insert(all[lore.Type], lore)
    count = count + 1
  end
  
  local list = ""
  for i, v in ipairs({ "Environments", "Items", "Equipment", "Survivors", "Monsters" }) do
    table.sort(all[v], function(a, b) return a.Name < b.Name end)
    list = list .. "==" .. v .. "==\r\n"
    for i, lore in ipairs(all[v]) do
      desc = lore.Desc:gsub("^<style=cMono>\r?\n", "<style=cMono>"):gsub("^%s*(.-)%s*$", "%1"):gsub("<style=cMono>", "<span class=\"mono\">"):gsub("<\/style>", "</span>"):gsub("(==+)", "<span>%1</span>"):gsub("(%-%-+)", "<span>%1</span>"):gsub("\u(%x%x%x%x)", function(s) return mw.ustring.char(tonumber(s, 16)) end)
      local pre = mw.html.create("pre"):addClass("lore"):wikitext(desc)
      list = list .. "<div style=\"display:inline-flex;flex-direction:column;margin-right:12px;margin-bottom:8px\"><div style=\"font-size:22px\">[[" .. lore.Name .. "]]</div>" .. tostring(pre) .. "</div>\r\n"
    end
  end
  return "There are " .. count .. " lore entries in the game.<span id='filter-hook'></span>\r\n\r\n" .. list
end

return p
--</nowiki>