米斯特利亚Wiki正在建设中,本WIKI编辑权限开放!欢迎参与~!

全站通知:

模块:Items

来自米斯特利亚WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:Items/doc创建

-- 模块:Items
-- 说明:本模块用于查询 Items@Data2.lua 中的物品数据
local data = require('模块:Items/Data2')
local Utils = require('模块:Utils')
local Custom = require('模块:custom')
local SMW = require('模块:SMW')
local Get = require('模块:Get')

local p = {}
p.pageCategory = mw.text.jsonDecode(SMW.show({
    args = {"Data", "PageCategoryJson"}
}))
-- 缓存名称到ID的映射,提高查找效率
local nameToIdMap = {}

-- 初始化名称到ID的映射
local function initNameToIdMap()
    if next(nameToIdMap) then
        return
    end -- 已初始化则直接返回

    for itemId, item in pairs(data) do
        if item and item.name then
            nameToIdMap[item.name] = itemId
        end
    end
end

-- 内部辅助函数:通过名称查找物品ID
local function findItemIdByName(name)
    if not name or type(name) ~= 'string' then
        return nil
    end

    initNameToIdMap()
    return nameToIdMap[name]
end

-- 内部函数:通过名称或ID获取物品数据
-- @param nameOrId string 物品名称或ID
-- @return table or nil 物品数据,找不到则返回nil
function p._getItemData(nameOrId)
    if not nameOrId then
        return nil
    end

    -- 如果是中文名称,则转换为ID
    if Utils.hasChinese(nameOrId) then
        local itemId = findItemIdByName(nameOrId)
        return itemId and data[itemId] or nil
    else
        -- 直接使用ID查找
        return data[nameOrId]
    end
end

-- 获取属性值的通用函数
-- @param nameOrId string 物品名称或ID
-- @param property string 属性名
-- @param default string 默认值
-- @return string 属性值或默认值
local function getProperty(nameOrId, property, default)
    local item = p._getItemData(nameOrId)
    if not item then
        return default
    end

    -- 处理嵌套属性,指定分隔符为点号
    local keys = Utils.split(property, '.')
    local value = item
    for _, key in ipairs(keys) do
        if type(value) == 'table' then
            value = value[key]
        else
            value = nil
            break
        end
    end

    return value ~= nil and value or default
end

-- 获取中文名
function p._name(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'name', '')
    return value ~= '' and value or ''
end

function p.name(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._name(nameOrId)
end

-- 获取英文名(ID)
function p._id(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    -- 如果已经是ID格式(不含中文),直接返回
    if not Utils.hasChinese(nameOrId) then
        return data[nameOrId] and nameOrId or ''
    end

    -- 如果是中文名称,转换为ID
    local itemId = findItemIdByName(nameOrId)
    return itemId or ''
end

function p.id(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._id(nameOrId)
end

-- 获取英文显示名称
function p._name_en(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'name_en', '')
    return value ~= '' and value or ''
end

function p.name_en(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._name_en(nameOrId)
end

-- 获取图标
function p._icon(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'icon_sprite', '')
    if value == '' then
        value = Custom._icon(nameOrId)
    end

    return value ~= '' and value or ''
end

function p.icon(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._icon(nameOrId)
end

-- 获取描述
function p._desc(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'description', '')
    return value ~= '' and value or ''
end

function p.desc(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._desc(nameOrId)
end

-- 获取食用效果
function p._restore(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'restore', '')
    return value ~= '' and value or ''
end

function p.restore(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._restore(nameOrId)
end

-- 获取季节
function p._season(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    -- 获取物品数据,如果是作物则通过seed_name找到种子
    local item = p._getItemData(nameOrId)
    if not item and not item.seasons and not item.seed_name then
        return ''
    end

    local seedItem = item
    if item and item.seed_name then
        seedItem = p._getItemData(item.seed_name)
    end

    if seedItem.seasons then
        return Custom._name(seedItem.seasons)
    end

    return ''
end

function p.season(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._season(nameOrId)
end

-- 获取生长天数
function p._grow_days(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    -- 获取物品数据,不是作物或者种子就直接返回
    local item = p._getItemData(nameOrId)
    if not item and not item.day_to_stage and not item.seed_name then
        return ''
    end

    local seedItem = item
    if item and item.seed_name then
        seedItem = p._getItemData(item.seed_name)
    end

    local day_to_stage = seedItem.day_to_stage or nil
    local firstGrowDays = ''
    if type(day_to_stage) == 'table' and #day_to_stage > 0 then
        firstGrowDays = #day_to_stage
    end

    local regrow_days = seedItem.regrow_days or nil

    if regrow_days then
        -- 循环收获的作物
        return firstGrowDays .. '天(首次收获)<br>' .. regrow_days .. '天(再次收获)'
    else
        -- 一次性收获的作物
        if firstGrowDays ~= '' then
            return firstGrowDays .. '天(一次性收获)'
        end
    end

end

function p.grow_days(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._grow_days(nameOrId)
end

-- 获取货币类型
function p._currency(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    -- 获取物品数据,如果是作物则通过seed_name找到种子
    local item = p._getItemData(nameOrId)
    if not item and not item.currency and not item.seed_name then
        return ''
    end

    local seedItem = item
    if item and item.seed_name then
        seedItem = p._getItemData(item.seed_name)
    end

    -- 优先从种子数据中获取currency,如果没有则从当前物品获取
    local currency = seedItem.currency or nil
    if not currency then
        return ''
    end

    return currency
end

function p.currency(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._currency(nameOrId)
end

-- 获取星级
function p._stars(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'stars', '')
    return value ~= '' and value or ''
end

function p.stars(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._stars(nameOrId)
end

-- 获取厨房等级需求
function p._kitchen_tier_requirement(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'kitchen_tier_requirement', '')
    return value ~= '' and value or ''
end

function p.kitchen_tier_requirement(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._kitchen_tier_requirement(nameOrId)
end

-- 获取是否为默认配方
function p._recipe_is_default(nameOrId)
    if not nameOrId or nameOrId == '' then
        return false
    end

    local value = getProperty(nameOrId, 'recipe_is_default', false)
    return value or false
end

function p.recipe_is_default(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._recipe_is_default(nameOrId)
end

-- 查找所有在配方中使用了指定原料的成品id
-- @param ingredientId string 原料的内部名,如 "hard_wood"
-- @return table {{icon,name,recipes,recipesTime,bin},...}
function p._findItemByIngredient(ingredient, itemIdTable)
    if not ingredient or ingredient == '' then
        return {}
    end

    local ingredientId = p._id(ingredient)
    local frame = mw.getCurrentFrame()
    local result = {}

    for _, itemId in ipairs(itemIdTable) do
        local item = p._getItemData(itemId)
        if item and item.recipe and type(item.recipe) == 'table' then
            for _, ingredient in ipairs(item.recipe) do
                if ingredient.item == ingredientId then
                    local r = {}
                    frame.args = {itemId}
                    table.insert(r, p._icon(itemId))
                    table.insert(r, p._name(itemId))
                    table.insert(r, p.recipes(frame))
                    table.insert(r, p.recipes_Time(frame))
                    table.insert(r, p._bin(itemId))
                    -- r.icon = p._icon(itemId)
                    -- r.name = p._name(itemId)
                    -- r.recipes = p.recipes(frame)
                    -- r.recipesTime = p.recipes_Time(frame)
                    -- r.bin = p._bin(itemId)
                    -- r.id = p._id(itemId)
                    table.insert(result, r)
                    break
                end
            end
        end
    end

    return result
end
-- local itemIdList = p._itemFiltByCategory("料理")
-- local result = p._findItemByIngredient("南瓜", itemIdList )
-- mw.logObject(result)

-- 框架函数:查找所有在配方中使用了指定原料的成品
function p.findItemByIngredient(frame)
    
    local ingredientId = frame.args[1]
    local category = frame.args[2]

    local itemIdList = p._itemFiltByCategory(category)
    local itemTable = p._findItemByIngredient(ingredientId, itemIdList)
    if not itemTable or #itemTable <= 0 then
        return nil
    end
	-- mw.logObject(itemTable)
	
    -- 渲染配方表格
    local moduleArgTable = {
        ["标题"] = category
    }
    for _, itemArgTable in ipairs(itemTable) do
        table.insert(moduleArgTable, table.concat(itemArgTable, "@"))
    end
    

    return frame:expandTemplate{
        title = '制作',
        args = moduleArgTable
    }

end

-- 获取出售价格
function p._bin(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'value.bin', '')

    return value ~= '' and value or ''
end

function p.bin(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._bin(nameOrId)
end

-- 获取捐献声望
function p._renown(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'value.renown', '')
    return value ~= '' and value or ''
end

function p.renown(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._renown(nameOrId)
end

-- 获取商店价格
function p._store(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'value.store', '')
    return value ~= '' and value or ''
end

function p.store(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._store(nameOrId)
end

-- 获取原料
function p._recipes(nameOrId)
    if not nameOrId or nameOrId == '' then
        return {}
    end

    local item = p._getItemData(nameOrId)
    if not item or not item.recipe or type(item.recipe) ~= 'table' then
        return {}
    end

    local ingredients = {}
    -- 复制除了最后一个可能是制作时间的元素之外的所有配方元素
    for i, ingredient in ipairs(item.recipe) do
        -- 检查是否是制作时间元素(包含hours或minutes字段)
        if not (ingredient.hours or ingredient.minutes) then
            table.insert(ingredients, ingredient)
        end
    end

    return ingredients
end

function p.recipes(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    local ingredients = p._recipes(nameOrId)
    if type(ingredients) == 'table' and #ingredients > 0 then
        return p._renderItemTable(ingredients)
    end
    return ''
end

-- 获取制作时间
function p._recipes_Time(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local item = p._getItemData(nameOrId)
    if not item or not item.recipe then
        return ''
    end

    for _, ingredient in ipairs(item.recipe) do
        if ingredient.hours or ingredient.minutes then
            local timeStr = ''
            if ingredient.hours and ingredient.hours > 0 then
                timeStr = ingredient.hours .. '小时'
            end
            if ingredient.minutes and ingredient.minutes > 0 then
                if timeStr ~= '' then
                    timeStr = timeStr .. ' '
                end
                timeStr = timeStr .. ingredient.minutes .. '分钟'
            end
            return timeStr ~= '' and timeStr or ''
        end
    end

    return ''
end

function p.recipes_Time(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._recipes_Time(nameOrId)
end

-- 获取技能等级
function p._crafting_level_requirement(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'crafting_level_requirement', '')
    return value ~= '' and value or ''
end

function p.crafting_level_requirement(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._crafting_level_requirement(nameOrId)
end

-- 获取种子
function p._seed_name(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'seed_name', '')
    return value ~= '' and value or ''
end

function p.seed_name(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._seed_name(nameOrId)
end

-- 获取tags
function p._tags(nameOrId)
    if not nameOrId or nameOrId == '' then
        return {}
    end

    local item = p._getItemData(nameOrId)
    if not item or not item.tags or type(item.tags) ~= 'table' then
        return {}
    end

    return item.tags
end

function p.tags(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    local tags = p._tags(nameOrId)
    if type(tags) == 'table' and #tags > 0 then
        return table.concat(tags, ', ')
    end
    return ''
end

-- 根据标签查找物品ID列表(忽略大小写与首尾空白)
-- @param tag string
-- @return table { itemId, ... }
function p._findItemByTag(tag)
    if not tag or type(tag) ~= 'string' or tag == '' then
        return {}
    end

    -- 处理标签:去除首尾空白并转换为小写以便忽略大小写比较
    local normalizedTag = string.lower(string.match(tag, '^%s*(.-)%s*$'))
    if normalizedTag == '' then
        return {}
    end

    local result = {}

    -- 遍历整个物品数据表
    for itemId, item in pairs(data) do
        if item and item.tags and type(item.tags) == 'table' then
            -- 检查物品的标签列表是否包含指定标签(忽略大小写)
            for _, itemTag in ipairs(item.tags) do
                if itemTag and type(itemTag) == 'string' then
                    local normalizedItemTag = string.lower(string.match(itemTag, '^%s*(.-)%s*$'))
                    if normalizedItemTag == normalizedTag then
                        table.insert(result, itemId)
                        break -- 每个物品只需要匹配一次就可以了
                    end
                end
            end
        end
    end

    return result
end

-- 框架函数:根据标签查找物品ID列表
function p.findItemByTag(frame)
    local tag = frame and frame.args and frame.args[1]
    local result = p._findItemByTag(tag)
    return table.concat(result, ', ')
end

-- 获取作物
function p._crop_object(nameOrId)
    if not nameOrId or nameOrId == '' then
        return ''
    end

    local value = getProperty(nameOrId, 'crop_object', '')
    return value ~= '' and value or ''
end

function p.crop_object(frame)
    local nameOrId = frame and frame.args and frame.args[1]
    return p._crop_object(nameOrId)
end

-- 内部函数:渲染单个物品
-- @param itemData table 物品数据,格式:{ ["count"] = 数量, ["item"] = "物品ID" }
-- @param tplName string 模板名称,默认为"ItemIcon"
-- @return string 渲染结果
function p._renderItem(itemData, moduleArg)
    if not itemData or type(itemData) ~= 'table' or not itemData.item then
        return ''
    end

    -- 获取物品中文名和图标
    local itemName = p._name(itemData.item)
    local itemIcon = p._icon(itemData.item)
    if itemName == '' or itemIcon == '' then
        return ''
    end

    -- 准备模板参数:{ 道具中文名, 数量 }
    local tmplateArgs = {itemName, itemIcon}
    if itemData.count then
        table.insert(tmplateArgs, tostring(itemData.count))
    end

    -- 调用模板
    local templateName = moduleArg or '物品'
    local frame = mw.getCurrentFrame()
    return frame:expandTemplate{
        title = templateName,
        args = tmplateArgs
    }
end

function p._renderItemTable(itemDataTable, moduleArg)
    if not itemDataTable or type(itemDataTable) ~= 'table' then
        return ''
    end

    local itemStrings = {}
    for _, itemData in ipairs(itemDataTable) do
        table.insert(itemStrings, p._renderItem(itemData, moduleArg))
    end

    return table.concat(itemStrings, '')
end

function p._renderItemList(strOrTable, moduleArg)
    local itemList = {}
    if type(strOrTable) == 'table' then
        itemList = strOrTable
    end

    if type(strOrTable) == 'string' then
        itemList = Utils.split(strOrTable, ',')
    end

    if type(itemList) ~= 'table' or #itemList == 0 then
        return ''
    end

    local itemTable = {}
    for _, item in ipairs(itemList) do
        local id = p._id(item)
        table.insert(itemTable, {
            ["item"] = id
        })
    end

    return p._renderItemTable(itemTable, moduleArg)
end

-- 根据分类名返回物品中文名组成的table
-- @param categoryName string 分类名称
-- @return table {name,...} 包含所有属于该分类的物品中文名的数组
function p._itemFiltByCategory(categoryName)
    -- 参数验证
    if not categoryName or type(categoryName) ~= 'string' or categoryName == '' then
        return {}
    end

    local result = {}

    -- 遍历p.pageCategory表,找出所有分类匹配的物品
    if p.pageCategory and type(p.pageCategory) == 'table' then
        for itemName, itemCategory in pairs(p.pageCategory) do
            -- 检查当前物品的分类是否匹配目标分类
            if itemCategory and type(itemCategory) == 'string' and itemCategory == categoryName then
                table.insert(result, itemName)
            end
        end
    end

    return result
end

function p.itemFiltByCategory(frame)
    if not frame or not frame.args or not frame.args[1] then
        return {}
    end

    local category = frame.args[1]
    local filterItems = p._itemFiltByCategory(category)
    local itemTable = {}
    for _, itemName in ipairs(filterItems) do
        table.insert(itemTable, {
            ["item"] = itemName
        })
    end

    return p._renderItemTable(itemTable)
end

-- 根据季节筛选分类为作物的物品
-- @param season string 季节名称
-- @return table { { id=作物id, item=作物对象 }, ... }
function p._filterCropBySeason(season)
    if not season or type(season) ~= 'string' or season == '' then
        return {}
    end

    local result = {}

    -- 使用_itemFiltByCategory函数获取所有作物分类的物品
    local cropItems = p._itemFiltByCategory("作物")

    -- 遍历作物物品,筛选符合季节条件的
    if cropItems and type(cropItems) == 'table' then
        for _, itemName in ipairs(cropItems) do
            -- 获取作物的季节信息
            local cropSeason = p._season(itemName)
            if cropSeason and string.find(cropSeason, season) then
                -- 获取物品ID和数据
                local itemId = p._id(itemName)
                local item = p._getItemData(itemId)
                if itemId and item then
                    table.insert(result, {
                        id = itemId,
                        item = item
                    })
                end
            end
        end
    end

    return result
end

-- 框架函数:根据季节筛选分类为作物的物品
-- @param frame frame对象,frame.args[1]为季节名称
-- @return string 渲染后的物品列表
function p.filterCropBySeason(frame)
    if not frame or not frame.args or not frame.args[1] then
        return ''
    end

    local season = frame.args[1]
    local filteredCrops = p._filterCropBySeason(season)

    -- 准备渲染数据
    local itemTable = {}
    for _, crop in ipairs(filteredCrops) do
        table.insert(itemTable, {
            ["item"] = crop.id
        })
    end

    return p._renderItemTable(itemTable)
end

-- 根据季节筛选分类为采集物的物品
-- @param season string 季节名称
-- @return table { { id=采集物id, item=采集物对象 }, ... }
function p._filterForageBySeason(season)
    if not season or type(season) ~= 'string' or season == '' then
        return {}
    end

    local result = {}

    -- 使用_itemFiltByCategory函数获取所有采集物分类的物品
    local forageItems = p._itemFiltByCategory("采集物")

    -- 遍历采集物物品,筛选符合季节条件的
    if forageItems and type(forageItems) == 'table' then
        for _, itemName in ipairs(forageItems) do
            -- 获取采集物的季节信息
            local forageSeason = p._season(itemName)
            if forageSeason and string.find(forageSeason, season) then
                -- 获取物品ID和数据
                local itemId = p._id(itemName)
                local item = p._getItemData(itemId)
                if itemId and item then
                    table.insert(result, {
                        id = itemId,
                        item = item
                    })
                end
            end
        end
    end

    return result
end

-- 框架函数:根据季节筛选分类为采集物的物品
-- @param frame frame对象,frame.args[1]为季节名称
-- @return string 渲染后的物品列表
function p.filterForageBySeason(frame)
    if not frame or not frame.args or not frame.args[1] then
        return ''
    end

    local season = frame.args[1]
    local filteredForage = p._filterForageBySeason(season)

    -- 准备渲染数据
    local itemTable = {}
    for _, forage in ipairs(filteredForage) do
        table.insert(itemTable, {
            ["item"] = forage.id
        })
    end

    return p._renderItemTable(itemTable)
end

-- 内部函数:根据烹饪主分类筛选物品
-- @param category string 烹饪主分类名称(如"主食")
-- @return table { { id=物品id, item=物品对象 }, ... }
function p._filterDishByCategory(category)
    if not category or type(category) ~= 'string' or category == '' then
        return {}
    end

    local result = {}

    -- 使用_itemFiltByCategory函数获取所有料理分类的物品
    local dishItems = p._itemFiltByCategory("料理")

    -- 遍历整个物品数据表
    for _, itemName in ipairs(dishItems) do
        local item = p._getItemData(itemName)
        local dishCategory = item and item.cooking_main_category
        local itemId = p._id(itemName)
        if dishCategory and dishCategory == category then
            -- 添加符合条件的物品到结果列表
            table.insert(result, {
                id = itemId,
                item = item
            })
        end
    end

    return result
end

-- 框架函数:根据烹饪主分类筛选物品
-- @param frame frame对象,frame.args[1]为烹饪主分类名称
-- @return string 渲染后的物品列表
function p.filterDishByCategory(frame)
    if not frame or not frame.args or not frame.args[1] then
        return ''
    end

    local category = frame.args[1]
    local filteredDishes = p._filterDishByCategory(category)

    -- 准备渲染数据
    local itemTable = {}
    for _, dish in ipairs(filteredDishes) do
        table.insert(itemTable, {
            ["item"] = dish.id
        })
    end

    return p._renderItemTable(itemTable)
end

return p
--[[
mw.logObject(p._name("ladder")=="直梯")
mw.logObject(p._id("直梯")=="ladder")
mw.logObject(p._desc("stairs")=="放置此楼梯后, 可以上房屋二楼。 ")
mw.logObject(p._bin("ladder")==500)
mw.logObject(p._store("ladder")==1000)
mw.logObject(p._crafting_level_requirement("stairs")==10)
mw.logObject(p._tags("stairs")=="furniture, misc_functional")
mw.logObject(p._recipes_Time("stairs")=="10分钟")
mw.logObject(p._restore("ladder")=="")
mw.logObject(p._renown("ladder")=="")

local frame = mw.getCurrentFrame()
frame.args = {"bakery_bread_basket_coffee"}
mw.logObject(p.recipes(frame))

local t = {
    ["count"] = 50,
    ["item"] = "hard_wood",
}
mw.logObject(p._renderItem(t))

local t = {{
    ["count"] = 50,
    ["item"] = "hard_wood",
},
{
    ["count"] = 100,
    ["item"] = "iron_ingot",
}}
mw.logObject(p._renderItemTable(t))

测试新添加的季节、生长天数和货币函数
使用Items@Data2.lua中的实际数据进行测试
seed_strawberry数据:seasons="spring", currency=3, day_to_stage={0,1,2,3,3,4}, regrow_days=3
strawberry数据:seed_name="seed_strawberry"

测试季节属性
mw.logObject(p._season("seed_strawberry")=="春天")
mw.logObject(p._season("strawberry")=="春天")

测试生长天数属性
mw.logObject(p._grow_days("seed_strawberry")=="6天(首次收获)<br>3天(再次收获)") 
mw.logObject(p._grow_days("strawberry")=="6天(首次收获)<br>3天(再次收获)")
mw.logObject(p._grow_days("seed_sweet_potato")=="5天(一次性收获)")
mw.logObject(p._grow_days("sweet_potato")=="5天(一次性收获)")

测试货币属性
mw.logObject(p._currency("seed_strawberry")==3)
mw.logObject(p._currency("strawberry")==3)

测试星级属性
mw.logObject(p._stars("blackberry_jam")==1)

测试厨房等级需求属性
mw.logObject(p._kitchen_tier_requirement("blackberry_jam")==1)

测试是否为默认配方属性
mw.logObject(p._recipe_is_default("blackberry_jam")==false)
mw.logObject(p._recipe_is_default("essence_stone_giant")==false)
mw.logObject(p._recipe_is_default("bread")==true)

-- 测试_inIngredients函数(修改后不传入data参数)
local result = p._inIngredients("hard_wood")
mw.logObject("查找使用hard_wood的物品数量: " .. #result)
if #result > 0 then
    mw.logObject("第一个物品ID: " .. result[1].id)
    mw.logObject("第一个物品用量: " .. result[1].count)
    mw.logObject("第一个物品分类: " .. result[1].category)
end

-- 测试_findItemByTag函数
-- 测试1: 使用精确标签
local furnitureItems = p._findItemByTag("furniture")
mw.logObject("查找标签为furniture的物品数量: " .. #furnitureItems)
if #furnitureItems > 0 then
    mw.logObject("第一个物品ID: " .. furnitureItems[1])
end

-- 测试2: 使用大小写混合的标签(应忽略大小写)
local foodItems = p._findItemByTag("Food")
mw.logObject("查找标签为Food的物品数量: " .. #foodItems)

-- 测试3: 使用带空格的标签(应忽略首尾空白)
local toolItems = p._findItemByTag("  tool  ")
mw.logObject("查找标签为  tool  的物品数量: " .. #toolItems)

-- 测试4: 使用不存在的标签
local nonExistentItems = p._findItemByTag("non_existent_tag")
mw.logObject("查找不存在标签的物品数量: " .. #nonExistentItems)

-- 测试新添加的_inIngredients函数
-- 查找所有使用hard_wood作为原料的物品
local hardWoodRecipes = p._inIngredients(data, "hard_wood")
mw.logObject(#hardWoodRecipes > 0) -- 应该找到多个使用hard_wood的物品
if #hardWoodRecipes > 0 then
    mw.logObject(hardWoodRecipes[1].id) -- 输出第一个使用hard_wood的物品ID
    mw.logObject(hardWoodRecipes[1].count) -- 输出第一个物品使用hard_wood的数量
    mw.logObject(hardWoodRecipes[1].category) -- 输出第一个物品的分类
end

-- 测试新添加的_filterCropBySeason函数
-- 测试1: 使用实际存在的季节(例如"春")
local springCrops = p._filterCropBySeason("春")
mw.logObject("春季作物数量: " .. #springCrops)
if #springCrops > 0 then
    mw.logObject("第一个春季作物ID: " .. springCrops[1].id)
    mw.logObject("第一个春季作物名称: " .. p._name(springCrops[1].id))
end

-- 测试2: 使用不存在的季节
local nonExistentSeasonCrops = p._filterCropBySeason("不存在的季节")
mw.logObject("不存在季节的作物数量: " .. #nonExistentSeasonCrops) -- 应该为0

-- 测试3: 测试框架函数
local frame = mw.getCurrentFrame()
frame.args = {"春"}
local renderedSpringCrops = p.filterCropBySeason(frame)
mw.logObject("渲染的春季作物数量不为空: " .. (renderedSpringCrops ~= ""))

-- 测试代码
-- 测试_itemFiltByCategory函数
local cropItems = p._itemFiltByCategory("作物")
mw.logObject("作物数量: " .. #cropItems)
if #cropItems > 0 then
    mw.logObject("第一个作物名称: " .. cropItems[1])
    -- 获取第一个作物的ID和季节信息
    local firstCropId = p._id(cropItems[1])
    local firstCropSeason = p._season(cropItems[1])
    mw.logObject("第一个作物ID: " .. firstCropId)
    mw.logObject("第一个作物季节: " .. firstCropSeason)
end

-- 测试_filterCropBySeason函数
-- 测试1: 使用实际存在的季节(例如"春")
local springCrops = p._filterCropBySeason("春")
mw.logObject("春季作物数量: " .. #springCrops)
if #springCrops > 0 then
    mw.logObject("第一个春季作物ID: " .. springCrops[1].id)
    mw.logObject("第一个春季作物名称: " .. p._name(springCrops[1].id))
end

-- 测试2: 使用不存在的季节
local nonExistentSeasonCrops = p._filterCropBySeason("不存在的季节")
mw.logObject("不存在季节的作物数量: " .. #nonExistentSeasonCrops) -- 应该为0

-- 测试3: 测试框架函数
local frame = mw.getCurrentFrame()
frame.args = {"春"}
local renderedSpringCrops = p.filterCropBySeason(frame)
mw.logObject("渲染的春季作物数量不为空: " .. (renderedSpringCrops ~= ""))

-- 测试_filterForageBySeason函数
-- 测试1: 使用实际存在的季节(例如"春")
local springForage = p._filterForageBySeason("春")
mw.logObject("春季采集物数量: " .. #springForage)
if #springForage > 0 then
    mw.logObject("第一个春季采集物ID: " .. springForage[1].id)
    mw.logObject("第一个春季采集物名称: " .. p._name(springForage[1].id))
end

-- 测试2: 使用不存在的季节
local nonExistentSeasonForage = p._filterForageBySeason("不存在的季节")
mw.logObject("不存在季节的采集物数量: " .. #nonExistentSeasonForage) -- 应该为0

-- 测试3: 测试框架函数
local frame = mw.getCurrentFrame()
frame.args = {"春"}
local renderedSpringForage = p.filterForageBySeason(frame)
mw.logObject("渲染的春季采集物数量不为空: " .. (renderedSpringForage ~= ""))

]] --