Skip to content

Commit

Permalink
[#2220] Add automatic hint, hide dropdown when only one size is possi…
Browse files Browse the repository at this point in the history
…ble, adjust styling
  • Loading branch information
arbron committed Nov 6, 2023
1 parent c2c421e commit bf3e373
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 13 deletions.
7 changes: 5 additions & 2 deletions dnd5e.css
Original file line number Diff line number Diff line change
Expand Up @@ -1616,9 +1616,12 @@ h5 {
.dnd5e.advancement.scale-value select option[value=""] {
color: var(--color-text-light-6);
}
.dnd5e.advancement.size textarea {
flex: 1 0 100%;
}
.dnd5e.advancement.size .trait-list {
display: flex;
flex-wrap: wrap;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.25rem;
padding: 0;
list-style: none;
Expand Down
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
"DND5E.AdvancementSelectionTitle": "Select Advancement Type",
"DND5E.AdvancementSizeTitle": "Size",
"DND5E.AdvancementSizeHint": "Set a character's size.",
"DND5E.AdvancementSizeFlowHintSingle": "Your size is {size}.",
"DND5E.AdvancementSizeflowHintMultiple": "Choose your size from either {sizes}.",
"DND5E.AdvancementTitle": "Advancement",
"DND5E.AdvancementTraitTitle": "Traits",
"DND5E.AdvancementTraitHint": "Grant a character certain traits or give them an option to select traits (such as proficiencies, skills, languages).",
Expand Down
8 changes: 6 additions & 2 deletions less/advancement.less
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,13 @@
/* Size */
/* ----------------------------------------- */
&.size {
textarea {
flex: 1 0 100%;
}

.trait-list {
display: flex;
flex-wrap: wrap;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.25rem;
padding: 0;
list-style: none;
Expand Down
5 changes: 3 additions & 2 deletions module/applications/advancement/size-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export default class SizeConfig extends AdvancementConfig {
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["dnd5e", "advancement", "size"],
dragDrop: [{ dropSelector: ".drop-target" }],
dropKeyPath: "items",
template: "systems/dnd5e/templates/advancement/size-config.hbs"
});
}
Expand All @@ -21,6 +19,9 @@ export default class SizeConfig extends AdvancementConfig {
/** @inheritdoc */
getData() {
return foundry.utils.mergeObject(super.getData(), {
default: {
hint: this.advancement.automaticHint
},
showLevelSelector: false,
sizes: Object.entries(CONFIG.DND5E.actorSizes).reduce((obj, [key, label]) => {
obj[key] = { label, chosen: this.advancement.configuration.sizes.has(key) };
Expand Down
5 changes: 4 additions & 1 deletion module/applications/advancement/size-flow.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ export default class SizeFlow extends AdvancementFlow {

/** @inheritdoc */
getData() {
const sizes = this.advancement.configuration.sizes;
return foundry.utils.mergeObject(super.getData(), {
singleSize: sizes.size === 1 ? sizes.first() : null,
hint: this.advancement.configuration.hint || this.advancement.automaticHint,
selectedSize: this.retainedData?.size ?? this.advancement.value.size,
sizes: Array.from(this.advancement.configuration.sizes).reduce((obj, key) => {
sizes: Array.from(sizes).reduce((obj, key) => {
obj[key] = CONFIG.DND5E.actorSizes[key];
return obj;
}, {})
Expand Down
20 changes: 19 additions & 1 deletion module/documents/advancement/size.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ export default class SizeAdvancement extends Advancement {
/* Instance Properties */
/* -------------------------------------------- */

/**
* Hint that will be displayed to players if none is entered.
* @type {string}
*/
get automaticHint() {
if ( !this.configuration.sizes.size ) return "";
if ( this.configuration.sizes.size === 1 ) return game.i18n.format("DND5E.AdvancementSizeFlowHintSingle", {
size: CONFIG.DND5E.actorSizes[this.configuration.sizes.first()]
});

const listFormatter = new Intl.ListFormat(game.i18n.lang, { type: "disjunction" });
return game.i18n.format("DND5E.AdvancementSizeflowHintMultiple", {
sizes: listFormatter.format(this.configuration.sizes.map(s => CONFIG.DND5E.actorSizes[s]))
});
}

/* -------------------------------------------- */

/** @inheritdoc */
get levels() {
return [0];
Expand All @@ -52,7 +70,7 @@ export default class SizeAdvancement extends Advancement {

/** @inheritdoc */
static availableForItem(item) {
return !item.advancement.byType.Race?.length;
return !item.advancement.byType.Size?.length;
}

/* -------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion templates/advancement/size-config.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<div class="form-group">
<label>{{localize "DND5E.AdvancementHint"}}</label>
<textarea name="configuration.hint">{{configuration.hint}}</textarea>
<textarea name="configuration.hint" placeholder="{{default.hint}}">{{configuration.hint}}</textarea>
</div>

{{> "dnd5e.trait-list" choices=sizes prefix="configuration.sizes"}}
Expand Down
12 changes: 8 additions & 4 deletions templates/advancement/size-flow.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<form id="{{appId}}" data-level="{{level}}" data-id="{{advancement.id}}" data-type="{{type}}">
<h3>{{{this.title}}}</h3>

<p>{{advancement.configuration.hint}}</p>
<p>{{hint}}</p>

<select name="size">
{{selectOptions sizes selected=selectedSize}}
</select>
{{#if singleSize}}
<input type="hidden" name="size" value="{{singleSize}}">
{{else}}
<select name="size">
{{selectOptions sizes selected=selectedSize}}
</select>
{{/if}}
</form>

0 comments on commit bf3e373

Please sign in to comment.