#!/usr/bin/env python3 """Generate an NPC menu; instanced dungeons always go to their original admission NPC.""" import json from pathlib import Path ROOT=Path(__file__).resolve().parent def generate(): rows=json.loads((ROOT/'destinations.json').read_text())['destinations'] lines=['-- Generated by generate.py; UTF-8, compiled as GBK by install.py.', 'quest ava2_travel begin',' state start begin', ' function destinations()',' return {'] for row in rows: lines.append(' {%s, %d, %d, %d, %s},'%( json.dumps(row['name'],ensure_ascii=False),row['x'],row['y'],row['level'], 'true' if row['mode']=='entrance' else 'false')) lines+=[' }',' end', ''' function menu() local destinations = ava2_travel.destinations() local page = 1 while true do local first = (page-1)*5+1 local last = math.min(first+4,table.getn(destinations)) local options = {} for i=first,last do table.insert(options,destinations[i][1]) 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