@@ -141,25 +141,53 @@ public Tileset LoadWorldMapTileset(MapType mapType)
141141 public void SaveWorldMap ( Map map )
142142 {
143143 var length = map . CompressedSize ;
144- if ( length > OverworldRowDataMaxLength )
144+ int maxLength =
145+ map . MapType == MapType . Overworld ? OverworldRowDataMaxLength :
146+ map . MapType == MapType . Underworld ? UnderworldRowDataMaxLength :
147+ map . MapType == MapType . Moon ? MoonRowDataMaxLength : 0 ;
148+ if ( length > maxLength )
145149 {
146- throw new IndexOutOfRangeException ( $ "Overworld map data is too big: { length } bytes used, { OverworldRowDataMaxLength } bytes allowed") ;
150+ throw new IndexOutOfRangeException ( $ "World map data is too big: { length } bytes used, { maxLength } bytes allowed") ;
147151 }
148152
149- byte [ ] pointerBytes = new byte [ OverworldRowCount * 2 ] ;
153+ byte [ ] pointerBytes = new byte [ 2 * map . Height ] ;
150154 map . GetCompressedData ( out byte [ ] data , out ushort [ ] pointers ) ;
151155 Buffer . BlockCopy ( pointers , 0 , pointerBytes , 0 , pointerBytes . Length ) ;
152156
153- Put ( OverworldRowDataOffset , data ) ;
154- Put ( OverworldRowPointersOffset , pointerBytes ) ;
157+ if ( map . MapType == MapType . Overworld )
158+ {
159+ Put ( OverworldRowDataOffset , data ) ;
160+ Put ( OverworldRowPointersOffset , pointerBytes ) ;
161+ }
162+ else if ( map . MapType == MapType . Underworld )
163+ {
164+ Put ( UnderworldRowDataOffset , data ) ;
165+ Put ( UnderworldRowPointersOffset , pointerBytes ) ;
166+ }
167+ else if ( map . MapType == MapType . Moon )
168+ {
169+ Put ( MoonRowDataOffset , data ) ;
170+ Put ( MoonRowPointersOffset , pointerBytes ) ;
171+ }
155172 }
156173
157- public void SaveWorldMapTileset ( Tileset tileset )
174+ public void SaveWorldMapTileset ( MapType mapType , Tileset tileset )
158175 {
159176 byte [ ] propertyBytes = new byte [ MapTileCount * 2 ] ;
160177 Buffer . BlockCopy ( tileset . TileProperties , 0 , propertyBytes , 0 , propertyBytes . Length ) ;
161178
162- Put ( OverworldTilePropertiesOffset , propertyBytes ) ;
179+ if ( mapType == MapType . Overworld )
180+ {
181+ Put ( OverworldTilePropertiesOffset , propertyBytes ) ;
182+ }
183+ else if ( mapType == MapType . Underworld )
184+ {
185+ Put ( UnderworldTilePropertiesOffset , propertyBytes ) ;
186+ }
187+ else if ( mapType == MapType . Moon )
188+ {
189+ Put ( MoonTilePropertiesOffset , propertyBytes ) ;
190+ }
163191 }
164192 }
165193}
0 commit comments