-
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 #2542 from arbron/advancement/size
[#2220] Add SizeAdvancement
- Loading branch information
Showing
16 changed files
with
282 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { filteredKeys } from "../../utils.mjs"; | ||
import AdvancementConfig from "./advancement-config.mjs"; | ||
|
||
/** | ||
* Configuration application for size advancement. | ||
*/ | ||
export default class SizeConfig extends AdvancementConfig { | ||
|
||
/** @inheritdoc */ | ||
static get defaultOptions() { | ||
return foundry.utils.mergeObject(super.defaultOptions, { | ||
classes: ["dnd5e", "advancement", "size"], | ||
template: "systems/dnd5e/templates/advancement/size-config.hbs" | ||
}); | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
|
||
/** @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) }; | ||
return obj; | ||
}, {}) | ||
}); | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
|
||
/** @inheritdoc */ | ||
async prepareConfigurationUpdate(configuration) { | ||
configuration.sizes = filteredKeys(configuration.sizes ?? {}); | ||
return configuration; | ||
} | ||
} |
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,30 @@ | ||
import AdvancementFlow from "./advancement-flow.mjs"; | ||
|
||
/** | ||
* Inline application that displays size advancement. | ||
*/ | ||
export default class SizeFlow extends AdvancementFlow { | ||
|
||
/** @inheritdoc */ | ||
static get defaultOptions() { | ||
return foundry.utils.mergeObject(super.defaultOptions, { | ||
template: "systems/dnd5e/templates/advancement/size-flow.hbs" | ||
}); | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
|
||
/** @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(sizes).reduce((obj, key) => { | ||
obj[key] = CONFIG.DND5E.actorSizes[key]; | ||
return obj; | ||
}, {}) | ||
}); | ||
} | ||
} |
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,26 @@ | ||
/** | ||
* Configuration data for the size advancement type. | ||
*/ | ||
export class SizeConfigurationData extends foundry.abstract.DataModel { | ||
/** @inheritdoc */ | ||
static defineSchema() { | ||
return { | ||
hint: new foundry.data.fields.StringField({label: "DND5E.AdvancementHint"}), | ||
sizes: new foundry.data.fields.SetField( | ||
new foundry.data.fields.StringField(), {required: false, initial: ["med"], label: "DND5E.Size"} | ||
) | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Value data for the size advancement type. | ||
*/ | ||
export class SizeValueData extends foundry.abstract.DataModel { | ||
/** @inheritdoc */ | ||
static defineSchema() { | ||
return { | ||
size: new foundry.data.fields.StringField({required: false, label: "DND5E.Size"}) | ||
}; | ||
} | ||
} |
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,100 @@ | ||
import Advancement from "./advancement.mjs"; | ||
import SizeConfig from "../../applications/advancement/size-config.mjs"; | ||
import SizeFlow from "../../applications/advancement/size-flow.mjs"; | ||
import { SizeConfigurationData, SizeValueData } from "../../data/advancement/size.mjs"; | ||
|
||
/** | ||
* Advancement that handles player size. | ||
*/ | ||
export default class SizeAdvancement extends Advancement { | ||
|
||
/** @inheritdoc */ | ||
static get metadata() { | ||
return foundry.utils.mergeObject(super.metadata, { | ||
dataModels: { | ||
configuration: SizeConfigurationData, | ||
value: SizeValueData | ||
}, | ||
order: 5, | ||
icon: "systems/dnd5e/icons/svg/size.svg", | ||
title: game.i18n.localize("DND5E.AdvancementSizeTitle"), | ||
hint: game.i18n.localize("DND5E.AdvancementSizeHint"), | ||
validItemTypes: new Set(["race"]), | ||
apps: { | ||
config: SizeConfig, | ||
flow: SizeFlow | ||
} | ||
}); | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
/* 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]; | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
/* Display Methods */ | ||
/* -------------------------------------------- */ | ||
|
||
/** @inheritdoc */ | ||
summaryForLevel(level, { configMode=false }={}) { | ||
const sizes = configMode ? Array.from(this.configuration.sizes) : this.value.size ? [this.value.size] : []; | ||
return sizes.map(s => `<span class="tag">${CONFIG.DND5E.actorSizes[s]}</span>`).join(""); | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
/* Editing Methods */ | ||
/* -------------------------------------------- */ | ||
|
||
/** @inheritdoc */ | ||
static availableForItem(item) { | ||
return !item.advancement.byType.Size?.length; | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
/* Application Methods */ | ||
/* -------------------------------------------- */ | ||
|
||
/** @inheritdoc */ | ||
async apply(level, data) { | ||
this.actor.updateSource({"system.traits.size": data.size ?? "med"}); | ||
this.updateSource({ value: data }); | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
|
||
/** @inheritdoc */ | ||
async restore(level, data) { | ||
this.apply(level, data); | ||
} | ||
|
||
/* -------------------------------------------- */ | ||
|
||
/** @inheritdoc */ | ||
async reverse(level) { | ||
this.actor.updateSource({"system.traits.size": "med"}); | ||
this.updateSource({ "value.-=size": null }); | ||
} | ||
} |
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,10 @@ | ||
<form autocomplete="off"> | ||
{{> "dnd5e.advancement-controls"}} | ||
|
||
<div class="form-group"> | ||
<label>{{localize "DND5E.AdvancementHint"}}</label> | ||
<textarea name="configuration.hint" placeholder="{{default.hint}}">{{configuration.hint}}</textarea> | ||
</div> | ||
|
||
{{> "dnd5e.trait-list" choices=sizes prefix="configuration.sizes"}} | ||
</form> |
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,13 @@ | ||
<form id="{{appId}}" data-level="{{level}}" data-id="{{advancement.id}}" data-type="{{type}}"> | ||
<h3>{{{this.title}}}</h3> | ||
|
||
<p>{{hint}}</p> | ||
|
||
{{#if singleSize}} | ||
<input type="hidden" name="size" value="{{singleSize}}"> | ||
{{else}} | ||
<select name="size"> | ||
{{selectOptions sizes selected=selectedSize}} | ||
</select> | ||
{{/if}} | ||
</form> |
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