Module:SandboxGive feedback
Documentation for this module may be created at Module:Sandbox/doc
local p = {}
local function get_item_property(itemName, property)
local itemData = require("Module:ItemData")
local success, value = pcall(itemData.get_prop, itemData, itemName, property)
return success and value or nil
end
local function get_lang_string(stringKey)
local lang = require("Module:Lang")
local success, value = pcall(lang.get_string, lang, stringKey)
return success and value or nil
end
local function process_string(text, itemName)
return text:gsub("{s:([^}]+)}", function(property)
local propValue = get_item_property(itemName, property)
return propValue or ("{" .. property .. "}") -- Return original if property not found
end)
end
function p.process_item_string(frame)
local args = frame.args
local parentArgs = frame:getParent().args
-- Get parameters
local stringKey = args[1] or parentArgs[1]
local itemName = args.item or parentArgs.item
if not stringKey or not itemName then
return "Error: Missing parameters. Usage: {{#invoke:ItemStringProcessor|process_item_string|string_key|item=item_name}}"
end
-- Get base string from Lang module
local baseString = get_lang_string(stringKey)
if not baseString then
return "Error: String key '" .. stringKey .. "' not found in Lang module"
end
-- Process the string with item properties
local processedString = process_string(baseString, itemName)
return processedString
end
return p