summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2021-02-28 19:51:39 -0600
committercheapie <no-email-for-you@example.com>2021-02-28 19:51:39 -0600
commit7570b4f5a59a65b4a90108ae29e06bede0a55652 (patch)
tree7c16689b9684fe522de831e8be69dbd8bef7f87f
parenta1a5e6b19c8005bbf5e3eecddbc12e15084993ae (diff)
downloaddigiscreen-master.tar
digiscreen-master.tar.gz
digiscreen-master.tar.bz2
digiscreen-master.tar.xz
digiscreen-master.zip
Add touch supportHEADmaster
-rw-r--r--README1
-rw-r--r--init.lua40
2 files changed, 41 insertions, 0 deletions
diff --git a/README b/README
index b34604a..44b4e52 100644
--- a/README
+++ b/README
@@ -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.
diff --git a/init.lua b/init.lua
index 314f833..a56195c 100644
--- a/init.lua
+++ b/init.lua
@@ -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,