Skip to content

Commit

Permalink
Update comments, add page numbers to page breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
waffle-stomper committed Feb 5, 2021
1 parent f135f41 commit 33d10b5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '2.1.4'
version = '2.1.5'
group = 'wafflestomper' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = '1.16.1-Ghostwriter'

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/wafflestomper/ghostwriter/BookUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.List;

public class BookUtilities {
public static final int BOOK_TEXT_WIDTH = 116;
public static final int BOOK_TEXT_WIDTH = 116; // TODO: I think the text width might be 114 pixels now
public static final char SPLIT_CHAR = '\u1337';
private static final Minecraft mc = Minecraft.getInstance();

Expand Down Expand Up @@ -335,10 +335,13 @@ public static List<String> splitStringIntoLines(String str){
return out;
}


/**
* Splits a monolithic string into a list of strings, each representing one
* book page.
* Splits a monolithic string into a list of strings, each representing one book page.
*
* Note that while the single player version will allow an almost unlimited number of characters
* on the same line, Spigot, (and likely the vanilla server) will only allow 256. This, combined with extra format
* characters being inserted was causing pages to be split in new and strange places
*/
public static List<String> stringToPages(String str){
String wrapped = wrapFormattedStringToWidth(str, BOOK_TEXT_WIDTH);
Expand Down Expand Up @@ -417,6 +420,7 @@ public static List<String> stringWithPageBreaksToPages(String str, String pageBr
/**
* Converts the new JSON strings with their escaped quotation marks back into regular old strings
* Hopefully this is just temporary.
* EditBookScreen seems to work with normal strings, but ReadBookScreen is converting the pages to JSON
*/
public static String deJSONify(String jsonIn){
try{
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/wafflestomper/ghostwriter/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ else if (line.toLowerCase().startsWith("author:") && book.author.isEmpty()){
}


// TODO: Add comments with page numbers
public boolean saveBookToGHBFile(String title, String author, List<String> pages, File savePath){
printer.gamePrint(Printer.GRAY + "Saving book to file...");
List<String> toWrite = new ArrayList<>();
Expand All @@ -363,18 +364,17 @@ public boolean saveBookToGHBFile(String title, String author, List<String> pages
while (pageAsString.startsWith("\"") && pageAsString.endsWith("\"")){
pageAsString = pageAsString.substring(1, pageAsString.length()-1);
}
// Strip
//convert all escaped newline characters to real newline characters
// Convert all escaped newline characters to real newline characters
pageAsString = pageAsString.replaceAll("\\\\n", "\\\n");
//Split the string into 116 pixel maximum lines
// Split the string into 116 pixel maximum lines
List<String> currPage = BookUtilities.splitStringIntoLines(pageAsString);
// Replace newline characters with double hashes and add the double hashes to the end of each line
for (String line : currPage){
toWrite.add(line.replaceAll("\\n", "##") + "##");
}
//Add pagebreaks
// Add pagebreaks with line numbers
if (i < pages.size()-1){
toWrite.add(">>>>");
toWrite.add(GHB_PAGE_BREAK + " // Page " + (i+2));
}
}
if (writeFile(toWrite, savePath)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public class GhostwriterEditBookScreen extends EditBookScreen {

private Clipboard clipboard;

private File autoReloadFile; // Auto Reload is active when this is not nullprivate Clipboard autoReloadBookClipboard;
private File autoReloadFile; // Auto Reload is active when this is not null
private long autoReloadLastModified = 0;
private long autoReloadLastCheck = 0;
private Clipboard autoReloadClipboard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import java.io.File;
import java.util.List;

// TODO: Focus on the filename field with the name (and not extension) highlighted to make saving with a custom name
// faster

public class GhostwriterFileBrowserScreen extends Screen{

private FileSelectionList fileSelectionList;
Expand Down
3 changes: 2 additions & 1 deletion update.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"homepage": "https://github.com/waffle-stomper/Ghostwriter/releases",
"promos":{
"1.16.1-recommended": "2.1.4",
"1.16.1-recommended": "2.1.5",
"1.15.2-recommended": "2.0.6",
"1.15.1-recommended": "2.0.5",
"1.14.4-recommended": "2.0.4",
Expand All @@ -13,6 +13,7 @@
"1.10-recommended": "1.8.5"
},
"1.16.1":{
"2.1.5": "Fix title bug when signing loaded book\nRemove redundant format chars when loading a book (thanks Maester Lodish)\nAdd page numbers to ghb files",
"2.1.4": "Fix crash when removing pages\nReported by Maester Lodish",
"2.1.3": "Code cleanup",
"2.1.2": "Convert all space indentation to tabs",
Expand Down

0 comments on commit 33d10b5

Please sign in to comment.