Module:Favilink

From Caves of Qud Wiki
Revision as of 16:56, 8 September 2019 by Teamtoto (talk | contribs) (Have to test call parser function outside of debug console)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Template-info.png Documentation

!!Currently only for use for objects in the tables: ItemsTable, Food, Corpses, Characters, Locations. All possible items can be found here: Special:CargoTables/GeneralData.

Usage

Used similar to regular wikipage linking syntax. First argument takes name of the object and will pull the image from that item. This must be called using Template:Favilink.

{{favilink|Stopsvalinn}}

Lua error: callParserFunction: function "#ifexists" was not found.

Optional Parameters

You can use the following values as the second argument:

plural pluralizes the item name while preserving the color formatting.
{{favilink |antimatter cell|plural}}

Lua error: callParserFunction: function "#ifexists" was not found.

possessive makes the item name possessive while preserving the color formatting.
{{favilink | Q Girl | possessive}}

Lua error at line 39: attempt to call field 'modulenonxmlparse' (a nil value).

displayname-tooltip-override makes the hover tooltip equal to the display name for items whose display name doesn't match their page name, such as cybernetics credit wedge 1¢. This is probably only needed in special locations where part of the favilink can get truncated, such as in the Character infobox's Inventory list.
{{favilink | cybernetics credit wedge 1¢ | displayname-tooltip-override}}
Lua error at line 39: attempt to call field 'modulenonxmlparse' (a nil value).

Compare to tooltip when this parameter is not specified:

Lua error: callParserFunction: function "#ifexists" was not found.
prefix:<prefix> Prepends a prefix to the name, which can include qud text color styles.
{{favilink | mental aggregator | prefix:&ylant&Ye&Wr&Yn&yed}}

Lua error at line 39: attempt to call field 'modulenonxmlparse' (a nil value).

suffix:<suffix> Postpends a suffix to the name, which can include qud text color styles.
{{favilink | plasma grenade | suffix:mk II}}

Lua error at line 39: attempt to call field 'modulenonxmlparse' (a nil value).

<any other value> completely overrides the name shown in the favilink to whatever argument specified.
{{favilink|torch|A &Rreally&y spicy meatball}}

Lua error at line 39: attempt to call field 'modulenonxmlparse' (a nil value).


local p = {}
local cargo= mw.ext.cargo
local htmlparse = require'Module:HTMLParse'
local colorparse = require'Module:ColorParse'

function p.favilink(frame,arg)

--[Getting query results...]
--local name = frame
--local modifier = arg or ''
local name=frame.args[1] or ''
local modifier=frame.args[2] or ''

local result = cargo.query('GeneralData','_pageName=Page, DisplayName, Image, DisplayChar',{where='_pageNamespace="0" AND PlainName="' .. name:gsub("'", "''") .. '"', default=name, limit='1'} )

if not next(result) then
  return 'There wasn\'t any results!'
end

local pagelink = result[1]['Page'] or name
local displayname = result[1]['DisplayName'] or name
local image = result[1]['Image'] or 'None'
local displaychar = result[1]['DisplayChar'] or '•'

--[Setting display name modifiers...]
local display

if modifier == 'plural' then
  local displayresult = htmlparse.pluralize( {args= {html = displayname} })
  display=displayresult

elseif modifier == 'possessive' then
  local displayresult = htmlparse.make_possessive({ args = {html = displayname} })
  display=displayresult

elseif modifier == '' then
  display = displayname
else
  display= colorparse.modulenonxmlparse(name)
end

local imageexists = frame:callParserFunction{name = '#ifexists', args={'File:'.. image, 'yeah', 'nah'}}
return imageexists
--return '<span class="qud-image"><span class="qud-image-link-image-container">' .. display

end

return p