template-systems #41

Merged
sebastian merged 30 commits from template-systems into main 2024-04-19 21:10:01 +02:00
5 changed files with 51 additions and 2 deletions
Showing only changes of commit 26db5392a4 - Show all commits

View File

@ -14,3 +14,12 @@
<button mat-stroked-button class="specify-btn" (click)="openTemplateSpecificator()">Specify Templatesystem</button> <button mat-stroked-button class="specify-btn" (click)="openTemplateSpecificator()">Specify Templatesystem</button>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
<mat-card>
<mat-card-header>
<mat-card-title>Character-Relations</mat-card-title>
</mat-card-header>
<mat-card-content>
<p *ngFor="let characterRelation of character!.characterRelations">{{characterRelation.firstCharacter.componentName}} - {{characterRelation.secondCharacter.componentName}}</p>
</mat-card-content>
</mat-card>

View File

@ -10,6 +10,7 @@ import {TemplateType} from "./templates/TemplateType";
import {SimpleTemplateGamesystem} from "./templates/simpleGamesystem/SimpleTemplateGamesystem"; import {SimpleTemplateGamesystem} from "./templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem"; import {ProductTemplateSystem} from "./templates/productGamesystem/ProductTemplateSystem";
import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator"; import {ProductTemplateCreator} from "./templates/productGamesystem/ProductTemplateCreator";
import {CharacterRelation} from "./characters/CharacterRelation";
export class GameModel { export class GameModel {
gameModelName: string gameModelName: string
@ -127,12 +128,21 @@ export class GameModel {
const searchedCharacter = this.characters.find(character => character.componentName === characterName); const searchedCharacter = this.characters.find(character => character.componentName === characterName);
if(searchedCharacter == undefined) { if(searchedCharacter == undefined) {
const character = new Character(characterName, ""); const character = new Character(characterName, "");
this.createCharacterRelation(character)
this.characters.push(character) this.characters.push(character)
return character return character
} }
return undefined return undefined
} }
private createCharacterRelation(addedCharacter: Character) {
this.characters.forEach(character => {
const characterRelation = new CharacterRelation(character, addedCharacter);
character.addCharacterRelation(characterRelation);
addedCharacter.addCharacterRelation(characterRelation);
})
}
removeScriptAccount(scriptAccount: ScriptAccount) { removeScriptAccount(scriptAccount: ScriptAccount) {
if(scriptAccount != undefined) { if(scriptAccount != undefined) {
this.scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount); this.scriptAccounts = this.scriptAccounts.filter(s => s != scriptAccount);

View File

@ -6,11 +6,14 @@ import {Gamesystem} from "../gamesystems/Gamesystem";
import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemplateGamesystem"; import {SimpleTemplateGamesystem} from "../templates/simpleGamesystem/SimpleTemplateGamesystem";
import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem"; import {ProductTemplateSystem} from "../templates/productGamesystem/ProductTemplateSystem";
import {ProductGamesystem} from "../gamesystems/ProductGamesystem"; import {ProductGamesystem} from "../gamesystems/ProductGamesystem";
import {CharacterRelation} from "./CharacterRelation";
export class Character extends ModelComponent implements TemplateElement { export class Character extends ModelComponent implements TemplateElement {
characterSpecificTemplateSystems: Gamesystem<any, any>[] = [] characterSpecificTemplateSystems: Gamesystem<any, any>[] = []
characterRelations: CharacterRelation[] = []
constructor(componentName: string, componentDescription: string) { constructor(componentName: string, componentDescription: string) {
super(componentName, componentDescription, ModelComponentType.CHARACTER); super(componentName, componentDescription, ModelComponentType.CHARACTER);
} }
@ -36,6 +39,10 @@ export class Character extends ModelComponent implements TemplateElement {
} }
} }
addCharacterRelation(characterRelation: CharacterRelation) {
this.characterRelations.push(characterRelation)
}
private isTemplateSystemCharacterSpecific(gamesystemName: string) { private isTemplateSystemCharacterSpecific(gamesystemName: string) {
return this.characterSpecificTemplateSystems.find(gamesystem => gamesystem.componentName === gamesystemName) != undefined return this.characterSpecificTemplateSystems.find(gamesystem => gamesystem.componentName === gamesystemName) != undefined
} }

View File

@ -0,0 +1,14 @@
import {TemplateElement} from "../templates/TemplateElement";
import {Character} from "./Character";
export class CharacterRelation implements TemplateElement{
firstCharacter: Character
secondCharacter: Character
constructor(firstCharacter: Character, secondCharacter: Character) {
this.firstCharacter = firstCharacter;
this.secondCharacter = secondCharacter;
}
}

View File

@ -6,6 +6,8 @@ import {ScriptAccountConditionParser} from "../gamesystemParser/ScriptAccountCon
import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount"; import {ScriptAccount} from "../../game-model/scriptAccounts/ScriptAccount";
import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/SimpleTemplateState"; import {SimpleTemplateState} from "../../game-model/templates/simpleGamesystem/SimpleTemplateState";
import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition"; import {SimpleTemplateTransition} from "../../game-model/templates/simpleGamesystem/SimpleTemplateTransition";
import {CharacterRelation} from "../../game-model/characters/CharacterRelation";
import {load} from "@angular-devkit/build-angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks";
export class CharacterParser { export class CharacterParser {
@ -23,12 +25,19 @@ export class CharacterParser {
public parseCharacters(characters: StoreComponent[]): Character[] { public parseCharacters(characters: StoreComponent[]): Character[] {
const loadedCharacters: Character[] = [] const loadedCharacters: Character[] = []
characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString)))) characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString), loadedCharacters)))
return loadedCharacters; return loadedCharacters;
} }
private parseSingleCharacter(characterData: any): Character { private parseSingleCharacter(characterData: any, loadedCharacters: Character[]): Character {
const character = new Character(characterData.componentName, characterData.componentDescription); const character = new Character(characterData.componentName, characterData.componentDescription);
loadedCharacters.forEach(loadedCharacter => {
const characterRelation = new CharacterRelation(loadedCharacter, character);
loadedCharacter.addCharacterRelation(characterRelation)
character.addCharacterRelation(characterRelation)
})
const templateSpecificGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterSpecificTemplateSystems); const templateSpecificGamesystems = this.parseCharacterSpecificGamesystems(character, characterData.characterSpecificTemplateSystems);
templateSpecificGamesystems.forEach(system => character.addCharacterSpecificSimpleTemplatesystem(system)) templateSpecificGamesystems.forEach(system => character.addCharacterSpecificSimpleTemplatesystem(system))
return character; return character;