Module:Area: Difference between revisions
From IdleOn MMO Wiki
mNo edit summary |
Kiokurashi (talk | contribs) mNo edit summary |
||
(13 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local AreaMapDisplay = require('Module:AreaMapDisplay') | |||
local TEMPLATE_OUTTER = [=[[[Worlds#{{{Area_str}}}|<span class="simple-tooltip simple-tooltip-inline tooltipstered" data-simple-tooltip="{{{html_root}}}">{{{Area}}}</span>]]]=] | local TEMPLATE_OUTTER = [=[[[Worlds#{{{Area_str}}}|<span class="simple-tooltip simple-tooltip-inline tooltipstered" data-simple-tooltip="{{{html_root}}}">{{{Area}}}</span>]]]=] | ||
Line 27: | Line 28: | ||
end | end | ||
local function prepare_map(Area, | local function prepare_map(Area, World_ID, Area_x, Area_y) | ||
local html_map_svg = "" | local html_map_svg = "" | ||
local WorldImage = AreaMapDisplay.getWorldImageData() | |||
if WorldImage | |||
if WorldImage and Area_x and Area_y then | |||
local results2 = cargo.query( | local results2 = cargo.query( | ||
'AreaData', | 'AreaData', | ||
'Area, | 'Area, World, x, y, ID', | ||
{where = ' | {where = 'World = "' .. World_ID .. '"'} | ||
) | ) | ||
local html_area = fillTemplate(TEMPLATE_MAP_RECORD_AREA, {x = Area_x, y = Area_y}) | local html_area = fillTemplate(TEMPLATE_MAP_RECORD_AREA, {x = Area_x, y = Area_y}) | ||
Line 42: | Line 44: | ||
html_list_ref_area = html_list_ref_area .. fillTemplate(TEMPLATE_MAP_RECORD_REF, {x = record.x, y = record.y}) | html_list_ref_area = html_list_ref_area .. fillTemplate(TEMPLATE_MAP_RECORD_REF, {x = record.x, y = record.y}) | ||
end | end | ||
html_map_svg = fillTemplate(TEMPLATE_MAP_SVG, {WorldImage = WorldImage[tonumber(World_ID)].image, html_area = html_area, html_list_ref_area = html_list_ref_area}) | |||
html_map_svg = fillTemplate(TEMPLATE_MAP_SVG, {WorldImage = WorldImage, html_area = html_area, html_list_ref_area = html_list_ref_area}) | |||
end | end | ||
Line 72: | Line 72: | ||
local results1 = cargo.query( | local results1 = cargo.query( | ||
'AreaData', | 'AreaData', | ||
'Area, | 'Area, World, x, y, ID', | ||
{where = 'Area = "' .. mw.text.nowiki(Area) .. '"'} | {where = 'Area = "' .. mw.text.nowiki(Area) .. '"'} | ||
) | ) | ||
local html_root = "" | local html_root = "" | ||
Line 81: | Line 80: | ||
if #results1 == 1 then | if #results1 == 1 then | ||
local ID = tostring(results1[1].ID) or "" | local ID = tostring(results1[1].ID) or "" | ||
local html_map = prepare_map(Area, results1[1]. | local html_map = prepare_map(Area, results1[1].World, results1[1].x, results1[1].y) | ||
local html_list_enemy = | local html_list_enemy = prepare_enemy(Area) | ||
html_root = fillTemplate(TEMPLATE_ROOT_DIV, {html_map = html_map, html_list_enemy =html_list_enemy}) | html_root = fillTemplate(TEMPLATE_ROOT_DIV, {html_map = html_map, html_list_enemy = html_list_enemy}) | ||
output = fillTemplate(TEMPLATE_OUTTER, {Area_str = Area,Area = Area, html_root = html_root}) | output = fillTemplate(TEMPLATE_OUTTER, {Area_str = Area, Area = Area, html_root = html_root}) | ||
else | else | ||
html_root = fillTemplate(TEMPLATE_ERROR1, {record_count = #results1, Area = Area}) | html_root = fillTemplate(TEMPLATE_ERROR1, {record_count = #results1, Area = Area}) | ||
output = fillTemplate(TEMPLATE_OUTTER, {Area_str = Area,Area = Area, html_root = html_root}) .. [=[[[Category:Error Template Area]]]=] | output = fillTemplate(TEMPLATE_OUTTER, {Area_str = Area, Area = Area, html_root = html_root}) .. [=[[[Category:Error Template Area]]]=] | ||
end | end | ||
return output | return output | ||
end | end | ||
return p | return p |
Latest revision as of 15:27, 16 October 2024
local p = {}
local cargo = mw.ext.cargo
local AreaMapDisplay = require('Module:AreaMapDisplay')
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, World_ID, Area_x, Area_y)
local html_map_svg = ""
local WorldImage = AreaMapDisplay.getWorldImageData()
if WorldImage and Area_x and Area_y then
local results2 = cargo.query(
'AreaData',
'Area, World, x, y, ID',
{where = 'World = "' .. World_ID .. '"'}
)
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[tonumber(World_ID)].image, 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, World, x, y, ID',
{where = 'Area = "' .. mw.text.nowiki(Area) .. '"'}
)
local html_root = ""
local output = ""
if #results1 == 1 then
local ID = tostring(results1[1].ID) or ""
local html_map = prepare_map(Area, results1[1].World, 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})
output = fillTemplate(TEMPLATE_OUTTER, {Area_str = Area, Area = Area, html_root = html_root})
else
html_root = fillTemplate(TEMPLATE_ERROR1, {record_count = #results1, Area = Area})
output = fillTemplate(TEMPLATE_OUTTER, {Area_str = Area, Area = Area, html_root = html_root}) .. [=[[[Category:Error Template Area]]]=]
end
return output
end
return p