Module:Changelog: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
m write_data_pages_list bullet pointed
Sur (talk | contribs)
m Changelog Tag Tree to ChangelogTagTree
(22 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {};
local p = {};
local date_module = require('Module:Date')
local changelog_dates = mw.loadJsonData("Data:Changelog Dates.json")
local tag_tree = mw.loadJsonData("Data:ChangelogTagTree.json")
local dictionary_module = require('Module:Dictionary')


--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
Line 5: Line 9:
local function date_tag_to_lines(date, tag_to_filter)  
local function date_tag_to_lines(date, tag_to_filter)  
-- Get the data for the respective line
-- Get the data for the respective line
local changelog_data = mw.loadJsonData("Data:Changelog_" .. date .. ".json")
local changelog_data = mw.loadJsonData(date_to_changelog_data_page(date))
local lines = ""
local lines = ""
for index, line in ipairs(changelog_data) do
for index, line in ipairs(changelog_data) do
description = line["Description"]
description = line["Description"]
for index2, tag in ipairs(line["Tags"]) do
if tag_to_filter == 'All' then
if tag == tag_to_filter then
lines = lines .. description .. "<br>"
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
end
Line 18: Line 26:
end
end


--testing by invoke in sandbox, will be called properly by other funcs later
--Expand the Update history table/row template for 1 specific changelog
p.invoke_date_tag_to_lines = function(frame)
local function write_changelog(date, tag_to_filter)
date = frame.args[1]
local template_title = "Update history table/row"
tag = frame.args[2]
local template_args = {}
return date_tag_to_lines(date, tag)
--05-03-2024 to May 3, 2024
template_args["update"] = date_module.format_date(date)
template_args["changes"] = date_tag_to_lines(date, 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
for index, date in ipairs(changelog_dates) do
if (num_dates_str ~= nil and index > num_dates) then
break
else
content = content .. write_changelog(date, tag) .. "\n"
end
end
template_args["contents"] = content
return mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
end
 
function date_to_changelog_data_page(date)
return "Data:Changelog " .. date .. ".json"
end
end


Line 28: Line 76:
p.write_data_pages_list = function(frame)
p.write_data_pages_list = function(frame)
local str = ""
local str = ""
local changelog_dates = mw.loadJsonData("Data:Changelog Dates")
for index, date in ipairs(changelog_dates) do
for index, date in ipairs(changelog_dates) do
str = str .. "* [[Data:Changelog " .. date .. ".json]]<br>"
str = str .. "[[" .. date_to_changelog_data_page(date) .. "]]<br>"
end
end
return str
return str
end
p.write_changelog_by_date = function(frame)
local date_to_write = frame.args[1]
-- Determine the previous and next update
-- Find the index in dates list
local previous_date = ''
local the_date = ''
local next_date = ''
local date_found = false
for index, date in ipairs(changelog_dates) do
if date == date_to_write then
--Date found
the_date = date
date_found = true
elseif date_found and next_date == '' then --on next iteration, save the next date
next_date = date
break
end
if not date_found then
previous_date = date -- only update previous date if the_date isnt found
end
end
local template_title = 'Update layout'
local template_args = {
['prev_update'] = prev_date,
['current_update'] = the_date,
['next_update'] = next_date,
['source'] = 'https://forums.playdeadlock.com/threads/09-26-2024-update.33015/',
['source_title'] = the_date .. ' Update',
['notes'] = date_tag_to_lines(the_date, '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 index, date in ipairs(changelog_dates) do
local changelog_data = mw.loadJsonData(date_to_changelog_data_page(date))
-- 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
end


return p
return p

Revision as of 22:13, 14 December 2024

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.

How to edit changelogs

Each changelogs should be exactly as written on the forum post, so edits are rarely justified, below are the exceptions to look out for

What are tags?

Each line in a changelog is parsed by User:DeadBot to have certain tags assigned to it. For example, if the forum post looks like Abrams: Shoulder Bash blah blah

It will be assigned tags, Shoulder Bash since its named explicitly, and therefore Ability, Abrams, and Hero. This will make this line added to all changelogs on pages Abrams/Update history, Shoulder Bash/Update history, Ability/Update history, and Hero/Update history.

Similarly, for the line Warp Stone: Distance traveled blah blah, the tags assigned would be Warp Stone since its named explicitly, along with the tags Item and Weapon Item.


Missing tags

Given the line Yamato: Shadow Explosion bonus Spirit per victim increased from 10 to 15, User:DeadBot will be able to assign the Yamato tag, but will not know which ability it is referring to, as Yamato's ability was renamed to Shadow Transformation. This would originally appear as

        "Description": "* {{PageRef|Yamato}}: Shadow Explosion bonus Spirit per victim increased from 10 to 15",
        "Tags": [
            "Yamato",
            "Hero"
        ]

To correct is, simply add the related tags for Shadow Transformation. To determine the related tags, see To see all related tags, see Module:Changelog/doc#Tag tree. Add the call to Template:PageRef in the description. The alt_name parameter will need to be passed to nickname the ability as Shadow Explosion, so that it stays written as is, but still links and is added to the relevant pages. The corrected changelog would then be

        "Description": "* {{PageRef|Yamato}}: {{PageRef|Shadow Transformation|alt_name=Shadow Explosion}} bonus Spirit per victim increased from 10 to 15",
        "Tags": [
            "Yamato",
            "Hero",
            "Ability",
            "Shadow Transformation"
        ]


Similar tags are assigned

Given the line * McGinnis: Heavy Barrage spirit scaling increased from 0.3 to 0.35, User:DeadBot will see both McGinnis' Heavy Barrage ability and Pocket's Barrage ability and assign both as tags. This would originally appear as

        "Description": "* {{PageRef|McGinnis}}: {{PageRef|Heavy Barrage}} spirit scaling increased from 0.3 to 0.35",
        "Tags": [
            "McGinnis",
            "Hero",
            "Heavy Barrage",
            "Ability",
            "Barrage",
            "Pocket"
        ]

To correct it, first determine if its referring to McGinnis' Heavy Barrage or Pocket's Barrage. In this case, it is quite obvious that its referring to McGinnis' Heavy Barrage. Then, simply remove all tags related to Pocket's Barrage. This includes both "Barrage" and "Pocket". To determine all related tags, see Module:Changelog/doc#Tag tree.

The corrected list of tags would then be

        "Tags": [
            "McGinnis",
            "Hero",
            "Heavy Barrage",
            "Ability",
        ]

Similarly, for the following example

        "Description": "* {{PageRef|Torment Pulse}}: Interval improved from 2s to 1.5s",
        "Tags": [
            "Torment Pulse",
            "Item",
            "Spirit Item",
            "Pulse",
            "Ability",
            "Rutger",
            "Hero"
        ]

It is actually referring to Torment Pulse the Item, so the tags "Pulse", "Ability", and "Rutger", "Hero" would all need to be removed.


Another example, given the line:

        "Description": "* {{PageRef|Cosmic Veil|alt_name=Veil}} {{PageRef|Walker}}: Cooldown increased from 20s to 25s",
        "Tags": [
            "Veil Walker",
            "Item",
            "Vitality Item",
            "Objective",
            "NPC",
            "Walker"
            "Cosmic Veil"
        ]

Here, the changelog is clearly referring to the item Veil Walker, not Cosmic Veils and Walkers. The fixed line would be:

        "Description": "* {{PageRef|Veil Walker}}: Cooldown increased from 20s to 25s",
        "Tags": [
            "Veil Walker",
            "Item",
            "Vitality Item",
            "Objective",
            "NPC",
        ]

Tag referenced but unaffected

Given the line Surge of Power: When the passive procs, you no longer get slowed when shooting (similar to Fleetfoot)., User:DeadBot will assign the tag Fleetfoot and all its related tags, even if Fleetfloot wasn't actually changed or modified at all. This would originally appear as

        "Description": "* {{PageRef|Surge of Power}}: When the passive procs, you no longer get slowed when shooting (similar to {{PageRef|Fleetfoot}})",
        "Tags": [
            "Fleetfoot",
            "Item",
            "Weapon Item",
            "Surge of Power",
            "Spirit Item"
        ]

To correct it, remove Fleetfoot and all its related tags (Weapon Item tag in this case), but leave the call to PageRef so that it can still refer users to the Fleetfoot page. After correction it should be

        "Description": "* {{PageRef|Surge of Power}}: When the passive procs, you no longer get slowed when shooting (similar to {{PageRef|Fleetfoot}})",
        "Tags": [
            "Item",
            "Surge of Power",
            "Spirit Item"
        ]

Tag tree

The tag tree is how to determine what tags are related. Given a tag, the tags that are in the same chain and have a shorter indentation will/should also be added to the list of tags.

For example, any change to Frost Bomb will also be referenced on the pages Ability, Kelvin, and Hero.

More Tag tree examples:

  • If Map tag is assigned, no other tags should be assigned
  • If Weapon Item is assigned, Basic Magazine shouldn't be assigned unless it is also referenced in the line, but Item should be assigned
  • If Basic Magazine is assigned, Weapon Item, and Item should be assigned

The full tree can be found at Changelogs

Functions

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

write_changelogs

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_changelogs|Pocket}}

Outputs Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates.json' is not a valid JSON page).


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

Outputs

Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates.json' is not a valid JSON page).

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

{{#invoke:Changelog|write_changelog_by_date_id|2024-05-03}}

Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates.json' is not a valid JSON page).

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

Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates.json' is not a valid JSON page).

get_last_updated

Retrieve the last 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.

Parameters

  • tag - Tag to search

Examples

{{#invoke:Changelog|get_last_updated|Basic Magazine}}

Outputs

Lua error: bad argument #1 to 'mw.loadJsonData' ('Data:Changelog Dates.json' is not a valid JSON page).


local p = {};
local date_module = require('Module:Date')
local changelog_dates = mw.loadJsonData("Data:Changelog Dates.json")
local tag_tree = mw.loadJsonData("Data:ChangelogTagTree.json")
local dictionary_module = require('Module:Dictionary')

--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 date_tag_to_lines(date, tag_to_filter) 
	-- Get the data for the respective line
	local changelog_data = mw.loadJsonData(date_to_changelog_data_page(date))
	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(date, tag_to_filter)
	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"] = date_tag_to_lines(date, 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
	for index, date in ipairs(changelog_dates) do
		if (num_dates_str ~= nil and index > num_dates) then
			break
		else
			content = content .. write_changelog(date, tag) .. "\n"
		end
	end
	
	template_args["contents"] = content
	
	return mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
end

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

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

p.write_changelog_by_date = function(frame)
	local date_to_write = frame.args[1]
	
	-- Determine the previous and next update
	-- Find the index in dates list
	local previous_date = ''
	local the_date = ''
	local next_date = ''
	local date_found = false
	for index, date in ipairs(changelog_dates) do
		if date == date_to_write then
			--Date found
			the_date = date
			date_found = true
		elseif date_found and next_date == '' then --on next iteration, save the next date
			next_date = date
			break
		end
		
		if not date_found then
			previous_date = date -- only update previous date if the_date isnt found
		end
	end
	
	local template_title = 'Update layout'
	local template_args = {
		['prev_update'] = prev_date,
		['current_update'] = the_date,
		['next_update'] = next_date,
		['source'] = 'https://forums.playdeadlock.com/threads/09-26-2024-update.33015/',
		['source_title'] = the_date .. ' Update',
		['notes'] = date_tag_to_lines(the_date, '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 index, date in ipairs(changelog_dates) do
		local changelog_data = mw.loadJsonData(date_to_changelog_data_page(date))
		
		-- 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