Module:OmegaMap

From Omega Wiki
Revision as of 03:02, 24 July 2026 by OmegaWiki seed importer (talk | contribs) (Fix imported seed rendering)
Jump to navigation Jump to search

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

local p = {}
local maps = {
  remake = {
    { text='###########', locations={ [3]={target='Locations/Harbor', label='Harbor', zh='港口', char='H', class='cyan'} } },
    { text='#.........#', locations={} },
    { text='#..@......#', locations={ [4]={target='Locations/Town', label='Town', zh='城镇', char='T', class='yellow'} } },
    { text='#.........#', locations={} },
    { text='###########', locations={} },
  },
  classic = {
    { text='#########', locations={ [3]={target='Classic:Locations/Harbor', label='Harbor', zh='港口', char='H', class='cyan'} } },
    { text='#.......#', locations={} },
    { text='#..@....#', locations={ [4]={target='Classic:Locations/Town', label='Town', zh='城镇', char='T', class='yellow'} } },
    { text='#########', locations={} },
  },
}

function p.render(frame)
  local edition = frame.args.edition or (mw.title.getCurrentTitle().namespace == 3002 and 'classic' or 'remake')
  local map = maps[edition] or maps.remake
  local out = {'<div class="omega-map" role="img" aria-label="' .. edition .. ' map">'}
  local locations = {}
  for row, line in ipairs(map) do
    local cells = {}
    for col = 1, #line.text do
      local char = line.text:sub(col, col)
      local location = line.locations[col]
      if location then
        local target = tostring(mw.uri.fullUrl(location.target))
        cells[#cells+1] = string.format('<a class="omega-color-%s" href="%s" title="%s (%s)" aria-label="%s">%s</a>', location.class, target, location.label, location.zh, location.label, location.char)
        locations[#locations+1] = string.format('<li><a href="%s">%s</a> <span lang="zh-Hans">%s</span></li>', target, location.label, location.zh)
      else cells[#cells+1] = mw.text.nowiki(char) end
    end
    out[#out+1] = table.concat(cells)
  end
  out[#out+1] = '</div><nav class="omega-map-directory" aria-label="Locations"><ol>' .. table.concat(locations) .. '</ol></nav>'
  return table.concat(out, '\n')
end
return p