aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_luaautomation')
-rw-r--r--advtrains_luaautomation/README.md36
-rw-r--r--advtrains_luaautomation/active_common.lua32
-rwxr-xr-x[-rw-r--r--]advtrains_luaautomation/atc_rail.lua41
-rw-r--r--advtrains_luaautomation/environment.lua19
-rw-r--r--advtrains_luaautomation/init.lua11
-rw-r--r--advtrains_luaautomation/mesecon_controller.lua260
-rwxr-xr-x[-rw-r--r--]advtrains_luaautomation/operation_panel.lua7
-rw-r--r--advtrains_luaautomation/pcnaming.lua15
-rw-r--r--advtrains_luaautomation/textures/atlatc_luacontroller_LED_A.pngbin0 -> 2196 bytes
-rw-r--r--advtrains_luaautomation/textures/atlatc_luacontroller_LED_B.pngbin0 -> 2188 bytes
-rw-r--r--advtrains_luaautomation/textures/atlatc_luacontroller_LED_C.pngbin0 -> 2191 bytes
-rw-r--r--advtrains_luaautomation/textures/atlatc_luacontroller_LED_D.pngbin0 -> 2200 bytes
-rw-r--r--advtrains_luaautomation/textures/atlatc_luacontroller_bottom.pngbin0 -> 222 bytes
-rw-r--r--advtrains_luaautomation/textures/atlatc_luacontroller_sides.pngbin0 -> 504 bytes
-rw-r--r--advtrains_luaautomation/textures/atlatc_luacontroller_top.pngbin0 -> 8440 bytes
15 files changed, 380 insertions, 41 deletions
diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md
index 683e45c..a885075 100644
--- a/advtrains_luaautomation/README.md
+++ b/advtrains_luaautomation/README.md
@@ -255,15 +255,32 @@ In addition to the above environment functions, the following functions are avai
The interlocking system uses this property for Automatic Routesetting.
#### Shunting Functions and Variables
-There are several functions available especially for shunting operations. Some of these functions make use of Freight Codes (FC) set in the Wagon Properties of each wagon and/or locomotive:
+There are several functions available especially for shunting operations.
+Some of these functions make use of Freight Codes (FC) set in the Wagon Properties of each wagon and/or locomotive.
+FCs are composed of codes separated by exclamation marks (`!`), for instance `"foo!bar!baz"`.
+Each wagon has a current FC, indicating its next destination.
- `split_at_index(index, atc_command)`
Splits the train at the specified index, into a train with index-1 wagons and a second train starting with the index-th wagon. The `atc_command` specified is sent to the second train after decoupling. `"S0"` or `"B0"` is common to ensure any locomotives in the remaining train don't continue to move.
+ `index` must be more than 1 to avoid trying to decouple the very front of a train.
+
Example: train has wagons `"foo","foo","foo","bar","bar","bar"`
Command: `split_at_index(4,"S0")`
Result: first train (continues at previous speed): `"foo","foo","foo"`, second train (slows at S0): `"bar","bar","bar"`
+ - `get_fc()`
+ Returns a table with the entire FC list for each wagon in the train.
+ Command: `get_fc()`
+ Result: `{"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"}`
+
+ - `set_fc(fc_list)`
+ Overwrites the FC list according to a table `fc_list`. A false or nil entry will leave the wagon unaffected, however all others will be overwritten.
+ Useful for mass-programming freight trains that use FC-shunting instead of walking to each wagon individually.
+ Example: train has FC lists: `"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"`
+ Command: `set_fc({"", "foo!turtle", nil, "4tehlulz", false})`
+ Result: `""` `"foo!turtle"` `"testing"` `"4tehlulz"` `"hello_world"`
+
- `split_at_fc(atc_command, len)`
Splits the train in such a way that all cars with non-empty current FC of the first part of the train have the same FC. The
`atc_command` specified is sent to the rear part, as with split_at_index. It returns the fc of the cars of the first part.
@@ -287,15 +304,11 @@ There are several functions available especially for shunting operations. Some o
first part of the train as above.
- `step_fc()`
- Steps the FCs of all train cars forward. FCs are composed of codes
- separated by exclamation marks (`!`), for instance
- `"foo!bar!baz"`. Each wagon has a current FC, indicating its next
- destination. Stepping the freight code forward, selects the next
- code after the !. If the end of the string is reached, then the
+ Steps the FCs of all train cars forward, selecting the next
+ code after the `!`. If the end of the string is reached, then the
first code is selected, except if the string ends with a question
mark (`?`), then the order is reversed.
-
- `train_length()`
returns the number of cars the train is composed of.
@@ -312,13 +325,16 @@ Deprecated:
#### Interlocking
-This additional function is available when advtrains_interlocking is enabled:
+These additional functions are available when advtrains_interlocking is enabled:
- - `atc_set_disable_ars(boolean)`
+ - `atc_set_ars_disable(boolean)`
Disables (true) or enables (false) the use of ARS for this train. The train will not trigger ARS (automatic route setting) on signals then.
- Note: If you want to disable ARS from an approach callback, the call to `atc_set_disable_ars(true)` *must* happen during the approach callback, and may not be deferred to an interrupt(). Else the train might trigger an ARS before the interrupt fires.
+ Note: If you want to disable ARS from an approach callback, the call to `atc_set_ars_disable(true)` *must* happen during the approach callback, and may not be deferred to an interrupt(). Else the train might trigger an ARS before the interrupt fires.
+ - `section_occupancy(section_id)`
+ Returns a table of train ids for the specified section, nil if no section id is provided, false if the section id is invalid, an empty table if the section id is valid but empty of trains.
+
#### Approach callbacks
The LuaATC interface provides a way to hook into the approach callback system, which is for example used in the TSR rails (provided by advtrains_interlocking) or the station tracks (provided by advtrains_lines). However, for compatibility reasons, this behavior needs to be explicitly enabled.
diff --git a/advtrains_luaautomation/active_common.lua b/advtrains_luaautomation/active_common.lua
index 9bf8377..1a7009f 100644
--- a/advtrains_luaautomation/active_common.lua
+++ b/advtrains_luaautomation/active_common.lua
@@ -1,4 +1,4 @@
-
+local S = atltrans
local ac = {nodes={}}
@@ -14,7 +14,7 @@ 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.")
+ meta:set_string("infotext", S("Unconfigured LuaATC component"))
local ph=minetest.pos_to_string(pos)
--just get first available key!
for en,_ in pairs(atlatc.envs) do
@@ -43,12 +43,12 @@ function ac.getform(pos, meta_p)
end
local form = "size["..atlatc.CODE_FORM_SIZE.."]"
.."style[code;font=mono]"
- .."label[0,-0.1;Environment]"
+ .."label[0,-0.1;"..S("LuaATC Environment").."]"
.."dropdown[0,0.3;3;env;"..table.concat(envs_asvalues, ",")..";"..sel.."]"
- .."button[5,0.2;2,1;save;Save]"
- .."button[7,0.2;3,1;cle;Clear Local Env.]"
- .."textarea[0.3,1.5;"..atlatc.CODE_FORM_SIZE..";code;Code;"..minetest.formspec_escape(code).."]"
- .."label[0,9.7;"..err.."]"
+ .."button[5,0.2;2,1;save;"..S("Save").."]"
+ .."button[7,0.2;3,1;cle;"..S("Clear Local Environment").."]"
+ .."textarea[0.3,1.5;"..atlatc.CODE_FORM_SIZE..";code;"..S("Code")..";"..minetest.formspec_escape(code).."]"
+ .."label["..atlatc.CODE_FORM_ERRLABELPOS..";"..err.."]"
return form
end
@@ -61,7 +61,7 @@ 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!")
+ minetest.chat_send_player(player:get_player_name(), S("You are not allowed to configure this LuaATC component without the @1 privilege.", "atlatc"))
return
end
@@ -91,17 +91,17 @@ function ac.on_receive_fields(pos, formname, fields, player)
meta:set_string("formspec", ac.getform(pos, meta))
if nodetbl.env then
- meta:set_string("infotext", "LuaAutomation component, assigned to environment '"..nodetbl.env.."'")
+ meta:set_string("infotext", S("LuaATC component assigned to environment '@1'", nodetbl.env))
else
- meta:set_string("infotext", "LuaAutomation component, invalid enviroment set!")
+ meta:set_string("infotext", S("LuaATC component assigned to an invalid environment"))
end
end
-function ac.run_in_env(pos, evtdata, customfct_p)
+function ac.run_in_env(pos, evtdata, customfct_p, ignore_no_code)
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'!")
+ atwarn("LuaATC component at",ph,": Data not in memory! Please visit component and click 'Save'!")
return
end
@@ -111,12 +111,14 @@ function ac.run_in_env(pos, evtdata, customfct_p)
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>"))
+ atwarn("LuaATC component at",ph,": Not an existing environment: "..(nodetbl.env or "<nil>"))
return false
end
local env = atlatc.envs[nodetbl.env]
if not nodetbl.code or nodetbl.code=="" then
- env:log("warning", "LuaAutomation component at",ph,": No code to run! (insert -- to suppress warning)")
+ if not ignore_no_code then
+ env:log("warning", "LuaATC component at",ph,": No code to run! (insert -- to suppress warning)")
+ end
return false
end
@@ -166,7 +168,7 @@ function ac.run_in_env(pos, evtdata, customfct_p)
atlatc.active.nodes[ph].err=dataout
env:log("error", "LuaATC component at",ph,": LUA Error:",dataout)
if meta then
- meta:set_string("infotext", "LuaATC component, ERROR:"..dataout)
+ meta:set_string("infotext", S("LuaATC component with error: @1", dataout))
end
--TODO temporary
--if customfct.atc_id then
diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua
index b862129..f069600 100644..100755
--- a/advtrains_luaautomation/atc_rail.lua
+++ b/advtrains_luaautomation/atc_rail.lua
@@ -14,7 +14,7 @@ function r.fire_event(pos, evtdata, appr_internal)
local railtbl = atlatc.active.nodes[ph]
if not railtbl then
- atwarn("LuaAutomation ATC interface rail at",ph,": Data not in memory! Please visit position and click 'Save'!")
+ atwarn("LuaATC interface rail at",ph,": Data not in memory! Please visit position and click 'Save'!")
return
end
@@ -56,7 +56,7 @@ function r.fire_event(pos, evtdata, appr_internal)
split_at_index = function(index, cmd)
if not train_id then return false end
assertt(cmd, "string")
- if type(index) ~= "number" then
+ if type(index) ~= "number" or index < 2 then
return false
end
local new_id = advtrains.split_train_at_index(train, index)
@@ -91,6 +91,38 @@ function r.fire_event(pos, evtdata, appr_internal)
if not train_id then return false end
advtrains.train_step_fc(train)
end,
+ get_fc = function()
+ if not train_id then return end
+ local fc_list = {}
+ for index,wagon_id in ipairs(train.trainparts) do
+ fc_list[index] = table.concat(advtrains.wagons[wagon_id].fc,"!") or ""
+ end
+ return fc_list
+ end,
+ set_fc = function(fc_list)
+ assertt(fc_list, "table")
+ if not train_id then return false end
+ -- safety type-check for entered values
+ for _,v in ipairs(fc_list) do
+ if v and type(v) ~= "string" then
+ error("FC entries must be a string")
+ return
+ end
+ end
+ for index,wagon_id in ipairs(train.trainparts) do
+ if fc_list[index] then -- has FC to enter to this wagon
+ local data = advtrains.wagons[wagon_id]
+ if data then -- wagon actually exists
+ for _,wagon in pairs(minetest.luaentities) do -- find wagon entity
+ if wagon.is_wagon and wagon.initialized and wagon.id==wagon_id then
+ wagon.set_fc(data,fc_list[index]) -- overwrite to new FC
+ break -- no point cycling through every other entity. we found our wagon
+ end
+ end
+ end
+ end
+ end
+ end,
set_shunt = function()
-- enable shunting mode
if not train_id then return false end
@@ -130,9 +162,8 @@ function r.fire_event(pos, evtdata, appr_internal)
get_rc = function()
return train.routingcode
end,
- atc_reset = function(cmd)
+ atc_reset = function()
if not train_id then return false end
- assertt(cmd, "string")
advtrains.atc.train_reset_command(train)
return true
end,
@@ -188,7 +219,7 @@ advtrains.register_tracks("default", {
models_prefix="advtrains_dtrack",
models_suffix=".b3d",
shared_texture="advtrains_dtrack_shared_atc.png",
- description=atltrans("LuaAutomation ATC Rail"),
+ description=atltrans("LuaATC Track"),
formats={},
get_additional_definiton = function(def, preset, suffix, rotation)
return {
diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua
index 63aa68d..6df5248 100644
--- a/advtrains_luaautomation/environment.lua
+++ b/advtrains_luaautomation/environment.lua
@@ -150,7 +150,7 @@ local static_env = {
--interrupts are handled per node, position unknown. (same goes for digilines)
--however external interrupts can be set here.
interrupt_pos = function(parpos, imesg)
- local pos=atlatc.pcnaming.resolve_pos(parpos)
+ local pos=atlatc.pcnaming.resolve_pos(parpos, "interrupt_pos")
atlatc.interrupt.add(0, pos, {type="ext_int", ext_int=true, message=imesg})
end,
-- sends an atc command to train regardless of where it is in the world
@@ -164,6 +164,9 @@ local static_env = {
return false
end
end,
+ get_slowdown = function()
+ return advtrains.global_slowdown
+ end
}
-- If interlocking is present, enable route setting functions
@@ -223,6 +226,15 @@ if advtrains.interlocking then
local pos = atlatc.pcnaming.resolve_pos(signal)
return advtrains.interlocking.signal_set_aspect(pos)
end
+
+ --section_occupancy()
+ static_env.section_occupancy = function(ts_id)
+ if not ts_id then return nil end
+ ts_id = tostring(ts_id)
+ local response = advtrains.interlocking.db.get_ts(ts_id)
+ if not response then return false end
+ return table.copy(response.trains)
+ end
end
-- Lines-specific:
@@ -250,6 +262,11 @@ if advtrains.lines then
}
end
+
+atlatc.register_function = function (name, f)
+ static_env[name] = f
+end
+
for _, name in pairs(safe_globals) do
static_env[name] = _G[name]
end
diff --git a/advtrains_luaautomation/init.lua b/advtrains_luaautomation/init.lua
index ab625b1..b359142 100644
--- a/advtrains_luaautomation/init.lua
+++ b/advtrains_luaautomation/init.lua
@@ -2,18 +2,20 @@
-- Lua automation features for advtrains
-- Uses global table 'atlatc' (AdvTrains_LuaATC)
---TODO: re-add localization (if merging localization, discard this hunk please)
-atltrans = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
+atltrans = attrans
+local S = atltrans
--Privilege
--Only trusted players should be enabled to build stuff which can break the server.
atlatc = { envs = {}}
-minetest.register_privilege("atlatc", { description = "Player can place and modify LUA ATC components. Grant with care! Allows to execute bad LUA code.", give_to_singleplayer = false, default= false })
+minetest.register_privilege("atlatc", { description = S("Can place and configure LuaATC components, including execute potentially harmful Lua code"), give_to_singleplayer = false, default= false })
--Size of code input forms in X,Y notation. Must be at least 10x10
atlatc.CODE_FORM_SIZE = "15,12"
+--Position of Error Label in Code Form
+atlatc.CODE_FORM_ERRLABELPOS = "0,12"
--assertt helper. error if a variable is not of a type
function assertt(var, typ)
@@ -31,6 +33,9 @@ dofile(mp.."/interrupt.lua")
dofile(mp.."/active_common.lua")
dofile(mp.."/atc_rail.lua")
dofile(mp.."/operation_panel.lua")
+if mesecon then
+ dofile(mp.."/mesecon_controller.lua")
+end
dofile(mp.."/pcnaming.lua")
dofile(mp.."/chatcmds.lua")
diff --git a/advtrains_luaautomation/mesecon_controller.lua b/advtrains_luaautomation/mesecon_controller.lua
new file mode 100644
index 0000000..6981839
--- /dev/null
+++ b/advtrains_luaautomation/mesecon_controller.lua
@@ -0,0 +1,260 @@
+-- mesecon_controller.lua
+-- Mesecon-interfaceable Operation Panel alternative
+-- Looks like a Mesecon Luacontroller
+
+-- Luacontroller Adapted Code
+-- From Mesecons mod https://mesecons.net/
+-- (c) Jeija and Contributors
+
+local S = atltrans
+local BASENAME = "advtrains_luaautomation:mesecon_controller"
+
+local rules = {
+ a = {x = -1, y = 0, z = 0, name="A"},
+ b = {x = 0, y = 0, z = 1, name="B"},
+ c = {x = 1, y = 0, z = 0, name="C"},
+ d = {x = 0, y = 0, z = -1, name="D"},
+}
+
+local function generate_name(ports)
+ local d = ports.d and 1 or 0
+ local c = ports.c and 1 or 0
+ local b = ports.b and 1 or 0
+ local a = ports.a and 1 or 0
+ return BASENAME..d..c..b..a
+end
+
+
+local function set_port(pos, rule, state)
+ if state then
+ mesecon.receptor_on(pos, {rule})
+ else
+ mesecon.receptor_off(pos, {rule})
+ end
+end
+
+local function clean_port_states(ports)
+ ports.a = ports.a and true or false
+ ports.b = ports.b and true or false
+ ports.c = ports.c and true or false
+ ports.d = ports.d and true or false
+end
+
+-- Local table for storing which Mesecons off events should be ignored
+-- Indexed by hex encoded position
+local ignored_off_events = {}
+
+local function set_port_states(pos, ports)
+ local node = advtrains.ndb.get_node(pos)
+ local name = node.name
+ clean_port_states(ports)
+ local vports = minetest.registered_nodes[name].virtual_portstates
+ local new_name = generate_name(ports)
+
+ if name ~= new_name and vports then
+ -- Problem:
+ -- We need to place the new node first so that when turning
+ -- off some port, it won't stay on because the rules indicate
+ -- there is an onstate output port there.
+ -- When turning the output off then, it will however cause feedback
+ -- so that the luacontroller will receive an "off" event by turning
+ -- its output off.
+ -- Solution / Workaround:
+ -- Remember which output was turned off and ignore next "off" event.
+ local ph=minetest.pos_to_string(pos)
+ local railtbl = atlatc.active.nodes[ph]
+ if not railtbl then return end
+
+ local ign = railtbl.ignored_off_events or {}
+ if ports.a and not vports.a and not mesecon.is_powered(pos, rules.a) then ign.A = true end
+ if ports.b and not vports.b and not mesecon.is_powered(pos, rules.b) then ign.B = true end
+ if ports.c and not vports.c and not mesecon.is_powered(pos, rules.c) then ign.C = true end
+ if ports.d and not vports.d and not mesecon.is_powered(pos, rules.d) then ign.D = true end
+ railtbl.ignored_off_events = ign
+
+ advtrains.ndb.swap_node(pos, {name = new_name, param2 = node.param2})
+
+ -- Apply mesecon state only if node loaded
+ -- If node is not loaded, mesecon update will occur on next load via on_updated_from_nodedb
+ if advtrains.is_node_loaded(pos) then
+ if ports.a ~= vports.a then set_port(pos, rules.a, ports.a) end
+ if ports.b ~= vports.b then set_port(pos, rules.b, ports.b) end
+ if ports.c ~= vports.c then set_port(pos, rules.c, ports.c) end
+ if ports.d ~= vports.d then set_port(pos, rules.d, ports.d) end
+ end
+ end
+end
+
+local function on_updated_from_nodedb(pos, newnode, oldnode)
+ -- Switch appropriate Mesecon receptors depending on the node change
+ local vports = minetest.registered_nodes[oldnode.name].virtual_portstates
+ local ports = minetest.registered_nodes[newnode.name].virtual_portstates
+ if ports.a ~= vports.a then set_port(pos, rules.a, ports.a) end
+ if ports.b ~= vports.b then set_port(pos, rules.b, ports.b) end
+ if ports.c ~= vports.c then set_port(pos, rules.c, ports.c) end
+ if ports.d ~= vports.d then set_port(pos, rules.d, ports.d) end
+end
+
+local function ignore_offevent(pos, rule)
+ local ph=minetest.pos_to_string(pos)
+ local railtbl = atlatc.active.nodes[ph]
+ if not railtbl then return nil end
+ local ign = railtbl.ignored_off_events
+ if ign and ign[rule.name] then
+ ign[rule.name] = nil
+ return true
+ end
+ return false
+end
+
+local valid_ports = {a=true, b=true, c=true, d=true}
+
+local function fire_event(pos, evtdata)
+ local customfct={
+ set_mesecon_outputs = function(states)
+ assertt(states, "table")
+ set_port_states(pos, states)
+ end,
+ get_mesecon_input = function(port)
+ local portl = string.lower(port)
+ if not valid_ports[portl] then
+ error("get_mesecon_input: Invalid port (expected a,b,c,d)")
+ end
+ if mesecon.is_powered(pos, rules[portl]) then
+ return true
+ end
+ return false
+ end,
+ }
+ atlatc.active.run_in_env(pos, evtdata, customfct, true)
+
+end
+
+local output_rules = {}
+local input_rules = {}
+
+local node_box = {
+ type = "fixed",
+ fixed = {
+ {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}, -- Bottom slab
+ {-5/16, -7/16, -5/16, 5/16, -6/16, 5/16}, -- Circuit board
+ {-3/16, -6/16, -3/16, 3/16, -5/16, 3/16}, -- IC
+ }
+}
+
+local selection_box = {
+ type = "fixed",
+ fixed = { -8/16, -8/16, -8/16, 8/16, -5/16, 8/16 },
+}
+
+for a = 0, 1 do -- 0 = off 1 = on
+for b = 0, 1 do
+for c = 0, 1 do
+for d = 0, 1 do
+ local cid = tostring(d)..tostring(c)..tostring(b)..tostring(a)
+ local node_name = BASENAME..cid
+ local top = "atlatc_luacontroller_top.png"
+ if a == 1 then
+ top = top.."^atlatc_luacontroller_LED_A.png"
+ end
+ if b == 1 then
+ top = top.."^atlatc_luacontroller_LED_B.png"
+ end
+ if c == 1 then
+ top = top.."^atlatc_luacontroller_LED_C.png"
+ end
+ if d == 1 then
+ top = top.."^atlatc_luacontroller_LED_D.png"
+ end
+
+ local groups
+ if a + b + c + d ~= 0 then
+ groups = {dig_immediate=2, not_in_creative_inventory=1, save_in_at_nodedb=1}
+ else
+ groups = {dig_immediate=2, save_in_at_nodedb=1}
+ end
+
+ output_rules[cid] = {}
+ input_rules[cid] = {}
+ if a == 1 then table.insert(output_rules[cid], rules.a) end
+ if b == 1 then table.insert(output_rules[cid], rules.b) end
+ if c == 1 then table.insert(output_rules[cid], rules.c) end
+ if d == 1 then table.insert(output_rules[cid], rules.d) end
+
+ if a == 0 then table.insert( input_rules[cid], rules.a) end
+ if b == 0 then table.insert( input_rules[cid], rules.b) end
+ if c == 0 then table.insert( input_rules[cid], rules.c) end
+ if d == 0 then table.insert( input_rules[cid], rules.d) end
+
+ local mesecons = {
+ effector = {
+ rules = input_rules[cid],
+ action_change = function (pos, _, rule_name, new_state)
+ if new_state == "off" then
+ -- check for ignored off event on this node
+ if ignore_offevent(pos, rule_name) then
+ return
+ end
+ end
+ --Note: rule_name is not a *name* but actually the full rule table (position + name field)
+ --Event format consistent with Mesecons Luacontroller event
+ atlatc.interrupt.add(0, pos, {type=new_state, [new_state]=true, pin=rule_name})
+ end,
+ },
+ receptor = {
+ state = mesecon.state.on,
+ rules = output_rules[cid]
+ },
+ }
+
+ minetest.register_node(node_name, {
+ description = S("LuaATC Mesecon Controller"),
+ drawtype = "nodebox",
+ tiles = {
+ top,
+ "atlatc_luacontroller_bottom.png",
+ "atlatc_luacontroller_sides.png",
+ "atlatc_luacontroller_sides.png",
+ "atlatc_luacontroller_sides.png",
+ "atlatc_luacontroller_sides.png"
+ },
+ inventory_image = top,
+ paramtype = "light",
+ is_ground_content = false,
+ groups = groups,
+ drop = BASENAME.."0000",
+ sunlight_propagates = true,
+ selection_box = selection_box,
+ node_box = node_box,
+ mesecons = mesecons,
+ -- Virtual portstates are the ports that
+ -- the node shows as powered up (light up).
+ virtual_portstates = {
+ a = a == 1,
+ b = b == 1,
+ c = c == 1,
+ d = d == 1,
+ },
+ after_dig_node = function (pos, node, player)
+ mesecon.receptor_off(pos, output_rules)
+ atlatc.active.after_dig_node(pos, node, player)
+ end,
+ after_place_node = atlatc.active.after_place_node,
+ on_receive_fields = atlatc.active.on_receive_fields,
+ advtrains = {
+ on_updated_from_nodedb = on_updated_from_nodedb
+ },
+ luaautomation = {
+ fire_event=fire_event
+ },
+ digiline = {
+ receptor = {},
+ effector = {
+ action = atlatc.active.on_digiline_receive
+ },
+ },
+ })
+end
+end
+end
+end
diff --git a/advtrains_luaautomation/operation_panel.lua b/advtrains_luaautomation/operation_panel.lua
index f8b93b5..8e12651 100644..100755
--- a/advtrains_luaautomation/operation_panel.lua
+++ b/advtrains_luaautomation/operation_panel.lua
@@ -1,13 +1,14 @@
+local S = atltrans
-local function on_punch(pos, player)
- atlatc.interrupt.add(0, pos, {type="punch", punch=true})
+local function on_punch(pos,node,player)
+ atlatc.interrupt.add(0, pos, {type="punch", punch=true, name=player:get_player_name()})
end
minetest.register_node("advtrains_luaautomation:oppanel", {
drawtype = "normal",
tiles={"atlatc_oppanel.png"},
- description = "LuaAutomation operation panel",
+ description = S("LuaATC Operation Panel"),
groups = {
cracky = 1,
save_in_at_nodedb=1,
diff --git a/advtrains_luaautomation/pcnaming.lua b/advtrains_luaautomation/pcnaming.lua
index ebb769f..60983a6 100644
--- a/advtrains_luaautomation/pcnaming.lua
+++ b/advtrains_luaautomation/pcnaming.lua
@@ -2,6 +2,8 @@
--a.k.a Passive component naming
--Allows to assign names to passive components, so they can be called like:
--setstate("iamasignal", "green")
+local S = atltrans
+
atlatc.pcnaming={name_map={}}
function atlatc.pcnaming.load(stuff)
if type(stuff)=="table" then
@@ -23,7 +25,7 @@ function atlatc.pcnaming.resolve_pos(pos, func_name)
end
minetest.register_craftitem("advtrains_luaautomation:pcnaming",{
- description = attrans("Passive Component Naming Tool\n\nRight-click to name a passive component."),
+ description = S("Passive Component Naming Tool\n\nRight-click to name a passive component."),
groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
inventory_image = "atlatc_pcnaming.png",
wield_image = "atlatc_pcnaming.png",
@@ -34,7 +36,7 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{
return
end
if not minetest.check_player_privs(pname, {atlatc=true}) then
- minetest.chat_send_player(pname, "Missing privilege: atlatc")
+ minetest.chat_send_player(pname, S("You are not allowed to name LuaATC passive components without the @1 privilege.", "atlatc"))
return
end
if pointed_thing.type=="node" then
@@ -44,7 +46,12 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{
return
end
local node = advtrains.ndb.get_node(pos)
- if node.name and (minetest.get_item_group(node.name, "advtrains_signal")>0 or advtrains.is_passive(pos)) then
+ local ndef = minetest.registered_nodes[node.name]
+ if node.name and (
+ minetest.get_item_group(node.name, "advtrains_signal")>0 --is IL signal
+ or advtrains.is_passive(pos) -- is passive component
+ or (ndef and ndef.luaautomation) -- is active component
+ ) then
--look if this one already has a name
local pn=""
for name, npos in pairs(atlatc.pcnaming.name_map) do
@@ -52,7 +59,7 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{
pn=name
end
end
- minetest.show_formspec(pname, "atlatc_naming_"..minetest.pos_to_string(pos), "field[pn;Set name of component (empty to clear);"..minetest.formspec_escape(pn).."]")
+ minetest.show_formspec(pname, "atlatc_naming_"..minetest.pos_to_string(pos), "field[pn;"..S("Set name of component (empty to clear)")..";"..minetest.formspec_escape(pn).."]")
end
end
end,
diff --git a/advtrains_luaautomation/textures/atlatc_luacontroller_LED_A.png b/advtrains_luaautomation/textures/atlatc_luacontroller_LED_A.png
new file mode 100644
index 0000000..c6182cc
--- /dev/null
+++ b/advtrains_luaautomation/textures/atlatc_luacontroller_LED_A.png
Binary files differ
diff --git a/advtrains_luaautomation/textures/atlatc_luacontroller_LED_B.png b/advtrains_luaautomation/textures/atlatc_luacontroller_LED_B.png
new file mode 100644
index 0000000..04c2da0
--- /dev/null
+++ b/advtrains_luaautomation/textures/atlatc_luacontroller_LED_B.png
Binary files differ
diff --git a/advtrains_luaautomation/textures/atlatc_luacontroller_LED_C.png b/advtrains_luaautomation/textures/atlatc_luacontroller_LED_C.png
new file mode 100644
index 0000000..01f6ae4
--- /dev/null
+++ b/advtrains_luaautomation/textures/atlatc_luacontroller_LED_C.png
Binary files differ
diff --git a/advtrains_luaautomation/textures/atlatc_luacontroller_LED_D.png b/advtrains_luaautomation/textures/atlatc_luacontroller_LED_D.png
new file mode 100644
index 0000000..6c8a26f
--- /dev/null
+++ b/advtrains_luaautomation/textures/atlatc_luacontroller_LED_D.png
Binary files differ
diff --git a/advtrains_luaautomation/textures/atlatc_luacontroller_bottom.png b/advtrains_luaautomation/textures/atlatc_luacontroller_bottom.png
new file mode 100644
index 0000000..7ae955c
--- /dev/null
+++ b/advtrains_luaautomation/textures/atlatc_luacontroller_bottom.png
Binary files differ
diff --git a/advtrains_luaautomation/textures/atlatc_luacontroller_sides.png b/advtrains_luaautomation/textures/atlatc_luacontroller_sides.png
new file mode 100644
index 0000000..40f4b60
--- /dev/null
+++ b/advtrains_luaautomation/textures/atlatc_luacontroller_sides.png
Binary files differ
diff --git a/advtrains_luaautomation/textures/atlatc_luacontroller_top.png b/advtrains_luaautomation/textures/atlatc_luacontroller_top.png
new file mode 100644
index 0000000..a5059af
--- /dev/null
+++ b/advtrains_luaautomation/textures/atlatc_luacontroller_top.png
Binary files differ