Clairvoyant

Clairvoyant Documentation

Graph Search

Explore the documentation for Graph Search

Go ->

Adversarial Search

Explore the documentation for Adversarial Search

Go ->

Property API

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.

I
interface
EditableComponent

p
property
get
id : number | string

All EditableComponents have an ID field. This can often be used to uniquely identify a component among a list of generic EditableComponents.

p
property
get
properties : ItemProperty[]

Gets all properties for the given component.

If you are extending an EditableComponent, you should generally extend the array given by super.properties.

f
function
getProp(name : string) : any

Gets the value of a given ItemProperty by name.

If no such property exists, it returns undefined.

f
function
setProp(name : string, value : any) : boolean

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.

I
interface
ItemProperty<T>

p
property
name : string

A unique name for the property.

p
property
type : string

The intended type of the property value. This is used for property inspector fields.

Currently accepted types are string, number, color, boolean, object.

p
property
value : T

The currently assigned value of the property.

p
property
fixed : boolean | undefined

If true, the property cannot be altered via the setProp function or via inspectors.

p
property
trigger : boolean | undefined

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.

p
property
hidden : boolean | undefined

If true, the property won't be displayed in inspectors.

p
property
dynamic : boolean | undefined

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.

p
property
options : T[] | undefined

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.

p
property
description : string | undefined

A textual description of the property. If defined, it will be used to display a tooltip on property inspectors.

p
property
display : string | undefined

If defined, it overrides the display name of the property in property inspectors.

p
property
check : (T) => boolean | undefined

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.

Canvas Helper API

The canvas helper API is a cross-problem API which simplifies some common operations on a canvas.

c
class
CanvasHelper

f
function
constructor(ctx : CanvasRenderingContext2D)

Constructs a new canvas helper with the given canvas context.

f
function
drawCircle(x : number, y : number, r : number, color : string | undefined = undefined) : void

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.

f
function
drawLine(x1 : number, y1 : number, x2 : number, y2 : number, color : string | undefined = undefined, thickness : number | undefined = undefined) : void

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.

f
function
drawTextCentered(text : string, x : number, y : number, size : number, color : string | undefined = undefined, strokeColor : string | undefined = undefined, maxWidth : number | undefined = undefined, fontFamily : string = "Arial") : void

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.

f
function
drawGrid(x : number, y : number, width : number, height : number, columns : number, rows : number, color : string | undefined = undefined, includeBorders : boolean = false) : void

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.