/** * A joint ties the object it is placed below to another one (#154): a hinge turns round one point, a * spring pulls towards a length, a rope allows no more than one, and a fixed joint keeps the two as * they were placed, and a slider lets it glide along one axis only. These are the keys of its rows; * what the engine reads off them is in `properties/joint.ts`. */ export const JOINT_TYPES = ['hinge', 'spring', 'rope', 'fixed', 'slider'] as const; export type JointType = (typeof JOINT_TYPES)[number]; export const JOINT_TYPE_LABELS: Record = { hinge: 'Hinge', spring: 'Spring', rope: 'Rope', fixed: 'Fixed', slider: 'Slider', }; export const JOINT_TYPE_KEY = 'jointType'; export const JOINT_CONNECTED_KEY = 'connected'; export const JOINT_ANCHOR_X_KEY = 'connectedAnchorX'; export const JOINT_ANCHOR_Y_KEY = 'connectedAnchorY'; export const JOINT_LENGTH_KEY = 'length'; export const JOINT_STIFFNESS_KEY = 'stiffness'; export const JOINT_DAMPING_KEY = 'damping'; export const JOINT_LIMIT_KEY = 'limitAngle'; export const JOINT_MIN_ANGLE_KEY = 'minAngle'; export const JOINT_MAX_ANGLE_KEY = 'maxAngle'; export const JOINT_LIMIT_DISTANCE_KEY = 'limitDistance'; export const JOINT_MIN_DISTANCE_KEY = 'minDistance'; export const JOINT_MAX_DISTANCE_KEY = 'maxDistance'; export const JOINT_MOTOR_KEY = 'motor'; export const JOINT_MOTOR_SPEED_KEY = 'motorSpeed'; export const JOINT_MOTOR_TARGET_KEY = 'motorTarget'; export const JOINT_MAX_FORCE_KEY = 'maxForce'; export const JOINT_COLLIDE_KEY = 'collideConnected'; /** What a motor on a hinge or a slider does: nothing, turn or glide on, or go to a place and stay. */ export const JOINT_MOTORS = ['off', 'speed', 'target'] as const; export type JointMotor = (typeof JOINT_MOTORS)[number]; export const JOINT_MOTOR_LABELS: Record = { off: 'Off', speed: 'Speed', target: 'Target', }; /** The types that move along one axis, which a motor can drive and a position can be read of. */ export const AXIS_TYPES: readonly JointType[] = ['hinge', 'slider']; /** The types with a point of their own on the other end; a hinge and a fixed joint have the one they sit on. */ export const TWO_ANCHOR_TYPES: readonly JointType[] = ['spring', 'rope']; export function hasConnectedAnchor(type: JointType): boolean { return TWO_ANCHOR_TYPES.includes(type); }