import { Entity , ObjectIdColumn , Column } from 'typeorm' ; import { PlayerOwned } from './PlayerOwned' ; import { Personality } from '../../interfaces' ; @ Entity ( ) export class Personalities extends PlayerOwned { @ ObjectIdColumn ( ) public _id : string ; @ Column ( ) private personalities : { [ key ] : string ; } ; @ Column ( ) private activePersonalities : { [ key ] : boolean ; } ; public get $personalitiesData ( ) { return { personalities : this . personalities , activePersonalities : this . activePersonalities } ; } constructor ( ) { super ( ) ; if ( ! this . personalities ) this . personalities = { } ; if ( ! this . activePersonalities ) this . activePersonalities = { } ; } public allEarnedPersonalities ( ) { return Object . keys ( this . personalities ) ; } public has ( personality ) { return ! ! this . personalities [ personality ] ; } public isActive ( personality ) { return this . personalities [ personality ] && this . activePersonalities [ personality ] ; } public toggle ( personality ) { const name = ( < any > personality ) . name ; if ( ! this . personalities [ name ] ) return ; this . activePersonalities [ name ] = ! this . activePersonalities [ name ] ; const toggleOff = ( < any > personality ) . toggleOff ; if ( this . activePersonalities [ name ] && toggleOff ) { toggleOff . forEach ( pers => this . activePersonalities [ pers ] = false ) ; } } public add ( personality ) { this . personalities [ ( < any > personality ) . name ] = ( < any > personality ) . description ; } public resetPersonalitiesTo ( personalities ) { this . personalities = { } ; personalities . forEach ( pers => this . add ( pers ) ) ; } }