diff --git a/scripting/api-reference/animation.mdx b/scripting/api-reference/animation.mdx index ccd45c71..d6ed32fb 100644 --- a/scripting/api-reference/animation.mdx +++ b/scripting/api-reference/animation.mdx @@ -13,6 +13,10 @@ The duration of the animation. ### `advance` +```lua +advance +``` + Advances the animation by the given time in seconds. Returns true if the animation hasn't reached its end. If the animation is set to loop or ping pong, it will always return true @@ -20,16 +24,28 @@ pong, it will always return true ### `setTime` +```lua +setTime +``` + set the animation time in seconds ### `setTimeFrames` +```lua +setTimeFrames +``` + set the animation time in frames ### `setTimePercentage` +```lua +setTimePercentage +``` + set the animation time as a percentage of the duration diff --git a/scripting/api-reference/artboard.mdx b/scripting/api-reference/artboard.mdx index 7c53cdea..709eef05 100644 --- a/scripting/api-reference/artboard.mdx +++ b/scripting/api-reference/artboard.mdx @@ -44,27 +44,47 @@ end ### `draw` +```lua +draw +``` + Draws the artboard using the provided renderer. ### `advance` +```lua +advance +``` + Advances the artboard by the given time in seconds. Returns true if the artboard should continue receiving advance calls. ### `instance` +```lua +instance +``` + Creates a new instance of the artboard with independent state. ### `animation` +```lua +animation +``` + Creates an animation instance linked to the artboard instance ### `bounds` +```lua +bounds +``` + Returns the bounding box of the artboard as two [Vector](/scripting/api-reference/vector) values: the minimum point and the maximum point. ```lua @@ -76,35 +96,59 @@ print("Bounds height", maxPt.y - minPt.y) ### `node` +```lua +node +``` + Returns the node with the given name, or nil if no such node exists. ### `pointerDown` +```lua +pointerDown +``` + Pointer event down handler. Each returns a hit-test result, where 0 indicates no hit and non-zero values indicate a hit. ### `pointerUp` +```lua +pointerUp +``` + Pointer event up handler. Each returns a hit-test result, where 0 indicates no hit and non-zero values indicate a hit. ### `pointerMove` +```lua +pointerMove +``` + Pointer event move handler. Each returns a hit-test result, where 0 indicates no hit and non-zero values indicate a hit. ### `pointerExit` +```lua +pointerExit +``` + Pointer event exit handler. Each returns a hit-test result, where 0 indicates no hit and non-zero values indicate a hit. ### `addToPath` +```lua +addToPath +``` + Adds the artboard’s geometry to the given path, optionally transformed by the provided matrix. diff --git a/scripting/api-reference/color.mdx b/scripting/api-reference/color.mdx index 6e293998..e1300c3a 100644 --- a/scripting/api-reference/color.mdx +++ b/scripting/api-reference/color.mdx @@ -6,6 +6,10 @@ title: Color ### `lerp` +```lua +lerp +``` + Linearly interpolates between two colors using the parameter t, where t = 0 returns 'from' and t = 1 returns 'to'. ```lua @@ -15,6 +19,10 @@ self.color = Color.lerp(color1, color2, t) ### `rgb` +```lua +rgb +``` + Returns a color constructed from red, green, and blue channels. Alpha defaults to 255 (fully opaque). Channel values are clamped to [0, 255]. ```lua @@ -25,6 +33,10 @@ self.color = Color.rgb(255, 0, 0) ### `rgba` +```lua +rgba +``` + Returns a color constructed from red, green, blue, and alpha channels. Channel values are clamped to [0, 255]. ```lua @@ -37,6 +49,10 @@ self.color = Color.rgba(255, 0, 0, 128) ### `red` +```lua +red +``` + Returns the red channel of the color. If a value is provided, returns a new color with that channel updated. ```lua @@ -46,6 +62,10 @@ print("Red:", Color.red(myColor)) ### `green` +```lua +green +``` + Returns the green channel of the color. If a value is provided, returns a new color with that channel updated. ```lua @@ -55,6 +75,10 @@ print("Green:", Color.green(myColor)) ### `blue` +```lua +blue +``` + Returns the blue channel of the color. If a value is provided, returns a new color with that channel updated. ```lua @@ -64,6 +88,10 @@ print("Blue:", Color.blue(myColor)) ### `alpha` +```lua +alpha +``` + Returns the alpha channel of the color, or returns a new color with the alpha channel set to the specified value. Values are clamped to [0, 255]. ```lua @@ -73,6 +101,10 @@ print("Alpha:", Color.alpha(myColor)) ### `opacity` +```lua +opacity +``` + Returns the opacity of the color as a normalized value in the range [0.0, 1.0], or returns a new color with its alpha set from the specified opacity. diff --git a/scripting/api-reference/context.mdx b/scripting/api-reference/context.mdx index a7a95f10..69b1923a 100644 --- a/scripting/api-reference/context.mdx +++ b/scripting/api-reference/context.mdx @@ -9,12 +9,20 @@ Provides access to update scheduling for scripted objects. ### `markNeedsUpdate` +```lua +markNeedsUpdate() +``` + Provides access to update scheduling for scripted objects. Marks the object as needing an update on the next frame. ### `viewModel` +```lua +viewModel() -> ViewModel +``` + Returns the context view model diff --git a/scripting/api-reference/converter.mdx b/scripting/api-reference/converter.mdx index 9c653711..d211217b 100644 --- a/scripting/api-reference/converter.mdx +++ b/scripting/api-reference/converter.mdx @@ -19,24 +19,40 @@ See [Converter Scripts](/scripting/protocols/converter-scripts). ### `init` +```lua +init +``` + Called once when the converter is created. Returns true if initialization succeeds. ### `convert` +```lua +convert +``` + Converts the input value (a view model property) to an output value. The input parameter must be a DataValue type. ### `reverseConvert` +```lua +reverseConvert +``` + Converts the output value back to an input value (a view model property). The input parameter must be a DataValue type. ### `advance` +```lua +advance +``` + Optional per-frame update. Returns true if the converter should continue receiving advance calls. diff --git a/scripting/api-reference/data-value.mdx b/scripting/api-reference/data-value.mdx index a4116508..b6b24e94 100644 --- a/scripting/api-reference/data-value.mdx +++ b/scripting/api-reference/data-value.mdx @@ -10,6 +10,10 @@ functions for checking the underlying value type. ### `number` +```lua +number +``` + Constructors for [DataValue](/scripting/api-reference/data-value) types. Each function returns a mutable DataValue container of the corresponding underlying type. Creates a [DataValueNumber](/scripting/api-reference/data-value-number) that stores a number. @@ -17,16 +21,28 @@ Creates a [DataValueNumber](/scripting/api-reference/data-value-number) that sto ### `string` +```lua +string +``` + Creates a [DataValueString](/scripting/api-reference/data-value-string) that stores a string. ### `boolean` +```lua +boolean +``` + Creates a [DataValueBoolean](/scripting/api-reference/data-value-boolean) that stores a boolean. ### `color` +```lua +color +``` + Creates a [DataValueColor](/scripting/api-reference/data-value-color) that stores a [Color](/scripting/api-reference/color). @@ -34,6 +50,10 @@ Creates a [DataValueColor](/scripting/api-reference/data-value-color) that store ### `isNumber` +```lua +isNumber() -> boolean +``` + Base type for values that can be stored in inputs. Provides functions for checking the underlying value type. Returns true if the value is a number. @@ -45,6 +65,10 @@ print(dv.isNumber) -- true ### `isString` +```lua +isString() -> boolean +``` + Returns true if the value is a string. ```lua local dv: DataValueNumber = DataValue.number() @@ -54,6 +78,10 @@ print(dv.isString) -- false ### `isBoolean` +```lua +isBoolean() -> boolean +``` + Returns true if the value is a boolean. ```lua local dv: DataValueNumber = DataValue.number() @@ -63,6 +91,10 @@ print(dv.isBoolean) -- false ### `isColor` +```lua +isColor() -> boolean +``` + Returns true if the value is a color. ```lua local dv: DataValueNumber = DataValue.number() diff --git a/scripting/api-reference/enum-values.mdx b/scripting/api-reference/enum-values.mdx index bcc6cd83..415e08af 100644 --- a/scripting/api-reference/enum-values.mdx +++ b/scripting/api-reference/enum-values.mdx @@ -6,3 +6,7 @@ title: EnumValues ### `__len` +```lua +__len +``` + diff --git a/scripting/api-reference/gradient.mdx b/scripting/api-reference/gradient.mdx index b11d2a31..cc467db3 100644 --- a/scripting/api-reference/gradient.mdx +++ b/scripting/api-reference/gradient.mdx @@ -10,6 +10,10 @@ defined by a set of color stops ([GradientStop](/scripting/api-reference/gradien ### `linear` +```lua +linear +``` + Creates a linear gradient that transitions between the specified color stops along the line from 'from' to 'to'. @@ -23,6 +27,10 @@ local g = Gradient.linear(Vector.xy(0, 0), Vector.xy(100, 0), { ### `radial` +```lua +radial +``` + Creates a radial gradient centered at 'from', extending outward to the given radius, using the specified color stops. diff --git a/scripting/api-reference/layout.mdx b/scripting/api-reference/layout.mdx index 5db04efb..f4a2817b 100644 --- a/scripting/api-reference/layout.mdx +++ b/scripting/api-reference/layout.mdx @@ -15,6 +15,10 @@ See [Layout Scripts](/scripting/protocols/layout-scripts). ### `measure` +```lua +measure +``` + When provided this Layout can be intrinsically sized/request to be a specific size. This is not guaranteed as the layout may have min/max dimensions. Resize will be called with the @@ -23,6 +27,10 @@ granted size after being measured. ### `resize` +```lua +resize +``` + Guaranteed to be called to set initial size and also called whenever the size changes. diff --git a/scripting/api-reference/listener-action.mdx b/scripting/api-reference/listener-action.mdx index 15c452d0..8a49521c 100644 --- a/scripting/api-reference/listener-action.mdx +++ b/scripting/api-reference/listener-action.mdx @@ -9,11 +9,19 @@ An action performed when a listener is triggered ### `init` +```lua +init +``` + Called once when the listener is created or attached. ### `perform` +```lua +perform +``` + Called any time a listener is triggered. diff --git a/scripting/api-reference/mat2d.mdx b/scripting/api-reference/mat2d.mdx index c7a06e12..7396b3da 100644 --- a/scripting/api-reference/mat2d.mdx +++ b/scripting/api-reference/mat2d.mdx @@ -60,16 +60,28 @@ Creates a scale-and-translation matrix from numeric values or vectors. ### `values` +```lua +values +``` + Creates a matrix using the specified components. ### `identity` +```lua +identity +``` + Returns the identity matrix. ### `withRotation` +```lua +withRotation +``` + Creates a rotation matrix from the given angle in radians. @@ -77,27 +89,47 @@ Creates a rotation matrix from the given angle in radians. ### `invert` +```lua +invert() -> Mat2D? +``` + Provides indexed access to the matrix components. Returns the inverse of the matrix, or nil if the matrix is not invertible. ### `isIdentity` +```lua +isIdentity() -> boolean +``` + Returns true if the matrix is the identity transform. ### `__eq` +```lua +__eq(rhs: Mat2D) -> boolean +``` + Returns true if all components of the two matrices are equal. ### `__mul` +```lua +__mul(rhs: Vector) -> Vector +``` + Transforms the given vector by the matrix and returns the result. ### `__mul` +```lua +__mul(rhs: Mat2D) -> Mat2D +``` + Returns the matrix product of this matrix and the given matrix diff --git a/scripting/api-reference/node-data.mdx b/scripting/api-reference/node-data.mdx index 3c57c077..28a73563 100644 --- a/scripting/api-reference/node-data.mdx +++ b/scripting/api-reference/node-data.mdx @@ -22,6 +22,10 @@ The parent of the node, or nil if it has none. ### `decompose` +```lua +decompose(worldTransform:Mat2D) +``` + Represents a node in the hierarchy, providing transform properties and access to parent and child nodes. Updates the node’s position, rotation, and scale from the given world diff --git a/scripting/api-reference/node.mdx b/scripting/api-reference/node.mdx index c802e743..c991e2fa 100644 --- a/scripting/api-reference/node.mdx +++ b/scripting/api-reference/node.mdx @@ -12,28 +12,48 @@ See [Node Scripts](/scripting/protocols/node-scripts). ### `init` +```lua +init +``` + Called once when the node is created. Returns true if initialization succeeds. ### `advance` +```lua +advance +``` + Optional per-frame update. Returns true if the node should continue receiving advance calls. ### `update` +```lua +update +``` + Called when an input value changes. ### `draw` +```lua +draw +``` + Called to render the node using the provided renderer. ### `pointerDown` +```lua +pointerDown +``` + Pointer event down handler. ```lua @@ -56,6 +76,10 @@ end ### `pointerMove` +```lua +pointerMove +``` + Pointer event move handler. ```lua @@ -78,6 +102,10 @@ end ### `pointerUp` +```lua +pointerUp +``` + Pointer event up handler. ```lua function handlePointerUp(self: MyGame, event: PointerEvent) @@ -99,6 +127,10 @@ end ### `pointerExit` +```lua +pointerExit +``` + Pointer event exit handler. ```lua function handlePointerExit(self: MyGame, event: PointerEvent) diff --git a/scripting/api-reference/paint.mdx b/scripting/api-reference/paint.mdx index 2d8fda42..ad7d8db7 100644 --- a/scripting/api-reference/paint.mdx +++ b/scripting/api-reference/paint.mdx @@ -54,6 +54,10 @@ Color. See [Color](/scripting/api-reference/color). ### `new` +```lua +new +``` + Creates a new [Paint](/scripting/api-reference/paint) object with default settings. Example: @@ -66,6 +70,10 @@ paint.color = Color.rgb(255, 200, 80) ### `with` +```lua +with +``` + Creates a new Paint initialized from the provided [PaintDefinition](/scripting/api-reference/paint-definition). Example: @@ -84,6 +92,10 @@ local strokePaint = Paint.with({ ### `copy` +```lua +copy(values:PaintDefinition?) -> Paint +``` + Returns a new Paint that copies this one, optionally overriding selected properties with values from the provided [PaintDefinition](/scripting/api-reference/paint-definition). diff --git a/scripting/api-reference/path-command.mdx b/scripting/api-reference/path-command.mdx index bb143292..6a8133de 100644 --- a/scripting/api-reference/path-command.mdx +++ b/scripting/api-reference/path-command.mdx @@ -19,6 +19,10 @@ See [CommandType](/scripting/api-reference/command-type). ### `__len` +```lua +__len() -> number +``` + points size varies depending on command. moveTo and lineTo have only two points cubicTo has 6 and close has none Returns the number of points stored on this command. diff --git a/scripting/api-reference/path-data.mdx b/scripting/api-reference/path-data.mdx index b820c1ad..a57fe6f9 100644 --- a/scripting/api-reference/path-data.mdx +++ b/scripting/api-reference/path-data.mdx @@ -10,6 +10,10 @@ Both Path and PathData behave like arrays of commands and support iteration via ### `__len` +```lua +__len() -> number +``` + PathData is an indexed collection of [PathCommand](/scripting/api-reference/path-command) objects. Both Path and PathData behave like arrays of commands and support iteration via ipairs. Each entry is a [PathCommand](/scripting/api-reference/path-command) describing one segment or action in the path. @@ -18,6 +22,10 @@ Returns the number of commands in the path. ### `contours` +```lua +contours(self: PathData) -> ContourMeasure? +``` + Returns a [ContourMeasure](/scripting/api-reference/contour-measure) for the first contour in the path. A contour is a sequence of path segments between moveTo operations. Use the 'next' property on the returned ContourMeasure to iterate through subsequent @@ -26,6 +34,10 @@ contours. Returns nil if the path has no contours. ### `measure` +```lua +measure(self: PathData) -> PathMeasure +``` + Returns a [PathMeasure](/scripting/api-reference/path-measure) that measures the entire path across all contours. This provides the total length and allows operations on the path as a whole. diff --git a/scripting/api-reference/path-effect.mdx b/scripting/api-reference/path-effect.mdx index 04dad6b4..0d64e173 100644 --- a/scripting/api-reference/path-effect.mdx +++ b/scripting/api-reference/path-effect.mdx @@ -9,12 +9,20 @@ A scripted effect applied to a path ### `init` +```lua +init +``` + Called once when the effect is created or attached. Return `true` to keep the effect active, or `false` to disable it. ### `update` +```lua +update +``` + Called any time an input changes. You receive the original [PathData](/scripting/api-reference/path-data) and must return the path that should be used for rendering. @@ -22,6 +30,10 @@ that should be used for rendering. ### `advance` +```lua +advance +``` + Called every frame to advance the effect over time. `seconds` is the time delta since the last frame. Return `true` to keep the effect active, or `false` to disable it. diff --git a/scripting/api-reference/path-measure.mdx b/scripting/api-reference/path-measure.mdx index 17cf8ec3..5caf90f0 100644 --- a/scripting/api-reference/path-measure.mdx +++ b/scripting/api-reference/path-measure.mdx @@ -24,6 +24,10 @@ contours are closed. ### `positionAndTangent` +```lua +positionAndTangent +``` + Returns the position and tangent vector at the given distance along the path. The distance is clamped to the valid range [0, length]. Returns two [Vector](/scripting/api-reference/vector) values: the position and the normalized tangent vector. @@ -31,6 +35,10 @@ path. The distance is clamped to the valid range [0, length]. Returns two ### `warp` +```lua +warp +``` + Warps a point onto the path. The x-coordinate of the source point is interpreted as a distance along the path, and the y-coordinate is used as an offset along the tangent direction. Returns the warped position as a @@ -39,6 +47,10 @@ an offset along the tangent direction. Returns the warped position as a ### `extract` +```lua +extract +``` + Extracts a sub-section of the path from startDistance to endDistance and appends it to the destination path. Distances are clamped to the valid range [0, length]. If startWithMove is true (the default), the extracted diff --git a/scripting/api-reference/path.mdx b/scripting/api-reference/path.mdx index d8dfe607..3facca91 100644 --- a/scripting/api-reference/path.mdx +++ b/scripting/api-reference/path.mdx @@ -6,10 +6,18 @@ title: Path ### `new` +```lua +new +``` + ## Methods ### `moveTo` +```lua +moveTo(self: Path, to: Vector) -> () +``` + Moves the current point to the specified location, starting a new contour. ```lua @@ -19,6 +27,10 @@ path:moveTo(Vector.xy(0, 0)) ### `lineTo` +```lua +lineTo(self: Path, to: Vector) -> () +``` + Adds a straight line segment from the current point to the specified point. ```lua @@ -28,6 +40,10 @@ path:lineTo(Vector.xy(10, 0)) ### `quadTo` +```lua +quadTo(self: Path, control: Vector, to: Vector) -> () +``` + Adds a quadratic Bézier curve from the current point to the specified point, using the control point to define the curve shape. ```lua @@ -40,6 +56,10 @@ path:quadTo( ### `cubicTo` +```lua +cubicTo(self: Path, controlOut: Vector, controlIn: Vector, to: Vector) -> () +``` + Adds a cubic Bézier curve from the current point to the specified point, using controlOut for the start tangent and controlIn for the end tangent. ```lua @@ -53,6 +73,10 @@ path:cubicTo( ### `close` +```lua +close(self: Path) -> () +``` + Closes the current contour by adding a line segment from the current point back to the first point of the contour (the last moveTo). ```lua @@ -68,12 +92,20 @@ path:close() ### `__len` +```lua +__len() -> number +``` + Each entry is a [PathCommand](/scripting/api-reference/path-command) describing one segment or action in the path. Returns the number of commands in the path. ### `reset` +```lua +reset(self: Path) -> () +``` + Paths should not be reset, or mutated at all, while they are in flight for rendering. Only call reset on subsequent frames if you've called Renderer.drawPath with it. @@ -84,11 +116,19 @@ path:reset() ### `add` +```lua +add(self: Path, other: PathData, transform: Mat2D?) -> () +``` + Add one path to another path with the given transform, when specified. ### `contours` +```lua +contours(self: Path) -> ContourMeasure? +``` + Returns a [ContourMeasure](/scripting/api-reference/contour-measure) for the first contour in the path. A contour is a sequence of path segments between moveTo operations. Use the 'next' property on the returned ContourMeasure to iterate through subsequent @@ -97,6 +137,10 @@ contours. Returns nil if the path has no contours. ### `measure` +```lua +measure(self: Path) -> PathMeasure +``` + Returns a [PathMeasure](/scripting/api-reference/path-measure) that measures the entire path across all contours. This provides the total length and allows operations on the path as a whole. ```lua diff --git a/scripting/api-reference/pointer-event.mdx b/scripting/api-reference/pointer-event.mdx index 2a830268..7e897062 100644 --- a/scripting/api-reference/pointer-event.mdx +++ b/scripting/api-reference/pointer-event.mdx @@ -22,6 +22,10 @@ The unique identifier for the pointer. ### `new` +```lua +new +``` + Creates a new [PointerEvent](/scripting/api-reference/pointer-event) with the given id and position. @@ -29,6 +33,10 @@ Creates a new [PointerEvent](/scripting/api-reference/pointer-event) with the gi ### `hit` +```lua +hit(self: PointerEvent, isTranslucent:boolean?) -> () +``` + Marks the event as handled. If isTranslucent is true, the event may continue to propagate through translucent hit targets. diff --git a/scripting/api-reference/property-enum.mdx b/scripting/api-reference/property-enum.mdx index f3f5847c..81b35930 100644 --- a/scripting/api-reference/property-enum.mdx +++ b/scripting/api-reference/property-enum.mdx @@ -6,3 +6,7 @@ title: PropertyEnum ### `values` +```lua +values +``` + diff --git a/scripting/api-reference/property-list.mdx b/scripting/api-reference/property-list.mdx index 5f5291df..8c877c1c 100644 --- a/scripting/api-reference/property-list.mdx +++ b/scripting/api-reference/property-list.mdx @@ -10,11 +10,31 @@ title: PropertyList ### `push` +```lua +push(vm: ViewModel) +``` + ### `insert` +```lua +insert(vm: ViewModel, index: number) +``` + ### `swap` +```lua +swap(index1: number, index2: number) +``` + ### `pop` +```lua +pop() -> ViewModel? +``` + ### `shift` +```lua +shift() -> ViewModel? +``` + diff --git a/scripting/api-reference/property-trigger.mdx b/scripting/api-reference/property-trigger.mdx index c3768f7a..90372162 100644 --- a/scripting/api-reference/property-trigger.mdx +++ b/scripting/api-reference/property-trigger.mdx @@ -18,3 +18,7 @@ Represents a trigger property that can fire events and notify listeners. ### `fire` +```lua +fire +``` + diff --git a/scripting/api-reference/renderer.mdx b/scripting/api-reference/renderer.mdx index d0d3c55d..b943ed2b 100644 --- a/scripting/api-reference/renderer.mdx +++ b/scripting/api-reference/renderer.mdx @@ -10,6 +10,10 @@ applying transforms during rendering. ### `drawPath` +```lua +drawPath(path: Path, paint: Paint) +``` + Provides functions for drawing paths and images, managing clipping, and applying transforms during rendering. Draws the given path using the specified paint. @@ -17,33 +21,57 @@ Draws the given path using the specified paint. ### `drawImage` +```lua +drawImage(image: Image, sampler: ImageSampler, blendMode: BlendMode, opacity: number) +``` + Draws an image using the specified sampler, blend mode, and opacity. ### `drawImageMesh` +```lua +drawImageMesh(image: Image, sampler: ImageSampler, vertices: VertexBuffer, uvs: VertexBuffer, triangles: TriangleBuffer, blendMode: BlendMode, opacity: number) +``` + Draws an image using mesh data defined by vertices, texture coordinates, and triangle indices. ### `clipPath` +```lua +clipPath(path: Path) +``` + Restricts subsequent drawing to the area defined by the given path. Clipping remains in effect until the next restore call. ### `save` +```lua +save() +``` + Saves the current rendering state, including transforms and clipping. ### `restore` +```lua +restore() +``` + Restores the most recently saved rendering state. ### `transform` +```lua +transform(transform: Mat2D) +``` + Applies a transform to the current rendering state. Transforms are applied cumulatively until restored. diff --git a/scripting/api-reference/vector.mdx b/scripting/api-reference/vector.mdx index 43936620..fdab1d6a 100644 --- a/scripting/api-reference/vector.mdx +++ b/scripting/api-reference/vector.mdx @@ -30,6 +30,10 @@ local yValue = v.y -- -5 ### `xy` +```lua +xy +``` + Creates a vector with the specified x and y components. ```lua local v = Vector.xy(5, -2) -- (5, -2) @@ -38,6 +42,10 @@ local v = Vector.xy(5, -2) -- (5, -2) ### `origin` +```lua +origin +``` + Returns the zero vector (0, 0). ```lua local origin = Vector.origin() -- (0,0) @@ -48,6 +56,10 @@ local origin = Vector.origin() -- (0,0) ### `length` +```lua +length(self:Vector) -> number +``` + Provides indexed access to the vector components. ```lua local v = Vector.xy(3, 4) @@ -62,6 +74,10 @@ local len = v:length() -- 5 ### `lengthSquared` +```lua +lengthSquared(self:Vector) -> number +``` + Returns the squared length of the vector. ```lua local v = Vector.xy(3, 4) @@ -71,6 +87,10 @@ local len2 = v:lengthSquared() -- 25 ### `normalized` +```lua +normalized(self:Vector) -> Vector +``` + Returns a normalized copy of the vector. If the length is zero, the result is the zero vector. ```lua @@ -81,6 +101,10 @@ local n = v:normalized() -- (1,0) ### `__eq` +```lua +__eq(rhs: Vector) -> boolean +``` + Returns true if the two vectors have equal components. ```lua local a = Vector.xy(1, 2) @@ -93,6 +117,10 @@ print(a == c) -- false ### `__unm` +```lua +__unm() -> Vector +``` + Returns the negated vector. ```lua local v = Vector.xy(2, -3) @@ -102,6 +130,10 @@ local neg = -v -- (-2, 3) ### `__add` +```lua +__add(rhs: Vector) -> Vector +``` + Returns the sum of two vectors. ```lua local a = Vector.xy(2, 3) @@ -112,6 +144,10 @@ local c = a + b -- (1, 8) ### `__sub` +```lua +__sub(rhs: Vector) -> Vector +``` + Returns the difference between two vectors. ```lua local a = Vector.xy(2, 3) @@ -123,6 +159,10 @@ Returns the difference between two vectors. ### `__mul` +```lua +__mul(rhs: number) -> Vector +``` + Returns the vector scaled by the given number. ```lua local v = Vector.xy(3, -2) @@ -132,6 +172,10 @@ local doubled = v * 2 -- (6, -4) ### `__div` +```lua +__div(rhs: number) -> Vector +``` + Returns the vector divided by the given number ```lua local v = Vector.xy(6, -4) @@ -141,6 +185,10 @@ local half = v / 2 -- (3, -2) ### `distance` +```lua +distance(other: Vector) -> number +``` + Returns the distance to the other vector. ```lua local a = Vector.xy(0, 0) @@ -151,6 +199,10 @@ print(a:distance(b)) -- 5 ### `distanceSquared` +```lua +distanceSquared(other: Vector) -> number +``` + Returns the squared distance to the other vector. ```lua local a = Vector.xy(0, 0) @@ -161,6 +213,10 @@ print(a:distanceSquared(b)) -- 25 ### `dot` +```lua +dot(other: Vector) -> number +``` + Returns the dot product of the vector and the other vector. ```lua local a = Vector.xy(1, 2) @@ -171,6 +227,10 @@ print(a:dot(b)) -- 11 (1*3 + 2*4) ### `lerp` +```lua +lerp(other: Vector, t:number) -> Vector +``` + Returns the linear interpolation between the vector and the other vector, using t where 0 returns the vector and 1 returns the other. diff --git a/scripting/api-reference/view-model.mdx b/scripting/api-reference/view-model.mdx index f2fe4fd7..efb746f3 100644 --- a/scripting/api-reference/view-model.mdx +++ b/scripting/api-reference/view-model.mdx @@ -10,19 +10,55 @@ title: ViewModel ### `getNumber` +```lua +getNumber +``` + ### `getTrigger` +```lua +getTrigger +``` + ### `getString` +```lua +getString +``` + ### `getBoolean` +```lua +getBoolean +``` + ### `getColor` +```lua +getColor +``` + ### `getList` +```lua +getList +``` + ### `getViewModel` +```lua +getViewModel +``` + ### `getEnum` +```lua +getEnum +``` + ### `instance` +```lua +instance +``` +