From 54b86ef525d983d1acb50a036e0af59c97148d5d Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sat, 27 Mar 2010 17:45:26 +0000 Subject: [PATCH] Save and load S-bends --- schemas/map.xsd | 14 +++++++++++++- src/Map.cpp | 16 ++++++++++++++++ src/SBend.cpp | 7 +++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/schemas/map.xsd b/schemas/map.xsd index 6e3e0e0..6a9eadb 100644 --- a/schemas/map.xsd +++ b/schemas/map.xsd @@ -45,7 +45,19 @@ + type="xs:string"/> + + + + + + + + + diff --git a/src/Map.cpp b/src/Map.cpp index 1327d6a..19a53e1 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -1452,6 +1452,8 @@ public: handlePoints(attrs); else if (localName == "slopeTrack") handleSlopeTrack(attrs); + else if (localName == "sbendTrack") + handleSBendTrack(attrs); else if (localName == "stationPart") handleStationPart(attrs); else if (localName == "station") @@ -1570,6 +1572,20 @@ private: makeSlopeTrack(axis, slope, slopeBefore, slopeAfter)); } + void handleSBendTrack(const AttributeSet attrs) + { + string align; + attrs.get("align", align); + + track::Direction axis = align == "x" ? axis::X : axis::Y; + + int offset, straight; + attrs.get("offset", offset); + attrs.get("straight", straight); + + myMap->setTrackAt(tile, makeSBend(axis, straight, offset)); + } + void handlePoints(const AttributeSet& attrs) { string align; diff --git a/src/SBend.cpp b/src/SBend.cpp index 182b08e..e1021b7 100644 --- a/src/SBend.cpp +++ b/src/SBend.cpp @@ -54,7 +54,7 @@ private: void ensureValidDirection(track::Direction dir) const; Point origin; - int straight, offset; + const int straight, offset; float height; track::Direction axis; @@ -179,7 +179,10 @@ void SBend::ensureValidDirection(track::Direction dir) const xml::element SBend::toXml() const { - assert(false); + return xml::element("sbendTrack") + .addAttribute("align", axis == axis::X ? "x" : "y") + .addAttribute("offset", offset) + .addAttribute("straight", straight); } ITrackSegmentPtr makeSBend(track::Direction dir, int straight, int off) -- 2.39.2