summaryrefslogtreecommitdiff
path: root/itemdb.py
blob: 593699fb5a73621a5bf99cf825af9d48d301fa0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from loggers import debuglog

item_names = {0: 'GP'}


def load_itemdb(dbfile='db/itemdb.txt'):
    with open(dbfile, 'rt') as f:
        for l in f.readlines():
            try:
                sn, sr = l.split(' ', 1)
                item_id = int(sn)
                item_name = sr[:-1] if sr.endswith('\n') else sr
                item_names[item_id] = item_name
            except ValueError:
                pass

    debuglog.info("Loaded itemdb from %s", dbfile)
    return item_names


def item_name(item_id, mplus=False):
    name = item_names.get(item_id, 'Item' + str(item_id))
    if mplus:
        return '[@@{}|{}@@]'.format(item_id, name)
    else:
        return name