diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d412ba8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[src/**] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + diff --git a/src/components/ChooseCharacters/ChooseCharacters.jsx b/src/components/ChooseCharacters/ChooseCharacters.jsx index c06c40c..047e4fc 100644 --- a/src/components/ChooseCharacters/ChooseCharacters.jsx +++ b/src/components/ChooseCharacters/ChooseCharacters.jsx @@ -12,11 +12,8 @@ class ChooseCharacters extends Component { selectedGroups: this.props.selectedGroups, showAlternatives: [] } - this.startGame = this.startGame.bind(this); - this.showGroupRows = this.showGroupRows.bind(this); this.toggleSelect = this.toggleSelect.bind(this); - this.selectAll = this.selectAll.bind(this); - this.selectNone = this.selectNone.bind(this); + this.startGame = this.startGame.bind(this); } getIndex(groupName) { @@ -28,7 +25,8 @@ class ChooseCharacters extends Component { } removeSelect(groupName) { - if(this.getIndex(groupName)<0) return; + if(this.getIndex(groupName)<0) + return; let newSelectedGroups = this.state.selectedGroups.slice(); newSelectedGroups.splice(this.getIndex(groupName), 1); this.setState({selectedGroups: newSelectedGroups}); @@ -39,55 +37,41 @@ class ChooseCharacters extends Component { } toggleSelect(groupName) { - if(this.getIndex(groupName) > -1) this.removeSelect(groupName); - else this.addSelect(groupName); + if(this.getIndex(groupName) > -1) + this.removeSelect(groupName); + else + this.addSelect(groupName); } - selectAll(whichKana) { - let thisKana = kanaDictionary[whichKana]; + selectAll(whichKana, altOnly=false, similarOnly=false) { + const thisKana = kanaDictionary[whichKana]; let newSelectedGroups = this.state.selectedGroups.slice(); - Object.keys(thisKana).map(function(groupName) { - if(!this.isSelected(groupName)) + Object.keys(thisKana).forEach(groupName => { + if(!this.isSelected(groupName) && ( + (altOnly && groupName.endsWith('_a')) || + (similarOnly && groupName.endsWith('_s')) || + (!altOnly && !similarOnly) + )) newSelectedGroups.push(groupName); - }, this); + }); this.setState({errMsg: '', selectedGroups: newSelectedGroups}); } - selectAllAlternative(whichKana) { - let thisKana = kanaDictionary[whichKana]; - let newSelectedGroups = this.state.selectedGroups.slice(); - Object.keys(thisKana).map(function(groupName) { - if(groupName.endsWith("_a")) - newSelectedGroups.push(groupName); - }, this); - this.setState({errMsg: '', selectedGroups: newSelectedGroups}); - } - - selectNone(whichKana) { + selectNone(whichKana, altOnly=false, similarOnly=false) { let newSelectedGroups = []; - this.state.selectedGroups.map(function(groupName) { + this.state.selectedGroups.forEach(groupName => { let mustBeRemoved = false; - Object.keys(kanaDictionary[whichKana]).map(function(removableGroupName) { - if(removableGroupName===groupName) + Object.keys(kanaDictionary[whichKana]).forEach(removableGroupName => { + if(removableGroupName === groupName && ( + (altOnly && groupName.endsWith('_a')) || + (similarOnly && groupName.endsWith('_s')) || + (!altOnly && !similarOnly) + )) mustBeRemoved = true; - }, this); + }); if(!mustBeRemoved) newSelectedGroups.push(groupName); - }, this); - this.setState({selectedGroups: newSelectedGroups}); - } - - selectNoneAlternative(whichKana) { - let newSelectedGroups = []; - this.state.selectedGroups.map(function(groupName) { - let mustBeRemoved = false; - Object.keys(kanaDictionary[whichKana]).map(function(removableGroupName) { - if(removableGroupName===groupName && groupName.endsWith("_a")) - mustBeRemoved = true; - }, this); - if(!mustBeRemoved) - newSelectedGroups.push(groupName); - }, this); + }); this.setState({selectedGroups: newSelectedGroups}); } @@ -125,27 +109,25 @@ class ChooseCharacters extends Component { status = 'unchecked' checkBtn += status - return