Updates for discworld core#28
Conversation
krbz999
left a comment
There was a problem hiding this comment.
Generally I'm a little confused by the underlying ideas here.
| <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}}" |
There was a problem hiding this comment.
| <img class="portrait" src="{{document.img}}" data-edit="img" data-action="editImage" data-tooltip="{{document.name}}" | |
| <img class="portrait" src="{{document.img}}" data-edit="img" data-action="editImage" data-tooltip-text="{{document.name}}" |
There was a problem hiding this comment.
Addressed in recent commit
| data-edit="img" | ||
| data-action="editImage" | ||
| title="{{document.name}}"> | ||
| data-tooltip="{{document.name}}" |
There was a problem hiding this comment.
| data-tooltip="{{document.name}}" | |
| data-tooltip-text="{{document.name}}" |
There was a problem hiding this comment.
Addressed in recent commit
|
|
||
| <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> |
There was a problem hiding this comment.
This rootId is not unique. Should use the application's id, but it may be that rootId is already in the context if it's DocumentSheet.
There was a problem hiding this comment.
Fixed in recent commit
| 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", |
There was a problem hiding this comment.
Shouldn't have choices here at all if a module can extend it. It would lead to the actor/item becoming invalid when the module is disabled.
Instead, remove choices here. Prepare the choices in the sheet's context preparation. If the current value is truthy and not one of the options, add it as an additional option with value === label.
There was a problem hiding this comment.
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:
| const [defaultType] = Object.keys(discworld.config.traitTypes[target.value]); | ||
| this.document.update( | ||
| { "system.type": defaultType }, | ||
| { render: false }, |
There was a problem hiding this comment.
Not sure I understand what's going on here. This seems like a workaround for something?
There was a problem hiding this comment.
When actorType is changed, the set of available trait types change. This sets the trait type to an allowed default for a particular actorType when it is changed
| 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); | ||
| } | ||
| }); | ||
| } |
There was a problem hiding this comment.
This should all just be in context prep.
| * @type {string} | ||
| */ | ||
| get actorBaseType() { | ||
| return this.actor.type.replace(/.*\./, ""); |
There was a problem hiding this comment.
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.
actorType filters the available options for traitTypes, so that npcs and characters 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).
This MR does the following:
actorTypeactorType)