Module:AreaMapDisplay: Difference between revisions

From IdleOn MMO Wiki
mNo edit summary
mNo edit summary
Line 3: Line 3:


function p.map(frame)
function p.map(frame)
     local args = frame.args
     local worldImage = frame.args[1]
local WorldImage = args.WorldImage
      
      
     local results = cargo.query(
     local results = cargo.query(

Revision as of 01:31, 25 July 2024

Usage:

{{#invoke:AreaMapDisplay|map|WorldImage=Blunder Hills World Map.png}}

Lua error in mw.text.lua at line 129: bad argument #1 to 'gsub' (string expected, got nil).


The data:

Special:CargoTables/AreaData (edit in Worlds)


local p = {}
local cargo = mw.ext.cargo

function p.map(frame)
    local worldImage = frame.args[1]
    
    local results = cargo.query(
        'AreaMapDisplayData',
        'Area, WorldImage, x, y, Size, ID',
        {where = 'WorldImage = "' .. mw.text.nowiki(WorldImage) .. '"'}
    )

    local root = mw.html.create('div')
        :css({
            position = 'relative',
            left = '0px',
            top = '0px',
            width = '808px',
            height = '428px'
        })



    -- ベースイメージの設定
    root:tag('span')
        :css({
            position = 'absolute',
            left = '0px',
            top = '0px',
            ['z-index'] = 0,
            width = '808px',
            height = '428px'
        })
        :wikitext('[[File:' .. results[1].WorldImage .. '|808x428px]]')

    -- 画像リンク無効化用DIV
    root:tag('div')
        :css({
            position = 'absolute',
            left = '0px',
            top = '0px',
            right = '0px',
            bottom = '0px',
            ['z-index'] = 1,
            ['background-color'] = 'rgba(0, 0, 0, 0)'
        })


    -- 各エリアごとの地点を追加
    for _, record in ipairs(results) do
        root:tag('div')
            :css({
                position = 'absolute',
                left = record.x .. 'px',
                top = record.y .. 'px',
                transform = 'translate(-50%, -50%)',
                ['line-height'] = '95%',
                ['z-index'] = 2
            })
            :wikitext('[[Worlds#' .. record.ID .. ' - ' .. record.Area .. '|' .. tostring(p.createMapPoint(record.ID, record.Area, record.Size + 6)) .. ']]')  
    end

    return tostring(root)
end

function p.createMapPoint(id, text, size)
	-- wiki link [[]]をまたぐので、ヘルプファンクションでinnerdivとspanを作る。
    local innerdiv =  mw.html.create('div')
        :css({
            display = 'inline-flex',
            ['justify-content'] = 'center',
            ['align-items'] = 'center',
            width = size .. 'px',
            height = size .. 'px',
            ['border-radius'] = '50%',
            ['background-color'] = 'rgb(255, 255, 255)',
            border = '2px solid #000000'
        })
        
        innerdiv:tag('span')
            :attr('title', text)
            :css({
                color = 'rgb(0, 0, 0)',
                ['font-size'] = '10px',
                ['font-family'] = "'Helvetica', sans-serif",
                ['font-weight'] = 'bold'
            })
            :wikitext(id)
    return tostring(innerdiv)
end

return p