Creates a Binding instance. When you create a binding, you provide a key name, a UI control,
										a game component, and an array of numbers. The array of numbers is a list of card faces
										(0 for front, 1 for back, and so on) that need to be updated when the bound state changes. For
										example, if the bound state represented content that is drawn only on the component's back face,
									then you would use [1].
the setting key that the control is bound to; if it starts with $,
											the $ will be removed and any underscores (_) replaced with dashes (-)
the UI component that will take part in the binding
the game component that will take part in the binding
an array of the indices of the game component's sheets which should be repainted when the bound setting changes
Converts the state of the control to a setting string. Subclasses override this to customize how the control's state is represented in the game component's private settings.
the control whose state should be converted to a string
the string representing the state of the control
Updates the UI component using the current setting value.
Changes the state of the control to reflect the provided
										setting value.
										Subclasses override this to customize how the control's state is
									represented in the game component's private settings.
the string value to be mapped to a control state
the control to update
Updates the UI component setting using the current value of the control.
true if the setting has changed
A Binding is an association between a UI control and part of a game component's state, usually one of the game component's private settings. When the UI control is activated by the user, calling
Binding.update()will convert the state of the control into a game component setting and use this to update the game component so that it matches the state of the UI control. When the game component is loaded from a file, callingBinding.initComponent()will read the game component's state and update the state of the UI control to match it.The Binding Process
When
updatemethod is called, it callscontrolToSettingto convert the state of the UI component into a setting value (a string). It will then look in the private settings of the game component for a setting with the provided key name. If the setting does not exist or is different from the the setting returned fromcontrolToSetting, then it will copy the new value into the game component's private settings and mark the sheets listed in the list of card faces as being out of date.updatereturns true if it updated the component.When
initComponentmethod is called, it will first fetch the named setting from the game component's private settings and then callsettingToControlto modify the state of the control to reflect the setting value.Writing Binding Classes
The Binding base class will copy the text that a user writes in a text component to a private setting (for update()) and will set the text in the component to the value of the private setting (for initComponent(). For other kinds of components, you need to create an appropriate subclass that knows about the specific kind of control it is binding the game component state to. To create a subclass you only need to override the controlToSetting() and settingToControl() methods to handle the new type of control. For example, the following binding will bind a checkbox to a yes/no setting value in the game component:
function CheckboxBinding( name, uiControl, gameComponent, sheetsToUpdate ) { // call superclass constructor Binding.call( this, name, uiControl, gameComponent, sheetsToUpdate ); } CheckboxBinding.subclass( Binding ); CheckboxBinding.prototype.toSetting = function controlToSetting( control ) { if( control.selected ) return 'yes'; else return 'no'; } CheckboxBinding.prototype.settingToControl = function settingToControl( control, value ) { control.selected = value != null && value.equals( 'yes' ); }If you wish to create more advanced binding behaviours, such as calling methods on the game component instead of changing private settings, override
updateandinitComponent. It is critical thatupdatemethod returns true if and only if the setting is updated with a different value.