Pr_robot_factory/facade/FactorySystem.java

51 lines
1.3 KiB
Java
Raw Normal View History

package facade;
import domain.Factory;
import domain.Robot;
2023-01-09 23:32:30 +01:00
import infrastructure.Persistenz;
public class FactorySystem {
private Factory factory;
private String factoryName;
public FactorySystem(String factoryName){
this.factoryName = factoryName;
if(Persistenz.existsSavedData(factoryName)){
try{
this.factory = (Factory) Persistenz.loadFactoryData(factoryName);
2023-01-06 22:55:33 +01:00
System.out.println("Loading of old factory successful");
} catch (Exception e) {
System.out.println("Loading of old factory not possible");
2023-01-06 22:55:33 +01:00
System.out.println(e.getMessage());
}
}else{
this.factory = new Factory();
}
}
//provide robot attributes
public String[] getAllRobots(){
return factory.getRobotList();
}
//Creating a new robot
public boolean buildNewRobot(String name, int type) {
boolean check = factory.buildNewRobot(name, type);
if(check) {
2023-01-06 22:55:33 +01:00
try {
Persistenz.saveFactoryData(factory, factoryName);
}catch(Exception e){
System.out.println(e.getCause());
}
}
return check;
}
//provides a specific robot
2023-01-06 22:55:33 +01:00
public Robot searchForRobot(int id){
return factory.getRobotOfList(id);
}
}