diff --git a/src/tools/trackeditor/gui/CheckDialog.java b/src/tools/trackeditor/gui/CheckDialog.java index 2f730d919..3fbda14cb 100644 --- a/src/tools/trackeditor/gui/CheckDialog.java +++ b/src/tools/trackeditor/gui/CheckDialog.java @@ -15,6 +15,7 @@ import javax.swing.JTextArea; import javax.swing.WindowConstants; import utils.Editor; +import utils.SegmentVector; import utils.TrackData; import utils.circuit.EnvironmentMapping; import utils.circuit.Segment; @@ -74,6 +75,7 @@ public class CheckDialog extends JDialog { public void componentShown(ComponentEvent e) { + checkTrackHeight(); checkSurfaces(); checkObjects(); checkTerrainGeneration(); @@ -87,6 +89,80 @@ public class CheckDialog extends JDialog this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); } + private void checkTrackHeight() + { + SegmentVector segments = editorFrame.getTrackData().getSegments(); + + double width = editorFrame.getTrackData().getMainTrack().getWidth(); + + for (int i = 0; i < segments.size(); i++) + { + Segment segment = segments.get(i); + + String segmentInfo = "Segment " + segment.getName() + " : "; + + double heightStartLeft = segment.getHeightStartLeft(); + boolean hasHeightStartLeft = !Double.isNaN(heightStartLeft); + + double heightStartRight = segment.getHeightStartRight(); + boolean hasHeightStartRight = !Double.isNaN(heightStartRight); + + boolean hasBankingStartFromHeights = hasHeightStartLeft && hasHeightStartRight && heightStartLeft != heightStartRight; + + double bankingStart = segment.getBankingStart(); + boolean hasBankingStart = !Double.isNaN(bankingStart); + + // Track must start at an elevation of 0.0. + if (i == 0) + { + if (hasHeightStartLeft && hasHeightStartRight) + { + double centerHeight = (heightStartLeft + heightStartRight) / 2.0; + + if (centerHeight != 0.0) + { + textArea.append(segmentInfo + "Track height at start must be 0. Actual height: " + centerHeight +"\n"); + } + } + } + + if (hasBankingStart && hasBankingStartFromHeights) + { + textArea.append(segmentInfo + "Banking start angle and banking from heights\n"); + + double bankingFromHeights = Math.atan2(heightStartLeft - heightStartRight, width) * 180.0 / Math.PI; + + if (bankingStart != bankingFromHeights) + { + textArea.append(segmentInfo + "Banking start: " + bankingStart + " doesn't match banking from heights: " + bankingFromHeights + "\n"); + } + } + + double heightEndLeft = segment.getHeightEndLeft(); + boolean hasHeightEndLeft = !Double.isNaN(heightEndLeft); + + double heightEndRight = segment.getHeightEndRight(); + boolean hasHeightEndRight = !Double.isNaN(heightEndRight); + + boolean hasBankingEndFromHeights = hasHeightEndLeft && hasHeightEndRight && heightEndLeft != heightEndRight; + + double bankingEnd = segment.getBankingEnd(); + boolean hasBankingEnd = !Double.isNaN(bankingEnd); + + if (hasBankingEnd && hasBankingEndFromHeights) + { + textArea.append(segmentInfo + "Banking end angle and banking from heights\n"); + + double bankingFromHeights = Math.atan2(heightEndLeft - heightEndRight, width) * 180.0 / Math.PI; + + if (bankingEnd != bankingFromHeights) + { + textArea.append(segmentInfo + "Banking end: " + bankingEnd + " doesn't match banking from heights: " + bankingFromHeights + "\n"); + } + } + } + } + private void checkGraphic() { String image = editorFrame.getTrackData().getGraphic().getBackgroundImage();