-
Notifications
You must be signed in to change notification settings - Fork 0
Updates for discworld core #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,34 +31,43 @@ export default class TraitSheet extends DiscworldSheetMixin(ItemSheetV2) { | |
| /** @inheritdoc */ | ||
| async _prepareContext(options) { | ||
| const context = await super._prepareContext(options); | ||
| const { document } = this; | ||
| const { system } = this.document; | ||
|
|
||
| context.fields = { | ||
| name: { | ||
| field: this.document.schema.getField("name"), | ||
| field: document.schema.getField("name"), | ||
| value: this.isEditMode | ||
| ? this.document._source.name | ||
| : this.document.name, | ||
| ? document._source.name | ||
| : document.name, | ||
| }, | ||
| actorType: { | ||
| field: system.schema.getField("actorType"), | ||
| value: this.isEditMode | ||
| ? system._source.actorType | ||
| : system.actorType, | ||
| }, | ||
| type: { | ||
| field: this.document.system.schema.getField("type"), | ||
| field: system.schema.getField("type"), | ||
| value: this.isEditMode | ||
| ? this.document.system._source.type | ||
| : this.document.system.type, | ||
| ? system._source.type | ||
| : system.type, | ||
| }, | ||
| severity: { | ||
| field: this.document.system.schema.getField("severity"), | ||
| field: system.schema.getField("severity"), | ||
| value: this.isEditMode | ||
| ? this.document.system._source.severity | ||
| : this.document.system.severity, | ||
| ? system._source.severity | ||
| : system.severity, | ||
| }, | ||
| notes: { | ||
| field: this.document.system.schema.getField("notes"), | ||
| field: system.schema.getField("notes"), | ||
| value: this.isEditMode | ||
| ? this.document.system._source.notes | ||
| : this.document.system.notes, | ||
| ? system._source.notes | ||
| : system.notes, | ||
| }, | ||
| }; | ||
|
|
||
| context.fields.actorType.show = !document.isOwned && (Object.keys(DISCWORLD.actorTypes).length > 1); | ||
| context.fields.severity.show = context.fields.type.value === "consequences"; | ||
| context.fields.notes.enriched = await CONFIG.ux.TextEditor.enrichHTML( | ||
| context.fields.notes.value, | ||
|
|
@@ -70,6 +79,30 @@ export default class TraitSheet extends DiscworldSheetMixin(ItemSheetV2) { | |
|
|
||
| /* -------------------------------------------------- */ | ||
|
|
||
| /** @inheritdoc */ | ||
| async _onRender(context, options) { | ||
| await super._onRender(context, options); | ||
|
|
||
| const { system } = this.document; | ||
|
|
||
| // Sort and filter <option> elements. | ||
| const validTraits = Object.keys(discworld.config.traitTypes[system.actorType]); | ||
| const select = this.element.querySelector("select[name=\"system.type\"]"); | ||
| const optionElements = Array.from(select.querySelectorAll("option")); | ||
|
|
||
| optionElements | ||
| .sort((a, b) => validTraits.indexOf(a.value) - validTraits.indexOf(b.value)) | ||
| .forEach((option) => { | ||
| if (!validTraits.includes(option.value)) { | ||
| option.remove(); | ||
| } else { | ||
| select.appendChild(option); | ||
| } | ||
| }); | ||
| } | ||
|
Comment on lines
+84
to
+102
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should all just be in context prep. |
||
|
|
||
| /* -------------------------------------------------- */ | ||
|
|
||
| /** @inheritdoc */ | ||
| async render(options) { | ||
| const renderedApp = await super.render(options); | ||
|
|
@@ -87,4 +120,21 @@ export default class TraitSheet extends DiscworldSheetMixin(ItemSheetV2) { | |
|
|
||
| return renderedApp; | ||
| } | ||
|
|
||
| /* ------------------------------------------------- */ | ||
|
|
||
| /** @inheritdoc */ | ||
| async _onChangeForm(formConfig, event) { | ||
| const { target } = event; | ||
|
|
||
| // Handle changes to actorType, assigning a valid trait type. | ||
| if (target?.name === "system.actorType") { | ||
| const [defaultType] = Object.keys(discworld.config.traitTypes[target.value]); | ||
| this.document.update( | ||
| { "system.type": defaultType }, | ||
| { render: false }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand what's going on here. This seems like a workaround for something?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When |
||
| ); | ||
| } | ||
| return super._onChangeForm(formConfig, event); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,20 @@ const { HTMLField, StringField } = foundry.data.fields; | |
| export default class TraitDataModel extends foundry.abstract.TypeDataModel { | ||
| /** @inheritdoc */ | ||
| static defineSchema() { | ||
| const traitTypeChoices = () => Object.values(DISCWORLD.traitTypes).reduce((acc, val) => { | ||
| return foundry.utils.mergeObject(acc, val, { inplace: false }); | ||
| }); | ||
| const actorTypeChoices = () => DISCWORLD.actorTypes; | ||
|
|
||
| return { | ||
| notes: new HTMLField(), | ||
| severity: new StringField({ required: true, initial: "minor", choices: DISCWORLD.consequenceSeverity }), | ||
| type: new StringField({ required: true, choices: () => DISCWORLD.traitTypes, initial: "consequences" }), | ||
| type: new StringField({ | ||
| required: true, choices: traitTypeChoices, initial: "consequences", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't have Instead, remove
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't fully understand your instruction here. Is something like this what you mean? prepareContext() {
...
const { traitTypes } = discworld.config;
let typeChoices = traitTypes[system.actorType] ?? traitTypes.character;
if (!Object.keys(typeChoices).includes(system.type) && system.type) {
typeChoices = foundry.utils.mergeObject(
typeChoices,
{ [system.type]: _loc(`DISCWORLD.trait.type.${system.type}`) },
{ inplace: false },
);
}
context.fields.type.choices = typeChoices;
...
}
// Got rid of this override:
// _onRender() {
// }And then in the form group: {{formGroup fields.type.field value=fields.type.value choices=fields.type.choices rootId=rootId}} |
||
| }), | ||
| actorType: new StringField({ | ||
| required: true, choices: actorTypeChoices, initial: "character", | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| <header class="sheet-header flexrow"> | ||||||
| <div class="portrait-container"> | ||||||
| <img class="portrait" src="{{document.img}}" data-edit="img" data-action="editImage" title="{{document.name}}" | ||||||
| alt=""> | ||||||
| <img class="portrait" src="{{document.img}}" data-edit="img" data-action="editImage" data-tooltip="{{document.name}}" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in recent commit |
||||||
| alt="{{document.name}}"> | ||||||
| </div> | ||||||
|
|
||||||
| <div class="header-data-container flexcol"> | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,16 +4,22 @@ | |||||
| src="{{document.img}}" | ||||||
| data-edit="img" | ||||||
| data-action="editImage" | ||||||
| title="{{document.name}}"> | ||||||
| data-tooltip="{{document.name}}" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in recent commit |
||||||
| alt="{{document.name}}"> | ||||||
| </div> | ||||||
|
|
||||||
| <div class="header-data-container flexcol"> | ||||||
| <h1 class="document-name">{{formInput fields.name.field value=fields.name.value}}</h1> | ||||||
| <h1 class="document-name">{{formInput fields.name.field value=fields.name.value rootId=document.id}}</h1> | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rootId is not unique. Should use the application's id, but it may be that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in recent commit |
||||||
| <div class="document-details flexrow"> | ||||||
| <div class="detail-left trait-type">{{formGroup fields.type.field value=fields.type.value}}</div> | ||||||
| {{#if fields.actorType.show }} | ||||||
| <div class="detail-left actor-type"> | ||||||
| {{formGroup fields.actorType.field value=fields.actorType.value localize=true rootId=document.id}} | ||||||
| </div> | ||||||
| {{/if}} | ||||||
| <div class="detail-left trait-type">{{formGroup fields.type.field value=fields.type.value rootId=document.id}}</div> | ||||||
| {{#if fields.severity.show }} | ||||||
| <div class="detail-right severity"> | ||||||
| {{formGroup fields.severity.field value=fields.severity.value}} | ||||||
| {{formGroup fields.severity.field value=fields.severity.value rootId=document.id}} | ||||||
| </div> | ||||||
| {{/if}} | ||||||
| </div> | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem necessary to me. Can you explain the logic behind this and the link between it and
DISCWORLD.traitTypes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actorTypefilters the available options fortraitTypes, so thatnpcs andcharacters each get their own set of traits types.This particular method just gets the base actor type without the discworld-core, so that storage/retrieval is simpler (i.e., not having to store/retrieve a cumbersome id like this,
discworld-core.npc).