Compare commits
	
		
			12 Commits
		
	
	
		
			b0158f5674
			...
			9b58f8db29
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					9b58f8db29 | ||
| 
						 | 
					7784b13da5 | ||
| 
						 | 
					0dd530312b | ||
| 
						 | 
					e78bbd6f98 | ||
| 
						 | 
					bfd952b51a | ||
| 
						 | 
					b7873e8e02 | ||
| 
						 | 
					d6b2a39c99 | ||
| 
						 | 
					1b54011b68 | ||
| 
						 | 
					15e743629e | ||
| 
						 | 
					1bf862f932 | ||
| 
						 | 
					1a9704f184 | ||
| 
						 | 
					8baa789eb1 | 
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						@@ -1 +1,3 @@
 | 
				
			|||||||
*~
 | 
					*~
 | 
				
			||||||
 | 
					*.patch
 | 
				
			||||||
 | 
					*.diff
 | 
				
			||||||
 
 | 
				
			|||||||
| 
		 Before Width: | Height: | Size: 323 B After Width: | Height: | Size: 191 B  | 
| 
		 Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 844 B  | 
| 
		 Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 838 B  | 
| 
		 Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 851 B  | 
| 
		 Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 846 B  | 
| 
		 Before Width: | Height: | Size: 550 B After Width: | Height: | Size: 222 B  | 
| 
		 Before Width: | Height: | Size: 613 B After Width: | Height: | Size: 504 B  | 
| 
		 Before Width: | Height: | Size: 204 B After Width: | Height: | Size: 144 B  | 
| 
		 Before Width: | Height: | Size: 465 B After Width: | Height: | Size: 377 B  | 
| 
		 Before Width: | Height: | Size: 464 B After Width: | Height: | Size: 362 B  | 
@@ -186,19 +186,11 @@ function mesecon.invertRule(r)
 | 
				
			|||||||
	return vector.multiply(r, -1)
 | 
						return vector.multiply(r, -1)
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function mesecon.tablecopy(table) -- deep table copy
 | 
					function mesecon.tablecopy(obj) -- deep copy
 | 
				
			||||||
	if type(table) ~= "table" then return table end -- no need to copy
 | 
						if type(obj) == "table" then
 | 
				
			||||||
	local newtable = {}
 | 
							return table.copy(obj)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	for idx, item in pairs(table) do
 | 
					 | 
				
			||||||
		if type(item) == "table" then
 | 
					 | 
				
			||||||
			newtable[idx] = mesecon.tablecopy(item)
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
			newtable[idx] = item
 | 
					 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	end
 | 
						return obj
 | 
				
			||||||
 | 
					 | 
				
			||||||
	return newtable
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function mesecon.cmpAny(t1, t2)
 | 
					function mesecon.cmpAny(t1, t2)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										
											BIN
										
									
								
								mesecons_blinkyplant/doc/blinkyplant/preview.png
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						| 
		 Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 54 KiB  | 
| 
		 Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 1.7 KiB  | 
| 
		 Before Width: | Height: | Size: 454 B After Width: | Height: | Size: 367 B  | 
| 
		 Before Width: | Height: | Size: 463 B After Width: | Height: | Size: 394 B  | 
| 
		 Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 68 KiB  | 
| 
		 Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 4.3 KiB  | 
| 
		 Before Width: | Height: | Size: 411 B After Width: | Height: | Size: 371 B  | 
| 
		 Before Width: | Height: | Size: 449 B After Width: | Height: | Size: 409 B  | 
| 
		 Before Width: | Height: | Size: 434 B After Width: | Height: | Size: 220 B  | 
| 
		 Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 33 KiB  | 
| 
		 Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 183 B  | 
| 
		 Before Width: | Height: | Size: 278 B After Width: | Height: | Size: 183 B  | 
| 
		 Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 50 KiB  | 
| 
		 Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 4.2 KiB  | 
@@ -33,19 +33,9 @@ end
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
-- Register the 2 (states) x 4 (delay times) delayers
 | 
					-- Register the 2 (states) x 4 (delay times) delayers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for i = 1, 4 do
 | 
					local delaytime = { 0.1, 0.3, 0.5, 1.0 }
 | 
				
			||||||
local groups = {}
 | 
					 | 
				
			||||||
if i == 1 then
 | 
					 | 
				
			||||||
	groups = {bendy=2,snappy=1,dig_immediate=2}
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
	groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1}
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local delaytime
 | 
					for i = 1, 4 do
 | 
				
			||||||
if 		i == 1 then delaytime = 0.1
 | 
					 | 
				
			||||||
elseif	i == 2 then delaytime = 0.3
 | 
					 | 
				
			||||||
elseif	i == 3 then delaytime = 0.5
 | 
					 | 
				
			||||||
elseif	i == 4 then delaytime = 1.0 end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local boxes = {
 | 
					local boxes = {
 | 
				
			||||||
	 { -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 },		-- the main slab
 | 
						 { -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 },		-- the main slab
 | 
				
			||||||
@@ -61,9 +51,36 @@ local boxes = {
 | 
				
			|||||||
	 { 6/16, -8/16, -1/16, 8/16, -7/16, 1/16 }
 | 
						 { 6/16, -8/16, -1/16, 8/16, -7/16, 1/16 }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
 | 
					-- Delayer definition defaults
 | 
				
			||||||
	description = "Delayer",
 | 
					local def = {
 | 
				
			||||||
	drawtype = "nodebox",
 | 
						drawtype = "nodebox",
 | 
				
			||||||
 | 
						walkable = true,
 | 
				
			||||||
 | 
						selection_box = {
 | 
				
			||||||
 | 
							type = "fixed",
 | 
				
			||||||
 | 
							fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						node_box = {
 | 
				
			||||||
 | 
							type = "fixed",
 | 
				
			||||||
 | 
							fixed = boxes
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						paramtype = "light",
 | 
				
			||||||
 | 
						paramtype2 = "facedir",
 | 
				
			||||||
 | 
						sunlight_propagates = true,
 | 
				
			||||||
 | 
						is_ground_content = false,
 | 
				
			||||||
 | 
						delayer_time = delaytime[i],
 | 
				
			||||||
 | 
						sounds = default.node_sound_stone_defaults(),
 | 
				
			||||||
 | 
						on_blast = mesecon.on_blastnode,
 | 
				
			||||||
 | 
						drop = "mesecons_delayer:delayer_off_1",
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Deactivated delayer definition defaults
 | 
				
			||||||
 | 
					local off_groups = {bendy=2,snappy=1,dig_immediate=2}
 | 
				
			||||||
 | 
					if i > 1 then
 | 
				
			||||||
 | 
						off_groups.not_in_creative_inventory = 1
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local off_state = {
 | 
				
			||||||
 | 
						description = "Delayer",
 | 
				
			||||||
	tiles = {
 | 
						tiles = {
 | 
				
			||||||
		"mesecons_delayer_off_"..tostring(i)..".png",
 | 
							"mesecons_delayer_off_"..tostring(i)..".png",
 | 
				
			||||||
		"mesecons_delayer_bottom.png",
 | 
							"mesecons_delayer_bottom.png",
 | 
				
			||||||
@@ -74,35 +91,18 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
 | 
				
			|||||||
	},
 | 
						},
 | 
				
			||||||
	inventory_image = "mesecons_delayer_off_1.png",
 | 
						inventory_image = "mesecons_delayer_off_1.png",
 | 
				
			||||||
	wield_image = "mesecons_delayer_off_1.png",
 | 
						wield_image = "mesecons_delayer_off_1.png",
 | 
				
			||||||
	walkable = true,
 | 
						groups = off_groups,
 | 
				
			||||||
	selection_box = {
 | 
						on_punch = function(pos, node, puncher)
 | 
				
			||||||
		type = "fixed",
 | 
							if minetest.is_protected(pos, puncher and puncher:get_player_name()) then
 | 
				
			||||||
		fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
 | 
								return
 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
	node_box = {
 | 
					 | 
				
			||||||
		type = "fixed",
 | 
					 | 
				
			||||||
		fixed = boxes
 | 
					 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
	groups = groups,
 | 
					 | 
				
			||||||
	paramtype = "light",
 | 
					 | 
				
			||||||
	paramtype2 = "facedir",
 | 
					 | 
				
			||||||
	sunlight_propagates = true,
 | 
					 | 
				
			||||||
	is_ground_content = false,
 | 
					 | 
				
			||||||
	drop = 'mesecons_delayer:delayer_off_1',
 | 
					 | 
				
			||||||
	on_punch = function (pos, node)
 | 
					 | 
				
			||||||
		if node.name=="mesecons_delayer:delayer_off_1" then
 | 
					 | 
				
			||||||
			minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_2", param2=node.param2})
 | 
					 | 
				
			||||||
		elseif node.name=="mesecons_delayer:delayer_off_2" then
 | 
					 | 
				
			||||||
			minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_3", param2=node.param2})
 | 
					 | 
				
			||||||
		elseif node.name=="mesecons_delayer:delayer_off_3" then
 | 
					 | 
				
			||||||
			minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_4", param2=node.param2})
 | 
					 | 
				
			||||||
		elseif node.name=="mesecons_delayer:delayer_off_4" then
 | 
					 | 
				
			||||||
			minetest.swap_node(pos, {name = "mesecons_delayer:delayer_off_1", param2=node.param2})
 | 
					 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							minetest.swap_node(pos, {
 | 
				
			||||||
 | 
								name = "mesecons_delayer:delayer_off_"..tostring(i % 4 + 1),
 | 
				
			||||||
 | 
								param2 = node.param2
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
	end,
 | 
						end,
 | 
				
			||||||
	delayer_time = delaytime,
 | 
					 | 
				
			||||||
	delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
 | 
						delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
 | 
				
			||||||
	sounds = default.node_sound_stone_defaults(),
 | 
					 | 
				
			||||||
	mesecons = {
 | 
						mesecons = {
 | 
				
			||||||
		receptor =
 | 
							receptor =
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -115,13 +115,15 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
 | 
				
			|||||||
			action_on = delayer_activate
 | 
								action_on = delayer_activate
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	on_blast = mesecon.on_blastnode,
 | 
					}
 | 
				
			||||||
})
 | 
					for k, v in pairs(def) do
 | 
				
			||||||
 | 
						off_state[k] = off_state[k] or v
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), off_state)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Activated delayer definition defaults
 | 
				
			||||||
minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
 | 
					local on_state = {
 | 
				
			||||||
	description = "You hacker you",
 | 
						description = "You hacker you",
 | 
				
			||||||
	drawtype = "nodebox",
 | 
					 | 
				
			||||||
	tiles = {
 | 
						tiles = {
 | 
				
			||||||
		"mesecons_delayer_on_"..tostring(i)..".png",
 | 
							"mesecons_delayer_on_"..tostring(i)..".png",
 | 
				
			||||||
		"mesecons_delayer_bottom.png",
 | 
							"mesecons_delayer_bottom.png",
 | 
				
			||||||
@@ -130,35 +132,18 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
 | 
				
			|||||||
		"mesecons_delayer_sides_on.png",
 | 
							"mesecons_delayer_sides_on.png",
 | 
				
			||||||
		"mesecons_delayer_sides_on.png"
 | 
							"mesecons_delayer_sides_on.png"
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	walkable = true,
 | 
					 | 
				
			||||||
	selection_box = {
 | 
					 | 
				
			||||||
		type = "fixed",
 | 
					 | 
				
			||||||
		fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
 | 
					 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
	node_box = {
 | 
					 | 
				
			||||||
		type = "fixed",
 | 
					 | 
				
			||||||
		fixed = boxes
 | 
					 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
	groups = {bendy = 2, snappy = 1, dig_immediate = 2, not_in_creative_inventory = 1},
 | 
						groups = {bendy = 2, snappy = 1, dig_immediate = 2, not_in_creative_inventory = 1},
 | 
				
			||||||
	paramtype = "light",
 | 
						on_punch = function(pos, node, puncher)
 | 
				
			||||||
	paramtype2 = "facedir",
 | 
							if minetest.is_protected(pos, puncher and puncher:get_player_name()) then
 | 
				
			||||||
	sunlight_propagates = true,
 | 
								return
 | 
				
			||||||
	is_ground_content = false,
 | 
					 | 
				
			||||||
	drop = 'mesecons_delayer:delayer_off_1',
 | 
					 | 
				
			||||||
	on_punch = function (pos, node)
 | 
					 | 
				
			||||||
		if node.name=="mesecons_delayer:delayer_on_1" then
 | 
					 | 
				
			||||||
			minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_2", param2=node.param2})
 | 
					 | 
				
			||||||
		elseif node.name=="mesecons_delayer:delayer_on_2" then
 | 
					 | 
				
			||||||
			minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_3", param2=node.param2})
 | 
					 | 
				
			||||||
		elseif node.name=="mesecons_delayer:delayer_on_3" then
 | 
					 | 
				
			||||||
			minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_4", param2=node.param2})
 | 
					 | 
				
			||||||
		elseif node.name=="mesecons_delayer:delayer_on_4" then
 | 
					 | 
				
			||||||
			minetest.swap_node(pos, {name = "mesecons_delayer:delayer_on_1", param2=node.param2})
 | 
					 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							minetest.swap_node(pos, {
 | 
				
			||||||
 | 
								name = "mesecons_delayer:delayer_on_"..tostring(i % 4 + 1),
 | 
				
			||||||
 | 
								param2 = node.param2
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
	end,
 | 
						end,
 | 
				
			||||||
	delayer_time = delaytime,
 | 
					 | 
				
			||||||
	delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i),
 | 
						delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i),
 | 
				
			||||||
	sounds = default.node_sound_stone_defaults(),
 | 
					 | 
				
			||||||
	mesecons = {
 | 
						mesecons = {
 | 
				
			||||||
		receptor =
 | 
							receptor =
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@@ -171,8 +156,12 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
 | 
				
			|||||||
			action_off = delayer_deactivate
 | 
								action_off = delayer_deactivate
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	on_blast = mesecon.on_blastnode,
 | 
					}
 | 
				
			||||||
})
 | 
					for k, v in pairs(def) do
 | 
				
			||||||
 | 
						on_state[k] = on_state[k] or v
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), on_state)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
minetest.register_craft({
 | 
					minetest.register_craft({
 | 
				
			||||||
 
 | 
				
			|||||||
| 
		 Before Width: | Height: | Size: 438 B After Width: | Height: | Size: 221 B  | 
| 
		 Before Width: | Height: | Size: 226 B After Width: | Height: | Size: 176 B  | 
| 
		 Before Width: | Height: | Size: 228 B After Width: | Height: | Size: 187 B  | 
| 
		 Before Width: | Height: | Size: 562 B After Width: | Height: | Size: 448 B  | 
| 
		 Before Width: | Height: | Size: 558 B After Width: | Height: | Size: 449 B  | 
| 
		 Before Width: | Height: | Size: 561 B After Width: | Height: | Size: 448 B  | 
| 
		 Before Width: | Height: | Size: 556 B After Width: | Height: | Size: 446 B  | 
| 
		 Before Width: | Height: | Size: 635 B After Width: | Height: | Size: 541 B  | 
| 
		 Before Width: | Height: | Size: 632 B After Width: | Height: | Size: 541 B  | 
| 
		 Before Width: | Height: | Size: 635 B After Width: | Height: | Size: 541 B  | 
| 
		 Before Width: | Height: | Size: 630 B After Width: | Height: | Size: 538 B  | 
| 
		 Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 173 B  | 
| 
		 Before Width: | Height: | Size: 234 B After Width: | Height: | Size: 181 B  | 
@@ -1,8 +1,11 @@
 | 
				
			|||||||
The node detector is a receptor. It changes its state when either any node
 | 
					The node detector is a receptor. It changes its state when either any node
 | 
				
			||||||
or a specific node is detected. Right-click it to set a nodename to scan for.
 | 
					or a specific node is detected. Right-click it to set a nodename to scan for.
 | 
				
			||||||
It can also receive digiline signals. You can either send "GET" and it will
 | 
					It can also receive digiline signals. For example, you can send
 | 
				
			||||||
respond with the detected nodename or you can send any other string and it will
 | 
					<code>{distance=4, scanname="default:dirt"}</code>
 | 
				
			||||||
set this string as the node to scan for.
 | 
					to set distance to 4 and scan for dirt. You can omit either parameter.
 | 
				
			||||||
 | 
					There is also a command parameter: <code>{command="get"}</code> will respond
 | 
				
			||||||
 | 
					with the detected nodename and <code>{command="scan"}</code> will respond with
 | 
				
			||||||
 | 
					a boolean using the distance and nodename of the detector.
 | 
				
			||||||
Nodenames must include the mod they reside in, so for instance default:dirt, not just dirt.
 | 
					Nodenames must include the mod they reside in, so for instance default:dirt, not just dirt.
 | 
				
			||||||
The distance parameter specifies how many blocks are between the node detector and the node to detect.
 | 
					The distance parameter specifies how many blocks are between the node detector and the node to detect.
 | 
				
			||||||
Automatic scanning with Mesecons output only works when the detector is in an active block, but Digilines queries always work.
 | 
					Automatic scanning with Mesecons output only works when the detector is in an active block, but Digilines queries always work.
 | 
				
			||||||
 
 | 
				
			|||||||
| 
		 Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 43 KiB  | 
| 
		 Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 7.3 KiB  | 
| 
		 Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 78 KiB  | 
| 
		 Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 7.1 KiB  | 
@@ -189,29 +189,50 @@ local function node_detector_scan(pos)
 | 
				
			|||||||
		(frontname ~= "air" and frontname ~= "ignore" and scanname == "")
 | 
							(frontname ~= "air" and frontname ~= "ignore" and scanname == "")
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local function node_detector_send_node_name(pos, node, channel, meta)
 | 
				
			||||||
 | 
						local distance = meta:get_int("distance")
 | 
				
			||||||
 | 
						local distance_max = mesecon.setting("node_detector_distance_max", 10)
 | 
				
			||||||
 | 
						if distance < 0 then distance = 0 end
 | 
				
			||||||
 | 
						if distance > distance_max then distance = distance_max end
 | 
				
			||||||
 | 
						local nodename = minetest.get_node(
 | 
				
			||||||
 | 
							vector.subtract(pos, vector.multiply(minetest.facedir_to_dir(node.param2), distance + 1))
 | 
				
			||||||
 | 
						).name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						digiline:receptor_send(pos, digiline.rules.default, channel, nodename)
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- set player name when receiving a digiline signal on a specific channel
 | 
					-- set player name when receiving a digiline signal on a specific channel
 | 
				
			||||||
local node_detector_digiline = {
 | 
					local node_detector_digiline = {
 | 
				
			||||||
	effector = {
 | 
						effector = {
 | 
				
			||||||
		action = function(pos, node, channel, msg)
 | 
							action = function(pos, node, channel, msg)
 | 
				
			||||||
			local meta = minetest.get_meta(pos)
 | 
								local meta = minetest.get_meta(pos)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			local distance = meta:get_int("distance")
 | 
					 | 
				
			||||||
			local distance_max = mesecon.setting("node_detector_distance_max", 10)
 | 
					 | 
				
			||||||
			if distance < 0 then distance = 0 end
 | 
					 | 
				
			||||||
			if distance > distance_max then distance = distance_max end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if channel ~= meta:get_string("digiline_channel") then return end
 | 
								if channel ~= meta:get_string("digiline_channel") then return end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if type(msg) == "table" then
 | 
				
			||||||
 | 
									if msg.distance or msg.scanname then
 | 
				
			||||||
 | 
										if msg.distance then
 | 
				
			||||||
 | 
											meta:set_string("distance", msg.distance)
 | 
				
			||||||
 | 
										end
 | 
				
			||||||
 | 
										if msg.scanname then
 | 
				
			||||||
 | 
											meta:set_string("scanname", msg.scanname)
 | 
				
			||||||
 | 
										end
 | 
				
			||||||
 | 
										node_detector_make_formspec(pos)
 | 
				
			||||||
 | 
									end
 | 
				
			||||||
 | 
									if msg.command == "get" then
 | 
				
			||||||
 | 
										node_detector_send_node_name(pos, node, channel, meta)
 | 
				
			||||||
 | 
									elseif msg.command == "scan" then
 | 
				
			||||||
 | 
										local result = node_detector_scan(pos)
 | 
				
			||||||
 | 
										digiline:receptor_send(pos, digiline.rules.default, channel, result)
 | 
				
			||||||
 | 
									end
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
				if msg == GET_COMMAND then
 | 
									if msg == GET_COMMAND then
 | 
				
			||||||
				local nodename = minetest.get_node(
 | 
										node_detector_send_node_name(pos, node, channel, meta)
 | 
				
			||||||
					vector.subtract(pos, vector.multiply(minetest.facedir_to_dir(node.param2), distance + 1))
 | 
					 | 
				
			||||||
				).name
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				digiline:receptor_send(pos, digiline.rules.default, channel, nodename)
 | 
					 | 
				
			||||||
				else
 | 
									else
 | 
				
			||||||
					meta:set_string("scanname", msg)
 | 
										meta:set_string("scanname", msg)
 | 
				
			||||||
					node_detector_make_formspec(pos)
 | 
										node_detector_make_formspec(pos)
 | 
				
			||||||
				end
 | 
									end
 | 
				
			||||||
 | 
								end
 | 
				
			||||||
		end,
 | 
							end,
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	receptor = {}
 | 
						receptor = {}
 | 
				
			||||||
 
 | 
				
			|||||||
| 
		 Before Width: | Height: | Size: 717 B After Width: | Height: | Size: 640 B  | 
| 
		 Before Width: | Height: | Size: 727 B After Width: | Height: | Size: 687 B  | 
| 
		 Before Width: | Height: | Size: 712 B After Width: | Height: | Size: 655 B  | 
| 
		 Before Width: | Height: | Size: 735 B After Width: | Height: | Size: 693 B  | 
| 
		 Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 36 KiB  | 
| 
		 Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 1.9 KiB  | 
| 
		 Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 58 KiB  | 
| 
		 Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 1.7 KiB  | 
| 
		 Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 28 KiB  | 
| 
		 Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 2.5 KiB  | 
| 
		 Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 47 KiB  | 
| 
		 Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 1.9 KiB  | 
| 
		 Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 11 KiB  | 
| 
		 Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 1.9 KiB  | 
| 
		 Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 20 KiB  | 
| 
		 Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.9 KiB  | 
| 
		 Before Width: | Height: | Size: 598 B After Width: | Height: | Size: 519 B  | 
| 
		 Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.7 KiB  | 
@@ -1,10 +1,11 @@
 | 
				
			|||||||
local plg = {}
 | 
					local plg = {}
 | 
				
			||||||
plg.rules = {}
 | 
					plg.rules = {}
 | 
				
			||||||
 | 
					-- per-player formspec positions
 | 
				
			||||||
 | 
					plg.open_formspecs = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local lcore = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/logic.lua")
 | 
					local lcore = dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/logic.lua")
 | 
				
			||||||
dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/tool.lua")(plg)
 | 
					dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/tool.lua")(plg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
plg.register_nodes = function(template)
 | 
					plg.register_nodes = function(template)
 | 
				
			||||||
	-- each loop is for one of the 4 IO ports
 | 
						-- each loop is for one of the 4 IO ports
 | 
				
			||||||
	for a = 0, 1 do
 | 
						for a = 0, 1 do
 | 
				
			||||||
@@ -93,16 +94,20 @@ plg.register_nodes({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		meta:set_string("instr", lcore.serialize(is))
 | 
							meta:set_string("instr", lcore.serialize(is))
 | 
				
			||||||
		meta:set_int("valid", 0)
 | 
							meta:set_int("valid", 0)
 | 
				
			||||||
		meta:set_string("formspec", plg.to_formspec_string(is))
 | 
					 | 
				
			||||||
		meta:set_string("infotext", "FPGA")
 | 
							meta:set_string("infotext", "FPGA")
 | 
				
			||||||
	end,
 | 
						end,
 | 
				
			||||||
	on_receive_fields = function(pos, formname, fields, sender)
 | 
						on_rightclick = function(pos, node, clicker)
 | 
				
			||||||
		if fields.program == nil then return end -- we only care when the user clicks "Program"
 | 
							if not minetest.is_player(clicker) then
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
		local meta = minetest.get_meta(pos)
 | 
							local meta = minetest.get_meta(pos)
 | 
				
			||||||
		local is = plg.from_formspec_fields(fields)
 | 
							local name = clicker:get_player_name()
 | 
				
			||||||
 | 
							-- Erase formspecs of old FPGAs
 | 
				
			||||||
 | 
							meta:set_string("formspec", "")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		meta:set_string("instr", lcore.serialize(is))
 | 
							plg.open_formspecs[name] = pos
 | 
				
			||||||
		plg.update_formspec(pos, is)
 | 
							local is = lcore.deserialize(meta:get_string("instr"))
 | 
				
			||||||
 | 
							minetest.show_formspec(name, "mesecons:fpga", plg.to_formspec_string(is, nil))
 | 
				
			||||||
	end,
 | 
						end,
 | 
				
			||||||
	sounds = default.node_sound_stone_defaults(),
 | 
						sounds = default.node_sound_stone_defaults(),
 | 
				
			||||||
	mesecons = {
 | 
						mesecons = {
 | 
				
			||||||
@@ -116,6 +121,12 @@ plg.register_nodes({
 | 
				
			|||||||
	},
 | 
						},
 | 
				
			||||||
	after_dig_node = function(pos, node)
 | 
						after_dig_node = function(pos, node)
 | 
				
			||||||
		mesecon.receptor_off(pos, plg.rules[node.name])
 | 
							mesecon.receptor_off(pos, plg.rules[node.name])
 | 
				
			||||||
 | 
							for name, open_pos in pairs(plg.open_formspecs) do
 | 
				
			||||||
 | 
								if vector.equals(pos, open_pos) then
 | 
				
			||||||
 | 
									minetest.close_formspec(name, "mesecons:fpga")
 | 
				
			||||||
 | 
									plg.open_formspecs[name] = nil
 | 
				
			||||||
 | 
								end
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
	end,
 | 
						end,
 | 
				
			||||||
	on_blast = mesecon.on_blastnode,
 | 
						on_blast = mesecon.on_blastnode,
 | 
				
			||||||
	on_rotate = function(pos, node, user, mode)
 | 
						on_rotate = function(pos, node, user, mode)
 | 
				
			||||||
@@ -153,13 +164,12 @@ plg.register_nodes({
 | 
				
			|||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		meta:set_string("instr", lcore.serialize(instr))
 | 
							meta:set_string("instr", lcore.serialize(instr))
 | 
				
			||||||
		plg.update_formspec(pos, instr)
 | 
							plg.update_meta(pos, instr)
 | 
				
			||||||
		return true
 | 
							return true
 | 
				
			||||||
	end,
 | 
						end,
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					plg.to_formspec_string = function(is, err)
 | 
				
			||||||
plg.to_formspec_string = function(is)
 | 
					 | 
				
			||||||
	local function dropdown_op(x, y, name, val)
 | 
						local function dropdown_op(x, y, name, val)
 | 
				
			||||||
		local s = "dropdown[" .. tostring(x) .. "," .. tostring(y) .. ";"
 | 
							local s = "dropdown[" .. tostring(x) .. "," .. tostring(y) .. ";"
 | 
				
			||||||
				.. "0.75,0.5;" .. name .. ";" -- the height seems to be ignored?
 | 
									.. "0.75,0.5;" .. name .. ";" -- the height seems to be ignored?
 | 
				
			||||||
@@ -180,26 +190,20 @@ plg.to_formspec_string = function(is)
 | 
				
			|||||||
		return s .. "]"
 | 
							return s .. "]"
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	local function dropdown_action(x, y, name, val)
 | 
						local function dropdown_action(x, y, name, val)
 | 
				
			||||||
		local s = "dropdown[" .. tostring(x) .. "," .. tostring(y) .. ";"
 | 
							local selected = 0
 | 
				
			||||||
				.. "1.125,0.5;" .. name .. ";" -- the height seems to be ignored?
 | 
							local titles = { " " }
 | 
				
			||||||
		s = s .. " , AND,  OR, NOT, XOR,NAND,   =,XNOR;"
 | 
							for i, data in ipairs(lcore.get_operations()) do
 | 
				
			||||||
		if val == nil then
 | 
								titles[i + 1] = data.fs_name
 | 
				
			||||||
			return s .. "0]" -- actually selects no field at all
 | 
								if val == data.gate then
 | 
				
			||||||
 | 
									selected = i + 1
 | 
				
			||||||
			end
 | 
								end
 | 
				
			||||||
		local mapping = {
 | 
							end
 | 
				
			||||||
			["and"] = 1,
 | 
							return ("dropdown[%f,%f;1.125,0.5;%s;%s;%i]"):format(
 | 
				
			||||||
			["or"] = 2,
 | 
								x, y, name, table.concat(titles, ","), selected)
 | 
				
			||||||
			["not"] = 3,
 | 
					 | 
				
			||||||
			["xor"] = 4,
 | 
					 | 
				
			||||||
			["nand"] = 5,
 | 
					 | 
				
			||||||
			["buf"] = 6,
 | 
					 | 
				
			||||||
			["xnor"] = 7,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return s .. tostring(1 + mapping[val]) .. "]"
 | 
					 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	local s = "size[9,9]"..
 | 
						local s = "size[9,9]"..
 | 
				
			||||||
		"label[3.4,-0.15;FPGA gate configuration]"..
 | 
							"label[3.4,-0.15;FPGA gate configuration]"..
 | 
				
			||||||
		"button_exit[7,7.5;2,2.5;program;Program]"..
 | 
							"button[7,7.5;2,2.5;program;Program]"..
 | 
				
			||||||
		"box[4.2,0.5;0.03,7;#ffffff]"..
 | 
							"box[4.2,0.5;0.03,7;#ffffff]"..
 | 
				
			||||||
		"label[0.25,0.25;op. 1]"..
 | 
							"label[0.25,0.25;op. 1]"..
 | 
				
			||||||
		"label[1.0,0.25;gate type]"..
 | 
							"label[1.0,0.25;gate type]"..
 | 
				
			||||||
@@ -225,6 +229,12 @@ plg.to_formspec_string = function(is)
 | 
				
			|||||||
			y = 1 - 0.25
 | 
								y = 1 - 0.25
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
						if err then
 | 
				
			||||||
 | 
							local fmsg = minetest.colorize("#ff0000", minetest.formspec_escape(err.msg))
 | 
				
			||||||
 | 
							s = s .. plg.red_box_around(err.i) ..
 | 
				
			||||||
 | 
								"label[0.25,8.25;The gate configuration is erroneous in the marked area:]"..
 | 
				
			||||||
 | 
								"label[0.25,8.5;" .. fmsg .. "]"
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
	return s
 | 
						return s
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -239,20 +249,11 @@ plg.from_formspec_fields = function(fields)
 | 
				
			|||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	local function read_action(s)
 | 
						local function read_action(s)
 | 
				
			||||||
		if s == nil or s == " " then
 | 
							for i, data in ipairs(lcore.get_operations()) do
 | 
				
			||||||
			return nil
 | 
								if data.fs_name == s then
 | 
				
			||||||
 | 
									return data.gate
 | 
				
			||||||
 | 
								end
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
		local mapping = {
 | 
					 | 
				
			||||||
			["AND"] = "and",
 | 
					 | 
				
			||||||
			["OR"] = "or",
 | 
					 | 
				
			||||||
			["NOT"] = "not",
 | 
					 | 
				
			||||||
			["XOR"] = "xor",
 | 
					 | 
				
			||||||
			["NAND"] = "nand",
 | 
					 | 
				
			||||||
			["="] = "buf",
 | 
					 | 
				
			||||||
			["XNOR"] = "xnor",
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		s = s:gsub("^%s*", "") -- remove leading spaces
 | 
					 | 
				
			||||||
		return mapping[s]
 | 
					 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	local is = {}
 | 
						local is = {}
 | 
				
			||||||
	for i = 1, 14 do
 | 
						for i = 1, 14 do
 | 
				
			||||||
@@ -266,12 +267,11 @@ plg.from_formspec_fields = function(fields)
 | 
				
			|||||||
	return is
 | 
						return is
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
plg.update_formspec = function(pos, is)
 | 
					plg.update_meta = function(pos, is)
 | 
				
			||||||
	if type(is) == "string" then -- serialized string
 | 
						if type(is) == "string" then -- serialized string
 | 
				
			||||||
		is = lcore.deserialize(is)
 | 
							is = lcore.deserialize(is)
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	local meta = minetest.get_meta(pos)
 | 
						local meta = minetest.get_meta(pos)
 | 
				
			||||||
	local form = plg.to_formspec_string(is)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local err = lcore.validate(is)
 | 
						local err = lcore.validate(is)
 | 
				
			||||||
	if err == nil then
 | 
						if err == nil then
 | 
				
			||||||
@@ -280,17 +280,20 @@ plg.update_formspec = function(pos, is)
 | 
				
			|||||||
	else
 | 
						else
 | 
				
			||||||
		meta:set_int("valid", 0)
 | 
							meta:set_int("valid", 0)
 | 
				
			||||||
		meta:set_string("infotext", "FPGA")
 | 
							meta:set_string("infotext", "FPGA")
 | 
				
			||||||
		local fmsg = minetest.colorize("#ff0000", minetest.formspec_escape(err.msg))
 | 
					 | 
				
			||||||
		form = form .. plg.red_box_around(err.i) ..
 | 
					 | 
				
			||||||
			"label[0.25,8.25;The gate configuration is erroneous in the marked area:]"..
 | 
					 | 
				
			||||||
			"label[0.25,8.5;" .. fmsg .. "]"
 | 
					 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	meta:set_string("formspec", form)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	-- reset ports and run programmed logic
 | 
						-- reset ports and run programmed logic
 | 
				
			||||||
	plg.setports(pos, false, false, false, false)
 | 
						plg.setports(pos, false, false, false, false)
 | 
				
			||||||
	plg.update(pos)
 | 
						plg.update(pos)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-- Refresh open formspecs
 | 
				
			||||||
 | 
						local form = plg.to_formspec_string(is, err)
 | 
				
			||||||
 | 
						for name, open_pos in pairs(plg.open_formspecs) do
 | 
				
			||||||
 | 
							if vector.equals(pos, open_pos) then
 | 
				
			||||||
 | 
								minetest.show_formspec(name, "mesecons:fpga", form)
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
plg.red_box_around = function(i)
 | 
					plg.red_box_around = function(i)
 | 
				
			||||||
@@ -409,6 +412,38 @@ plg.setports = function(pos, A, B, C, D) -- sets states of OUTPUT
 | 
				
			|||||||
	end
 | 
						end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					minetest.register_on_player_receive_fields(function(player, formname, fields)
 | 
				
			||||||
 | 
						local player_name = player:get_player_name()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if formname ~= "mesecons:fpga" or fields.quit then
 | 
				
			||||||
 | 
							plg.open_formspecs[player_name] = nil -- potential garbage
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						if not fields.program then
 | 
				
			||||||
 | 
							return -- we only care when the user clicks "Program"
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						local pos = plg.open_formspecs[player_name]
 | 
				
			||||||
 | 
						if minetest.is_protected(pos, player_name) then
 | 
				
			||||||
 | 
							minetest.record_protection_violation(pos, player_name)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						local meta = minetest.get_meta(pos)
 | 
				
			||||||
 | 
						local is = plg.from_formspec_fields(fields)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						meta:set_string("instr", lcore.serialize(is))
 | 
				
			||||||
 | 
						local err = plg.update_meta(pos, is)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if not err then
 | 
				
			||||||
 | 
							plg.open_formspecs[player_name] = nil
 | 
				
			||||||
 | 
							-- Close on success
 | 
				
			||||||
 | 
							minetest.close_formspec(player_name, "mesecons:fpga")
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					minetest.register_on_leaveplayer(function(player)
 | 
				
			||||||
 | 
						plg.open_formspecs[player:get_player_name()] = nil
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
minetest.register_craft({
 | 
					minetest.register_craft({
 | 
				
			||||||
	output = "mesecons_fpga:fpga0000 2",
 | 
						output = "mesecons_fpga:fpga0000 2",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,27 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
local lg = {}
 | 
					local lg = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local operations = {
 | 
				
			||||||
 | 
						-- table index: Index in the formspec dropdown
 | 
				
			||||||
 | 
						-- gate:    Internal name
 | 
				
			||||||
 | 
						-- short:   Serialized form, single character
 | 
				
			||||||
 | 
						-- fs_name: Display name, padded to 4 characters
 | 
				
			||||||
 | 
						-- func:    Function that applies the operation
 | 
				
			||||||
 | 
						-- unary:   Whether this gate only has one input
 | 
				
			||||||
 | 
						{ gate = "and",  short = "&", fs_name = " AND", func = function(a, b) return a and b end },
 | 
				
			||||||
 | 
						{ gate = "or",   short = "|", fs_name = "  OR", func = function(a, b) return a or b end },
 | 
				
			||||||
 | 
						{ gate = "not",  short = "~", fs_name = " NOT", func = function(a, b) return not b end, unary = true },
 | 
				
			||||||
 | 
						{ gate = "xor",  short = "^", fs_name = " XOR", func = function(a, b) return a ~= b end },
 | 
				
			||||||
 | 
						{ gate = "nand", short = "?", fs_name = "NAND", func = function(a, b) return not (a and b) end },
 | 
				
			||||||
 | 
						{ gate = "buf",  short = "_", fs_name = "   =", func = function(a, b) return b end, unary = true },
 | 
				
			||||||
 | 
						{ gate = "xnor", short = "=", fs_name = "XNOR", func = function(a, b) return a == b end },
 | 
				
			||||||
 | 
						{ gate = "nor",  short = "!", fs_name = " NOR", func = function(a, b) return not (a or b) end },
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					lg.get_operations = function()
 | 
				
			||||||
 | 
						return operations
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- (de)serialize
 | 
					-- (de)serialize
 | 
				
			||||||
lg.serialize = function(t)
 | 
					lg.serialize = function(t)
 | 
				
			||||||
	local function _op(t)
 | 
						local function _op(t)
 | 
				
			||||||
@@ -11,20 +33,14 @@ lg.serialize = function(t)
 | 
				
			|||||||
			return tostring(t.n)
 | 
								return tostring(t.n)
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	local function _action(s)
 | 
						-- Serialize actions (gates) from eg. "and" to "&"
 | 
				
			||||||
		if s == nil then
 | 
						local function _action(action)
 | 
				
			||||||
			return " "
 | 
							for i, data in ipairs(operations) do
 | 
				
			||||||
 | 
								if data.gate == action then
 | 
				
			||||||
 | 
									return data.short
 | 
				
			||||||
			end
 | 
								end
 | 
				
			||||||
		local mapping = {
 | 
							end
 | 
				
			||||||
			["and"] = "&",
 | 
							return " "
 | 
				
			||||||
			["or"] = "|",
 | 
					 | 
				
			||||||
			["not"] = "~",
 | 
					 | 
				
			||||||
			["xor"] = "^",
 | 
					 | 
				
			||||||
			["nand"] = "?", --dunno
 | 
					 | 
				
			||||||
			["buf"] = "_",
 | 
					 | 
				
			||||||
			["xnor"] = "=",
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return mapping[s]
 | 
					 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local s = ""
 | 
						local s = ""
 | 
				
			||||||
@@ -48,18 +64,14 @@ lg.deserialize = function(s)
 | 
				
			|||||||
			return {type = "reg", n = tonumber(c)}
 | 
								return {type = "reg", n = tonumber(c)}
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	local function _action(c)
 | 
						-- Deserialize actions (gates) from eg. "&" to "and"
 | 
				
			||||||
		local mapping = {
 | 
						local function _action(action)
 | 
				
			||||||
			["&"] = "and",
 | 
							for i, data in ipairs(operations) do
 | 
				
			||||||
			["|"] = "or",
 | 
								if data.short == action then
 | 
				
			||||||
			["~"] = "not",
 | 
									return data.gate
 | 
				
			||||||
			["^"] = "xor",
 | 
								end
 | 
				
			||||||
			["?"] = "nand",
 | 
							end
 | 
				
			||||||
			["_"] = "buf",
 | 
							-- nil
 | 
				
			||||||
			["="] = "xnor",
 | 
					 | 
				
			||||||
			[" "] = nil,
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return mapping[c]
 | 
					 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local ret = {}
 | 
						local ret = {}
 | 
				
			||||||
@@ -109,16 +121,25 @@ lg.validate_single = function(t, i)
 | 
				
			|||||||
		return false
 | 
							return false
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	local elem = t[i]
 | 
						local elem = t[i]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						local gate_data
 | 
				
			||||||
 | 
						for j, data in ipairs(operations) do
 | 
				
			||||||
 | 
							if data.gate == elem.action then
 | 
				
			||||||
 | 
								gate_data = data
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	-- check for completeness
 | 
						-- check for completeness
 | 
				
			||||||
	if elem.action == nil then
 | 
						if not gate_data then
 | 
				
			||||||
		return {i = i, msg = "Gate type required"}
 | 
							return {i = i, msg = "Gate type is required"}
 | 
				
			||||||
	elseif elem.action == "not" or elem.action == "buf" then
 | 
						elseif gate_data.unary then
 | 
				
			||||||
		if elem.op1 ~= nil or elem.op2 == nil or elem.dst == nil then
 | 
							if elem.op1 ~= nil or elem.op2 == nil or elem.dst == nil then
 | 
				
			||||||
			return {i = i, msg = "Second operand (only) and destination required"}
 | 
								return {i = i, msg = "Second operand (only) and destination are required"}
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		if elem.op1 == nil or elem.op2 == nil or elem.dst == nil then
 | 
							if elem.op1 == nil or elem.op2 == nil or elem.dst == nil then
 | 
				
			||||||
			return {i = i, msg = "Operands and destination required"}
 | 
								return {i = i, msg = "Operands and destination are required"}
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
	-- check whether operands/destination are identical
 | 
						-- check whether operands/destination are identical
 | 
				
			||||||
@@ -159,22 +180,13 @@ end
 | 
				
			|||||||
-- interpreter
 | 
					-- interpreter
 | 
				
			||||||
lg.interpret = function(t, a, b, c, d)
 | 
					lg.interpret = function(t, a, b, c, d)
 | 
				
			||||||
	local function _action(s, v1, v2)
 | 
						local function _action(s, v1, v2)
 | 
				
			||||||
		if s == "and" then
 | 
							for i, data in ipairs(operations) do
 | 
				
			||||||
			return v1 and v2
 | 
								if data.gate == s then
 | 
				
			||||||
		elseif s == "or" then
 | 
									return data.func(v1, v2)
 | 
				
			||||||
			return v1 or v2
 | 
					 | 
				
			||||||
		elseif s == "not" then
 | 
					 | 
				
			||||||
			return not v2
 | 
					 | 
				
			||||||
		elseif s == "xor" then
 | 
					 | 
				
			||||||
			return v1 ~= v2
 | 
					 | 
				
			||||||
		elseif s == "nand" then
 | 
					 | 
				
			||||||
			return not (v1 and v2)
 | 
					 | 
				
			||||||
		elseif s == "buf" then
 | 
					 | 
				
			||||||
			return v2
 | 
					 | 
				
			||||||
		else -- s == "xnor"
 | 
					 | 
				
			||||||
			return v1 == v2
 | 
					 | 
				
			||||||
			end
 | 
								end
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
							return false -- unknown gate
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
	local function _op(t, regs, io_in)
 | 
						local function _op(t, regs, io_in)
 | 
				
			||||||
		if t.type == "reg" then
 | 
							if t.type == "reg" then
 | 
				
			||||||
			return regs[t.n]
 | 
								return regs[t.n]
 | 
				
			||||||
 
 | 
				
			|||||||
| 
		 Before Width: | Height: | Size: 311 B After Width: | Height: | Size: 256 B  | 
| 
		 Before Width: | Height: | Size: 536 B After Width: | Height: | Size: 480 B  | 
| 
		 Before Width: | Height: | Size: 816 B After Width: | Height: | Size: 760 B  | 
@@ -34,17 +34,22 @@ minetest.register_tool("mesecons_fpga:programmer", {
 | 
				
			|||||||
		if minetest.get_node(pos).name:find("mesecons_fpga:fpga") ~= 1 then
 | 
							if minetest.get_node(pos).name:find("mesecons_fpga:fpga") ~= 1 then
 | 
				
			||||||
			return itemstack
 | 
								return itemstack
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
							local player_name = user:get_player_name()
 | 
				
			||||||
 | 
							if minetest.is_protected(pos, player_name) then
 | 
				
			||||||
 | 
								minetest.record_protection_violation(pos, player_name)
 | 
				
			||||||
 | 
								return itemstack
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local imeta = itemstack:get_metadata()
 | 
							local imeta = itemstack:get_metadata()
 | 
				
			||||||
		if imeta == "" then
 | 
							if imeta == "" then
 | 
				
			||||||
			minetest.chat_send_player(user:get_player_name(), "Use shift+right-click to copy a gate configuration first.")
 | 
								minetest.chat_send_player(player_name, "Use shift+right-click to copy a gate configuration first.")
 | 
				
			||||||
			return itemstack
 | 
								return itemstack
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local meta = minetest.get_meta(pos)
 | 
							local meta = minetest.get_meta(pos)
 | 
				
			||||||
		meta:set_string("instr", imeta)
 | 
							meta:set_string("instr", imeta)
 | 
				
			||||||
		plg.update_formspec(pos, imeta)
 | 
							plg.update_meta(pos, imeta)
 | 
				
			||||||
		minetest.chat_send_player(user:get_player_name(), "Gate configuration was successfully written to FPGA!")
 | 
							minetest.chat_send_player(player_name, "Gate configuration was successfully written to FPGA!")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return itemstack
 | 
							return itemstack
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 
 | 
				
			|||||||
| 
		 Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 52 KiB  | 
| 
		 Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 1.7 KiB  | 
| 
		 Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 54 KiB  | 
| 
		 Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.3 KiB  | 
| 
		 Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 47 KiB  | 
| 
		 Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 1.7 KiB  | 
| 
		 Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 21 KiB  | 
| 
		 Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.1 KiB  | 
| 
		 Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 53 KiB  | 
| 
		 Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.3 KiB  | 
| 
		 Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 21 KiB  | 
| 
		 Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.1 KiB  | 
| 
		 Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 53 KiB  | 
| 
		 Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 1.6 KiB  | 
| 
		 Before Width: | Height: | Size: 233 B After Width: | Height: | Size: 123 B  | 
| 
		 Before Width: | Height: | Size: 231 B After Width: | Height: | Size: 128 B  | 
| 
		 Before Width: | Height: | Size: 251 B After Width: | Height: | Size: 127 B  | 
| 
		 Before Width: | Height: | Size: 251 B After Width: | Height: | Size: 127 B  | 
| 
		 Before Width: | Height: | Size: 241 B After Width: | Height: | Size: 128 B  | 
| 
		 Before Width: | Height: | Size: 195 B After Width: | Height: | Size: 84 B  | 
| 
		 Before Width: | Height: | Size: 195 B After Width: | Height: | Size: 84 B  | 
| 
		 Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 127 B  | 
| 
		 Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 128 B  | 
| 
		 Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 32 KiB  | 
| 
		 Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 7.0 KiB  | 
| 
		 Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.7 KiB  | 
| 
		 Before Width: | Height: | Size: 782 B After Width: | Height: | Size: 776 B  | 
| 
		 Before Width: | Height: | Size: 758 B After Width: | Height: | Size: 754 B  | 
| 
		 Before Width: | Height: | Size: 820 B After Width: | Height: | Size: 729 B  | 
| 
		 Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 1.7 KiB  |