105 lines
5.0 KiB
Python
105 lines
5.0 KiB
Python
# coding: utf-8
|
|
"""Generate the quest from the audited server map catalog (Python 3)."""
|
|
import json
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent
|
|
|
|
def generate():
|
|
catalog = json.loads((ROOT / 'maps.json').read_text(encoding='utf-8'))
|
|
def quote(value):
|
|
return json.dumps(value, ensure_ascii=False)
|
|
lines = ['-- Generated by generate.py from maps.json. Do not edit by hand.',
|
|
'-- UTF-8 source; install.sh compiles GBK for the 203 server.',
|
|
'quest ring_warp begin', ' state start begin',
|
|
' function destinations()', ' return {']
|
|
for category in catalog['categories']:
|
|
lines.append(' {name = %s, maps = {' % quote(category['name']))
|
|
for m in category['maps']:
|
|
lines.append(' {id = %d, name = %s, x = %d, y = %d, mode = %s, note = %s},' %
|
|
(m['id'], quote(m['name']), m['target'][1], m['target'][2], quote(m['mode']), quote(m['note'])))
|
|
lines.append(' }},')
|
|
lines.extend([' }', ' end'])
|
|
lines.append(''' when 10031.sig_use begin
|
|
local categories = ring_warp.destinations()
|
|
local category_options = {}
|
|
for i = 1, table.getn(categories) do
|
|
table.insert(category_options, categories[i].name)
|
|
end
|
|
table.insert(category_options, "关闭")
|
|
while true do
|
|
say_title("移动戒指")
|
|
say("请选择地图分类:")
|
|
local category = select_table(category_options)
|
|
if category == table.getn(category_options) then return end
|
|
local maps = categories[category].maps
|
|
local page = 1
|
|
local browsing = true
|
|
while browsing do
|
|
local first = (page - 1) * 5 + 1
|
|
local last = math.min(first + 4, table.getn(maps))
|
|
local options = {}
|
|
for i = first, last do
|
|
local label = maps[i].name
|
|
if maps[i].mode == "entrance" then label = label .. "(入口)" end
|
|
table.insert(options, label)
|
|
end
|
|
local count = table.getn(options)
|
|
local previous = 0
|
|
local following = 0
|
|
if page > 1 then
|
|
table.insert(options, "上一页")
|
|
previous = table.getn(options)
|
|
end
|
|
if last < table.getn(maps) then
|
|
table.insert(options, "下一页")
|
|
following = table.getn(options)
|
|
end
|
|
table.insert(options, "返回分类")
|
|
say_title(categories[category].name)
|
|
say("第 " .. page .. " 页 / 共 " .. math.ceil(table.getn(maps) / 5) .. " 页")
|
|
local choice = select_table(options)
|
|
if choice == table.getn(options) then
|
|
browsing = false
|
|
elseif previous > 0 and choice == previous then
|
|
page = page - 1
|
|
elseif following > 0 and choice == following then
|
|
page = page + 1
|
|
elseif choice >= 1 and choice <= count then
|
|
local destination = maps[first + choice - 1]
|
|
say_title(destination.name)
|
|
say("地图编号:" .. destination.id)
|
|
if destination.mode == "gm" and not pc.is_gm() then
|
|
say(destination.note)
|
|
wait()
|
|
elseif destination.mode == "event" then
|
|
say(destination.note)
|
|
wait()
|
|
else
|
|
if destination.mode == "entrance" then say(destination.note) end
|
|
if destination.mode == "gm" then say("管理员专用测试地图。") end
|
|
if select("传送", "返回列表") == 1 then
|
|
if not pc.can_warp() then
|
|
say("当前无法传送,请结束交易或其他操作后再试。")
|
|
return
|
|
end
|
|
pc.warp(destination.x, destination.y)
|
|
return
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end''')
|
|
result = '\n'.join(lines) + '\n'
|
|
encoded = result.encode('gbk')
|
|
if b'\\' in encoded:
|
|
bad = sorted({c for c in result if b'\\' in c.encode('gbk')})
|
|
raise ValueError('qc cannot parse GBK backslash bytes: %r' % bad)
|
|
return result
|
|
|
|
if __name__ == '__main__':
|
|
(ROOT / 'ring_warp.quest').write_text(generate(), encoding='utf-8')
|