issue-15 #21
@ -9,6 +9,42 @@ class DeleteTransaction {
 | 
			
		||||
        fs.unlinkSync(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;
 | 
			
		||||
//# sourceMappingURL=DeleteModel.js.map
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
import * as path from "node:path";
 | 
			
		||||
import * as fs from "fs";
 | 
			
		||||
import {json} from "node:stream/consumers";
 | 
			
		||||
 | 
			
		||||
export class DeleteTransaction {
 | 
			
		||||
  static deleteScriptAccount(projectDir: string, componentName: string) {
 | 
			
		||||
@ -7,4 +8,43 @@ export class DeleteTransaction {
 | 
			
		||||
    fs.unlinkSync(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
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -219,5 +219,7 @@ function deleteComponent(component: DeleteModel) {
 | 
			
		||||
  console.log("Delete Component")
 | 
			
		||||
  if(component.modeltype == ModelComponentType.SCRIPTACCOUNT) {
 | 
			
		||||
    DeleteTransaction.deleteScriptAccount(projectDirectory, component.componentName);
 | 
			
		||||
  } else if(component.modeltype === ModelComponentType.GAMESYTEM) {
 | 
			
		||||
    DeleteTransaction.deleteGamesystem(projectDirectory, component.componentName);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -119,6 +119,7 @@ export class AppComponent implements OnInit{
 | 
			
		||||
          this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.SCRIPTACCOUNT))
 | 
			
		||||
        } else if(affectedModelComponent instanceof Gamesystem) {
 | 
			
		||||
          this.gameModel!.removeGamesystem(affectedModelComponent);
 | 
			
		||||
          this.electronService.ipcRenderer.send('delete-component', new DeleteModel(affectedModelComponent.componentName, ModelComponentType.GAMESYTEM))
 | 
			
		||||
          this.gamesystemOverview!.refresh()
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@ -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"
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user