Add touch support

This commit is contained in:
cheapie 2021-02-28 19:51:39 -06:00
parent a1a5e6b19c
commit 7570b4f5a5
2 changed files with 41 additions and 0 deletions

1
README

@ -5,6 +5,7 @@ How to use:
1. Place one and set the channel 1. Place one and set the channel
2. Send an image (see below for the format) 2. Send an image (see below for the format)
3. Image will be displayed on the screen 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) local meta = minetest.get_meta(pos)
meta:set_string("channel",fields.channel) meta:set_string("channel",fields.channel)
end, 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 = { digiline = {
wire = { wire = {
rules = digiline.rules.default, rules = digiline.rules.default,