Skip to content

Commit

Permalink
fix(core): use array instead of boolean object (#138)
Browse files Browse the repository at this point in the history
### Description

- Remove boolean types support
- Use boolean array as type for `enabled` functions

Co-authored-by: Jaime A Torrealba C <[email protected]>
  • Loading branch information
Neosoulink and JaimeTorrealba authored Oct 9, 2024
1 parent 18abcb0 commit b89c4d9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/types/boolean.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './boolean'
export * from './collider'
export * from './collision'
export * from './object'
export * from './physics'
export * from './rapier'
Expand Down
9 changes: 4 additions & 5 deletions src/types/rigid-body.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ActiveCollisionTypes, Collider, ColliderDesc, RigidBody, RigidBodyDesc, World } from '@dimforge/rapier3d-compat'
import type { TresObject3D, TresVector3, VectorCoordinates } from '@tresjs/core'

import type { enableBolean } from './boolean'
import type { ColliderShape } from './collider'

/** @description Tres Rapier supported `RigidBody` types. */
Expand Down Expand Up @@ -58,14 +57,14 @@ export interface RigidBodyProps {
dominanceGroup?: number
/**
* @description Set the dominance group of the`RigidBody`.
* @default { x: true, y: true, z: true }
* @default [true,true,true]
*/
enabledRotations?: enableBolean
enabledRotations?: [x: boolean, y: boolean, z: boolean]
/**
* @description Set the dominance group of the`RigidBody`.
* @default { x: true, y: true, z: true }
* @default [true,true,true]
*/
enableTranslations?: enableBolean
enabledTranslations?: [x: boolean, y: boolean, z: boolean]
/**
* @description Locks the translations of the `RigidBody`.
* @default false
Expand Down
16 changes: 12 additions & 4 deletions src/utils/props.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import { watch } from 'vue'
import type { RigidBody } from '@dimforge/rapier3d-compat'
import type { ShallowRef } from 'vue'
import type { CallableProps, ColliderProps, CreateColliderReturnType, Methods, RigidBodyContext, RigidBodyProps } from '../types'
import type {
CallableProps,
ColliderProps,
CreateColliderReturnType,
Methods,
RigidBodyContext,
RigidBodyProps,
} from '../types'

export const makePropWatcherRB = <
K extends keyof RigidBodyProps,
>(
props: RigidBodyProps,
toWatch: K,
instance: ShallowRef<RigidBodyContext['rigidBody']>,
instance: ShallowRef<RigidBodyContext['rigidBody'] | undefined>,
onSet: `set${Capitalize<keyof RigidBodyProps>}`,
) => watch([() => props[toWatch], instance], ([newValue, _]) => {
if (!instance.value) { return }
((instance.value[onSet as keyof Methods<RigidBody>]) as CallableProps<RigidBody>[keyof CallableProps<RigidBody>])?.(newValue, true)
// TODO: we should give users the possibility to set the wakeUp parameter.
((instance.value[onSet as keyof Methods<RigidBody>]) as CallableProps<RigidBody>[keyof CallableProps<RigidBody>])?.(...(Array.isArray(newValue) ? (newValue as boolean[]) : [newValue]), true)
})

export const makePropsWatcherRB = <
K extends keyof RigidBodyProps,
>(
props: RigidBodyProps,
watchers: K[],
instance: ShallowRef<RigidBodyContext['rigidBody']>,
instance: ShallowRef<RigidBodyContext['rigidBody'] | undefined>,
) => watchers.forEach((_) => {
const watcher = _ as string
// Uppercase only for the first letter in the watcher
Expand Down

0 comments on commit b89c4d9

Please sign in to comment.