-
Notifications
You must be signed in to change notification settings - Fork 43
Added screen mode LCD #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
824c141
a41179f
5c4ac5d
0b151a8
754811c
b59e266
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,7 +161,7 @@ local generate_line = function(s, ypos) | |
| return texture | ||
| end | ||
|
|
||
| local generate_texture = function(lines) | ||
| local generate_text_texture = function(lines) | ||
| local texture = "[combine:"..LCD_WIDTH.."x"..LCD_WIDTH | ||
| local ypos = math.floor((LCD_WIDTH - LINE_HEIGHT*NUMBER_OF_LINES) / 2) | ||
| for i = 1, #lines do | ||
|
|
@@ -171,6 +171,44 @@ local generate_texture = function(lines) | |
| return texture | ||
| end | ||
|
|
||
| local number_to_color = function(num) | ||
| if type(num) ~= "number" or num >= 4096 or num < 0 then | ||
| return "#0000" | ||
| end | ||
|
|
||
| return string.format("#%X%X%X", num / 16^2, num / 16 % 16, num % 16 ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the |
||
| end | ||
|
|
||
| local generate_raster_texture = function(colors) | ||
| -- the LCD texture is 16x16, will upscale the resolution by 4 | ||
| local total_width = 16 * 4 | ||
| local w_padding = 1 * 4 | ||
| local h_padding = 2 * 4 | ||
|
|
||
| local width = total_width - w_padding * 2 | ||
| local height = total_width - h_padding * 2 | ||
|
|
||
| -- using escapes for the combine at the end | ||
| local texture = "lcd_anyside.png\\^[resize\\:"..total_width.."x"..total_width | ||
|
|
||
| if type(colors) == "table" then | ||
| local pixels = {} | ||
| for i = 1, width * height do | ||
| local color = "#0000" | ||
| if (i <= #colors) then | ||
| color = number_to_color(colors[i]) | ||
| end | ||
| pixels[i] = color | ||
| end | ||
| local png = minetest.encode_base64(minetest.encode_png(width, height, pixels)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| texture = "[combine:"..total_width.."x"..total_width | ||
| ..":0,0="..texture | ||
| ..":"..w_padding..","..h_padding.."=[png\\:"..png | ||
| end | ||
|
|
||
| return texture | ||
| end | ||
|
|
||
| local lcds = { | ||
| -- on ceiling | ||
| --* [0] = {delta = {x = 0, y = 0.4, z = 0}, pitch = math.pi / -2}, | ||
|
|
@@ -202,10 +240,18 @@ end | |
|
|
||
| local set_texture = function(ent) | ||
| local meta = minetest.get_meta(ent.object:get_pos()) | ||
| local text = meta:get_string("text") | ||
| local message = meta:get_string("message") | ||
| local message_type = meta:get_string("message_type") | ||
|
|
||
| local texture | ||
| if message_type == "string" then | ||
| texture = generate_text_texture(create_lines(message)) | ||
| else | ||
| texture = generate_raster_texture(minetest.deserialize(message)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be documented somewhere. Otherwise no-one else would know about this raster feature. |
||
| end | ||
| ent.object:set_properties({ | ||
| textures = { | ||
| generate_texture(create_lines(text)) | ||
| texture | ||
| } | ||
| }) | ||
| end | ||
|
|
@@ -260,12 +306,19 @@ local on_digiline_receive = function(pos, _, channel, msg) | |
| local setchan = meta:get_string("channel") | ||
| if setchan ~= channel then return end | ||
|
|
||
| if type(msg) ~= "string" and type(msg) ~= "number" then return end | ||
| if type(msg) == "string" or type(msg) == "number" then | ||
| meta:set_string("message", msg) | ||
| meta:set_string("infotext", msg) | ||
| elseif type(msg) == "table" then | ||
| meta:set_string("message", minetest.serialize(msg)) | ||
| meta:set_string("infotext", "") | ||
| else | ||
| return | ||
| end | ||
|
|
||
| meta:set_string("text", msg) | ||
| meta:set_string("infotext", msg) | ||
| meta:set_string("message_type", type(msg)) | ||
|
|
||
| if msg ~= "" then | ||
| if type(msg) ~= string or msg ~= "" then | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| prepare_writing(pos) | ||
| end | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of an error, it might make more sense to either:
0xF00(red = error)tonumber(num) or 0to the numeric computation below and let the user see when it looks strange.Also: What if
nanis passed to this function?