Documentation ¶
Overview ¶
The declare package is used to generate rbxfile structures in a declarative style.
Most items have a Declare method, which returns a new rbxfile structure corresponding to the declared item.
The easiest way to use this package is to import it directly into the current package:
import . "github.com/robloxapi/rbxfile/declare"
This allows the package's identifiers to be used directly without a qualifier.
Example ¶
root := Root{ Instance("Part", Ref("RBX12345678"), Property("Name", String, "BasePlate"), Property("CanCollide", Bool, true), Property("Position", Vector3, 0, 10, 0), Property("Size", Vector3, 2, 1.2, 4), Instance("CFrameValue", Property("Name", String, "Value"), Property("Value", CFrame, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1), ), Instance("ObjectValue", Property("Name", String, "Value"), Property("Value", Reference, "RBX12345678"), ), ), }.Declare()
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Instance ¶
func Instance(className string, elements ...element) instance
Instance declares a rbxfile.Instance. It defines an instance with a class name, and a series of "elements". An element can be a Property declaration, which defines a property for the instance. An element can also be another Instance declaration, which becomes a child of the instance.
An element can also be a "Ref" declaration, which defines a string that can be used to refer to the instance by properties with the Reference value type. This also sets the instance's Reference field.
func Metadata ¶
func Metadata(key, value string) metadata
Metadata declares key-value pair to be applied to the root's Metadata field.
func Property ¶
Property declares a property of a rbxfile.Instance. It defines the name of the property, a type corresponding to a rbxfile.Value, and the value of the property.
The value argument may be one or more values of any type, which are asserted to a rbxfile.Value corresponding to the given type. If the value(s) cannot be asserted, then the zero value for the given type is returned instead.
When the given type or a field of the given type is a number, any number type except for complex numbers may be given as the value.
The value may be a single rbxfile.Value that corresponds to the given type (e.g. rbxfile.ValueString for String), in which case the value itself is returned.
Otherwise, for a given type, values must be the following:
String, BinaryString, ProtectedString, Content, SharedString: A single string or []byte. Extra values are ignored. Bool: A single bool. Extra values are ignored. Int, Float, Double, BrickColor, Token, Int64: A single number. Extra values are ignored. UDim: 2 numbers, corresponding to the Scale and Offset fields. UDim2: 1) 2 rbxfile.ValueUDims, corresponding to the X and Y fields. 2) 4 numbers, corresponding to the X.Scale, X.Offset, Y.Scale, and Y.Offset fields. Ray: 1) 2 rbxfile.ValueVector3s, corresponding to the Origin and Direction fields. 2) 6 numbers, corresponding to the X, Y, and Z fields of Origin, then of Direction. Faces: 6 bools, corresponding to the Right, Top, Back, Left, Bottom, and Front fields. Axes: 3 bools, corresponding to the X, Y, and Z fields. Color3: 3 numbers, corresponding to the R, G, and B fields. Vector2, Vector2int16: 2 numbers, corresponding to the X and Y fields. Vector3, Vector3int16: 3 numbers, corresponding to the X, Y, and Z fields. CFrame: 1) 10 values. The first value must be a rbxfile.ValueVector3, which corresponds to the Position field. The remaining 9 values must be numbers, which correspond to the components of the Rotation field. 2) 12 numbers. The first 3 correspond to the X, Y, and Z fields of the Position field. The remaining 9 numbers correspond to the Rotation field. Reference: A single string, []byte or *rbxfile.Instance. Extra values are ignored. When the value is a string or []byte, the reference is resolved by looking for an instance whose "Ref" declaration is equal to the value. NumberSequence: 1) 2 or more rbxfile.ValueNumberSequenceKeypoints, which correspond to keypoints in the sequence. 2) 2 or more groups of 3 numbers. Each group corresponds to the fields Time, Value, and Envelope of a single keypoint in the sequence. ColorSequence: 1) 2 or more rbxfile.ValueColorSequenceKeypoints, which correspond to keypoints in the sequence. 2) 2 or more groups of 3 values: A number, a rbxfile.ValueColor3, and a number. Each group corresponds to the Time, Value and Envelope fields of a single keypoint in the sequence. 3) 2 or more groups of 5 numbers. Each group corresponds to the fields Time, Value.R, Value.G, Value.B, and Envelope of a single keypoint in the sequence. NumberRange: 2 numbers, corresponding to the Min and Max fields. Rect2D: 1) 2 rbxfile.ValueVector2s, corresponding to the Min and Max fields. 2) 4 numbers, corresponding to the Min.X, Min.Y, Max.X, and Max.Y fields. PhysicalProperties: 1) No values, indicating PhysicalProperties with CustomPhysics set to false. 2) 3 numbers, corresponding to the Density, Friction, and Elasticity fields (CustomPhysics is set to true). 3) 5 numbers, corresponding to the Density, Friction, and Elasticity, FrictionWeight, and ElasticityWeight fields (CustomPhysics is set to true). Color3uint8: 3 numbers, corresponding to the R, G, and B fields.
Types ¶
type Ref ¶
type Ref string
Ref declares a string that can be used to refer to the Instance under which it was declared. This will also set the instance's Reference field.
type Root ¶
type Root []primary
Root declares a rbxfile.Root. It is a list that contains Instance and Metadata declarations.
type Type ¶
type Type byte
Type corresponds to a rbxfile.Type.
const ( String Type BinaryString ProtectedString Content Bool Int Float Double UDim UDim2 Ray Faces Axes BrickColor Color3 Vector2 Vector3 CFrame Token Reference Vector3int16 Vector2int16 NumberSequence ColorSequence NumberRange Rect2D PhysicalProperties Color3uint8 Int64 )
func TypeFromString ¶
TypeFromString returns a Type from its string representation. Type(0) is returned if the string does not represent an existing Type.