Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | import React, { useCallback, useMemo } from "react"; import { FormRow } from "ui/form/layout/FormLayout"; import entitiesActions from "store/features/entities/entitiesActions"; import { ActorPrefabNormalized } from "shared/lib/entities/entitiesTypes"; import { useAppDispatch, useAppSelector } from "store/hooks"; import { CheckboxField } from "ui/form/CheckboxField"; import { removeArrayElements, toggleArrayElement, } from "shared/lib/helpers/array"; import { sceneSelectors } from "store/features/entities/entitiesSelectors"; import l10n, { L10NKey } from "shared/lib/lang/l10n"; import uniqBy from "lodash/uniqBy"; interface ActorPrefabExtraCollisionFlagsProps { prefab: ActorPrefabNormalized; sceneId?: string; } export const ActorPrefabExtraCollisionFlags = ({ prefab, sceneId, }: ActorPrefabExtraCollisionFlagsProps) => { const dispatch = useAppDispatch(); const sceneTypeKey = useAppSelector( (state) => sceneSelectors.selectById(state, sceneId ?? "")?.type, ); const sceneTypeSchemas = useAppSelector((state) => state.engine.sceneTypes); const extraActorCollisionFlags = useMemo(() => { Iif (!sceneTypeSchemas) { return []; } Iif (sceneTypeKey) { return ( sceneTypeSchemas.find((s) => s.key === sceneTypeKey) ?.extraActorCollisionFlags ?? [] ); } return uniqBy( sceneTypeSchemas.flatMap((s) => s.extraActorCollisionFlags || []), "key", ).map((flagDef) => ({ ...flagDef, clearFlags: [], // Can't reliably determine which flags should be cleared without knowing the scene type, so just don't clear any })); }, [sceneTypeKey, sceneTypeSchemas]); const onChangeActorPrefabProp = useCallback( <K extends keyof ActorPrefabNormalized>( key: K, value: ActorPrefabNormalized[K], ) => { dispatch( entitiesActions.editActorPrefab({ actorPrefabId: prefab.id, changes: { [key]: value, }, }), ); }, [dispatch, prefab.id], ); Iif (!prefab || extraActorCollisionFlags.length === 0) { return <></>; } return Array.from({ length: Math.ceil(extraActorCollisionFlags.length / 2), }).map((_, rowIndex) => { const startIndex = rowIndex * 2; const items = extraActorCollisionFlags.slice(startIndex, startIndex + 2); return ( <FormRow key={rowIndex}> {items.map((flagDef) => ( <CheckboxField key={flagDef.key} name={flagDef.key} label={l10n(flagDef.label as L10NKey)} title={ flagDef.description ? l10n(flagDef.description as L10NKey) : undefined } checked={prefab.collisionExtraFlags.includes(flagDef.setFlag)} onChange={() => { onChangeActorPrefabProp( "collisionExtraFlags", removeArrayElements( toggleArrayElement( prefab.collisionExtraFlags, flagDef.setFlag, ), flagDef.clearFlags ?? [], ), ); }} /> ))} </FormRow> ); }); }; |