全站通知:

模块:Snippets

来自星露谷物语维基
跳到导航 跳到搜索
[ 创建 | 刷新 ]文档页面
当前模块文档缺失,需要扩充。
local p = {}

-- 按类别组织的文本片段
local categories = {
    -- 物品用途相关
    ['不用于'] = {
        ['收集包'] = '{{PAGENAME}}不用于任何[[收集包]]。',
        ['食谱'] = '{{PAGENAME}}不用于任何[[烹饪#食谱|食谱]]。',
        ['配方'] = '{{PAGENAME}}不用于任何[[打造#可打造物品|配方]]。',
        ['任务'] = '{{PAGENAME}}不用于任何[[任务]]。',
        ['裁制'] = '{{PAGENAME}}不可用于[[裁缝|裁制]]。',
        ['裁缝'] = '{{PAGENAME}}不可用于[[裁缝|裁制]]。',
    },
    
    -- 人际关系相关
    ['人际关系'] = {
        ['花舞节'] = '如果玩家在[[花舞节]]中没有邀请{actor}或[[{param3}]]跳舞,{actor}和{param3}会成为舞伴。',
    },
    
    -- 任务相关
    ['任务'] = {
        ['布告栏'] = '{actor}可能会在[[皮埃尔的杂货店|杂货店]]外墙的布告栏张贴[[任务#求助任务|求助任务]]。完成后会获得物品价值 3 倍的金币,并提高{actor} 150 点的[[好感度]]。',
    },
    
    -- 好感度相关
    ['好感度'] = {
        ['礼物'] = '{actor}对玩家的[[友谊|好感度]]大于 0 时,{actor}就有可能会向玩家邮寄礼物。好感度越高,玩家收到礼物的可能性越大。',
        ['食谱'] = '与{actor}的好感度到达 {param3} 心后,{actor}会通过信件和玩家分享{{Name|{param4}|class=inline}}的食谱。',
        ['配方'] = '与{actor}的好感度到达 {param3} 心后,{actor}会通过信件和玩家分享{{Name|{param4}|class=inline}}的配方。',
    },
    
    -- 人物摘要相关
    ['摘要'] = {
        ['可结婚'] = '{actor}是 12 位可[[婚姻|结婚]]的人物之一。',
    },
    
    -- NPC日程相关
    ['日程'] = {
        ['表格'] = '下方展示的是{actor}的日程。上方的日程的优先级高于下方的日程,例如雨天的日程一般位于普通日程的上方,如果雨天上方没有其他日程或者日程的条件没有满足,则会执行雨天的日程。',
        ['度假村'] = '如果[[姜岛]]的[[姜岛#海滩度假村|度假村]]已经重建、度假村处于开放状态并且姜岛没有下雨,{actor}可能会去度假。下午 6 点后,{actor}便会离开度假村,回家准备睡觉。{actor}不会在{schedule_exception}节日期间度假。',
    },
    
    -- 元素相关
    ['元素'] = {
        ['农场'] = '<span class="player-name">农场名</span>',
        ['后缀'] = '<span class="trigger-chance">{param3}</span>',
        ['锚点'] = '<span id="{param3}" data-id="{param3}" class="tab-archor"></span>',
        ['小标题'] = '<span class="talk-title">{param3}</span>',
        ['年份'] = '<span class="player-name">年份</span>',
        ['玩家'] = '<span class="player-name">玩家名</span>',
    },
    
    -- 游戏设定相关
    ['设定'] = {
        ['早期设定'] = '{actor}的肖像图以及人物设定随着游戏开发的推进进行了多次调整和迭代。下方的图片展示了 ConcernedApe 在游戏正式发布之前对人物进行过的调整和细化。',
    },
}

-- 特殊处理函数:处理"不用于"模板的大小写转换和别名
local function processNotUsedFor(subtype)
    local lowerSubtype = string.lower(subtype or '')
    
    -- 处理别名映射
    local aliasMap = {
        ['b'] = '收集包',
        ['r'] = '食谱', 
        ['c'] = '配方',
        ['q'] = '任务',
        ['t'] = '裁制',
        ['裁缝'] = '裁制',
    }
    
    return aliasMap[lowerSubtype] or subtype
end

-- 特殊处理函数:处理日程模板中的特殊逻辑
local function processScheduleException(actor)
    local exceptionMap = {
        ['谢恩'] = '<!-- 谢恩不体检 -->',
        ['哈维'] = '工作日或',
        ['潘妮'] = '工作日、体检日或',
        ['玛鲁'] = '工作日、体检日或',
        ['艾米丽'] = '秋季 15 日(桑迪的生日)、体检日或',
    }
    
    return exceptionMap[actor] or '体检日或'
end

function p.main(frame)
    local args = frame:getParent().args
    
    -- 获取基本参数
    local category = args[1] or ''
    local subtype = args[2] or ''
    local actor = args.actor or args.villager or frame:preprocess('{{PAGENAME}}')
    
    -- 特殊处理"不用于"模板
    if category == '不用于' then
        subtype = processNotUsedFor(subtype)
    end
    
    -- 获取对应的文本片段
    local text = categories[category] and categories[category][subtype]
    if not text then
        return '' -- 如果没找到对应的片段,返回空
    end
    
    -- 替换基本占位符
    text = text:gsub('{actor}', actor)
    text = text:gsub('{param3}', args[3] or '')
    text = text:gsub('{param4}', args[4] or '')
    text = text:gsub('{param5}', args[5] or '')
    text = text:gsub('{param6}', args[6] or '')
    
    -- 处理特殊占位符
    if category == '日程' and subtype == '度假村' then
        local scheduleException = processScheduleException(actor)
        text = text:gsub('{schedule_exception}', scheduleException)
    end
    
    -- 支持具名参数(优先级更高)
    if args.param3 then text = text:gsub('{param3}', args.param3) end
    if args.param4 then text = text:gsub('{param4}', args.param4) end
    if args.param5 then text = text:gsub('{param5}', args.param5) end
    if args.param6 then text = text:gsub('{param6}', args.param6) end
    
    return frame:preprocess(text)
end

-- 获取某个类别下的所有可用子类型
function p.listSubtypes(frame)
    local category = frame.args[1] or ''
    if not categories[category] then
        return '类别 "' .. category .. '" 不存在'
    end
    
    local result = {}
    for subtype, _ in pairs(categories[category]) do
        table.insert(result, subtype)
    end
    
    table.sort(result)
    return table.concat(result, '、')
end

-- 获取所有可用类别
function p.listCategories(frame)
    local result = {}
    for category, _ in pairs(categories) do
        table.insert(result, category)
    end
    
    table.sort(result)
    return table.concat(result, '、')
end

-- 调试函数:显示所有传入的参数
function p.debugArgs(frame)
    local args = frame:getParent().args
    local result = {}
    
    -- 显示位置参数
    for i = 1, 10 do
        if args[i] then
            table.insert(result, string.format('位置参数 %d: %s', i, args[i]))
        end
    end
    
    -- 显示具名参数
    for key, value in pairs(args) do
        if type(key) == 'string' then
            table.insert(result, string.format('具名参数 %s: %s', key, value))
        end
    end
    
    return table.concat(result, '<br>')
end

-- 兼容性函数:为原有模板调用提供向后兼容
function p.compatibility(frame)
    local templateName = frame.args[1] or ''
    local args = frame:getParent().args
    
    -- 映射原模板名到新的类别/子类型
    local templateMap = {
        ['不用于'] = {category = '不用于', subtype = args[1]},
        ['人际关系'] = {category = '人际关系', subtype = args[1]},
        ['任务'] = {category = '任务', subtype = args[1]},
        ['农场'] = {category = '元素', subtype = '农场'},
        ['后缀'] = {category = '元素', subtype = '后缀'},
        ['锚点'] = {category = '元素', subtype = '锚点'},
        ['早期设定'] = {category = '设定', subtype = '早期设定'},
        ['好感度'] = {category = '好感度', subtype = args[1]},
        ['小标题'] = {category = '元素', subtype = '小标题'},
        ['年份'] = {category = '元素', subtype = '年份'},
        ['摘要'] = {category = '摘要', subtype = args[1]},
        ['日程'] = {category = '日程', subtype = args[1]},
        ['玩家'] = {category = '元素', subtype = '玩家'},
    }
    
    local mapping = templateMap[templateName]
    if not mapping then
        return '未知模板: ' .. templateName
    end
    
    -- 模拟调用主函数
    local newArgs = {
        [1] = mapping.category,
        [2] = mapping.subtype,
        actor = args.actor
    }
    
    -- 复制其他参数
    for i = 2, 10 do
        newArgs[i + 1] = args[i]
    end
    
    local newFrame = {
        getParent = function() return {args = newArgs} end,
        preprocess = frame.preprocess
    }
    
    return p.main(newFrame)
end

return p