diff --git a/src/DrawingObjectGasolineTanker.java b/src/DrawingObjectGasolineTanker.java index c637751..53b932c 100644 --- a/src/DrawingObjectGasolineTanker.java +++ b/src/DrawingObjectGasolineTanker.java @@ -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; } diff --git a/src/ExtentionGasolineTanker.java b/src/ExtentionGasolineTanker.java new file mode 100644 index 0000000..f1b0cb2 --- /dev/null +++ b/src/ExtentionGasolineTanker.java @@ -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(); + } +} diff --git a/src/IDrawingObject.java b/src/IDrawingObject.java index 3df3eb3..561bb92 100644 --- a/src/IDrawingObject.java +++ b/src/IDrawingObject.java @@ -6,4 +6,5 @@ public interface IDrawingObject { void MoveObject(Direction direction); void DrawingObject(Graphics g); float[] GetCurrentPosition(); + String GetInfo(); }