From e15a84fa0eb181e8266acfd60e796fbf0462def6 Mon Sep 17 00:00:00 2001 From: Maxime Moraine Date: Sat, 13 Mar 2021 18:33:35 +0100 Subject: [PATCH] =?UTF-8?q?tooltips=20cr=C3=A9atures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theme/layouts/MagicItemsLayout.vue | 19 +++ .../theme/layouts/MonstersLayout.vue | 21 +++- docs/.vuepress/theme/layouts/SpellsLayout.vue | 19 +++ docs/.vuepress/theme/styles/_colors.scss | 2 + docs/.vuepress/theme/styles/_tooltips.scss | 13 ++- docs/.vuepress/theme/util/index.js | 104 ++++++++++++++++- docs/.vuepress/theme/util/monsterHelpers.js | 108 ++++++++++++++++++ 7 files changed, 281 insertions(+), 5 deletions(-) diff --git a/docs/.vuepress/theme/layouts/MagicItemsLayout.vue b/docs/.vuepress/theme/layouts/MagicItemsLayout.vue index 98d0f84..8871518 100644 --- a/docs/.vuepress/theme/layouts/MagicItemsLayout.vue +++ b/docs/.vuepress/theme/layouts/MagicItemsLayout.vue @@ -220,6 +220,15 @@ export default { changePage (page) { // console.log(page) setUrlParams("page", [page]) + let self = this + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100); + this.$router.afterEach(() => { + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100) + }) }, onClickRow (row, item) { @@ -240,6 +249,16 @@ export default { if (page) { this.page = page } + + let self = this + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100); + this.$router.afterEach(() => { + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100) + }) } } diff --git a/docs/.vuepress/theme/layouts/MonstersLayout.vue b/docs/.vuepress/theme/layouts/MonstersLayout.vue index e5884aa..c44ba84 100644 --- a/docs/.vuepress/theme/layouts/MonstersLayout.vue +++ b/docs/.vuepress/theme/layouts/MonstersLayout.vue @@ -154,7 +154,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 { isResourceInLibrary, handleTooltips } from '@theme/util' import Monster from '@theme/components/Monster' import MyMonstersButton from '@theme/global-components/MyMonstersButton' import { CHALLENGES } from '../../data/monsters' @@ -387,6 +387,15 @@ export default { changePage (page) { // console.log(page) setUrlParams("page", [page]) + let self = this + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100); + this.$router.afterEach(() => { + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100) + }) }, onClickRow (row, item) { @@ -416,6 +425,16 @@ export default { if (showColumn) { this.showColumn = JSON.parse(showColumn) } + + let self = this + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100); + this.$router.afterEach(() => { + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100) + }) } } diff --git a/docs/.vuepress/theme/layouts/SpellsLayout.vue b/docs/.vuepress/theme/layouts/SpellsLayout.vue index e913383..8c6aa2c 100644 --- a/docs/.vuepress/theme/layouts/SpellsLayout.vue +++ b/docs/.vuepress/theme/layouts/SpellsLayout.vue @@ -385,6 +385,15 @@ export default { changePage (page) { // console.log(page) setUrlParams("page", [page]) + let self = this + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100); + this.$router.afterEach(() => { + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100) + }) }, onClickRow (row, item) { @@ -425,6 +434,16 @@ export default { if (showColumn) { this.showColumn = JSON.parse(showColumn) } + + let self = this + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100); + this.$router.afterEach(() => { + setTimeout(function () { + handleTooltips({pages:self.$site.pages}) + }, 100) + }) } } diff --git a/docs/.vuepress/theme/styles/_colors.scss b/docs/.vuepress/theme/styles/_colors.scss index cfe4eb7..b8bdeae 100644 --- a/docs/.vuepress/theme/styles/_colors.scss +++ b/docs/.vuepress/theme/styles/_colors.scss @@ -7,3 +7,5 @@ $color-table-header-bg: #6f6f6f; $color-gold: #bab468; $color-gold-dark: #9f994f; $color-gold-light: #d6d082; +$color-red: #9b1c47; +$color-purple: #563f5a; diff --git a/docs/.vuepress/theme/styles/_tooltips.scss b/docs/.vuepress/theme/styles/_tooltips.scss index 8551348..4a76cb7 100644 --- a/docs/.vuepress/theme/styles/_tooltips.scss +++ b/docs/.vuepress/theme/styles/_tooltips.scss @@ -28,8 +28,12 @@ &.tooltip-spell { background-color: $color-dragon; } - // &.tooltip-condition { - // } + &.tooltip-monster { + background-color: $color-red; + } + &.tooltip-condition { + background-color: $color-purple; + } color: #fff; font-family: 'Oswald', sans-serif; font-weight: bold; @@ -60,6 +64,11 @@ margin-bottom: .5rem; padding-bottom: .5rem; } + .monster-details { + border-bottom: 2px solid $color-red; + margin-bottom: .5rem; + padding-bottom: .5rem; + } } } diff --git a/docs/.vuepress/theme/util/index.js b/docs/.vuepress/theme/util/index.js index 0a5cdfa..8755379 100644 --- a/docs/.vuepress/theme/util/index.js +++ b/docs/.vuepress/theme/util/index.js @@ -267,7 +267,8 @@ export function isResourceInLibrary (resource, library) { ** Handles rule tooltips like conditions */ import { tooltips } from '../../data/ruleTooltips.js' -import {displaySchoolLevel} from '@theme/util/spellHelpers' +import { displaySchoolLevel } from '@theme/util/spellHelpers' +import { displayMonsterTypeSizeAlignment, displayAC, displayHP, displayChallenge, displayAbilityScore } from '@theme/util/monsterHelpers' import MarkdownIt from 'markdown-it' export function handleTooltips (params = {}) { if (!params.component) { @@ -318,11 +319,15 @@ export function handleTooltips (params = {}) { tooltip.style.display = 'none' tooltipTitle.classList.remove('tooltip-condition') }, false); + l.addEventListener("click", function( event ) { + tooltip.style.display = 'none' + tooltipTitle.classList.remove('tooltip-condition') + }, false); } else if (l.pathname.startsWith('/grimoire/')) { // console.log(l.pathname) if (params.pages) { let spell = params.pages.find((el) => el.path === l.pathname) - if (spell) { + if (spell && spell.frontmatter.school) { // console.log(spell) l.addEventListener("mouseover", function( event ) { let ttitle = '
' @@ -384,6 +389,101 @@ export function handleTooltips (params = {}) { }, false); } } + } else if (l.pathname.startsWith('/bestiaire/')) { + // console.log(l.pathname) + if (params.pages) { + let monster = params.pages.find((el) => el.path === l.pathname) + if (monster && monster.frontmatter.challenge) { + // console.log(spell) + l.addEventListener("mouseover", function( event ) { + let ttitle = '
' + ttitle += '
' + monster.title + '
' + ttitle += '
' + displayMonsterTypeSizeAlignment(monster.frontmatter, true) + '
' + ttitle += '
' + tooltipTitle.innerHTML = ttitle + tooltipTitle.classList.add('tooltip-monster') + let tcontent = '
' + + tcontent += '
' + tcontent += '
' + tcontent += '
Points de vie
' + displayHP(monster) + '
' + tcontent += '
Classe d\'armure
' + displayAC(monster) + '
' + tcontent += '
Dangerosité
' + displayChallenge(monster.frontmatter.challenge, true) + '
' + tcontent += '
' + tcontent += '
' + + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += 'For' + tcontent += '
' + tcontent += '
' + tcontent += '' + displayAbilityScore(monster.frontmatter.abilityScores.for) + '' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += 'Dex' + tcontent += '
' + tcontent += '
' + tcontent += '' + displayAbilityScore(monster.frontmatter.abilityScores.dex) + '' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += 'Con' + tcontent += '
' + tcontent += '
' + tcontent += '' + displayAbilityScore(monster.frontmatter.abilityScores.con) + '' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += 'Int' + tcontent += '
' + tcontent += '
' + tcontent += '' + displayAbilityScore(monster.frontmatter.abilityScores.int) + '' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += 'Sag' + tcontent += '
' + tcontent += '
' + tcontent += '' + displayAbilityScore(monster.frontmatter.abilityScores.sag) + '' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += 'Cha' + tcontent += '
' + tcontent += '
' + tcontent += '' + displayAbilityScore(monster.frontmatter.abilityScores.cha) + '' + tcontent += '
' + tcontent += '
' + tcontent += '
' + tcontent += '
' + + tcontent += '
' + tcontent += '
' + tcontent += '
' + tooltipContent.innerHTML = tcontent + tooltip.style.display = 'block' + }, false); + + l.addEventListener("mouseout", function( event ) { + tooltip.style.display = 'none' + tooltipTitle.classList.remove('tooltip-monster') + }, false); + l.addEventListener("click", function( event ) { + tooltip.style.display = 'none' + tooltipTitle.classList.remove('tooltip-monster') + }, false); + } + } } } } diff --git a/docs/.vuepress/theme/util/monsterHelpers.js b/docs/.vuepress/theme/util/monsterHelpers.js index 37afb4b..a73c4d6 100644 --- a/docs/.vuepress/theme/util/monsterHelpers.js +++ b/docs/.vuepress/theme/util/monsterHelpers.js @@ -70,6 +70,114 @@ export function displayMonsterTypeSizeAlignment (monster, hideAlignment = false, return result } +// Affiche la Classe d'armure +export function displayAC (monster) { + let ac = 10 + let hasMageArmor = false + let mageArmorAc = 13 + let mageArmor = '' + let armor = '' + // Le monstre n'a pas d'armure. + // CA = 10 + Dex + if (!monster.frontmatter.ac.armorType) { + ac = 10 + getModifier(monster.frontmatter.abilityScores.dex) + } else { + // Le type d'armure n'est pas formalisé. On prend la valeur brute + if (monster.frontmatter.ac.armorType == 'custom') { + return monster.frontmatter.ac.value + } + + // Le monstre a une armure naturelle. + // CA = 10 + Armure naturelle + Dex + if (monster.frontmatter.ac.armorType == 'armure naturelle') { + armor = monster.frontmatter.ac.armorType + if (parseInt(monster.frontmatter.ac.value)) { + ac = ac + parseInt(monster.frontmatter.ac.value) + getModifier(monster.frontmatter.abilityScores.dex) + } else { + ac = ac + getModifier(monster.frontmatter.abilityScores.dex) + } + } else if (monster.frontmatter.ac.armorType == 'armure du mage') { + hasMageArmor = true + ac = ac + getModifier(monster.frontmatter.abilityScores.dex) + mageArmorAc = mageArmorAc + getModifier(monster.frontmatter.abilityScores.dex) + armor = mageArmorAc + ' avec armure du mage' + } else { + // Le monstre a un type d'armure défini. + // On calcule sa CA selon le type + let armorType = armorTypes[monster.frontmatter.ac.armorType] + + // Le type d'armure n'existe pas. On l'ignore. + // CA = 10 + Dex + if (!armorType) { + ac = ac + getModifier(monster.frontmatter.abilityScores.dex) + } else { + // L'armure n'impose pas de limite de Dex + armor = monster.frontmatter.ac.armorType + if (armorType.maxDex === false) { + ac = armorType.value + getModifier(monster.frontmatter.abilityScores.dex) + } else { + // La limite de Dex de l'armure est inférieure à la Dex du monstre + if (armorType.maxDex === 0) { + ac = armorType.value + } else if ((armorType.maxDex !== 0) && (armorType.maxDex <= getModifier(monster.frontmatter.abilityScores.dex))) { + ac = armorType.value + armorType.maxDex + } else { + ac = armorType.value + getModifier(monster.frontmatter.abilityScores.dex) + } + } + } + } + } + + + // Le monstre a un bouclier. Sa CA augmente de 2. + if (monster.frontmatter.ac.hasShield) { + ac = ac + 2 + mageArmorAc = mageArmorAc + 2 + if (armor != '') { + armor += ', ' + } + armor += 'bouclier' + + if (hasMageArmor) { + armor = mageArmorAc + ' avec armure du mage, bouclier' + } + } + + if (armor != '') { + ac += ' (' + armor + ')' + } + + return ac +} + +// Affiche les points de vie +export function displayHP (monster) { + if (monster.frontmatter.customHP) { + return monster.frontmatter.customHP + } else if (monster.frontmatter.hitDiceCount) { + let hitDieSize = 8 // Dé de vie moyen par défaut + if (monster.frontmatter.hitDieSize) { + hitDieSize = monster.frontmatter.hitDieSize + } else if (monster.frontmatter.size) { + hitDieSize = stats.sizes[monster.frontmatter.size].hitDie + } + let hitPointsBonus = 0 + if (monster.frontmatter.hitDiceCount > 1) { + hitPointsBonus = Math.floor(monster.frontmatter.hitDiceCount / 2) + } + let averageHP = monster.frontmatter.hitDiceCount * (hitDieSize / 2) + monster.frontmatter.hitDiceCount * getModifier(monster.frontmatter.abilityScores.con) + hitPointsBonus + let conMod = "" + if (getModifier(monster.frontmatter.abilityScores.con) != 0) { + conMod = monster.frontmatter.hitDiceCount * getModifier(monster.frontmatter.abilityScores.con) + conMod = displayBonus(conMod) + } + return averageHP + ' (' + monster.frontmatter.hitDiceCount + "d" + hitDieSize + conMod + ')' + } + return "" +} + + // Retourne le nombre de points de combat pour un indice de dangerosité export function getPCbyChallenge(challenge) { let challengeIndex = CHALLENGES.findIndex(item => item.value == challenge)