-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PlaybackSerialiser] Added basic layout
- Loading branch information
1 parent
ceb078e
commit e8d8d5c
Showing
4 changed files
with
116 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
src/main/java/com/minecrafttas/tasmod/playback/tasfile/PlaybackSerialiserBase.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
src/main/java/com/minecrafttas/tasmod/playback/tasfile/PlaybackSerialiserFlavorBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.minecrafttas.tasmod.playback.tasfile; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.dselent.bigarraylist.BigArrayList; | ||
import com.minecrafttas.tasmod.playback.PlaybackControllerClient; | ||
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TickInputContainer; | ||
|
||
public abstract class PlaybackSerialiserFlavorBase { | ||
|
||
|
||
public abstract String flavorName(); | ||
|
||
public void serialise(PlaybackControllerClient controller, File file) { | ||
|
||
} | ||
|
||
public BigArrayList<String> serialise(BigArrayList<TickInputContainer> container) { | ||
BigArrayList<String> out = new BigArrayList<>(); | ||
return out; | ||
} | ||
|
||
public BigArrayList<TickInputContainer> deserialise(BigArrayList<String> lines) { | ||
BigArrayList<TickInputContainer> out = new BigArrayList<>(); | ||
return out; | ||
} | ||
|
||
public List<String> serialiseMetadata(){ | ||
return null; | ||
} | ||
|
||
public void deserialiseMetadata(List<String> metadataString) { | ||
|
||
} | ||
|
||
public static String createCenteredHeading(String text, char spacingChar, int headingWidth) { | ||
|
||
if(text == null || text.isEmpty()) { | ||
return createPaddedString(spacingChar, headingWidth); | ||
} | ||
|
||
text = " "+text+" "; | ||
|
||
int spacingWidth = headingWidth - text.length(); | ||
|
||
String paddingPre = createPaddedString(spacingChar, spacingWidth % 2 == 1 ? spacingWidth / 2 + 1 : spacingWidth / 2); | ||
String paddingSuf = createPaddedString(spacingChar, spacingWidth/2); | ||
|
||
return String.format("%s%s%s", paddingPre, text, paddingSuf); | ||
} | ||
|
||
private static String createPaddedString(char spacingChar, int width) { | ||
char[] spacingLine = new char[width]; | ||
for (int i = 0; i < spacingLine.length; i++) { | ||
spacingLine[i] = spacingChar; | ||
} | ||
return new String(spacingLine); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/tasmod/playback/tasfile/PlaybackSerializerBaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package tasmod.playback.tasfile; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.minecrafttas.tasmod.playback.tasfile.PlaybackSerialiserFlavorBase; | ||
|
||
public class PlaybackSerializerBaseTest { | ||
|
||
@Test | ||
void testStringPaddingEven() { | ||
String actual = PlaybackSerialiserFlavorBase.createCenteredHeading(null, '#', 52); | ||
String expected = "####################################################"; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void testStringPaddingOdd() { | ||
String actual = PlaybackSerialiserFlavorBase.createCenteredHeading(null, '#', 51); | ||
String expected = "###################################################"; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void testCenterHeadingEven() { | ||
String actual = PlaybackSerialiserFlavorBase.createCenteredHeading("TASfile", '#', 52); | ||
String expected = "###################### TASfile #####################"; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void testCenterHeadingOdd() { | ||
String actual = PlaybackSerialiserFlavorBase.createCenteredHeading("TASfile", '#', 51); | ||
String expected = "##################### TASfile #####################"; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void testCenterHeadingEvenText() { | ||
String actual = PlaybackSerialiserFlavorBase.createCenteredHeading("TASfiles", '#', 51); | ||
String expected = "##################### TASfiles ####################"; | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void testCenterHeadingEvenText2() { | ||
String actual = PlaybackSerialiserFlavorBase.createCenteredHeading("Keystrokes", '#', 51); | ||
String expected = "#################### Keystrokes ###################"; | ||
assertEquals(expected, actual); | ||
} | ||
} |