UNPKG

@kobold/xiv

Version:

Automated Kobold configuration for Final Fantasy XIV

109 lines (77 loc) 3.63 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault"); var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property"); _Object$defineProperty(exports, "__esModule", { value: true }); exports.buildKoboldXIV = buildKoboldXIV; var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/map")); var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/promise")); var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/includes")); var _flatMap = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/instance/flat-map")); var _core = require("@kobold/core"); var _fs = _interopRequireDefault(require("fs")); var _path = _interopRequireDefault(require("path")); var _util = _interopRequireDefault(require("util")); var _context; const asyncAccess = _util.default.promisify(_fs.default.access); const asyncReadDir = _util.default.promisify(_fs.default.readdir); /* eslint-disable @typescript-eslint/camelcase */ const categories = { common: 0x00, bgcommon: 0x01, bg: 0x02, cut: 0x03, chara: 0x04, shader: 0x05, ui: 0x06, sound: 0x07, vfx: 0x08, ui_script: 0x09, exd: 0x0a, game_script: 0x0b, music: 0x0c, sqpack_test: 0x12, debug: 0x13 }; /* eslint-enable @typescript-eslint/camelcase */ // Stolen from goatcorp. Pls2not sic lawyers. const tryPaths = (0, _flatMap.default)(_context = ['C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn', 'C:\\Program Files (x86)\\Steam\\steamapps\\common\\FINAL FANTASY XIV Online', 'C:\\Program Files (x86)\\Steam\\steamapps\\common\\FINAL FANTASY XIV - A Realm Reborn', 'C:\\Program Files (x86)\\FINAL FANTASY XIV - A Realm Reborn', 'C:\\Program Files (x86)\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn']).call(_context, tryPath => [tryPath, tryPath.split(_path.default.win32.sep).join(_path.default.posix.sep).replace('C:', '/mnt/c')]); const sqPackDir = _path.default.join('game', 'sqpack'); async function buildKoboldXIV(opts) { const sqPackPath = await getSqPackPath(opts === null || opts === void 0 ? void 0 : opts.path); // Get the list of game data repositories let repoDirs; try { repoDirs = await asyncReadDir(sqPackPath); } catch { throw new Error(`Could not read SqPack dir at "${sqPackPath}". Please ensure you have a valid installation of FFXIV.`); } // _All_ xiv installations will have at least the ffxiv repo - if it's missing, something is wrong if (!(0, _includes.default)(repoDirs).call(repoDirs, 'ffxiv')) { throw new Error(`SqPack dir "${sqPackPath}" does not contain the base "ffxiv" repository. Please ensure you have a valid installation of FFXIV.`); } // Build up the actual kobold instance :meowpraise: const kobold = new _core.Kobold(); kobold.addCategories(categories); for (const repoDir of repoDirs) { kobold.addRepository({ name: repoDir, path: _path.default.join(sqPackPath, repoDir), default: repoDir === 'ffxiv' }); } return kobold; } async function getSqPackPath(providedPath) { let gamePath = providedPath; if (gamePath == null) { // They haven't provided a path, try to find one try { gamePath = await _promise.default.any((0, _map.default)(tryPaths).call(tryPaths, tryPath => asyncAccess(tryPath).then(() => tryPath))); } catch { /* noop */ } } if (gamePath == null) { throw new Error('Could not find FFXIV. Please specify an absolute path to your installation.'); } return _path.default.join(gamePath, sqPackDir); }