javascript/features/playground/playground_commands.js
// |category|. The actual settings part of this category will be re-computed on call.
|category|. The actual settings part of this category will be re-computed on call.
|category| . The actual settings part of this category will be re - computed on call .
async handleSettingCategory(player, category) {
        const settings = new Set();
        for (const setting of this.settings_().getSettings()) {
            if (setting.category !== category)
                continue;
            settings.add(setting);
        }
        const sortedSettings =
            Array.from(settings).sort((lhs, rhs) => lhs.name.localeCompare(rhs.name));
        const innerMenu = new Menu('Choose a setting', ['Setting', 'Value']);
        for (const setting of sortedSettings) {
            let valueLabel = 'null';
            switch (setting.type) {
                case Setting.TYPE_BOOLEAN:
                    valueLabel = setting.value ? 'enabled' : 'disabled';
                    if (setting.value != setting.defaultValue) {
                        valueLabel = '{FFFF00}' + valueLabel + '{FFFFFF} (default: ' +
                                        (setting.defaultValue ? 'enabled' : 'disabled') + ')';
                    }
                    break;
                case Setting.TYPE_NUMBER:
                    valueLabel = '' + setting.value;
                    if (setting.value != setting.defaultValue) {
                        valueLabel = '{FFFF00}' + valueLabel + '{FFFFFF} (default: ' +
                                        setting.defaultValue + ')';
                    }
                    break;
                case Setting.TYPE_STRING:
                    valueLabel = setting.value;
                    if (setting.value != setting.defaultValue) {
                        valueLabel = '{FFFF00}' + valueLabel + '{FFFFFF} (default: ' +
                                        setting.defaultValue + ')';
                    }
                    break;
                default:
                    throw new Error('Invalid setting type for ' + setting.name);
            }
            innerMenu.addItem(setting.name, valueLabel, async(player) => {
                switch (setting.type) {
                    case Setting.TYPE_BOOLEAN:
                        await this.handleBooleanSettingModification(player, setting);
                        break;
                    case Setting.TYPE_NUMBER:
                        await this.handleNumberSettingModification(player, setting);
                        break;
                    case Setting.TYPE_STRING:
                        await this.handleStringSettingModification(player, setting);
                        break;
                }
            });
        }
        await innerMenu.displayForPlayer(player);
    }
async handleSettingCategory ( player , category ) { const settings = new Set ( ) ; for ( const setting of this . settings_ ( ) . getSettings ( ) ) { if ( setting . category !== category ) continue ; settings . add ( setting ) ; } const sortedSettings = Array . from ( settings ) . sort ( ( lhs , rhs ) => lhs . name . localeCompare ( rhs . name ) ) ; const innerMenu = new Menu ( 'Choose a setting' , [ 'Setting' , 'Value' ] ) ; for ( const setting of sortedSettings ) { let valueLabel = 'null' ; switch ( setting . type ) { case Setting . TYPE_BOOLEAN : valueLabel = setting . value ? 'enabled' : 'disabled' ; if ( setting . value != setting . defaultValue ) { valueLabel = '{FFFF00}' + valueLabel + '{FFFFFF} (default: ' + ( setting . defaultValue ? 'enabled' : 'disabled' ) + ')' ; } break ; case Setting . TYPE_NUMBER : valueLabel = '' + setting . value ; if ( setting . value != setting . defaultValue ) { valueLabel = '{FFFF00}' + valueLabel + '{FFFFFF} (default: ' + setting . defaultValue + ')' ; } break ; case Setting . TYPE_STRING : valueLabel = setting . value ; if ( setting . value != setting . defaultValue ) { valueLabel = '{FFFF00}' + valueLabel + '{FFFFFF} (default: ' + setting . defaultValue + ')' ; } break ; default : throw new Error ( 'Invalid setting type for ' + setting . name ) ; } innerMenu . addItem ( setting . name , valueLabel , async ( player ) => { switch ( setting . type ) { case Setting . TYPE_BOOLEAN : await this . handleBooleanSettingModification ( player , setting ) ; break ; case Setting . TYPE_NUMBER : await this . handleNumberSettingModification ( player , setting ) ; break ; case Setting . TYPE_STRING : await this . handleStringSettingModification ( player , setting ) ; break ; } } ) ; } await innerMenu . displayForPlayer ( player ) ; }
|category|.
|category| .
// Fetch the settings which are part of the given |category| first. // Add a menu item for the particular setting, that will in turn defer to a // function that allows the particular setting to be changed.