Skip to content

Commit

Permalink
Merge pull request #264 from scottbenton/feat/asset-row-inputs
Browse files Browse the repository at this point in the history
feat(assets): Added support for asset row inputs
  • Loading branch information
scottbenton authored Oct 29, 2023
2 parents 8f29f26 + dd4892c commit 9dcb023
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
30 changes: 29 additions & 1 deletion src/components/features/assets/AssetCard/AssetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DialogTitle,
FormControlLabel,
IconButton,
Stack,
SxProps,
Theme,
Tooltip,
Expand All @@ -26,6 +27,7 @@ import { assetMap, assetTypeLabels } from "data/assets";
import { encodeDataswornId } from "functions/dataswornIdEncoder";
import GroupIcon from "@mui/icons-material/Group";
import { getIsLocalEnvironment } from "functions/getGameSystem";
import { FieldType } from "./FieldType";

export interface AssetCardProps {
assetId: string;
Expand Down Expand Up @@ -78,15 +80,25 @@ export function AssetCard(props: AssetCardProps) {

if (!asset) return null;

const abilityInputs: FieldType[] = [];

let alternateConditionMeterProperties:
| AssetAlterPropertiesConditionMeter
| undefined;

asset.Abilities.forEach((ability) => {
asset.Abilities.forEach((ability, index) => {
if (ability["Alter properties"]) {
alternateConditionMeterProperties =
ability["Alter properties"]?.["Condition meter"];
}
if (
((ability.Enabled || storedAsset?.enabledAbilities[index]) ?? false) &&
Object.values(ability.Inputs ?? {}).length > 0
) {
Object.values(ability.Inputs ?? {}).forEach((input) => {
abilityInputs.push(input);
});
}
});

const conditionMeter = asset["Condition meter"]
Expand Down Expand Up @@ -184,6 +196,22 @@ export function AssetCard(props: AssetCardProps) {
disabled={readOnly || !handleInputChange}
/>
))}
{abilityInputs.map((field, index) => (
<AssetCardField
key={field.$id}
field={field}
value={storedAsset?.inputs?.[encodeDataswornId(field.$id)]}
onChange={(value) => {
if (handleInputChange) {
return handleInputChange(encodeDataswornId(field.$id), value);
}
return new Promise((res, reject) =>
reject("handleInputChange is undefined")
);
}}
disabled={readOnly || !handleInputChange}
/>
))}
<Box flexGrow={1}>
{asset.Abilities.map((ability, index) => (
<Box
Expand Down
4 changes: 2 additions & 2 deletions src/components/features/assets/AssetCard/AssetCardField.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MenuItem, TextField } from "@mui/material";
import { InputClock, InputNumber, InputSelect, InputText } from "dataforged";
import { useState } from "react";
import { InputType } from "types/Datasworn";
import { FieldType } from "./FieldType";

export interface AssetCardFieldProps {
field: InputNumber | InputClock | InputText | InputSelect;
field: FieldType;
value?: string;
onChange?: (newValue: string) => Promise<void>;
disabled: boolean;
Expand Down
3 changes: 3 additions & 0 deletions src/components/features/assets/AssetCard/FieldType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { InputClock, InputNumber, InputSelect, InputText } from "dataforged";

export type FieldType = InputNumber | InputClock | InputText | InputSelect;

0 comments on commit 9dcb023

Please sign in to comment.