From 96d028dfa61ba9eb95e6e55c3f6e9c1234d4ce32 Mon Sep 17 00:00:00 2001 From: Maxime Moraine Date: Sun, 24 May 2020 13:32:31 +0200 Subject: [PATCH] modification de l'identification des resources plus robuste --- docs/.vuepress/store/modules/myMagicItems.js | 23 ++++--- docs/.vuepress/store/modules/myMonsters.js | 23 ++++--- docs/.vuepress/store/modules/mySpells.js | 23 ++++--- .../.vuepress/theme/components/MyMonsters.vue | 2 +- .../theme/layouts/CreateMonsterLayout.vue | 65 +++++++++++++++++-- .../theme/layouts/CreateSpellLayout.vue | 9 +-- .../theme/layouts/MagicItemLayout.vue | 9 +-- .../theme/layouts/MagicItemsLayout.vue | 9 +-- .../.vuepress/theme/layouts/MonsterLayout.vue | 9 +-- .../theme/layouts/MonstersLayout.vue | 9 +-- docs/.vuepress/theme/layouts/SpellLayout.vue | 9 +-- docs/.vuepress/theme/layouts/SpellsLayout.vue | 9 +-- docs/.vuepress/theme/util/index.js | 24 +++++++ docs/bestiaire/acolyte/README.md | 1 - 14 files changed, 130 insertions(+), 94 deletions(-) diff --git a/docs/.vuepress/store/modules/myMagicItems.js b/docs/.vuepress/store/modules/myMagicItems.js index d1292b6..9837a5f 100644 --- a/docs/.vuepress/store/modules/myMagicItems.js +++ b/docs/.vuepress/store/modules/myMagicItems.js @@ -1,4 +1,5 @@ import {sortByString} from '@theme/util/filterHelpers' +import { getResourceIndexInLibrary } from '@theme/util' export default { namespaced: true, @@ -51,30 +52,28 @@ export default { state.magicItems.sort((a, b) => { return sortByString(a.title, b.title) }) }, updateMagicItem: (state, payload) => { - state.magicItems.forEach((magicItem, idx) => { - if (magicItem.key == payload.key) { - state.magicItems[idx] = payload - } - }) + let magicItemIndex = getResourceIndexInLibrary(payload, state.magicItems) + if (magicItemIndex >= 0) { + state.magicItems[magicItemIndex] = payload + } }, removeMagicItem: (state, payload) => { - state.magicItems.forEach((magicItem, idx) => { - if (magicItem.key == payload.key) { - state.magicItems.splice(idx, 1) - } - }) + let magicItemIndex = getResourceIndexInLibrary(payload, state.magicItems) + if (magicItemIndex >= 0) { + state.magicItems.splice(magicItemIndex, 1) + } }, setNotPrintedMagicItems: (state, payload) => { state.notPrintedMagicItems = payload }, addNotPrintedMagicItem: (state, payload) => { - let magicItemIndex = state.notPrintedMagicItems.findIndex(magicItem => magicItem.key == payload.key) + let magicItemIndex = getResourceIndexInLibrary(payload, state.notPrintedMagicItems) if (!magicItemIndex >= 0) { state.notPrintedMagicItems.push(payload) } }, removeNotPrintedMagicItem: (state, payload) => { - let magicItemIndex = state.notPrintedMagicItems.findIndex(magicItem => magicItem.key == payload.key) + let magicItemIndex = getResourceIndexInLibrary(payload, state.notPrintedMagicItems) if (magicItemIndex >= 0) { state.notPrintedMagicItems.splice(magicItemIndex, 1) } diff --git a/docs/.vuepress/store/modules/myMonsters.js b/docs/.vuepress/store/modules/myMonsters.js index 1989546..15ab5c7 100644 --- a/docs/.vuepress/store/modules/myMonsters.js +++ b/docs/.vuepress/store/modules/myMonsters.js @@ -1,4 +1,5 @@ import {sortByString} from '@theme/util/filterHelpers' +import { getResourceIndexInLibrary } from '@theme/util' export default { namespaced: true, @@ -51,30 +52,28 @@ export default { state.monsters.sort((a, b) => { return sortByString(a.title, b.title) }) }, updateMonster: (state, payload) => { - state.monsters.forEach((monster, idx) => { - if (monster.key == payload.key) { - state.monsters[idx] = payload - } - }) + let monsterIndex = getResourceIndexInLibrary(payload, state.monsters) + if (monsterIndex >= 0) { + state.monsters[monsterIndex] = payload + } }, removeMonster: (state, payload) => { - state.monsters.forEach((monster, idx) => { - if (monster.key == payload.key) { - state.monsters.splice(idx, 1) - } - }) + let monsterIndex = getResourceIndexInLibrary(payload, state.monsters) + if (monsterIndex >= 0) { + state.monsters.splice(monsterIndex, 1) + } }, setNotPrintedMonsters: (state, payload) => { state.notPrintedMonsters = payload }, addNotPrintedMonster: (state, payload) => { - let monsterIndex = state.notPrintedMonsters.findIndex(monster => monster.key == payload.key) + let monsterIndex = getResourceIndexInLibrary(payload, state.notPrintedMonsters) if (!monsterIndex >= 0) { state.notPrintedMonsters.push(payload) } }, removeNotPrintedMonster: (state, payload) => { - let monsterIndex = state.notPrintedMonsters.findIndex(monster => monster.key == payload.key) + let monsterIndex = getResourceIndexInLibrary(payload, state.notPrintedMonsters) if (monsterIndex >= 0) { state.notPrintedMonsters.splice(monsterIndex, 1) } diff --git a/docs/.vuepress/store/modules/mySpells.js b/docs/.vuepress/store/modules/mySpells.js index ba67cb5..316c474 100644 --- a/docs/.vuepress/store/modules/mySpells.js +++ b/docs/.vuepress/store/modules/mySpells.js @@ -1,4 +1,5 @@ import {sortByString} from '@theme/util/filterHelpers' +import { getResourceIndexInLibrary } from '@theme/util' export default { namespaced: true, @@ -55,18 +56,16 @@ export default { state.spells.sort((a, b) => { return sortByString(a.title, b.title) }) }, updateSpell: (state, payload) => { - state.spells.forEach((spell, idx) => { - if (spell.key == payload.key) { - state.spells[idx] = payload - } - }) + let spellIndex = getResourceIndexInLibrary(payload, state.spells) + if (spellIndex >= 0) { + state.spells[spellIndex] = payload + } }, removeSpell: (state, payload) => { - state.spells.forEach((spell, idx) => { - if (spell.key == payload.key) { - state.spells.splice(idx, 1) - } - }) + let spellIndex = getResourceIndexInLibrary(payload, state.spells) + if (spellIndex >= 0) { + state.spells.splice(spellIndex, 1) + } }, setSpellSlots: (state, payload) => { state.spellSlots = payload @@ -75,13 +74,13 @@ export default { state.notPrintedSpells = payload }, addNotPrintedSpell: (state, payload) => { - let spellIndex = state.notPrintedSpells.findIndex(spell => spell.key == payload.key) + let spellIndex = getResourceIndexInLibrary(payload, state.notPrintedSpells) if (!spellIndex >= 0) { state.notPrintedSpells.push(payload) } }, removeNotPrintedSpell: (state, payload) => { - let spellIndex = state.notPrintedSpells.findIndex(spell => spell.key == payload.key) + let spellIndex = getResourceIndexInLibrary(payload, state.notPrintedSpells) if (spellIndex >= 0) { state.notPrintedSpells.splice(spellIndex, 1) } diff --git a/docs/.vuepress/theme/components/MyMonsters.vue b/docs/.vuepress/theme/components/MyMonsters.vue index aa606ec..d5a391a 100644 --- a/docs/.vuepress/theme/components/MyMonsters.vue +++ b/docs/.vuepress/theme/components/MyMonsters.vue @@ -47,7 +47,7 @@ mdi-printer-off mdi-printer - mdi-pencil + mdi-pencil mdi-delete diff --git a/docs/.vuepress/theme/layouts/CreateMonsterLayout.vue b/docs/.vuepress/theme/layouts/CreateMonsterLayout.vue index c00739b..b818cdd 100644 --- a/docs/.vuepress/theme/layouts/CreateMonsterLayout.vue +++ b/docs/.vuepress/theme/layouts/CreateMonsterLayout.vue @@ -222,6 +222,7 @@ import { CONDITIONS } from '../../data/conditions' import { DAMAGETYPES } from '../../data/damageTypes' import { LANGUAGES } from '../../data/languages' import { getUrlParameter } from '@theme/util/filterHelpers' +import { isResourceInLibrary } from '@theme/util' import { getProficiencyBonus, displayBonus } from '@theme/util/monsterHelpers' import slugify from 'slugify' slugify.extend({"'": '-'}) @@ -236,13 +237,7 @@ export default { computed: { isMonsterInBestiary () { - let isInBestiary = false - for (let s of this.$store.state.myMonsters.monsters) { - if (s.key == this.monster.key) { - isInBestiary = true - } - } - return isInBestiary + return isResourceInLibrary(this.monster, this.$store.state.myMonsters.monsters) }, displayToggleMonsterButton () { @@ -514,9 +509,65 @@ export default { for (let monster of this.$store.state.myMonsters.monsters) { if (monster.key == monsterKey) { this.monster = monster + // this.monster = { + // custom: monster.custom, + // pid: 'monster', + // key: monster.key, + // title: monster.title, + // content: '', + // frontmatter: { + // type: monster.frontmatter.type ? monster.frontmatter.type : '', + // subtype: monster.frontmatter.subtype ? monster.frontmatter.subtype : '', + // size: monster.frontmatter.size ? monster.frontmatter.size : '', + // challenge: monster.frontmatter.challenge ? monster.frontmatter.challenge : '0', + // alignment: monster.frontmatter.alignment ? monster.frontmatter.alignment : '', + // isSwarm: monster.frontmatter.isSwarm, + // swarmSize: monster.frontmatter.swarmSize ? monster.frontmatter.swarmSize : '', + // hitDiceCount: monster.frontmatter.hitDiceCount, + // hitDieSize: monster.frontmatter.hitDieSize, + // abilityScores: { + // for: monster.frontmatter.abilityScores.for, + // dex: monster.frontmatter.abilityScores.dex, + // con: monster.frontmatter.abilityScores.con, + // int: monster.frontmatter.abilityScores.int, + // sag: monster.frontmatter.abilityScores.sag, + // cha: monster.frontmatter.abilityScores.cha, + // }, + // ac: { + // armorType: monster.frontmatter.ac ? monster.frontmatter.ac.armorType : null, + // value: monster.frontmatter.ac ? monster.frontmatter.ac.value : null, + // hasShield: monster.frontmatter.ac ? monster.frontmatter.ac.hasShield : false, + // }, + // savingThrow: monster.frontmatter.savingThrow ? monster.frontmatter.savingThrow : null, + // skills: monster.frontmatter.skills ? monster.frontmatter.skills : null, + // movement: { + // walk: monster.frontmatter.movement ? monster.frontmatter.movement.walk : null, + // climb: monster.frontmatter.movement ? monster.frontmatter.movement.climb : null, + // burrow: monster.frontmatter.movement ? monster.frontmatter.movement.burrow : null, + // swim: monster.frontmatter.movement ? monster.frontmatter.movement.swim : null, + // fly: monster.frontmatter.movement ? monster.frontmatter.movement.fly : null, + // hover: monster.frontmatter.movement ? monster.frontmatter.movement.hover : null, + // }, + // senses: { + // tremorsense: monster.frontmatter.senses ? monster.frontmatter.senses.tremorsense : null, + // blindsight: monster.frontmatter.senses ? monster.frontmatter.senses.blindsight : null, + // darkvision: monster.frontmatter.senses ? monster.frontmatter.senses.darkvision : null, + // truesight: monster.frontmatter.senses ? monster.frontmatter.senses.truesight : null, + // }, + // conditionImmunities: monster.frontmatter.conditionImmunities, + // damageTypeVulnerabilities: monster.frontmatter.damageTypeVulnerabilities, + // damageTypeResistances: monster.frontmatter.damageTypeResistances, + // damageTypeImmunities: monster.frontmatter.damageTypeImmunities, + // languages: monster.frontmatter.languages, + // customLanguage: monster.frontmatter.customLanguage, + // telepathy: monster.frontmatter.telepathy + // } + // } if (!this.monster.custom) { this.monster.content = monster.rawContent this.monster.custom = true + } else { + this.monster.content = monster.content } if (this.monster.frontmatter.skills) { this.monster.frontmatter.skills.forEach((mskill, idx) => { diff --git a/docs/.vuepress/theme/layouts/CreateSpellLayout.vue b/docs/.vuepress/theme/layouts/CreateSpellLayout.vue index 1b2dc88..79ea4c0 100644 --- a/docs/.vuepress/theme/layouts/CreateSpellLayout.vue +++ b/docs/.vuepress/theme/layouts/CreateSpellLayout.vue @@ -110,6 +110,7 @@ import { saveAs } from 'file-saver' import { CLASSES } from '../../data/classes' import { SPELLSCHOOLS, SPELLLEVELS } from '../../data/spells' import { getUrlParameter } from '@theme/util/filterHelpers' +import { isResourceInLibrary } from '@theme/util' import slugify from 'slugify' slugify.extend({"'": '-'}) @@ -123,13 +124,7 @@ export default { computed: { isSpellInSpellBook () { - let isInSpellBook = false - for (let s of this.$store.state.mySpells.spells) { - if (s.key == this.spell.key) { - isInSpellBook = true - } - } - return isInSpellBook + return isResourceInLibrary(this.spell, this.$store.state.mySpells.spells) }, displayToggleSpellButton () { diff --git a/docs/.vuepress/theme/layouts/MagicItemLayout.vue b/docs/.vuepress/theme/layouts/MagicItemLayout.vue index 81aaaeb..9e19ab4 100644 --- a/docs/.vuepress/theme/layouts/MagicItemLayout.vue +++ b/docs/.vuepress/theme/layouts/MagicItemLayout.vue @@ -18,6 +18,7 @@ import Breadcrumb from '@theme/components/Breadcrumb' import MagicItem from '@theme/components/MagicItem' import MyMagicItemsButton from '@theme/global-components/MyMagicItemsButton' import Edit from '@theme/components/Edit' +import { isResourceInLibrary } from '@theme/util' export default { name: 'MagicItemLayout', @@ -31,13 +32,7 @@ export default { computed: { isMagicItemInTreasureChest () { - let isInTreasureChest = false - for (let s of this.$store.state.myMagicItems.magicItems) { - if (s.key == this.$page.key) { - isInTreasureChest = true - } - } - return isInTreasureChest + return isResourceInLibrary(this.$page, this.$store.state.myMagicItems.magicItems) }, displayToggleMagicItemButton () { diff --git a/docs/.vuepress/theme/layouts/MagicItemsLayout.vue b/docs/.vuepress/theme/layouts/MagicItemsLayout.vue index 2a8196b..56864d4 100644 --- a/docs/.vuepress/theme/layouts/MagicItemsLayout.vue +++ b/docs/.vuepress/theme/layouts/MagicItemsLayout.vue @@ -77,6 +77,7 @@ import { mapState } from 'vuex' import Breadcrumb from '@theme/components/Breadcrumb' import { setUrlParams, getUrlParameter } from '@theme/util/filterHelpers' +import { isResourceInLibrary } from '@theme/util' import MagicItem from '@theme/components/MagicItem' import MyMagicItemsButton from '@theme/global-components/MyMagicItemsButton' @@ -182,13 +183,7 @@ export default { methods: { isItemInTreasureChest (magicItem) { - let isInTreasureChest = false - for (let mi of this.$store.state.myMagicItems.magicItems) { - if (mi.key == magicItem.key) { - isInTreasureChest = true - } - } - return isInTreasureChest + return isResourceInLibrary(magicItem, this.$store.state.myMagicItems.magicItems) }, toggleItemInTreasureChest (magicItem) { if (this.isItemInTreasureChest(magicItem)) { diff --git a/docs/.vuepress/theme/layouts/MonsterLayout.vue b/docs/.vuepress/theme/layouts/MonsterLayout.vue index 092da9f..388f52e 100644 --- a/docs/.vuepress/theme/layouts/MonsterLayout.vue +++ b/docs/.vuepress/theme/layouts/MonsterLayout.vue @@ -18,6 +18,7 @@ import Breadcrumb from '@theme/components/Breadcrumb' import Monster from '@theme/components/Monster' import MyMonstersButton from '@theme/global-components/MyMonstersButton' import Edit from '@theme/components/Edit' +import { isResourceInLibrary } from '@theme/util' export default { name: 'MonsterLayout', @@ -31,13 +32,7 @@ export default { computed: { isMonsterInBestiary () { - let isInBestiary = false - for (let s of this.$store.state.myMonsters.monsters) { - if (s.key == this.$page.key) { - isInBestiary = true - } - } - return isInBestiary + return isResourceInLibrary(this.$page, this.$store.state.myMonsters.monsters) }, displayToggleMonsterButton () { diff --git a/docs/.vuepress/theme/layouts/MonstersLayout.vue b/docs/.vuepress/theme/layouts/MonstersLayout.vue index 2936c92..47c48ba 100644 --- a/docs/.vuepress/theme/layouts/MonstersLayout.vue +++ b/docs/.vuepress/theme/layouts/MonstersLayout.vue @@ -90,6 +90,7 @@ import { mapState } from 'vuex' import Breadcrumb from '@theme/components/Breadcrumb' import { displayChallenge } from '@theme/util/monsterHelpers' import { setUrlParams, getUrlParameter } from '@theme/util/filterHelpers' +import { isResourceInLibrary } from '@theme/util' import Monster from '@theme/components/Monster' import MyMonstersButton from '@theme/global-components/MyMonstersButton' import { CHALLENGES } from '../../data/monsters' @@ -268,13 +269,7 @@ export default { displayList (list) { return list.join(', ') }, displayChallenge (challenge) { return displayChallenge(challenge) }, isMonsterInBestiary (monster) { - let isInBestiary = false - for (let m of this.$store.state.myMonsters.monsters) { - if (m.key == monster.key) { - isInBestiary = true - } - } - return isInBestiary + return isResourceInLibrary(monster, this.$store.state.myMonsters.monsters) }, toggleMonsterInBestiary (monster) { if (this.isMonsterInBestiary(monster)) { diff --git a/docs/.vuepress/theme/layouts/SpellLayout.vue b/docs/.vuepress/theme/layouts/SpellLayout.vue index cc87076..9fbaeb6 100644 --- a/docs/.vuepress/theme/layouts/SpellLayout.vue +++ b/docs/.vuepress/theme/layouts/SpellLayout.vue @@ -18,6 +18,7 @@ import Breadcrumb from '@theme/components/Breadcrumb' import Spell from '@theme/components/Spell' import MySpellsButton from '@theme/global-components/MySpellsButton' import Edit from '@theme/components/Edit' +import { isResourceInLibrary } from '@theme/util' export default { name: 'SpellLayout', @@ -31,13 +32,7 @@ export default { computed: { isSpellInSpellBook () { - let isInSpellBook = false - for (let s of this.$store.state.mySpells.spells) { - if (s.key == this.$page.key) { - isInSpellBook = true - } - } - return isInSpellBook + return isResourceInLibrary(this.$page, this.$store.state.mySpells.spells) }, displayToggleSpellButton () { diff --git a/docs/.vuepress/theme/layouts/SpellsLayout.vue b/docs/.vuepress/theme/layouts/SpellsLayout.vue index af923d7..4b1a34f 100644 --- a/docs/.vuepress/theme/layouts/SpellsLayout.vue +++ b/docs/.vuepress/theme/layouts/SpellsLayout.vue @@ -117,6 +117,7 @@ import { mapState } from 'vuex' import Breadcrumb from '@theme/components/Breadcrumb' import { setUrlParams, getUrlParameter } from '@theme/util/filterHelpers' +import { isResourceInLibrary } from '@theme/util' import Spell from '@theme/components/Spell' import MySpellsButton from '@theme/global-components/MySpellsButton' @@ -281,13 +282,7 @@ export default { methods: { isSpellInSpellBook (spell) { - let isInSpellBook = false - for (let s of this.$store.state.mySpells.spells) { - if (s.key == spell.key) { - isInSpellBook = true - } - } - return isInSpellBook + return isResourceInLibrary(spell, this.$store.state.mySpells.spells) }, toggleSpellInSpellBook (spell) { if (this.isSpellInSpellBook(spell)) { diff --git a/docs/.vuepress/theme/util/index.js b/docs/.vuepress/theme/util/index.js index 4627faa..3d924fa 100644 --- a/docs/.vuepress/theme/util/index.js +++ b/docs/.vuepress/theme/util/index.js @@ -238,3 +238,27 @@ function resolveItem (item, pages, base, groupDepth = 1) { } } } + +/* +** Returns index of resource in library +*/ +export function getResourceIndexInLibrary (resource, library) { + let idx = -1 + if (resource.custom) { + idx = library.findIndex(item => item.key == resource.key) + } else { + idx = library.findIndex(item => item.path == resource.path) + } + return idx +} + +/* +** Returns presence of resource in library +*/ +export function isResourceInLibrary (resource, library) { + let idx = getResourceIndexInLibrary(resource, library) + if (idx >= 0) { + return true + } + return false +} diff --git a/docs/bestiaire/acolyte/README.md b/docs/bestiaire/acolyte/README.md index 01c40ab..ae1bede 100644 --- a/docs/bestiaire/acolyte/README.md +++ b/docs/bestiaire/acolyte/README.md @@ -20,7 +20,6 @@ skills: - name: "religion" movement: walk: 9 -senses: languages: - "une langue au choix (commun le plus souvent)" source: "Créatures & Oppositions"