issue-15 #21

Merged
sebastian merged 60 commits from issue-15 into main 2024-03-22 08:46:49 +01:00
5 changed files with 79 additions and 32 deletions
Showing only changes of commit b62f93bfd5 - Show all commits

View File

@ -9,6 +9,42 @@ class DeleteTransaction {
fs.unlinkSync(filename); fs.unlinkSync(filename);
console.log("Delete ", filename); console.log("Delete ", filename);
} }
static deleteGamesystem(projectDir, componentName) {
const gamesystemDir = path.join(projectDir, "gamesystems");
const gamesystemFile = this.findGamesystemPath(gamesystemDir, componentName);
try {
if (gamesystemFile != undefined) {
console.log("Delete Gamesystem under File: ", gamesystemFile);
if (fs.lstatSync(gamesystemFile).isDirectory()) {
fs.rmSync(gamesystemFile, { recursive: true, force: true });
}
else {
fs.unlinkSync(gamesystemFile);
}
}
}
catch (e) {
console.log(e);
}
}
static findGamesystemPath(gamesystemRootDir, searchedFilename) {
const directoriesToProcess = [];
directoriesToProcess.push(gamesystemRootDir);
while (directoriesToProcess.length > 0) {
const currentDirectory = directoriesToProcess.shift();
const filesInDirectory = fs.readdirSync(currentDirectory);
for (let i = 0; i < filesInDirectory.length; i++) {
const currentFile = path.join(currentDirectory, filesInDirectory[i]);
if (fs.lstatSync(currentFile).isDirectory()) {
directoriesToProcess.push(currentFile);
}
if (path.parse(path.basename(currentFile)).name === searchedFilename) {
return currentFile;
}
}
}
return undefined;
}
} }
exports.DeleteTransaction = DeleteTransaction; exports.DeleteTransaction = DeleteTransaction;
//# sourceMappingURL=DeleteModel.js.map //# sourceMappingURL=DeleteModel.js.map

View File

@ -1,5 +1,6 @@
import * as path from "node:path"; import * as path from "node:path";
import * as fs from "fs"; import * as fs from "fs";
import {json} from "node:stream/consumers";
export class DeleteTransaction { export class DeleteTransaction {
static deleteScriptAccount(projectDir: string, componentName: string) { static deleteScriptAccount(projectDir: string, componentName: string) {
@ -7,4 +8,43 @@ export class DeleteTransaction {
fs.unlinkSync(filename) fs.unlinkSync(filename)
console.log("Delete ", filename) console.log("Delete ", filename)
} }
static deleteGamesystem(projectDir: string, componentName: string) {
const gamesystemDir = path.join(projectDir, "gamesystems")
const gamesystemFile = this.findGamesystemPath(gamesystemDir, componentName)
try {
if(gamesystemFile != undefined) {
console.log("Delete Gamesystem under File: ", gamesystemFile)
if(fs.lstatSync(gamesystemFile).isDirectory()) {
fs.rmSync(gamesystemFile, {recursive: true, force: true})
} else {
fs.unlinkSync(gamesystemFile)
}
}
}catch (e) {
console.log(e)
}
}
static findGamesystemPath(gamesystemRootDir: string, searchedFilename: string) {
const directoriesToProcess: string[] = [];
directoriesToProcess.push(gamesystemRootDir);
while(directoriesToProcess.length > 0) {
const currentDirectory = directoriesToProcess.shift();
const filesInDirectory = fs.readdirSync(currentDirectory!)
for(let i=0; i<filesInDirectory.length; i++) {
const currentFile = path.join(currentDirectory!, filesInDirectory[i])
if(fs.lstatSync(currentFile).isDirectory()) {
directoriesToProcess.push(currentFile);
}
if(path.parse(path.basename(currentFile)).name === searchedFilename) {
return currentFile;
}
}
}
return undefined
}
} }

View File

@ -219,5 +219,7 @@ function deleteComponent(component: DeleteModel) {
console.log("Delete Component") console.log("Delete Component")
if(component.modeltype == ModelComponentType.SCRIPTACCOUNT) { if(component.modeltype == ModelComponentType.SCRIPTACCOUNT) {
DeleteTransaction.deleteScriptAccount(projectDirectory, component.componentName); DeleteTransaction.deleteScriptAccount(projectDirectory, component.componentName);
} else if(component.modeltype === ModelComponentType.GAMESYTEM) {
DeleteTransaction.deleteGamesystem(projectDirectory, component.componentName);
} }
} }

View File

@ -119,6 +119,7 @@ export class AppComponent implements OnInit{
this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT)) this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT))
} else if(affectedModelComponent instanceof Gamesystem) { } else if(affectedModelComponent instanceof Gamesystem) {
this.gameModel!.removeGamesystem(affectedModelComponent); this.gameModel!.removeGamesystem(affectedModelComponent);
this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.GAMESYTEM))
this.gamesystemOverview!.refresh() this.gamesystemOverview!.refresh()
} }
} }

View File

@ -1,32 +0,0 @@
{
"componentName": "A",
"componentDescription": "",
"states": [
{
"initial": false,
"conditions": [],
"stateLabel": "A",
"stateDescription": ""
},
{
"initial": false,
"conditions": [],
"stateLabel": "B",
"stateDescription": ""
}
],
"transitions": [
{
"scriptAccountActions": [],
"scriptAccountConditions": [
{
"scriptAccount": "Temperature",
"minValue": 0,
"maxValue": "10"
}
],
"startingState": "A",
"endingState": "B"
}
]
}