mirror of
https://github.com/minetest-mods/digilines.git
synced 2024-09-27 22:30:22 +02:00
fix generalization for arbitrary number of lines, line lengths etc.
This commit is contained in:
parent
473b9088d8
commit
358644708e
9
lcd.lua
9
lcd.lua
|
@ -5,7 +5,6 @@
|
||||||
-- load characters map
|
-- load characters map
|
||||||
local chars_file = io.open(minetest.get_modpath("digilines").."/characters", "r")
|
local chars_file = io.open(minetest.get_modpath("digilines").."/characters", "r")
|
||||||
local charmap = {}
|
local charmap = {}
|
||||||
local max_chars = 12
|
|
||||||
if not chars_file then
|
if not chars_file then
|
||||||
print("[digilines] E: LCD: character map file not found")
|
print("[digilines] E: LCD: character map file not found")
|
||||||
else
|
else
|
||||||
|
@ -31,8 +30,8 @@ local LINE_HEIGHT = 14
|
||||||
local CHAR_WIDTH = 5
|
local CHAR_WIDTH = 5
|
||||||
|
|
||||||
|
|
||||||
assert(CHAR_WIDTH * LINE_LENGTH <= LCD_WIDTH - LCD_PADDING*2, "LCD: Lines set too long!")
|
assert((CHAR_WIDTH+1) * LINE_LENGTH <= LCD_WIDTH - LCD_PADDING*2, "LCD: Lines set too long!")
|
||||||
assert(LINE_HEIGHT * NUMBER_OF_LINES <= LCD_WIDTH - LCD_PADDING*2, "LCD: Too many lines!")
|
assert((LINE_HEIGHT+1) * NUMBER_OF_LINES <= LCD_WIDTH - LCD_PADDING*2, "LCD: Too many lines!")
|
||||||
|
|
||||||
|
|
||||||
local split = function(s, pat)
|
local split = function(s, pat)
|
||||||
|
@ -128,7 +127,7 @@ local generate_line = function(s, ypos)
|
||||||
local parsed = {}
|
local parsed = {}
|
||||||
local width = 0
|
local width = 0
|
||||||
local chars = 0
|
local chars = 0
|
||||||
while chars < max_chars and i <= #s do
|
while chars < LINE_LENGTH and i <= #s do
|
||||||
local file = nil
|
local file = nil
|
||||||
if charmap[s:sub(i, i)] ~= nil then
|
if charmap[s:sub(i, i)] ~= nil then
|
||||||
file = charmap[s:sub(i, i)]
|
file = charmap[s:sub(i, i)]
|
||||||
|
@ -162,7 +161,7 @@ end
|
||||||
|
|
||||||
local generate_texture = function(lines)
|
local generate_texture = function(lines)
|
||||||
local texture = "[combine:"..LCD_WIDTH.."x"..LCD_WIDTH
|
local texture = "[combine:"..LCD_WIDTH.."x"..LCD_WIDTH
|
||||||
local ypos = 16
|
local ypos = math.floor((LCD_WIDTH - LINE_HEIGHT*NUMBER_OF_LINES) / 2)
|
||||||
for i = 1, #lines do
|
for i = 1, #lines do
|
||||||
texture = texture..generate_line(lines[i], ypos)
|
texture = texture..generate_line(lines[i], ypos)
|
||||||
ypos = ypos + LINE_HEIGHT
|
ypos = ypos + LINE_HEIGHT
|
||||||
|
|
Loading…
Reference in New Issue
Block a user