Date: 2017/03/03 22:32:03 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#--------------------------------------
#
# Color Enabled Line Wrap Utility
#
# Turn a long string into a list of smaller strings and respects color codes
#
# Usage: <procedure[script:LineWrap_colored|string:string|length:10].return>
# Example: <procedure[script:LineWrap_colored|string:Hi <&[a]>i <&[b]>am a long <&[c]>string m8|length:10].return>
LineWrap_colored:
type: procedure
debug: minimal
script:
- define string '<context.string>'
- define targetLen <context.length>
- define line ''
- define return <list[]>
- define index 0
- while <def[string].length.is_greater_than[0]>:
- define index <def[index].add[1]>
- define split '<def[string].index_of_cased[ ]>'
- if <def[split]> == 0:
- if <def[targetLen]> > <def[string].length>:
- define split <def[string].length>
- else:
- define split <def[targetLen]>
- define word '<def[string].substring[1|<def[split]>]>'
- if <texts.for_old_colors[<def[line]><def[word]>].plain.length> <= <def[targetLen]>:
- addto line parsed '<def[word]>'
- define string '<def[string].after[<def[word]>]>'
- else:
- addto return list '<def[line]>'
- define line ''
- if <def[index]> == 50:
- while stop
- addto return list '<def[line]>'
- echo <def[index]>
- determine return <def[return]>
#
# END Color Enabled Line Wrap Utility
#--------------------------------------
#
# Line Wrap Utility
#
# Turn a long string into a list of smaller strings
#
# Usage: <procedure[script:LineWrap|string:string|length:10].return>
# Example: <procedure[script:LineWrap|string:Hi i am a long string m8|length:10].return>
LineWrap:
type: procedure
speed: 0
debug: minimal
script:
- define string '<context.string>'
- define stringLen <context.string.length>
- define targetLen <context.length>
- define increment 0
- if <def[stringLen]> > <def[targetLen]>:
- define lines '<list[]>'
- while <def[stringLen].is_greater_than[0]>:
- define low '<def[increment].add[1]>'
- define hi '<def[increment].add[<def[targetLen]>]>'
- define pass '<def[string].substring[<def[low]>|<def[hi]>]>'
- if <def[pass].length> == <def[stringLen]>:
- addto lines list '<def[pass]>'
- while stop
- else:
- define brake '<def[pass].last_index_of_cased[ ]>'
- define increment '<def[increment].add[<def[brake]>]>'
- if <def[brake]> > 0:
- define passtrim '<def[brake]>'
- else:
- define passtrim '<def[pass].length>'
- define passtrim '<def[pass].substring[1|<def[passtrim]>]>'
- addto lines list '<def[passtrim]>'
- define stringLen '<def[stringLen].subtract[<def[brake]>]>'
- determine return '<def[lines]>'
- else:
- determine return '<def[string]>'
#
# END Line Wrap Utility
#--------------------------------------