diff --git a/Shadowrun5thEdition/Shadowrun5thEdition.html b/Shadowrun5thEdition/Shadowrun5thEdition.html index 51e3f03c1a..07b9aabf92 100644 --- a/Shadowrun5thEdition/Shadowrun5thEdition.html +++ b/Shadowrun5thEdition/Shadowrun5thEdition.html @@ -1,5 +1,5 @@ - +
@@ -435,12 +435,12 @@ - +
- @@ -452,7 +452,7 @@ - @@ -466,7 +466,7 @@ x
- @@ -564,16 +564,16 @@
@@ -588,12 +588,12 @@ - +
-
- @@ -605,7 +605,7 @@ - @@ -620,19 +620,19 @@
@@ -647,12 +647,12 @@ - +
-
- @@ -664,7 +664,7 @@ - @@ -679,19 +679,19 @@
@@ -3493,6 +3493,11 @@ const onepointthreefive = () => { return values } + const getRepeatingSection = triggerName => { + const split = triggerName.split('_'); + return `${split[0]}_${split[1]}_${split[2]}` + } + const calculateLimitTotal = (values, type) => { const attributes = sheetAttribues[`${type}Limits`]; values.essence ? Math.ceil(values.essence) || 0 : false; @@ -4147,78 +4152,102 @@ const onepointthreefive = () => { }); //REFACTORED Skills - sheetAttribues.repeatingSkills.forEach(field => { - on(`change:repeating_${field}`, eventinfo => { - const source = eventinfo.sourceAttribute; - const type = eventinfo.sourceType; - if (source.includes("rating")) { - getAttrs([`${field}_rating`, `${field}_rating_modifier`], (v) => { - const bas = parseInt(v[`${field}_rating`]) || 0; - const mod = parseInt(v[`${field}_rating_modifier`]) || 0; - const tot = bas + mod; - setAttrs({ - [`${field}_dicepool`]: tot, - [`${field}_display_rating`]: (mod === 0) ? bas : `${bas} (${tot})` - }); - }); - } else if (source.includes("attribute") && type === "player") { - getAttrs([`${source}`], (v) => { - const attribute = v[`${source}`].slice(2, -1); - const translation = getTranslationByKey(`${attribute}`); - setAttrs({ - [`${field}_display_attribute`]: translation - }); - }); - } else if (source.includes("limit") && type === "player") { - const limit = eventinfo.newValue.slice(2, -1); - if (eventinfo.newValue === "none") { - setAttrs({ - [`${field}_display_limit`]: "" - }); - } else { - const translation = getTranslationByKey(`${limit}`); - setAttrs({ - [`${field}_display_limit`]: `${translation} ${eventinfo.newValue}` - }); - } - } else if (source.includes("specialization") && type === "player") { - getAttrs([`${source}`], (v) => { - const bas = v[`${source}`]; - const size = bas.length; - let display = (size > 0 && size <= 20) ? `(${bas})` : (size > 20 ) ? "(" + bas.slice(0, 20) + "...)" : " "; - setAttrs({ - [`${eventinfo.triggerName}_display_specialization`]: display - }); - }); - } else if (source.includes("skill") && type === "player") { - getAttrs([`${source}`], (v) => { - console.log(eventinfo) - const bas = v[`${source}`]; - const size = bas.length; - let display = (size > 0 && size <= 20) ? bas : (size > 20 ) ? bas.slice(0, 20) + "..." : " "; + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:rating change:repeating_${field}:rating_modifier`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); - console.log(display) - console.log(field) - setAttrs({ - [`${eventinfo.triggerName}_display`]: display - }); - }); - } else if (source.includes("dicepool") && type === "player") { - getAttrs([`${source}`, `${field}_skill`], (v) => { - const skill = v[`${field}_skill`]; - let lowercase = skill.toLowerCase(); - let removeGroup = (lowercase.includes("group")) ? lowercase.slice(0, -6) : lowercase; - let skillSet = (removeGroup.includes(" ")) ? removeGroup.replace(/ /g,"") : removeGroup; - setAttrs({ - [`${skillSet}`]: v[`${source}`] - }); - }); - } else { - console.log(`Change to ${field} did not set attr`); - }; - }); - }); + getAttrs([`${section}_rating`, `${section}_rating_modifier`], value => { + const numbers = parseIntegers(value); + const base = numbers[`${section}_rating`]; + const total = calculateSum(Object.values(numbers)); + setAttrs({ + [`${section}_dicepool`]: total, + [`${section}_display_rating`]: numbers[`${section}_rating_modifier`] === 0 ? base : `${base} (${total})` + }) + }) + }); + }); + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:attribute`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + const attribute = eventinfo.newValue.slice(2, -1) + const translation = getTranslationByKey(`${attribute}`) + + setAttrs({ + [`${section}_display_attribute`]: translation + }); + } + }) + }) + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:limit`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + const limit = eventinfo.newValue.slice(2, -1); + + setAttrs({ + [`${section}_display_limit`]: eventinfo.newValue === "none" ? "" : `${getTranslationByKey(`${limit}`)} ${eventinfo.newValue}` + }); + } + }) + }) + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:specialization`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + const base = eventinfo.newValue; + const size = base.length; + const display = size > 0 && size <= 20 ? `(${base})` : size > 20 ? "(" + base.slice(0, 20) + "...)" : " "; + + setAttrs({ + [`${section}_display_specialization`]: display + }); + } + }) + }) + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:skill`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + const base = eventinfo.newValue; + const size = base.length; + const display = size > 0 && size <= 20 ? base : size > 20 ? base.slice(0, 20) + "...)" : " "; + + setAttrs({ + [`${section}_display`]: display + }); + } + }) + }) + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:dicepool`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + getAttrs([`${section}_skill`], value => { + let skill = value[`${section}_skill`]; + skill = skill.toLowerCase(); + skill = skill.includes("group") ? skill.split(' group')[0] : skill + skill = skill.includes(" ") ? skill.replace(/ /g,"") : skill + + setAttrs({ + [`${skill}`]: eventinfo.newValue + }); + }) + } + }) + }) //Setting the Default attribute name for default skill on("change:default_attribute", (eventinfo) => { diff --git a/Shadowrun5thEdition/Shadowrun5thEdition.pug b/Shadowrun5thEdition/Shadowrun5thEdition.pug index e50b4d1a85..85e3f80b29 100644 --- a/Shadowrun5thEdition/Shadowrun5thEdition.pug +++ b/Shadowrun5thEdition/Shadowrun5thEdition.pug @@ -1,4 +1,4 @@ -input(name='attr_version' type='hidden' value='4.0') +input(name='attr_version' type='hidden' value='4.01') //- CHARACTER SHEET PAGE input.sheet_type(name='attr_sheet_type' type='hidden' value='pc') @@ -12,7 +12,6 @@ include src/pug/_mixins.pug //- VARIABLES include src/pug/_variables.pug - .pc .tabs img(alt='Shadowrun black and metallic logo' src='https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/Shadowrun5thEdition/images/ShadowrunLogo.png') @@ -74,8 +73,8 @@ include src/pug/_variables.pug +attributeSelect('Agility') select.limit-select(name='attr_limit' title='Skill limit') +limitSelect('Physical') - fieldset(class='repeating_' + key) - - const skillsRepeatingSection = `@{repeating_${val[0]}`+'_${x}'; + fieldset(class=`repeating_${key}`) + - const skillsRepeatingSection = `@{repeating_${key}_`+'${x}'; input(name='attr_display' type='hidden') input(name='attr_display_rating' type='hidden') @@ -84,36 +83,36 @@ include src/pug/_variables.pug input(name='attr_display_attribute' type='hidden' value=val[1]) input(name='attr_dicepool' type='hidden' value='0') - input.settings-flag(name='attr_flag' type='hidden' value='settings' title=`${repeatingSection}_flag}`) + input.settings-flag(name='attr_flag' type='hidden' value='settings' title=`${skillsRepeatingSection}_flag}`) .buttons //- SKILL BUTTON +skillButton(false) //- SPECILIZATION BUTTON +skillButton(true) span.text-align-center(name='attr_display_rating' title=`${skillsRepeatingSection}_display_rating}`) - select.attribute-select(name='attr_attribute' title=`${repeatingSection}_attribute}`) + select.attribute-select(name='attr_attribute' title=`${skillsRepeatingSection}_attribute}`) +attributeSelect(val[1]) - select.limit-select(name='attr_limit' value='physical_limit' title=`${repeatingSection}_limit}`) + select.limit-select(name='attr_limit' value='physical_limit' title=`${skillsRepeatingSection}_limit}`) +limitSelect(val[2]) +repeatingSectionFlags() .settings if key === 'active' - select.skill-select(name='attr_skill' value='Close Combat Group' title=`${repeatingSection}_skill}`) + select.skill-select(name='attr_skill' value='Close Combat Group' title=`${skillsRepeatingSection}_skill}`) include src/html/skillselect.html else label(data-i18n-title='skill' title='skill') - input(name='attr_skill' placeholder=key type='text' title=`${repeatingSection}_skill}`) + input(name='attr_skill' placeholder=key type='text' title=`${skillsRepeatingSection}_skill}`) label(data-i18n-title='rating' title='rating') - input(name='attr_rating' min='0' placeholder='0' type='number' title=`${repeatingSection}_rating}`) + input(name='attr_rating' min='0' placeholder='0' type='number' title=`${skillsRepeatingSection}_rating}`) label(data-i18n-title='ratingmodifier' title='Rating Modifier') span(data-i18n='ratingmodifier') Rating Modifier - input(name='attr_rating_modifier' placeholder='0' type='number' title=`${repeatingSection}_rating_modifier}`) + input(name='attr_rating_modifier' placeholder='0' type='number' title=`${skillsRepeatingSection}_rating_modifier}`) label(data-i18n-title='specialization' title='specialization') span(data-i18n='specialization') specialization - input(name='attr_specialization}' placeholder='Specalizations' type='text' title=`${repeatingSection}_specialization}`) + input(name='attr_specialization' placeholder='Specalizations' type='text' title=`${skillsRepeatingSection}_specialization}`) label(data-i18n-title='notes' title='notes') span(data-i18n='notes') Notes - textarea(name='attr_notes' value='' placeholder='Notes' title=`${repeatingSection}_notes}`) + textarea(name='attr_notes' value='' placeholder='Notes' title=`${skillsRepeatingSection}_notes}`) //- CORE TAB diff --git a/Shadowrun5thEdition/src/js/helpers.js b/Shadowrun5thEdition/src/js/helpers.js index bcdcd5c54a..2030c7af8f 100644 --- a/Shadowrun5thEdition/src/js/helpers.js +++ b/Shadowrun5thEdition/src/js/helpers.js @@ -12,6 +12,11 @@ return values } + const getRepeatingSection = triggerName => { + const split = triggerName.split('_'); + return `${split[0]}_${split[1]}_${split[2]}` + } + const calculateLimitTotal = (values, type) => { const attributes = sheetAttribues[`${type}Limits`]; values.essence ? Math.ceil(values.essence) || 0 : false; diff --git a/Shadowrun5thEdition/src/js/scripts.js b/Shadowrun5thEdition/src/js/scripts.js index 43a57614d9..8fe44c2b5f 100644 --- a/Shadowrun5thEdition/src/js/scripts.js +++ b/Shadowrun5thEdition/src/js/scripts.js @@ -449,78 +449,102 @@ }); //REFACTORED Skills - sheetAttribues.repeatingSkills.forEach(field => { - on(`change:repeating_${field}`, eventinfo => { - const source = eventinfo.sourceAttribute; - const type = eventinfo.sourceType; - if (source.includes("rating")) { - getAttrs([`${field}_rating`, `${field}_rating_modifier`], (v) => { - const bas = parseInt(v[`${field}_rating`]) || 0; - const mod = parseInt(v[`${field}_rating_modifier`]) || 0; - const tot = bas + mod; - setAttrs({ - [`${field}_dicepool`]: tot, - [`${field}_display_rating`]: (mod === 0) ? bas : `${bas} (${tot})` - }); - }); - } else if (source.includes("attribute") && type === "player") { - getAttrs([`${source}`], (v) => { - const attribute = v[`${source}`].slice(2, -1); - const translation = getTranslationByKey(`${attribute}`); - setAttrs({ - [`${field}_display_attribute`]: translation - }); - }); - } else if (source.includes("limit") && type === "player") { - const limit = eventinfo.newValue.slice(2, -1); - if (eventinfo.newValue === "none") { - setAttrs({ - [`${field}_display_limit`]: "" - }); - } else { - const translation = getTranslationByKey(`${limit}`); - setAttrs({ - [`${field}_display_limit`]: `${translation} ${eventinfo.newValue}` - }); - } - } else if (source.includes("specialization") && type === "player") { - getAttrs([`${source}`], (v) => { - const bas = v[`${source}`]; - const size = bas.length; - let display = (size > 0 && size <= 20) ? `(${bas})` : (size > 20 ) ? "(" + bas.slice(0, 20) + "...)" : " "; - setAttrs({ - [`${eventinfo.triggerName}_display_specialization`]: display - }); - }); - } else if (source.includes("skill") && type === "player") { - getAttrs([`${source}`], (v) => { - console.log(eventinfo) - const bas = v[`${source}`]; - const size = bas.length; - let display = (size > 0 && size <= 20) ? bas : (size > 20 ) ? bas.slice(0, 20) + "..." : " "; + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:rating change:repeating_${field}:rating_modifier`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); - console.log(display) - console.log(field) - setAttrs({ - [`${eventinfo.triggerName}_display`]: display - }); - }); - } else if (source.includes("dicepool") && type === "player") { - getAttrs([`${source}`, `${field}_skill`], (v) => { - const skill = v[`${field}_skill`]; - let lowercase = skill.toLowerCase(); - let removeGroup = (lowercase.includes("group")) ? lowercase.slice(0, -6) : lowercase; - let skillSet = (removeGroup.includes(" ")) ? removeGroup.replace(/ /g,"") : removeGroup; - setAttrs({ - [`${skillSet}`]: v[`${source}`] - }); - }); - } else { - console.log(`Change to ${field} did not set attr`); - }; - }); - }); + getAttrs([`${section}_rating`, `${section}_rating_modifier`], value => { + const numbers = parseIntegers(value); + const base = numbers[`${section}_rating`]; + const total = calculateSum(Object.values(numbers)); + setAttrs({ + [`${section}_dicepool`]: total, + [`${section}_display_rating`]: numbers[`${section}_rating_modifier`] === 0 ? base : `${base} (${total})` + }) + }) + }); + }); + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:attribute`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + const attribute = eventinfo.newValue.slice(2, -1) + const translation = getTranslationByKey(`${attribute}`) + + setAttrs({ + [`${section}_display_attribute`]: translation + }); + } + }) + }) + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:limit`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + const limit = eventinfo.newValue.slice(2, -1); + + setAttrs({ + [`${section}_display_limit`]: eventinfo.newValue === "none" ? "" : `${getTranslationByKey(`${limit}`)} ${eventinfo.newValue}` + }); + } + }) + }) + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:specialization`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + const base = eventinfo.newValue; + const size = base.length; + const display = size > 0 && size <= 20 ? `(${base})` : size > 20 ? "(" + base.slice(0, 20) + "...)" : " "; + + setAttrs({ + [`${section}_display_specialization`]: display + }); + } + }) + }) + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:skill`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + const base = eventinfo.newValue; + const size = base.length; + const display = size > 0 && size <= 20 ? base : size > 20 ? base.slice(0, 20) + "...)" : " "; + + setAttrs({ + [`${section}_display`]: display + }); + } + }) + }) + + sheetAttribues.repeatingSkills.forEach(field => { + on(`change:repeating_${field}:dicepool`, eventinfo => { + const section = getRepeatingSection(eventinfo.triggerName); + + if (eventinfo.sourceType === "player") { + getAttrs([`${section}_skill`], value => { + let skill = value[`${section}_skill`]; + skill = skill.toLowerCase(); + skill = skill.includes("group") ? skill.split(' group')[0] : skill + skill = skill.includes(" ") ? skill.replace(/ /g,"") : skill + + setAttrs({ + [`${skill}`]: eventinfo.newValue + }); + }) + } + }) + }) //Setting the Default attribute name for default skill on("change:default_attribute", (eventinfo) => {