From 763a1a26b5d44f9dc0c6aa3788e690bdf612a458 Mon Sep 17 00:00:00 2001 From: chrys Date: Thu, 20 Oct 2016 21:10:39 +0200 Subject: [PATCH] clean up broken word wrap, add , endOfScreen return value --- src/fenrir/utils/char_utils.py | 36 ++++++++++++++++++++++------------ src/fenrir/utils/line_utils.py | 19 ++++++++++++------ 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/fenrir/utils/char_utils.py b/src/fenrir/utils/char_utils.py index 8ff8f0d4..53338385 100644 --- a/src/fenrir/utils/char_utils.py +++ b/src/fenrir/utils/char_utils.py @@ -7,8 +7,9 @@ from core import debug def getPrevChar(currX,currY, currText): + endOfScreen = False if currText == '': - return -1, -1, '' + return -1, -1, '', endOfScreen wrappedLines = currText.split('\n') x = currX y = currY @@ -16,51 +17,60 @@ def getPrevChar(currX,currY, currText): if y - 1 > 0: y -= 1 x = len(wrappedLines[y]) - 1 + else: + endOfScreen = True else: x -= 1 currChar = wrappedLines[y][x] - return x, y, currChar + return x, y, currChar, endOfScreen def getCurrentChar(currX,currY, currText): + endOfScreen = False if currText == '': return -1, -1, '' wrappedLines = currText.split('\n') currChar = wrappedLines[currY][currX] - return currX, currY, currChar + return currX, currY, currChar, endOfScreen def getUpChar(currX,currY, currText): + endOfScreen = False if currText == '': - return -1, -1, '' + return -1, -1, '', endOfScreen wrappedLines = currText.split('\n') currY -= 1 if currY < 0: currY = 0 currChar = wrappedLines[currY][currX] - return currX, currY, currChar + return currX, currY, currChar, endOfScreen def getDownChar(currX,currY, currText): + endOfScreen = False if currText == '': - return -1, -1, '' + return -1, -1, '', endOfScreen wrappedLines = currText.split('\n') currY += 1 if currY >= len(wrappedLines): - currY = len(wrappedLines) -1 + currY = len(wrappedLines) -1 + else: + endOfScreen = True currChar = wrappedLines[currY][currX] - return currX, currY, currChar + return currX, currY, currChar, endOfScreen def getLastCharInLine(currY, currText): + endOfScreen = False if currText == '': - return -1, -1, '' + return -1, -1, '', endOfScreen wrappedLines = currText.split('\n') currX = len(wrappedLines[currY].rstrip())-1 if currX < 0: currX = 0 currChar = wrappedLines[currY][currX] - return currX, currY, currChar + return currX, currY, currChar, endOfScreen def getNextChar(currX,currY, currText): + endOfScreen = False if currText == '': - return -1, -1, '' + return -1, -1, '', endOfScreen wrappedLines = currText.split('\n') x = currX y = currY @@ -68,10 +78,12 @@ def getNextChar(currX,currY, currText): if y + 1 < len(wrappedLines) - 1: y += 1 x = 0 + else: + endOfScreen = True else: x += 1 currChar = wrappedLines[y][x] - return x, y, currChar + return x, y, currChar, endOfScreen def getPhonetic(currChar): if len(currChar) != 1: diff --git a/src/fenrir/utils/line_utils.py b/src/fenrir/utils/line_utils.py index 2de24fad..10ded91c 100644 --- a/src/fenrir/utils/line_utils.py +++ b/src/fenrir/utils/line_utils.py @@ -7,35 +7,42 @@ from core import debug def getPrevLine(currX,currY, currText): + endOfScreen = False if currText == '': - return -1, -1, '' + return -1, -1, '', endOfScreen wrappedLines = currText.split('\n') x = currX y = currY if y - 1 >= 0: y -= 1 + else: + endOfScreen = True x = 0 currLine = wrappedLines[y] - return x, y, currLine + return x, y, currLine, endOfScreen def getCurrentLine(currX,currY, currText): + endOfScreen = False if currText == '': - return -1, -1, '' + return -1, -1, '', endOfScreen wrappedLines = currText.split('\n') x = currX y = currY x = 0 currLine = wrappedLines[y] - return x, y, currLine + return x, y, currLine, endOfScreen def getNextLine(currX,currY, currText): + endOfScreen = False if currText == '': - return -1, -1, '' + return -1, -1, '', endOfScreen wrappedLines = currText.split('\n') x = currX y = currY if y + 1 < len(wrappedLines): y += 1 + else: + endOfScreen = True x = 0 currLine = wrappedLines[y] - return x, y, currLine + return x, y, currLine, endOfScreen