RC-92 | Datamodel Defined Input Definition

This commit is contained in:
Oliver-Akins 2025-01-08 21:53:09 -07:00
parent 94c89f72e1
commit 4b423a0729
5 changed files with 43 additions and 2 deletions

View file

@ -38,7 +38,7 @@ export class AllItemSheetV1 extends GenericAppMixin(HandlebarsApplicationMixin(I
// #region Lifecycle
async _preparePartContext(partId, ctx, opts) {
ctx = await super._preparePartContext(partId, ctx, opts);
ctx.actor = this.document;
ctx.item = this.document;
Logger.debug(`Context:`, ctx);
return ctx;

View file

@ -55,4 +55,23 @@ export class WeaponData extends foundry.abstract.TypeDataModel {
return String(this.range.short ?? this.range.long ?? ``);
}
// #endregion
// #region Sheet Data
get formFields() {
const fields = [
{ type: `set`, label: `Traits` },
{ type: `integer`, label: `Short Range` },
{ type: `integer`, label: `Long Range` },
{ type: `integer`, label: `Damage` },
{ type: `bar`, label: `Wear` },
{ type: `dropdown`, label: `Access` },
];
if (this.parent.isEmbedded) {
fields.push({ type: `boolean`, label: `Equipped` });
};
return fields;
};
// #endregion
};

View file

@ -1,8 +1,10 @@
import { handlebarsLocalizer, localizer } from "../utils/Localizer.mjs";
import { formFields } from "./inputs/formFields.mjs";
import { options } from "./options.mjs";
export default {
// #region Complex
"rc-formFields": formFields,
"rc-i18n": handlebarsLocalizer,
"rc-options": options,

View file

@ -0,0 +1,20 @@
const inputTypes = {
set: displayOnly,
integer: displayOnly,
bar: displayOnly,
dropdown: displayOnly,
boolean: displayOnly,
};
function displayOnly(input) {
return `<div data-input-type="${input.type}">${input.label}</div>`;
};
export function formFields(inputs) {
let htmlString = ``;
for (const input of inputs) {
if (inputTypes[input.type] == null) { continue };
htmlString += inputTypes[input.type](input);
};
return htmlString;
};