UNPKG

enkanetwork

Version:

API wrapper for enka.network written on TypeScript which provides localization, caching and convenience

65 lines (64 loc) 3.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataManager = void 0; const promises_1 = __importDefault(require("node:fs/promises")); const node_path_1 = __importDefault(require("node:path")); // @ts-ignore: Json Import const characters_json_1 = __importDefault(require("../../../assets/data/characters.json")); // @ts-ignore: Json Import const constellations_json_1 = __importDefault(require("../../../assets/data/constellations.json")); // @ts-ignore: Json Import const costumes_json_1 = __importDefault(require("../../../assets/data/costumes.json")); // @ts-ignore: Json Import const namecards_json_1 = __importDefault(require("../../../assets/data/namecards.json")); // @ts-ignore: Json Import const profilePictures_json_1 = __importDefault(require("../../../assets/data/profilePictures.json")); // @ts-ignore: Json Import const skills_json_1 = __importDefault(require("../../../assets/data/skills.json")); const constants_1 = require("./constants"); class DataManager { characters; constellations; costumes; namecards; skills; profilePictures; constructor() { this.characters = characters_json_1.default; this.constellations = constellations_json_1.default; this.costumes = costumes_json_1.default; this.namecards = namecards_json_1.default; this.skills = skills_json_1.default; this.profilePictures = profilePictures_json_1.default; } async writeCharacters(data) { // Replace contents in place (keeps the array reference the finders hold) and // fully mirrors what is written to disk, even if the upstream list shrinks. this.characters.splice(0, this.characters.length, ...data); await promises_1.default.writeFile(node_path_1.default.resolve(constants_1.ASSETS_PATH, "data", "characters.json"), JSON.stringify(data, null, 4)); } async writeConstellations(data) { this.constellations.splice(0, this.constellations.length, ...data); await promises_1.default.writeFile(node_path_1.default.resolve(constants_1.ASSETS_PATH, "data", "constellations.json"), JSON.stringify(data, null, 4)); } async writeCostumes(data) { this.costumes.splice(0, this.costumes.length, ...data); await promises_1.default.writeFile(node_path_1.default.resolve(constants_1.ASSETS_PATH, "data", "costumes.json"), JSON.stringify(data, null, 4)); } async writeNamecards(data) { this.namecards.splice(0, this.namecards.length, ...data); await promises_1.default.writeFile(node_path_1.default.resolve(constants_1.ASSETS_PATH, "data", "namecards.json"), JSON.stringify(data, null, 4)); } async writeSkills(data) { this.skills.splice(0, this.skills.length, ...data); await promises_1.default.writeFile(node_path_1.default.resolve(constants_1.ASSETS_PATH, "data", "skills.json"), JSON.stringify(data, null, 4)); } async writeProfilePictures(data) { this.profilePictures.splice(0, this.profilePictures.length, ...data); await promises_1.default.writeFile(node_path_1.default.resolve(constants_1.ASSETS_PATH, "data", "profilePictures.json"), JSON.stringify(data, null, 4)); } } exports.DataManager = DataManager;