From 45c662e4d4abe49453e6f0558d0efcba5b37d3e5 Mon Sep 17 00:00:00 2001 From: V13Axel Date: Thu, 12 May 2022 20:53:22 -0400 Subject: [PATCH 01/33] Initializing Importing for empty Pull Request From a05edbf106487367bbf3a5504784161be54439b0 Mon Sep 17 00:00:00 2001 From: V13Axel Date: Thu, 12 May 2022 20:55:58 -0400 Subject: [PATCH 02/33] Functional API call, prototype interface --- docs/index.html | 64 ++++++++++ docs/js/app.js | 220 ++++++++++++++++++++++++---------- src/index.html | 64 ++++++++++ src/js/app.js | 22 ++-- src/js/constants.js | 2 +- src/js/encounter.js | 20 ++-- src/js/{lib.js => helpers.js} | 0 src/js/importer.js | 22 ++++ src/js/monster.js | 6 +- 9 files changed, 335 insertions(+), 85 deletions(-) rename src/js/{lib.js => helpers.js} (100%) create mode 100644 src/js/importer.js diff --git a/docs/index.html b/docs/index.html index eac642b0..ac88a257 100644 --- a/docs/index.html +++ b/docs/index.html @@ -103,6 +103,7 @@ + +
diff --git a/docs/js/app.js b/docs/js/app.js index 6e347b74..2ac772f8 100644 --- a/docs/js/app.js +++ b/docs/js/app.js @@ -9161,15 +9161,16 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var choices_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! choices.js */ "./node_modules/choices.js/public/assets/scripts/choices.js"); /* harmony import */ var choices_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(choices_js__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var hotkeys_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! hotkeys-js */ "./node_modules/hotkeys-js/dist/hotkeys.esm.js"); -/* harmony import */ var _encounter_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./encounter.js */ "./src/js/encounter.js"); -/* harmony import */ var nouislider__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! nouislider */ "./node_modules/nouislider/dist/nouislider.js"); -/* harmony import */ var nouislider__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(nouislider__WEBPACK_IMPORTED_MODULE_4__); -/* harmony import */ var _lib_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./lib.js */ "./src/js/lib.js"); -/* harmony import */ var _constants_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./constants.js */ "./src/js/constants.js"); -/* harmony import */ var _monster_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./monster.js */ "./src/js/monster.js"); -/* harmony import */ var tippy_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! tippy.js */ "./node_modules/tippy.js/dist/tippy.esm.js"); -/* harmony import */ var _alpinejs_persist__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @alpinejs/persist */ "./node_modules/@alpinejs/persist/dist/module.esm.js"); -/* harmony import */ var alpinejs__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! alpinejs */ "./node_modules/alpinejs/dist/module.esm.js"); +/* harmony import */ var _encounter__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./encounter */ "./src/js/encounter.js"); +/* harmony import */ var _helpers__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./helpers */ "./src/js/helpers.js"); +/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./constants */ "./src/js/constants.js"); +/* harmony import */ var _monster__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./monster */ "./src/js/monster.js"); +/* harmony import */ var _importer__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./importer */ "./src/js/importer.js"); +/* harmony import */ var tippy_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! tippy.js */ "./node_modules/tippy.js/dist/tippy.esm.js"); +/* harmony import */ var nouislider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! nouislider */ "./node_modules/nouislider/dist/nouislider.js"); +/* harmony import */ var nouislider__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(nouislider__WEBPACK_IMPORTED_MODULE_8__); +/* harmony import */ var _alpinejs_persist__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! @alpinejs/persist */ "./node_modules/@alpinejs/persist/dist/module.esm.js"); +/* harmony import */ var alpinejs__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! alpinejs */ "./node_modules/alpinejs/dist/module.esm.js"); function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } @@ -9206,29 +9207,31 @@ __webpack_require__(/*! @fortawesome/fontawesome-free */ "./node_modules/@fortaw + var internationalNumberFormat = new Intl.NumberFormat('en-US'); function app() { return { sourcesVersion: "2.1.0", - storedSourcesVersion: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist("2.0.0").as('storedSourcesVersion'), + storedSourcesVersion: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist("2.0.0").as('storedSourcesVersion'), menu: false, showFilters: false, showSourcesModal: false, showEncounterModal: false, showPartyModal: false, showKeyboardModal: false, + showImporterModal: true, mobileEncounterTab: false, filters: {}, searchPlaceholder: "", nonDefaultFiltersCount: 0, - loadedSources: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist([]).as('sources'), - loadedMonsters: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist([]).as('monsters'), - encounterHistory: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist([]).as('encounterHistory'), - savedEncounters: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist([]).as('savedEncounters'), - loadedEncounterIndex: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist(null).as('loadedEncounterIndex'), - loadedLastEncounter: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist(false).as('loadedLastEncounter'), - savedParties: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist([]).as('savedParties'), + loadedSources: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('sources'), + loadedMonsters: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('monsters'), + encounterHistory: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('encounterHistory'), + savedEncounters: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('savedEncounters'), + loadedEncounterIndex: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist(null).as('loadedEncounterIndex'), + loadedLastEncounter: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist(false).as('loadedLastEncounter'), + savedParties: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('savedParties'), sources: {}, enabledSources: [], allMonsters: [], @@ -9236,23 +9239,23 @@ function app() { monsterLookupTable: {}, environments: {}, totalPages: 1, - currentPage: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist(1).as('currentPage'), + currentPage: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist(1).as('currentPage'), pagination: [], - monstersPerPage: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist(10).as("monstersPerPage"), - encounterType: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist("random").as("encounterType"), + monstersPerPage: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist(10).as("monstersPerPage"), + encounterType: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist("random").as("encounterType"), encounterTypeSelectOpen: false, - encounterTypes: Object.fromEntries(Object.entries(_constants_js__WEBPACK_IMPORTED_MODULE_6__["default"].ENCOUNTER_TYPES).map(function (entry) { + encounterTypes: Object.fromEntries(Object.entries(_constants__WEBPACK_IMPORTED_MODULE_5__["default"].ENCOUNTER_TYPES).map(function (entry) { return [entry[0], { key: entry[0], label: entry[1].name }]; })), difficultySelectOpen: false, - difficulty: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist("medium").as("difficulty"), - search: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist("").as("search"), - encounter: _encounter_js__WEBPACK_IMPORTED_MODULE_3__["default"], - sortBy: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist("name").as("sortBy"), - sortByDesc: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist(true).as("sortByDesc"), + difficulty: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist("medium").as("difficulty"), + search: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist("").as("search"), + encounter: _encounter__WEBPACK_IMPORTED_MODULE_3__["default"], + sortBy: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist("name").as("sortBy"), + sortByDesc: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist(true).as("sortByDesc"), setSortBy: function setSortBy(type) { if (type === this.sortBy) { this.sortByDesc = !this.sortByDesc; @@ -9329,7 +9332,7 @@ function app() { }, party: { - groups: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist([{ + groups: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([{ players: 4, level: 1, getsXP: true @@ -9356,7 +9359,7 @@ function app() { getGroupExperience: function getGroupExperience(acc, group) { var _acc$easy, _group$players, _acc$medium, _group$players2, _acc$hard, _group$players3, _acc$deadly, _group$players4, _acc$daily, _group$players5; - var groupExp = _constants_js__WEBPACK_IMPORTED_MODULE_6__["default"].EXP[group.level]; + var groupExp = _constants__WEBPACK_IMPORTED_MODULE_5__["default"].EXP[group.level]; return { easy: ((_acc$easy = acc === null || acc === void 0 ? void 0 : acc.easy) !== null && _acc$easy !== void 0 ? _acc$easy : 0) + groupExp.easy * ((_group$players = group === null || group === void 0 ? void 0 : group.players) !== null && _group$players !== void 0 ? _group$players : 1), medium: ((_acc$medium = acc === null || acc === void 0 ? void 0 : acc.medium) !== null && _acc$medium !== void 0 ? _acc$medium : 0) + groupExp.medium * ((_group$players2 = group === null || group === void 0 ? void 0 : group.players) !== null && _group$players2 !== void 0 ? _group$players2 : 1), @@ -9463,7 +9466,7 @@ function app() { _context.t2.formatMonsters.call(_context.t2, _context.t3); - _this2.searchPlaceholder = _lib_js__WEBPACK_IMPORTED_MODULE_5__.randomArrayElement(_this2.allMonsters).name; + _this2.searchPlaceholder = _helpers__WEBPACK_IMPORTED_MODULE_4__.randomArrayElement(_this2.allMonsters).name; if (_this2.loadedEncounterIndex !== null) { _this2.encounter.load(_this2.savedEncounters[_this2.loadedEncounterIndex]); @@ -9574,7 +9577,7 @@ function app() { while (1) { switch (_context2.prev = _context2.next) { case 0: - if (!(_this4.loadedSources.length > 0 && _lib_js__WEBPACK_IMPORTED_MODULE_5__.versionCompare(_this4.sourcesVersion, _this4.storedSourcesVersion) === 0)) { + if (!(_this4.loadedSources.length && _helpers__WEBPACK_IMPORTED_MODULE_4__.versionCompare(_this4.sourcesVersion, _this4.storedSourcesVersion) === 0)) { _context2.next = 2; break; } @@ -9630,7 +9633,7 @@ function app() { while (1) { switch (_context3.prev = _context3.next) { case 0: - if (!(_this5.loadedMonsters.length > 0 && _lib_js__WEBPACK_IMPORTED_MODULE_5__.versionCompare(_this5.storedSourcesVersion, _this5.sourcesVersion) === 0)) { + if (!(_this5.loadedSources.length && _helpers__WEBPACK_IMPORTED_MODULE_4__.versionCompare(_this5.storedSourcesVersion, _this5.sourcesVersion) === 0)) { _context3.next = 2; break; } @@ -9685,7 +9688,7 @@ function app() { var _this6 = this; this.allMonsters = data.map(function (data) { - var monster = new _monster_js__WEBPACK_IMPORTED_MODULE_7__["default"](_this6, data); + var monster = new _monster__WEBPACK_IMPORTED_MODULE_6__["default"](_this6, data); _this6.monsterLookupTable[monster.slug] = monster; return monster; }); @@ -9741,7 +9744,7 @@ function app() { return filter.min !== 0 || filter.max !== 30; case "alignment": - return filter !== _constants_js__WEBPACK_IMPORTED_MODULE_6__["default"].ALL_ALIGNMENTS; + return filter !== _constants__WEBPACK_IMPORTED_MODULE_5__["default"].ALL_ALIGNMENTS; default: return filter.length && !filter.includes('any'); @@ -9870,7 +9873,7 @@ function app() { return player.active; }).forEach(function (player, playerIndex) { data.Combatants.push({ - Id: _lib_js__WEBPACK_IMPORTED_MODULE_5__.slugify("".concat(party.name, "-").concat(player.name)), + Id: _helpers__WEBPACK_IMPORTED_MODULE_4__.slugify("".concat(party.name, "-").concat(player.name)), Name: player.name, InitiativeModifier: player.initiativeMod, InitiativeAdvantage: player.initiativeAdvantage, @@ -9913,14 +9916,14 @@ function multiSlider($el, name, options, updateCallback) { max: '30' }, options: options, - value: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist({ + value: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist({ min: '0', max: '30' }).as(name), init: function init() { var _this10 = this; - this.slider = nouislider__WEBPACK_IMPORTED_MODULE_4___default().create($el, { + this.slider = nouislider__WEBPACK_IMPORTED_MODULE_8___default().create($el, { start: [options.findIndex(function (option) { return option.value === _this10.value.min; }), options.findIndex(function (option) { @@ -9951,8 +9954,8 @@ function multiSlider($el, name, options, updateCallback) { detail: { name: "cr", value: { - min: _constants_js__WEBPACK_IMPORTED_MODULE_6__["default"].CR[this.value.min].numeric, - max: _constants_js__WEBPACK_IMPORTED_MODULE_6__["default"].CR[this.value.max].numeric + min: _constants__WEBPACK_IMPORTED_MODULE_5__["default"].CR[this.value.min].numeric, + max: _constants__WEBPACK_IMPORTED_MODULE_5__["default"].CR[this.value.max].numeric } } })); @@ -9990,7 +9993,7 @@ function multiSlider($el, name, options, updateCallback) { function multiSelect($el, name, options) { return { multiple: true, - value: alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].$persist(['any']).as(name), + value: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist(['any']).as(name), name: name, options: options, init: function init() { @@ -10069,12 +10072,13 @@ window.hotkeys = hotkeys_js__WEBPACK_IMPORTED_MODULE_2__["default"]; window.app = app; window.multiSelect = multiSelect; window.multiSlider = multiSlider; -window.noUiSlider = (nouislider__WEBPACK_IMPORTED_MODULE_4___default()); +window.noUiSlider = (nouislider__WEBPACK_IMPORTED_MODULE_8___default()); window.Choices = (choices_js__WEBPACK_IMPORTED_MODULE_1___default()); -window.tippy = tippy_js__WEBPACK_IMPORTED_MODULE_10__["default"]; -window.Alpine = alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"]; -alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].plugin(_alpinejs_persist__WEBPACK_IMPORTED_MODULE_8__["default"]); -alpinejs__WEBPACK_IMPORTED_MODULE_9__["default"].start(); +window.tippy = tippy_js__WEBPACK_IMPORTED_MODULE_11__["default"]; +window.Importer = _importer__WEBPACK_IMPORTED_MODULE_7__["default"]; +window.Alpine = alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"]; +alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].plugin(_alpinejs_persist__WEBPACK_IMPORTED_MODULE_9__["default"]); +alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].start(); /***/ }), @@ -10089,7 +10093,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); -/* harmony import */ var _lib_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./lib.js */ "./src/js/lib.js"); +/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./helpers.js */ "./src/js/helpers.js"); var CONST = { EXP: { @@ -10640,7 +10644,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) /* harmony export */ }); -/* harmony import */ var _lib_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./lib.js */ "./src/js/lib.js"); +/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./helpers.js */ "./src/js/helpers.js"); /* harmony import */ var _constants_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants.js */ "./src/js/constants.js"); function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } @@ -10723,11 +10727,11 @@ var encounter = { upperKey = _levels$i[0], upperValue = _levels$i[1]; - var _ratio = _lib_js__WEBPACK_IMPORTED_MODULE_0__.ratio(lowerValue, upperValue, exp); + var _ratio = _helpers_js__WEBPACK_IMPORTED_MODULE_0__.ratio(lowerValue, upperValue, exp); if (upperKey === "daily" && _ratio >= 0.0) { if (_ratio >= 0.2) { - return _ratio >= 1.0 ? "like " + _lib_js__WEBPACK_IMPORTED_MODULE_0__.randomArrayElement(this.insaneDifficultyStrings) : _ratio >= 0.6 ? 'extremely deadly' : "really deadly"; + return _ratio >= 1.0 ? "like " + _helpers_js__WEBPACK_IMPORTED_MODULE_0__.randomArrayElement(this.insaneDifficultyStrings) : _ratio >= 0.6 ? 'extremely deadly' : "really deadly"; } return lowerKey; @@ -10740,7 +10744,7 @@ var encounter = { } } - var ratio = _lib_js__WEBPACK_IMPORTED_MODULE_0__.ratio(0, levels[0][1], exp); + var ratio = _helpers_js__WEBPACK_IMPORTED_MODULE_0__.ratio(0, levels[0][1], exp); return ratio > 0.5 ? "like a nuisance" : "like a minor nuisance"; }, @@ -10884,13 +10888,13 @@ var encounter = { }); } - return _lib_js__WEBPACK_IMPORTED_MODULE_0__.randomArrayElement(monsterList); + return _helpers_js__WEBPACK_IMPORTED_MODULE_0__.randomArrayElement(monsterList); }, getEncounterTemplate: function getEncounterTemplate() { - var template = _lib_js__WEBPACK_IMPORTED_MODULE_0__.clone(_constants_js__WEBPACK_IMPORTED_MODULE_1__["default"].ENCOUNTER_TYPES[this.app.encounterType]); + var template = _helpers_js__WEBPACK_IMPORTED_MODULE_0__.clone(_constants_js__WEBPACK_IMPORTED_MODULE_1__["default"].ENCOUNTER_TYPES[this.app.encounterType]); if (template.samples) { - template = _lib_js__WEBPACK_IMPORTED_MODULE_0__.randomArrayElement(template.samples); + template = _helpers_js__WEBPACK_IMPORTED_MODULE_0__.randomArrayElement(template.samples); if (this.app.encounterType === "random") { template = { @@ -10911,7 +10915,7 @@ var encounter = { part = part.replaceAll("players", players); return eval(part); }); - group.count = parts.length > 1 ? _lib_js__WEBPACK_IMPORTED_MODULE_0__.randomIntBetween.apply(_lib_js__WEBPACK_IMPORTED_MODULE_0__, _toConsumableArray(parts)) : parts[0]; + group.count = parts.length > 1 ? _helpers_js__WEBPACK_IMPORTED_MODULE_0__.randomIntBetween.apply(_helpers_js__WEBPACK_IMPORTED_MODULE_0__, _toConsumableArray(parts)) : parts[0]; } return group; @@ -10964,7 +10968,7 @@ var encounter = { }); }); if (!monsterList.length) return; - group.monster = _lib_js__WEBPACK_IMPORTED_MODULE_0__.randomArrayElement(monsterList); + group.monster = _helpers_js__WEBPACK_IMPORTED_MODULE_0__.randomArrayElement(monsterList); this.saveToHistory(); }, addMonster: function addMonster(monster) { @@ -11075,7 +11079,7 @@ var encounter = { load: function load(encounter) { var _this2 = this; - var groups = _lib_js__WEBPACK_IMPORTED_MODULE_0__.clone(encounter).map(function (group) { + var groups = _helpers_js__WEBPACK_IMPORTED_MODULE_0__.clone(encounter).map(function (group) { group.monster = _this2.app.monsterLookupTable[group.monster.slug]; if (!group.monster) return false; return group; @@ -11119,10 +11123,10 @@ var encounter = { /***/ }), -/***/ "./src/js/lib.js": -/*!***********************!*\ - !*** ./src/js/lib.js ***! - \***********************/ +/***/ "./src/js/helpers.js": +/*!***************************!*\ + !*** ./src/js/helpers.js ***! + \***************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; @@ -11271,6 +11275,98 @@ function versionCompare(v1, v2, options) { return 0; } +/***/ }), + +/***/ "./src/js/importer.js": +/*!****************************!*\ + !*** ./src/js/importer.js ***! + \****************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +__webpack_require__.r(__webpack_exports__); +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ "default": () => (/* binding */ Importer) +/* harmony export */ }); +/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/regenerator */ "./node_modules/@babel/runtime/regenerator/index.js"); +/* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__); + + +function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } + +function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +var Importer = /*#__PURE__*/function () { + function Importer() { + _classCallCheck(this, Importer); + } + + _createClass(Importer, null, [{ + key: "import", + value: + /* import({ + * resourceLocator = false, + * type = 'google-sheets', + * }={}) + * + * <- Exact format needed for localStorage + * + */ + function () { + var _import2 = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee() { + var _ref, + _ref$resourceLocator, + resourceLocator, + _ref$type, + type, + results, + _args = arguments; + + return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _ref = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, _ref$resourceLocator = _ref.resourceLocator, resourceLocator = _ref$resourceLocator === void 0 ? false : _ref$resourceLocator, _ref$type = _ref.type, type = _ref$type === void 0 ? 'google-sheets' : _ref$type; + _context.next = 3; + return fetch("https://sheets.googleapis.com/v4/spreadsheets/".concat(resourceLocator, "/values/Monsters?") + new URLSearchParams({ + key: this.key + })); + + case 3: + results = _context.sent; + return _context.abrupt("return", results); + + case 5: + case "end": + return _context.stop(); + } + } + }, _callee, this); + })); + + function _import() { + return _import2.apply(this, arguments); + } + + return _import; + }() + }]); + + return Importer; +}(); + +_defineProperty(Importer, "key", 'AIzaSyASDsLebocDQEHt3-MV_a_tI8r25CHotT4'); + + + /***/ }), /***/ "./src/js/monster.js": @@ -11285,7 +11381,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ "default": () => (/* binding */ Monster) /* harmony export */ }); /* harmony import */ var _constants_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants.js */ "./src/js/constants.js"); -/* harmony import */ var _lib_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./lib.js */ "./src/js/lib.js"); +/* harmony import */ var _helpers_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers.js */ "./src/js/helpers.js"); function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } @@ -11320,7 +11416,7 @@ var Monster = /*#__PURE__*/function () { this.app = app; this.data = data; this.cr = _constants_js__WEBPACK_IMPORTED_MODULE_0__["default"].CR[this.data.cr]; - this.slug = _lib_js__WEBPACK_IMPORTED_MODULE_1__.slugify(this.data.name + '-' + this.data.sources + "-" + this.cr.string); + this.slug = _helpers_js__WEBPACK_IMPORTED_MODULE_1__.slugify(this.data.name + '-' + this.data.sources + "-" + this.cr.string); this.tags = this.data.tags ? this.data.tags.split(/\s*,\s*/).sort() : null; this.special = !!this.data.special; this.legendary = !!this.data.legendary; @@ -11349,7 +11445,7 @@ var Monster = /*#__PURE__*/function () { if (!isNaN(location)) { source.reference = _this.app.sources[book]; source.page = location; - } else if (_lib_js__WEBPACK_IMPORTED_MODULE_1__.isValidHttpUrl(location)) { + } else if (_helpers_js__WEBPACK_IMPORTED_MODULE_1__.isValidHttpUrl(location)) { source.reference = { name: book, shortname: book, diff --git a/src/index.html b/src/index.html index eac642b0..ac88a257 100644 --- a/src/index.html +++ b/src/index.html @@ -103,6 +103,7 @@
+ +
diff --git a/src/js/app.js b/src/js/app.js index b390a474..4e51aaa7 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -2,12 +2,14 @@ require('@fortawesome/fontawesome-free') import Choices from 'choices.js'; import hotkeys from 'hotkeys-js'; -import encounter from "./encounter.js"; -import noUiSlider from "nouislider"; -import * as lib from "./lib.js"; -import CONST from "./constants.js"; -import Monster from "./monster.js"; +import encounter from "./encounter"; +import * as helpers from "./helpers"; +import CONST from "./constants"; +import Monster from "./monster"; +import Importer from "./importer"; + import tippy from 'tippy.js'; +import noUiSlider from "nouislider"; import persist from '@alpinejs/persist' import Alpine from 'alpinejs' @@ -27,6 +29,7 @@ function app() { showEncounterModal: false, showPartyModal: false, showKeyboardModal: false, + showImporterModal: true, mobileEncounterTab: false, @@ -252,7 +255,7 @@ function app() { async fetchData() { this.formatSources(await this.fetchSources()); this.formatMonsters(await this.fetchMonsters()); - this.searchPlaceholder = lib.randomArrayElement(this.allMonsters).name; + this.searchPlaceholder = helpers.randomArrayElement(this.allMonsters).name; if (this.loadedEncounterIndex !== null){ this.encounter.load(this.savedEncounters[this.loadedEncounterIndex]); @@ -323,7 +326,7 @@ function app() { async fetchSources(){ - if(this.loadedSources.length > 0 && lib.versionCompare(this.sourcesVersion, this.storedSourcesVersion) === 0){ + if(this.loadedSources.length && helpers.versionCompare(this.sourcesVersion, this.storedSourcesVersion) === 0){ return this.loadedSources; } @@ -358,7 +361,7 @@ function app() { async fetchMonsters(){ - if(this.loadedMonsters.length > 0 && lib.versionCompare(this.storedSourcesVersion, this.sourcesVersion) === 0){ + if(this.loadedSources.length && helpers.versionCompare(this.storedSourcesVersion, this.sourcesVersion) === 0){ return this.loadedMonsters; } @@ -541,7 +544,7 @@ function app() { this.savedParties.forEach((party, partyIndex) => { party.players.filter(player => player.active).forEach((player, playerIndex) => { data.Combatants.push({ - Id: lib.slugify(`${party.name}-${player.name}`), + Id: helpers.slugify(`${party.name}-${player.name}`), Name: player.name, InitiativeModifier: player.initiativeMod, InitiativeAdvantage: player.initiativeAdvantage, @@ -719,6 +722,7 @@ window.multiSlider = multiSlider; window.noUiSlider = noUiSlider; window.Choices = Choices; window.tippy = tippy; +window.Importer = Importer; window.Alpine = Alpine diff --git a/src/js/constants.js b/src/js/constants.js index 09c57ea4..c1f6125c 100644 --- a/src/js/constants.js +++ b/src/js/constants.js @@ -1,4 +1,4 @@ -import * as lib from "./lib.js"; +import * as helpers from "./helpers.js"; const CONST = { diff --git a/src/js/encounter.js b/src/js/encounter.js index c0df118d..65cc1614 100644 --- a/src/js/encounter.js +++ b/src/js/encounter.js @@ -1,4 +1,4 @@ -import * as lib from "./lib.js"; +import * as helpers from "./helpers.js"; import CONST from "./constants.js"; const encounter = { @@ -60,12 +60,12 @@ const encounter = { for(let i = 1; i < levels.length; i++){ const [lowerKey, lowerValue] = levels[i-1]; const [upperKey, upperValue] = levels[i]; - const ratio = lib.ratio(lowerValue, upperValue, exp); + const ratio = helpers.ratio(lowerValue, upperValue, exp); if(upperKey === "daily" && ratio >= 0.0) { if (ratio >= 0.2) { return ratio >= 1.0 - ? "like " + lib.randomArrayElement(this.insaneDifficultyStrings) + ? "like " + helpers.randomArrayElement(this.insaneDifficultyStrings) : ratio >= 0.6 ? 'extremely deadly' : "really deadly"; } return lowerKey; @@ -77,7 +77,7 @@ const encounter = { } } - const ratio = lib.ratio(0, levels[0][1], exp); + const ratio = helpers.ratio(0, levels[0][1], exp); return ratio > 0.5 ? "like a nuisance" : "like a minor nuisance"; }, @@ -216,16 +216,16 @@ const encounter = { } - return lib.randomArrayElement(monsterList); + return helpers.randomArrayElement(monsterList); }, getEncounterTemplate() { - let template = lib.clone(CONST.ENCOUNTER_TYPES[this.app.encounterType]); + let template = helpers.clone(CONST.ENCOUNTER_TYPES[this.app.encounterType]); if (template.samples) { - template = lib.randomArrayElement(template.samples); + template = helpers.randomArrayElement(template.samples); if (this.app.encounterType === "random") { template = { subtractive: true, @@ -243,7 +243,7 @@ const encounter = { part = part.replaceAll("players", players); return eval(part); }); - group.count = parts.length > 1 ? lib.randomIntBetween(...parts) : parts[0]; + group.count = parts.length > 1 ? helpers.randomIntBetween(...parts) : parts[0]; } return group; }); @@ -293,7 +293,7 @@ const encounter = { return !this.groups.some(group => group.monster === monster); }); if (!monsterList.length) return; - group.monster = lib.randomArrayElement(monsterList); + group.monster = helpers.randomArrayElement(monsterList); this.saveToHistory(); }, @@ -389,7 +389,7 @@ const encounter = { }, load(encounter){ - const groups = lib.clone(encounter).map(group => { + const groups = helpers.clone(encounter).map(group => { group.monster = this.app.monsterLookupTable[group.monster.slug]; if (!group.monster) return false; return group; diff --git a/src/js/lib.js b/src/js/helpers.js similarity index 100% rename from src/js/lib.js rename to src/js/helpers.js diff --git a/src/js/importer.js b/src/js/importer.js new file mode 100644 index 00000000..7cf92dac --- /dev/null +++ b/src/js/importer.js @@ -0,0 +1,22 @@ +export default class Importer { + static key = 'AIzaSyASDsLebocDQEHt3-MV_a_tI8r25CHotT4'; + + /* import({ + * resourceLocator = false, + * type = 'google-sheets', + * }={}) + * + * <- Exact format needed for localStorage + * + */ + static async import({ + resourceLocator = false, + type = 'google-sheets' + } = {}) { + let results = await fetch(`https://sheets.googleapis.com/v4/spreadsheets/${resourceLocator}/values/Monsters?` + new URLSearchParams({ + key: this.key + })); + // HI! + return results; + } +} \ No newline at end of file diff --git a/src/js/monster.js b/src/js/monster.js index dce9f082..2690c767 100644 --- a/src/js/monster.js +++ b/src/js/monster.js @@ -1,5 +1,5 @@ import CONST from "./constants.js"; -import * as lib from "./lib.js"; +import * as helpers from "./helpers.js"; const regexCache = {}; let lastRegex = ""; @@ -11,7 +11,7 @@ export default class Monster { this.data = data; this.cr = CONST.CR[this.data.cr]; - this.slug = lib.slugify(this.data.name+'-'+this.data.sources+"-"+this.cr.string); + this.slug = helpers.slugify(this.data.name+'-'+this.data.sources+"-"+this.cr.string); this.tags = this.data.tags ? this.data.tags.split(/\s*,\s*/).sort() : null; @@ -48,7 +48,7 @@ export default class Monster { if (!isNaN(location)) { source.reference = this.app.sources[book]; source.page = location; - } else if (lib.isValidHttpUrl(location)) { + } else if (helpers.isValidHttpUrl(location)) { source.reference = { name: book, shortname: book, From cc5bf19b7636ef20ed951aaae9e2909561080513 Mon Sep 17 00:00:00 2001 From: V13Axel Date: Thu, 12 May 2022 22:08:58 -0400 Subject: [PATCH 03/33] Mostly functional importer --- docs/css/styles.css | 30 +++++++++++ docs/index.html | 125 ++++++++++++++++++++++++++++++++++++++++---- docs/js/app.js | 109 ++++++++++++++++++++++++++++++++------ src/index.html | 125 ++++++++++++++++++++++++++++++++++++++++---- src/js/app.js | 16 +++--- src/js/importer.js | 63 +++++++++++++++++++--- 6 files changed, 420 insertions(+), 48 deletions(-) diff --git a/docs/css/styles.css b/docs/css/styles.css index 93f6cf99..760d25bc 100644 --- a/docs/css/styles.css +++ b/docs/css/styles.css @@ -8580,6 +8580,9 @@ input[type=text]:disabled{ .col-span-6{ grid-column: span 6 / span 6; } +.col-span-5{ + grid-column: span 5 / span 5; +} .mx-auto{ margin-left: auto; margin-right: auto; @@ -8604,6 +8607,10 @@ input[type=text]:disabled{ margin-top: 0.5rem; margin-bottom: 0.5rem; } +.-my-2{ + margin-top: -0.5rem; + margin-bottom: -0.5rem; +} .ml-1{ margin-left: 0.25rem; } @@ -9380,6 +9387,9 @@ input[type=text]:disabled{ .pr-8{ padding-right: 2rem; } +.pl-4{ + padding-left: 1rem; +} .pt-0\.5{ padding-top: 0.125rem; } @@ -9395,6 +9405,9 @@ input[type=text]:disabled{ .text-right{ text-align: right; } +.align-middle{ + vertical-align: middle; +} .align-bottom{ vertical-align: bottom; } @@ -10618,6 +10631,10 @@ body .choices__input:focus{ --tw-bg-opacity: 1; background-color: rgb(31 41 55 / var(--tw-bg-opacity)); } +.dark .dark\:even\:bg-gray-600:nth-child(even){ + --tw-bg-opacity: 1; + background-color: rgb(75 85 99 / var(--tw-bg-opacity)); +} .dark .dark\:hover\:border-gray-600:hover{ --tw-border-opacity: 1; border-color: rgb(75 85 99 / var(--tw-border-opacity)); @@ -10787,6 +10804,10 @@ body .choices__input:focus{ max-width: 42rem; } + .sm\:max-w-4xl{ + max-width: 56rem; + } + .sm\:translate-y-0{ --tw-translate-y: 0px; transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)); @@ -11026,6 +11047,11 @@ body .choices__input:focus{ margin-bottom: -1px; } + .lg\:-mx-8{ + margin-left: -2rem; + margin-right: -2rem; + } + .lg\:ml-6{ margin-left: 1.5rem; } @@ -11099,6 +11125,10 @@ body .choices__input:focus{ .lg\:pl-0{ padding-left: 0px; } + + .lg\:pl-8{ + padding-left: 2rem; + } } @media (min-width: 1536px){ diff --git a/docs/index.html b/docs/index.html index ac88a257..26f3ad94 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1327,7 +1327,7 @@

Keybo -
Keybo
-

Keyboard Shortcuts

+

Import Custom Monsters

-
+
- + +
+ +
+
New Sources
+ +
+
+
+
+
+ + + + + + + + + + + + +
Name
+
+
+
+
+
+ +
New Monsters (Preview)
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + +
NameSize
+ And more. +
+
+
+
+
+
+ +
diff --git a/docs/js/app.js b/docs/js/app.js index 2ac772f8..66a75f2b 100644 --- a/docs/js/app.js +++ b/docs/js/app.js @@ -9226,7 +9226,9 @@ function app() { searchPlaceholder: "", nonDefaultFiltersCount: 0, loadedSources: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('sources'), + importedSources: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('importedSources'), loadedMonsters: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('monsters'), + importedMonsters: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('importedMonsters'), encounterHistory: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('encounterHistory'), savedEncounters: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist([]).as('savedEncounters'), loadedEncounterIndex: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist(null).as('loadedEncounterIndex'), @@ -9682,26 +9684,26 @@ function app() { this.sources = data.reduce(function (acc, source) { acc[source.name] = source; return acc; - }, {}); + }, this.sources); }, formatMonsters: function formatMonsters(data) { var _this6 = this; - this.allMonsters = data.map(function (data) { + this.allMonsters = this.allMonsters.concat(data.map(function (data) { var monster = new _monster__WEBPACK_IMPORTED_MODULE_6__["default"](_this6, data); _this6.monsterLookupTable[monster.slug] = monster; return monster; - }); - this.environments = Object.values(this.environments); - this.environments.sort(function (a, b) { + })); + var environments = Object.values(this.environments); + environments.sort(function (a, b) { return a.value > b.label ? -1 : 1; }); - this.environments.unshift({ + environments.unshift({ value: "any", label: "Any Environment" }); window.dispatchEvent(new CustomEvent('set-environments', { - detail: this.environments + detail: environments })); }, filterMonsters: function filterMonsters() { @@ -11327,7 +11329,6 @@ var Importer = /*#__PURE__*/function () { resourceLocator, _ref$type, type, - results, _args = arguments; return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee$(_context) { @@ -11335,16 +11336,10 @@ var Importer = /*#__PURE__*/function () { switch (_context.prev = _context.next) { case 0: _ref = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, _ref$resourceLocator = _ref.resourceLocator, resourceLocator = _ref$resourceLocator === void 0 ? false : _ref$resourceLocator, _ref$type = _ref.type, type = _ref$type === void 0 ? 'google-sheets' : _ref$type; - _context.next = 3; - return fetch("https://sheets.googleapis.com/v4/spreadsheets/".concat(resourceLocator, "/values/Monsters?") + new URLSearchParams({ - key: this.key - })); + console.log(type, this.loaders[type]); + return _context.abrupt("return", this.loaders[type](resourceLocator)); case 3: - results = _context.sent; - return _context.abrupt("return", results); - - case 5: case "end": return _context.stop(); } @@ -11363,7 +11358,87 @@ var Importer = /*#__PURE__*/function () { return Importer; }(); -_defineProperty(Importer, "key", 'AIzaSyASDsLebocDQEHt3-MV_a_tI8r25CHotT4'); +_defineProperty(Importer, "loaders", { + 'google-sheets': function () { + var _googleSheets = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee2(resourceLocator) { + var monsters, sources; + return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + _context2.next = 2; + return fetch("https://sheets.googleapis.com/v4/spreadsheets/".concat(resourceLocator, "/values/Monsters?") + new URLSearchParams({ + key: Importer.key + })).then(function (response) { + return response.json(); + }).then(function (jsonifiedBody) { + var headers = jsonifiedBody.values.splice(0, 1)[0]; + return jsonifiedBody.values.map(function (item) { + return { + "name": item[headers.indexOf("name")], + "cr": item[headers.indexOf("cr")], + "size": item[headers.indexOf("size")], + "type": item[headers.indexOf("type")], + "tags": item[headers.indexOf("tags")], + "section": item[headers.indexOf("section")], + "alignment": item[headers.indexOf("alignment")], + "environment": item[headers.indexOf("environment")], + "ac": item[headers.indexOf("ac")], + "hp": item[headers.indexOf("hp")], + "init": item[headers.indexOf("init")], + "lair": item[headers.indexOf("lair?")], + "legendary": item[headers.indexOf("legendary?")], + "unique": item[headers.indexOf("unique?")], + "sources": item[headers.indexOf("sources")] + }; + }); + })["catch"](function (err) { + return console.log(err); + }); + + case 2: + monsters = _context2.sent; + _context2.next = 5; + return fetch("https://sheets.googleapis.com/v4/spreadsheets/".concat(resourceLocator, "/values/Sources?") + new URLSearchParams({ + key: Importer.key + })).then(function (response) { + return response.json(); + }).then(function (jsonifiedBody) { + var headers = jsonifiedBody.values.splice(0, 1)[0]; + return jsonifiedBody.values.map(function (item) { + return { + "name": item[headers.indexOf("name")], + "type": 'Custom', + "short_name": item[headers.indexOf("short name")], + "link": item[headers.indexOf("link")] + }; + }); + })["catch"](function (err) { + return console.log(err); + }); + + case 5: + sources = _context2.sent; + return _context2.abrupt("return", { + sources: sources, + monsters: monsters + }); + + case 7: + case "end": + return _context2.stop(); + } + } + }, _callee2); + })); + + function googleSheets(_x) { + return _googleSheets.apply(this, arguments); + } + + return googleSheets; + }() +}); diff --git a/src/index.html b/src/index.html index ac88a257..26f3ad94 100644 --- a/src/index.html +++ b/src/index.html @@ -1327,7 +1327,7 @@

Keybo -
Keybo
-

Keyboard Shortcuts

+

Import Custom Monsters

-
+
- + +
+ +
+
New Sources
+ +
+
+
+
+
+ + + + + + + + + + + + +
Name
+
+
+
+
+
+ +
New Monsters (Preview)
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + +
NameSize
+ And more. +
+
+
+
+
+
+ +
diff --git a/src/js/app.js b/src/js/app.js index 4e51aaa7..a23b88f7 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -38,7 +38,9 @@ function app() { nonDefaultFiltersCount: 0, loadedSources: Alpine.$persist([]).as('sources'), + importedSources: Alpine.$persist([]).as('importedSources'), loadedMonsters: Alpine.$persist([]).as('monsters'), + importedMonsters: Alpine.$persist([]).as('importedMonsters'), encounterHistory: Alpine.$persist([]).as('encounterHistory'), savedEncounters: Alpine.$persist([]).as('savedEncounters'), @@ -396,21 +398,21 @@ function app() { this.sources = data.reduce((acc, source) => { acc[source.name] = source; return acc; - }, {}); + }, this.sources); }, formatMonsters(data){ - this.allMonsters = data.map(data => { + this.allMonsters = this.allMonsters.concat(data.map(data => { const monster = new Monster(this, data); this.monsterLookupTable[monster.slug] = monster; return monster; - }); - this.environments = Object.values(this.environments); - this.environments.sort((a, b) => { + })); + let environments = Object.values(this.environments); + environments.sort((a, b) => { return a.value > b.label ? -1 : 1; }); - this.environments.unshift({ value: "any", label: "Any Environment" }); - window.dispatchEvent(new CustomEvent('set-environments', { detail: this.environments })); + environments.unshift({ value: "any", label: "Any Environment" }); + window.dispatchEvent(new CustomEvent('set-environments', { detail: environments })); }, filterMonsters(crString = false, filterCallback = () => { return true; }){ diff --git a/src/js/importer.js b/src/js/importer.js index 7cf92dac..ee432add 100644 --- a/src/js/importer.js +++ b/src/js/importer.js @@ -1,5 +1,58 @@ export default class Importer { - static key = 'AIzaSyASDsLebocDQEHt3-MV_a_tI8r25CHotT4'; + + + static loaders = { + 'google-sheets': async (resourceLocator) => { + let monsters = await fetch(`https://sheets.googleapis.com/v4/spreadsheets/${resourceLocator}/values/Monsters?` + new URLSearchParams({ + key: this.key + })) + .then(response => response.json()) + .then(jsonifiedBody => { + let headers = jsonifiedBody.values.splice(0, 1)[0]; + + return jsonifiedBody.values.map((item) => ({ + "name": item[headers.indexOf("name")], + "cr": item[headers.indexOf("cr")], + "size": item[headers.indexOf("size")], + "type": item[headers.indexOf("type")], + "tags": item[headers.indexOf("tags")], + "section": item[headers.indexOf("section")], + "alignment": item[headers.indexOf("alignment")], + "environment": item[headers.indexOf("environment")], + "ac": item[headers.indexOf("ac")], + "hp": item[headers.indexOf("hp")], + "init": item[headers.indexOf("init")], + "lair": item[headers.indexOf("lair?")], + "legendary": item[headers.indexOf("legendary?")], + "unique": item[headers.indexOf("unique?")], + "sources": item[headers.indexOf("sources")], + })); + }) + .catch( + err => console.log(err) + ); + + let sources = await fetch(`https://sheets.googleapis.com/v4/spreadsheets/${resourceLocator}/values/Sources?` + new URLSearchParams({ + key: this.key + })) + .then(response => response.json()) + .then(jsonifiedBody => { + let headers = jsonifiedBody.values.splice(0, 1)[0]; + + return jsonifiedBody.values.map((item) => ({ + "name": item[headers.indexOf("name")], + "type": 'Custom', + "short_name": item[headers.indexOf("short name")], + "link": item[headers.indexOf("link")], + })); + }) + .catch( + err => console.log(err) + ); + + return {sources, monsters}; + } + } /* import({ * resourceLocator = false, @@ -13,10 +66,8 @@ export default class Importer { resourceLocator = false, type = 'google-sheets' } = {}) { - let results = await fetch(`https://sheets.googleapis.com/v4/spreadsheets/${resourceLocator}/values/Monsters?` + new URLSearchParams({ - key: this.key - })); - // HI! - return results; + console.log(type, this.loaders[type]); + + return this.loaders[type](resourceLocator); } } \ No newline at end of file From 7521bcdcb4c32546089aaa7651989618da729fa0 Mon Sep 17 00:00:00 2001 From: V13Axel Date: Thu, 12 May 2022 22:36:54 -0400 Subject: [PATCH 04/33] short_name -> shortname --- docs/js/app.js | 9 ++++++++- src/js/app.js | 7 +++++++ src/js/importer.js | 2 +- src/js/monster.js | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/js/app.js b/docs/js/app.js index 66a75f2b..66344912 100644 --- a/docs/js/app.js +++ b/docs/js/app.js @@ -9998,6 +9998,7 @@ function multiSelect($el, name, options) { value: alpinejs__WEBPACK_IMPORTED_MODULE_10__["default"].$persist(['any']).as(name), name: name, options: options, + completedSetup: false, init: function init() { var _this11 = this; @@ -10009,6 +10010,10 @@ function multiSelect($el, name, options) { setUp: function setUp() { var _this12 = this; + if (this.completedSetup) { + return; + } + var choices = new (choices_js__WEBPACK_IMPORTED_MODULE_1___default())($el, { allowHTML: true, removeItemButton: true @@ -10053,6 +10058,7 @@ function multiSelect($el, name, options) { return refreshChoices(); }); this.onFiltersChanged(); + this.completedSetup = true; }, onFiltersChanged: function onFiltersChanged() { window.dispatchEvent(new CustomEvent('filters-changed', { @@ -11409,7 +11415,7 @@ _defineProperty(Importer, "loaders", { return { "name": item[headers.indexOf("name")], "type": 'Custom', - "short_name": item[headers.indexOf("short name")], + "shortname": item[headers.indexOf("short name")], "link": item[headers.indexOf("link")] }; }); @@ -11531,6 +11537,7 @@ var Monster = /*#__PURE__*/function () { source.fullText = source.reference.name + (source.page ? ' p.' + source.page : ''); return source; }); + console.log(this.sources); this.sources.sort(function (a, b) { return a.fullText.localeCompare(b.fullText, 'en', { sensitivity: "base" diff --git a/src/js/app.js b/src/js/app.js index a23b88f7..2fa734d9 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -657,6 +657,7 @@ function multiSelect($el, name, options) { value: Alpine.$persist(['any']).as(name), name: name, options: options, + completedSetup: false, init() { if(!options.length) return; this.$nextTick(() => { @@ -664,6 +665,10 @@ function multiSelect($el, name, options) { }) }, setUp(){ + if(this.completedSetup) { + return; + } + let choices = new Choices($el, { allowHTML: true, removeItemButton: true @@ -702,6 +707,8 @@ function multiSelect($el, name, options) { this.$watch('options', () => refreshChoices()) this.onFiltersChanged(); + + this.completedSetup = true; }, onFiltersChanged() { window.dispatchEvent(new CustomEvent('filters-changed', { detail: { diff --git a/src/js/importer.js b/src/js/importer.js index ee432add..4d14a369 100644 --- a/src/js/importer.js +++ b/src/js/importer.js @@ -42,7 +42,7 @@ export default class Importer { return jsonifiedBody.values.map((item) => ({ "name": item[headers.indexOf("name")], "type": 'Custom', - "short_name": item[headers.indexOf("short name")], + "shortname": item[headers.indexOf("short name")], "link": item[headers.indexOf("link")], })); }) diff --git a/src/js/monster.js b/src/js/monster.js index 2690c767..03172089 100644 --- a/src/js/monster.js +++ b/src/js/monster.js @@ -60,6 +60,8 @@ export default class Monster { return source; }); + console.log(this.sources); + this.sources.sort((a, b) => a.fullText.localeCompare(b.fullText, 'en', { sensitivity: "base" })) } From 750610b7985eafb00f52849437ec71745a214aca Mon Sep 17 00:00:00 2001 From: V13Axel Date: Thu, 12 May 2022 22:37:52 -0400 Subject: [PATCH 05/33] Remove debugt --- docs/js/app.js | 1 - src/js/monster.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/docs/js/app.js b/docs/js/app.js index 66344912..be4562bc 100644 --- a/docs/js/app.js +++ b/docs/js/app.js @@ -11537,7 +11537,6 @@ var Monster = /*#__PURE__*/function () { source.fullText = source.reference.name + (source.page ? ' p.' + source.page : ''); return source; }); - console.log(this.sources); this.sources.sort(function (a, b) { return a.fullText.localeCompare(b.fullText, 'en', { sensitivity: "base" diff --git a/src/js/monster.js b/src/js/monster.js index 03172089..2690c767 100644 --- a/src/js/monster.js +++ b/src/js/monster.js @@ -60,8 +60,6 @@ export default class Monster { return source; }); - console.log(this.sources); - this.sources.sort((a, b) => a.fullText.localeCompare(b.fullText, 'en', { sensitivity: "base" })) } From 5f28a77fc88ba6ecf458c07e4e289b90cabfbff2 Mon Sep 17 00:00:00 2001 From: V13Axel Date: Thu, 12 May 2022 22:43:22 -0400 Subject: [PATCH 06/33] Enable source upon import --- docs/index.html | 7 +++++++ docs/js/app.js | 3 ++- src/index.html | 7 +++++++ src/js/importer.js | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index 26f3ad94..7f041e56 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1355,8 +1355,15 @@

Keybo this.step = 2; }, finishImport() { + importedSources.push(this.stagedSources) formatSources(this.stagedSources); + this.stagedSources = []; + + importedMonsters.push(this.stagedMonsters) formatMonsters(this.stagedMonsters); + this.stagedMonsters = []; + + showImporterModal = false; } }">
diff --git a/docs/js/app.js b/docs/js/app.js index be4562bc..f6b21c40 100644 --- a/docs/js/app.js +++ b/docs/js/app.js @@ -11416,7 +11416,8 @@ _defineProperty(Importer, "loaders", { "name": item[headers.indexOf("name")], "type": 'Custom', "shortname": item[headers.indexOf("short name")], - "link": item[headers.indexOf("link")] + "link": item[headers.indexOf("link")], + "enabled": true }; }); })["catch"](function (err) { diff --git a/src/index.html b/src/index.html index 26f3ad94..7f041e56 100644 --- a/src/index.html +++ b/src/index.html @@ -1355,8 +1355,15 @@

Keybo this.step = 2; }, finishImport() { + importedSources.push(this.stagedSources) formatSources(this.stagedSources); + this.stagedSources = []; + + importedMonsters.push(this.stagedMonsters) formatMonsters(this.stagedMonsters); + this.stagedMonsters = []; + + showImporterModal = false; } }">
diff --git a/src/js/importer.js b/src/js/importer.js index 4d14a369..3164c2ed 100644 --- a/src/js/importer.js +++ b/src/js/importer.js @@ -44,6 +44,7 @@ export default class Importer { "type": 'Custom', "shortname": item[headers.indexOf("short name")], "link": item[headers.indexOf("link")], + "enabled": true, })); }) .catch( From 3defbfaef2dedf5d82c6c6960f517f20a8ba7937 Mon Sep 17 00:00:00 2001 From: V13Axel Date: Thu, 12 May 2022 22:50:10 -0400 Subject: [PATCH 07/33] Fix short name in preview --- docs/index.html | 5 ++++- docs/js/app.js | 3 +-- src/index.html | 5 ++++- src/js/importer.js | 2 -- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/index.html b/docs/index.html index 7f041e56..7428f6c1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1363,6 +1363,9 @@

Keybo formatMonsters(this.stagedMonsters); this.stagedMonsters = []; + dispatchEvent(new CustomEvent('notification', {detail: {title: 'Import complete!', body: 'Your new source(s) have been imported'}})); + + this.step = 1; showImporterModal = false; } }"> @@ -1406,7 +1409,7 @@

Impor - + diff --git a/docs/js/app.js b/docs/js/app.js index f6b21c40..904a27e9 100644 --- a/docs/js/app.js +++ b/docs/js/app.js @@ -11342,10 +11342,9 @@ var Importer = /*#__PURE__*/function () { switch (_context.prev = _context.next) { case 0: _ref = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, _ref$resourceLocator = _ref.resourceLocator, resourceLocator = _ref$resourceLocator === void 0 ? false : _ref$resourceLocator, _ref$type = _ref.type, type = _ref$type === void 0 ? 'google-sheets' : _ref$type; - console.log(type, this.loaders[type]); return _context.abrupt("return", this.loaders[type](resourceLocator)); - case 3: + case 2: case "end": return _context.stop(); } diff --git a/src/index.html b/src/index.html index 7f041e56..7428f6c1 100644 --- a/src/index.html +++ b/src/index.html @@ -1363,6 +1363,9 @@

Keybo formatMonsters(this.stagedMonsters); this.stagedMonsters = []; + dispatchEvent(new CustomEvent('notification', {detail: {title: 'Import complete!', body: 'Your new source(s) have been imported'}})); + + this.step = 1; showImporterModal = false; } }"> @@ -1406,7 +1409,7 @@

Impor - + diff --git a/src/js/importer.js b/src/js/importer.js index 3164c2ed..3a2ee435 100644 --- a/src/js/importer.js +++ b/src/js/importer.js @@ -67,8 +67,6 @@ export default class Importer { resourceLocator = false, type = 'google-sheets' } = {}) { - console.log(type, this.loaders[type]); - return this.loaders[type](resourceLocator); } } \ No newline at end of file From 15c6331db50b7b2f1a041eea363db222ca0d3a4c Mon Sep 17 00:00:00 2001 From: V13Axel Date: Thu, 12 May 2022 23:03:44 -0400 Subject: [PATCH 08/33] make the import button less goofy --- docs/css/styles.css | 3 +++ docs/index.html | 2 +- src/index.html | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/css/styles.css b/docs/css/styles.css index 760d25bc..2c95b4f2 100644 --- a/docs/css/styles.css +++ b/docs/css/styles.css @@ -8583,6 +8583,9 @@ input[type=text]:disabled{ .col-span-5{ grid-column: span 5 / span 5; } +.float-right{ + float: right; +} .mx-auto{ margin-left: auto; margin-right: auto; diff --git a/docs/index.html b/docs/index.html index 7428f6c1..265bb652 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1480,7 +1480,7 @@

Impor

- +

diff --git a/src/index.html b/src/index.html index 7428f6c1..265bb652 100644 --- a/src/index.html +++ b/src/index.html @@ -1480,7 +1480,7 @@

Impor

- +
From 8ea2be00138fc76e969fa4d3d6ecee98718a066f Mon Sep 17 00:00:00 2001 From: Haxxer Date: Fri, 13 May 2022 13:50:13 +0100 Subject: [PATCH 09/33] JSON loaders, babeeyyyyy --- docs/css/styles.css | 10 -- docs/index.html | 7 +- docs/js/app.js | 234 +++++++++++++++++++++++++++++--------------- src/index.html | 7 +- src/js/app.js | 4 + src/js/importer.js | 137 +++++++++++++++----------- 6 files changed, 249 insertions(+), 150 deletions(-) diff --git a/docs/css/styles.css b/docs/css/styles.css index 2c95b4f2..efe8a21e 100644 --- a/docs/css/styles.css +++ b/docs/css/styles.css @@ -8580,9 +8580,6 @@ input[type=text]:disabled{ .col-span-6{ grid-column: span 6 / span 6; } -.col-span-5{ - grid-column: span 5 / span 5; -} .float-right{ float: right; } @@ -9390,9 +9387,6 @@ input[type=text]:disabled{ .pr-8{ padding-right: 2rem; } -.pl-4{ - padding-left: 1rem; -} .pt-0\.5{ padding-top: 0.125rem; } @@ -11128,10 +11122,6 @@ body .choices__input:focus{ .lg\:pl-0{ padding-left: 0px; } - - .lg\:pl-8{ - padding-left: 2rem; - } } @media (min-width: 1536px){ diff --git a/docs/index.html b/docs/index.html index 265bb652..f661e5df 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1339,7 +1339,7 @@

Keybo
Keybo this.step = 2; }, finishImport() { - importedSources.push(this.stagedSources) + importedSources = importedSources.push(this.stagedSources) formatSources(this.stagedSources); this.stagedSources = []; - importedMonsters.push(this.stagedMonsters) + importedMonsters = importedMonsters.concat(this.stagedMonsters) formatMonsters(this.stagedMonsters); this.stagedMonsters = []; @@ -1383,6 +1383,7 @@

Impor +

diff --git a/docs/js/app.js b/docs/js/app.js index 904a27e9..832b9ece 100644 --- a/docs/js/app.js +++ b/docs/js/app.js @@ -9459,15 +9459,19 @@ function app() { _context.t0.formatSources.call(_context.t0, _context.t1); + _this2.formatSources(_this2.importedSources); + _context.t2 = _this2; - _context.next = 8; + _context.next = 9; return _this2.fetchMonsters(); - case 8: + case 9: _context.t3 = _context.sent; _context.t2.formatMonsters.call(_context.t2, _context.t3); + _this2.formatMonsters(_this2.importedMonsters); + _this2.searchPlaceholder = _helpers__WEBPACK_IMPORTED_MODULE_4__.randomArrayElement(_this2.allMonsters).name; if (_this2.loadedEncounterIndex !== null) { @@ -9476,7 +9480,7 @@ function app() { _this2.encounter.load(_this2.encounterHistory[_this2.encounterHistory.length - 1]); } - case 12: + case 14: case "end": return _context.stop(); } @@ -11358,92 +11362,164 @@ var Importer = /*#__PURE__*/function () { return _import; }() - }]); + }, { + key: "_importJsonFile", + value: function () { + var _importJsonFile2 = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee2(resourceLocator) { + return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + return _context2.abrupt("return", new Promise(function (resolve, reject) { + var reader = new FileReader(); + reader.addEventListener('load', function () { + try { + var data = JSON.parse(reader.result); + resolve(data); + } catch (err) { + console.error(err); + reject(err); + } + }); + reader.readAsText(resourceLocator); + })); - return Importer; -}(); + case 1: + case "end": + return _context2.stop(); + } + } + }, _callee2); + })); -_defineProperty(Importer, "loaders", { - 'google-sheets': function () { - var _googleSheets = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee2(resourceLocator) { - var monsters, sources; - return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee2$(_context2) { - while (1) { - switch (_context2.prev = _context2.next) { - case 0: - _context2.next = 2; - return fetch("https://sheets.googleapis.com/v4/spreadsheets/".concat(resourceLocator, "/values/Monsters?") + new URLSearchParams({ - key: Importer.key - })).then(function (response) { - return response.json(); - }).then(function (jsonifiedBody) { - var headers = jsonifiedBody.values.splice(0, 1)[0]; - return jsonifiedBody.values.map(function (item) { - return { - "name": item[headers.indexOf("name")], - "cr": item[headers.indexOf("cr")], - "size": item[headers.indexOf("size")], - "type": item[headers.indexOf("type")], - "tags": item[headers.indexOf("tags")], - "section": item[headers.indexOf("section")], - "alignment": item[headers.indexOf("alignment")], - "environment": item[headers.indexOf("environment")], - "ac": item[headers.indexOf("ac")], - "hp": item[headers.indexOf("hp")], - "init": item[headers.indexOf("init")], - "lair": item[headers.indexOf("lair?")], - "legendary": item[headers.indexOf("legendary?")], - "unique": item[headers.indexOf("unique?")], - "sources": item[headers.indexOf("sources")] - }; + function _importJsonFile(_x) { + return _importJsonFile2.apply(this, arguments); + } + + return _importJsonFile; + }() + }, { + key: "_importJson", + value: function () { + var _importJson2 = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee3(resourceLocator) { + return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee3$(_context3) { + while (1) { + switch (_context3.prev = _context3.next) { + case 0: + _context3.prev = 0; + return _context3.abrupt("return", JSON.parse(resourceLocator)); + + case 4: + _context3.prev = 4; + _context3.t0 = _context3["catch"](0); + console.error(_context3.t0); + return _context3.abrupt("return", false); + + case 8: + case "end": + return _context3.stop(); + } + } + }, _callee3, null, [[0, 4]]); + })); + + function _importJson(_x2) { + return _importJson2.apply(this, arguments); + } + + return _importJson; + }() + }, { + key: "_importGoogleSheets", + value: function () { + var _importGoogleSheets2 = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().mark(function _callee4(resourceLocator) { + var monsters, sources; + return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default().wrap(function _callee4$(_context4) { + while (1) { + switch (_context4.prev = _context4.next) { + case 0: + _context4.next = 2; + return fetch("https://sheets.googleapis.com/v4/spreadsheets/".concat(resourceLocator, "/values/Monsters?") + new URLSearchParams({ + key: this.key + })).then(function (response) { + return response.json(); + }).then(function (jsonifiedBody) { + var headers = jsonifiedBody.values.splice(0, 1)[0]; + return jsonifiedBody.values.map(function (item) { + return { + "name": item[headers.indexOf("name")], + "cr": item[headers.indexOf("cr")], + "size": item[headers.indexOf("size")], + "type": item[headers.indexOf("type")], + "tags": item[headers.indexOf("tags")], + "section": item[headers.indexOf("section")], + "alignment": item[headers.indexOf("alignment")], + "environment": item[headers.indexOf("environment")], + "ac": item[headers.indexOf("ac")], + "hp": item[headers.indexOf("hp")], + "init": item[headers.indexOf("init")], + "lair": item[headers.indexOf("lair?")], + "legendary": item[headers.indexOf("legendary?")], + "unique": item[headers.indexOf("unique?")], + "sources": item[headers.indexOf("sources")] + }; + }); + })["catch"](function (err) { + return console.error(err); }); - })["catch"](function (err) { - return console.log(err); - }); - case 2: - monsters = _context2.sent; - _context2.next = 5; - return fetch("https://sheets.googleapis.com/v4/spreadsheets/".concat(resourceLocator, "/values/Sources?") + new URLSearchParams({ - key: Importer.key - })).then(function (response) { - return response.json(); - }).then(function (jsonifiedBody) { - var headers = jsonifiedBody.values.splice(0, 1)[0]; - return jsonifiedBody.values.map(function (item) { - return { - "name": item[headers.indexOf("name")], - "type": 'Custom', - "shortname": item[headers.indexOf("short name")], - "link": item[headers.indexOf("link")], - "enabled": true - }; + case 2: + monsters = _context4.sent; + _context4.next = 5; + return fetch("https://sheets.googleapis.com/v4/spreadsheets/".concat(resourceLocator, "/values/Sources?") + new URLSearchParams({ + key: this.key + })).then(function (response) { + return response.json(); + }).then(function (jsonifiedBody) { + var headers = jsonifiedBody.values.splice(0, 1)[0]; + return jsonifiedBody.values.map(function (item) { + return { + "name": item[headers.indexOf("name")], + "type": 'Custom', + "shortname": item[headers.indexOf("short name")], + "link": item[headers.indexOf("link")], + "enabled": true + }; + }); + })["catch"](function (err) { + return console.error(err); }); - })["catch"](function (err) { - return console.log(err); - }); - case 5: - sources = _context2.sent; - return _context2.abrupt("return", { - sources: sources, - monsters: monsters - }); + case 5: + sources = _context4.sent; + return _context4.abrupt("return", { + sources: sources, + monsters: monsters + }); - case 7: - case "end": - return _context2.stop(); + case 7: + case "end": + return _context4.stop(); + } } - } - }, _callee2); - })); + }, _callee4, this); + })); - function googleSheets(_x) { - return _googleSheets.apply(this, arguments); - } + function _importGoogleSheets(_x3) { + return _importGoogleSheets2.apply(this, arguments); + } + + return _importGoogleSheets; + }() + }]); - return googleSheets; - }() + return Importer; +}(); + +_defineProperty(Importer, "loaders", { + 'google-sheets': Importer._importGoogleSheets, + 'json-raw': Importer._importJson, + 'json-file': Importer._importJsonFile }); diff --git a/src/index.html b/src/index.html index 265bb652..f661e5df 100644 --- a/src/index.html +++ b/src/index.html @@ -1339,7 +1339,7 @@

Keybo
Keybo this.step = 2; }, finishImport() { - importedSources.push(this.stagedSources) + importedSources = importedSources.push(this.stagedSources) formatSources(this.stagedSources); this.stagedSources = []; - importedMonsters.push(this.stagedMonsters) + importedMonsters = importedMonsters.concat(this.stagedMonsters) formatMonsters(this.stagedMonsters); this.stagedMonsters = []; @@ -1383,6 +1383,7 @@

Impor +

diff --git a/src/js/app.js b/src/js/app.js index 2fa734d9..70b26b0b 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -256,7 +256,11 @@ function app() { async fetchData() { this.formatSources(await this.fetchSources()); + this.formatSources(this.importedSources); + this.formatMonsters(await this.fetchMonsters()); + this.formatMonsters(this.importedMonsters); + this.searchPlaceholder = helpers.randomArrayElement(this.allMonsters).name; if (this.loadedEncounterIndex !== null){ diff --git a/src/js/importer.js b/src/js/importer.js index 3a2ee435..4d01bc92 100644 --- a/src/js/importer.js +++ b/src/js/importer.js @@ -2,57 +2,9 @@ export default class Importer { static loaders = { - 'google-sheets': async (resourceLocator) => { - let monsters = await fetch(`https://sheets.googleapis.com/v4/spreadsheets/${resourceLocator}/values/Monsters?` + new URLSearchParams({ - key: this.key - })) - .then(response => response.json()) - .then(jsonifiedBody => { - let headers = jsonifiedBody.values.splice(0, 1)[0]; - - return jsonifiedBody.values.map((item) => ({ - "name": item[headers.indexOf("name")], - "cr": item[headers.indexOf("cr")], - "size": item[headers.indexOf("size")], - "type": item[headers.indexOf("type")], - "tags": item[headers.indexOf("tags")], - "section": item[headers.indexOf("section")], - "alignment": item[headers.indexOf("alignment")], - "environment": item[headers.indexOf("environment")], - "ac": item[headers.indexOf("ac")], - "hp": item[headers.indexOf("hp")], - "init": item[headers.indexOf("init")], - "lair": item[headers.indexOf("lair?")], - "legendary": item[headers.indexOf("legendary?")], - "unique": item[headers.indexOf("unique?")], - "sources": item[headers.indexOf("sources")], - })); - }) - .catch( - err => console.log(err) - ); - - let sources = await fetch(`https://sheets.googleapis.com/v4/spreadsheets/${resourceLocator}/values/Sources?` + new URLSearchParams({ - key: this.key - })) - .then(response => response.json()) - .then(jsonifiedBody => { - let headers = jsonifiedBody.values.splice(0, 1)[0]; - - return jsonifiedBody.values.map((item) => ({ - "name": item[headers.indexOf("name")], - "type": 'Custom', - "shortname": item[headers.indexOf("short name")], - "link": item[headers.indexOf("link")], - "enabled": true, - })); - }) - .catch( - err => console.log(err) - ); - - return {sources, monsters}; - } + 'google-sheets': this._importGoogleSheets, + 'json-raw': this._importJson, + 'json-file': this._importJsonFile, } /* import({ @@ -63,10 +15,85 @@ export default class Importer { * <- Exact format needed for localStorage * */ - static async import({ - resourceLocator = false, - type = 'google-sheets' - } = {}) { + static async import({ resourceLocator = false, type = 'google-sheets' } = {}) { return this.loaders[type](resourceLocator); } + + static async _importJsonFile(resourceLocator) { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.addEventListener('load', function() { + try { + const data = JSON.parse(reader.result); + resolve(data); + }catch (err) { + console.error(err); + reject(err); + } + }); + reader.readAsText(resourceLocator); + }); + } + + static async _importJson(resourceLocator) { + try { + return JSON.parse(resourceLocator); + }catch (err) { + console.error(err); + return false; + } + } + + static async _importGoogleSheets(resourceLocator) { + let monsters = await fetch(`https://sheets.googleapis.com/v4/spreadsheets/${resourceLocator}/values/Monsters?` + new URLSearchParams({ + key: this.key + })) + .then(response => response.json()) + .then(jsonifiedBody => { + let headers = jsonifiedBody.values.splice(0, 1)[0]; + + return jsonifiedBody.values.map((item) => ({ + "name": item[headers.indexOf("name")], + "cr": item[headers.indexOf("cr")], + "size": item[headers.indexOf("size")], + "type": item[headers.indexOf("type")], + "tags": item[headers.indexOf("tags")], + "section": item[headers.indexOf("section")], + "alignment": item[headers.indexOf("alignment")], + "environment": item[headers.indexOf("environment")], + "ac": item[headers.indexOf("ac")], + "hp": item[headers.indexOf("hp")], + "init": item[headers.indexOf("init")], + "lair": item[headers.indexOf("lair?")], + "legendary": item[headers.indexOf("legendary?")], + "unique": item[headers.indexOf("unique?")], + "sources": item[headers.indexOf("sources")], + })); + }) + .catch( + err => console.error(err) + ); + + let sources = await fetch(`https://sheets.googleapis.com/v4/spreadsheets/${resourceLocator}/values/Sources?` + new URLSearchParams({ + key: this.key + })) + .then(response => response.json()) + .then(jsonifiedBody => { + let headers = jsonifiedBody.values.splice(0, 1)[0]; + + return jsonifiedBody.values.map((item) => ({ + "name": item[headers.indexOf("name")], + "type": 'Custom', + "shortname": item[headers.indexOf("short name")], + "link": item[headers.indexOf("link")], + "enabled": true, + })); + }) + .catch( + err => console.error(err) + ); + + return {sources, monsters}; + } + } \ No newline at end of file From adf4600ee87ae63570d73bc3e5dbd475688ecb74 Mon Sep 17 00:00:00 2001 From: Haxxer Date: Fri, 13 May 2022 13:52:33 +0100 Subject: [PATCH 10/33] textarea works --- docs/index.html | 5 ++++- src/index.html | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/index.html b/docs/index.html index f661e5df..2eb8e29e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1339,7 +1339,7 @@

Keybo
Impor + diff --git a/src/index.html b/src/index.html index f661e5df..2eb8e29e 100644 --- a/src/index.html +++ b/src/index.html @@ -1339,7 +1339,7 @@

Keybo
Impor + From c470377ce8690b63706da27a9289db518408ddcd Mon Sep 17 00:00:00 2001 From: Haxxer Date: Fri, 13 May 2022 13:55:04 +0100 Subject: [PATCH 11/33] concat --- docs/index.html | 2 +- src/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.html b/docs/index.html index 2eb8e29e..1b871ac5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1355,7 +1355,7 @@

Keybo this.step = 2; }, finishImport() { - importedSources = importedSources.push(this.stagedSources) + importedSources = importedSources.concat(this.stagedSources) formatSources(this.stagedSources); this.stagedSources = []; diff --git a/src/index.html b/src/index.html index 2eb8e29e..1b871ac5 100644 --- a/src/index.html +++ b/src/index.html @@ -1355,7 +1355,7 @@

Keybo this.step = 2; }, finishImport() { - importedSources = importedSources.push(this.stagedSources) + importedSources = importedSources.concat(this.stagedSources) formatSources(this.stagedSources); this.stagedSources = []; From aece9447f27dc6707cb08a1bc64d5507adc69db4 Mon Sep 17 00:00:00 2001 From: Haxxer Date: Fri, 13 May 2022 14:26:12 +0100 Subject: [PATCH 12/33] Added deleteImportedSource --- docs/index.html | 2 +- docs/js/app.js | 24 ++++++++++++++++++++++-- src/index.html | 2 +- src/js/app.js | 20 ++++++++++++++++++++ src/js/importer.js | 6 ++++-- src/js/monster.js | 3 ++- 6 files changed, 50 insertions(+), 7 deletions(-) diff --git a/docs/index.html b/docs/index.html index 1b871ac5..f5828786 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1339,7 +1339,7 @@

Keybo
Keybo
{ const [book, location] = str.split(": "); let source = {}; + source.actual_source = this.app.sources[book]; if (!isNaN(location)) { - source.reference = this.app.sources[book]; + source.reference = source.actual_source; source.page = location; } else if (helpers.isValidHttpUrl(location)) { source.reference = { From 0101b5cc83dc227a9d4c752a8aaf9b0956742eef Mon Sep 17 00:00:00 2001 From: Haxxer Date: Fri, 13 May 2022 14:50:49 +0100 Subject: [PATCH 13/33] Remove key... --- docs/js/app.js | 2 -- src/js/importer.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/docs/js/app.js b/docs/js/app.js index 43c8e855..c750175a 100644 --- a/docs/js/app.js +++ b/docs/js/app.js @@ -11533,8 +11533,6 @@ var Importer = /*#__PURE__*/function () { return Importer; }(); -_defineProperty(Importer, "key", "AIzaSyA6AlaWOOlyFIXE6KSs1QsiALp26JbHzdI"); - _defineProperty(Importer, "loaders", { 'google-sheets': Importer._importGoogleSheets, 'json-raw': Importer._importJson, diff --git a/src/js/importer.js b/src/js/importer.js index 23a6be87..d739aef4 100644 --- a/src/js/importer.js +++ b/src/js/importer.js @@ -1,7 +1,5 @@ export default class Importer { - static key = "AIzaSyA6AlaWOOlyFIXE6KSs1QsiALp26JbHzdI" - static loaders = { 'google-sheets': this._importGoogleSheets, 'json-raw': this._importJson, From 39c7b9c16cc624be99cae73ef80744c451e2bffb Mon Sep 17 00:00:00 2001 From: V13Axel Date: Fri, 13 May 2022 21:49:48 -0400 Subject: [PATCH 14/33] Various adjustments --- docs/css/styles.css | 137 ++++++++++++++++++++++++++++++++------------ docs/index.html | 82 +++++++++++++++++++------- docs/js/app.js | 6 +- src/css/kobold.css | 13 +++-- src/index.html | 82 +++++++++++++++++++------- src/js/app.js | 4 +- src/js/importer.js | 1 + 7 files changed, 236 insertions(+), 89 deletions(-) diff --git a/docs/css/styles.css b/docs/css/styles.css index efe8a21e..d56c786a 100644 --- a/docs/css/styles.css +++ b/docs/css/styles.css @@ -8806,6 +8806,9 @@ input[type=text]:disabled{ .w-screen{ width: 100vw; } +.w-\[42px\]{ + width: 42px; +} .w-\[30px\]{ width: 30px; } @@ -8916,6 +8919,15 @@ input[type=text]:disabled{ .grid-cols-\[12px_12px_repeat\(12\2c _minmax\(0\2c _1fr\)\)\]{ grid-template-columns: 12px 12px repeat(12, minmax(0, 1fr)); } +.grid-cols-6{ + grid-template-columns: repeat(6, minmax(0, 1fr)); +} +.grid-cols-\[1fr_42px\]{ + grid-template-columns: 1fr 42px; +} +.grid-cols-\[42px_1fr_42px\]{ + grid-template-columns: 42px 1fr 42px; +} .grid-cols-\[30px_1fr\]{ grid-template-columns: 30px 1fr; } @@ -9314,6 +9326,10 @@ input[type=text]:disabled{ padding-left: 1.5rem; padding-right: 1.5rem; } +.\!px-0{ + padding-left: 0px !important; + padding-right: 0px !important; +} .py-5{ padding-top: 1.25rem; padding-bottom: 1.25rem; @@ -9405,9 +9421,6 @@ input[type=text]:disabled{ .align-middle{ vertical-align: middle; } -.align-bottom{ - vertical-align: bottom; -} .font-sans{ font-family: Inter var, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; } @@ -9453,9 +9466,6 @@ input[type=text]:disabled{ .italic{ font-style: italic; } -.leading-4{ - line-height: 1rem; -} .leading-6{ line-height: 1.5rem; } @@ -9547,6 +9557,10 @@ input[type=text]:disabled{ --tw-text-opacity: 1; color: rgb(239 68 68 / var(--tw-text-opacity)); } +.text-orange-500{ + --tw-text-opacity: 1; + color: rgb(249 115 22 / var(--tw-text-opacity)); +} .text-red-700{ --tw-text-opacity: 1; color: rgb(185 28 28 / var(--tw-text-opacity)); @@ -9851,13 +9865,13 @@ body .choices__list--multiple .choices__item{ margin-bottom: 0px; border-radius: 0.375rem; --tw-border-opacity: 1; - border-color: rgb(6 95 70 / var(--tw-border-opacity)); + border-color: rgb(4 120 87 / var(--tw-border-opacity)); --tw-bg-opacity: 1; - background-color: rgb(4 120 87 / var(--tw-bg-opacity)); + background-color: rgb(5 150 105 / var(--tw-bg-opacity)); } body .choices__list--multiple .choices__item:hover{ --tw-bg-opacity: 1; - background-color: rgb(5 150 105 / var(--tw-bg-opacity)); + background-color: rgb(4 120 87 / var(--tw-bg-opacity)); } body .choices__list--single{ padding-top: 0px; @@ -9924,7 +9938,7 @@ body .choices__input:focus{ } .noUi-connect{ --tw-bg-opacity: 1; - background-color: rgb(4 120 87 / var(--tw-bg-opacity)); + background-color: rgb(5 150 105 / var(--tw-bg-opacity)); } .dark .noUi-connect{ --tw-bg-opacity: 1; @@ -9983,7 +9997,7 @@ body .choices__input:focus{ border-width: 1px; border-color: transparent; --tw-bg-opacity: 1; - background-color: rgb(4 120 87 / var(--tw-bg-opacity)); + background-color: rgb(5 150 105 / var(--tw-bg-opacity)); padding-left: 1rem; padding-right: 1rem; padding-top: 0.5rem; @@ -10000,7 +10014,7 @@ body .choices__input:focus{ .button-primary-md:hover{ --tw-bg-opacity: 1; - background-color: rgb(5 150 105 / var(--tw-bg-opacity)); + background-color: rgb(4 120 87 / var(--tw-bg-opacity)); } .button-primary-md:focus{ @@ -10015,14 +10029,12 @@ body .choices__input:focus{ } .button-primary-md:disabled{ - --tw-bg-opacity: 1; - background-color: rgb(110 231 183 / var(--tw-bg-opacity)); opacity: 0.7; } .button-primary-md:hover:disabled{ --tw-bg-opacity: 1; - background-color: rgb(110 231 183 / var(--tw-bg-opacity)); + background-color: rgb(5 150 105 / var(--tw-bg-opacity)); } .dark .button-primary-md{ @@ -10044,6 +10056,51 @@ body .choices__input:focus{ --tw-bg-opacity: 1; background-color: rgb(6 78 59 / var(--tw-bg-opacity)); } +.button-primary-outline-md{ + display: inline-flex; + align-items: center; + border-radius: 0.375rem; + border-width: 1px; + --tw-border-opacity: 1; + border-color: rgb(16 185 129 / var(--tw-border-opacity)); + background-color: transparent; + padding-left: 1rem; + padding-right: 1rem; + padding-top: 0.5rem; + padding-bottom: 0.5rem; + font-size: 0.875rem; + line-height: 1.25rem; + font-weight: 500; + --tw-text-opacity: 1; + color: rgb(5 150 105 / var(--tw-text-opacity)); +} +.button-primary-outline-md:hover{ + --tw-bg-opacity: 1; + background-color: rgb(236 253 245 / var(--tw-bg-opacity)); +} +.button-primary-outline-md:focus{ + outline: 2px solid transparent; + outline-offset: 2px; + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + --tw-ring-opacity: 1; + --tw-ring-color: rgb(16 185 129 / var(--tw-ring-opacity)); + --tw-ring-offset-width: 2px; +} +.dark .button-primary-outline-md{ + --tw-border-opacity: 1; + border-color: rgb(6 95 70 / var(--tw-border-opacity)); + background-color: transparent; + --tw-text-opacity: 1; + color: rgb(5 150 105 / var(--tw-text-opacity)); +} +.dark .button-primary-outline-md:hover{ + --tw-bg-opacity: 1; + background-color: rgb(6 95 70 / var(--tw-bg-opacity)); + --tw-text-opacity: 1; + color: rgb(255 255 255 / var(--tw-text-opacity)); +} .button-secondary-md{ display: inline-flex; align-items: center; @@ -10154,9 +10211,9 @@ body .choices__input:focus{ align-items: center; border-radius: 0.375rem; border-width: 1px; - border-color: transparent; - --tw-bg-opacity: 1; - background-color: rgb(254 226 226 / var(--tw-bg-opacity)); + --tw-border-opacity: 1; + border-color: rgb(239 68 68 / var(--tw-border-opacity)); + background-color: transparent; padding-left: 1rem; padding-right: 1rem; padding-top: 0.5rem; @@ -10165,11 +10222,11 @@ body .choices__input:focus{ line-height: 1.25rem; font-weight: 500; --tw-text-opacity: 1; - color: rgb(185 28 28 / var(--tw-text-opacity)); + color: rgb(220 38 38 / var(--tw-text-opacity)); } .button-danger-outline-md:hover{ --tw-bg-opacity: 1; - background-color: rgb(254 202 202 / var(--tw-bg-opacity)); + background-color: rgb(254 242 242 / var(--tw-bg-opacity)); } .button-danger-outline-md:focus{ outline: 2px solid transparent; @@ -10283,10 +10340,6 @@ body .choices__input:focus{ --tw-bg-opacity: 1; background-color: rgb(243 244 246 / var(--tw-bg-opacity)); } -.hover\:bg-red-700:hover{ - --tw-bg-opacity: 1; - background-color: rgb(185 28 28 / var(--tw-bg-opacity)); -} .hover\:bg-emerald-600:hover{ --tw-bg-opacity: 1; background-color: rgb(5 150 105 / var(--tw-bg-opacity)); @@ -10295,6 +10348,10 @@ body .choices__input:focus{ --tw-bg-opacity: 1; background-color: rgb(254 226 226 / var(--tw-bg-opacity)); } +.hover\:bg-emerald-700:hover{ + --tw-bg-opacity: 1; + background-color: rgb(4 120 87 / var(--tw-bg-opacity)); +} .hover\:bg-gray-50:hover{ --tw-bg-opacity: 1; background-color: rgb(249 250 251 / var(--tw-bg-opacity)); @@ -10587,6 +10644,10 @@ body .choices__input:focus{ --tw-text-opacity: 1; color: rgb(209 250 229 / var(--tw-text-opacity)); } +.dark .dark\:text-orange-700{ + --tw-text-opacity: 1; + color: rgb(194 65 12 / var(--tw-text-opacity)); +} .dark .dark\:text-red-400{ --tw-text-opacity: 1; color: rgb(248 113 113 / var(--tw-text-opacity)); @@ -10785,10 +10846,6 @@ body .choices__input:focus{ height: 2.5rem; } - .sm\:w-full{ - width: 100%; - } - .sm\:w-10{ width: 2.5rem; } @@ -10797,12 +10854,12 @@ body .choices__input:focus{ width: auto; } - .sm\:max-w-2xl{ - max-width: 42rem; + .sm\:max-w-xl{ + max-width: 36rem; } - .sm\:max-w-4xl{ - max-width: 56rem; + .sm\:max-w-2xl{ + max-width: 42rem; } .sm\:translate-y-0{ @@ -10891,10 +10948,6 @@ body .choices__input:focus{ text-align: left; } - .sm\:align-middle{ - vertical-align: middle; - } - .sm\:text-sm{ font-size: 0.875rem; line-height: 1.25rem; @@ -10980,6 +11033,10 @@ body .choices__input:focus{ width: auto; } + .md\:max-w-2xl{ + max-width: 42rem; + } + .md\:transform-none{ transform: none; } @@ -10988,8 +11045,8 @@ body .choices__input:focus{ grid-template-columns: repeat(5, minmax(0, 1fr)); } - .md\:grid-cols-2{ - grid-template-columns: repeat(2, minmax(0, 1fr)); + .md\:grid-cols-12{ + grid-template-columns: repeat(12, minmax(0, 1fr)); } .md\:grid-cols-\[60px_1fr_50px_75px_150px_30px\]{ @@ -11081,6 +11138,10 @@ body .choices__input:focus{ width: auto; } + .lg\:max-w-4xl{ + max-width: 56rem; + } + .lg\:flex-row{ flex-direction: row; } diff --git a/docs/index.html b/docs/index.html index f5828786..accd4e04 100644 --- a/docs/index.html +++ b/docs/index.html @@ -389,7 +389,7 @@
-
@@ -398,7 +398,7 @@
-
- -
@@ -816,7 +816,7 @@

CE

-
Any
-
Unaligned
+
Any
+
Unaligned

@@ -936,9 +936,9 @@

@@ -398,7 +398,7 @@
-
- -
@@ -816,7 +816,7 @@

CE

-
Any
-
Unaligned
+
Any
+
Unaligned

@@ -936,9 +936,9 @@