aboutsummaryrefslogtreecommitdiff
path: root/advtrains_train_track/textures/advtrains_dtrack_xing4590_placer.png
blob: 7c5633bb4fbcbdf197ca4ece493a4aadcde073c3 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 38 00 00 00 38 04 03 00 00 00 5a a8 26 .PNG........IHDR...8...8.....Z.&
0020 2d 00 00 00 1b 50 4c 54 45 3e 47 c6 4c 07 01 39 16 05 50 21 01 66 4a 42 81 78 75 9a 94 92 b0 ac -....PLTE>G.L..9..P!.fJB.xu.....
0040 aa c8 c9 c6 4d aa af be 00 00 00 01 74 52 4e 53 00 40 e6 d8 66 00 00 00 09 70 48 59 73 00 00 0b ....M.......tRNS.@..f....pHYs...
0060 13 00 00 0b 13 01 00 9a 9c 18 00 00 01 52 49 44 41 54 38 cb ed d4 b1 4e c3 30 10 06 e0 50 07 b5 .............RIDAT8....N.0...P..
0080 63 95 28 e0 11 9c 16 18 9b 18 1e a1 85 b1 20 4c 67 50 91 18 a9 d4 c1 63 0c 55 ef 1e 9b 3b 17 d1 c.(............LgP.....c.U...;..
00a0 38 a1 88 81 81 a1 1e 92 c8 9f 7e c7 b9 b3 12 45 fb b1 1f 7f 36 30 b8 fd 16 79 06 fb fc 14 43 0b 8.........~....E....60...y....C.
00c0 af f1 07 2c 48 ed eb 0e 14 c5 4d 35 c1 1d 18 09 e9 c0 60 0b 6d e5 6f 5d 87 f0 80 4d cc 36 da 7b ...,H.....M5......`.m.o]...M.6.{
00e0 b3 33 ce c6 d0 ab b6 a8 37 da 75 36 99 51 56 80 ac a1 57 a1 8f 09 53 ce 82 74 7a 14 e8 4a 49 87 .3......7.u6.QV...W...S..tz..JI.
0100 c9 a9 a6 2c c8 45 3e 0a b3 4b 4e 96 ba 98 a1 91 2e a9 23 ab 75 98 e6 5a 53 36 c3 a7 00 a3 d2 58 ...,.E>..KN.......#.u..ZS6.....X
0120 4a 2a a5 0a 0d d2 e0 34 c0 43 34 0b 54 14 d4 97 20 c1 84 78 30 c4 bb 97 39 25 55 0e 72 0d d3 46 J*.....4.C4.T......x0...9%U.r..F
0140 6d a5 33 76 55 fa e4 e2 3c ec a9 c8 69 b7 cf 76 99 97 1a a5 2b 26 81 76 d4 85 43 24 55 03 fe ce m.3vU...<...i..v....+&.v..C$U...
0160 50 7d 85 86 ac 29 c8 77 ad 03 ed 70 85 d2 8c 95 92 ea 44 70 f7 b7 c9 ab 47 9b 6a 52 44 5f 5b 51 P}...).w...p......Dp....G.jRD_[Q
0180 cb 76 d4 e0 16 13 c5 ea 93 bc ff 71 70 02 fb 34 93 e1 fc b3 65 e2 ac 81 b4 fc 11 d5 b6 6a 1f 23 .v.........qp..4....e........j.#
01a0 db f7 2f a7 7d d9 b6 7e 9d 5b ea d1 6e 24 fd 7e d9 28 5e d3 65 d4 c2 b1 9f 12 f7 ff f8 47 f0 01 ../.}..~.[..n$.~.(^.e........G..
01c0 d8 76 70 34 8f 70 70 d0 00 00 00 00 49 45 4e 44 ae 42 60 82 .vp4.pp.....IEND.B`.
ref='#n122'>122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177


local ac = {nodes={}}

function ac.load(data)
	if data then
		ac.nodes=data.nodes
	end
end
function ac.save()
	return {nodes = ac.nodes}
end

function ac.after_place_node(pos, player)
	local meta=minetest.get_meta(pos)
	meta:set_string("formspec", ac.getform(pos, meta))
	meta:set_string("infotext", "LuaAutomation component, unconfigured.")
	local ph=minetest.pos_to_string(pos)
	--just get first available key!
	for en,_ in pairs(atlatc.envs) do
		ac.nodes[ph]={env=en}
		return
	end
end
function ac.getform(pos, meta_p)
	local meta = meta_p or minetest.get_meta(pos)
	local envs_asvalues={}
	
	local ph=minetest.pos_to_string(pos)
	local nodetbl = ac.nodes[ph]
	local env, code, err = nil, "", ""
	if nodetbl then
		code=nodetbl.code or ""
		err=nodetbl.err or ""
		env=nodetbl.env or ""
	end
	local sel = 1
	for n,_ in pairs(atlatc.envs) do
		envs_asvalues[#envs_asvalues+1]=minetest.formspec_escape(n)
		if n==env then
			sel=#envs_asvalues
		end
	end
	local form = "size[10,10]dropdown[0,0;3;env;"..table.concat(envs_asvalues, ",")..";"..sel.."]"
		.."button[4,0;2,1;save;Save]button[7,0;2,1;cle;Clear local env] textarea[0.2,1;10,10;code;Code;"..minetest.formspec_escape(code).."]"
		.."label[0,9.8;"..err.."]"
	return form
end

function ac.after_dig_node(pos, node, player)
	advtrains.invalidate_all_paths(pos)
	advtrains.ndb.clear(pos)
	local ph=minetest.pos_to_string(pos)
	ac.nodes[ph]=nil
end

function ac.on_receive_fields(pos, formname, fields, player)
	if not minetest.check_player_privs(player:get_player_name(), {atlatc=true}) then
		minetest.chat_send_player(player:get_player_name(), "Missing privilege: atlatc - Operation cancelled!")
		return
	end
	
	local meta=minetest.get_meta(pos)
	local ph=minetest.pos_to_string(pos)
	local nodetbl = ac.nodes[ph] or {}
	--if fields.quit then return end
	if fields.env then
		nodetbl.env=fields.env
	end
	if fields.code then
		nodetbl.code=fields.code
	end
	if fields.save then
		-- reset certain things
		nodetbl.err=nil
		if advtrains.lines and advtrains.lines.sched then
			-- discard all schedules for this node
			advtrains.lines.sched.discard_all(advtrains.encode_pos(pos))
		end
	end
	if fields.cle then
		nodetbl.data={}
	end
	
	ac.nodes[ph]=nodetbl
	
	meta:set_string("formspec", ac.getform(pos, meta))
	if nodetbl.env then
		meta:set_string("infotext", "LuaAutomation component, assigned to environment '"..nodetbl.env.."'")
	else
		meta:set_string("infotext", "LuaAutomation component, invalid enviroment set!")
	end
end

function ac.run_in_env(pos, evtdata, customfct_p)
	local ph=minetest.pos_to_string(pos)
	local nodetbl = ac.nodes[ph]
	if not nodetbl then
		atwarn("LuaAutomation component at",ph,": Data not in memory! Please visit component and click 'Save'!")
		return
	end
	
	local meta
	if advtrains.is_node_loaded(pos) then
		meta=minetest.get_meta(pos)
	end
	
	if not nodetbl.env or not atlatc.envs[nodetbl.env] then
		atwarn("LuaAutomation component at",ph,": Not an existing environment: "..(nodetbl.env or "<nil>"))
		return false
	end
	if not nodetbl.code or nodetbl.code=="" then
		atwarn("LuaAutomation component at",ph,": No code to run! (insert -- to suppress warning)")
		return false
	end
	
	local customfct=customfct_p or {}
	-- add interrupt function
	customfct.interrupt=function(t, imesg)
		assertt(t, "number")
		assert(t >= 0)
		atlatc.interrupt.add(t, pos, {type="int", int=true, message=imesg, msg=imesg}) --Compatiblity "message" field.
	end
	-- add digiline_send function, if digiline is loaded
	if minetest.global_exists("digiline") then
		customfct.digiline_send=function(channel, msg)
			assertt(channel, "string")
			if advtrains.is_node_loaded(pos) then
				digiline:receptor_send(pos, digiline.rules.default, channel, msg)
			end
		end
	end
	-- add lines scheduler if enabled
	if advtrains.lines and advtrains.lines.sched then
		customfct.schedule = function(rwtime, msg)
			return advtrains.lines.sched.enqueue(rwtime, "atlatc_env", {pos=pos, msg=msg}, advtrains.encode_pos(pos), 1)
		end
		customfct.schedule_in = function(rwtime, msg)
			return advtrains.lines.sched.enqueue_in(rwtime, "atlatc_env", {pos=pos, msg=msg}, advtrains.encode_pos(pos), 1)
		end
	end
	
	local datain=nodetbl.data or {}
	local succ, dataout = atlatc.envs[nodetbl.env]:execute_code(datain, nodetbl.code, evtdata, customfct)
	if succ then
		atlatc.active.nodes[ph].data=atlatc.remove_invalid_data(dataout)
	else
		atlatc.active.nodes[ph].err=dataout
		atwarn("LuaAutomation ATC interface rail at",ph,": LUA Error:",dataout)
		if meta then
			meta:set_string("infotext", "LuaAutomation ATC interface rail, ERROR:"..dataout)
		end
	end
	if meta then
		meta:set_string("formspec", ac.getform(pos, meta))
	end
end

function ac.on_digiline_receive(pos, node, channel, msg)
	atlatc.interrupt.add(0, pos, {type="digiline", digiline=true, channel = channel, msg = msg})
end

if advtrains.lines and advtrains.lines.sched then
	advtrains.lines.sched.register_callback("atlatc_env", function(data)
		-- This adds another interrupt to the atlatc queue... there might be a better way
		atlatc.interrupt.add(0, data.pos, {type="schedule",schedule=true, msg=data.msg})
	end)
end

ac.trackdef_advtrains_defs = {
	on_train_enter = function(pos, train_id)
		--do async. Event is fired in train steps
		atlatc.interrupt.add(0, pos, {type="train", train=true, id=train_id})
	end,
}

atlatc.active=ac