local deck_name = "russian" local deck = {} local card_file = rb.current_path() .. deck_name .. ".txt" local action = "" local null, font_w, font_h = rb.font_getstringsize("a", rb.FONT_UI) local char_w = rb.LCD_WIDTH / font_w function print_card(card_no, total_cards, top, bottom) rb.lcd_clear_display() rb.lcd_puts(22, 0, card_no .. "/" .. total_cards) local foo, top_w, top_h = rb.font_getstringsize(top, rb.FONT_UI) local top_len = rb.utf8length(top) if (top_w >= rb.LCD_WIDTH ) then rb.lcd_puts_scroll(0, 1, top) else rb.lcd_puts(((char_w - top_len) / 2 ) + 1, 1, top) end rb.lcd_update() press() local foo, bottom_w, bottom_h = rb.font_getstringsize(bottom, rb.FONT_UI) local bottom_len = rb.utf8length(bottom) if (bottom_w >= rb.LCD_WIDTH ) then rb.lcd_puts_scroll(0, 3, bottom) else rb.lcd_puts(((char_w - bottom_len) / 2 ) + 1, 3, bottom) end rb.lcd_update() press() end function load_deck() local card_no = 1 for line in io.lines(card_file) do deck[card_no] = {} deck[card_no][1], deck[card_no][2] = parse_line(line) card_no = card_no + 1 end end function parse_line(line) index = string.find(line, " ") + 1 top = string.match(line, "(.+)%[") sound = string.match(line, "%[(.+)%]") bottom = string.match(line, "(.+)", index) return top, bottom, sound end function print_deck_in_order() for i = 1,#deck do if action == "back" then i = i - 2 end print_card(i, #deck, deck[i][1], deck[i][2]) end end function print_deck_at_random() for i = 1,#deck do rand = (rb.rand() * #deck) / 2147483647 print_card(rand, #deck, deck[rand][1], deck[rand][2]) end end function press() rb.button_clear_queue() rb.button_get(1) rb.lcd_update() while rb.button_status(0) > 0 do if rb.button_status(0) > 255 then os.exit() elseif rb.button_status(0) == 32 then action = "back" else action = "" end rb.sleep(rb.HZ/60) end end load_deck() print_deck_in_order()