More actions
m Changelog Tag Tree to ChangelogTagTree |
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 | 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 | 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( | 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( | 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"] = | 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 | 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( | content = content .. write_changelog(id, config, tag) .. "\n" | ||
end | end | ||
index = index+1 | |||
end | end | ||
Line 69: | Line 102: | ||
end | end | ||
function | function id_to_changelog_data_page(id) | ||
return "Data:Changelog " .. | return "Data:Changelog " .. id .. ".json" | ||
end | end | ||
Line 77: | Line 110: | ||
local str = "" | local str = "" | ||
for | for i, id in ipairs(ordered_ids) do | ||
str = str .. "[[" .. | str = str .. "[[" .. id_to_changelog_data_page(id) .. "]]<br>" | ||
end | end | ||
Line 84: | Line 117: | ||
end | end | ||
p. | p.write_changelog_by_date_id = function(frame) | ||
local | 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 | --ordered_ids defined at global scope | ||
local | local previous_id = '' | ||
local | local the_id = '' | ||
local | local next_id = '' | ||
for | local id_found = false | ||
if | for i, id in ipairs(ordered_ids) do | ||
-- | if id == date_id_to_write then | ||
--id found | |||
the_id = id | |||
elseif | id_found = true | ||
elseif id_found and next_id == '' then --on next iteration, save the next id | |||
next_id = id | |||
break | break | ||
end | end | ||
if not | if not id_found then | ||
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_update'] = prev_id, | ||
['current_update'] = | ['current_update'] = the_id, | ||
['next_update'] = | ['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'] = | ['source_title'] = the_id .. ' Update', | ||
['notes'] = | ['notes'] = write_changelog_lines(id, changelog_configs[the_id], 'All') | ||
} | } | ||
Line 125: | Line 159: | ||
-- Iterate changelog dates | -- Iterate changelog dates | ||
for | for i, id in ipairs(ordered_ids) do | ||
local changelog_data = mw.loadJsonData( | local config = changelog_configs[id] | ||
local date = config["date"] | |||
local changelog_data = mw.loadJsonData(id_to_changelog_data_page(id)) | |||
-- Iterate lines | -- Iterate lines |