Module:Area: Difference between revisions
From IdleOn MMO Wiki
Kiokurashi (talk | contribs) mNo edit summary Tags: Manual revert Reverted |
Kiokurashi (talk | contribs) m (Undo revision 78996 by Kiokurashi (talk)) Tag: Undo |
||
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 19: | Line 20: | ||
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 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) | local function fillTemplate(template, args) | ||
Line 29: | Line 28: | ||
end | end | ||
local function prepare_map(Area | local function prepare_map(Area, Area_x, Area_y) | ||
local html_map_svg = "" | local html_map_svg = "" | ||
local WorldImage = | local WorldImage = AreaMapDisplay.getWorldImageData(Area) | ||
if WorldImage and Area_x and Area_y then | if WorldImage and Area_x and Area_y then | ||
Line 37: | Line 36: | ||
'AreaData', | 'AreaData', | ||
'Area, World, x, y, ID', | 'Area, World, x, y, ID', | ||
{where = ' | {where = 'WorldImage = "' .. mw.text.nowiki(WorldImage) .. '"'} | ||
) | ) | ||
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 53: | Line 52: | ||
return html_map | return html_map | ||
end | end | ||
local function prepare_enemy(Area) | local function prepare_enemy(Area) | ||
Line 83: | Line 81: | ||
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 | local html_map = prepare_map(Area, results1[1].x, results1[1].y) | ||
local html_list_enemy = prepare_enemy(Area) | 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}) | ||
Line 94: | Line 92: | ||
return output | return output | ||
end | end | ||
return p | return p |
Revision as of 14: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, Area_x, Area_y)
local html_map_svg = ""
local WorldImage = AreaMapDisplay.getWorldImageData(Area)
if WorldImage and Area_x and Area_y then
local results2 = cargo.query(
'AreaData',
'Area, World, 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, 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].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