56 lines
1.6 KiB
Java

package ProjectElectricLocomotive;
import java.awt.*;
public class ExtentionDrawingLoco {
public static DrawingLocomotive CreateDrawingLocomotive(String info, char separatorForObject, int width, int height)
{
String[] strs = info.split(String.valueOf(separatorForObject));
if(strs.length == 3){
return new DrawingLocomotive(
Integer.parseInt(strs[0]),
Integer.parseInt(strs[1]),
Color.getColor(strs[2]),
width,
height
);
}
if(strs.length == 6){
return new DrawingElectricLocomotive(
Integer.parseInt(strs[0]),
Integer.parseInt(strs[1]),
Color.getColor(strs[2]),
Color.getColor(strs[3]),
strs[4].equals(true),
strs[5].equals(true),
width,
height
);
}
return null;
}
public static String GetDataForSave(DrawingLocomotive drawingLoco, char separatorForObject)
{
var loco = drawingLoco.EntityLocomotive;
if (loco == null)
{
return null;
}
String str = loco.Speed + separatorForObject + loco.Weight + separatorForObject + loco.BodyColor.toString();
if (!(loco instanceof EntityElectricLocomotive electroLoco))
{
return str;
}
else
{
return str + separatorForObject + electroLoco.AdditionalColor.toString() + separatorForObject +
electroLoco.Horns + separatorForObject + electroLoco.SeifBatteries;
}
}
}