UNPKG

pogo-data-generator

Version:
62 lines (61 loc) 2.28 kB
"use strict"; 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 LocationCards extends Masterfile_1.default { options; parsedLocationCards; static resolveId(value, label = 'location card id') { if (value === undefined || value === null || value === '') return undefined; if (typeof value === 'number') return value; if (/^\d+$/.test(value)) return +value; const resolved = pogo_protos_1.Rpc.LocationCard[value]; if (resolved !== undefined) return resolved; console.warn(`Unable to resolve ${label}`, value); return undefined; } constructor(options) { super(); this.options = options; this.parsedLocationCards = {}; } addLocationCard(object) { const { templateId, data } = object; const { locationCardSettings } = data; if (!locationCardSettings) { return; } try { const { locationCard, imageUrl, cardType, vfxAddress } = locationCardSettings; const id = LocationCards.resolveId(locationCard); if (id === undefined) { return; } const resolvedProto = typeof id === 'number' && typeof pogo_protos_1.Rpc.LocationCard[id] === 'string' ? pogo_protos_1.Rpc.LocationCard[id] : typeof locationCard === 'string' && !/^\d+$/.test(locationCard) ? locationCard : templateId; const formattedProto = resolvedProto.replace(/^LC_(SPECIALBACKGROUND_|SPECIAL_BACKGROUND_)?/, ''); this.parsedLocationCards[id] = { id, proto: resolvedProto, formatted: this.capitalize(formattedProto), imageUrl, cardType, vfxAddress, }; } catch (e) { console.warn(e, '\n', object); } } } exports.default = LocationCards;