summaryrefslogtreecommitdiff
path: root/trafficlight
diff options
context:
space:
mode:
authorChristian Danscheid <Christian_D_97@gmx.de>2013-08-13 18:03:48 +0200
committerChristian Danscheid <Christian_D_97@gmx.de>2013-08-13 18:03:48 +0200
commitfd7efeb54dcff7f290ce29521e808c4111cb12a8 (patch)
tree60571b980643a1f6f112c8fff1c9a9e5eac85851 /trafficlight
parent98294097b64f5187bdf4e9af7942fa1f49540343 (diff)
downloadroads-fd7efeb54dcff7f290ce29521e808c4111cb12a8.tar
roads-fd7efeb54dcff7f290ce29521e808c4111cb12a8.tar.gz
roads-fd7efeb54dcff7f290ce29521e808c4111cb12a8.tar.bz2
roads-fd7efeb54dcff7f290ce29521e808c4111cb12a8.tar.xz
roads-fd7efeb54dcff7f290ce29521e808c4111cb12a8.zip
Added trafficlight code and basic textures
Diffstat (limited to 'trafficlight')
-rw-r--r--trafficlight/init.lua140
-rw-r--r--trafficlight/textures/streets_tl_bg.pngbin0 -> 3513 bytes
-rw-r--r--trafficlight/textures/streets_tl_green.pngbin0 -> 3290 bytes
-rw-r--r--trafficlight/textures/streets_tl_off.pngbin0 -> 3267 bytes
-rw-r--r--trafficlight/textures/streets_tl_red.pngbin0 -> 3295 bytes
-rw-r--r--trafficlight/textures/streets_tl_redyellow.pngbin0 -> 3318 bytes
-rw-r--r--trafficlight/textures/streets_tl_warn.pngbin0 -> 3699 bytes
-rw-r--r--trafficlight/textures/streets_tl_yellow.pngbin0 -> 3295 bytes
8 files changed, 134 insertions, 6 deletions
diff --git a/trafficlight/init.lua b/trafficlight/init.lua
index bec4410..a915b0e 100644
--- a/trafficlight/init.lua
+++ b/trafficlight/init.lua
@@ -5,12 +5,15 @@ minetest.register_node(":streets:trafficlight_bottom",{
description = "Trafficlight",
groups = {cracky = 1},
paramtype = "light",
+ paramtype2 = "facedir",
drawtype = "nodebox",
+ sunlight_propagates = true,
+ tiles = {"streets_pole.png"},
node_box = {
type = "fixed",
fixed = {
- {-0.25,-0.5,-0.25,0.25,0.25,0.25},
- {-0.2,0.25,-0.2,0.2,0.5,0.2}
+ {-0.15,-0.5,-0.15,0.15,0.25,0.15},
+ {-0.1,0.25,-0.1,0.1,0.5,0.1}
}
},
selection_box = {
@@ -20,11 +23,12 @@ minetest.register_node(":streets:trafficlight_bottom",{
}
},
after_place_node = function(pos,placer,itemstack)
+ local facedir = minetest.get_node(pos).param2
if minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z}).name == "air" and minetest.get_node({x = pos.x, y = pos.y + 2, z = pos.z}).name == "air" then
pos.y = pos.y + 1
minetest.set_node(pos,{name="streets:trafficlight_middle"})
pos.y = pos.y + 1
- minetest.set_node(pos,{name="streets:trafficlight_top"})
+ minetest.set_node(pos,{name="streets:trafficlight_top_off",param2=facedir})
else
minetest.chat_send_player(placer:get_player_name(),"Not enough vertical space! The traffic light has a height of 3 blocks.")
minetest.remove_node(pos)
@@ -33,6 +37,7 @@ minetest.register_node(":streets:trafficlight_bottom",{
pos.y = pos.y - 2
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "field[channel;Channel;${channel}]")
+ meta:set_string("infotext", "Off")
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
pos.y = pos.y + 1
@@ -49,7 +54,37 @@ minetest.register_node(":streets:trafficlight_bottom",{
action = function(pos,node,channel,msg)
local setchannel = minetest.get_meta(pos):get_string("channel")
if channel == setchannel then
- -- Trafficlight code goes here
+ -- Set a meta entry for the trafficlight's state
+ local meta = minetest.get_meta(pos)
+ local state = meta:get_string("infotext")
+ if msg == "green" or msg == "red" or msg == "warn" or msg == "off" then
+ meta:set_string("infotext",msg)
+ local facedir = minetest.get_node(pos).param2
+ -- Modify <pos> to the top node of the trafficlight
+ pos.y = pos.y + 2
+ --
+ if msg == "red" then
+ minetest.set_node(pos,{name = "streets:trafficlight_top_yellow",param2=facedir})
+ minetest.after(3,function(param)
+ minetest.set_node(pos,{name = "streets:trafficlight_top_red",param2=facedir})
+ end)
+ end
+ --
+ if msg == "green" then
+ minetest.set_node(pos,{name = "streets:trafficlight_top_redyellow",param2=facedir})
+ minetest.after(3,function(param)
+ minetest.set_node(pos,{name = "streets:trafficlight_top_green",param2=facedir})
+ end)
+ end
+ --
+ if msg == "off" then
+ minetest.set_node(pos,{name = "streets:trafficlight_top_off",param2=facedir})
+ end
+ --
+ if msg == "warn" then
+ minetest.set_node(pos,{name = "streets:trafficlight_top_warn",param2=facedir})
+ end
+ end
end
end
}
@@ -61,20 +96,113 @@ minetest.register_node(":streets:trafficlight_middle",{
groups = {cracky = 1, not_in_creative_inventory = 1},
paramtype = "light",
drawtype = "nodebox",
+ sunlight_propagates = true,
+ tiles = {"streets_pole.png"},
node_box = {
type = "fixed",
fixed = {
- {-0.2,-0.5,-0.2,0.2,0.5,0.2}
+ {-0.1,-0.5,-0.1,0.1,0.5,0.1},
}
},
pointable = false,
})
-minetest.register_node(":streets:trafficlight_top",{
+minetest.register_node(":streets:trafficlight_top_off",{
description = "U cheater U",
groups = {cracky = 1, not_in_creative_inventory = 1},
paramtype = "light",
+ paramtype2 = "facedir",
+ sunlight_propagates = true,
drawtype = "nodebox",
+ tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_off.png"},
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.25,-0.5,-0.25,0.25,0.5,0.25}
+ }
+ },
+ pointable = false,
+})
+
+minetest.register_node(":streets:trafficlight_top_red",{
+ description = "U cheater U",
+ groups = {cracky = 1, not_in_creative_inventory = 1},
+ paramtype = "light",
+ paramtype2 = "facedir",
+ sunlight_propagates = true,
+ drawtype = "nodebox",
+ tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_red.png"},
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.25,-0.5,-0.25,0.25,0.5,0.25}
+ }
+ },
+ pointable = false,
+})
+
+minetest.register_node(":streets:trafficlight_top_yellow",{
+ description = "U cheater U",
+ groups = {cracky = 1, not_in_creative_inventory = 1},
+ paramtype = "light",
+ paramtype2 = "facedir",
+ sunlight_propagates = true,
+ drawtype = "nodebox",
+ tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_yellow.png"},
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.25,-0.5,-0.25,0.25,0.5,0.25}
+ }
+ },
+ pointable = false,
+})
+
+minetest.register_node(":streets:trafficlight_top_redyellow",{
+ description = "U cheater U",
+ groups = {cracky = 1, not_in_creative_inventory = 1},
+ paramtype = "light",
+ paramtype2 = "facedir",
+ sunlight_propagates = true,
+ drawtype = "nodebox",
+ tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_redyellow.png"},
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.25,-0.5,-0.25,0.25,0.5,0.25}
+ }
+ },
+ pointable = false,
+})
+
+minetest.register_node(":streets:trafficlight_top_green",{
+ description = "U cheater U",
+ groups = {cracky = 1, not_in_creative_inventory = 1},
+ paramtype = "light",
+ paramtype2 = "facedir",
+ sunlight_propagates = true,
+ drawtype = "nodebox",
+ tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_green.png"},
+ node_box = {
+ type = "fixed",
+ fixed = {
+ {-0.25,-0.5,-0.25,0.25,0.5,0.25}
+ }
+ },
+ pointable = false,
+})
+
+minetest.register_node(":streets:trafficlight_top_warn",{
+ description = "U cheater U",
+ groups = {cracky = 1, not_in_creative_inventory = 1},
+ paramtype = "light",
+ paramtype2 = "facedir",
+ sunlight_propagates = true,
+ drawtype = "nodebox",
+ tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png",{
+ name="streets_tl_warn.png",
+ animation={type="vertical_frames", aspect_w=64, aspect_h=64, length=1.5},
+ }},
node_box = {
type = "fixed",
fixed = {
diff --git a/trafficlight/textures/streets_tl_bg.png b/trafficlight/textures/streets_tl_bg.png
new file mode 100644
index 0000000..f0bba98
--- /dev/null
+++ b/trafficlight/textures/streets_tl_bg.png
Binary files differ
diff --git a/trafficlight/textures/streets_tl_green.png b/trafficlight/textures/streets_tl_green.png
new file mode 100644
index 0000000..014b118
--- /dev/null
+++ b/trafficlight/textures/streets_tl_green.png
Binary files differ
diff --git a/trafficlight/textures/streets_tl_off.png b/trafficlight/textures/streets_tl_off.png
new file mode 100644
index 0000000..16621e7
--- /dev/null
+++ b/trafficlight/textures/streets_tl_off.png
Binary files differ
diff --git a/trafficlight/textures/streets_tl_red.png b/trafficlight/textures/streets_tl_red.png
new file mode 100644
index 0000000..2481a86
--- /dev/null
+++ b/trafficlight/textures/streets_tl_red.png
Binary files differ
diff --git a/trafficlight/textures/streets_tl_redyellow.png b/trafficlight/textures/streets_tl_redyellow.png
new file mode 100644
index 0000000..0a85622
--- /dev/null
+++ b/trafficlight/textures/streets_tl_redyellow.png
Binary files differ
diff --git a/trafficlight/textures/streets_tl_warn.png b/trafficlight/textures/streets_tl_warn.png
new file mode 100644
index 0000000..8b4da58
--- /dev/null
+++ b/trafficlight/textures/streets_tl_warn.png
Binary files differ
diff --git a/trafficlight/textures/streets_tl_yellow.png b/trafficlight/textures/streets_tl_yellow.png
new file mode 100644
index 0000000..3666cae
--- /dev/null
+++ b/trafficlight/textures/streets_tl_yellow.png
Binary files differ