2023-01-02 19:51:04 +01:00
|
|
|
package facade;
|
|
|
|
|
2023-01-07 16:34:36 +01:00
|
|
|
import domain.Factory;
|
|
|
|
import domain.Robot;
|
2023-01-02 19:51:04 +01:00
|
|
|
import infrastructure.Persistenz;
|
|
|
|
|
|
|
|
public class FactorySystem {
|
2023-01-03 01:18:57 +01:00
|
|
|
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");
|
2023-01-03 01:18:57 +01:00
|
|
|
} 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());
|
2023-01-03 01:18:57 +01:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
this.factory = new Factory();
|
|
|
|
}
|
2023-01-02 19:51:04 +01:00
|
|
|
|
2023-01-03 01:18:57 +01:00
|
|
|
}
|
2023-01-02 19:51:04 +01:00
|
|
|
|
2023-01-07 18:35:00 +01:00
|
|
|
//provide robot attributes
|
2023-01-03 01:18:57 +01:00
|
|
|
public String[] getAllRobots(){
|
2023-01-07 16:34:36 +01:00
|
|
|
return factory.getRobotList();
|
2023-01-03 01:18:57 +01:00
|
|
|
}
|
2023-01-07 18:35:00 +01:00
|
|
|
//Creating a new robot
|
|
|
|
public boolean buildNewRobot(String name, int type) {
|
2023-01-03 01:18:57 +01:00
|
|
|
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());
|
|
|
|
}
|
2023-01-03 01:18:57 +01:00
|
|
|
}
|
|
|
|
return check;
|
2023-01-02 19:51:04 +01:00
|
|
|
}
|
2023-01-07 18:35:00 +01:00
|
|
|
//provides a specific robot
|
2023-01-06 22:55:33 +01:00
|
|
|
public Robot searchForRobot(int id){
|
|
|
|
return factory.getRobotOfList(id);
|
|
|
|
}
|
|
|
|
|
2023-01-02 19:51:04 +01:00
|
|
|
}
|