Module:GetImage

--| Centralized InfoIcon lookup for The Sims Wiki on FANDOM --by Isaac Fischer  --$Id: GetImage.lua,v 0.5 2018/04/15 00:00:00 FishTank Exp $ --TODO remaining functions

local GetImage = {} local HF = require('Module:HF') local getArgs = require('Dev:Arguments').getArgs local Images = mw.loadData( 'Module:GetImage/data' )

-- --   --

--% Creates an "internal link"-style  reference --@ filename (string)  reference --@ size (string) Visible image /media width --@ linkTarget (string) Page / Article linked-to on click --: (string) Image / Media  link local function ImageLink ( filename, size, linkTarget ) if not HF.isempty( filename ) then return string.format( '%s'..'%s]]', '[[',           filename ..            (size and '|'..size or ) ..            ( linkTarget and '|link='..linkTarget or )        ) end end

--% Meta-function for frame invocations of internal public functions local function makeInvokeFunc(funcName) return function (frame) local args = getArgs(frame) return GetImage[funcName](args) end end

local function parameterImage ( args, data, size, target ) local parameter = args[1]:match('') or ( not data[args[1]:lower] and args[1] ) local value = parameter and data[args[parameter]:lower] or data[args[1]:lower] local linktarget = target or args[parameter] or args[1] return value and ImageLink( 'File:'..value, size, linktarget ) or args[1] end

-- If wrappers are declared, these functions only work when invoked directly.

--% replaces --@ frame (table) Arguments passed from direct invocation and template call --: (string)  link | rendered image / media GetImage.Game = makeInvokeFunc('_Game') --% & retrieves game logo from central table --@ args (table) Arguments passed from Module function call function GetImage._Game ( args ) local VG_LOGO = require('Module:VGcode')._toLogo local VG_CODE = require('Module:VGcode')._toTitle return ImageLink( VG_LOGO( args[1], args[2] ), '50px', VG_CODE( args[1] ) ) end

--% replaces --@ frame (table) Arguments passed from direct invocation and template call [.Gender] --: (string) File: link / rendered image / media GetImage.Gender = makeInvokeFunc('_Gender') --% & retrieves Gender infoicon from central table --@ args (table) Arguments passed from Module function call [._Gender] function GetImage._Gender ( args ) if args[1] then return parameterImage ( args, Images.Gender, '20px', 'Gender' ) end end

--% replaces --@ frame (table) Arguments passed from direct invocation and template call [.Gender2] --: (string) File: link / rendered image / media GetImage.Gender2 = makeInvokeFunc('_Gender2') --% & retrieves Gender (Type 2) infoicon from central table --@ args (table) Arguments passed from Module function call [._Gender2] function GetImage._Gender2 ( args ) if args[1] then return parameterImage ( args, Images.Gender2, '20px', 'Gender' ) end end

--% replaces --@ frame (table) Arguments passed from direct invocation and template call [.Stage] --: (string) File: link / rendered image / media GetImage.Stage = makeInvokeFunc('_Stage') --% & retrieves Stage infoicon from central table --@ args (table) Arguments passed from Module function call [._Stage] function GetImage._Stage ( args ) if args[1] then return parameterImage ( args, Images.Stage, '20px', nil ) end end

function GetImage.State ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetStateImage' } ) end function GetImage.State2 ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetState2Image' } ) end function GetImage.School ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetSchoolImage' } ) end function GetImage.Career ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetCareerImage' } ) end function GetImage.Career2 ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetCareer2Image' } ) end function GetImage.Career3 ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetCareer3Image' } ) end function GetImage.Trait ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetTraitImage' } ) end function GetImage.MedievalTrait ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetMedievalTraitImage' } ) end function GetImage.Sign ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetSignImage' } ) end function GetImage.Sign2 ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetSign2Image' } ) end function GetImage.Aspiration ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetAspirationImage' } ) end function GetImage.Aspiration3 ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetAspiration3Image' } ) end function GetImage.Want ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetWantImage' } ) end function GetImage.Wish ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetWishImage' } ) end function GetImage.Favorites ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetFavoritesImage' } ) end function GetImage.Chemistry ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetChemistryImage' } ) end function GetImage.Appearance ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetAppearanceImage' } ) end function GetImage.Appearance2 ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetAppearance2Image' } ) end function GetImage.Celebrity ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetCelebrityImage' } ) end function GetImage.Reputation ( frame ) local args = getArgs( frame, { wrappers = 'Template:GetReputationImage' } ) end return GetImage