import {ModelComponent} from "../ModelComponent"; import {ModelComponentType} from "../ModelComponentType"; import {TemplateElement} from "../templates/TemplateElement"; import {TemplateGamesystem} from "../templates/TemplateGamesystem"; import {Gamesystem} from "../gamesystems/Gamesystem"; import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemplateGamesystem"; import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem"; import {ProductGamesystem} from "../gamesystems/ProductGamesystem"; import {CharacterRelation} from "./CharacterRelation"; export class Character extends ModelComponent implements TemplateElement { characterSpecificTemplateSystems: Gamesystem[] = [] characterRelations: CharacterRelation[] = [] characterRelationGamesystems: Gamesystem[] = [] constructor(componentName: string, componentDescription: string) { super(componentName, componentDescription, ModelComponentType.CHARACTER); } addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem, recursiveCall: boolean = false) { if(!this.isTemplateSystemCharacterSpecific(gamesystem.componentName)) { if(gamesystem instanceof SimpleTemplateGamesystem) { this.characterSpecificTemplateSystems.push(gamesystem) gamesystem.addTemplateElement(this) } else if(gamesystem instanceof ProductTemplateSystem) { this.characterSpecificTemplateSystems.push(gamesystem) gamesystem.addTemplateElement(this) if(!recursiveCall) { gamesystem.innerGamesystems.forEach(innerGamesystem => this.addCharacterSpecificSimpleTemplatesystem(innerGamesystem, true)) } } if(gamesystem.parentGamesystem != undefined) { this.addCharacterSpecificSimpleTemplatesystem(gamesystem.parentGamesystem, true) } } } addAsymetricCharacterRelationGamesystem(gamesystem: Gamesystem, recursiveCall: boolean = false) { if(!this.isTemplateSystemCharacterRelationSpecific(gamesystem.componentName)) { if(gamesystem instanceof SimpleTemplateGamesystem) { this.characterRelationGamesystems.push(gamesystem); gamesystem.addTemplateElement(this); this.characterRelations.forEach(characterRelation => { characterRelation.addCharacterRelationSystem(gamesystem) }) } else if(gamesystem instanceof ProductTemplateSystem) { this.characterRelationGamesystems.push(gamesystem); gamesystem.addTemplateElement(this); this.characterRelations.forEach(characterRelation => { characterRelation.addCharacterRelationSystem(gamesystem) }) if(!recursiveCall) { gamesystem.innerGamesystems.forEach(innerGamesystem => this.addAsymetricCharacterRelationGamesystem(innerGamesystem, true)) } } if(gamesystem.parentGamesystem != undefined) { this.addAsymetricCharacterRelationGamesystem(gamesystem.parentGamesystem, true) } } else { console.log("Was already added") console.log(this) } } addCharacterRelation(characterRelation: CharacterRelation) { this.characterRelations.push(characterRelation) } private isTemplateSystemCharacterSpecific(gamesystemName: string) { return this.characterSpecificTemplateSystems.find(gamesystem => gamesystem.componentName === gamesystemName) != undefined } private isTemplateSystemCharacterRelationSpecific(gamesystemName: string) { return this.characterRelationGamesystems.find(gamesystem => gamesystem.componentName === gamesystemName) != undefined; } }