Skip to content

Commit

Permalink
fix(import): Allow previous name to import spells for monster
Browse files Browse the repository at this point in the history
closes #439
  • Loading branch information
symposion committed Mar 28, 2017
1 parent 94fffcb commit 6cb8821
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/5eSRDData.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion lib/entity-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = class EntityLookup {
this.entityOrder = [];
this.entities = {};
this.noWhiteSpaceEntities = {};
this.aliases = {};
this.entityProcessors = {};
this.versionCheckers = {};
this.processedEntityGroupNames = [];
Expand All @@ -21,6 +22,7 @@ module.exports = class EntityLookup {
configureEntity(entityName, processors, versionChecker) {
this.entityOrder.push(entityName);
this.entities[entityName] = {};
this.aliases[entityName] = {};
this.noWhiteSpaceEntities[entityName] = {};
this.entityProcessors[entityName] = processors || [];
this.versionCheckers[entityName] = versionChecker || _.constant(true);
Expand Down Expand Up @@ -93,7 +95,7 @@ module.exports = class EntityLookup {
const processed = _.reduce(this.entityProcessors[type], Utils.executor, {
entity,
lookup: (otherType, name) =>
(name ? this.entities[otherType][name.toLowerCase()] : _.values(this.entities[otherType])),
(name ? this.findEntity(otherType, name) : _.values(this.entities[otherType])),
type,
previousName,
source: entitiesObject.name,
Expand All @@ -111,6 +113,7 @@ module.exports = class EntityLookup {
delete this.entities[type][key];
delete this.noWhiteSpaceEntities[type][key.replace(/\s+/g, '')];
key = processed.entity.name.toLowerCase();
this.aliases[type][previousName.toLowerCase()] = key;
}
this.entities[type][key] = processed.entity;
this.noWhiteSpaceEntities[type][key.replace(/\s+/g, '')] = processed.entity;
Expand Down Expand Up @@ -180,6 +183,9 @@ module.exports = class EntityLookup {
if (!found && tryWithoutWhitespace) {
found = this.noWhiteSpaceEntities[type][key.replace(/\s+/g, '')];
}
if (!found && this.aliases[type][key]) {
return this.findEntity(type, this.aliases[type][key], tryWithoutWhitespace);
}
return found && Utils.deepClone(found);
}

Expand Down
8 changes: 8 additions & 0 deletions lib/modules/spell-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ module.exports = class SpellManager extends ShapedModule {
});
spell.lists = _.union(spell.lists, newLists);
});
if (spellEntityInfo.previousName !== spell.name) {
const re = new RegExp(spellEntityInfo.previousName, 'ig');
_.chain(spellEntityInfo.lookup('monsters'))
.pluck('traits')
.flatten()
.filter(trait => trait && trait.name.toLowerCase().includes('spellcasting'))
.forEach(trait => (trait.text = trait.text.replace(re, spell.name.toLowerCase())));
}
return spellEntityInfo;
};
}
Expand Down

0 comments on commit 6cb8821

Please sign in to comment.