Module:SpecializationLink: Difference between revisions
From Against the Storm Official Wiki
(Updated with new specialization names; refactored the code; now using StyleUtils) |
(Updated to use new SpecializationsData module, which includes masonry) |
||
Line 1: | Line 1: | ||
---Retrieves and validates data on the specified specialization, then sends data over to the view, another template. | |||
---@module SpecializationLink | |||
local SpecializationLink = {} | local SpecializationLink = {} | ||
Line 5: | Line 7: | ||
--region Dependencies | --region Dependencies | ||
local | local SpecializationsData = mw.loadData("Module:SpecializationsData") | ||
local VIEW_TEMPLATE = "Specialization_link/view" | |||
--endregion | --endregion | ||
Line 12: | Line 16: | ||
--region Private constants | --region Private constants | ||
--endregion | --endregion | ||
Line 102: | Line 23: | ||
--region Public methods | --region Public methods | ||
--- | ---@public | ||
---Validates data then compiles arguments to send to the view template. | |||
--- | --- | ||
---@param frame table the MediaWiki calling context | ---@param frame table the MediaWiki calling context | ||
---@return string wiki markup with the results | ---@return string wiki markup with the results | ||
function SpecializationLink. | function SpecializationLink.main(frame) | ||
-- Extract the template parameters. | --Extract the template parameters. | ||
local | local specialization = frame.args.spec or frame.args[1] | ||
local iconSize = frame.args. | local iconSize = frame.args.size | ||
local showType = frame.args.display == "show_type" | |||
local noText = frame.args.display == "notext" | |||
if not | if not specialization or "" == specialization then | ||
error("The Specialization link template requires the name of a specialization") | |||
end | |||
--Use the icon filename for validation check. | |||
local iconFilename = nil | |||
local type= "Type" | |||
local species = "Species" | |||
for _, specData in ipairs(SpecializationsData.specializations) do | |||
--Once match found, extract the data | |||
if string.lower(specData[SpecializationsData.NAME]) == string.lower(specialization) then | |||
iconFilename = specData[SpecializationsData.ICON_FILENAME] | |||
type = (specData[SpecializationsData.IS_COMFORTABLE] and "Comfort") or (specData[SpecializationsData.IS_PROFICIENCY] and "Proficiency") or "Type" | |||
end | |||
end | end | ||
if not iconFilename then | if not iconFilename then | ||
error("No specialization found with that name: " .. specialization) | |||
end | end | ||
local viewParameters = { | |||
["name"] = specialization, | |||
["iconfilename"] = iconFilename, | |||
["iconsize"] = iconSize, | |||
["type"] = showType and type or "", | |||
["display"] = noText and "notext" or "", | |||
} | |||
return frame:expandTemplate{ | |||
title = VIEW_TEMPLATE, | |||
args = viewParameters, | |||
} | |||
end | end | ||
Revision as of 17:59, 8 November 2024
Documentation for this module may be created at Module:SpecializationLink/doc
---Retrieves and validates data on the specified specialization, then sends data over to the view, another template. ---@module SpecializationLink local SpecializationLink = {} --region Dependencies local SpecializationsData = mw.loadData("Module:SpecializationsData") local VIEW_TEMPLATE = "Specialization_link/view" --endregion --region Private constants --endregion --region Public methods ---@public ---Validates data then compiles arguments to send to the view template. --- ---@param frame table the MediaWiki calling context ---@return string wiki markup with the results function SpecializationLink.main(frame) --Extract the template parameters. local specialization = frame.args.spec or frame.args[1] local iconSize = frame.args.size local showType = frame.args.display == "show_type" local noText = frame.args.display == "notext" if not specialization or "" == specialization then error("The Specialization link template requires the name of a specialization") end --Use the icon filename for validation check. local iconFilename = nil local type= "Type" local species = "Species" for _, specData in ipairs(SpecializationsData.specializations) do --Once match found, extract the data if string.lower(specData[SpecializationsData.NAME]) == string.lower(specialization) then iconFilename = specData[SpecializationsData.ICON_FILENAME] type = (specData[SpecializationsData.IS_COMFORTABLE] and "Comfort") or (specData[SpecializationsData.IS_PROFICIENCY] and "Proficiency") or "Type" end end if not iconFilename then error("No specialization found with that name: " .. specialization) end local viewParameters = { ["name"] = specialization, ["iconfilename"] = iconFilename, ["iconsize"] = iconSize, ["type"] = showType and type or "", ["display"] = noText and "notext" or "", } return frame:expandTemplate{ title = VIEW_TEMPLATE, args = viewParameters, } end --endregion return SpecializationLink