打开/关闭菜单
331
1.7K
131
11.8K
星露谷物语扩展百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:GiftsByItem:修订间差异

来自星露谷物语扩展百科
Sizau留言 | 贡献
重构
Sizau留言 | 贡献
更新
第1行: 第1行:
local Vanilla = require("模块:GiftsByItem")
local Utils = require("Module:Utils")
local ID = require("Module:ID")
local Vanilla = require("Module:GiftsByItem")
 
local p = {}
local p = {}


第16行: 第19行:
}
}


-- 翻译映射表合并
-- 缓存合并后的数据
local function createTranslationMap()
local translationMap
     local combined = {}
local orderList
    -- 原版翻译
local originalMap
local orderIndexMap
 
-- 初始化函数
local function initializeData()
     if translationMap then return end
   
    translationMap = {}
     for k, v in pairs(Vanilla.translation) do
     for k, v in pairs(Vanilla.translation) do
         combined[k] = v
         translationMap[k] = v
     end
     end
    -- SVE 翻译
     for k, v in pairs(newVillagers) do
     for k, v in pairs(newVillagers) do
         combined[k] = v
         translationMap[k] = v
     end
     end
     return combined
      
end
     orderList = {}
 
-- 排序顺序合并
local function createNewOrder()
     local combined = {}
    -- 原版顺序
     for _, name in ipairs(Vanilla.predefinedOrder) do
     for _, name in ipairs(Vanilla.predefinedOrder) do
         table.insert(combined, name)
         table.insert(orderList, name)
     end
     end
    -- SVE 顺序
     for _, name in ipairs(orderAdditions) do
     for _, name in ipairs(orderAdditions) do
         table.insert(combined, name)
         table.insert(orderList, name)
    end
   
    originalMap = {}
    for en, zh in pairs(translationMap) do
        originalMap[zh] = en
    end
   
    orderIndexMap = {}
    for i, name in ipairs(orderList) do
        orderIndexMap[name] = i
     end
     end
    return combined
end
end


-- 创建 SVE 的数据
-- SVE 的主函数
local newTranslationMap = createTranslationMap()
function p.tssve(frame)
local newOrder = createNewOrder()
    initializeData()
    local villagerlist = frame.args[1]
    return Vanilla.processVillagers(villagerlist, translationMap, orderIndexMap, originalMap, "SVE")
end


-- 生成 SVE 的反向映射和索引
-- 重写 getCurrentProcessor 函数,返回 SVE 的处理函数
local sveOriginal = {}
function p.getCurrentProcessor()
for en, zh in pairs(newTranslationMap) do
     return p.tssve
     sveOriginal[zh] = en
end
end


local newOrderIndex = {}
-- 重写 getCurrentIDFunction 函数,返回 SVE 的 ID 函数
for i, name in ipairs(newOrder) do
function p.getCurrentIDFunction()
     newOrderIndex[name] = i
     return ID.idSVE
end
end


-- SVE 的主函数
-- 重写 getCurrentDataSource 函数,返回 SVE 的数据源
function p.tssve(frame)
function p.getCurrentDataSource()
     local villagerlist = frame.args[1]
     return Utils.LazyLoad('Module:Expanded/GiftsByItem/data')
     return Vanilla.processVillagers(villagerlist, newTranslationMap, newOrderIndex, sveOriginal, "SVE")
end
 
-- SVE 的 generateGiftTable 函数
function p.generateGiftTable(frame)
     return Vanilla.generateGiftTableWithProcessor(frame, p.getCurrentProcessor(), p.getCurrentIDFunction(), p.getCurrentDataSource())
end
end


-- 导出原版模块的函数供其他地方使用
-- 导出一些有用的数据和函数
p.newVillagers = newVillagers
p.orderAdditions = orderAdditions
p.base = Vanilla
p.base = Vanilla
function p.getTranslationMap()
    initializeData()
    return translationMap
end
function p.getOrderList()
    initializeData()
    return orderList
end


return p
return p

2025年9月4日 (四) 21:11的版本

描述

当前模块用于物品的人物喜好列表的生成,能够根据导出的数据进行全自动的格式化、排序和输出。

人物按照一定的逻辑排序,此外还对排版显示上进行了一定的优化。

如果该模块存在任何问题,请在{{GiftsByItem}}对应的讨论页中反馈。

模块使用的数据见模块:GiftsByItem/data,相关数据是通过由中文社区维护的模组导出的,相关代码见 Github 仓库中的 GetNPCGiftTastes 部分

[ 查看 | 编辑 | 历史 | 刷新 ]上述文档的内容来自模块:GiftsByItem/doc
local Utils = require("Module:Utils")
local ID = require("Module:ID")
local Vanilla = require("Module:GiftsByItem")

local p = {}

-- SVE 新增人物
local newVillagers = {
    ["Lance"] = "兰斯", ["Magnus"] = "马格努斯", ["Marlon"] = "马龙",
    ["Martin"] = "马丁", ["Morgan"] = "摩根", ["Morris"] = "莫里斯",
    ["Olivia"] = "奥利维亚", ["Andy"] = "安迪", ["Scarlett"] = "斯嘉丽",
    ["Sophia"] = "索菲娅", ["Susan"] = "苏珊", ["Victor"] = "维克多",
    ["Henchman"] = "仆从", ["Claire"] = "克莱尔", ["Gunther"] = "冈瑟",
    ["Apples"] = "苹果"
}

local orderAdditions = {
    "索菲娅", "维克多", "克莱尔", "马丁", "安迪", "苏珊", "奥利维亚", "兰斯", "斯嘉丽", "莫里斯", "马龙", "冈瑟", "仆从", "马格努斯", "摩根", "苹果"
}

-- 缓存合并后的数据
local translationMap
local orderList
local originalMap
local orderIndexMap

-- 初始化函数
local function initializeData()
    if translationMap then return end
    
    translationMap = {}
    for k, v in pairs(Vanilla.translation) do
        translationMap[k] = v
    end
    for k, v in pairs(newVillagers) do
        translationMap[k] = v
    end
    
    orderList = {}
    for _, name in ipairs(Vanilla.predefinedOrder) do
        table.insert(orderList, name)
    end
    for _, name in ipairs(orderAdditions) do
        table.insert(orderList, name)
    end
    
    originalMap = {}
    for en, zh in pairs(translationMap) do
        originalMap[zh] = en
    end
    
    orderIndexMap = {}
    for i, name in ipairs(orderList) do
        orderIndexMap[name] = i
    end
end

-- SVE 的主函数
function p.tssve(frame)
    initializeData()
    local villagerlist = frame.args[1]
    return Vanilla.processVillagers(villagerlist, translationMap, orderIndexMap, originalMap, "SVE")
end

-- 重写 getCurrentProcessor 函数,返回 SVE 的处理函数
function p.getCurrentProcessor()
    return p.tssve
end

-- 重写 getCurrentIDFunction 函数,返回 SVE 的 ID 函数
function p.getCurrentIDFunction()
    return ID.idSVE
end

-- 重写 getCurrentDataSource 函数,返回 SVE 的数据源
function p.getCurrentDataSource()
    return Utils.LazyLoad('Module:Expanded/GiftsByItem/data')
end

-- SVE 的 generateGiftTable 函数
function p.generateGiftTable(frame)
    return Vanilla.generateGiftTableWithProcessor(frame, p.getCurrentProcessor(), p.getCurrentIDFunction(), p.getCurrentDataSource())
end

-- 导出一些有用的数据和函数
p.newVillagers = newVillagers
p.orderAdditions = orderAdditions
p.base = Vanilla

function p.getTranslationMap()
    initializeData()
    return translationMap
end

function p.getOrderList()
    initializeData()
    return orderList
end

return p