ConceptCreator/src/app/project/game-model/characters/Character.ts
Sebastian Böckelmann 448ff5bd1b
All checks were successful
E2E Testing / test (push) Successful in 1m36s
Add CharacterRelation Gamesystems to CharacterRelation and adjust ProductGeneration
2024-04-19 14:46:02 +02:00

89 lines
3.6 KiB
TypeScript

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<any, any>[] = []
characterRelations: CharacterRelation[] = []
characterRelationGamesystems: Gamesystem<any, any>[] = []
constructor(componentName: string, componentDescription: string) {
super(componentName, componentDescription, ModelComponentType.CHARACTER);
}
addCharacterSpecificSimpleTemplatesystem(gamesystem: Gamesystem<any, any>, 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<any, any>, 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;
}
}