打开/关闭搜索
搜索
打开/关闭菜单
1K
5.2K
4
8.2K
星砂岛百科
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
上传文件
打开/关闭外观设置菜单
通知
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
本站正在进行早期测试,目前仍存在许多内容的缺失。
查看“︁模块:Shop”︁的源代码
来自星砂岛百科
查看
阅读
查看源代码
查看历史
associated-pages
模块
讨论
更多操作
←
模块:Shop
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:已验证邮箱用户
您没有权限编辑
模块
命名空间内的页面。
您必须确认您的电子邮件地址才能编辑页面。请通过
参数设置
设置并确认您的电子邮件地址。
您可以查看和复制此页面的源代码。
local common = require('Module:Common') local item_common = require('Module:ItemCommon') local item = require('Module:Item') local css = require('Module:CSS') local p = {} local SHOP_FIELD_MAP = { name = 'n', kind = 'k', open_duration = 'od', shop_template = 'st', festival_template = 'ft', area_ids = 'a', sources = 'ss', entries = 'e', } local ENTRY_FIELD_MAP = { item_id = 'i', group = 'g', source = 's', price_value = 'pv', price_currency = 'pc', price_costs = 'ca', max_count = 'm', refresh_interval = 'r', condition = 'c', title_requirement = 'tr', discount = 'd', need_discount = 'nd', only_one = 'o', ui_sort = 'u', } local REVERSE_SHOP_KEY = 'sid' local DEFAULT_CURRENCY = 'Currency.Default' local shop_data_cache local shop_mapping_cache local by_item_cache local function normalize_key(value) return common.normalizeKey(value) end local function load_shop_data() if shop_data_cache then return end local raw_data raw_data, shop_mapping_cache = item_common.loadDomainData('数据:Shop/shop_index.json', '数据:Shop/shop_mapping.json') if type(raw_data) == 'table' and type(raw_data.records) == 'table' then shop_data_cache = raw_data.records else shop_data_cache = raw_data or {} end local raw_reverse = common.loadJsonData('数据:Shop/shop_by_item.json') or {} if type(raw_reverse) == 'table' and type(raw_reverse.records) == 'table' then by_item_cache = raw_reverse.records else by_item_cache = raw_reverse or {} end end local function get_shop_field(record, field) if type(record) ~= 'table' then return nil end local short_key = SHOP_FIELD_MAP[field] or field if record[short_key] ~= nil then return record[short_key] end return record[field] end local function get_entry_field(entry, field) if type(entry) ~= 'table' then return nil end local short_key = ENTRY_FIELD_MAP[field] or field if entry[short_key] ~= nil then return entry[short_key] end return entry[field] end local function resolve_shop_id_from_mapping(value) if type(shop_mapping_cache) ~= 'table' then return '' end local normalized = normalize_key(value) if normalized == '' then return '' end if shop_mapping_cache.name_to_id and shop_mapping_cache.name_to_id[normalized] then return shop_mapping_cache.name_to_id[normalized] end if shop_mapping_cache.aliases and shop_mapping_cache.aliases[normalized] then return shop_mapping_cache.aliases[normalized] end return '' end local function find_shop_record(key) load_shop_data() local resolved = common.trim(key) if resolved == '' then resolved = common.getCurrentTitleText() end local normalized = normalize_key(resolved) if shop_data_cache[normalized] then return shop_data_cache[normalized], resolved end local mapped_id = resolve_shop_id_from_mapping(resolved) if mapped_id ~= '' then local mapped_key = normalize_key(mapped_id) if shop_data_cache[mapped_key] then return shop_data_cache[mapped_key], mapped_id end end return nil, '' end local function resolve_item_id(key) local record = item_common.findItemRecord(key) if type(record) == 'table' and common.trim(record.id or '') ~= '' then return common.trim(record.id) end return common.trim(key) end local function get_entries_for_item(key) load_shop_data() local item_id = resolve_item_id(key) if item_id == '' then return {} end return by_item_cache[normalize_key(item_id)] or {} end local function render_shop_link(shop_record, shop_id) local display_name = common.trim(get_shop_field(shop_record, 'name') or shop_id) if display_name == '' then display_name = common.trim(shop_id) end if display_name == '' then return '' end return ('[[%s]]'):format(display_name) end local function render_currency_item(frame, currency_id, count) local resolved_currency = common.trim(currency_id) if resolved_currency == '' then return '' end local suffix = '' if tonumber(count) and tonumber(count) > 0 then suffix = tostring(math.floor(tonumber(count))) end return item.renderItemWithArgs(frame, { resolved_currency, suffix, }) end local function render_price(frame, entry) local costs = get_entry_field(entry, 'price_costs') if type(costs) == 'table' and #costs > 0 then local parts = {} for _, cost in ipairs(costs) do if type(cost) == 'table' and common.trim(cost[1] or '') ~= '' then parts[#parts + 1] = render_currency_item(frame, cost[1], cost[2]) end end return table.concat(parts, '') end local currency = common.trim(get_entry_field(entry, 'price_currency') or DEFAULT_CURRENCY) local value = tonumber(get_entry_field(entry, 'price_value')) or 0 if currency == '' or currency == DEFAULT_CURRENCY then if value <= 0 then return '免费' end return tostring(math.floor(value)) .. ' 金币' end return render_currency_item(frame, currency, value) end local function format_refresh(refresh_interval) local refresh = tonumber(refresh_interval) or 0 if refresh == -1 then return '不刷新' end if refresh == 1 then return '每日刷新' end if refresh > 1 then return tostring(math.floor(refresh)) .. ' 天刷新' end return '' end local function format_limit(entry) local parts = {} local max_count = tonumber(get_entry_field(entry, 'max_count')) or 0 if max_count == -1 or max_count == 0 then parts[#parts + 1] = '不限购' else parts[#parts + 1] = '限购 ' .. tostring(math.floor(max_count)) end local refresh_text = format_refresh(get_entry_field(entry, 'refresh_interval')) if refresh_text ~= '' then parts[#parts + 1] = refresh_text end if get_entry_field(entry, 'only_one') then parts[#parts + 1] = '单次仅购 1' end return table.concat(parts, ' / ') end local function format_condition(entry) local parts = {} local title_requirement = common.trim(get_entry_field(entry, 'title_requirement') or '') local condition = common.trim(get_entry_field(entry, 'condition') or '') local discount = tonumber(get_entry_field(entry, 'discount')) or 0 local need_discount = get_entry_field(entry, 'need_discount') if title_requirement ~= '' then parts[#parts + 1] = title_requirement end if condition ~= '' then parts[#parts + 1] = condition end if discount ~= 0 then parts[#parts + 1] = '折扣值 ' .. tostring(math.floor(discount)) elseif need_discount then parts[#parts + 1] = '受折扣系统影响' end if #parts == 0 then return '' end return table.concat(parts, '<br>') end local function render_item_cell(frame, entry) local item_id = common.trim(get_entry_field(entry, 'item_id') or '') if item_id == '' then return '' end return item.renderItemWithArgs(frame, { item_id, class = 'block' }) end local function render_sold_by_table(frame, entries) if type(entries) ~= 'table' or #entries == 0 then return '' end load_shop_data() local out = {} out[#out + 1] = css.quickCall('Item') or '' out[#out + 1] = '{| class="wikitable"' out[#out + 1] = '! 商店' out[#out + 1] = '! 价格' out[#out + 1] = '! 限购 / 刷新' out[#out + 1] = '! 条件' for _, entry in ipairs(entries) do local shop_id = common.trim(entry[REVERSE_SHOP_KEY] or '') local shop_record = shop_data_cache[normalize_key(shop_id)] local shop_cell = render_shop_link(shop_record, shop_id) local price_cell = render_price(frame, entry) local limit_cell = format_limit(entry) local condition_cell = format_condition(entry) if condition_cell == '' then condition_cell = '无' end out[#out + 1] = '|-' out[#out + 1] = '| ' .. shop_cell out[#out + 1] = '| ' .. price_cell out[#out + 1] = '| ' .. limit_cell out[#out + 1] = '| ' .. condition_cell end out[#out + 1] = '|}' return table.concat(out, '\n') end local function render_inventory_table(frame, shop_record) local entries = get_shop_field(shop_record, 'entries') if type(entries) ~= 'table' or #entries == 0 then return '' end local out = {} out[#out + 1] = css.quickCall('Item') or '' out[#out + 1] = '{| class="wikitable"' out[#out + 1] = '! 物品' out[#out + 1] = '! 分类' out[#out + 1] = '! 价格' out[#out + 1] = '! 限购 / 刷新' out[#out + 1] = '! 条件' for _, entry in ipairs(entries) do local category = common.trim(get_entry_field(entry, 'group') or '') local price_cell = render_price(frame, entry) local limit_cell = format_limit(entry) local condition_cell = format_condition(entry) if category == '' then category = '未分组' end if condition_cell == '' then condition_cell = '无' end out[#out + 1] = '|-' out[#out + 1] = '| ' .. render_item_cell(frame, entry) out[#out + 1] = '| ' .. category out[#out + 1] = '| ' .. price_cell out[#out + 1] = '| ' .. limit_cell out[#out + 1] = '| ' .. condition_cell end out[#out + 1] = '|}' return table.concat(out, '\n') end function p.getShopField(frame) local key = common.getArg(frame, 1, '') local field = common.getArg(frame, 2, '') if field == '' then return '' end local shop_record = find_shop_record(key) if not shop_record then return '' end return common.toText(get_shop_field(shop_record, field)) end function p.renderSoldBy(frame) local key = common.getArg(frame, 1, '') local entries = get_entries_for_item(key) if #entries == 0 then return '暂无商店出售记录。' end return render_sold_by_table(frame, entries) end function p.renderShopInventory(frame) local key = common.getArg(frame, 1, '') local shop_record = find_shop_record(key) if not shop_record then return '未找到商店数据。' end return render_inventory_table(frame, shop_record) end return p
该页面嵌入的页面:
模板:Documentation subpage
(
查看源代码
)
模块:Shop/doc
(
查看源代码
)
返回
模块:Shop
。
查看“︁模块:Shop”︁的源代码
来自星砂岛百科