Module:MonsterIndex: Difference between revisions

From Omega Wiki
Jump to navigation Jump to search
Refresh OmegaWiki seed content
Refresh OmegaTheme homepage and navigation
 
Line 10: Line 10:
  },
  },
}
}
local function matches(m, filter)
return filter == '' or m.name:lower():find(filter, 1, true) or m.char == filter or m.category == filter
end
local function marker(m)
return mw.html.create('span')
  :addClass('omega-color-' .. m.class)
  :attr('aria-label', m.name .. ' (' .. m.zh .. ')')
  :wikitext(mw.text.nowiki(m.char))
end
function p.render(frame)
function p.render(frame)
  local edition = frame.args.edition or (mw.title.getCurrentTitle().namespace == 3002 and 'classic' or 'remake')
  local edition = frame.args.edition or (mw.title.getCurrentTitle().namespace == 3002 and 'classic' or 'remake')
  local filter = mw.text.trim(frame.args.filter or ''):lower()
  local filter = mw.text.trim(frame.args.filter or ''):lower()
local mode = mw.text.trim(frame.args.mode or ''):lower()
if mode == 'compact' then
  local strip = mw.html.create('div')
  :addClass('omega-monster-strip')
  :attr('role', 'navigation')
  :attr('aria-label', edition .. ' monster index')
  for _, m in ipairs(data[edition] or {}) do
  if matches(m, filter) then
    strip:wikitext('[[' .. m.target .. '|' .. tostring(marker(m)) .. ']]')
  end
  end
  return tostring(strip)
end
  local tableNode = mw.html.create('table'):addClass('wikitable omega-monster-index')
  local tableNode = mw.html.create('table'):addClass('wikitable omega-monster-index')
  local header = tableNode:tag('tr')
  local header = tableNode:tag('tr')
Line 19: Line 46:
  header:tag('th'):wikitext('Category')
  header:tag('th'):wikitext('Category')
  for _, m in ipairs(data[edition] or {}) do
  for _, m in ipairs(data[edition] or {}) do
   if filter == '' or m.name:lower():find(filter, 1, true) or m.char == filter or m.category == filter then
   if matches(m, filter) then
   local row = tableNode:tag('tr')
   local row = tableNode:tag('tr')
  local marker = mw.html.create('span')
   row:tag('td'):wikitext('[[' .. m.target .. '|' .. tostring(marker(m)) .. ']]')
    :addClass('omega-color-' .. m.class)
    :attr('aria-label', m.name .. ' (' .. m.zh .. ')')
    :wikitext(mw.text.nowiki(m.char))
   row:tag('td'):wikitext('[[' .. m.target .. '|' .. tostring(marker) .. ']]')
   local nameCell = row:tag('td')
   local nameCell = row:tag('td')
   nameCell:wikitext('[[' .. m.target .. '|' .. mw.text.nowiki(m.name) .. ']]')
   nameCell:wikitext('[[' .. m.target .. '|' .. mw.text.nowiki(m.name) .. ']]')

Latest revision as of 06:32, 24 July 2026

Documentation for this module may be created at Module:MonsterIndex/doc

local p = {}
local data = {
 remake = {
  { char='d', name='Dire rat', zh='巨鼠', category='beast', target='Monster/Dire rat', class='red' },
  { char='D', name='Dragon', zh='龙', category='dragon', target='Monster/Dragon', class='yellow' },
 },
 classic = {
  { char='d', name='Giant rat', zh='巨鼠', category='beast', target='Classic:Monster/Giant rat', class='red' },
  { char='D', name='Dragon', zh='龙', category='dragon', target='Classic:Monster/Dragon', class='yellow' },
 },
}

local function matches(m, filter)
 return filter == '' or m.name:lower():find(filter, 1, true) or m.char == filter or m.category == filter
end

local function marker(m)
 return mw.html.create('span')
  :addClass('omega-color-' .. m.class)
  :attr('aria-label', m.name .. ' (' .. m.zh .. ')')
  :wikitext(mw.text.nowiki(m.char))
end

function p.render(frame)
 local edition = frame.args.edition or (mw.title.getCurrentTitle().namespace == 3002 and 'classic' or 'remake')
 local filter = mw.text.trim(frame.args.filter or ''):lower()
 local mode = mw.text.trim(frame.args.mode or ''):lower()

 if mode == 'compact' then
  local strip = mw.html.create('div')
   :addClass('omega-monster-strip')
   :attr('role', 'navigation')
   :attr('aria-label', edition .. ' monster index')
  for _, m in ipairs(data[edition] or {}) do
   if matches(m, filter) then
    strip:wikitext('[[' .. m.target .. '|' .. tostring(marker(m)) .. ']]')
   end
  end
  return tostring(strip)
 end

 local tableNode = mw.html.create('table'):addClass('wikitable omega-monster-index')
 local header = tableNode:tag('tr')
 header:tag('th'):wikitext('Char')
 header:tag('th'):wikitext('Name')
 header:tag('th'):wikitext('Category')
 for _, m in ipairs(data[edition] or {}) do
  if matches(m, filter) then
   local row = tableNode:tag('tr')
   row:tag('td'):wikitext('[[' .. m.target .. '|' .. tostring(marker(m)) .. ']]')
   local nameCell = row:tag('td')
   nameCell:wikitext('[[' .. m.target .. '|' .. mw.text.nowiki(m.name) .. ']]')
   nameCell:wikitext(' ')
   nameCell:tag('span')
    :attr('lang', 'zh-Hans')
    :wikitext(mw.text.nowiki(m.zh))
   row:tag('td'):wikitext(mw.text.nowiki(m.category))
  end
 end
 return tostring(tableNode)
end
return p