pogo-data-generator
Version:
Pokemon GO project data generator
65 lines (64 loc) • 2.46 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const pogo_protos_1 = require("@na-ji/pogo-protos");
const Masterfile_1 = __importDefault(require("./Masterfile"));
class Item extends Masterfile_1.default {
options;
parsedItems;
static resolveId(value, label = 'item id') {
if (value === undefined || value === null || value === '')
return undefined;
if (typeof value === 'number')
return value;
if (/^\d+$/.test(value))
return +value;
const directMatch = pogo_protos_1.Rpc.Item[value];
if (directMatch !== undefined)
return directMatch;
const prefixedValue = value.startsWith('ITEM_') ? value : `ITEM_${value}`;
const prefixedMatch = pogo_protos_1.Rpc.Item[prefixedValue];
if (prefixedMatch !== undefined)
return prefixedMatch;
console.warn(`Unable to resolve ${label}`, value);
return undefined;
}
constructor(options) {
super();
this.options = options;
this.parsedItems = {};
}
addItem(object) {
try {
const { data: { itemSettings: { itemId, itemType, category, dropTrainerLevel }, }, templateId, } = object;
if (!this.options.minTrainerLevel ||
!dropTrainerLevel ||
dropTrainerLevel <= this.options.minTrainerLevel) {
const id = Item.resolveId(itemId);
if (id === undefined) {
return;
}
this.parsedItems[id] = {
itemId: id,
itemName: templateId
? this.capitalize(templateId.replace('ITEM_', ''))
: '',
proto: templateId,
type: typeof itemType === 'string'
? this.capitalize(itemType.replace('ITEM_TYPE_', ''))
: '',
category: category
? this.capitalize(category.replace('ITEM_CATEGORY_', ''))
: '',
minTrainerLevel: dropTrainerLevel,
};
}
}
catch (e) {
console.warn(e, '\n', object);
}
}
}
exports.default = Item;