UNPKG

phaser3-rex-plugins

Version:
60 lines (47 loc) 1.65 kB
import CreateCheckbox from './utils/CreateCheckbox.js'; var SetCheckboxReadOnly = function (gameObject, readOnly) { if (readOnly === undefined) { readOnly = true; } var checkbox = gameObject.childrenMap.checkbox; checkbox.setReadOnly(readOnly); } export default { name: 'CheckboxInput', accept(config) { if (config.hasOwnProperty('view')) { return (config.view === 'boolean') } return typeof (config.value) === 'boolean'; }, // Callback after `constructor()` build(gameObject, config, inputRowStyle, styles) { var scene = gameObject.scene; gameObject.type = 'rexTweaker.CheckboxInput'; var checkboxConfig = inputRowStyle.checkbox; var checkbox = CreateCheckbox(scene, checkboxConfig); var size = checkboxConfig.size; if (size !== undefined) { checkbox.setSize(size, size); } var fitRatio = (size !== undefined) ? 0 : 1; gameObject.add( checkbox, { proportion: 0, expand: false, fitRatio: fitRatio, key: 'checkbox' } ) checkbox.on('valuechange', function (value) { gameObject.setValue(value); }); }, // Callback inside `setValue()` displayValue(gameObject, value) { var checkbox = gameObject.childrenMap.checkbox; checkbox.setValue(value); }, setReadOnly(gameObject, readOnly) { if (readOnly === undefined) { readOnly = true; } SetCheckboxReadOnly(gameObject, readOnly); } }