Module:Monster

Revision as of 10:43, 2 November 2025 by Choco (talk | contribs) (Created page with "-- Module:Monster local p = {} local data = require('Module:MonsterData') ---------------------------------------------------------- -- Return a single stat ---------------------------------------------------------- function p.get(frame) local args = frame.args local name = args.name or args[1] local stat = args.stat or args[2] local e = data[name] if not e then return "Monster not found: " .. tostring(name) end if not stat or not e[...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

-- Module:Monster local p = {} local data = require('Module:MonsterData')


-- Return a single stat


function p.get(frame)

   local args = frame.args
   local name = args.name or args[1]
   local stat = args.stat or args[2]
   local e = data[name]
   if not e then
       return "Monster not found: " .. tostring(name)
   end
   if not stat or not e[stat] then
       return "Stat not found: " .. tostring(stat)
   end
   return e[stat]

end


-- Return a single wikitable row (two columns for drops with left-aligned bullet points)


function p.row(frame)

   local args = frame.args
   local name = args.name or args[1]
   local e = data[name]
   if not e then
       return "Monster not found: " .. tostring(name)
   end
   -- Handle drops
   local drops = e.drops or '—'
   if type(drops) == "table" then
       local lines = {}
       for _, drop in ipairs(drops) do
           local icon = drop.icon and frame:expandTemplate{title = drop.icon} .. " " or ""
           local quantity = drop.quantity and drop.quantity .. " " or ""
           local chance = drop.chance and " – " .. drop.chance or ""

table.insert(lines, string.format("

  • %s%s %s%s
  • ", icon, drop.name, quantity, chance)) end drops = "

      " .. table.concat(lines, "") .. "

    "

       end
    
       return string.format(
           '|-\n| File:%s || %s || %s || %s || %s || %s || %s || %s || %s || %s || %s',
           e.image or ,
           name,
           e.element or ,
           e.level or ,
           e.exp or ,
           e.hp or ,
           e.atk or ,
           e.def or ,
           e.mp or ,
           e.spd or ,
           drops
       )
    

    end


    -- Generate a Portable Infobox (single-column drops with icons, left-aligned)


    function p.infobox(frame)

       local args = frame.args
       local name = args.name or args[1]
       local e = data[name]
    
       if not e then
           return "Monster not found: " .. tostring(name)
       end
    
       local infobox_params = {
           name = string.format('%s', name, e.name or name),
           image = e.image and string.format('File:%s', e.image) or "",
           element = e.element or "—",
           level = e.level or "—",
           exp = e.exp or "—",
           hp = e.hp or "—",
           atk = e.attack or "—",
           def = e.defence or "—",
           mp = e.mp or "—",
           spd = e.spd or "—"
       }
    
       -- Single-column drops, left-aligned bullet list
       local drops = e.drops or '—'
       if type(drops) == "table" then
           local lines = {}
           for _, drop in ipairs(drops) do
               local icon = drop.icon and "Template:" .. drop.icon .. " " or ""
               local quantity = drop.quantity and drop.quantity .. " " or ""
               local chance = drop.chance and " – " .. drop.chance or ""
               table.insert(lines, string.format('* %s%s %s%s', icon, drop.name, quantity, chance))
           end
           -- Add newline before first bullet to ensure proper wikitext rendering
    

    infobox_params.drops = "

      \n" .. table.concat(lines, "\n") .. "\n

    "

       else
           infobox_params.drops = drops
       end
    
       return frame:expandTemplate{
           title = "Monster/Infobox",
           args = infobox_params
       }
    

    end

    return p