2023-12-18 00:49:42 +04:00

90 lines
3.9 KiB
Java

package ProjectElectricLocomotive;
import java.awt.*;
import java.util.Objects;
public class ExtentionDrawingLoco {
public static DrawingLocomotive CreateDrawingLocomotive(String info, String separatorForObject, int width, int height)
{
String[] strs = info.split(separatorForObject);
if (strs.length == 7) {
DrawingLocomotive drawingLoco = new DrawingLocomotive(
Integer.parseInt(strs[0]),
Double.parseDouble(strs[1]),
new Color(
Integer.parseInt(strs[2]),
Integer.parseInt(strs[3]),
Integer.parseInt(strs[4])
),
width, height
);
if (Objects.equals(strs[5], "DrawingWheel")) {
drawingLoco._drawingWheels = new DrawingWheel();
} else if (Objects.equals(strs[5], "DrawingEmptyWheels")) {
drawingLoco._drawingWheels = new DrawingEmptyWheels();
} else if (Objects.equals(strs[5], "DrawingWheelsBlueCrom")) {
drawingLoco._drawingWheels = new DrawingWheelsBlueCrom();
}
drawingLoco.SetWheelsCount(Integer.parseInt(strs[6]));
return drawingLoco;
}
if (strs.length == 12) {
DrawingLocomotive drawingLoco = new DrawingElectricLocomotive(
Integer.parseInt(strs[0]),
Double.parseDouble(strs[1]),
new Color(
Integer.parseInt(strs[2]),
Integer.parseInt(strs[3]),
Integer.parseInt(strs[4])
),
new Color(
Integer.parseInt(strs[7]),
Integer.parseInt(strs[8]),
Integer.parseInt(strs[9])
),
Boolean.parseBoolean(strs[10]),
Boolean.parseBoolean(strs[11]),
width, height
);
if (Objects.equals(strs[5], "DrawingWheel")) {
drawingLoco._drawingWheels = new DrawingWheel();
} else if (Objects.equals(strs[5], "DrawingEmptyWheels")) {
drawingLoco._drawingWheels = new DrawingEmptyWheels();
} else if (Objects.equals(strs[5], "DrawingWheelsBlueCrom")) {
drawingLoco._drawingWheels = new DrawingWheelsBlueCrom();
}
drawingLoco.SetWheelsCount(Integer.parseInt(strs[6]));
return drawingLoco;
}
return null;
}
public static String GetDataForSave(DrawingLocomotive drawingLoco, String separatorForObject) {
var loco = drawingLoco.EntityLocomotive;
if (loco == null) {
return "";
}
String str = loco.Speed +
separatorForObject +
loco.Weight +
separatorForObject +
loco.BodyColor.getRed() + separatorForObject +
loco.BodyColor.getGreen() + separatorForObject +
loco.BodyColor.getBlue() + separatorForObject +
(drawingLoco._drawingWheels.GetWheelsCount() == null ? "null" : drawingLoco._drawingWheels.getClass()) + separatorForObject +
(drawingLoco._drawingWheels.GetWheelsCount() == null ? "0" : drawingLoco._drawingWheels.GetWheelsCount().count);
if (!(loco instanceof EntityElectricLocomotive electroLoco)) {
return str;
}
return str +
separatorForObject +
electroLoco.AdditionalColor.getRed() + separatorForObject +
electroLoco.AdditionalColor.getGreen() + separatorForObject +
electroLoco.AdditionalColor.getBlue() + separatorForObject +
electroLoco.Horns +
separatorForObject +
electroLoco.SeifBatteries;
}
}