Module:OmegaMap: Difference between revisions

From Omega Wiki
Jump to navigation Jump to search
Import OmegaWiki seed content
 
Refresh OmegaWiki seed content
 
(2 intermediate revisions by the same user not shown)
Line 19: Line 19:
   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 map = maps[edition] or maps.remake
   local map = maps[edition] or maps.remake
   local out = {'<div class="omega-map" role="img" aria-label="' .. edition .. ' map">'}
   local root = mw.html.create('div'):addClass('omega-map-layout')
  local mapNode = root:tag('div')
    :addClass('omega-map')
    :attr('role', 'group')
    :attr('aria-label', edition .. ' map')
   local locations = {}
   local locations = {}
   for row, line in ipairs(map) do
   for _, line in ipairs(map) do
     local cells = {}
     local rowNode = mapNode:tag('div'):addClass('omega-map-row')
     for col = 1, #line.text do
     for col = 1, #line.text do
       local char = line.text:sub(col, col)
       local char = line.text:sub(col, col)
       local location = line.locations[col]
       local location = line.locations[col]
       if location then
       if location then
         cells[#cells+1] = string.format('<a class="omega-color-%s" href="%s" title="%s (%s)" aria-label="%s">%s</a>', location.class, mw.uri.fullUrl(location.target), location.label, location.zh, location.label, location.char)
         local marker = mw.html.create('span')
         locations[#locations+1] = string.format('<li><a href="%s">%s</a> <span lang="zh-Hans">%s</span></li>', mw.uri.fullUrl(location.target), location.label, location.zh)
          :addClass('omega-color-' .. location.class)
       else cells[#cells+1] = mw.text.nowiki(char) end
          :attr('title', location.label .. ' (' .. location.zh .. ')')
          :attr('aria-label', location.label .. ' (' .. location.zh .. ')')
          :wikitext(mw.text.nowiki(location.char))
        rowNode:wikitext('[[' .. location.target .. '|' .. tostring(marker) .. ']]')
         locations[#locations+1] = {
          target = location.target,
          label = location.label,
          zh = location.zh,
        }
       else
        rowNode:wikitext(mw.text.nowiki(char))
      end
     end
     end
    out[#out+1] = table.concat(cells)
   end
   end
   out[#out+1] = '</div><nav class="omega-map-directory" aria-label="Locations"><ol>' .. table.concat(locations) .. '</ol></nav>'
 
  return table.concat(out, '\n')
   local directory = root:tag('div')
    :addClass('omega-map-directory')
    :attr('role', 'navigation')
    :attr('aria-label', 'Locations')
  local list = directory:tag('ol')
  for _, location in ipairs(locations) do
    local item = list:tag('li')
    item:wikitext('[[' .. location.target .. '|' .. mw.text.nowiki(location.label) .. ']]')
    item:wikitext(' ')
    item:tag('span')
      :attr('lang', 'zh-Hans')
      :wikitext(mw.text.nowiki(location.zh))
  end
 
  return tostring(root)
end
end
return p
return p

Latest revision as of 03:31, 24 July 2026

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 root = mw.html.create('div'):addClass('omega-map-layout')
  local mapNode = root:tag('div')
    :addClass('omega-map')
    :attr('role', 'group')
    :attr('aria-label', edition .. ' map')
  local locations = {}
  for _, line in ipairs(map) do
    local rowNode = mapNode:tag('div'):addClass('omega-map-row')
    for col = 1, #line.text do
      local char = line.text:sub(col, col)
      local location = line.locations[col]
      if location then
        local marker = mw.html.create('span')
          :addClass('omega-color-' .. location.class)
          :attr('title', location.label .. ' (' .. location.zh .. ')')
          :attr('aria-label', location.label .. ' (' .. location.zh .. ')')
          :wikitext(mw.text.nowiki(location.char))
        rowNode:wikitext('[[' .. location.target .. '|' .. tostring(marker) .. ']]')
        locations[#locations+1] = {
          target = location.target,
          label = location.label,
          zh = location.zh,
        }
      else
        rowNode:wikitext(mw.text.nowiki(char))
      end
    end
  end

  local directory = root:tag('div')
    :addClass('omega-map-directory')
    :attr('role', 'navigation')
    :attr('aria-label', 'Locations')
  local list = directory:tag('ol')
  for _, location in ipairs(locations) do
    local item = list:tag('li')
    item:wikitext('[[' .. location.target .. '|' .. mw.text.nowiki(location.label) .. ']]')
    item:wikitext(' ')
    item:tag('span')
      :attr('lang', 'zh-Hans')
      :wikitext(mw.text.nowiki(location.zh))
  end

  return tostring(root)
end
return p