Skip to content

Revise book data writing function #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Niels-NTG
Copy link
Contributor

Complete revision of the function that generates book data for Minecraft's written books. The previous implementation didn't break the pages as expected, resulting in pages with needless empty lines at the end of the page. It also couldn't deal that well with certain escape characters. This revised function deals with these shortcomings, inspired by the algorithm used by this Kotlin project: https://github.com/NightlyNexus/Gutencraft/blob/master/gutencraft/src/commonMain/kotlin/Gutencraft.kt

To test, create a Python file containing the following:

from pyglm.glm import ivec3

from gdpc import Editor
from gdpc.editor_tools import placeLectern
from gdpc.minecraft_tools import bookData

editor = Editor(buffering=True)

data = bookData(text="""some very long text with linebreaks and some Minecraft text markup tokens (§)""", author="Me")

placeLectern(editor, position=ivec3(4, -60, 27), bookData=data)

Copy link
Owner

@avdstaaij avdstaaij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

I didn't look at the algorithm itself, if it can generate a simple book, I'll trust it's correct. But I did leave a few comments.

How close is this code to the linked projects? Should we include their licenses?

It might be better to move the character width dict into a separate (private) file, but that can be done later.

Comment on lines -214 to -216
- ``\\\\s``: When at start of page, print page as string directly
- ``\\c``: When at start of line, align text to center
- ``\\r``: When at start of line, align text to right side
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why these are no longer supported? Removing support for them is a breaking change. In this case I'm willing to turn a blind eye to that, but it would be better if we could keep them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware of this. I couldn't quite figure out how to re-implement these. But I wouldn't say it's impossible. I will take another look at it.

@Niels-NTG
Copy link
Contributor Author

How close is this code to the linked projects? Should we include their licenses?

The character list is pretty much verbatim, the only difference being that I reformatted from JSON into a Python dict. I shall a comment that mentions their MIR license.

Gutencraft, the code on which the book writing algorithm is based, doesn't have a license at the moment. When I started this project I made an incorrect assumption that no license meant it's free for the taking, but in actuality this means legally can only view and fork the code. So I've filed an issue which will need to be resolved before this can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants