Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronized tracks in Assets and assets summary in Moves #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Ironsworn/Ironsworn.css
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,7 @@
}
.charsheet .assets.assets-summary .repitem {
width: 100%;
margin-bottom: -5px;
}
.charsheet fieldset.assets-summary~.repcontrol {
display: none;
Expand Down
16 changes: 15 additions & 1 deletion Ironsworn/Ironsworn.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Ironsworn/src/app/components/assets/asset-builder.pug
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mixin description(asset, type, key)
- var translationDesc = `asset-description-${key}`
.asset-description-text(data-i18n=translationDesc)!=locals.translations[translationDesc]

mixin track(number, name)
mixin track(number, name, isSummary)
.asset-track-wrapper
-
var currentTrack = 0
Expand All @@ -75,7 +75,7 @@ mixin track(number, name)
.asset-track-box-display=0
else
.asset-track-box-display=`+ ${currentTrack}`
input(type='radio' name=`attr_assettrack_${transformedName}` value=`${currentTrack}`)
input(type='radio' name=`attr_assettrack_${transformedName + (isSummary ? '_summary' : '')}` value=`${currentTrack}`)
- currentTrack++

mixin combatTalentBuilder
Expand Down Expand Up @@ -142,7 +142,7 @@ mixin ritualBuilder
each ability in [ 1, 2, 3 ]
+ability(asset, ability, key)
if asset.track
+track(asset.track, key)
+track(asset.track, key, false)

mixin pathBuilder
- var assetType = 'path'
Expand All @@ -158,4 +158,4 @@ mixin pathBuilder
each ability in [ 1, 2, 3 ]
+ability(asset, ability, key)
if asset.track
+track(asset.track, key)
+track(asset.track, key, false)
8 changes: 4 additions & 4 deletions Ironsworn/src/app/components/assets/asset-custom.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ mixin builderTitles(parent, child)
value=''
)

mixin assetTrackBox(parent, value)
mixin assetTrackBox(parent, value, isSummary)
.asset-track-box
if value == 0
.asset-track-box-display 0
else
.asset-track-box-display='+ ' + value
input(type='radio' name=`attr_custom-asset-track-${parent}` value=`${value}`)
input(type='radio' name=`attr_custom-asset-track-${parent + (isSummary ? '_summary' : '')}` value=`${value}`)

mixin abilityView(value)
input(
Expand Down Expand Up @@ -138,7 +138,7 @@ mixin customAssets
.asset-track-wrapper.custom-track
- var currentBox = 0
while currentBox <= dropdownNumber
+assetTrackBox(dropdownNumber, currentBox++)
+assetTrackBox(dropdownNumber, currentBox++, false)

mixin customSummaryBuilder
input.asset-summary-custom.hide-element(type='checkbox' name='attr_assetcustom')
Expand Down Expand Up @@ -168,7 +168,7 @@ mixin customSummaryBuilder
.asset-track-wrapper.custom-track
- var currentBox = 0
while currentBox <= dropdownNumber
+assetTrackBox(dropdownNumber, currentBox++)
+assetTrackBox(dropdownNumber, currentBox++, true)

mixin summaryAbilityView(value)
//- text only
Expand Down
6 changes: 3 additions & 3 deletions Ironsworn/src/app/components/assets/asset-summary-builder.pug
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mixin companionSummaryBuilder()
.asset-track-box-display=value
else
.asset-track-box-display=`+ ${value}`
input(type='radio' name=`attr_assettrack_${key}` value=`${value}`)
input(type='radio' name=`attr_assettrack_${key}_summary` value=`${value}`)

mixin ritualSummaryBuilder()
- var assetType = 'ritual'
Expand All @@ -50,7 +50,7 @@ mixin ritualSummaryBuilder()
each ability in [ 1, 2, 3 ]
+summaryAbility(asset, ability, key)
if asset.track
+track(asset.track, key)
+track(asset.track, key, true)

mixin pathSummaryBuilder()
- var assetType = 'path'
Expand All @@ -64,7 +64,7 @@ mixin pathSummaryBuilder()
each ability in [ 1, 2, 3 ]
+summaryAbility(asset, ability, key)
if asset.track
+track(asset.track, key)
+track(asset.track, key, true)

mixin summaryAbility(asset, number, key)
if asset.firstAbilityChecked && number == 1
Expand Down
1 change: 1 addition & 0 deletions Ironsworn/src/app/components/assets/assets.styl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ div.assets
padding: 0px 4px 0px 0px
& .repitem
width 100%
margin-bottom -5px // for some reason there is a 5px bottom margin when in roll20

fieldset.assets-summary~.repcontrol
display none
Expand Down
14 changes: 14 additions & 0 deletions Ironsworn/src/app/workers/scripts/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ on('change:repeating_assets:track-dropdown', function (values) {
});
});

on('change:repeating_assets', function (eventInfo) {
// sync assets and summary tracks
const attrName = eventInfo.sourceAttribute
if (attrName.includes('_assettrack_') || attrName.includes('_custom-asset-track-')) {
const summarySuffix = '_summary';
const syncedAttribute = attrName.endsWith(summarySuffix)
? attrName.substring(0, attrName.length - summarySuffix.length)
: attrName + summarySuffix;
setAttrs({
[syncedAttribute]: eventInfo.newValue
});
}
});

21 changes: 15 additions & 6 deletions Ironsworn/src/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let currentRepeatingContext = undefined; // stores the repeating section info wh
window.getAttrs = (attributeNames, fn) => {
const values = {};
for (attributeName of attributeNames) {
const attribute = createAttribute(attributeName);
const attribute = buildAttribute(attributeName);
values[attributeName] = attributeStore.getValue(attribute.fullName);
}

Expand All @@ -57,7 +57,7 @@ window.setAttrs = (attributeValues, isInit) => {

for (const attributeName in attributeValues) {
// build attribute
const attribute = createAttribute(attributeName);
const attribute = buildAttribute(attributeName);
attribute.currentValue = attributeStore.getValue(attribute.fullName);
attribute.newValue = attributeValues[attributeName];

Expand Down Expand Up @@ -98,6 +98,12 @@ window.setAttrs = (attributeValues, isInit) => {

let input = inputParent.find(`input[name='${inputName}'], input[data-attrname='${shortName}'], select[name='${inputName}'], textarea[name='${inputName}'],
input[name='${inputName.toLowerCase()}'], input[data-attrname='${shortName.toLowerCase()}'], select[name='${inputName.toLowerCase()}'], textarea[name='${inputName.toLowerCase()}']`);

if (currentRepeatingContext?.skippedInputUpdate === attribute.fullName) { // roll20 does not sync radio inputs in sections with same name
console.log(`Skipped radio input update for ${inputName}`);
return;
}

if (!input.prop('disabled')) { // it seems roll20 explicitly does not update values of disabled inputs (perhaps linked to autocalc inputs needing to be disabled)
input.val([attribute.newValue]);
}
Expand Down Expand Up @@ -151,7 +157,7 @@ window.setAttrs = (attributeValues, isInit) => {
}
};

function createAttribute(attributeName) {
function buildAttribute(attributeName) {
// supported names are:
// <attribute_name>
// <sectionName>_<attributeShortname> with sectionName = repeating_<any>
Expand Down Expand Up @@ -300,7 +306,7 @@ function instrumentInputs(root) {
}

// init the attributes values in the store
let attributeName = input.attr('data-attrname') ?? getInputAttributeName(input);
let attributeName = getInputAttributeName(input);

const repItem = input.parents('.repitem');
if (repItem.length > 0) {
Expand Down Expand Up @@ -330,7 +336,7 @@ function instrumentInputs(root) {
}

// store the value
let attributeName = input.attr('data-attrname') ?? getInputAttributeName(input);
let attributeName = getInputAttributeName(input);

const repItem = input.parents('.repitem');
if (repItem.length > 0) {
Expand All @@ -341,6 +347,9 @@ function instrumentInputs(root) {

attributeName = `${currentRepeatingContext.sectionName}_${currentRepeatingContext.rowId}_${attributeName}`;

if (input.attr('type') == 'radio') { // roll20 does not sync radio inputs in sections with same name
currentRepeatingContext.skippedInputUpdate = attributeName;
}
} else {
currentRepeatingContext = undefined;
}
Expand Down Expand Up @@ -422,5 +431,5 @@ function instrumentInputs(root) {
}

function getInputAttributeName(input) {
return input.attr('name').substring(ATTR_PREFIX.length);
return input.attr('data-attrname') ?? input.attr('name').substring(ATTR_PREFIX.length);
}