Module:OmegaMap

From Omega Wiki
Revision as of 10:39, 26 July 2026 by OmegaAdmin (talk | contribs) (以 Omega 0.90.4 源码地图替换示意图并链接地点草稿)
Jump to navigation Jump to search

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

local p = {}

-- OMEGA-SOURCE commit=009707d17482b977061a6223b9de63eac4d368c3
-- staging/remake/winomega/country.c:8-113 decrypts and loads the 64x64 map.
-- staging/remake/winomega/defs.h:687-707 defines terrain glyphs and colors.
-- staging/remake/winomega/lib/country.dat contains the encrypted map cells.
local remakeSource = [=[^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+^^^^^%^^^^^^^^^^^^^---^^^^^^^^^^^^^^^^((((((------^^^^^^^^^~~^^
++^^~^^v^^^---------------((((((((((((((((((--------^^^^^^~~~~~^
+++^^~^^v^^------------(((((((((((((((((((((((((------^^^~~~~|~^
++++^^~^^v^------((((((((((((((^^^((((((((((------------^^^~v~~^
++++^~^^v^^----------((((((((((^5^((((((((-------.......a~~^~~~^
++++^^~d^^--------------(((((((^(^(((((---------.------~~^^^^^^^
+++----~.......-----------((((((((((-----------.------~~--^^^^^^
++++--~--------.......------((((((((((((------.-------~^^^^^^^^^
+++++++---------------.......(((((((((-------.--------~~--^^^^^^
+++++++----------------------......-.........--------~~-----^^^^
+++++++++--------------((((((((((((b(((((((------^^3~~------^^^^
++++++++++++---------------(((((((.(((((((------^^^~~-------^^^^
++++++++++-------((((((((((((((((.(((((((((((((^^^-~~-------^^^^
+++++++----------------(((((((((.(((((((((---^^^----~~------^^^^
++++++++++++---------------((((.(((((((((--^^^-----~~---^^^^^^^^
++++++++++++++++--------------.--------^^^^^------~~---^^^^^^^^^
+++++++++++++++++++----------.------^^^^---------~~---^^^^^^^^^^
++++++++++++++++++++++++----.---v^^^^^^^^-((((--~~----------^^^^
+++++++++++++++++++++++++++O--^^^v^^^((((((((((((~~---^^^^^^^^^^
+++++++++++++-------------.----^^^v^(((((((((((((~~(----^^^^^^^^
++++++++++---------------.-^^^^^^(((((((((((((((~~((--------^^^^
++++++++++++++++++++++...-^*^^^^(((((((((((((((~~((((((-----^^^^
++++++++++++++++++-...-----^^^-(((((((((((((((~~(((((((((---^^^^
+++++++++++++-----.------^^^^((((((((((((((((~~(((((((((----^^^^
++++++++++-------.-----^^^^--((((((((((((((~~~(((((((((-----^^^^
++++++++++++++++.------^^^-------(((((((((~~(((((((((((((---^^^^
+++++++++++++++.------^^^---((((((((((((((~~(((((((--------^^^^^
+++++++++++++++.-----^^^(((((((((((((((~~~~(((((((-------^^^^^^^
+++++++++++++--.------vvv(((((((((((~~~~(((((((((-------^^^"^^^^
+++++++++++++++.-----^1^-------((~~~~(((((((((((((((-^^^^^""^^^^
+++++++++++++++.------^^^-----((~~~((((((((((((((((-^^^"""""^^^^
++++++++++-----.----^^^------(((((~~(((((((((---^^^^""""""""^^^^
++++++++-------.----^^^-(((((((((((~((((((((((((--^"""""""^^^^^^
++++++---------.-----^^^(((((((((((~~((((((((((--^^^""""""""$^^^
+++++++++++++++.----^^-(((((((((((~~((((((((((--^^^"""""""""^^^^
+++++++++++++++.-----^^^^((((((((~~(((((((((-------""""""""^^^^^
++++++++++++---.----^^^(((((((~~~~(((((((-----^^""""""""""""^^^^
+++++++++++++++.---^^^-(((~~~~~(((((((------^^^"""""""""""""^^^^
+++++++++++++++.---^^^^~~~~(((((----------^^^"""""""""""""""^^^^
++++++++++c....-...~~~~~-((((((((((-----^^^^""""""""""""""""^^^^
++++++++++++++~~~~~.f==-------------^^^^""""""""""""""""^^^^^^^^
++++++++++++=====~==~======----^^^^^^^^^"""""""""""""""""""^^^^^
+++++++++++=====~====~====---------------e""""""""""""""^^^^^^^^
+++++++++++++++~====~====-^^-------^^^^^^"""""""""""""""""""^^^^
+++++++++++++++====~====-^^------^^^"""""""""2"""""""""""---^^^^
+++++++++++++=====~4~===---^-----^^"""""""""""---^^^^-------^^^^
++++++++++=======~==~====---------^^"""""""""--^^-----------^^^^
+++++++++++++===~====~====--^--------""""""---^^-)))-^^-----^^^^
++++++++++++===~======~===---^^^^------------^^~)))))--^^---^^^^
+++++++++++++++======~======-----^^^------^----)~)))))--^^^-^^^^
+++++++++++++++=====~===^=======--~~~^^^-^---))))~))))))----^^^^
++++++++++++++=====~=============~~=~~~~^^))))))))~))))))))-^^^^
+++++++++++++++===~=~~~~~~=====~~~~====^^^^)))))))~)))))))^^^^^^
++++&++++++++++==~========~~~~~~==~~~~===^^^)))))))~))))))))^^^^
+++++=+++++++===~=~=========~===~~===~~~~~~^^)))))))~)))))^^^^^^
++++++=++++++++~===~===^===~===~=====~====^^^^)))))))~))))))^^^^
+++++++=+++++++====~~=====~===^=======~====^^)))))))))~)))))^^^+
++++++++=+========~==~===~===^!^=======~===^^^))+++)))~)))^^^^++
+++++++++=++=====~====~=~~====^=======~=~=^^^)))+6+))~)))^^^^+++
++++++++++++====~======~==~++++======~===~==^^))+++))~^^^^^+++++
++++++++++++++++========~++++++++===~====~^^^^^^^+^^^^~^^+++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++]=]

local remakeRows = mw.text.split(remakeSource, '\n', true)
assert(#remakeRows == 64, 'Omega 0.90.4 country map must have 64 rows')
for rowNumber, row in ipairs(remakeRows) do
  assert(#row == 64, 'Omega 0.90.4 country map row ' .. rowNumber .. ' must have 64 columns')
end

local terrain = {
  ['-'] = { char='-', class='light-green' },
  ['_'] = { char='_', class='grey' },
  ['.'] = { char='.', class='brown' },
  ['^'] = { char='^', class='grey' },
  ['v'] = { char='v', class='brown' },
  ['~'] = { char='~', class='blue' },
  ['O'] = { char='O', class='white' },
  ['('] = { char='(', class='light-green' },
  [')'] = { char=')', class='green' },
  ['='] = { char='=', class='green' },
  ['!'] = { char='!', class='red' },
  ['%'] = { char='%', class='grey' },
  ['X'] = { char='X', class='brown' },
  ['*'] = { char='*', class='black-on-brown' },
  ['"'] = { char='"', class='yellow' },
  ['+'] = { char='+', class='light-purple' },
  ['|'] = { char='|', class='light-blue' },
  ['$'] = { char='$', class='brown' },
  ['&'] = { char='&', class='purple' },
}

local remakeLocations = {
  ['%'] = { target="Draft:Archmage's Castle", label="Archmage's Castle", zh='大法师城堡', char='%', class='grey' },
  ['|'] = { target='Draft:Star Peak', label='Star Peak', zh='星辰峰', char='|', class='light-blue' },
  ['*'] = { target='Draft:Goblin Caves', label='Goblin Caves', zh='地精洞窟', char='*', class='black-on-brown' },
  ['!'] = { target='Draft:HellWell Volcano', label='HellWell Volcano', zh='地狱井火山', char='!', class='red' },
  ['$'] = { target="Draft:Dragon's Lair", label="Dragon's Lair", zh='龙穴', char='$', class='brown' },
  ['&'] = { target='Draft:Magic Isle', label='Magic Isle', zh='魔法岛', char='&', class='purple' },
  ['O'] = { target='Draft:Rampart', label='Rampart', zh='兰帕特', char='O', class='white' },
  ['a'] = { target='Draft:Village 1', label='Village 1', zh='村庄 1', char='o', class='white' },
  ['b'] = { target='Draft:Village 2', label='Village 2', zh='村庄 2', char='o', class='white' },
  ['c'] = { target='Draft:Village 3', label='Village 3', zh='村庄 3', char='o', class='white' },
  ['d'] = { target='Draft:Village 4', label='Village 4', zh='村庄 4', char='o', class='white' },
  ['e'] = { target='Draft:Village 5', label='Village 5', zh='村庄 5', char='o', class='white' },
  ['f'] = { target='Draft:Village 6', label='Village 6', zh='村庄 6', char='o', class='white' },
  ['1'] = { target='Draft:Temple of Odin', label='Temple of Odin', zh='奥丁神殿', char='X', class='brown' },
  ['2'] = { target='Draft:Temple of Set', label='Temple of Set', zh='赛特神殿', char='X', class='brown' },
  ['3'] = { target='Draft:Temple of Athena', label='Temple of Athena', zh='雅典娜神殿', char='X', class='brown' },
  ['4'] = { target='Draft:Temple of Hecate', label='Temple of Hecate', zh='赫卡忒神殿', char='X', class='brown' },
  ['5'] = { target='Draft:Temple of Druidism', label='Temple of Druidism', zh='德鲁伊神殿', char='X', class='brown' },
  ['6'] = { target='Draft:Temple of Destiny', label='Temple of Destiny', zh='命运神殿', char='X', class='brown' },
}

local maps = {
  remake = {
    rows=remakeRows,
    terrain=terrain,
    locations=remakeLocations,
    aria='Omega 0.90.4 countryside map',
    draft=true,
  },
  classic = {
    rows={
      '##H######',
      '#.......#',
      '#..T....#',
      '#########',
    },
    terrain={},
    locations={
      H={ target='Classic:Locations/Harbor', label='Harbor', zh='港口', char='H', class='cyan' },
      T={ target='Classic:Locations/Town', label='Town', zh='城镇', char='T', class='yellow' },
    },
    aria='classic map',
    draft=false,
  },
}

local function appendCell(rowNode, text, className)
  local cell = rowNode:tag('span')
  if className then
    cell:addClass('omega-color-' .. className)
  end
  cell:wikitext(mw.text.nowiki(text))
end

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', map.aria)
  local locations = {}

  for rowIndex, row in ipairs(map.rows) do
    local rowNode = mapNode:tag('div'):addClass('omega-map-row')
    local pendingClass = nil
    local pendingText = ''

    local function flushPending()
      if pendingText ~= '' then
        appendCell(rowNode, pendingText, pendingClass)
        pendingClass = nil
        pendingText = ''
      end
    end

    for col = 1, #row do
      local sourceChar = row:sub(col, col)
      local location = map.locations[sourceChar]
      if location then
        flushPending()
        local x = col - 1
        local y = rowIndex - 1
        local title = location.label .. ' (' .. location.zh .. '; x=' .. x .. ', y=' .. y .. ')'
        local marker = mw.html.create('span')
          :addClass('omega-color-' .. location.class)
          :attr('title', title)
          :attr('aria-label', title)
          :wikitext(mw.text.nowiki(location.char))
        rowNode:wikitext('[[' .. location.target .. '|' .. tostring(marker) .. ']]')
        locations[#locations + 1] = {
          target=location.target,
          label=location.label,
          zh=location.zh,
          x=x,
          y=y,
        }
      else
        local cell = map.terrain[sourceChar] or { char=sourceChar, class=nil }
        if pendingClass ~= cell.class then
          flushPending()
          pendingClass = cell.class
        end
        pendingText = pendingText .. cell.char
      end
    end
    flushPending()
  end

  local directory = root:tag('div')
    :addClass('omega-map-directory')
    :attr('role', 'navigation')
    :attr('aria-label', map.draft and 'Draft locations from Omega 0.90.4' or 'Locations')
  if map.draft then
    directory:tag('p')
      :addClass('omega-map-draft-note')
      :wikitext('Location articles are pending review in the Draft namespace. ')
      :tag('span')
        :attr('lang', 'zh-Hans')
        :wikitext('地点条目均位于 Draft 命名空间,等待审核。')
  end
  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))
    item:wikitext(' ')
    item:tag('span')
      :addClass('omega-map-coordinates')
      :wikitext('(x=' .. location.x .. ', y=' .. location.y .. ')')
  end

  return tostring(root)
end

return p