Jump to content

Module:Changelog

From Deadlock Wiki
Revision as of 21:55, 21 December 2024 by Sur (talk | contribs) (Early version of reworked changelogs to go by id instead of date)

Overview

Generates lines of changes for all data pages. See [[Category:Changelog Dates]] for the dates of all changelogs, and Changelogs for list of all the data pages that contain a Changelog.

Functions

All of these functions are callable by wikitext, i.e. {{#invoke|Changelog|invokable_name|param1|paramN}}

write_changelog_by_tag

The main invokable that will be used. Given a specific tag, it outputs all relevant changelogs from all dates in a Template:Update history table.

Parameters

  • tag - Tag to search relevant changelogs for. Should be localized, i.e. Abrams for hero_atlas in english.
  • num_dates - (OPTIONAL) Number of dates to add, recommend 3 for articles. If unprovided, defaults to all.

Examples

For use on Pocket/Update history: {{#invoke:Changelog|write_changelog_by_tag|Pocket}}

Outputs Script error: The function "write_changelog_by_tag" does not exist.


For use on Pocket#Update history: {{#invoke:Changelog|write_changelog_by_tag|Pocket|3}}

Outputs

Script error: The function "write_changelog_by_tag" does not exist.

write_changelog_by_date_id

Write's a specific date's changelog, as opposed to a specific tag's changelog.

Parameters

  • date_id_to_write - Date-id to write, format yyyy-mm-dd, view all at [[Category:Changelog Dates]]

Examples

For a non-herolab patch page
{{#invoke:Changelog|write_changelog_by_date_id|2024-05-03}}

Lua error at line 105: attempt to concatenate local 'id' (a nil value).


For a herolab patch page
{{#invoke:Changelog|write_changelog_by_date_id|2024-12-06_HeroLab}}

Lua error at line 105: attempt to concatenate local 'id' (a nil value).

write_data_pages_list

Writes list of all changelog data pages using the list of patches at Data:ChangelogConfigs.json. Used on [[Category:Changelog Dates]].

Parameters

None

Examples

{{#invoke:Changelog|write_data_pages_list}}

Outputs

Data:Changelog 2024-05-03.json
Data:Changelog 2024-05-10.json
Data:Changelog 2024-05-13.json
Data:Changelog 2024-05-16.json
Data:Changelog 2024-05-19.json
Data:Changelog 2024-05-23.json
Data:Changelog 2024-05-24.json
Data:Changelog 2024-05-30.json
Data:Changelog 2024-06-01.json
Data:Changelog 2024-06-06.json
Data:Changelog 2024-06-07.json
Data:Changelog 2024-06-13.json
Data:Changelog 2024-06-14.json
Data:Changelog 2024-06-16.json
Data:Changelog 2024-06-20.json

get_last_updated

Retrieve the last (or first) date that a tag was updated on. Planned to be used on a given tag's page, i.e. Abrams's infobox could mention that it was last updated on 2024-05-03, or that Mirage was released on 2024-05-03, etc.

Parameters

  • tag - Tag to search
  • last_or_first - Named optional - Must be last or first - defaults to last - Retrieves last or first date

Examples

Example using last {{#invoke:Changelog|get_last_updated|Basic Magazine}}

Outputs

2024-05-30


Example using first {{#invoke:Changelog|get_last_updated|Basic Magazine|last_or_first=first}}

Outputs

2024-05-30


local p = {};
local date_module = require('Module:Date')
local changelog_configs = mw.loadJsonData("Data:ChangelogConfigs.json")
local tag_tree = mw.loadJsonData("Data:ChangelogTagTree.json")
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
--Returns all lines of a given date that has that tag
local function write_changelog_lines(id, config, tag_to_filter) 
	-- Get the data for the respective line
	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 = ""
	for index, line in ipairs(changelog_data) do
		description = line["Description"]
		if tag_to_filter == 'All' then
			lines = lines .. description .. "<br>"
		else
			for index2, tag in ipairs(line["Tags"]) do
				if tag == tag_to_filter then
					lines = lines .. description .. "<br>"
				end
			end
		end
	end
	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

-- Write changelogs table
p.write_changelogs = function(frame)
	tag = frame.args[1]
	num_dates_str = frame.args[2]
	local num_dates
	if (tag == nil) then return "tag parameter must be provided" end
	if (num_dates_str ~= nil) then
		num_dates = tonumber(num_dates_str)
		if (num_dates == nil) then return "num_dates parameter must be numerical" end
	end
	
	local template_title = "Update history table"
	local template_args = {}
	local content = "\n"
	
	-- Write changelog for each date
	local index = 0
	for id, config in pairs(changelog_configs) do
		if (num_dates_str ~= nil and index > num_dates) then
			break
		else
			content = content .. write_changelog(id, config, tag) .. "\n"
		end
		index = index+1
	end
	
	template_args["contents"] = content
	
	return mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
end

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

--Shows all changelog date data pages as a list of pages
p.write_data_pages_list = function(frame)
	local str = ""
	
	for i, id in ipairs(ordered_ids) do
		str = str .. "[[" .. id_to_changelog_data_page(id) .. "]]<br>"
	end
	
	return str
end

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

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

p.get_last_updated = function(frame)
	local tag_to_search = frame.args[1]
	
	-- Iterate changelog dates
	for i, id in ipairs(ordered_ids) do
		local config = changelog_configs[id]
		local date = config["date"]
		local changelog_data = mw.loadJsonData(id_to_changelog_data_page(id))
		
		-- Iterate lines
		for _, line in ipairs(changelog_data) do
			local tags = line['Tags']
			
			-- Iterate tags
			for _, tag in ipairs(tags) do
				if tag_to_search == tag then
					return '[[Update:' .. date .. '|' .. date .. ']]'
				end
			end
		end
	end
	
	return dictionary_module.translate('N/A')
end

function p.write_tag_tree(frame)
	return p.write_branch(tag_tree, 1)
end
	
function p.write_branch(branch, depth)
	local list_str = ""
	if branch == nil then return "" end
	
	for parent, children in pairs(branch) do
		list_str = list_str .. string.rep("*", depth) .. string.format("[[%s#Update history|%s]]\n", parent, parent)
		if children ~= nil then
			list_str = list_str .. p.write_branch(children, depth+1)
		end
	end
	
	return list_str
end

return p