Module:Sandbox/LVL: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| Line 10: | Line 6: | ||
local lang_module = require('Module:Lang') | local lang_module = require('Module:Lang') | ||
-- returns the entire data table for a specific NPC, used by other Lua modules | |||
function p.get_npc_data(name) | function p.get_npc_data(name) | ||
if not name or name == '' then | if not name or name == '' then | ||
| Line 17: | Line 14: | ||
end | end | ||
-- Retrieves a specific stat value for a given NPC. | |||
--{{#invoke:NpcData|get_npc_var|NPC_KEY|STAT_KEY|OPTIONS}}-- | |||
p.get_npc_var = function(frame) | p.get_npc_var = function(frame) | ||
-- Get arguments from the #invoke call and trim whitespace | |||
local args = frame.args | local args = frame.args | ||
local npc_name = args[1] and mw.text.trim(args[1]) or nil | local npc_name = args[1] and mw.text.trim(args[1]) or nil | ||
| Line 23: | Line 23: | ||
local sig_figs_or_localize = args[3] and mw.text.trim(args[3]) or nil | local sig_figs_or_localize = args[3] and mw.text.trim(args[3]) or nil | ||
-- Validate required arguments | |||
if not npc_name or npc_name == '' then | if not npc_name or npc_name == '' then | ||
return '<span class="error">Error: NPC name not provided.</span>' | return '<span class="error">Error: NPC name not provided.</span>' | ||
| Line 30: | Line 31: | ||
end | end | ||
-- Retrieve the NPC data table | |||
local npc = npcs_data[npc_name] | local npc = npcs_data[npc_name] | ||
if not npc then | if not npc then | ||
| Line 35: | Line 37: | ||
end | end | ||
-- Get the specific stat value | |||
local var_value = npc[npc_stat_key] | local var_value = npc[npc_stat_key] | ||
if var_value == nil then | if var_value == nil then | ||
| Line 40: | Line 43: | ||
end | end | ||
-- round | |||
if sig_figs_or_localize and tonumber(sig_figs_or_localize) then | if sig_figs_or_localize and tonumber(sig_figs_or_localize) then | ||
var_value = util_module.round_to_sig_fig(var_value, sig_figs_or_localize) | var_value = util_module.round_to_sig_fig(var_value, sig_figs_or_localize) | ||
| Line 47: | Line 51: | ||
end | end | ||
-- localize | |||
if sig_figs_or_localize == "true" then | if sig_figs_or_localize == "true" then | ||
return lang_module.get_string(var_value) | return lang_module.get_string(var_value) | ||
| Line 54: | Line 59: | ||
end | end | ||
-- Retrieves an element from a list (array) within an NPC's data. | |||
--{{#invoke:NpcData|get_list_elem|NPC_KEY|LIST_KEY|INDEX|localize}}-- | |||
p.get_list_elem = function(frame) | p.get_list_elem = function(frame) | ||
local npc_name = frame.args[1] and mw.text.trim(frame.args[1]) or nil | local npc_name = frame.args[1] and mw.text.trim(frame.args[1]) or nil | ||
| Line 83: | Line 90: | ||
end | end | ||
-- Retrieves an ability key from an NPC's "BoundAbilities" map. | |||
--{{#invoke:NpcData|get_ability_key|NPC_KEY|SLOT_KEY}}-- | |||
p.get_ability_key = function(frame) | p.get_ability_key = function(frame) | ||
local npc_name = frame.args[1] and mw.text.trim(frame.args[1]) or nil | local npc_name = frame.args[1] and mw.text.trim(frame.args[1]) or nil | ||