Module:SpecializationLink
From Against the Storm Official Wiki
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