Toggle menu
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 Changelog Tag Tree to ChangelogTagTree
Sur (talk | contribs)
m Early version of reworked changelogs to go by id instead of date
Line 1: Line 1:
local p = {};
local p = {};
local date_module = require('Module:Date')
local date_module = require('Module:Date')
local changelog_dates = mw.loadJsonData("Data:Changelog Dates.json")
local changelog_configs = mw.loadJsonData("Data:ChangelogConfigs.json")
local tag_tree = mw.loadJsonData("Data:ChangelogTagTree.json")
local tag_tree = mw.loadJsonData("Data:ChangelogTagTree.json")
local dictionary_module = require('Module:Dictionary')
local dictionary_module = require('Module:Dictionary')
-- Takes in changelog_configs
-- Returns [oldest_id, next_oldest_id, ..., newest_id]
local function get_ordered_ids(data)
-- Collect the keys into a table
    local keys = {}
    for key in pairs(data) do
        table.insert(keys, key)
    end
    -- Sort the keys (ascending order)
    table.sort(keys)
    -- Build an ordered array
    local ordered_array = {}
    for _, key in ipairs(keys) do
        table.insert(ordered_array, key)
    end
    return ordered_array
end
--Global scope
local ordered_ids = get_ordered_ids(changelog_configs)


--Only Data:Changelog_05-03-2024.json is loaded right now, as it still needs work and for now it was uploaded manually, need an uploader script to handle it
--Only Data:Changelog_05-03-2024.json is loaded right now, as it still needs work and for now it was uploaded manually, need an uploader script to handle it
--Returns all lines of a given date that has that tag
--Returns all lines of a given date that has that tag
local function date_tag_to_lines(date, 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 changelog_data = mw.loadJsonData(date_to_changelog_data_page(date))
local page_name = 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 = ""
for index, line in ipairs(changelog_data) do
for index, line in ipairs(changelog_data) do
Line 27: Line 57:


--Expand the Update history table/row template for 1 specific changelog
--Expand the Update history table/row template for 1 specific changelog
local function write_changelog(date, tag_to_filter)
local function write_changelog(id, config, tag_to_filter)
local date = config["date"]
local template_title = "Update history table/row"
local template_title = "Update history table/row"
local template_args = {}
local template_args = {}
--05-03-2024 to May 3, 2024
--05-03-2024 to May 3, 2024
template_args["update"] = date_module.format_date(date)
template_args["update"] = date_module.format_date(date)
template_args["changes"] = date_tag_to_lines(date, tag_to_filter)
template_args["changes"] = write_changelog_lines(id, config, tag_to_filter)
if (template_args["changes"] ~= "") then
if (template_args["changes"] ~= "") then
return mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
return mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
Line 56: Line 87:
-- Write changelog for each date
-- Write changelog for each date
for index, date in ipairs(changelog_dates) do
local index = 0
for id, config in pairs(changelog_configs) do
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(date, tag) .. "\n"
content = content .. write_changelog(id, config, tag) .. "\n"
end
end
index = index+1
end
end
Line 69: Line 102:
end
end


function date_to_changelog_data_page(date)
function id_to_changelog_data_page(id)
return "Data:Changelog " .. date .. ".json"
return "Data:Changelog " .. id .. ".json"
end
end


Line 77: Line 110:
local str = ""
local str = ""
for index, date in ipairs(changelog_dates) do
for i, id in ipairs(ordered_ids) do
str = str .. "[[" .. date_to_changelog_data_page(date) .. "]]<br>"
str = str .. "[[" .. id_to_changelog_data_page(id) .. "]]<br>"
end
end
Line 84: Line 117:
end
end


p.write_changelog_by_date = function(frame)
p.write_changelog_by_date_id = function(frame)
local date_to_write = frame.args[1]
local date_id_to_write = frame.args[1]
-- Determine the previous and next update
-- Determine the previous and next update
-- Find the index in dates list
-- Find the index in dates list
local previous_date = ''
--ordered_ids defined at global scope
local the_date = ''
local previous_id = ''
local next_date = ''
local the_id = ''
local date_found = false
local next_id = ''
for index, date in ipairs(changelog_dates) do
local id_found = false
if date == date_to_write then
for i, id in ipairs(ordered_ids) do
--Date found
if id == date_id_to_write then
the_date = date
--id found
date_found = true
the_id = id
elseif date_found and next_date == '' then --on next iteration, save the next date
id_found = true
next_date = date
elseif id_found and next_id == '' then --on next iteration, save the next id
next_id = id
break
break
end
end
if not date_found then
if not id_found then
previous_date = date -- only update previous date if the_date isnt found
previous_id = id -- only update previous if the_id isnt found
end
end
end
end
Line 110: Line 144:
local template_title = 'Update layout'
local template_title = 'Update layout'
local template_args = {
local template_args = {
['prev_update'] = prev_date,
['prev_update'] = prev_id,
['current_update'] = the_date,
['current_update'] = the_id,
['next_update'] = next_date,
['next_update'] = next_id,
['source'] = 'https://forums.playdeadlock.com/threads/09-26-2024-update.33015/',
['source'] = 'https://forums.playdeadlock.com/threads/09-26-2024-update.33015/',
['source_title'] = the_date .. ' Update',
['source_title'] = the_id .. ' Update',
['notes'] = date_tag_to_lines(the_date, 'All')
['notes'] = write_changelog_lines(id, changelog_configs[the_id], 'All')
}
}


Line 125: Line 159:
-- Iterate changelog dates
-- Iterate changelog dates
for index, date in ipairs(changelog_dates) do
for i, id in ipairs(ordered_ids) do
local changelog_data = mw.loadJsonData(date_to_changelog_data_page(date))
local config = changelog_configs[id]
local date = config["date"]
local changelog_data = mw.loadJsonData(id_to_changelog_data_page(id))
-- Iterate lines
-- Iterate lines