mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-20 02:59:20 +01:00
Reduced memory usage of BigLetter library
This commit is contained in:
parent
0eb990a87f
commit
0e3acc1e95
@ -1,27 +1,36 @@
|
||||
{
|
||||
label = "Beer",
|
||||
tooltip = "Cold wheat beer... mmmmm",
|
||||
label = "Companion Cube",
|
||||
shapes = {
|
||||
{ 0, 0, 2, 7, 1, 5, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 1, 0, 1, 6, 1, 6, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 2, 0, 0, 5, 1, 7, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 0, 1, 2, 1, 7, 5, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 1, 1, 1, 2, 7, 2, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 1, 1, 5, 2, 7, 6, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 2, 1, 0, 5, 7, 1, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 2, 1, 6, 5, 7, 7, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 5, 1, 1, 6, 7, 2, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 5, 1, 5, 6, 7, 6, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 6, 1, 2, 7, 7, 5, texture = "minecraft:blocks/log_spruce" },
|
||||
{ 7, 1, 3, 9, 2, 4, texture = "minecraft:blocks/stone" },
|
||||
{ 5, 2, 0, 6, 8, 1, texture = "minecraft:blocks/snow", tint = 16771749 },
|
||||
{ 6, 2, 1, 7, 8, 2, texture = "minecraft:blocks/snow", tint = 16771749 },
|
||||
{ 8, 2, 3, 9, 6, 4, texture = "minecraft:blocks/stone" },
|
||||
{ 7, 5, 3, 9, 6, 4, texture = "minecraft:blocks/stone" },
|
||||
{ 1, 6, 2, 6, 7, 5, texture = "minecraft:blocks/snow", tint = 16771749 },
|
||||
{ 2, 6, 1, 5, 8, 5, texture = "minecraft:blocks/snow", tint = 16771749 },
|
||||
{ 2, 6, 5, 5, 7, 6, texture = "minecraft:blocks/snow", tint = 16771749 },
|
||||
{ 3, 7, 0, 6, 8, 5, texture = "minecraft:blocks/snow", tint = 16771749 },
|
||||
{ 3, 8, 1, 6, 9, 4, texture = "minecraft:blocks/snow", tint = 16771749 }
|
||||
-- Center
|
||||
{2, 2,2, 14, 14, 14, texture = "wool_colored_gray"},
|
||||
|
||||
-- Corners
|
||||
{ 0, 0, 0, 5, 5, 5, texture = "wool_colored_silver"},
|
||||
{ 0, 0, 11, 5, 5, 16, texture = "wool_colored_silver"},
|
||||
{ 0, 11, 0, 5, 16, 5, texture = "wool_colored_silver"},
|
||||
{ 0, 11, 11, 5, 16, 16, texture = "wool_colored_silver"},
|
||||
{ 11, 0, 0, 16, 5, 5, texture = "wool_colored_silver"},
|
||||
{ 11, 0, 11, 16, 5, 16, texture = "wool_colored_silver"},
|
||||
{ 11, 11, 0, 16, 16, 5, texture = "wool_colored_silver"},
|
||||
{ 11, 11, 11, 16, 16, 16, texture = "wool_colored_silver"},
|
||||
|
||||
-- Edges
|
||||
{ 1, 6, 1, 3, 10, 3, texture = "wool_colored_silver"},
|
||||
{ 1, 6, 13, 3, 10, 15, texture = "wool_colored_silver"},
|
||||
{ 13, 6, 1, 15, 10, 3, texture = "wool_colored_silver"},
|
||||
{ 13, 6, 13, 15, 10, 15, texture = "wool_colored_silver"},
|
||||
{ 6, 1, 1, 10, 3, 3, texture = "wool_colored_silver"},
|
||||
{ 6, 1, 13, 10, 3, 15, texture = "wool_colored_silver"},
|
||||
{ 6, 13, 1, 10, 15, 3, texture = "wool_colored_silver"},
|
||||
{ 6, 13, 13, 10, 15, 15, texture = "wool_colored_silver"},
|
||||
{ 1, 1, 6, 3, 3, 10, texture = "wool_colored_silver"},
|
||||
{ 13, 1, 6, 15, 3, 10, texture = "wool_colored_silver"},
|
||||
{ 1, 13, 6, 3, 15, 10, texture = "wool_colored_silver"},
|
||||
{ 13, 13, 6, 15, 15, 10, texture = "wool_colored_silver"},
|
||||
|
||||
-- Centers
|
||||
{ 1, 6, 6, 15, 10, 10, texture = "wool_colored_magenta"},
|
||||
{ 6, 6, 1, 10, 10, 15, texture = "wool_colored_magenta"},
|
||||
{ 6, 1, 6, 10, 15, 10, texture = "wool_colored_magenta"}
|
||||
}
|
||||
}
|
||||
@ -7,7 +7,8 @@ local lettersInterval = 2
|
||||
local unknownSymbol = "*"
|
||||
local spaceWidth = 2
|
||||
|
||||
local letters = {
|
||||
local function getCharTable(c)
|
||||
return ({
|
||||
["0"] = {
|
||||
{ 1, 1, 1 },
|
||||
{ 1, 0, 1 },
|
||||
@ -544,52 +545,58 @@ local letters = {
|
||||
{ 0, 0, 0, 0, 0 },
|
||||
{ 1, 0, 1, 0, 1 },
|
||||
},
|
||||
}
|
||||
})[c]
|
||||
end
|
||||
|
||||
function bigLetters.draw(x, y, color, symbol, drawWithSymbol)
|
||||
local char
|
||||
|
||||
if symbol == " " then
|
||||
return spaceWidth
|
||||
elseif not letters[symbol] then
|
||||
symbol = unknownSymbol
|
||||
end
|
||||
|
||||
for j = 1, #letters[symbol] do
|
||||
for i = 1, #letters[symbol][j] do
|
||||
if letters[symbol][j][i] == 1 then
|
||||
if not drawWithSymbol then
|
||||
screen.drawRectangle(x + i * 2 - 2, y + (pixelHeight - #letters[symbol]) + j - 1, 2, 1, color, 0xFFFFFF, " ")
|
||||
else
|
||||
screen.drawText(x + i * 2 - 2, y + (pixelHeight - #letters[symbol]) + j - 1, color, "*")
|
||||
char = getCharTable(symbol) or getCharTable(unknownSymbol)
|
||||
end
|
||||
|
||||
for j = 1, #char do
|
||||
for i = 1, #char[j] do
|
||||
if char[j][i] == 1 then
|
||||
if not drawWithSymbol then
|
||||
screen.drawRectangle(x + i * 2 - 2, y + (pixelHeight - #char) + j - 1, 2, 1, color, 0xFFFFFF, " ")
|
||||
else
|
||||
screen.drawText(x + i * 2 - 2, y + (pixelHeight - #char) + j - 1, color, "*")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return #letters[symbol][1]
|
||||
return #char[1]
|
||||
end
|
||||
|
||||
function bigLetters.drawText(x, y, color, stroka, drawWithSymbol)
|
||||
checkArg(4, stroka, "string")
|
||||
|
||||
for i = 1, unicode.len(stroka) do
|
||||
x = x + bigLetters.draw(x, y, color, unicode.sub(stroka, i, i), drawWithSymbol) * 2 + lettersInterval
|
||||
end
|
||||
|
||||
return x
|
||||
end
|
||||
|
||||
function bigLetters.getTextSize(text)
|
||||
local width, height = 0, 0
|
||||
local symbol, symbolWidth, symbolHeight
|
||||
local symbol, symbolWidth, symbolHeight, char
|
||||
|
||||
for i = 1, unicode.len(text) do
|
||||
symbol = unicode.sub(text, i, i)
|
||||
|
||||
if symbol == " " then
|
||||
symbolWidth = spaceWidth
|
||||
symbolHeight = 5
|
||||
elseif not letters[symbol] then
|
||||
symbolHeight = #letters[unknownSymbol]
|
||||
symbolWidth = #letters[unknownSymbol][1]
|
||||
else
|
||||
symbolHeight = #letters[symbol]
|
||||
symbolWidth = #letters[symbol][1]
|
||||
char = getCharTable(symbol) or getCharTable(unknownSymbol)
|
||||
|
||||
symbolHeight = #char
|
||||
symbolWidth = #char[1]
|
||||
end
|
||||
|
||||
width = width + symbolWidth * 2 + lettersInterval
|
||||
@ -600,14 +607,3 @@ function bigLetters.getTextSize(text)
|
||||
end
|
||||
|
||||
return bigLetters
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user