Toggle menu
517
2.5K
889
23.2K
Deadlock Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Changelog: Difference between revisions

From Deadlock Wiki
Sur (talk | contribs)
m write_changelog_by_date_id() warning added if date_id isnt found; used actual forum link
Sur (talk | contribs)
m swap mw.getCurrentFrame() with frame
 
(14 intermediate revisions by 2 users not shown)
Line 33: Line 33:
local function write_changelog_lines(id, config, tag_to_filter)  
local function write_changelog_lines(id, config, tag_to_filter)  
-- Get the data for the respective line
-- Get the data for the respective line
local page_name = id_to_changelog_data_page(id)
local changelog_data = mw.loadJsonData(id_to_changelog_data_page(id))
local title = mw.title.new(page_name)
if not (title and title.exists) then
return ""
end
local changelog_data = mw.loadJsonData(page_name)
local lines = ""
local lines = ""
Line 44: Line 39:
description = line["Description"]
description = line["Description"]
if tag_to_filter == 'All' then
if tag_to_filter == 'All' then
lines = lines .. description .. "<br>"
lines = lines .. description .. "\n"
else
else
for index2, tag in ipairs(line["Tags"]) do
for index2, tag in ipairs(line["Tags"]) do
if tag == tag_to_filter then
if tag == tag_to_filter then
lines = lines .. description .. "<br>"
lines = lines .. description .. "\n"
end
end
end
end
Line 54: Line 49:
end
end
return lines
return lines
end
--Expand the Update history table/row template for 1 specific changelog
local function write_changelog(id, config, tag_to_filter)
local date = config["date"]
local template_title = "Update history table/row"
local template_args = {}
--05-03-2024 to May 3, 2024
template_args["update"] = date_module.format_date(date)
template_args["changes"] = write_changelog_lines(id, config, tag_to_filter)
if (template_args["changes"] ~= "") then
return mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
else
return ""
end
end
end


-- Write changelogs table
-- Write changelogs table
p.write_changelogs = function(frame)
p.write_changelog_by_tag = function(frame)
tag = frame.args[1]
tag = frame.args[1]
num_dates_str = frame.args[2]
num_dates_str = frame.args[2]
Line 87: Line 67:
-- Write changelog for each date
-- Write changelog for each date
local index = 0
for index, id in ipairs(ordered_ids) do
for id, config in pairs(changelog_configs) do
config = changelog_configs[id]
if (num_dates_str ~= nil and index > num_dates) then
if (num_dates_str ~= nil and index > num_dates) then
break
break
else
else
content = content .. write_changelog(id, config, tag) .. "\n"
local date = config["date"]
local frontfacing_date_id = config["frontfacing_date_id"]
local template_title_row = "Update history table/row"
local template_args_row = {}
local changes
--05-03-2024 to May 3, 2024
template_args_row["update"] = frontfacing_date_id
template_args_row["changes"] = write_changelog_lines(id, config, tag)
if (template_args_row["changes"] ~= "") then
changes = frame:expandTemplate{ title = template_title_row, args = template_args_row }
else
changes = ""
end
content = content .. frame:preprocess(changes) .. "\n"
end
end
index = index+1
index = index+1
Line 99: Line 93:
template_args["contents"] = content
template_args["contents"] = content
return mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
return frame:expandTemplate{ title = template_title, args = template_args }
end
end


Line 118: Line 112:


p.write_changelog_by_date_id = function(frame)
p.write_changelog_by_date_id = function(frame)
local date_id_to_write = frame.args[1]
local req_date_id = frame.args[1]
--req = requested, as this is the requested changelog
local config = changelog_configs[req_date_id]
if config == nil then return "date id " .. req_date_id .. " not found" end
local frontfacing_req_date_id = config["frontfacing_date_id"]
local req_is_herolab = config["is_hero_lab"]
-- Determine the previous and next update
-- Determine the previous and next update
-- Find the index in dates list
-- Find the index in dates list
--ordered_ids defined at global scope
--ordered_ids defined at global scope
local previous_id = ''
local previous_ff_id = ''
local the_id = ''
local the_ff_id = ''
local next_id = ''
local next_ff_id = ''
local id_found = false
local id_found = false
local frontfacing_date_id
local is_herolab
for i, id in ipairs(ordered_ids) do
for i, id in ipairs(ordered_ids) do
if id == date_id_to_write then
frontfacing_date_id = changelog_configs[id]["frontfacing_date_id"]
--id found
is_herolab = changelog_configs[id]["is_hero_lab"]
the_id = id
if is_herolab == req_is_herolab then --only look at herolab or non-herolab patches, not mix and match
id_found = true
if frontfacing_date_id == frontfacing_req_date_id then
elseif id_found and next_id == '' then --on next iteration, save the next id
--id found
next_id = id
the_ff_id = frontfacing_date_id
break
the_id = id
end
id_found = true
elseif id_found and next_ff_id == '' then --on next iteration, save the next id
if not id_found then
next_ff_id = frontfacing_date_id
previous_id = id -- only update previous if the_id isnt found
break
end
if not id_found then
previous_ff_id = frontfacing_date_id -- only update previous if the_id isnt found
end
end
end
end
end
if not id_found then
if not id_found then
return "date_id " .. date_id_to_write .. " not found"
return "date_id " .. req_date_id .. " not found"
end
end
local config = changelog_configs[the_id]
local template_title = 'Update layout'
local template_title = 'Update layout'
local template_args = {
local template_args = {
['prev_update'] = prev_id,
['prev_update'] = prev_ff_id,
['current_update'] = the_id,
['current_update'] = the_ff_id,
['next_update'] = next_id,
['next_update'] = next_ff_id,
['source'] = config[link],
['source'] = config[link],
['source_title'] = the_id .. ' Update',
['source_title'] = the_ff_id .. ' Update',
['notes'] = write_changelog_lines(the_id, config, 'All')
['is_herolab'] = req_is_herolab,
['notes'] = frame:preprocess(write_changelog_lines(the_id, config, 'All'))
}
}


return mw.getCurrentFrame():expandTemplate{title = template_title, args = template_args}
return frame:expandTemplate{title = template_title, args = template_args}
end
end


p.get_last_updated = function(frame)
p.get_last_updated = function(frame)
local tag_to_search = frame.args[1]
local tag_to_search = frame.args[1]
local last_or_first = frame.args["last_or_first"]
if last_or_first == nil or last_or_first == 'last' then
last_or_first = 'last'
else
last_or_first = 'first'
end
local list = {}
if last_or_first == 'last' then
list = ordered_ids
else
-- Create the list in reverse
for i = #ordered_ids, 1, -1 do
table.insert(list, ordered_ids[i])
end
end
   
-- Iterate changelog dates
-- Iterate changelog dates
for i, id in ipairs(ordered_ids) do
local frontfacing_date_id
for i, id in ipairs(list) do
-- Get frontfacing date from id
frontfacing_date_id = changelog_configs[id]["frontfacing_date_id"]
-- If next changelog data page doesn't yet exist, return latest page that exists
-- If next changelog data page doesn't yet exist, return latest page that exists
local page_name = id_to_changelog_data_page(id)
local page_name = id_to_changelog_data_page(id)
local title = mw.title.new(page_name)
local title = mw.title.new(page_name)
if not (title and title.exists) then
if not (title and title.exists) then
return '[[Update:' .. id .. '|' .. id .. ']]'
return '[[Update:' .. frontfacing_date_id .. '|' .. frontfacing_date_id .. ']]'
end
end
Line 180: Line 208:
for _, tag in ipairs(tags) do
for _, tag in ipairs(tags) do
if tag_to_search == tag then
if tag_to_search == tag then
return '[[Update:' .. id .. '|' .. id .. ']]'
return '[[Update:' .. frontfacing_date_id .. '|' .. frontfacing_date_id .. ']]'
end
end
end
end
Line 198: Line 226:
for parent, children in pairs(branch) do
for parent, children in pairs(branch) do
list_str = list_str .. string.rep("*", depth) .. string.format("[[%s#Update history|%s]]\n", parent, parent)
-- If parent starts with < or ends with >, its referencing individual page
-- the link won't work, so instead we just display the parent raw
local parent_str
if string.sub(parent, 1, 1) == '<' or string.sub(parent, -1) == '>' then
parent_str = parent
else
parent_str = string.format("[[%s#Update history|%s]]", parent, parent)
end
list_str = list_str .. string.rep("*", depth) .. parent_str .. "\n"
if children ~= nil then
if children ~= nil then
list_str = list_str .. p.write_branch(children, depth+1)
list_str = list_str .. p.write_branch(children, depth+1)