From 77b4fbe12db947911fcccd82d0da1eef4b68d9b1 Mon Sep 17 00:00:00 2001 From: cheapie Date: Sat, 28 Mar 2020 01:31:12 -0500 Subject: [PATCH] Add magnetic card reader/writer and cards to go with it --- README | 9 ++ cardreader.lua | 118 ++++++++++++++++++++++++ init.lua | 1 + textures/digistuff_cardreader_sides.png | Bin 0 -> 6015 bytes textures/digistuff_cardreader_top.png | Bin 0 -> 6094 bytes textures/digistuff_magnetic_card.png | Bin 0 -> 635 bytes 6 files changed, 128 insertions(+) create mode 100644 cardreader.lua create mode 100644 textures/digistuff_cardreader_sides.png create mode 100644 textures/digistuff_cardreader_top.png create mode 100644 textures/digistuff_magnetic_card.png diff --git a/README b/README index 79f68c7..d04d661 100644 --- a/README +++ b/README @@ -71,3 +71,12 @@ As in, [digiline][junction box][dirt][junction box][digiline] will work to trans How to use the I/O expander: After setting a channel, send a table (same format as a Luacontroller's "port" table) to set the output states. A table in this same format will be sent back whenever an input changes or you manually poll it by sending a "GET" message. + +How to use the card reader: +After setting a channel, swiping a card (punch the reader with the card to swipe) will send a message in the following format: + {event = "read",data = "The data that was on the card"} +To write a card, send a command in the following format: + {command = "write",data = "The data to put on the card",description = "A description of what the card is for"} +After sending the write command, swipe the card to be written and the reader will send back the following message: + {event = "write"} +Both blank and previously written cards can be written to. If the card was not blank, it will be overwritten. diff --git a/cardreader.lua b/cardreader.lua new file mode 100644 index 0000000..31ff7e4 --- /dev/null +++ b/cardreader.lua @@ -0,0 +1,118 @@ +local cardreader_rules = { + {x = 1, y = 0,z = 0,}, + {x = 2, y = 0,z = 0,}, + {x = -1, y = 0,z = 0,}, + {x = -2, y = 0,z = 0,}, + {x = 0, y = 1,z = 0,}, + {x = 0, y = 2,z = 0,}, + {x = 0, y = -1,z = 0,}, + {x = 0, y = -2,z = 0,}, + {x = 0, y = 0,z = 1,}, + {x = 0, y = 0,z = 2,}, + {x = 0, y = 0,z = -1,}, + {x = 0, y = 0,z = -2,}, +} + +minetest.register_craftitem("digistuff:card",{ + description = "Blank Magnetic Card", + image = "digistuff_magnetic_card.png", + stack_max = 1, + on_use = function(stack,_,pointed) + local pos = pointed.under + if minetest.get_node(pos).name ~= "digistuff:card_reader" then return end + local meta = minetest.get_meta(pos) + local channel = meta:get_string("channel") + local stackmeta = stack:get_meta() + if meta:get_int("writepending") > 0 then + local data = meta:get_string("writedata") + meta:set_int("writepending",0) + meta:set_string("infotext","Ready to Read") + digiline:receptor_send(pos,cardreader_rules,channel,{event = "write",}) + stackmeta:set_string("data",data) + stackmeta:set_string("description",string.format("Magnetic Card (%s)",meta:get_string("writedescription"))) + return stack + else + local channel = meta:get_string("channel") + local data = stackmeta:get_string("data") + digiline:receptor_send(pos,cardreader_rules,channel,{event = "read",data = data,}) + end + end, +}) + +minetest.register_node("digistuff:card_reader",{ + description = "Digilines Magnetic Card Reader/Writer", + groups = {cracky = 3,digiline_receiver = 1,}, + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec","field[channel;Channel;${channel}") + meta:set_int("writepending",0) + meta:set_string("infotext","Ready to Read") + end, + on_receive_fields = function(pos, formname, fields, sender) + local name = sender:get_player_name() + if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then + minetest.record_protection_violation(pos,name) + return + end + local meta = minetest.get_meta(pos) + if fields.channel then meta:set_string("channel",fields.channel) end + end, + paramtype = "light", + paramtype2 = "facedir", + tiles = { + "digistuff_cardreader_sides.png", + "digistuff_cardreader_sides.png", + "digistuff_cardreader_sides.png", + "digistuff_cardreader_sides.png", + "digistuff_cardreader_sides.png", + "digistuff_cardreader_top.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.08,-0.12,0.4,0.08,0.12,0.5}, + } + }, + digiline = { + receptor = {}, + wire = { + rules = cardreader_rules, + }, + effector = { + action = function(pos,node,channel,msg) + local setchannel = minetest.get_meta(pos):get_string("channel") + if channel ~= setchannel or type(msg) ~= "table" then return end + if msg.command == "write" and (type(msg.data) == "string" or type(msg.data) == "number") then + local meta = minetest.get_meta(pos) + meta:set_string("infotext","Ready to Write") + meta:set_int("writepending",1) + if type(msg.data) ~= "string" then msg.data = tostring(msg.data) end + meta:set_string("writedata",string.sub(msg.data,1,256)) + if type(msg.description == "string") then + meta:set_string("writedescription",string.sub(msg.description,1,64)) + else + meta:set_string("writedescription","no name") + end + end + end, + }, + }, +}) + +minetest.register_craft({ + output = "digistuff:card", + recipe = { + {"basic_materials:plastic_sheet",}, + {"default:iron_lump",}, + } +}) + +minetest.register_craft({ + output = "digistuff:card_reader", + recipe = { + {"basic_materials:plastic_sheet","basic_materials:plastic_sheet","digilines:wire_std_00000000",}, + {"basic_materials:plastic_sheet","basic_materials:copper_wire","mesecons_luacontroller:luacontroller0000",}, + {"basic_materials:plastic_sheet","basic_materials:plastic_sheet","",}, + } +}) diff --git a/init.lua b/init.lua index 4df2e65..90d8ea0 100644 --- a/init.lua +++ b/init.lua @@ -13,6 +13,7 @@ local components = { "detector", "piston", "timer", + "cardreader", } if minetest.get_modpath("mesecons_luacontroller") then table.insert(components,"ioexpander") end diff --git a/textures/digistuff_cardreader_sides.png b/textures/digistuff_cardreader_sides.png new file mode 100644 index 0000000000000000000000000000000000000000..ede5f181e277b2602113f9a1f3ede09d92cafb2b GIT binary patch literal 6015 zcmeHLdpuO@8Xi<~NfbpXV-zW4?#zstgb`Cn%!KaCnl)o$W=%6|%t%za&8E9_fH=9<^4R|d~1tq)rl#7-agX&VfW3uyIdoZ z9pcN0RQ&MOw^&Z``vSIH-tycrt1}PhkoHj8w&AC9(g(azz1>n)+0{|LK&5{mQmSp` zZkp0MqA|+QTDfbBZDZ~lm*g4Er1=FA7BNY?VeWLA*!%LZh5V&eSX^YLhHm4 zMx8U(ktb&J-YBxhIgWAvy;E>M>a3gQ$yKiwxaGGa*B5fPyBRe8zBmN?m@?{VGN?5c z8SJO{q?=qR>wI#2&ZQM>Z}a+l*E0jxkDO9bnS0T4I+)jVXt3`wiy%qWuDZ?}?Kd?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