summaryrefslogtreecommitdiff
path: root/init.lua
blob: 850732b94e39792cc1cfe5d4948bf1ba22db8665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
minetest.register_node("advtouchscreen:advtouchscreen", {
	description = "Advanced Digilines Touchscreen",
	groups = {
		cracky=3
	},
	on_construct = function(pos)
		minetest.get_meta(pos):set_string("formspec","field[channel;Channel;]")
	end,
	drawtype = "nodebox",
	tiles = {
		"advtouchscreen_sides.png",
		"advtouchscreen_sides.png",
		"advtouchscreen_sides.png",
		"advtouchscreen_sides.png",
		"advtouchscreen_sides.png",
		"advtouchscreen_front.png"
		},
	paramtype = "light",
	paramtype2 = "facedir",
	node_box = {
		type = "fixed",
		fixed = {
			{ -0.5, -0.5, 0.4, 0.5, 0.5, 0.5 }
		}
    },
    _digistuff_channelcopier_fieldname = "channel",
	_digistuff_channelcopier_onset = function(pos)
		local meta = minetest.get_meta(pos)
		meta:set_int("init",1)
		meta:set_string("formspec","")
	end,
	on_receive_fields = function(pos,_,fields,player)
		local meta = minetest.get_meta(pos)
		local name = player:get_player_name()
		local protected = minetest.is_protected(pos,name) and not minetest.check_player_privs(name,"protection_bypass")
		if meta:get_int("init") == 0 then
			if fields.channel and fields.channel ~= "" then
				if protected then
					minetest.record_protection_violation(pos,name)
					minetest.chat_send_player(name,"You don't have access to set the channel on this screen.")
					return
				end
				meta:set_string("channel",fields.channel)
				meta:set_int("init",1)
				meta:set_string("formspec","")
			end
		else
			local locked = meta:get_int("locked") > 0
			if locked and protected and not fields.quit then
				minetest.record_protection_violation(pos,name)
				minetest.chat_send_player(name,"This screen is locked.")
				return
			end
			fields.clicker = name
			digilines.receptor_send(pos,digilines.rules.default,meta:get_string("channel"),fields)
		end
	end,
	digiline = {
		receptor = {},
		effector = {
			action = function(pos,_,channel,msg)
				local meta = minetest.get_meta(pos)
				if meta:get_string("channel") ~= channel or type(msg) ~= "string" then return end
				local lockcommands
				local unlockcommands
				--string.gsub() returns two values, the second one is how many times the replacement happened
				msg,lockcommands = string.gsub(msg,"lock%[1]","")
				msg,unlockcommands = string.gsub(msg,"lock%[0]","")
				if lockcommands > 0 then
					meta:set_int("locked",1)
				elseif unlockcommands > 0 then
					meta:set_int("locked",0)
				end
				meta:set_string("formspec",msg)
			end,
		},
	},
})

minetest.register_alias_force("digistuff:advtouchscreen","advtouchscreen:advtouchscreen")

minetest.register_craft({
	output = "advtouchscreen:advtouchscreen",
	type = "shapeless",
	recipe = {
		"digistuff:touchscreen",
		"default:mese_crystal",
	},
})