UNPKG

@skullandbonestools/snbdata

Version:

Inofficial data package for the Skull and Bones game by Ubisoft.

125 lines 5.55 kB
import cosmeticsData from '../../data/cosmetics.json'; import { Contracts } from './contracts'; import { Events } from './events'; import { Factions } from './factions'; import { Items } from './items'; import { Materials } from './materials'; import { Seasons } from './seasons'; import { Sets } from './sets'; import { Ships } from './ships'; import { WorldEvents } from './worldEvents'; export class Cosmetic { constructor(id, type, dateAdded, lastUpdated, rarity, tier, set, obtainable, pieces, effect, season, faction, ship, /** * @deprecated Not actively maintained anymore and may be removed in the future, obtainable field is used in favor */ contract, basic, upgrades, required, requiredRank, /** * @deprecated Not actively maintained anymore and may be removed in the future, obtainable field is used in favor */ bounty, event, worldEvent, /** * Timestamp of when the cosmetic was removed from the game. Use only for completely removed pieces. */ removed) { this.id = id; this.type = type; this.dateAdded = dateAdded; this.lastUpdated = lastUpdated; this.rarity = rarity; this.tier = tier; this.set = set; this.obtainable = obtainable; this.pieces = pieces; this.effect = effect; this.season = season; this.faction = faction; this.ship = ship; this.contract = contract; this.basic = basic; this.upgrades = upgrades; this.required = required; this.requiredRank = requiredRank; this.bounty = bounty; this.event = event; this.worldEvent = worldEvent; this.removed = removed; } static fromRawData(rawData) { const season = rawData.season; const faction = rawData.faction; const ship = rawData.ship; const set = rawData.set; const contract = rawData.contract; const event = rawData.event; const worldEvent = Array.isArray(rawData.worldEvent) ? rawData.worldEvent.map((_worldEvent) => WorldEvents[_worldEvent]) : WorldEvents[rawData.worldEvent]; const required = rawData.required ? new Map() : undefined; if (required) { for (const [requiredKey, quantity] of Object.entries(rawData.required)) { const requiredMaterial = requiredKey; required.set(Materials[requiredMaterial], quantity); } } let obtainable = rawData.obtainable ?? undefined; if (Array.isArray(obtainable)) { const _obtainable = new Array(); for (const obtainableKey of rawData.obtainable) { if (Array.isArray(obtainableKey)) { const obtainableGroup = new Array(); for (const subKey of obtainableKey) { const obtainableItem = Items[subKey]; if (obtainableItem && obtainableItem.type === "chest") { obtainableGroup.push(obtainableItem); } else { obtainableGroup.push(subKey); } } _obtainable.push(obtainableGroup); } else { const obtainableItem = Items[obtainableKey]; if (obtainableItem && obtainableItem.type === "chest") { _obtainable.push(obtainableItem); } else { _obtainable.push(obtainableKey); } } } obtainable = _obtainable; } else if (obtainable) { const obtainableItem = Items[rawData.obtainable]; if (obtainableItem && obtainableItem.type === "chest") { obtainable = obtainableItem; } } return new Cosmetic(rawData.id, rawData.type, new Date(rawData.dateAdded), new Date(rawData.lastUpdated), rawData.rarity ?? undefined, rawData.tier ?? undefined, rawData.set ? Sets[set] : undefined, obtainable, rawData.pieces ?? undefined, rawData.effect ?? undefined, rawData.season ? Seasons[season] : undefined, rawData.faction ? Factions[faction] : undefined, rawData.ship ? Ships[ship] : undefined, rawData.contract ? Contracts[contract] : undefined, undefined, undefined, required, rawData.requiredRank ?? undefined, rawData.bounty ?? undefined, rawData.event ? Events[event] : undefined, worldEvent ?? undefined, rawData.removed ? new Date(rawData.removed) : undefined); } static updateCosmeticWithUpgrades(key, rawData, cosmetics) { if (rawData.basic) { const basic = cosmetics[rawData.basic]; if (basic) cosmetics[key].basic = basic; } if (rawData.upgrades) { const upgrades = rawData.upgrades.map((upgradeCosmetic) => cosmetics[upgradeCosmetic]); cosmetics[key].upgrades = upgrades; } } static loadCosmetics() { const cosmetics = {}; for (const [key, value] of Object.entries(cosmeticsData)) { cosmetics[key] = Cosmetic.fromRawData(value); } for (const [key, value] of Object.entries(cosmeticsData)) { Cosmetic.updateCosmeticWithUpgrades(key, value, cosmetics); } return cosmetics; } } export const Cosmetics = Cosmetic.loadCosmetics(); //# sourceMappingURL=cosmetics.js.map