From Dark and Darker Wiki
m (temp changing colspan from 2 to 1 in header to check if it affects the body) Tag: Reverted |
Tag: Undo |
||
Line 18: | Line 18: | ||
-- Iterate enchant groups | -- Iterate enchant groups | ||
for i, slot_name in ipairs(enchantments_data["slottype_order"]) do | for i, slot_name in ipairs(enchantments_data["slottype_order"]) do | ||
slot_headers = slot_headers .. '<th colspan=" | slot_headers = slot_headers .. '<th colspan="2">' .. slot_name .. '</th>' | ||
min_max_headers = min_max_headers .. '<th>Min</th>' .. '<th>Max</th>' | min_max_headers = min_max_headers .. '<th>Min</th>' .. '<th>Max</th>' | ||
end | end |
Revision as of 20:53, 23 February 2025
Overview
Functions for Enchantments. Data comes from Data:Enchantments.json.
Functions
draw_roll_range_table
Create's a table of enchants for the Enchantments page
Parameters
- base_or_gem - List 'base' (traditional) or 'gem' enchant roll ranges?
Examples
{{#invoke:Enchantments|draw_roll_range_table|gem}}
Script error: The function "draw_roll_range_table" does not exist.
draw_socket_cost_table
Create's a table of socket's cost per rarity for the Enchantments page
Parameters
none
Examples
{{#invoke:Enchantments|draw_socket_cost_table}}
Script error: The function "draw_socket_cost_table" does not exist.
local enchantments_data = mw.loadJsonData("Data:Enchantments.json")
local p = {}
function p.draw_table(base_or_gem)
-- Handle based on how it was called
if type(base_or_gem) == "table" and base_or_gem.args then -- if called via wikitext instead of lua
local frame = base_or_gem
base_or_gem = frame.args[1]
end
-- Validate
if base_or_gem ~= "base" and base_or_gem ~= "gem" then return "1st parameter 'base_or_gem' must be either 'base' or 'gem'." end
local slot_headers = '<th rowspan="2"></th><th rowspan="2">Enchantments</th>'
local min_max_headers = ''
-- Create enchant_name_headers (row1) and min/max (row2)
-- Iterate enchant groups
for i, slot_name in ipairs(enchantments_data["slottype_order"]) do
slot_headers = slot_headers .. '<th colspan="2">' .. slot_name .. '</th>'
min_max_headers = min_max_headers .. '<th>Min</th>' .. '<th>Max</th>'
end
-- Add body rows
local enchant_rows = ""
local enchant_row
for i, enchant_group_name in ipairs(enchantments_data["enchant_group_order"]) do
local enchants_in_group = enchantments_data["enchant_order"][enchant_group_name]
if enchants_in_group == nil then return "Error: " .. enchant_group_name .. " not found in \"enchant_order\"" end
-- Iterate enchants in the group
-- First just determine how many enchants are in the group to get the proper rowspan
local num_enchants_in_group = 0
for i, enchant_name in ipairs(enchants_in_group) do
num_enchants_in_group = num_enchants_in_group + 1
end
local is_first = true
for i, enchant_name in ipairs(enchants_in_group) do
-- Get that enchant's data
local slots_data = enchantments_data["enchant_rolls"][enchant_name]
if slots_data == nil then return "Error: " .. enchant_name .. " not found in \"enchant_rolls\"" end
-- Iterate slottypes
local min_max_cols = ""
for i, slot_type in ipairs(enchantments_data["slottype_order"]) do
slot_data = slots_data[slot_type]
-- Get rolls, default to blank if missing
local min_roll = ""
local max_roll = ""
if slot_data ~= nil then
local roll_data = slot_data[base_or_gem]
if roll_data ~= nil then
min_roll = roll_data["min"]
max_roll = roll_data["max"]
end
end
if min_roll == nil then min_roll = "" end
if max_roll == nil then max_roll = "" end
min_max_cols = min_max_cols .. "<td>" .. min_roll .. "</td>"
min_max_cols = min_max_cols .. "<td>" .. max_roll .. "</td>"
end
local rowspanned_cell = ''
if is_first then
rowspan = ' rowspan="' .. num_enchants_in_group .. '"'
rowspanned_cell = '<td' .. rowspan .. '>' .. enchant_group_name .. "</td>"
end
enchant_row = '' .. rowspanned_cell
enchant_row = enchant_row .. "<td>" .. enchant_name .. "</td>"
enchant_row = enchant_row .. "<td>" .. min_max_cols .. "</td>"
enchant_rows = enchant_rows .. "<tr>" .. enchant_row .. "</tr>"
is_first = false
end
end
local slot_headers = "<tr>" .. slot_headers .. "</tr>"
local min_max_headers = "<tr>" .. min_max_headers .. "</tr>"
local table_str = '<table class="wikitable">' .. slot_headers .. min_max_headers .. enchant_rows .. "</table>"
return table_str
end
return p