Implement basic version of characters #32
							
								
								
									
										31
									
								
								app/storage/loader/CharacterLoader.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								app/storage/loader/CharacterLoader.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
Object.defineProperty(exports, "__esModule", { value: true });
 | 
			
		||||
exports.CharacterLoader = void 0;
 | 
			
		||||
const StoreComponent_1 = require("../StoreComponent");
 | 
			
		||||
const FileUtils_1 = require("../FileUtils");
 | 
			
		||||
const ModelComponentType_1 = require("../../../src/app/project/game-model/ModelComponentType");
 | 
			
		||||
const fs = require("fs");
 | 
			
		||||
class CharacterLoader {
 | 
			
		||||
    constructor(characterDir) {
 | 
			
		||||
        this.characterDir = characterDir;
 | 
			
		||||
    }
 | 
			
		||||
    loadCharacters() {
 | 
			
		||||
        const characterFiles = FileUtils_1.FileUtils.listFilesInDirectory(this.characterDir);
 | 
			
		||||
        const loadedCharacters = [];
 | 
			
		||||
        characterFiles.forEach(characterFile => {
 | 
			
		||||
            const loadedCharacter = this.loadSingleCharacter(characterFile);
 | 
			
		||||
            if (loadedCharacter != undefined) {
 | 
			
		||||
                loadedCharacters.push(loadedCharacter);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
        return loadedCharacters;
 | 
			
		||||
    }
 | 
			
		||||
    loadSingleCharacter(characterFile) {
 | 
			
		||||
        if (characterFile.endsWith(".json")) {
 | 
			
		||||
            const characterData = fs.readFileSync(characterFile, 'utf-8');
 | 
			
		||||
            return new StoreComponent_1.StoreComponent(characterData, characterFile, ModelComponentType_1.ModelComponentType.SCRIPTACCOUNT);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
exports.CharacterLoader = CharacterLoader;
 | 
			
		||||
//# sourceMappingURL=CharacterLoader.js.map
 | 
			
		||||
							
								
								
									
										34
									
								
								app/storage/loader/CharacterLoader.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								app/storage/loader/CharacterLoader.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
			
		||||
import {StoreComponent} from "../StoreComponent";
 | 
			
		||||
import {FileUtils} from "../FileUtils";
 | 
			
		||||
import {ModelComponentType} from "../../../src/app/project/game-model/ModelComponentType";
 | 
			
		||||
import * as fs from "fs";
 | 
			
		||||
import {ModelComponentFileDirectory} from "../ModelComponentFileDirectory";
 | 
			
		||||
import {load} from "@angular-devkit/build-angular/src/utils/server-rendering/esm-in-memory-loader/loader-hooks";
 | 
			
		||||
 | 
			
		||||
export class CharacterLoader {
 | 
			
		||||
  characterDir: string
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  constructor(characterDir: string) {
 | 
			
		||||
    this.characterDir = characterDir;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  loadCharacters(): StoreComponent[] {
 | 
			
		||||
    const characterFiles = FileUtils.listFilesInDirectory(this.characterDir);
 | 
			
		||||
    const loadedCharacters: StoreComponent[] = []
 | 
			
		||||
    characterFiles.forEach(characterFile => {
 | 
			
		||||
      const loadedCharacter = this.loadSingleCharacter(characterFile);
 | 
			
		||||
      if(loadedCharacter != undefined) {
 | 
			
		||||
        loadedCharacters.push(loadedCharacter)
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    return loadedCharacters;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private loadSingleCharacter(characterFile: string) {
 | 
			
		||||
    if(characterFile.endsWith(".json")) {
 | 
			
		||||
      const characterData = fs.readFileSync(characterFile, 'utf-8');
 | 
			
		||||
      return new StoreComponent(characterData, characterFile, ModelComponentType.SCRIPTACCOUNT);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -6,6 +6,7 @@ const path = require("node:path");
 | 
			
		||||
const ModelComponentFileDirectory_1 = require("../ModelComponentFileDirectory");
 | 
			
		||||
const ScriptAccountLoader_1 = require("./ScriptAccountLoader");
 | 
			
		||||
const GamesystemLoader_1 = require("./GamesystemLoader");
 | 
			
		||||
const CharacterLoader_1 = require("./CharacterLoader");
 | 
			
		||||
class GameModelLoader {
 | 
			
		||||
    constructor(gameModelDir) {
 | 
			
		||||
        this.gameModelDir = gameModelDir;
 | 
			
		||||
@ -14,7 +15,8 @@ class GameModelLoader {
 | 
			
		||||
        const gameModelName = path.basename(this.gameModelDir);
 | 
			
		||||
        const storedScriptAccounts = this.loadScriptAccountComponents();
 | 
			
		||||
        const storedGamesystems = this.loadGamesystems();
 | 
			
		||||
        return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, []);
 | 
			
		||||
        const storedCharacters = this.loadCharacters();
 | 
			
		||||
        return new StoredGameModel_1.StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters);
 | 
			
		||||
    }
 | 
			
		||||
    loadScriptAccountComponents() {
 | 
			
		||||
        const scriptAccountDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.SCRIPTACCOUNT_DIR_NAME);
 | 
			
		||||
@ -26,6 +28,11 @@ class GameModelLoader {
 | 
			
		||||
        const gamesystemLoader = new GamesystemLoader_1.GamesystemLoader(gamesystemDir);
 | 
			
		||||
        return gamesystemLoader.loadGamesystems();
 | 
			
		||||
    }
 | 
			
		||||
    loadCharacters() {
 | 
			
		||||
        const characterDir = path.join(this.gameModelDir, ModelComponentFileDirectory_1.ModelComponentFileDirectory.CHARACTER_DIR_NAME);
 | 
			
		||||
        const characterLoader = new CharacterLoader_1.CharacterLoader(characterDir);
 | 
			
		||||
        return characterLoader.loadCharacters();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
exports.GameModelLoader = GameModelLoader;
 | 
			
		||||
//# sourceMappingURL=GameModelLoader.js.map
 | 
			
		||||
@ -5,6 +5,7 @@ import * as fs from "fs";
 | 
			
		||||
import {ModelComponentFileDirectory} from "../ModelComponentFileDirectory";
 | 
			
		||||
import {ScriptAccountLoader} from "./ScriptAccountLoader";
 | 
			
		||||
import {GamesystemLoader} from "./GamesystemLoader";
 | 
			
		||||
import {CharacterLoader} from "./CharacterLoader";
 | 
			
		||||
 | 
			
		||||
export class GameModelLoader {
 | 
			
		||||
  gameModelDir: string
 | 
			
		||||
@ -19,8 +20,9 @@ export class GameModelLoader {
 | 
			
		||||
 | 
			
		||||
    const storedScriptAccounts = this.loadScriptAccountComponents();
 | 
			
		||||
    const storedGamesystems = this.loadGamesystems();
 | 
			
		||||
    const storedCharacters = this.loadCharacters()
 | 
			
		||||
 | 
			
		||||
    return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, []);
 | 
			
		||||
    return new StoredGameModel(gameModelName, storedScriptAccounts, storedGamesystems, storedCharacters);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private loadScriptAccountComponents() {
 | 
			
		||||
@ -35,6 +37,12 @@ export class GameModelLoader {
 | 
			
		||||
    return gamesystemLoader.loadGamesystems();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private loadCharacters(): StoreComponent[] {
 | 
			
		||||
    const characterDir = path.join(this.gameModelDir, ModelComponentFileDirectory.CHARACTER_DIR_NAME);
 | 
			
		||||
    const characterLoader = new CharacterLoader(characterDir)
 | 
			
		||||
    return characterLoader.loadCharacters();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -23,6 +23,7 @@ import {GamesystemSerializer} from "./project/serializer/GamesystemSerializer";
 | 
			
		||||
import {Character} from "./project/game-model/characters/Character";
 | 
			
		||||
import {CharacterOverviewComponent} from "./side-overviews/character-overview/character-overview.component";
 | 
			
		||||
import {CharacterSerializer} from "./project/serializer/CharacterSerializer";
 | 
			
		||||
import {CharacterParser} from "./project/parser/characterParser/CharacterParser";
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'app-root',
 | 
			
		||||
@ -203,11 +204,14 @@ export class AppComponent implements OnInit{
 | 
			
		||||
    const gamesystemParser = new GamesystemParser(scriptAccounts);
 | 
			
		||||
    const gamesystems = gamesystemParser.parseStoredGamesystems(storedGameModel.storedGamesystems);
 | 
			
		||||
 | 
			
		||||
    const characterParser = new CharacterParser();
 | 
			
		||||
    const characters = characterParser.parseCharacters(storedGameModel.storedCharacters);
 | 
			
		||||
 | 
			
		||||
    gameModel.scriptAccounts = scriptAccounts
 | 
			
		||||
    gameModel.gamesystems = gamesystems
 | 
			
		||||
    gameModel.generateProductSystemContents()
 | 
			
		||||
 | 
			
		||||
    console.log(gameModel.scriptAccounts)
 | 
			
		||||
    gameModel.characters = characters
 | 
			
		||||
 | 
			
		||||
    this.gameModel = gameModel;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -16,8 +16,6 @@ export class GameModel {
 | 
			
		||||
 | 
			
		||||
  constructor(gameModelName: string) {
 | 
			
		||||
    this.gameModelName = gameModelName;
 | 
			
		||||
    this.characters.push(new Character("Astrid Hofferson", ""))
 | 
			
		||||
    this.characters.push(new Character("Hicks Haddock", ""))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  addGamesystem(gamesystem: Gamesystem<any, any>) {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										16
									
								
								src/app/project/parser/characterParser/CharacterParser.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/app/project/parser/characterParser/CharacterParser.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
			
		||||
import {StoreComponent} from "../../../../../app/storage/StoreComponent";
 | 
			
		||||
import {Character} from "../../game-model/characters/Character";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export class CharacterParser {
 | 
			
		||||
 | 
			
		||||
  public parseCharacters(characters: StoreComponent[]): Character[] {
 | 
			
		||||
    const loadedCharacters: Character[] = []
 | 
			
		||||
    characters.forEach(character => loadedCharacters.push(this.parseSingleCharacter(JSON.parse(character.jsonString))))
 | 
			
		||||
    return loadedCharacters;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private parseSingleCharacter(characterData: any): Character {
 | 
			
		||||
    return new Character(characterData.componentName, characterData.componentDescription);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user