Module:Area
From IdleOn MMO Wiki
local p = {}
local cargo = mw.ext.cargo
local TEMPLATE_OUTTER = [=[[[Worlds#{{{Area_str}}}|<span class="simple-tooltip simple-tooltip-inline tooltipstered" data-simple-tooltip="{{{html_root}}}">{{{Area}}}</span>]]]=]
local TEMPLATE_ROOT_DIV = [=[<div class='Infobox Detailbox'>{{{html_map}}}{{{html_list_enemy}}}</div>]=]
local TEMPLATE_MAP = [=[<b class='Header'>{{{Area}}}</b>{{{html_map_svg}}}]=]
local TEMPLATE_MAP_SVG = [=[<svg width="100%" height="100%" viewBox="0 0 808 428" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<use id="MapIMG" xlink:href="#_MapIMG" x="0" y="0" width="808px" height="428px" />
{{{html_list_ref_area}}}
{{{html_area}}}
<defs><image id="_MapIMG" width="808px" height="428px" xlink:href="{{filepath:{{{WorldImage}}}}}" /></defs>
</svg>]=]
local TEMPLATE_MAP_RECORD_AREA = [=[<circle cx="{{{x}}}" cy="{{{y}}}" r="15" style="fill:#f0f;stroke:#000;stroke-width:2px;" />]=]
local TEMPLATE_MAP_RECORD_REF = [=[<circle cx="{{{x}}}" cy="{{{y}}}" r="7.5" style="fill:#ff0;stroke:#000;stroke-width:1px;" />]=]
local TEMPLATE_ENEMY = [=[<b class='SubHeader'>The {{{Enemy}}} map</b><i class='HeaderImage'><img src='{{filepath:{{{EnemyImage}}}}}'></i>]=]
local TEMPLATE_ERROR1 = [=[<span style="color: red; font-weight: bold; font-size: larger;">Table `AreaData` contains {{{record_count}}} records for `{{{Area}}}`. Check for typo.</span>]=]
local function fillTemplate(template, args)
return (template:gsub("({{{.-}}})", function(placeholder)
local name = placeholder:sub(4, -4)
return args[name] or placeholder
end))
end
local function prepare_map(Area, WorldImage, Area_x, Area_y)
local html_map_svg = ""
if WorldImage ~= nil and Area_x ~= nil and Area_y ~= nil then
local results2 = cargo.query(
'AreaData',
'Area, WorldImage, x, y, ID',
{where = 'WorldImage = "' ..mw.text.nowiki(WorldImage) .. '"'}
)
local html_area = fillTemplate(TEMPLATE_MAP_RECORD_AREA, {x = Area_x, y = Area_y})
local html_list_ref_area = ""
for _, record in ipairs(results2) do
html_list_ref_area = html_list_ref_area .. fillTemplate(TEMPLATE_MAP_RECORD_REF, {x = record.x, y = record.y})
end
html_map_svg = fillTemplate(TEMPLATE_MAP_SVG, {WorldImage = WorldImage, html_area = html_area, html_list_ref_area = html_list_ref_area})
end
local html_map = fillTemplate(TEMPLATE_MAP, {Area = Area, html_map_svg = html_map_svg})
return html_map
end
local function prepare_enemy(Area)
local html_enemy = ""
local results3 = cargo.query(
'Enemies',
'_pageName=Enemy, Image=EnemyImage',
{where = 'Areas HOLDS LIKE "' .. mw.text.nowiki(Area) .. '"'}
)
for _, record in ipairs(results3) do
html_enemy = html_enemy .. fillTemplate(TEMPLATE_ENEMY, {Enemy = record.Enemy, EnemyImage = record.EnemyImage})
end
return html_enemy
end
function p.run(frame)
local args = frame.args
local Area = args.Area
local results1 = cargo.query(
'AreaData',
'Area, WorldImage, x, y, ID',
{where = 'Area = "' .. mw.text.nowiki(Area) .. '"'}
)
local Area_str = ""
local html_root = ""
if #results1 == 1 then
local ID = tostring(results1[1].ID) or ""
Area_str = ID .. " - " .. results1[1].Area
local html_map = prepare_map(Area, results1[1].WorldImage, results1[1].x, results1[1].y)
local html_list_enemy = prepare_enemy(Area)
html_root = fillTemplate(TEMPLATE_ROOT_DIV, {html_map = html_map, html_list_enemy =html_list_enemy})
else
Area_str = Area
html_root = fillTemplate(TEMPLATE_ERROR1, {record_count = #results1, Area = Area})
end
local output = fillTemplate(TEMPLATE_OUTTER, {Area_str = Area_str,Area = Area, html_root = html_root})
return output
end
return p