Add number inputs into the supported structures, and redesign the sheet to make it actually look good

This commit is contained in:
Oliver-Akins 2025-01-11 17:35:17 -07:00
parent 5aee7e4a29
commit fb52e1b58d
11 changed files with 161 additions and 48 deletions

View file

@ -62,14 +62,33 @@ export class WeaponData extends foundry.abstract.TypeDataModel {
{
type: `string-set`,
label: `RipCrypt.common.traits`,
placeholder: `RipCrypt.Apps.traits-placeholder`,
path: `system.traits`,
value: this.traitString,
value: ctx.meta.limited ? `???` : this.traitString,
},
{ type: `integer`, label: `Short Range` },
{ type: `integer`, label: `Long Range` },
{ type: `integer`, label: `Damage` },
{ type: `bar`, label: `Wear` },
{ type: `dropdown`, label: `Access` },
{
type: `integer`,
label: `RipCrypt.Apps.short-range`,
path: `system.range.short`,
value: ctx.meta.limited ? `???` : (this.range.short ?? ``),
min: 0,
},
{
type: `integer`,
label: `RipCrypt.Apps.long-range`,
path: `system.range.long`,
value: ctx.meta.limited ? `???` : (this.range.long ?? ``),
min: 0,
},
{
type: `integer`,
label: `RipCrypt.common.damage`,
path: `system.damage`,
value: ctx.meta.limited ? `???` : this.damage,
min: 0,
},
// { type: `bar`, label: `Wear` },
// { type: `dropdown`, label: `Access` },
];
if (this.parent.isEmbedded) {

View file

@ -1,8 +1,9 @@
import { numberInput } from "./numberInput.mjs";
import { stringSet } from "./stringSet.mjs";
const inputTypes = {
"string-set": stringSet,
integer: displayOnly,
integer: numberInput,
bar: displayOnly,
dropdown: displayOnly,
boolean: displayOnly,
@ -13,10 +14,10 @@ function displayOnly(input) {
};
export function formFields(inputs, opts) {
let htmlString = ``;
const fields = [];
for (const input of inputs) {
if (inputTypes[input.type] == null) { continue };
htmlString += inputTypes[input.type](input, opts.data.root);
fields.push(inputTypes[input.type](input, opts.data.root));
};
return htmlString;
return fields.join(opts.hash?.joiner ?? `<hr />`);
};

View file

@ -0,0 +1,35 @@
import { localizer } from "../../utils/Localizer.mjs";
const { randomID } = foundry.utils;
export function numberInput(input, data) {
const label = localizer(input.label);
const id = `${data.meta.idp}-${randomID(10)}`;
if (!data.meta.editable) {
return `<div data-input-type="integer">
<span class="label">${label}</span>
<span class="value">${data.meta.limited ? `???` : input.value}</span>
</div>`;
};
let attrs = ``;
if (input.min) { attrs += ` min="${input.min}"` };
if (input.max) { attrs += ` max="${input.max}"` };
if (input.step) { attrs += `step="${input.step}"` };
return `<div data-input-type="integer">
<label
for="${id}"
>
${label}
</label>
<input
type="number"
id="${id}"
value="${input.value}"
name="${input.path}"
${attrs}
/>
</div>`;
};

View file

@ -4,12 +4,34 @@ const { randomID } = foundry.utils;
export function stringSet(input, data) {
const label = localizer(input.label);
const placeholder = localizer(input.placeholder ?? ``);
const id = `${data.meta.idp}-${randomID(10)}`;
if (!data.meta.editable) {
const tagList = input.value
.split(/,\s*/)
.filter(t => t.length > 0)
.map(t => {
return `<div class="tag">${t.trim()}</div>`;
});
let tags = tagList.join(``);
if (tagList.length === 0) {
tags = `---`;
};
if (data.meta.limited) {
tags = `???`;
};
return `<div data-input-type="string-set">
<span class="label">${label}</span>
<span>${input.value}</span>
<div
class="input-element-tags tags ${tags.length == 0 ? `empty` : ``}"
data-tag-count="${tagList.length}"
>
${tags}
</div>
</div>`;
};
@ -21,6 +43,7 @@ export function stringSet(input, data) {
</label>
<string-tags
id="${id}"
placeholder="${placeholder}"
value="${input.value}"
name="${input.path}"
/>