This commit is contained in:
Кашин Максим 2022-12-13 19:30:51 +04:00
parent 8c08a8b884
commit 8c6e5da721
3 changed files with 53 additions and 0 deletions

View File

@ -36,6 +36,18 @@ public class DrawingObjectGasolineTanker implements IDrawingObject {
return _gasolineTanker.GetCurrentPosition();
return null;
}
@Override
public String GetInfo() {
if(_gasolineTanker==null)
return null;
return ExtentionGasolineTanker.GetDataForSave(_gasolineTanker);
}
public static IDrawingObject Create(String data){
return new DrawingObjectGasolineTanker(ExtentionGasolineTanker.CreateDrawingWarship(data));
}
public DrawingGasolineTanker GetGasolineTanker() {
return _gasolineTanker;
}

View File

@ -0,0 +1,40 @@
import java.awt.*;
public class ExtentionGasolineTanker {
private static final char _separatorForObject=':';
public static DrawingGasolineTanker CreateDrawingWarship(String info){
String[] strs = info.split(Character.toString(_separatorForObject));
int spd=Integer.parseInt(strs[0]);
float wght = Float.parseFloat(strs[1]);
Color bodyClr=new Color(Integer.parseInt(strs[2]));
IDrawningObjectWheels block = switch(strs[3]) {
case "DrawingWheels" -> new DrawingWheels(Integer.parseInt(strs[4]));
case "DrawingOrnamentWheelsFirst" -> new DrawingOrnamentWheelsFirst(Integer.parseInt(strs[4]));
case "DrawingOrnamentWheelsSecond" -> new DrawingOrnamentWheelsSecond(Integer.parseInt(strs[4]));
default -> null;
};
if (strs.length==5){
EntityGasolineTanker ent=new EntityGasolineTanker(spd,wght,bodyClr);
return new DrawingGasolineTanker(ent,block);
}
if(strs.length==9){
Color dopClr=new Color(Integer.parseInt(strs[5]));
boolean bdkit=Boolean.parseBoolean(strs[6]);
boolean ant=Boolean.parseBoolean(strs[7]);
EntityImprovedGasolineTanker ent = new EntityImprovedGasolineTanker(spd,wght,bodyClr,dopClr,bdkit,ant);
return new DrawingImprovedGasolineTanker(ent,block);
}
return null;
}
public static String GetDataForSave(DrawingGasolineTanker drawingGasolineTanker){
var gasolineTanker = drawingGasolineTanker.GasolineTanker;
var str = ""+gasolineTanker.getSpeed()+_separatorForObject+gasolineTanker.getWeight()+_separatorForObject+gasolineTanker.getBodyColor().getRGB()+_separatorForObject+drawingGasolineTanker.getWhees().getClass().getSimpleName()+_separatorForObject+drawingGasolineTanker.GetBlocks().GetCount();
if(!(gasolineTanker instanceof EntityImprovedGasolineTanker adv)){
return str;
}
return str+_separatorForObject+adv.GetDopColor().getRGB()+_separatorForObject+adv.GetBodyKit()+_separatorForObject+adv.GetAntena();
}
}

View File

@ -6,4 +6,5 @@ public interface IDrawingObject {
void MoveObject(Direction direction);
void DrawingObject(Graphics g);
float[] GetCurrentPosition();
String GetInfo();
}