Module:Infotable

From Noita Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Infotable/doc

local inft = {
  InvokeOpts = {},
  Dictionary = {},
  TableField = {},
  Infobox = {},
}

local yutil = require('Module:Y_util');
local ystr = yutil.string;
local ytbl = yutil.table;

local ibh = require('Module:InfoboxHelper');

function formatVar( vadata, base, ext, xopt ) -- this func gets the values of variables
  local function fromDict(id,cell) return (type(id)=="string" and id)
    or(cell~=nil and type(id)=="function" and id(cell))or nil;end
  local itable = vadata.table;
  local fmtData,langext=nil,vadata.lang or "en";  -- formatVar is called from InfoboxHelper
  if( inft.Dictionary[vadata.table] ~= nil ) then
    fmtData = inft.Dictionary[vadata.table][base];
  end
  if( ext == nil ) then -- key string (lang)
    local retv = base;
    if( fmtData ~= nil ) then -- unconditional categories are pulled from the dictionary
      if( ystr.isStrExist( fmtData[langext] ) ) then retv=fmtData[langext]; end
      if( ystr.isStrExist( fmtData.cat      ) ) then retv=fmtData.cat..retv; end
      if( ystr.isStrExist( fmtData.icon     ) ) then retv=fmtData.icon.." "..retv; end
      if( ystr.isStrExist( fmtData.info     ) ) then retv=retv.." "..fmtData.info; end
    end return retv;
  else -- cell value string (tabs) -- conditional category definitions
  -- and extra formatting of values (like processing lists of strings)
    local cellv = vadata.tab_vars[base.."_"..ext];
    local fcond, text, base_set = (fmtData~=nil), {}, false;
    local vcond, celln = ystr.isStrExist(cellv), ystr.parseFloat(cellv);
    --
    if(vcond and fcond)then ytbl.insert_lazy( text, fromDict( fmtData.fmtp, cellv ) );end
    --
    if(not vcond)then
      if(fcond)then ytbl.insert_lazy( text, fromDict( fmtData.defv ) );end
    else
      if( itable=="Spells" ) then
        if( celln~=nil ) then
          if( base=="castDelay" ) then
            if(    celln<0)then table.insert(text,"[[Category:Spells with negative cast delay]]");
            elseif(celln>0)then table.insert(text,"[[Category:Spells with positive cast delay]]");end
          elseif( base=="rechargeDelay" ) then
            if(    celln<0)then table.insert(text,"[[Category:Spells with negative recharge time]]");
            elseif(celln>0)then table.insert(text,"[[Category:Spells with positive recharge time]]");end
          end
        end
      elseif( itable=="Enemies" ) then
        if(base=="spawnLocation" or base=="ngplusSpawnLocation" or base=="ngplus2SpawnLocation" or base=="ngplus3SpawnLocation") then
          base_set=true; table.insert( text, ytbl.concatx(ystr.splitTrim(cellv,","), "[[", "]]", ", " ) );
        elseif(base=="faction") then
          base_set=true; table.insert( text, ytbl.concatx(ystr.splitTrim(cellv,","), "<code>", "</code>", " " ) );
        elseif(base=="immunities") then
          base_set=true; table.insert( text, "<div style=\"display:flex;justify-content:center;\">"..vadata.frame:expandTemplate{ title="Infobox enemy/Immunities",args={cellv} }.."</div>" );
        end
      end
    end
    -- fixed resolution for images
    if(not(base_set))then table.insert( text, cellv );end
    if(base=="image" or base=="icon")then
      if(xopt=="tab") then
        table.insert( text, "|32px" );
      else
        if( (itable=="Spells") )then
          table.insert( text, "|80px" );
        end
      end
    end
    if(vcond and fcond)then ytbl.insert_lazy( text, fromDict( fmtData.fmts, cellv ) );end
    return table.concat( text );
  end
  return "";
end

local function fc_n(n)
  local sym = ""; n = tonumber(n);
  if( n ~= nil ) then
    sym=(n>0 and "+")or(n<0 and "-")or("=");
  end
  return sym;
end
local function fc_0(n)
  local sym = ""; n = tonumber(n);
  if( n ~= nil and n==0 ) then sym = "="; end
  return sym;
end

inft.TableField["Spells"] = {
  -- not part of any group
    "sortKey"           ,
    "image"             ,
    "name"              ,
    "type"              ,
  ["main"] = {
    "description"       ,
    "manaDrain"         ,
    "uses"              ,
    "castDelay"         ,
    "rechargeDelay"     ,
    "spread"            ,
    "spreadMod"         ,
    "lifetime"          ,
    "lifetimeMod"       ,
    "timerLifetime"     ,
    "speed"             ,
    "speedMod"          ,
    "unlockCondition"   ,
  },["damage"] = {
    "damageProjectile"  ,
    "damageDrill"       ,
    "damageElectric"    ,
    "damageExplosion"   ,
    "damageFire"        ,
    "damageHealing"     ,
    "damageIce"         ,
    "damageMelee"       ,
    "damageSlice"       ,
    "criticalChance"    ,
  },["extra"] = {
    "id"                ,
    "recoil"            ,
    "radius"            ,
    "bounces"           ,
    "effect"            ,
    "spawnProbability"  ,
    "spellTier"         ,
  },
}
inft.InvokeOpts["spell"] = {
  tables   = "Spells",
  fields   = "_pageName,type",
  orderBy  = 'type,sortKey,_pageName',
  limit    = 20,
}
function inft.Infobox.spell( vadata, invoke )
  vadata.float = ( invoke.float or "right" );
  vadata.clear = ( invoke.clear or "right" );
  vadata.width = ( invoke.width or "30em"  );
  local Categories = inft.TableField[vadata.table];
  return ibh.vinfobox( vadata, {}, {
    ibh.header( { ["class"]={"ib-group"} }, {
      ibh.vtabs_parse( vadata, { }, { "image", "name" } ),
      ibh.vprops_parse( vadata, { ["class"]={"ib-nokey"}, ["style"]={"text-align:center;"} }, { "name" } ),
      ibh.vprops_parse( vadata, { }, { "type" } )
    })
    ,
    ibh.group( { ["class"]={"ib-nokey"}, "columnize_right" }, {
      ibh.vprops_parse( vadata, { }, { "image" } )
    })
    ,
    ibh.group( {}, {
      ibh.vprops_parse( vadata, { }, Categories["main"] )
    })
    ,
    ibh.group( {}, {
      ibh.header( { ["class"]={"ib-item"},"collapse_btn" }, "Damage Information" ),
      ibh.collapse( {}, {
        ibh.vprops_parse( vadata, { }, Categories["damage"] )
      })
    })
    ,
    ibh.group( {}, {
      ibh.header( { ["class"]={"ib-item"},"collapse_btn" }, "Additional Information" ),
      ibh.collapse( { ["class"]={"mw-collapsed"} }, {
        ibh.vprops_parse( vadata, { }, Categories["extra"] )
      })
    })
  })
end

inft.TableField["Enemies"] = {
  -- not part of any group
    "icon"                 ,
    "image"                ,
    "name"                 ,
    "alias"                ,

    "attackType"           ,
    "critResist"           ,
  ["spawn"] = {
    "spawnLocation"        ,
    "ngplusSpawnLocation"  ,
    "ngplus2SpawnLocation" ,
    "ngplus3SpawnLocation" ,
  },["health"] = {
    "health"               ,
  },["chara"] = {
    "blood"                ,
    "faction"              ,
    "corpse"               ,
  },["immunity"] = {
    "immunities"           ,
  },["multipliers"] = {
    "dmgMultDrill"         ,
    "dmgMultElectricity"   ,
    "dmgMultExplosion"     ,
    "dmgMultFire"          ,
    "dmgMultIce"           ,
    "dmgMultMelee"         ,
    "dmgMultProjectile"    ,
    "dmgMultRadioactive"   ,
    "dmgMultSlice"         ,
  },
  -- ["drops"] = {"drops"},
}
inft.InvokeOpts["enemy"] = {
  tables   = "Enemies",
  fields   = "_pageName,name",
  orderBy  = 'faction,name,_pageName',
  limit    = 20,
}
function inft.Infobox.enemy( vadata, invoke )
  vadata.float = ( invoke.float or "right" );
  vadata.clear = ( invoke.clear or "right" );
  vadata.width = ( invoke.width or "30em"  );
  local Categories = inft.TableField[vadata.table];
  return ibh.vinfobox( vadata, {}, {
    ibh.header( { ["class"]={"ib-group"} }, {
      ibh.vtabs_parse( vadata, { }, { "icon", "name" } ),
      ibh.vprops_parse( vadata, { ["class"]={"ib-nokey"}, ["style"]={"text-align:center;"} }, { "name" } )
    })
    ,
    ibh.group( { ["class"]={"ib-nokey"} }, {
      ibh.vprops_parse( vadata, { ["style"]={"text-align:center;"} }, { "image", "alias" } )
    })
    ,
    ibh.group( {}, {
      ibh.header( { ["class"]={"ib-item"},"collapse_btn" }, "Spawn Locations" ),
      ibh.collapse( {}, {
        ibh.vprops_parse( vadata, { }, Categories["spawn"] )
      })
    })
    ,
    ibh.group( {}, {
      ibh.header( { ["class"]={"ib-item"},"collapse_btn" }, "Health" ),
      ibh.collapse( {}, {
        ibh.vprops_parse( vadata, { }, Categories["health"] )
      })
    })
    ,
    ibh.group( { }, {
      ibh.header( { ["class"]={"ib-item"},"collapse_btn" }, "Characteristics" ),
      ibh.collapse( {}, {
        ibh.vprops_parse( vadata, { "columnize" }, Categories["chara"] )
      })
    })
    ,
    ibh.group( {}, {
      ibh.header( { ["class"]={"ib-item"},"collapse_btn" }, "Crits and shit" ),
      ibh.collapse( { ["class"]={"mw-collapsed"} }, {
        ibh.vprops_parse( vadata, { ["style"]={"text-align: center;"}, "columnize" }, { "attackType" } ),
        ibh.vprops_parse( vadata, { }, { "critResist" } )
      })
    })
    ,
    ibh.group( { ["class"]={"ib-nokey"} }, {
      ibh.header( { ["class"]={"ib-item"},"collapse_btn" }, "Immunities" ),
      ibh.collapse( { ["class"]={"mw-collapsed"} }, {
        ibh.vprops_parse( vadata, { }, Categories["immunity"] )
      })
    })
    ,
    ibh.group( { }, {
      ibh.header( { ["class"]={"ib-item"},"collapse_btn" }, "Damage Multipliers" ),
      ibh.collapse( { ["class"]={"mw-collapsed"} }, {
        ibh.vprops_parse( vadata, { ["style"]={"text-align:center;"}, ["columns"]=3, "columnize" }, Categories["multipliers"] )
      })
    })
    --,
    --ibh.group( {}, {
    --  ibh.header( { ["class"]={"ib-item"},"collapse_btn" }, "Drops" ),
    --  ibh.collapse( { ["class"]={"mw-collapsed"} }, {
    --    ibh.vprops_parse( vadata, { }, Categories["drops"] )
    --  })
    --})
  })
end

-- Dictionaries

inft.Dictionary["Spells"] = {
  ["sortKey"]          = { },
  ["image"]            = { fmtp="[[File:",fmts="]]", defv=nil, en=""               , cat=nil, icon=nil, info=nil },
  ["name"]             = { fmtp=nil  , fmts=nil, defv=nil, en=""                  , cat=nil, icon=nil, info=nil },
  ["type"]             = { fmtp=nil  , fmts=nil, defv=nil, en="Type"              , cat=nil, icon="[[File:Inventory Icon action type.png|x20px|link=|alt=]]" },
--  ,
  ["description"]      = { fmtp=nil  , fmts=nil, defv=nil, en="Description"       , cat=nil, icon=nil },
  ["manaDrain"]        = { fmtp=nil  , fmts=nil, defv=nil, en="Mana Drain"        , cat=nil, icon="[[File:Inventory Icon mana drain.png|x20px|link=|alt=]]" },
  ["uses"]             = { fmtp=nil  , fmts=nil, defv=nil, en="Uses"              , cat="[[Category:Limited use spells]]", icon="[[File:Inventory Icon action max uses.png|x20px|link=|alt=]]" },
  ["castDelay"]        = { fmtp=fc_0 , fmts="s", defv=nil, en="Cast Delay"        , cat=nil, icon="[[File:Inventory Icon fire rate wait.png|x20px|link=|alt=]]" },
  ["rechargeDelay"]    = { fmtp=fc_0 , fmts="s", defv=nil, en="Recharge Time"     , cat=nil, icon="[[File:Inventory Icon gun reload time.png|x20px|link=|alt=]]" },
  ["spread"]           = { fmtp=nil  , fmts=nil, defv=nil, en="Spread"            , cat=nil, icon="[[File:Inventory Icon spread degrees.png|x20px|link=|alt=]]" },
  ["spreadMod"]        = { fmtp=fc_0 , fmts=nil, defv=nil, en="Spread Modifier"   , cat="[[Category:Spells that modify spread]]", icon="[[File:Inventory Icon spread degrees.png|x20px|link=|alt=]]" },
  ["lifetime"]         = { fmtp=nil  , fmts=nil, defv=nil, en="Lifetime"          , cat=nil, icon=nil },
  ["lifetimeMod"]      = { fmtp=fc_0 , fmts=nil, defv=nil, en="Lifetime Modifier" , cat="[[Category:Spells that modify lifetime]]", icon=nil },
  ["timerLifetime"]    = { fmtp=nil  , fmts=nil, defv=nil, en="Timer Lifetime"    , cat="[[Category:Timer spells]]", icon="[[File:Inventory Icon lifetime.png|x20px|link=|alt=]]" },
  ["speed"]            = { fmtp=nil  , fmts=nil, defv=nil, en="Speed"             , cat=nil, icon="[[File:Inventory Icon speed multiplier.png|x20px|link=|alt=]]" },
  ["speedMod"]         = { fmtp="x"  , fmts=nil, defv=nil, en="Speed Modifier"    , cat="[[Category:Spells that modify speed]]", icon="[[File:Inventory Icon speed multiplier.png|x20px|link=|alt=]]" },
  ["unlockCondition"]  = { fmtp=nil  , fmts=nil, defv=nil, en="Unlock"            , cat="[[Category:Unlockable spells]]", icon=nil },
--
  ["damageProjectile"] = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Proj.)"    , cat="[[Category:Projectile damage spells]]", icon="[[File:Inventory Icon damage projectile.png|x20px|link=|alt=]]" },
  ["damageCurse"]      = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Curse)"    , cat=nil, icon="[[File:Icon damage curse.png|x20px|link=|alt=\"Custom icon by Copi\"]]" },
  ["damageDrill"]      = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Drill)"    , cat="[[Category:Drill damage spells]]", icon="[[File:Icon damage drill.png|x20px|link=|alt=\"Custom icon by Copi\"]]" },
  ["damageElectric"]   = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Elec.)"    , cat="[[Category:Electric damage spells]]", icon="[[File:Inventory Icon damage electricity.png|x20px|link=|alt=]]" },
  ["damageExplosion"]  = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Expl.)"    , cat="[[Category:Explosion damage spells]]", icon="[[File:Inventory Icon damage explosion.png|x20px|link=|alt=]]" },
  ["damageFire"]       = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Fire)"     , cat="[[Category:Fire damage spells]]", icon="[[File:Inventory Icon damage fire.png|x20px|link=|alt=]]" },
  ["damageHealing"]    = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Heal)"     , cat="[[Category:Healing damage spells]]", icon="[[File:Icon damage healing.png|x20px|link=|alt=\"Custom icon by Copi\"]]" },
  ["damageIce"]        = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Ice)"      , cat="[[Category:Ice damage spells]]", icon="[[File:Icon damage ice.png|x20px|link=|alt=\"Custom icon by Copi\"]]" },
  ["damageMelee"]      = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Melee)"    , cat="[[Category:Melee damage spells]]", icon="[[File:Icon damage melee alt.png|x20px|link=|alt=\"Custom icon by Copi\"]]" },
  ["damageSlice"]      = { fmtp=nil  , fmts=nil, defv=nil, en="Damage (Slice)"    , cat="[[Category:Slice damage spells]]", icon="[[File:Icon damage slice.png|x20px|link=|alt=\"Custom icon by Copi\"]]" },
  ["criticalChance"]   = { fmtp=nil  , fmts=nil, defv=nil, en="Critical Chance"   , cat="[[Category:Spells that modify critical chance]]", icon="[[File:Inventory Icon damage critical chance.png|x20px|link=|alt=]]" },
--
  ["id"]               = { fmtp="<code>",fmts="</code>", defv=nil, en="ID"        , cat=nil, icon=nil },
  ["recoil"]           = { fmtp=nil  , fmts=nil, defv=nil, en="Recoil"            , cat="[[Category:Spells that modify recoil]]", icon="[[File:Inventory Icon recoil.png|x20px|link=|alt=]]" },
  ["radius"]           = { fmtp=nil  , fmts=nil, defv=nil, en="Radius"            , cat=nil, icon="[[File:Inventory Icon explosion radius.png|x20px|link=|alt=]]" },
  ["bounces"]          = { fmtp=nil  , fmts=nil, defv=nil, en="Bounces"           , cat="[[Category:Spells that modify bounces]]", icon="[[File:Inventory Icon bounces.png|x20px|link=|alt=]]" },
  ["effect"]           = { fmtp=nil  , fmts=nil, defv=nil, en="Effect"            , cat=nil, icon=nil },
  ["spawnProbability"] = { fmtp=nil  , fmts=nil, defv=nil, en="Spawn Probability" , cat=nil, icon=nil, info="[[Spells#Spell_Attributes|ⓘ]]" },
  ["spellTier"]        = { fmtp=nil  , fmts=nil, defv=nil, en="Spell Tiers"       , cat=nil, icon=nil, info="[[Spell Tiers|ⓘ]]" },
}

inft.Dictionary["Enemies"] = {
  ["image"]                = { fmtp="[[File:", fmts="]]", defv=nil,    en=nil           , cat=nil, icon=nil },
  ["icon"]                 = { fmtp="[[File:", fmts="]]", defv=nil,    en=nil           , cat=nil, icon=nil },
  ["name"]                 = { fmtp=nil, fmts=nil, defv=nil,    en=nil           , cat=nil, icon=nil },
  ["alias"]                = { fmtp=nil, fmts=nil, defv=nil,    en=nil           , cat=nil, icon=nil },

  ["spawnLocation"]        = { fmtp=nil, fmts=nil, defv=nil,    en="Normal"      , cat=nil, icon=nil },
  ["ngplusSpawnLocation"]  = { fmtp=nil, fmts=nil, defv=nil,    en="NG+"         , cat=nil, icon=nil },
  ["ngplus2SpawnLocation"] = { fmtp=nil, fmts=nil, defv=nil,    en="NG+2"        , cat=nil, icon=nil },
  ["ngplus3SpawnLocation"] = { fmtp=nil, fmts=nil, defv=nil,    en="NG+3"        , cat=nil, icon=nil },

  ["health"]               = { fmtp=nil, fmts=nil, defv=nil,    en="Health"      , cat=nil, icon=nil },

  ["blood"]                = { fmtp=nil, fmts=nil, defv=nil,    en="Bleeds"      , cat=nil, icon=nil },
  ["faction"]              = { fmtp=nil, fmts=nil, defv=nil,    en="Faction"     , cat=nil, icon=nil, info="[[Factions|ⓘ]]" },
  ["corpse"]               = { fmtp=nil, fmts=nil, defv=nil,    en="Corpse"      , cat=nil, icon=nil },

  ["attackType"]           = { fmtp=nil, fmts=nil, defv=nil,    en="Attacks"     , cat=nil, icon=nil },
  ["critResist"]           = { fmtp=nil, fmts=nil, defv="None", en="Crit Resist" , cat=nil, icon=nil },

  ["immunities"]           = { fmtp=nil, fmts=nil, defv=nil,    en="Immunities"  , cat=nil, icon=nil },

  ["dmgMultDrill"]         = { fmtp=nil, fmts=nil, defv="1.0x", en="Drill"       , cat=nil, icon=nil },
  ["dmgMultElectricity"]   = { fmtp=nil, fmts=nil, defv="1.0x", en="Elec."       , cat=nil, icon=nil },
  ["dmgMultExplosion"]     = { fmtp=nil, fmts=nil, defv="1.0x", en="Expl."       , cat=nil, icon=nil },
  ["dmgMultFire"]          = { fmtp=nil, fmts=nil, defv="1.0x", en="Fire"        , cat=nil, icon=nil },
  ["dmgMultIce"]           = { fmtp=nil, fmts=nil, defv="1.0x", en="Ice"         , cat=nil, icon=nil },
  ["dmgMultMelee"]         = { fmtp=nil, fmts=nil, defv="1.0x", en="Melee"       , cat=nil, icon=nil },
  ["dmgMultProjectile"]    = { fmtp=nil, fmts=nil, defv="1.0x", en="Proj."       , cat=nil, icon=nil },
  ["dmgMultRadioactive"]   = { fmtp=nil, fmts=nil, defv="1.0x", en="Tox."        , cat=nil, icon=nil },
  ["dmgMultSlice"]         = { fmtp=nil, fmts=nil, defv="1.0x", en="Slice"       , cat=nil, icon=nil },
  -- ["drops"] = {"drops"},
}



return inft;