From Dark and Darker Wiki

m (properly nowiki the debug_mode output)
Tag: Reverted
m (removing debug_mode, still not working)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local merge_spells = mw.loadJsonData("Data:MergeSpells.json")
local merge_spells = mw.loadJsonData("Data:MergeSpells.json")
local utils = require("Module:Utilities")


function p.draw_merge_recipe(merge_spell, debug_mode)
function p.draw_merge_recipe(merge_spell)
if type(merge_spell) == "table" and merge_spell.args then -- if called via wikitext instead of lua
if type(merge_spell) == "table" and merge_spell.args then -- if called via wikitext instead of lua
         local frame = merge_spell
         local frame = merge_spell
         merge_spell = frame.args[1]
         merge_spell = frame.args[1]
        debug_mode = frame.args["debug_mode"]
     end
     end
Line 17: Line 17:
-- Draw them
-- Draw them
wikitext = "| [[File:Icon_Spell " .. merge_spell .. ".png|link=|96px]] <br> " .. merge_spell .. "\n"
wikitext = "| [[File:Icon_Spell " .. merge_spell .. ".png|link=|96px]] <br> " .. utils.insert_space_before_capitals(merge_spell) .. "\n"
for i, component_spell in ipairs(component_spells) do
for i, component_spell in ipairs(component_spells) do
wikitext = wikitext ..  "| [[File:Icon_Spell " .. component_spell .. ".png|link=|96px]] <br> " .. component_spell .. "\n"
wikitext = wikitext ..  "| [[File:Icon_Spell " .. component_spell .. ".png|link=|65px]] <br> " .. utils.insert_space_before_capitals(component_spell) .. "\n"
end
end
-- Return the drawn wikitext
-- Return the drawn wikitext
if debug_mode then
return mw.getCurrentFrame():preprocess(wikitext)
return mw.text.tag('nowiki', {}, wikitext)
else
return mw.getCurrentFrame():preprocess(wikitext)
end
end
end


return p
return p

Latest revision as of 03:53, 22 December 2024

Overview

Functions for Sorcerer's Merge Spells and their component spells. Data comes from Data:MergeSpells.json

Functions

draw_merge_recipe

Draws a visual for the components that make up a given merge spell

Parameters

  • merge_spell - 1st parameter - the name of the merge spell without spaces but capitalized properly, i.e. ElementalBolt

Example

{| class="wikitable sortable jquery-tablesorter ClassesTable" style="min-width:360px;>
! style="width:15%" class="headerSort" role="columnheader button" title="Sort ascending" | Merge Spell
! style="width:15%" class="headerSort" role="columnheader button" title="Sort ascending" | Parent Spell 1
! style="width:15%" class="headerSort" role="columnheader button" title="Sort ascending" | Parent Spell 2
|-
| {{#invoke:MergeSpells|draw_merge_recipe|ElementalBolt}}
|}
Merge Spell Parent Spell 1 Parent Spell 2
Icon Spell ElementalBolt.png
Elemental Bolt
Icon Spell FireArrow.png
Fire Arrow
Icon Spell WaterBolt.png
Water Bolt

local p = {}
local merge_spells = mw.loadJsonData("Data:MergeSpells.json")
local utils = require("Module:Utilities")

function p.draw_merge_recipe(merge_spell)
	if type(merge_spell) == "table" and merge_spell.args then -- if called via wikitext instead of lua
        local frame = merge_spell
        merge_spell = frame.args[1]
    end
	
	-- Validate and cast to bool
	if debug_mode == nil then debug_mode = false else debug_mode = true end
		
	-- Retrieve the merge spell's component spells
	component_spells = merge_spells[merge_spell]
	if component_spells == nil then return merge_spell .. " is not a valid merge spell" end
	
	-- Draw them
	wikitext = "| [[File:Icon_Spell " .. merge_spell .. ".png|link=|96px]] <br> " .. utils.insert_space_before_capitals(merge_spell) .. "\n"
	for i, component_spell in ipairs(component_spells) do
		wikitext = wikitext ..  "| [[File:Icon_Spell " .. component_spell .. ".png|link=|65px]] <br> " .. utils.insert_space_before_capitals(component_spell) .. "\n"
	end
	
	-- Return the drawn wikitext
	return mw.getCurrentFrame():preprocess(wikitext)
end

return p