use luxe str function and small progress

This commit is contained in:
Ronja 2020-11-01 16:45:30 +01:00
parent 0f984696c7
commit 85b3f6315b
2 changed files with 12 additions and 22 deletions

View file

@ -52,18 +52,16 @@ class Game is Ready {
ui_mouse = Camera.screen_point_to_world(app.ui_camera, ui_mouse.x, ui_mouse.y)
Globals["UiMouse"] = ui_mouse
if(Input.key_state_released(Key.escape)) {
IO.shutdown()
}
if(Input.key_state_pressed(Key.key_q)) {
_tooltip.cycle_size()
}
DrawDebug.commit()
_tooltip.tick()
_adventures.tick()
app.tick(delta)
if(Input.key_state_released(Key.escape)) {
IO.shutdown()
}
} //tick
destroy() {

View file

@ -1,5 +1,4 @@
//a lot of this is bad and can only handle ASCII
//too bad ¯\_(ツ)_/¯
import "luxe: string" for Str
class StringUtil{
static directions{
@ -59,28 +58,20 @@ class StringUtil{
//checks if a character (as codepoint is lowercase)
static is_lower(char){
return char >= 97 && char <= 122
return Str.compare(Str.upper(char), char) != 0
}
//checks if a character (as codepoint is uppercase)
static is_upper(char){
return char >= 65 && char <= 90
return Str.compare(Str.lower(char), char) != 0
}
static is_letter(char){
return is_lower(char) || is_upper(char)
}
static to_upper(string){
return string.codePoints.map{|c|is_lower(c)?c-32:c}.map{|c|String.fromCodePoint(c)}.join()
}
static to_lower(string){
return string.codePoints.map{|c|is_upper(c)?c+32:c}.map{|c|String.fromCodePoint(c)}.join()
}
static capitalize(string){
return to_upper(string[0]) + string[1..-1]
return Str.upper(string[0]) + string[1..-1]
}
//todo: this ignores words that arent preceeded by a space like (this) or "this". maybe fix that?
@ -107,10 +98,11 @@ class WordSequence is Sequence{
if(!iterator) iterator = [-1, -1, false] //fake value from -1 to -1
if(iterator[1] >= _string.count-1) return false //abort when at end
var start = iterator[1]+1
var is_word = StringUtil.is_letter(_string.codePointAt_(start))
System.print(_string.codePointAt_(start))
var is_word = StringUtil.is_letter(_string[start])
var end = start + 1
//count up until you find something thats not a word/separator depending on what the first letter was
while(end < _string.count && StringUtil.is_letter(_string.codePointAt_(end)) == is_word){
while(end < _string.count && StringUtil.is_letter(_string[end]) == is_word){
end = end + 1
}
end = end - 1