mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
refactor wrap in dialogue.rb
This commit is contained in:
@@ -287,34 +287,17 @@ class Dialogue
|
|||||||
def wrap # TODO redo this
|
def wrap # TODO redo this
|
||||||
next if @type == :options
|
next if @type == :options
|
||||||
lines = []
|
lines = []
|
||||||
maximum_width = (@type == :text) ? MAXIMUM_LINE_WIDTH : MAXIMUM_MEDIA_LINE_WIDTH
|
|
||||||
maximum_lines = MAXIMUM_LINE_COUNT
|
maximum_lines = MAXIMUM_LINE_COUNT
|
||||||
|
|
||||||
text = @text.first
|
text = @text.first
|
||||||
segments = []
|
segments = segment_text(text)
|
||||||
index = 0; width = 0; space = 0
|
|
||||||
|
|
||||||
while index < text.length
|
|
||||||
char = text[index]
|
|
||||||
space = index if char == ' '
|
|
||||||
width += get_width(char)
|
|
||||||
index += 1
|
|
||||||
|
|
||||||
if (width >= maximum_width)
|
|
||||||
segments << text[0..space]
|
|
||||||
text = text[(space + 1)..-1]
|
|
||||||
width = index = space = 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
segments << text
|
|
||||||
|
|
||||||
if (segments.size <= maximum_lines)
|
if (segments.size <= maximum_lines)
|
||||||
lines.concat(segments)
|
lines = segments.clone
|
||||||
@text = @text[1..-1]
|
@text = @text[1..-1]
|
||||||
insert_copy(@text) if @text.size > 0
|
insert_copy(@text) if @text.size > 0
|
||||||
else
|
else
|
||||||
lines.concat(segments.first(maximum_lines))
|
lines = segments.first(maximum_lines).clone
|
||||||
segments = [ segments.drop(maximum_lines).join() ]
|
segments = [ segments.drop(maximum_lines).join() ]
|
||||||
insert_copy(segments << @text[1..-1].join())
|
insert_copy(segments << @text[1..-1].join())
|
||||||
end
|
end
|
||||||
@@ -337,6 +320,29 @@ class Dialogue
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def segment_text(text)
|
||||||
|
maximum_width = (@type == :text) ? MAXIMUM_LINE_WIDTH : MAXIMUM_MEDIA_LINE_WIDTH
|
||||||
|
|
||||||
|
segments = []
|
||||||
|
index = 0; width = 0; space = 0
|
||||||
|
|
||||||
|
while index < text.length
|
||||||
|
char = text[index]
|
||||||
|
space = index if char == ' '
|
||||||
|
width += get_width(char)
|
||||||
|
index += 1
|
||||||
|
|
||||||
|
if (width >= maximum_width)
|
||||||
|
segments << text[0..space]
|
||||||
|
text = text[(space + 1)..-1]
|
||||||
|
width = index = space = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
segments << text if ! text.empty?
|
||||||
|
|
||||||
|
segments
|
||||||
|
end
|
||||||
|
|
||||||
# Inserts a copy of this Dialogue into the chain, but with different text.
|
# Inserts a copy of this Dialogue into the chain, but with different text.
|
||||||
def insert_copy(text)
|
def insert_copy(text)
|
||||||
name = @name
|
name = @name
|
||||||
|
|||||||
Reference in New Issue
Block a user