Refactoring and Bugfixes (#127)

* Replacing nil + compact! with delete, delete_at and delete_if wherever possible
* Fixed Terrain Tag editor not setting the correct terrain
* Fixed Text Cursor in Animation Editor not going right
This commit is contained in:
Golisopod-User
2021-08-23 02:55:29 +05:30
committed by GitHub
parent e57e1f4a1e
commit ecc5a040cd
21 changed files with 40 additions and 171 deletions

View File

@@ -247,40 +247,6 @@ def getFormattedTextFast(bitmap,xDst,yDst,widthDst,heightDst,text,lineheight,
end
position+=1
end
# This code looks at whether the text occupies exactly two lines when
# displayed. If it does, it balances the length of each line.
=begin
# Count total number of lines
numlines = (x==0 && y>0) ? y-1 : y
realtext = (newlineBreaks) ? text : text.gsub(/\n/," ")
if numlines==2 && !explicitBreaksOnly && !realtext[/\n/] && realtext.length>=50
# Set half to middle of text (known to contain no formatting)
half = realtext.length/2
leftSearch = 0
rightSearch = 0
# Search left for a space
i = half; while i>=0
break if realtext[i,1][/\s/]||isWaitChar(realtext[i]) # found a space
leftSearch += 1
i -= 1
end
# Search right for a space
i = half; while i<realtext.length
break if realtext[i,1][/\s/]||isWaitChar(realtext[i]) # found a space
rightSearch += 1
i += 1
end
# Move half left or right whichever is closer
trialHalf = half+((leftSearch<rightSearch) ? -leftSearch : rightSearch)
if trialHalf!=0 && trialHalf!=realtext.length
# Insert newline and re-call this function (force explicitBreaksOnly)
newText = realtext.clone
newText.insert(trialHalf,"\n")
return getFormattedTextFast(bitmap,xDst,yDst,
widthDst,heightDst,newText,lineheight,true,explicitBreaksOnly)
end
end
=end
# Eliminate spaces before newlines and pause character
if havenl
firstspace=-1
@@ -292,11 +258,9 @@ def getFormattedTextFast(bitmap,xDst,yDst,widthDst,heightDst,text,lineheight,
for j in firstspace...i
characters[j]=nil
end
firstspace=-1
firstspace = -1
elsif characters[i][0][/[ \r\t]/]
if firstspace<0
firstspace=i
end
firstspace = i if firstspace < 0
else
firstspace=-1
end
@@ -868,14 +832,7 @@ def getFormattedText(bitmap,xDst,yDst,widthDst,heightDst,text,lineheight=32,
end
end
# Remove all characters with Y greater or equal to _yDst_+_heightDst_
if heightDst>=0
for i in 0...characters.length
if characters[i][2]>=yDst+heightDst
characters[i]=nil
end
end
characters.compact!
end
characters.delete_if { |ch| ch[2] >= yDst + heightDst } if heightDst >= 0
bitmap.font=oldfont
dummybitmap.dispose if dummybitmap
return characters