-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworldbreak2.lua
More file actions
22 lines (21 loc) · 762 Bytes
/
Copy pathworldbreak2.lua
File metadata and controls
22 lines (21 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function worldBreak(text, w, fontScale, font)
local lastEnd, lastStart = 0, 0
local currentEnd, currentStart
local str = ""
local currentWorld
local sepFromLastWorld
while true do
currentStart, currentEnd = string.find(text, "%w+", lastEnd+1)
if not (currentStart) then break end
sepFromLastWorld = string.sub(text, lastEnd+1, currentStart-1)
currentWorld = string.sub(text, currentStart, currentEnd)
if (dxGetTextWidth(str, fontScale, font)<w) then
str = str..sepFromLastWorld..currentWorld
else
str = str.."\n"..currentWorld
print("Break at", currentStart)
end
lastEnd, lastStart = currentEnd, currentStart
end
return str
end