Date: 2024/12/26 03:10:13 UTC-08:00
Type: Denizen Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
split_by_pages_output:
type: task
debug: false
script:
- define book "<&8>I am trying to write a method that will automatically wrap text from one page onto the next without any problems. Book pages used to be capped at 256 characters each, but since some characters are smaller than others they changed it to use character width instead. I'm trying to use this to wrap my text from page 1 to page 2 to page 3 etc. perfectly without cutting off words or anything like that."
- adjust <player> show_book:split_by_pages_book[book_pages=<[book].proc[split_by_pages]>]
- playsound <player> sound:ITEM_BOOK_PAGE_TURN pitch:1
split_by_pages:
type: procedure
debug: false
definitions: book
script:
- define wordbyword <list>
- define pages <list>
- define splitted <[book].trim.split[ ]>
- define rows <list>
- foreach <[splitted]> as:word:
- if <[wordbyword].length> > 0 && <element[<[wordbyword].space_separated> <[word]>].text_width> > 114:
- define row:->:<&8><[wordbyword].space_separated>
- define wordbyword <empty>
- define wordbyword:->:<[word]>
- define rows:->:<[row]>
- else:
- define wordbyword:->:<[word]>
- define row:->:<[wordbyword].space_separated>
- define lines 0
- define page <empty>
- foreach <[row]> as:line:
- define page "<[page]><[line]> "
- define lines:++
- if <[lines]> == 14:
- define page <[page]>
- define lines 1
- define pages:->:<[page]>
- define page <empty>
- define pages:->:<&8><[page]>
- determine <[pages]>
split_by_pages_book:
type: book
title: test
author: test
signed: true
text:
- <empty>