From Dark and Darker Wiki

m (moved icon to its own column instead)
m (testing)
Tag: Reverted
Line 9: Line 9:
hidden_or_nonhidden = "hidden"
hidden_or_nonhidden = "hidden"
end
end
return hidden_or_nonhidden
local html = ""
local record
for index, achievement in ipairs(achievements) do
-- Ensure only the hidden or nonhidden are shown depending on parameter
local is_hidden
if achievement.hidden == 'true' then
is_hidden = true
else
is_hidden = false
end
if (is_hidden and hidden_or_nonhidden == "nonhidden") or
(not is_hidden and hidden_or_nonhidden == "hidden") then
break
end
record = "<tr>\n"
record = record .. "<td>" .. (achievement.localized_name) .. "</td>\n"
record = record .. "<td>" .. "[[File:" .. achievement.icon .. ".png|45px]]"  .. "</td>\n"
record = record .. "<td>" .. (achievement.main_category or '') .. "</td>\n"
record = record .. "<td>" .. (achievement.sub_category or '') .. "</td>\n"
record = record .. "<td>" .. (achievement.prerequisite or '') .. "</td>\n"
record = record .. "<td>" .. (achievement.description) .. "</td>\n"
record = record .. "</tr>\n"
html = html .. record .. "\n"
end
return mw.getCurrentFrame():preprocess(html)
end
end


return p
return p

Revision as of 04:27, 22 December 2024

Overview

Functions for Data:Achievements.json

Functions

create_achievements_table_body

Creates the body of a html function with 6 pre-set columns

Parameters

  • hidden_or_nonhidden - defaults to nonhidden - must be hidden or nonhidden - Displays only hidden or nonhidden achievements

Examples

Ensure to surround it by html table and its headers:

<table class="wikitable sortable">
<tr>
    <th>Name</th>
    <th>Icon</th>
    <th>Category</th>
    <th>Sub-Category</th>
    <th>Pre-requisite</th>
    <th>Description</th>
</tr>
{{#invoke:Achievements|create_achievements_table_body}}
</table>

nonhidden
Name Icon Category Sub-Category Pre-requisite Description




Example of hidden achievements only

<table class="wikitable mw-collapsible mw-collapsed">
<tr>
    <th>Name</th>
    <th>Icon</th>
    <th>Category</th>
    <th>Sub-Category</th>
    <th>Pre-requisite</th>
    <th>Description</th>
</tr>
{{#invoke:Achievements|create_achievements_table_body|hidden}}
</table>

hidden
Name Icon Category Sub-Category Pre-requisite Description

local p = {}
local achievements = mw.loadJsonData("Data:Achievements.json")

function p.create_achievements_table_body(frame)
	local hidden_or_nonhidden = frame.args[1]
	if hidden_or_nonhidden == nil then 
		hidden_or_nonhidden = "nonhidden"
	elseif hidden_or_nonhidden ~= "nonhidden" then
		hidden_or_nonhidden = "hidden"
	end
	return hidden_or_nonhidden
	
	
end

return p