Module:Creature Mutation Query: Difference between revisions

m
no edit summary
mNo edit summary
mNo edit summary
Line 22: Line 22:
end
end


local query = {
 
result= doQuery(mutation)
mutation, parentheses = formatQuery(result["Cost"], result["Type"])
 
end
 
function doQuery(mutation)
    local query = {
tables = { 'Mutations' },
tables = { 'Mutations' },
fields = {'Cost, Type'},
fields = {'Cost, Type, _pageName'},
where = '(_pageNamespace="14" OR _pageNamespace="0") AND _pageName="' .. mutation..'"',
where = '(_pageNamespace="14" OR _pageNamespace="0") AND _pageName="' .. mutation..'"',
limit= '1'
limit= '1'
}
}
-- Try to find a mutation with this name, if not, just return the name unlinked.
-- Try to find a mutation with this name, if not, just return the name unlinked.
result = util_cargo.queryAndCast(query)[1]
    result = util_cargo.queryAndCast(query)
local parentheses = ""
    if not next(result) then
        return nil
    else return result[1]
    end
end
 
function formatBonus(modifier)
    if modifier > 0 then
      c = "00c420\">+"
    elseif modifier < 0 then
      c= "d74200\">"
return '<span style = \"color:#"=' .. c .. tostring(modifier) .. '</span>'
    end
end
 
function formatResult(page, name, formattedLevel, modifier, showBonus)
  parentheses ='<b><span style="color:#b1c9c3;">&nbsp;(</span><span style="color:#"' .. formattedLevel
  if showBonus then
        parentheses = parentheses .. formatBonus(modifier)
  end
  parentheses = parentheses .. '</span><span style="color:#b1c9c3;">)</span></b>'
-- formatting
local mutationString = mw.html.create('div')
mutationString
  :addClass('qud-mutation-entry')
:wikitext('[[' .. name.. '|'.. page .. parentheses .. ']]')
  return mutationString
end


if query ~= nil then
 
local cost, type = tonumber(result["Cost"]), result["Type"]
function format(page, name, cost, type, level, ego)
     local isDefect = false
     local isDefect = false
     local isMental = false
     local isMental = false
Line 41: Line 75:
     end
     end
     local modifier = math.floor((ego-16)/2)
     local modifier = math.floor((ego-16)/2)
 
    local parentheses = ""
   if isDefect then
   if isDefect then
    parentheses ='<b><span style="color:#b1c9c3;">&nbsp;(</span><span style="color:#a64a2e;">D</span><span style="color:#b1c9c3;">)</b>'
      formattedLevel ='a64a2e;">D'
   elseif (cost == nil or cost > 1) then
   elseif (cost == nil or cost > 1) then
       parentheses = '<b><span style="color:#b1c9c3;">&nbsp;(<span style="color:#77bfcf;">' .. level .. '</span>'
       formattedLevel = '77bfcf;">' .. level
      if isMental then
        local bonus = ""
        if modifier > 0 then
        bonus = "<span style = \"color:#00c420\">+" .. tostring(modifier) .. '</span>'
        elseif modifier < 0 then
          bonus = "<span style = \"color:#d74200\">" .. tostring(modifier) .. '</span>'
        end
        parentheses = parentheses .. bonus
     
    end
  parentheses = parentheses .. ")</span></b>"
   end
   end
 
  return formatResult(page, name, formattedLevel, modifier, isMental)
end
end
-- formatting
local mutationString = mw.html.create('div')
mutationString
  :addClass('qud-mutation-entry')
:wikitext('[[' .. mutation .. '|'.. mutation .. parentheses .. ']]')


return mutationString
function p.test()
a= doQuery("Night Vision")
 
return format(a["_pageName"], "Night Vision", a["cost"], a["type"], 1, 18)
 
end
end


return p
return p