mirror of
				https://github.com/em-squared/5e-drs.git
				synced 2025-10-31 05:24:20 +00:00 
			
		
		
		
	modification de l'identification des resources plus robuste
This commit is contained in:
		
							parent
							
								
									0494298159
								
							
						
					
					
						commit
						96d028dfa6
					
				
					 14 changed files with 130 additions and 94 deletions
				
			
		|  | @ -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) | ||||
|       } | ||||
|  |  | |||
|  | @ -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) | ||||
|       } | ||||
|  |  | |||
|  | @ -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) | ||||
|       } | ||||
|  |  | |||
|  | @ -47,7 +47,7 @@ | |||
|                   <v-icon v-if="isHiddenPrint(item)">mdi-printer-off</v-icon> | ||||
|                   <v-icon v-else>mdi-printer</v-icon> | ||||
|                 </v-btn> | ||||
|                 <v-btn class="d-print-none mr-2" small depressed link icon :to="{ path: '/creation-de-monstre-pnj/', query: { key: item.key } }"><v-icon>mdi-pencil</v-icon></v-btn> | ||||
|                 <v-btn v-if="item.custom" class="d-print-none mr-2" small depressed link icon :to="{ path: '/creation-de-monstre-pnj/', query: { key: item.key } }"><v-icon>mdi-pencil</v-icon></v-btn> | ||||
|                 <v-btn color="error" class="d-print-none" small depressed icon @click="removeMonster(item)"><v-icon>mdi-delete</v-icon></v-btn> | ||||
|               </div> | ||||
|             </template> | ||||
|  |  | |||
|  | @ -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) => { | ||||
|  |  | |||
|  | @ -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 () { | ||||
|  |  | |||
|  | @ -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 () { | ||||
|  |  | |||
|  | @ -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)) { | ||||
|  |  | |||
|  | @ -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 () { | ||||
|  |  | |||
|  | @ -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)) { | ||||
|  |  | |||
|  | @ -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 () { | ||||
|  |  | |||
|  | @ -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)) { | ||||
|  |  | |||
|  | @ -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 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Maxime Moraine
						Maxime Moraine