Skip to content

Commit

Permalink
[foundryvtt#1401] Add data model support for more restriction types, …
Browse files Browse the repository at this point in the history
…fix drop bug
  • Loading branch information
arbron committed Jan 15, 2023
1 parent 217b8c5 commit 4ecfe96
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@
"DND5E.SubclassDuplicateError": "A subclass with the identifier {identifier} already exists on this actor.",
"DND5E.SubclassMismatchWarn": "{name} subclass has no matching class with identifier '{class}'.",
"DND5E.SubclassName": "Subclass Name",
"DND5E.Subtype": "Subtype",
"DND5E.Supply": "Supply",
"DND5E.Target": "Target",
"DND5E.TargetAlly": "Ally",
Expand Down
2 changes: 1 addition & 1 deletion module/applications/advancement/item-choice-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class ItemChoiceConfig extends AdvancementConfig {
configuration.pool = await configuration.pool.reduce(async (pool, uuid) => {
const item = await fromUuid(uuid);
if ( this.advancement._validateItemType(item, {
restriction: configuration.type, spellLevel: configuration.spellLevel ?? false, error: false
restriction: configuration.type, spellLevel: configuration.restriction.level ?? false, error: false
}) ) return [...await pool, uuid];
return pool;
}, []);
Expand Down
4 changes: 2 additions & 2 deletions module/applications/advancement/item-choice-flow.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default class ItemChoiceFlow extends ItemGrantFlow {
const item = await Item.implementation.fromDropData(data);

try {
this.advancement._verifyItemType(item);
this.advancement._validateItemType(item);
} catch(err) {
return ui.notifications.error(err.message);
}
Expand All @@ -140,7 +140,7 @@ export default class ItemChoiceFlow extends ItemGrantFlow {
}

// If spell level is restricted to available level, ensure the spell is of the appropriate level
const spellLevel = this.advancement.configuration.spellLevel;
const spellLevel = this.advancement.configuration.restriction.level;
if ( (this.advancement.configuration.type === "spell") && spellLevel === "available" ) {
const maxSlot = this._maxSpellSlotLevel();
if ( item.system.level > maxSlot ) return ui.notifications.error(game.i18n.format(
Expand Down
6 changes: 5 additions & 1 deletion module/data/advancement/item-choice.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export default class ItemChoiceConfigurationData extends foundry.abstract.DataMo
}),
pool: new foundry.data.fields.ArrayField(new foundry.data.fields.StringField(), {label: "DOCUMENT.Items"}),
spell: new foundry.data.fields.EmbeddedDataField(SpellConfigurationData, {nullable: true, initial: null}),
spellLevel: new foundry.data.fields.StringField({label: "DND5E.SpellLevel"})
restriction: new foundry.data.fields.SchemaField({
type: new foundry.data.fields.StringField({label: "DND5E.Type"}),
subtype: new foundry.data.fields.StringField({label: "DND5E.Subtype"}),
level: new foundry.data.fields.StringField({label: "DND5E.SpellLevel"})
}, {label: ""})
};
}
}
4 changes: 2 additions & 2 deletions module/data/item/feat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default class FeatData extends SystemDataModel.mixin(
static defineSchema() {
return this.mergeSchema(super.defineSchema(), {
type: new foundry.data.fields.SchemaField({
value: new foundry.data.fields.StringField({required: true}),
subtype: new foundry.data.fields.StringField({required: true})
value: new foundry.data.fields.StringField({required: true, label: "DND5E.Type"}),
subtype: new foundry.data.fields.StringField({required: true, label: "DND5E.Subtype"})
}, {label: "DND5E.ItemFeatureType"}),
requirements: new foundry.data.fields.StringField({required: true, nullable: true, label: "DND5E.Requirements"}),
recharge: new foundry.data.fields.SchemaField({
Expand Down
2 changes: 1 addition & 1 deletion module/documents/advancement/item-choice.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class ItemChoiceAdvancement extends ItemGrantAdvancement {
_validateItemType(item, { restriction, spellLevel, error=true }={}) {
super._validateItemType(item, { error });
restriction ??= this.configuration.type;
spellLevel ??= this.configuration.spellLevel;
spellLevel ??= this.configuration.restriction.level;

// Type restriction is set and the item type does not match the selected type
if ( restriction && (restriction !== item.type) ) {
Expand Down
4 changes: 2 additions & 2 deletions templates/advancement/item-choice-config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<div class="form-group">
<label>{{localize "DND5E.SpellLevel"}}</label>
<div class="form-fields">
<select name="configuration.spellLevel">
{{#select configuration.spellLevel}}
<select name="configuration.restriction.level">
{{#select configuration.restriction.level}}
<option value="">&mdash;</option>
{{#each CONFIG.spellLevels as |label key|}}
<option value="{{key}}">{{label}}</option>
Expand Down

0 comments on commit 4ecfe96

Please sign in to comment.