TheWilley / Text2Book

A web app to convert text to Minecraft books
https://thewilley.github.io/Text2Book/
MIT License
8 stars 1 forks source link

Doesn't seem to always account for line break spacing #4

Closed Traehgniw closed 9 months ago

Traehgniw commented 10 months ago

Sorry about this but it seems like it doesn't always take into account the space taken up by a line break when splitting books up. In the most recent lore book I made it put in one line's worth more text than actually fit in a page that had a line break in the middle.

TheWilley commented 10 months ago

You're right, good catch! I managed to reproduce the bug too trough this text:

Hey there! How's it going? I hope you're having a fantastic day. Just wanted to touch base and see what's up. I recently discovered this amazing coffee shop downtown. 

The atmosphere is so cozy, and they serve the best cappuccino I've ever had. It's become my new go-to spot for some quiet time.

Which incorrectly produces:

Hey there! How's it
going? I hope you're
having a fantastic
day. Just wanted to
touch base and see
what's up. I recently
discovered this
amazing coffee shop
downtown.

The atmosphere is so
cozy, and they serve
the best cappuccino
I've ever had. It's

spot for some quiet
time.

I'm gonna take a look to see what the issue might be.

TheWilley commented 10 months ago

The issue has been found, it has to do with a regex which doesn't account for new lines with a space before them. Should be fixed by 488792cdfcb37fcf4f16ddcdfb52b254bf8e6a74.

Can you test again and confirm if the fix worked?

Traehgniw commented 10 months ago

Doesn't seem to be working with a text that starts with a square bracket

TheWilley commented 10 months ago

I can't find any issues with square brackets, can you show some text which reproduces the error? What exactly does not work? Is text cut off?

Traehgniw commented 10 months ago

I was writing lorebooks for an SMP with some roleplay with your online tool and noticed one was failing to paste, which means it doesn't fit

Text that does this for me, snipped to just the first 3 pages, second page fails to paste, removing the space after 'accident' makes it paste but since it's working for you with spaces preceding line breaks I'm assuming something else in this block of text is breaking it:

[Wingyl's diary. The first third of the book has daily entries and is mostly focused on describing plans. Plans to try to replant bare land, plans to modify a complex and rather janky botanical magitech setup to produce different kinds of spawn eggs, plans to use other complex magitech to alter a cursed biome to something more pleasant, and page after page of plans to deliberately create a teleporter accident.

There is an abrupt change in the type of ink used at the one-third mark, and the first entry in the new ink is about receiving a tour from a dryad Wingyl had immediately decided was a friend. Later diary entries are more sporadic, skipping days or weeks, and focus much more on what happened since the last entry rather than on future plans.

Some entries are very

TheWilley commented 10 months ago

Yep, managed to reproduce this one too, very strange behavior. It works fine however when generating commands but not when copying and pasting. In fact, I've just noticed that I've only applied these fixes to the command generation, not the text generation.

Thanks for the heads up! I will get onto this ASAP. Sorry for any inconvenience!

Traehgniw commented 10 months ago

It's fine! I can just check for any trailing spaces before linebreaks if pasting fails

you have made a very good tool I have recommended it to the other people on the server for their lorebooks (though i dont think anyone else is uh. decorating with chiselled bookshelves and then trying to fill them All)

TheWilley commented 10 months ago

I have discovered the cause of the bug, and it's an edge case. Basically, if you have text which exactly fills out one row, and you add a empty space after, it will wrap to a new row. This issue can be easily demonstrated by entering the same line 10 time, all of which have a space after:

a teleporter accident. 
a teleporter accident. 
a teleporter accident. 
a teleporter accident. 
a teleporter accident. 
a teleporter accident. 
a teleporter accident. 
a teleporter accident. 
a teleporter accident. 
a teleporter accident. 

The tool will assume all of them can fit in one page, since it does not account for the line breaks. If you attempt to paste the tool output into a Minecraft book, it would look something like this:

a teleporter accident. 

a teleporter accident. 

a teleporter accident. 

a teleporter accident. 

a teleporter accident. 

a teleporter accident. 

a teleporter accident. 

a teleporter accident. 

a teleporter accident. 

a teleporter accident. 

This would of course fail to paste, since we are well beyond the cap of 14 rows per page. I will try to figure out a fix for this, which I don't think should be too hard, as all we need to do is check for spaces after strings of specific widths. Thanks again for the bug report!

TheWilley commented 10 months ago

Another fix has been deployed by c410f1e. I'm keeping this issue open for now as I want to do some further testing to see if it really is fixed now.

TheWilley commented 9 months ago

I've developed a testing methodology to check if the app output matches the generated Minecraft book. Assuming the test itself is not flawed, I'm pretty sure the app should handle line breaks correctly, as I generated 96 pages all of which matched the Minecraft book. There may be other edge cases still unresolved, but the issue regarding line breaks is resolved.