Module:Ideas

From Roots of Pacha Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Ideas/doc

local p = {}

local ideasTable = mw.loadData('Module:Ideas/data')
local pagename = mw.title.getCurrentTitle().text

function p.getInfobox(frame)
local ideaData = ideasTable[pagename]
local ideaName = ideaData.originalName or pagename
local ideaImage = ideaData.alternativeImage or pagename
 if not ideasTable then return "Data not found! Please refer '''[[module:Ideas/data]]'''" end
 local template = [=[ 
{{Idea
|image       =]=] ..ideaImage.. [=[.png
|description = 
|npc         ={{Name|]=] ..ideaData.character.. [=[}}
|unlock      =]=] ..ideaData.howToUnlock.. [=[
|prosperity  =]=] ..ideaData.prosperity.. [=[
|materials   =]=] ..ideaData.materials.. [=[
|rewards     =]=] ..ideaData.reward.. [=[
}}
'''{{Name|]=] ..ideaImage.. [=[||]=]..ideaName..[=[}}''' is {{Name|]=] ..ideaData.character.. [=[}}'s [[Ideas|idea]]. ]=]
 return frame:preprocess(template)
end

function p.getHowToUnlock(frame)
	local ideaData = ideasTable[pagename]

 if not ideasTable then return "Data not found! Please refer '''[[module:Ideas/data]]'''" end
 local template = [=[ 
{{PAGENAME}} can be unlocked by talking to ]=] ..ideaData.character.. [=[ after reaching the unlock requirements: 
]=] ..ideaData.howToUnlock:gsub('<br>',' ').. [=[.]=]
 return frame:preprocess(template)
end

function p.getCompletionRequirements(frame)
	local ideaData = ideasTable[pagename]

 if not ideasTable then return "Data not found! Please refer '''[[module:Ideas/data]]'''" end
 local template = [=[ 
{{PAGENAME}} can be completed after reaching prosperity {{Prosperity|]=] ..ideaData.prosperity.. [=[}} and having delivered ]=] ..ideaData.materials:gsub('<br>',' and ').. [=[.]=]
 return frame:preprocess(template)
end

function p.getRewards(frame)
	local ideaData = ideasTable[pagename]

 if not ideasTable then return "Data not found! Please refer '''[[module:Ideas/data]]'''" end
 local template = [=[ 
Completing the idea rewards the [[Player]] with ]=] ..ideaData.reward.. [=[.]=]
 return frame:preprocess(template)
end

function p.getGallery(frame)
 if not ideasTable then return "Data not found! Please refer '''[[module:Ideas/data]]'''" end
 local template = [=[ 
TBA]=]
 return frame:preprocess(template)
end

function p.getAllIdeas(frame)
 if not ideasTable then return "Data not found! Please refer '''[[module:Ideas/data]]'''" end
 
 local template = [=[ 
 {|class="sortable pachan-table" style="width:100%; text-align:center;"
 ! style="width: 20%;" |Idea
 ! style="width:  5%;" |Character
 ! style="width: 30%;" |How To Unlock
 ! style="width:  5%;" |Prosperity
 ! style="width: 25%;" |Materials
 ! style="width: 15%;" |Reward
 |- 
 ]=].. getIdeas() ..[=[ 
 |}]=]
 return frame:preprocess(template)
end

function getIdeas()
 local template = ""

 local defaultOrder = { "Animal Friendship","Animal Riding","Animal Taming","Art Station (Idea)","Beekeeping","Breeding Pen (Idea)","Brewer (Idea)","Calendar (Idea)","Cask (Idea)","Cheese Cloth (Idea)","Clay Oven (Idea)","Cold Storage","Composting","Fermenter (Idea)","Granary (Idea)","Hammering","A New Way of Fishing","Irrigation (Idea)","Mortar and Pestle (Idea)","Obsidian Working","Gathered Garden","Vinegar Pickling","Plant Nursery (Idea)","Press (Idea)","Smelting","Spindle Whorl (Idea)","Sundial (Idea)","Trading (Idea)","Water Wheel (Idea)","Well" }

 for _, ideaName in ipairs(defaultOrder) do
 	local idea = ideasTable[ideaName]
	local image = idea.alternativeImage and (idea.alternativeImage.."|"..ideaName.."|"..ideaName) or ideaName
	template = template .. [=[
|- 
! {{I|]=] .. image .. [=[}} 
| {{Name|]=] .. idea.character .. [=[}} 
| ]=] .. idea.howToUnlock .. [=[ 
| {{Prosperity|]=] .. idea.prosperity .. [=[}} 
| ]=] .. idea.materials .. [=[ 
| ]=] .. idea.reward .. [=[ 
]=]
	end

	return template
end

function p.getByMaterials(frame)
	local template = ""
	local result = ""

	for idea, data in pairs(ideasTable) do
		if data.materials:find(pagename) then
			local image = data.alternativeImage and (data.alternativeImage.."|"..idea.."|"..idea) or idea
			result = result .. [=[
|- 
! {{I|]=] .. image .. [=[}} 
| {{Name|]=] .. data.character .. [=[}} 
| ]=] .. data.howToUnlock .. [=[ 
| {{Prosperity|]=] .. data.prosperity .. [=[}} 
| ]=] .. data.materials .. [=[ 
| ]=] .. data.reward .. [=[ 
]=]
	end
end

template = [=[ 
{{PAGENAME}} is used to unlock an idea.
 {|class="sortable pacha" style="width:100%; text-align:center;"
 ! style="width: 20%;" |Idea
 ! style="width:  5%;" |Character
 ! style="width: 30%;" |How To Unlock
 ! style="width:  5%;" |Prosperity
 ! style="width: 25%;" |Materials
 ! style="width: 15%;" |Reward
 |- 
 ]=].. result ..[=[ 
 |}]=]
 
 
 return frame:preprocess(template)
end

return p