Project Service had to be deleted as the gamemodel binding would suffer flexibility
Some checks failed
E2E Testing / test (push) Failing after 1m33s
Some checks failed
E2E Testing / test (push) Failing after 1m33s
This commit is contained in:
parent
ed2f28760e
commit
ad36913ff9
41
app/storage/loader/GamesystemLoader.js
Normal file
41
app/storage/loader/GamesystemLoader.js
Normal file
@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GamesystemLoader = void 0;
|
||||
const StoreComponent_1 = require("../StoreComponent");
|
||||
const FileUtils_1 = require("../FileUtils");
|
||||
const fs = require("fs");
|
||||
const path = require("node:path");
|
||||
const ModelComponentType_1 = require("../../../src/app/project/game-model/ModelComponentType");
|
||||
class GamesystemLoader {
|
||||
constructor(gamesystemDir) {
|
||||
this.gamesystemDir = gamesystemDir;
|
||||
}
|
||||
loadGamesystems() {
|
||||
return this.loadGamesystemsRecursivly(this.gamesystemDir);
|
||||
}
|
||||
loadGamesystemsRecursivly(currentGamesystemDir) {
|
||||
let loadedGamesystems = [];
|
||||
const gamesystemFiles = FileUtils_1.FileUtils.listFilesInDirectory(currentGamesystemDir);
|
||||
gamesystemFiles.forEach(gamesystemFile => {
|
||||
if (fs.lstatSync(gamesystemFile).isDirectory()) {
|
||||
const childGamesystems = this.loadGamesystemsRecursivly(gamesystemFile);
|
||||
loadedGamesystems = loadedGamesystems.concat(childGamesystems);
|
||||
}
|
||||
else if (path.basename(gamesystemFile).endsWith(".json")) {
|
||||
const loadedGamesystem = this.loadGamesystem(gamesystemFile);
|
||||
if (loadedGamesystem != undefined) {
|
||||
loadedGamesystems.push(loadedGamesystem);
|
||||
}
|
||||
}
|
||||
});
|
||||
return loadedGamesystems;
|
||||
}
|
||||
loadGamesystem(gamesystemFile) {
|
||||
if (gamesystemFile.endsWith(".json")) {
|
||||
const gamesystemData = fs.readFileSync(gamesystemFile, 'utf-8');
|
||||
return new StoreComponent_1.StoreComponent(gamesystemData, gamesystemFile, ModelComponentType_1.ModelComponentType.GAMESYTEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.GamesystemLoader = GamesystemLoader;
|
||||
//# sourceMappingURL=GamesystemLoader.js.map
|
@ -1,4 +1,4 @@
|
||||
import {Component, NgZone, OnInit, ViewChild} from '@angular/core';
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import {MatDrawerContainer} from "@angular/material/sidenav";
|
||||
import {EditorComponent} from "./editor/editor.component";
|
||||
import {
|
||||
@ -7,14 +7,16 @@ import {
|
||||
import {MatDialog} from "@angular/material/dialog";
|
||||
import {DeleteConfirmationDialogComponent} from "./delete-confirmation-dialog/delete-confirmation-dialog.component";
|
||||
import {GamescriptOverviewComponent} from "./side-overviews/gamescript-overview/gamescript-overview.component";
|
||||
|
||||
import {ProjectService} from "./project/project.service";
|
||||
import {ModelComponentType} from "./project/game-model/ModelComponentType";
|
||||
import {ModelComponentTypeUtillities} from "./project/game-model/ModelComponentTypeUtillities";
|
||||
import {ScriptAccount} from "./project/game-model/scriptAccounts/ScriptAccount";
|
||||
import {Gamesystem} from "./project/game-model/gamesystems/Gamesystem";
|
||||
import {ModelComponent} from "./project/game-model/ModelComponent";
|
||||
import {GameModel} from "./project/game-model/GameModel";
|
||||
import {StoredGameModel} from "../../app/storage/StoredGameModel";
|
||||
import {GamesystemParser} from "./project/parser/gamesystemParser/GamesystemParser";
|
||||
import {ScriptAccountParser} from "./project/parser/ScriptAccountParser";
|
||||
import {ElectronService} from "./core/services";
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@ -31,9 +33,8 @@ export class AppComponent implements OnInit{
|
||||
|
||||
gameModel: GameModel | undefined
|
||||
|
||||
constructor(private zone: NgZone,
|
||||
private dialog: MatDialog,
|
||||
private projectService: ProjectService
|
||||
constructor(private electronService: ElectronService,
|
||||
private dialog: MatDialog
|
||||
) {
|
||||
|
||||
}
|
||||
@ -63,7 +64,7 @@ export class AppComponent implements OnInit{
|
||||
} break;
|
||||
case ModelComponentType.GAMESYTEM: {
|
||||
if(this.gamesystemOverview!.selectedGamesystem != undefined) {
|
||||
const gamesystem = this.projectService!.gameModel!.findGamesystem(this.gamesystemOverview!.selectedGamesystemName!);
|
||||
const gamesystem = this.gameModel!.findGamesystem(this.gamesystemOverview!.selectedGamesystemName!);
|
||||
this.editor!.openGameModelComponent(gamesystem!);
|
||||
}
|
||||
} break
|
||||
@ -78,7 +79,7 @@ export class AppComponent implements OnInit{
|
||||
dialogRef.afterClosed().subscribe(res => {
|
||||
if(res != undefined && res) {
|
||||
if(affectedModelComponent instanceof ScriptAccount) {
|
||||
this.projectService!.gameModel!.removeScriptAccount(affectedModelComponent);
|
||||
this.gameModel!.removeScriptAccount(affectedModelComponent);
|
||||
//this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT))
|
||||
} else if(affectedModelComponent instanceof Gamesystem) {
|
||||
//this.gameModel!.removeGamesystem(affectedModelComponent);
|
||||
@ -97,7 +98,7 @@ export class AppComponent implements OnInit{
|
||||
}
|
||||
|
||||
private onCreateNewScriptAccount() {
|
||||
const createdScriptAccount = this.projectService!.gameModel!.createScriptAccount("New ScriptAccount");
|
||||
const createdScriptAccount = this.gameModel!.createScriptAccount("New ScriptAccount");
|
||||
if(createdScriptAccount != undefined) {
|
||||
this.editor?.openGameModelComponent(createdScriptAccount);
|
||||
} else {
|
||||
@ -114,7 +115,7 @@ export class AppComponent implements OnInit{
|
||||
}
|
||||
|
||||
|
||||
const createdGamesystem = this.projectService!.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName);
|
||||
const createdGamesystem = this.gameModel!.createGamesystem("New Gamesystem", parentGamesystemName);
|
||||
if(createdGamesystem != undefined) {
|
||||
this.gamesystemOverview!.refresh();
|
||||
this.editor?.openGameModelComponent(createdGamesystem);
|
||||
@ -124,13 +125,13 @@ export class AppComponent implements OnInit{
|
||||
private getSelectedModelComponent(): ModelComponent | undefined {
|
||||
if(this.openContent == ModelComponentType.SCRIPTACCOUNT) {
|
||||
if(this.scriptAccountOverview != undefined) {
|
||||
return this.scriptAccountOverview!.selectedScriptAccount;
|
||||
return this.scriptAccountOverview.selectedScriptAccount;
|
||||
} else {
|
||||
console.log("[WARN] [App.component] ScriptAccountOverview is undefined")
|
||||
}
|
||||
} else if(this.openContent == ModelComponentType.GAMESYTEM){
|
||||
if(this.gamesystemOverview != undefined) {
|
||||
return this.gamesystemOverview!.getSelectedGamesystem()
|
||||
return this.gamesystemOverview.getSelectedGamesystem()
|
||||
} else {
|
||||
console.log("[WARN] [App.component] GamesystemOverview is undefined")
|
||||
}
|
||||
@ -139,30 +140,41 @@ export class AppComponent implements OnInit{
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.gameModel = this.projectService.gameModel
|
||||
/*this.gameModel = new GameModel("No More");
|
||||
this.gameModel.createScriptAccount("Temperature");
|
||||
this.gameModel.createScriptAccount("Luftfeuchtigkeit");
|
||||
if(this.electronService.isElectron) {
|
||||
this.electronService.ipcRenderer.on('get-project-data', () => {
|
||||
this.onSaveProject();
|
||||
})
|
||||
|
||||
const weather = new SimpleGamesystem("Weather");
|
||||
const season = new SimpleGamesystem("Season");
|
||||
this.electronService.ipcRenderer.on('open-project', (event: any, loadedProject: StoredGameModel) => {
|
||||
this.onLoadProject(loadedProject);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const springState = season.createState("Spring", "Spring, also known as springtime, is one of the four temperate seasons, succeeding winter and preceding summer.");
|
||||
const summerState = season.createState("Summer", "Summer is the hottest and brightest of the four temperate seasons, occurring after spring and before autumn. ");
|
||||
onLoadProject(storedGameModel: StoredGameModel) {
|
||||
const gameModel = new GameModel(storedGameModel.gameModelName)
|
||||
const gamesystemParser = new GamesystemParser();
|
||||
storedGameModel.loadedModels.forEach(storedComponent => {
|
||||
switch (storedComponent.componentType) {
|
||||
case ModelComponentType.SCRIPTACCOUNT: {
|
||||
const scriptAccount = ScriptAccountParser.parseScriptAccount(storedComponent);
|
||||
gameModel.addScriptAccount(scriptAccount);
|
||||
} break
|
||||
case ModelComponentType.GAMESYTEM: {
|
||||
gamesystemParser.parseGamesystem(storedComponent);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const sunnyState = weather.createState("Sunny", "The sun is shining. No clouds, no rain, no storm.");
|
||||
const rainingState = weather.createState("Raining", "It rains")
|
||||
gamesystemParser.computeGamesystemStructure().forEach(topGamesystem => {
|
||||
gameModel.addGamesystem(topGamesystem)
|
||||
})
|
||||
|
||||
season.createTransition(springState!, summerState!);
|
||||
weather.createTransition(sunnyState!, rainingState!);
|
||||
this.gameModel = gameModel;
|
||||
}
|
||||
|
||||
const weather_season = new ProductGamesystem("Weather-Season");
|
||||
weather_season.addChildGamesystem(weather);
|
||||
weather_season.addChildGamesystem(season);
|
||||
onSaveProject() {
|
||||
|
||||
weather_season.createState([springState!, sunnyState!]);
|
||||
|
||||
this.gameModel.addGamesystem(weather_season);*/
|
||||
}
|
||||
|
||||
openScriptAccountsOverview() {
|
||||
|
@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ProjectService } from './project.service';
|
||||
|
||||
describe('ProjectService', () => {
|
||||
let service: ProjectService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ProjectService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -1,57 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {ElectronService} from "../core/services";
|
||||
import {GameModel} from "./game-model/GameModel";
|
||||
import {StoredGameModel} from "../../../app/storage/StoredGameModel";
|
||||
import {ScriptAccount} from "./game-model/scriptAccounts/ScriptAccount";
|
||||
import {ModelComponentType} from "./game-model/ModelComponentType";
|
||||
import {ScriptAccountParser} from "./parser/ScriptAccountParser";
|
||||
import {GamesystemParser} from "./parser/gamesystemParser/GamesystemParser";
|
||||
import {Gamesystem} from "./game-model/gamesystems/Gamesystem";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProjectService {
|
||||
|
||||
gameModel: GameModel = new GameModel("New GameModel")
|
||||
constructor(private electronService: ElectronService) {
|
||||
if(electronService.isElectron) {
|
||||
electronService.ipcRenderer.on('get-project-data', (event: any, message: string) => {
|
||||
this.saveProject();
|
||||
})
|
||||
|
||||
electronService.ipcRenderer.on('open-project', (event: any, loadedProject: StoredGameModel) => {
|
||||
this.loadProject(loadedProject);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
saveProject() {
|
||||
|
||||
}
|
||||
|
||||
loadProject(storedGameModel: StoredGameModel) {
|
||||
const gameModel = new GameModel(storedGameModel.gameModelName)
|
||||
const gamesystemParser = new GamesystemParser();
|
||||
storedGameModel.loadedModels.forEach(storedComponent => {
|
||||
switch (storedComponent.componentType) {
|
||||
case ModelComponentType.SCRIPTACCOUNT: {
|
||||
const scriptAccount = ScriptAccountParser.parseScriptAccount(storedComponent);
|
||||
gameModel.addScriptAccount(scriptAccount);
|
||||
} break
|
||||
case ModelComponentType.GAMESYTEM: {
|
||||
gamesystemParser.parseGamesystem(storedComponent);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
gamesystemParser.computeGamesystemStructure().forEach(topGamesystem => {
|
||||
gameModel.addGamesystem(topGamesystem)
|
||||
})
|
||||
|
||||
console.log(gameModel)
|
||||
this.gameModel = gameModel;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user