Module:AbilityData/hero: Difference between revisions
Jump to navigation
Jump to search
m return ret enclosed in tabbber |
m removing old funcs |
||
(15 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local ability_module = require("Module: | local ability_module = require("Module:Abilities/card") | ||
local dictionary_module = require("Module:Dictionary") | local dictionary_module = require("Module:Dictionary") | ||
local lang_module = require("Module:Lang") | local lang_module = require("Module:Lang") | ||
Line 8: | Line 8: | ||
-- Write each of the hero's ability cards in a tab of a tabber | -- Write each of the hero's ability cards in a tab of a tabber | ||
function write_hero_abilities(frame) | function p.write_hero_abilities(frame) | ||
local hero_key = frame.args[1] | local hero_key = frame.args[1] | ||
Line 22: | Line 22: | ||
local ability_name_en = ability_data["Name"] | local ability_name_en = ability_data["Name"] | ||
local ability_name_localized = lang_module.get_string(ability_key) | local ability_name_localized = lang_module.get_string(ability_key) | ||
local notes_str_localized = dictionary_module.translate('Notes', nil, '') | local notes_str_localized = dictionary_module.translate('Notes', nil, '') | ||
local tab_name = "|-|(" .. ability_num .. ")" .. ability_name_en .. "=" | local tab_name = "|-|(" .. ability_num .. ") " .. ability_name_en .. "=" | ||
local | |||
--Determine notes link | |||
local notes_source_page | |||
local notes_untranslated_msg = '' | |||
-- if either "Notes" string or ability_name is not able to be localized, | |||
-- use an english link instead, as transcluded content relies on it | |||
if (ability_name_localized == '') or (notes_str_localized == '') then | |||
notes_source_page = ability_name_en .. '/' .. dictionary_module.translate('Notes', 'en', '') | |||
if notes_str_localized=='' then | |||
notes_untranslated_msg = dictionary_module.translate('NotesNeedsTranslation') .. ' [[Template:Translate]]' .. "<br>" | |||
end | |||
else | |||
notes_source_page = ability_name_localized .. '/' .. notes_str_localized | |||
end | |||
notes_source_page = "User:Sur/" .. notes_source_page --temp | |||
--Determine tab content | |||
local tab_content = "<i>" .. dictionary_module.translate_embed( | |||
'TranscludedNotesFrom', | 'TranscludedNotesFrom', | ||
'https://en.wikipedia.org/wiki/Help:Transclusion', | 'https://en.wikipedia.org/wiki/Help:Transclusion', | ||
'[[ | '[['..notes_source_page..']]', | ||
'https://deadlocked.wiki/index.php?title= | 'https://deadlocked.wiki/index.php?title='..util_module.url_encode(notes_source_page)..'&action=edit' | ||
) .. "</i>" | ) .. "</i><br>" .. notes_untranslated_msg | ||
local tab_content = | local tab_content = tab_content .. ability_module.get_ability_card_from_key( | ||
hero_key, | |||
ability_num, | |||
'true', | |||
'{{'..notes_source_page..'}}' | |||
) | |||
ret = ret .. tab_name .. tab_content | ret = ret .. tab_name .. tab_content | ||
end | end | ||
ret = "<tabber>" .. ret .. "</tabber>" | |||
return frame:preprocess(ret) | |||
end | |||
--collapsible list | |||
function p.write_hero_abilities2(frame) | |||
local hero_key = frame.args[1] | |||
--Determine the hero's abilities | |||
local hero_data = heroes_data[hero_key] | |||
if (hero_data==nil) then return "Hero key "..hero_key.." not found" end | |||
local abilities_data = hero_data["BoundAbilities"] | |||
if (abilities_data==nil) then return "Hero key"..hero_key.." has no BoundAbilities" end | |||
local ret = "" | |||
for ability_num, ability_data in pairs(abilities_data) do | |||
local ability_key = ability_data["Key"] | |||
local ability_name_en = ability_data["Name"] | |||
local ability_name_localized = lang_module.get_string(ability_key) | |||
local notes_str_localized = dictionary_module.translate('Notes', nil, '') | |||
local tab_name = "<h3>" .. ability_name_localized .. "</h3>\n" | |||
--Determine notes link | |||
local notes_source_page | |||
local notes_untranslated_msg = '' | |||
-- if either "Notes" string or ability_name is not able to be localized, | |||
-- use an english link instead, as transcluded content relies on it | |||
if (ability_name_localized == '') or (notes_str_localized == '') then | |||
notes_source_page = ability_name_en .. '/' .. dictionary_module.translate('Notes', 'en', '') | |||
if notes_str_localized=='' then | |||
notes_untranslated_msg = '<br>' .. dictionary_module.translate('NotesNeedsTranslation') .. ' [[Template:Translate]]' .. "<br>" | |||
end | |||
else | |||
notes_source_page = ability_name_localized .. '/' .. notes_str_localized | |||
end | |||
notes_source_page = "User:Sur/" .. notes_source_page --temp | |||
--Determine tab content | |||
local notes_content = '{{'..notes_source_page..'}}' | |||
local tab_content = ability_module.get_ability_card_from_key( | |||
hero_key, | |||
ability_num, | |||
'true', | |||
frame:preprocess(notes_content) | |||
) | |||
ret = ret .. tab_name .. tab_content .. '\n' | |||
end | |||
return frame:preprocess(ret) | |||
end | end | ||
return p | return p |
Latest revision as of 16:09, 6 November 2024
Documentation for this module may be created at Module:AbilityData/hero/doc
local ability_module = require("Module:Abilities/card")
local dictionary_module = require("Module:Dictionary")
local lang_module = require("Module:Lang")
local util_module = require("Module:Utilities")
local heroes_data = mw.loadJsonData("Data:HeroData.json")
local p = {}
-- Write each of the hero's ability cards in a tab of a tabber
function p.write_hero_abilities(frame)
local hero_key = frame.args[1]
--Determine the hero's abilities
local hero_data = heroes_data[hero_key]
if (hero_data==nil) then return "Hero key "..hero_key.." not found" end
local abilities_data = hero_data["BoundAbilities"]
if (abilities_data==nil) then return "Hero key"..hero_key.." has no BoundAbilities" end
local ret = ""
for ability_num, ability_data in pairs(abilities_data) do
local ability_key = ability_data["Key"]
local ability_name_en = ability_data["Name"]
local ability_name_localized = lang_module.get_string(ability_key)
local notes_str_localized = dictionary_module.translate('Notes', nil, '')
local tab_name = "|-|(" .. ability_num .. ") " .. ability_name_en .. "="
--Determine notes link
local notes_source_page
local notes_untranslated_msg = ''
-- if either "Notes" string or ability_name is not able to be localized,
-- use an english link instead, as transcluded content relies on it
if (ability_name_localized == '') or (notes_str_localized == '') then
notes_source_page = ability_name_en .. '/' .. dictionary_module.translate('Notes', 'en', '')
if notes_str_localized=='' then
notes_untranslated_msg = dictionary_module.translate('NotesNeedsTranslation') .. ' [[Template:Translate]]' .. "<br>"
end
else
notes_source_page = ability_name_localized .. '/' .. notes_str_localized
end
notes_source_page = "User:Sur/" .. notes_source_page --temp
--Determine tab content
local tab_content = "<i>" .. dictionary_module.translate_embed(
'TranscludedNotesFrom',
'https://en.wikipedia.org/wiki/Help:Transclusion',
'[['..notes_source_page..']]',
'https://deadlocked.wiki/index.php?title='..util_module.url_encode(notes_source_page)..'&action=edit'
) .. "</i><br>" .. notes_untranslated_msg
local tab_content = tab_content .. ability_module.get_ability_card_from_key(
hero_key,
ability_num,
'true',
'{{'..notes_source_page..'}}'
)
ret = ret .. tab_name .. tab_content
end
ret = "<tabber>" .. ret .. "</tabber>"
return frame:preprocess(ret)
end
--collapsible list
function p.write_hero_abilities2(frame)
local hero_key = frame.args[1]
--Determine the hero's abilities
local hero_data = heroes_data[hero_key]
if (hero_data==nil) then return "Hero key "..hero_key.." not found" end
local abilities_data = hero_data["BoundAbilities"]
if (abilities_data==nil) then return "Hero key"..hero_key.." has no BoundAbilities" end
local ret = ""
for ability_num, ability_data in pairs(abilities_data) do
local ability_key = ability_data["Key"]
local ability_name_en = ability_data["Name"]
local ability_name_localized = lang_module.get_string(ability_key)
local notes_str_localized = dictionary_module.translate('Notes', nil, '')
local tab_name = "<h3>" .. ability_name_localized .. "</h3>\n"
--Determine notes link
local notes_source_page
local notes_untranslated_msg = ''
-- if either "Notes" string or ability_name is not able to be localized,
-- use an english link instead, as transcluded content relies on it
if (ability_name_localized == '') or (notes_str_localized == '') then
notes_source_page = ability_name_en .. '/' .. dictionary_module.translate('Notes', 'en', '')
if notes_str_localized=='' then
notes_untranslated_msg = '<br>' .. dictionary_module.translate('NotesNeedsTranslation') .. ' [[Template:Translate]]' .. "<br>"
end
else
notes_source_page = ability_name_localized .. '/' .. notes_str_localized
end
notes_source_page = "User:Sur/" .. notes_source_page --temp
--Determine tab content
local notes_content = '{{'..notes_source_page..'}}'
local tab_content = ability_module.get_ability_card_from_key(
hero_key,
ability_num,
'true',
frame:preprocess(notes_content)
)
ret = ret .. tab_name .. tab_content .. '\n'
end
return frame:preprocess(ret)
end
return p