You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
module.exports = class {
|
|
onCreate(input) {
|
|
this.state = {
|
|
characters: input.characters,
|
|
modal: null,
|
|
}
|
|
}
|
|
|
|
open(modal) {
|
|
this.state.modal = modal
|
|
}
|
|
|
|
close() {
|
|
this.state.modal = null
|
|
}
|
|
|
|
characterRemoved({id}) {
|
|
this.state.characters = this.state.characters.filter(c => c.id !== id)
|
|
}
|
|
|
|
characterEdited(character, patch) {
|
|
const characters = this.state.characters.slice()
|
|
const index = characters.findIndex(c => c.id === character.id)
|
|
if (index === -1) {
|
|
return
|
|
}
|
|
|
|
characters[index] = Object.assign({}, characters[index], patch)
|
|
|
|
this.state.characters = characters
|
|
}
|
|
|
|
characterAdded(character) {
|
|
const index = this.state.characters.findIndex(c => c.id === character.id)
|
|
if (index !== -1) {
|
|
const characters = this.state.characters.slice()
|
|
characters[index] = character
|
|
this.state.characters = characters
|
|
|
|
return
|
|
}
|
|
|
|
this.state.characters = this.state.characters.concat(character)
|
|
}
|
|
|
|
characterNicksChanged(character, nicks) {
|
|
const characters = this.state.characters.slice()
|
|
const index = characters.findIndex(c => c.id === character.id)
|
|
if (index === -1) {
|
|
return
|
|
}
|
|
|
|
characters[index] = Object.assign(characters[index], {nicks: nicks.slice(), nick: (nicks[0] || "")})
|
|
|
|
this.state.characters = characters
|
|
}
|
|
}
|