模块:Object:修订间差异
来自星露谷物语扩展百科
更多操作
删除的内容 添加的内容
排除fish_mines |
getColorById |
||
| 第1行: | 第1行: | ||
local Helper = require("Module:Helper") |
local Helper = require("Module:Helper") |
||
local |
local ObjectData = Helper.LazyLoad('Module:Object/Data') |
||
local p = {} |
local p = {} |
||
| 第8行: | 第8行: | ||
function p.getFieldsById(frame) |
function p.getFieldsById(frame) |
||
local id = frame.args[1] |
local id = frame.args[1] |
||
local item = |
local item = ObjectData[id] |
||
if not item then return "Error: ID not found." end |
if not item then return "Error: ID not found." end |
||
| 第24行: | 第24行: | ||
function p.getFirstFishTagById(frame) |
function p.getFirstFishTagById(frame) |
||
local id = frame.args[1] |
local id = frame.args[1] |
||
local item = |
local item = ObjectData[id] |
||
if not item or not item.ContextTags then return "" end |
if not item or not item.ContextTags then return "" end |
||
| 第30行: | 第30行: | ||
if tag:match("^fish_") and tag ~= "fish_has_roe" and tag ~= "fish_pond" and tag ~= "fish_mines" then |
if tag:match("^fish_") and tag ~= "fish_has_roe" and tag ~= "fish_pond" and tag ~= "fish_mines" then |
||
return tag |
return tag |
||
end |
|||
end |
|||
return "" |
|||
end |
|||
-- =p.getColorById{ args = { "137"} } |
|||
-- mw.logObject(p.getColorById{ args = { "137"} }) |
|||
function p.getColorById(frame) |
|||
local id = frame.args[1] |
|||
local item = ObjectData[id] |
|||
if not item or not item.ContextTags then return "" end |
|||
for _, tag in ipairs(item.ContextTags) do |
|||
if tag:match("^color_") then |
|||
local result = tag |
|||
result = result:gsub("color_", ""):gsub("^%l", string.upper) |
|||
return result |
|||
end |
end |
||
end |
end |
||
| 第37行: | 第54行: | ||
function p.getIdByName(frame) |
function p.getIdByName(frame) |
||
local name = mw.ustring.lower(frame.args[1]) |
local name = mw.ustring.lower(frame.args[1]) |
||
for id, item in pairs( |
for id, item in pairs(ObjectData) do |
||
if mw.ustring.lower(item.Name) == name then |
if mw.ustring.lower(item.Name) == name then |
||
mw.logObject(id) -- !!! |
mw.logObject(id) -- !!! |
||
2024年11月14日 (四) 00:58的版本
local Helper = require("Module:Helper")
local ObjectData = Helper.LazyLoad('Module:Object/Data')
local p = {}
-- =p.getFieldsById{ args = { "137"} }
-- mw.logObject(p.getFieldsById{ args = { "137"} })
function p.getFieldsById(frame)
local id = frame.args[1]
local item = ObjectData[id]
if not item then return "Error: ID not found." end
return {
Name = item.Name,
Type = item.Type,
Category = item.Category,
Price = item.Price,
ContextTags = item.ContextTags
}
end
-- =p.getFirstFishTagById{ args = { "137"} }
-- mw.logObject(p.getFirstFishTagById{ args = { "137"} })
function p.getFirstFishTagById(frame)
local id = frame.args[1]
local item = ObjectData[id]
if not item or not item.ContextTags then return "" end
for _, tag in ipairs(item.ContextTags) do
if tag:match("^fish_") and tag ~= "fish_has_roe" and tag ~= "fish_pond" and tag ~= "fish_mines" then
return tag
end
end
return ""
end
-- =p.getColorById{ args = { "137"} }
-- mw.logObject(p.getColorById{ args = { "137"} })
function p.getColorById(frame)
local id = frame.args[1]
local item = ObjectData[id]
if not item or not item.ContextTags then return "" end
for _, tag in ipairs(item.ContextTags) do
if tag:match("^color_") then
local result = tag
result = result:gsub("color_", ""):gsub("^%l", string.upper)
return result
end
end
return ""
end
function p.getIdByName(frame)
local name = mw.ustring.lower(frame.args[1])
for id, item in pairs(ObjectData) do
if mw.ustring.lower(item.Name) == name then
mw.logObject(id) -- !!!
return id
end
end
return "Error: Name not found."
end
-- =p.getFieldsByName{ args = { "Smallmouth Bass"} }
-- mw.logObject(p.getFieldsByName{ args = { "Smallmouth Bass"} })
function p.getFieldsByName(frame)
local id = p.getIdByName({ args = { frame.args[1] } })
local name = mw.ustring.lower(frame.args[1])
if id then
return p.getFieldsById({ args = { id } })
end
return "Error: Name not found."
end
-- mw.logObject(p.getPriceById{ args = { "137"} })
function p.getPriceById(frame)
return p.getFieldsById({ args = { frame.args[1] } })["Price"]
end
-- mw.logObject(p.getPriceByName{ args = { "Smallmouth Bass"} })
function p.getPriceByName(frame)
local id = p.getIdByName({ args = { frame.args[1] } })
return p.getPriceById({ args = { id } })
end
return p