diff options
author | cheapie <no-email-for-you@example.com> | 2021-02-28 19:51:39 -0600 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2021-02-28 19:51:39 -0600 |
commit | 7570b4f5a59a65b4a90108ae29e06bede0a55652 (patch) | |
tree | 7c16689b9684fe522de831e8be69dbd8bef7f87f | |
parent | a1a5e6b19c8005bbf5e3eecddbc12e15084993ae (diff) | |
download | digiscreen-7570b4f5a59a65b4a90108ae29e06bede0a55652.tar digiscreen-7570b4f5a59a65b4a90108ae29e06bede0a55652.tar.gz digiscreen-7570b4f5a59a65b4a90108ae29e06bede0a55652.tar.bz2 digiscreen-7570b4f5a59a65b4a90108ae29e06bede0a55652.tar.xz digiscreen-7570b4f5a59a65b4a90108ae29e06bede0a55652.zip |
Add touch support
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | init.lua | 40 |
2 files changed, 41 insertions, 0 deletions
@@ -5,6 +5,7 @@ How to use: 1. Place one and set the channel 2. Send an image (see below for the format) 3. Image will be displayed on the screen +4. If the screen is clicked, the screen will send a message on its channel containing the X and Y positions of the click and the name of the player. @@ -106,6 +106,46 @@ minetest.register_node("digiscreen:digiscreen",{ local meta = minetest.get_meta(pos) meta:set_string("channel",fields.channel) end, + on_punch = function(screenpos,_,player) + if player and not player.is_fake_player then + local eyepos = vector.add(player:get_pos(),vector.add(player:get_eye_offset(),vector.new(0,1.5,0))) + local lookdir = player:get_look_dir() + local distance = vector.distance(eyepos,screenpos) + local endpos = vector.add(eyepos,vector.multiply(lookdir,distance+1)) + local ray = minetest.raycast(eyepos,endpos,true,false) + local pointed,screen,hitpos + repeat + pointed = ray:next() + if pointed and pointed.type == "node" then + local node = minetest.get_node(pointed.under) + if node.name == "digiscreen:digiscreen" then + screen = pointed.under + hitpos = vector.subtract(pointed.intersection_point,screen) + end + end + until screen or not pointed + if not hitpos then return end + local facedir = minetest.facedir_to_dir(minetest.get_node(screen).param2) + if facedir.x > 0 then + hitpos.x = -1*hitpos.z + elseif facedir.x < 0 then + hitpos.x = hitpos.z + elseif facedir.z < 0 then + hitpos.x = -1*hitpos.x + end + hitpos.y = -1*hitpos.y + local hitpixel = {} + hitpixel.x = math.floor((hitpos.x+0.5)*16+0.5)+1 + hitpixel.y = math.floor((hitpos.y+0.5)*16+0.5)+1 + if hitpixel.x < 1 or hitpixel.x > 16 or hitpixel.y < 1 or hitpixel.y > 16 then return end + local message = { + x = hitpixel.x, + y = hitpixel.y, + player = player:get_player_name(), + } + digilines.receptor_send(screenpos,digilines.rules.default,minetest.get_meta(screenpos):get_string("channel"),message) + end + end, digiline = { wire = { rules = digiline.rules.default, |