Fix issue #89: Traits and items are mixed up
All checks were successful
Test / test (push) Successful in 2s
All checks were successful
Test / test (push) Successful in 2s
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { numberOr, asText, plainText, stringList } = require('./foundry-fields');
|
||||
const { isFoundryGearType } = require('./item-foundry');
|
||||
|
||||
// D&D 5e keeps an actor's background, species, class and subclass as a reference to an
|
||||
// embedded item: `system.details.background` and friends hold that item's id, and the
|
||||
@@ -169,8 +170,11 @@ function foundryActorToCharacter(foundryActor) {
|
||||
armorClass: numberOr(attributes.ac?.value ?? attributes.ac, 10),
|
||||
speed: numberOr(movement.walk ?? movement.value, 30),
|
||||
proficiencies: foundryProficiencies || asText(savedDragonrollFields.proficiencies),
|
||||
// What the character carries: gear, and gear only (Syndria98/dragonroll#89). A feat
|
||||
// is a trait — its tab shows it — and a race is the species; standing them in the
|
||||
// inventory next to the longswords is how traits and items got mixed up.
|
||||
inventory: items
|
||||
.filter((item) => !['class', 'subclass', 'background', 'spell'].includes(item.type))
|
||||
.filter((item) => isFoundryGearType(item.type))
|
||||
.map((item) => ({
|
||||
name: asText(item.name).trim(),
|
||||
quantity: numberOr(item.system?.quantity, 1),
|
||||
|
||||
@@ -23,6 +23,14 @@ const NON_GEAR_FOUNDRY_TYPES = new Set([
|
||||
'spell', 'class', 'subclass', 'background', 'feat', 'race', 'species', 'status', 'spellbook', 'language'
|
||||
]);
|
||||
|
||||
// Whether a Foundry document of this type is gear: something a character carries. Traits,
|
||||
// species, spells and the rest are documents of the world that mean something else on a
|
||||
// Dragonroll sheet — a feat is a trait and a race is a species — so they stand in the
|
||||
// character's own fields, never in its inventory (Syndria98/dragonroll#89).
|
||||
function isFoundryGearType(type) {
|
||||
return !NON_GEAR_FOUNDRY_TYPES.has(asText(type).toLowerCase().trim());
|
||||
}
|
||||
|
||||
// Item categories the Dragonroll Item model accepts.
|
||||
const CATEGORIES = ['weapon', 'armor', 'shield', 'adventuring-gear', 'magic-item', 'consumable', 'tool', 'treasure', 'other'];
|
||||
|
||||
@@ -107,4 +115,4 @@ function foundryItemToItemData(foundryItem) {
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { foundryItemToItemData };
|
||||
module.exports = { foundryItemToItemData, isFoundryGearType };
|
||||
|
||||
Reference in New Issue
Block a user