The property API is a cross-problem API which may in useful for advanced user interactions.
Some classes across problems implement the EditableComponent interface. You can see a list of their properties and the constraints they have by accessing its properties getter.
All EditableComponents have an ID field. This can often be used to uniquely identify a component among a list of generic EditableComponents.
Gets all properties for the given component.
If you are extending an EditableComponent, you should generally extend the array given by super.properties.
Gets the value of a given ItemProperty by name.
If no such property exists, it returns undefined.
Attempts to set the ItemProperty given by the name to the given value.
It no such property exists, it returns false.
If the property's restrictions forbid it from being set to that value, it will throw a descriptive error.
Otherwise, it returns true.
If you override this method, it is your responsibility to ensure that property constraints are respected.
If you are extending a class that is already an EditableComponent, calling super.setProp will perform a generalized check on all your properties before allowing a change. It will also handle property changes from the superclass. If it returns true, you should also return true immediately, as that means the superclass already handled the property change.
A unique name for the property.
The intended type of the property value. This is used for property inspector fields.
Currently accepted types are string, number, color, boolean, object.
The currently assigned value of the property.
If true, the property cannot be altered via the setProp function or via inspectors.
Only works for boolean properties. If true, inspectors will render a button that sets the property to true instead of a checkbox. The button is disabled if the property is already true.
If true, inspectors will not show an Apply button to confirm changes. Every change in the input field will be immediately submitted.
For types such as numbers or objects, the change will only be submitted if the field text can be parsed correctly.
If defined, values assigned to the property must be contained within the given options.
String property inspectors with defined options will display a dropdown menu with the given options instead of a text field.
A textual description of the property. If defined, it will be used to display a tooltip on property inspectors.
If defined, it overrides the display name of the property in property inspectors.
If defined, whenever an attempt to change the property is made, it will be called with the new value. If it returns false, the property set will deemed invalid and aborted.
The canvas helper API is a cross-problem API which simplifies some common operations on a canvas.
Constructs a new canvas helper with the given canvas context.
Draws a circle at (x,y) with radius r. If a color is given, it will set the fillStyle of the context to that color before drawing.
Draws a line from (x1,y1) to (x2,y2). If a color is given, it will set the strokeStyle of the context to that color before drawing. If a thickness is given, it will set the lineWidth value in the context to that thickness before drawing.
This function draws the given text with the given parameters centered around (x,y) and with the font given by the fontFamily and size.
This function has side effects on the context, it sets textAlign, textBaseline, and font.
If a color is provided, it also sets the fillStyle. If a strokeColor is provided, it also sets the strokeStyle.
This draws a grid whose top left corner is in (x,y), has size (width, height), and has the given rows and columns.
If includeBorders is set to true, it will also draw the outside borders
If a color is provided, it will set the context strokeStyle before drawing.