Skip to content
1 change: 1 addition & 0 deletions src/module/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PBTA.attrTypes = [
"Resource",
"Text",
"LongText",
"TextMany",
"Checkbox",
"ListMany",
"ListOne",
Expand Down
55 changes: 47 additions & 8 deletions src/module/forms/sheet-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ export class PbtaSettingsConfigDialog extends FormApplication {
let newConfig = game.pbta.utils.convertSheetConfig(duplicateConfig);

let configDiff = {
add: [],
del: [],
max: [],
softType: [],
hardType: [],
safe: [],
options: [],
values: []
// change types that don't delete any data from the world
add: [], // adding entirely new attributes, actor types, etc
max: [], // changing the max or steps values on a Resource, Clock, XP, etc
softType: [], // attribute type changes with no data loss, eg Resource->Clock
safe: [], // cosmetic changes to sheet labels or descriptions, with no data model changes
options: [], // adding new options to a ListOne or ListMany attribute

// destructive changes that can delete data and trigger extra warnings in the UI
del: [], // removing attributes, options from a ListMany, etc; destructive change
hardType: [], // type changes where data cannot be preserved, eg Resource->ListOne
values: [] // removing options from a ListOne or ListMany
};
let updatesDiff = {
character: {},
Expand Down Expand Up @@ -346,7 +349,43 @@ export class PbtaSettingsConfigDialog extends FormApplication {
configDiff.safe.push(`${actorType}.${attrGroup}.${attr}.showResults`);
updatesDiff[actorType][`system.${attrGroup}.${attr}.showResults`] = newGroup[attr].showResults ?? true;
}
} else if (newType === "TextMany") {
console.log("in new type code", newGroup[attr], oldGroup[attr]);
// TODO: lines should have a default value somewhere? or error if it's missing, eg
// check lines val here
if (newGroup[attr]?.lines !== oldGroup[attr]?.lines) {
// adding lines is safe, but deleting them can delete actor data
//
//
// TODO: don't put list value changes into the options list
// INSTEAD: detect if any actors have data in more than (newList) fields; if they
// do, push that into the del list
if (newGroup[attr]?.lines > oldGroup[attr]?.lines) {
configDiff.options.push(`${actorType}.${attrGroup}.${attr}`);
} else {
configDiff.del.push(`${actorType}.${attrGroup}.${attr}`);

}
updatesDiff[actorType][`system.${attrGroup}.${attr}.lines`] = newGroup[attr]?.lines ?? 3; // note default value here

// newGroup[attr]?.values = Array(newGroup[attr]?.lines).fill("");

// TODO: preserve as many values as possible, don't wipe them out like this
configDiff.values.push(`${actorType}.${attrGroup}.${attr}`);
updatesDiff[actorType][`system.${attrGroup}.${attr}.values`] = newGroup[attr]?.values ?? Array(newGroup[attr]?.lines).fill("");

// const oldClone = foundry.utils.duplicate(oldGroup);
// for (let optK of Object.keys(newGroup[attr].values)) {
// delete oldClone[attr]?.values[optK];
// }
// for (let optK of Object.keys(oldClone[attr]?.values)) {
// configDiff.del.push(`${actorType}.${attrGroup}.${attr}.values.${optK}`);
// updatesDiff[actorType][`system.${attrGroup}.${attr}.values`][`-=${optK}`] = null;
// }

}
}

}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/module/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export function validateSheetConfig(sheetConfig) {
export function parseTomlString(tomlString) {
let computed = {};
let errors = [];

// Try to retrieve the TOML string.
if (tomlString) {
// Get the parsed value.
Expand Down Expand Up @@ -446,6 +445,8 @@ export function convertAttr(attrGroup, position) {
attr.playbook = attrValue.playbook ?? null;
attr.limited = attrValue.limited ?? false;
attr.position = attrValue.position ?? position;
// TODO is this a good default value?
attr.lines = attrValue.lines ?? null;

if (!attrValue.type) {
// If an object structure was used and no type was specified, it's invalid.
Expand Down Expand Up @@ -479,6 +480,10 @@ export function convertAttr(attrGroup, position) {
attr.value = attrValue.default ?? "";
break;

case "TextMany":
attr.values = attrValue.default ?? Array(attr.lines).fill("");
break;

case "Roll":
attr.value = attrValue.default ?? "";
attr.showResults = attrValue.showResults ?? true;
Expand Down
10 changes: 9 additions & 1 deletion src/styles/src/global/base/_cell.scss
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,12 @@
color: #4878a8;
justify-self: stretch;
}
}
}

.cell--TextMany {
> input[type=text] {
margin-bottom: 5px;
text-align: left;
font-size: var(--font-size-14);
}
}
9 changes: 6 additions & 3 deletions src/templates/actors/parts/actor-attributes.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@
<span style="grid-column-end: span {{attr.stepsPositive}}" class="cell__track__label">{{attr.positive.label}}</span>
{{/if}}
</div>

{{!-- Fallback to a text field. --}}
{{else if (eq attr.type "TextMany")}}
{{#each attr.values as |value valueKey|}}
<input type="text" class="input input--{{key}}" name="system.attributes.{{key}}.values.{{valueKey}}" value="{{value}}"/>
{{/each}}
{{!-- Fallback to a text field. --}}
{{else}}
<input type="text" class="input input--{{key}}" name="system.attributes.{{key}}.value" value="{{attr.value}}"/>
{{/if}}
</div>
{{/each}}
</div>
{{/if}}
{{/if}}