Initial commit
commit
c8c4b70d4f
|
@ -0,0 +1 @@
|
|||
.got/*
|
|
@ -0,0 +1,8 @@
|
|||
## Minetest QR Code
|
||||
|
||||
Installing mod:
|
||||
|
||||
|
||||
Download from source...
|
||||
|
||||
Please add `qrcode` to `secure.trusted_mods` or else the mod won't load and your server will crash!
|
|
@ -0,0 +1,61 @@
|
|||
|
||||
qrencode = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/qrencode.lua")
|
||||
|
||||
local function matrix_to_string(tab)
|
||||
local str_tab = {}
|
||||
for i=1,#tab + 2 do
|
||||
str_tab[i] = {"0"}
|
||||
end
|
||||
|
||||
for x=1,#tab do
|
||||
for y=1,#tab do
|
||||
if tab[x][y] > 0 then
|
||||
str_tab[y + 1][x + 1] = "1"
|
||||
elseif tab[x][y] < 0 then
|
||||
str_tab[y + 1][x + 1] = "0"
|
||||
else
|
||||
str_tab[y + 1][x + 1] = " "
|
||||
str_tab[y + 1][x + 2] = "1"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local padding_string = {}
|
||||
for i=1,#tab do
|
||||
padding_string[i] = "0"
|
||||
end
|
||||
str_tab[1] = padding_string
|
||||
str_tab[#tab + 2] = padding_string
|
||||
|
||||
for i=1,#tab + 2 do
|
||||
str_tab[i][#str_tab[i] + 1] = "0"
|
||||
end
|
||||
return str_tab
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("qrcode", {
|
||||
params = "<message>",
|
||||
description = "Creates QR Code.",
|
||||
func = function(name, message)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local pos = player:get_pos()
|
||||
local ok, tab_or_message = qrencode.qrcode(message)
|
||||
if not ok then
|
||||
print('Something went wrong')
|
||||
else
|
||||
local rows = matrix_to_string(tab_or_message)
|
||||
local string
|
||||
for x=1,#rows do
|
||||
for z=1,#rows do
|
||||
if rows[x][z] == "1" then
|
||||
minetest.set_node(vector.new(pos.x + x, pos.y - 1, pos.z + z), { name = "wool:black" })
|
||||
elseif rows[x][z] == "0" then
|
||||
minetest.set_node(vector.new(pos.x + x, pos.y - 1, pos.z + z), { name = "wool:white" })
|
||||
-- else
|
||||
-- string = string .. " "
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
|
@ -0,0 +1,3 @@
|
|||
name = qrcode
|
||||
description = Create QR Codes in your minetest world
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue