source number added for command interface

This commit is contained in:
Joachim Stolberg 2019-08-25 18:08:30 +02:00
parent 266195db74
commit 2721fc72cd
27 changed files with 65 additions and 47 deletions

View File

@ -355,7 +355,7 @@ local tubing = {
return techage.put_items(inv, "dst", stack)
end
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
on_node_load = function(pos)

View File

@ -33,7 +33,7 @@ local function send_off_command(pos)
local numbers = meta:get_string("numbers") or ""
if numbers ~= "" then
local own_num = meta:get_string("node_number")
techage.send_multi(numbers, "off", own_num)
techage.send_multi(own_num, numbers, "off")
end
end
@ -43,7 +43,7 @@ local function send_command(pos)
local numbers = meta:get_string("numbers") or ""
if numbers ~= "" then
local own_num = meta:get_string("node_number")
techage.send_multi(numbers, "on", own_num)
techage.send_multi(own_num, numbers, "on")
minetest.after(1, send_off_command, pos)
end
end
@ -254,7 +254,7 @@ techage.register_node({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_
return techage.put_items(inv, "main", stack)
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
if topic == "state" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()

View File

@ -326,7 +326,7 @@ local tubing = {
local inv = M(pos):get_inventory()
return techage.put_items(inv, "src", stack)
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
if topic == "info" then
return INFO
elseif topic == "port" then

View File

@ -216,7 +216,7 @@ local tubing = {
return techage.put_items(inv, "dst", stack)
end
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp

View File

@ -234,7 +234,7 @@ local tubing = {
return techage.put_items(inv, "dst", stack)
end
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp

View File

@ -171,7 +171,7 @@ local tubing = {
return techage.put_items(inv, "dst", stack)
end
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp

View File

@ -182,7 +182,7 @@ local tubing = {
return techage.put_items(inv, "dst", stack)
end
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
return CRD(pos).State:on_receive_message(pos, topic, payload)
end,
on_node_load = function(pos)

View File

@ -110,7 +110,7 @@ tiles.act = {
local tubing = {
is_pusher = true, -- is a pulling/pushing node
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp

View File

@ -247,7 +247,7 @@ end
-- on_pull_item = func(pos, in_dir, num),
-- on_push_item = func(pos, in_dir, item),
-- on_unpull_item = func(pos, in_dir, item),
-- on_recv_message = func(pos, topic, payload),
-- on_recv_message = func(pos, src, topic, payload),
-- on_node_load = func(pos), -- LBM function
-- on_transfer = func(pos, in_dir, topic, payload),
-- }
@ -299,22 +299,22 @@ function techage.check_numbers(numbers, placer_name)
return false
end
function techage.send_multi(numbers, topic, payload)
function techage.send_multi(src, numbers, topic, payload)
for _,num in ipairs(string_split(numbers, " ")) do
if Number2Pos[num] and Number2Pos[num].name then
local data = Number2Pos[num]
if data.pos and NodeDef[data.name] and NodeDef[data.name].on_recv_message then
NodeDef[data.name].on_recv_message(data.pos, topic, payload)
NodeDef[data.name].on_recv_message(data.pos, src, topic, payload)
end
end
end
end
function techage.send_single(number, topic, payload)
function techage.send_single(src, number, topic, payload)
if Number2Pos[number] and Number2Pos[number].name then
local data = Number2Pos[number]
if data.pos and NodeDef[data.name] and NodeDef[data.name].on_recv_message then
return NodeDef[data.name].on_recv_message(data.pos, topic, payload)
return NodeDef[data.name].on_recv_message(data.pos, src, topic, payload)
end
end
return false

View File

@ -99,7 +99,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
if validStates[stage] then
local on_recv_message = tNode.tubing.on_recv_message
if stage > 2 then
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
return "unsupported"
end
end

View File

@ -169,4 +169,18 @@ function mydbg(topic, text, ...)
end
print(t..text, unpack({...}))
end
end
end
-- needed for windmill plants
local function determine_ocean_ids()
techage.OceanIdTbl = {}
for name, _ in pairs(minetest.registered_biomes) do
if string.find(name, "ocean") then
local id = minetest.get_biome_id(name)
print(id, name)
techage.OceanIdTbl[id] = true
end
end
end
determine_ocean_ids()

View File

@ -204,7 +204,7 @@ techage.register_node({"techage:coalfirebox"}, {
local inv = meta:get_inventory()
return techage.put_items(inv, "fuel", stack)
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "state" then
if mem.running then

View File

@ -206,7 +206,7 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
end
end
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "load" then
return techage.power.percent(PWR_CAPA, mem.provided)

View File

@ -170,7 +170,7 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"},
local inv = meta:get_inventory()
return techage.put_items(inv, "fuel", stack)
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "state" then
if mem.running then

View File

@ -212,7 +212,7 @@ local tubing = {
return techage.put_items(inv, "dst", stack)
end
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp

View File

@ -41,13 +41,13 @@ function techage.logic.send_on(pos, meta, time)
if time and time > 0 then
minetest.get_node_timer(pos):start(time)
end
techage.send_multi(numbers, "on", own_num)
techage.send_multi(own_num, numbers, "on")
end
function techage.logic.send_off(pos, meta)
local own_num = meta:get_string("node_number") or ""
local numbers = meta:get_string("numbers") or ""
techage.send_multi(numbers, "off", own_num)
techage.send_multi(own_num, numbers, "off")
end
function techage.logic.infotext(meta, descr, text)

View File

@ -92,7 +92,7 @@ minetest.register_craft({
})
techage.register_node({"techage:ta3_repeater"}, {
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
mem.overload_cnt = (mem.overload_cnt or 0) + 1
if mem.overload_cnt > OVER_LOAD_MAX then
@ -101,7 +101,7 @@ techage.register_node({"techage:ta3_repeater"}, {
return false
else
local numbers = M(pos):get_string("numbers") or ""
techage.send_multi(numbers, topic, payload)
techage.send_multi(src, numbers, topic, payload)
end
end,
on_node_load = function(pos)

View File

@ -107,7 +107,7 @@ local function check_rules(pos, elapsed)
while true do -- process all rules as long as offs == 0
local rule = mem.rules[mem.index]
local offs = tonumber(mem.rules[mem.index].offs or 1)
techage.send_multi(rule.num, tAction[rule.act], own_num)
techage.send_multi(own_num, rule.num, tAction[rule.act])
mem.index = get_next_slot(mem.index, mem.rules, mem.endless)
if mem.index ~= nil and offs ~= nil and mem.running then
-- after the last rule a pause with 1 or more sec is required
@ -251,7 +251,7 @@ minetest.register_craft({
})
techage.register_node({"techage:ta3_sequencer"}, {
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
if topic == "on" then
start_the_sequencer(pos)
elseif topic == "off" then

View File

@ -112,8 +112,7 @@ minetest.register_node("techage:signal_lamp_on", {
})
techage.register_node({"techage:signal_lamp_off", "techage:signal_lamp_on"}, {
on_recv_message = function(pos, topic, payload)
print("on_recv_message", topic)
on_recv_message = function(pos, src, topic, payload)
if topic == "on" then
local node = minetest.get_node(pos)
switch_on(pos, node)

View File

@ -126,10 +126,11 @@ local function command(pos, command, player)
output(pos, S("Switched to private use!"))
elseif meta:get_int("public") == 1 or owner == player then
output(pos, "$ "..command)
local own_num = meta:get_string("node_number")
local num, cmnd, payload = command:match('^cmd%s+([0-9]+)%s+(%w+)%s*(.*)$')
if num and cmnd then
if techage.not_protected(num, owner, owner) then
local resp = techage.send_single(num, cmnd, payload)
local resp = techage.send_single(own_num, num, cmnd, payload)
if type(resp) == "string" then
output(pos, resp)
else
@ -141,7 +142,7 @@ local function command(pos, command, player)
num, cmnd = command:match('^turn%s+([0-9]+)%s+([onf]+)$')
if num and (cmnd == "on" or cmnd == "off") then
if techage.not_protected(num, owner, owner) then
local resp = techage.send_single(num, cmnd)
local resp = techage.send_single(own_num, num, cmnd)
output(pos, dump(resp))
end
return
@ -284,8 +285,8 @@ minetest.register_craft({
})
techage.register_node({"techage:terminal1", "techage:terminal2"}, {
on_recv_message = function(pos, topic, payload)
output(pos, "cmd="..dump(topic)..", data="..dump(payload))
on_recv_message = function(pos, src, topic, payload)
output(pos, "src="..src..", cmd="..dump(topic)..", data="..dump(payload))
return true
end,
on_node_load = function(pos)

View File

@ -95,7 +95,7 @@ local function check_rules(pos,elapsed)
local hr = (events[idx] - 1) * 2
if ((hour - hr) % 24) <= 4 then -- last 4 hours?
if mem.done[idx] == false then -- not already executed?
techage.send_multi(numbers[idx], act, number)
techage.send_multi(number, numbers[idx], act)
mem.done[idx] = true
end
else

View File

@ -237,7 +237,7 @@ local tubing = {
return techage.put_items(inv, "dst", stack)
end
end,
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp

View File

@ -225,7 +225,7 @@ techage.power.register_node({"techage:tiny_generator", "techage:tiny_generator_o
})
techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "load" then
return power.percent(PWR_CAPA, mem.provided)

View File

@ -141,7 +141,7 @@ tiles.act = {
local tubing = {
is_pusher = true, -- is a pulling/pushing node
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
if resp then
return resp

View File

@ -194,7 +194,7 @@ techage.power.register_node({"techage:powerswitch_box"}, {
})
techage.register_node({"techage:powerswitch", "techage:powerswitch_on"}, {
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local node = minetest.get_node(pos)
if topic == "on" and node.name == "techage:powerswitch" then
switch_on(pos, node)

View File

@ -108,7 +108,7 @@ techage.power.register_node({"techage:ta4_solar_minicell"}, {
})
techage.register_node({"techage:ta4_solar_minicell"}, {
on_recv_message = function(pos, topic, payload)
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
if topic == "state" then
if mem.providing then

View File

@ -33,7 +33,11 @@ local function read_state(itemstack, user, pointed_thing)
minetest.chat_send_player(user:get_player_name(), S("Time")..": "..hours..":"..mins.." ")
local data = minetest.get_biome_data(pos)
if data then
minetest.chat_send_player(user:get_player_name(), S("Biome")..": "..data.biome..", "..S("Position temperature")..": "..math.floor(data.heat).." ")
local name = minetest.get_biome_name(data.biome)
minetest.chat_send_player(user:get_player_name(), S("Biome")..": "..name..", "..S("Position temperature")..": "..math.floor(data.heat).." ")
if techage.OceanIdTbl[data.biome] then
minetest.chat_send_player(user:get_player_name(), "Suitable for windmills")
end
end
local number = techage.get_node_number(pos)
local node = minetest.get_node(pos)
@ -48,27 +52,27 @@ local function read_state(itemstack, user, pointed_thing)
local ndef = minetest.registered_nodes[node.name]
if number then
if ndef and ndef.description then
local info = techage.send_single(number, "info", nil)
local info = techage.send_single("0", number, "info", nil)
if info and info ~= "" and info ~= "unsupported" then
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": Supported Commands:\n"..info.." ")
end
local state = techage.send_single(number, "state", nil)
local state = techage.send_single("0", number, "state", nil)
if state and state ~= "" and state ~= "unsupported" then
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": state = "..state.." ")
end
local fuel = techage.send_single(number, "fuel", nil)
local fuel = techage.send_single("0", number, "fuel", nil)
if fuel and fuel ~= "" and fuel ~= "unsupported" then
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": fuel = "..fuel.." ")
end
local counter = techage.send_single(number, "counter", nil)
local counter = techage.send_single("0", number, "counter", nil)
if counter and counter ~= "" and counter ~= "unsupported" then
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": counter = "..counter.." ")
end
local load = techage.send_single(number, "load", nil)
local load = techage.send_single("0", number, "load", nil)
if load and load ~= "" and load ~= "unsupported" then
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": load = "..load.." % ")
end
local power = techage.send_single(number, "power", nil)
local power = techage.send_single("0", number, "power", nil)
if power and power ~= "" and power ~= "unsupported" then
minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": power = "..power.." % ")
end
@ -134,4 +138,4 @@ techage.register_entry_page("ta", "end_wrench",
S("The TechAge Info Tool is a tool to read any kind of status information from nodes providing a command interface.@n"..
"Click on the node to read the status"),
"techage:end_wrench")