Module:Sandbox: Difference between revisionsGive feedback
Jump to navigation
Jump to search
test |
test |
||
| Line 1: | Line 1: | ||
local function | 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) | 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) | ||
end | end | ||
| Line 12: | Line 24: | ||
local parentArgs = frame:getParent().args | local parentArgs = frame:getParent().args | ||
-- Get parameters | -- Get parameters | ||
local stringKey = args[1] or parentArgs[1] | local stringKey = args[1] or parentArgs[1] | ||
local itemName = args.item or parentArgs.item | local itemName = args.item or parentArgs.item | ||
if not stringKey or not itemName then | if not stringKey or not itemName then | ||
return "Error: Missing | return "Error: Missing parameters. Usage: {{#invoke:ItemStringProcessor|process_item_string|string_key|item=item_name}}" | ||
end | end | ||
-- | -- Get base string from Lang module | ||
local baseString = get_lang_string(stringKey) | |||
local baseString = | |||
if not baseString then | if not baseString then | ||
return "Error: String key '" .. stringKey .. "' not found" | return "Error: String key '" .. stringKey .. "' not found in Lang module" | ||
end | end | ||
-- Process the string | -- Process the string with item properties | ||
local processedString = | local processedString = process_string(baseString, itemName) | ||
return processedString | return processedString | ||
end | end | ||
return p | |||