diff --git a/src/assets/asset-card.ts b/src/assets/asset-card.ts index 4bb448bb..729daf67 100644 --- a/src/assets/asset-card.ts +++ b/src/assets/asset-card.ts @@ -1,23 +1,29 @@ import { Asset, AssetAbility, + AssetAbilityControlField, AssetConditionMeter, AssetControlField, AssetOptionField, DictKey, } from "@datasworn/core/dist/Datasworn"; -import { TemplateResult, html } from "lit-html"; +import { TemplateResult, html, nothing } from "lit-html"; import { map } from "lit-html/directives/map.js"; import { range } from "lit-html/directives/range.js"; +import { Clock } from "clocks/clock"; +import { clockWidget } from "clocks/ui/clock-widget"; import { IDataContext } from "datastore/data-context"; import { produce } from "immer"; import IronVaultPlugin from "index"; import { repeat } from "lit-html/directives/repeat.js"; +import { rootLogger } from "logger"; import { md } from "utils/ui/directives"; import { integratedAssetLens } from "../characters/assets"; import { IronVaultSheetAssetSchema } from "../characters/lens"; +const logger = rootLogger.getLogger("asset-card"); + export function makeDefaultSheetAsset(asset: Asset) { return { id: asset._id, @@ -194,6 +200,14 @@ function renderAssetAbility( }), ); }; + const updateControlField = (key: string) => + updateAsset && + ((control: AssetAbilityControlField) => + updateAsset( + produce(asset, (draft) => { + draft.abilities[i].controls![key] = control; + }), + )); return html`
  • + ${ability.controls + ? html`` + : null}
  • `; } @@ -242,10 +274,10 @@ function renderControls( `; } -function renderControl( +function renderControl( key: string, - control: AssetControlField, - updateControl?: (asset: AssetControlField) => void, + control: C, + updateControl?: (control: C) => void, ) { const updateControlValue = (e: Event) => { const value = (e.target as HTMLInputElement).value; @@ -275,6 +307,14 @@ function renderControl( }), ); }; + const updateClockValue = (newProgress: number) => { + if (!updateControl) return; + updateControl( + produce(control, (draft) => { + draft.value = newProgress; + }), + ); + }; switch (control.field_type) { case "condition_meter": { @@ -283,7 +323,12 @@ function renderControl( @submit=${(ev: Event) => ev.preventDefault()} > ${control.controls && - renderControls(control, control.controls, updateControl)} + renderControls( + control, + control.controls, + // At this point we know this must be an updater for a condition meter + updateControl as (control: AssetConditionMeter) => void, + )}