22
33import org .wurstscript .projectconfig .WurstProjectConfigData ;
44import org .wurstscript .projectconfig .WurstProjectBuildMapData ;
5+ import org .wurstscript .projectconfig .WurstProjectBuildPlayer ;
56import de .peeeq .wurstio .languageserver .WFile ;
67import de .peeeq .wurstio .languageserver .ProjectConfigBuilder ;
78import de .peeeq .wurstio .languageserver .WurstBuildConfig ;
1314
1415import java .io .File ;
1516import java .lang .reflect .Method ;
17+ import java .nio .charset .StandardCharsets ;
1618import java .nio .file .Files ;
1719import java .nio .file .Path ;
1820import java .util .List ;
@@ -236,7 +238,7 @@ public void mapHeaderConfigAcceptsAnArchiveWithoutAnHm3wPrefix() throws Exceptio
236238 Files .write (mapWithoutHeader , original );
237239
238240 Method applyMapHeader = ProjectConfigBuilder .class .getDeclaredMethod (
239- "applyMapHeader" , WurstProjectConfigData .class , File .class , int .class
241+ "applyMapHeader" , WurstProjectConfigData .class , File .class , int .class , String . class
240242 );
241243 applyMapHeader .setAccessible (true );
242244
@@ -250,7 +252,8 @@ public void mapHeaderConfigAcceptsAnArchiveWithoutAnHm3wPrefix() throws Exceptio
250252 null
251253 ),
252254 mapWithoutHeader .toFile (),
253- 3
255+ 3 ,
256+ "Existing map"
254257 );
255258
256259 assertEquals (Files .readAllBytes (mapWithoutHeader )[0 ], (byte ) 'H' );
@@ -269,14 +272,52 @@ public void mapHeaderConfigDoesNotReadAnArchiveWhenNothingNeedsChanging() throws
269272 Files .write (mapWithoutHeader , original );
270273
271274 Method applyMapHeader = ProjectConfigBuilder .class .getDeclaredMethod (
272- "applyMapHeader" , WurstProjectConfigData .class , File .class , int .class
275+ "applyMapHeader" , WurstProjectConfigData .class , File .class , int .class , String . class
273276 );
274277 applyMapHeader .setAccessible (true );
275- applyMapHeader .invoke (null , WurstProjectConfigData .empty (), mapWithoutHeader .toFile (), 0 );
278+ applyMapHeader .invoke (null , WurstProjectConfigData .empty (), mapWithoutHeader .toFile (), 0 , null );
276279
277280 assertEquals (Files .readAllBytes (mapWithoutHeader ), original );
278281 }
279282
283+ @ Test
284+ public void mapHeaderConfigPreservesExistingMapNameWhenOnlyPlayersChange () throws Exception {
285+ Path mapWithoutHeader = Files .createTempFile ("wurst-map-without-header-name" , ".w3x" );
286+ byte [] original = new byte [1024 ];
287+ original [0 ] = 'M' ;
288+ original [1 ] = 'P' ;
289+ original [2 ] = 'Q' ;
290+ original [3 ] = 0x1a ;
291+ Files .write (mapWithoutHeader , original );
292+
293+ Method applyMapHeader = ProjectConfigBuilder .class .getDeclaredMethod (
294+ "applyMapHeader" , WurstProjectConfigData .class , File .class , int .class , String .class
295+ );
296+ applyMapHeader .setAccessible (true );
297+
298+ applyMapHeader .invoke (
299+ null ,
300+ new WurstProjectConfigData (
301+ "Test" ,
302+ List .of (),
303+ new WurstProjectBuildMapData (
304+ "" , null , null , null , null ,
305+ List .of (new WurstProjectBuildPlayer (0 , null , null , null , null )),
306+ List .of ()
307+ ),
308+ null ,
309+ null
310+ ),
311+ mapWithoutHeader .toFile (),
312+ 4 ,
313+ "Existing map"
314+ );
315+
316+ byte [] result = Files .readAllBytes (mapWithoutHeader );
317+ assertEquals (MapHeader .ofFile (mapWithoutHeader .toFile ()).getMaxPlayersCount (), 1 );
318+ assertTrue (new String (result , StandardCharsets .UTF_8 ).contains ("Existing map" ));
319+ }
320+
280321 private static String calculateProjectConfigHash (File buildDir ) throws Exception {
281322 Method method = ProjectConfigBuilder .class .getDeclaredMethod (
282323 "calculateProjectConfigHash" ,
0 commit comments