Module:SpecializationLink: Difference between revisions
From Against the Storm Official Wiki
(created) |
m (renaming first parameter to name for consistency with other link templates) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
--- | ---Retrieves and validates data on the specified specialization, then sends data over to the view, another template. | ||
---@module SpecializationLink | |||
- | |||
-- @module SpecializationLink | |||
local SpecializationLink = {} | local SpecializationLink = {} | ||
-- | --region Dependencies | ||
local SpecializationsData = mw.loadData("Module:SpecializationsData") | |||
-------------- | local VIEW_TEMPLATE = "Specialization_link/view" | ||
--endregion | |||
-- | |||
- | |||
- | |||
-- @param frame | --region Private constants | ||
--endregion | |||
- | |||
-- @return | |||
function SpecializationLink. | --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.name 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 | end | ||
--endregion | |||
return SpecializationLink | return SpecializationLink |
Latest revision as of 21:53, 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.name 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