-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2015 from arbron/advancement/item-choice-rework
[#1401] Item Choice Advancement
- Loading branch information
Showing
23 changed files
with
718 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import AdvancementConfig from "./advancement-config.mjs"; | ||
|
||
/** | ||
* Configuration application for item choices. | ||
*/ | ||
export default class ItemChoiceConfig extends AdvancementConfig { | ||
|
||
/** @inheritdoc */ | ||
static get defaultOptions() { | ||
return foundry.utils.mergeObject(super.defaultOptions, { | ||
classes: ["dnd5e", "advancement", "item-choice", "two-column"], | ||
dragDrop: [{ dropSelector: ".drop-target" }], | ||
dropKeyPath: "pool", | ||
template: "systems/dnd5e/templates/advancement/item-choice-config.hbs", | ||
width: 540 | ||
}); | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
|
||
/** @inheritdoc */ | ||
getData(options={}) { | ||
const context = { | ||
...super.getData(options), | ||
showSpellConfig: this.advancement.configuration.type === "spell", | ||
validTypes: this.advancement.constructor.VALID_TYPES.reduce((obj, type) => { | ||
obj[type] = game.i18n.localize(`ITEM.Type${type.capitalize()}`); | ||
return obj; | ||
}, {}) | ||
}; | ||
if ( this.advancement.configuration.type === "feat" ) { | ||
const selectedType = CONFIG.DND5E.featureTypes[this.advancement.configuration.restriction.type]; | ||
context.typeRestriction = { | ||
typeLabel: game.i18n.localize("DND5E.ItemFeatureType"), | ||
typeOptions: CONFIG.DND5E.featureTypes, | ||
subtypeLabel: game.i18n.format("DND5E.ItemFeatureSubtype", {category: selectedType?.label}), | ||
subtypeOptions: selectedType?.subtypes | ||
}; | ||
} | ||
return context; | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
|
||
/** @inheritdoc */ | ||
async prepareConfigurationUpdate(configuration) { | ||
if ( configuration.choices ) configuration.choices = this.constructor._cleanedObject(configuration.choices); | ||
|
||
// Ensure items are still valid if type restriction or spell restriction are changed | ||
const pool = []; | ||
for ( const uuid of (configuration.pool ?? this.advancement.configuration.pool) ) { | ||
if ( this.advancement._validateItemType(await fromUuid(uuid), { | ||
type: configuration.type, restriction: configuration.restriction ?? {}, strict: false | ||
}) ) pool.push(uuid); | ||
} | ||
configuration.pool = pool; | ||
|
||
return configuration; | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
|
||
/** @inheritdoc */ | ||
_validateDroppedItem(event, item) { | ||
this.advancement._validateItemType(item); | ||
} | ||
} |
Oops, something went wrong.