From 5c2534cc35bc0fc47b53c8a992e3e71b15a60ec4 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Mon, 27 Apr 2020 16:02:28 +0200 Subject: Remove pcall wrappers completely, add command to disable advtrains mainloop --- advtrains/atc.lua | 80 +++++++++++++-------------- advtrains/copytool.lua | 134 +++++++++++++++++++++++----------------------- advtrains/couple.lua | 14 ----- advtrains/init.lua | 61 ++++++++++++--------- advtrains/nodedb.lua | 6 --- advtrains/trackplacer.lua | 8 +-- advtrains/trainlogic.lua | 6 +-- advtrains/wagons.lua | 16 ++---- 8 files changed, 146 insertions(+), 179 deletions(-) diff --git a/advtrains/atc.lua b/advtrains/atc.lua index 1c6df36..0cb6019 100644 --- a/advtrains/atc.lua +++ b/advtrains/atc.lua @@ -108,53 +108,49 @@ advtrains.atc_function = function(def, preset, suffix, rotation) return { after_place_node=apn_func, after_dig_node=function(pos) - return advtrains.pcall(function() - advtrains.invalidate_all_paths(pos) - advtrains.ndb.clear(pos) - local pts=minetest.pos_to_string(pos) - atc.controllers[pts]=nil - end) + advtrains.invalidate_all_paths(pos) + advtrains.ndb.clear(pos) + local pts=minetest.pos_to_string(pos) + atc.controllers[pts]=nil end, on_receive_fields = function(pos, formname, fields, player) - return advtrains.pcall(function() - if advtrains.is_protected(pos, player:get_player_name()) then - minetest.record_protection_violation(pos, player:get_player_name()) + if advtrains.is_protected(pos, player:get_player_name()) then + minetest.record_protection_violation(pos, player:get_player_name()) + return + end + local meta=minetest.get_meta(pos) + if meta then + if not fields.save then + --[[--maybe only the dropdown changed + if fields.mode then + meta:set_string("mode", idxtrans[fields.mode]) + if fields.mode=="digiline" then + meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", fields.mode, meta:get_string("command")) ) + else + meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", fields.mode, meta:get_string("command")) ) + end + meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta)) + end]]-- return end - local meta=minetest.get_meta(pos) - if meta then - if not fields.save then - --maybe only the dropdown changed - if fields.mode then - meta:set_string("mode", idxtrans[fields.mode]) - if fields.mode=="digiline" then - meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", (fields.mode or "?"), meta:get_string("command")) ) - else - meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", (fields.mode or "?"), meta:get_string("command")) ) - end - meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta)) - end - return - end - meta:set_string("mode", idxtrans[fields.mode]) - meta:set_string("command", fields.command) - meta:set_string("command_on", fields.command_on) - meta:set_string("channel", fields.channel) - if fields.mode=="digiline" then - meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", (fields.mode or "?"), meta:get_string("command")) ) - else - meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", (fields.mode or "?"), meta:get_string("command")) ) - end - meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta)) - - local pts=minetest.pos_to_string(pos) - local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes) - atc.controllers[pts]={command=fields.command} - if #advtrains.occ.get_trains_at(pos) > 0 then - atc.send_command(pos) - end + --meta:set_string("mode", idxtrans[fields.mode]) + meta:set_string("command", fields.command) + --meta:set_string("command_on", fields.command_on) + meta:set_string("channel", fields.channel) + --if fields.mode=="digiline" then + -- meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", fields.mode, meta:get_string("command")) ) + --else + meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", "-", meta:get_string("command")) ) + --end + meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta)) + + local pts=minetest.pos_to_string(pos) + local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes) + atc.controllers[pts]={command=fields.command} + if #advtrains.occ.get_trains_at(pos) > 0 then + atc.send_command(pos) end - end) + end end, advtrains = { on_train_enter = function(pos, train_id) diff --git a/advtrains/copytool.lua b/advtrains/copytool.lua index dc18081..0c1cdfe 100644 --- a/advtrains/copytool.lua +++ b/advtrains/copytool.lua @@ -13,76 +13,74 @@ minetest.register_tool("advtrains:copytool", { -- The front of the train is used as the start of the new train and it proceeds backwards from -- the direction of travel. on_place = function(itemstack, placer, pointed_thing) - return advtrains.pcall(function() - if ((not pointed_thing.type == "node") or (not placer.get_player_name)) then - return - end - local pname = placer:get_player_name() - - local node=minetest.get_node_or_nil(pointed_thing.under) - if not node then atprint("[advtrains]Ignore at placer position") return itemstack end - local nodename=node.name - if(not advtrains.is_track_and_drives_on(nodename, {default=true})) then - atprint("no track here, not placing.") - return itemstack - end - if not minetest.check_player_privs(placer, {train_operator = true }) then - minetest.chat_send_player(pname, "You don't have the train_operator privilege.") - return itemstack - end - if not minetest.check_player_privs(placer, {train_admin = true }) and minetest.is_protected(pointed_thing.under, placer:get_player_name()) then - return itemstack - end - local tconns=advtrains.get_track_connections(node.name, node.param2) - local yaw = placer:get_look_horizontal() - local plconnid = advtrains.yawToClosestConn(yaw, tconns) - - local prevpos = advtrains.get_adjacent_rail(pointed_thing.under, tconns, plconnid, {default=true}) - if not prevpos then - minetest.chat_send_player(pname, "The track you are trying to place the wagon on is not long enough!") - return - end - - local meta = itemstack:get_meta() - if not meta then - minetest.chat_send_player(pname, attrans("The clipboard couldn't access the metadata. Paste failed.")) + if ((not pointed_thing.type == "node") or (not placer.get_player_name)) then return - end - local clipboard = meta:get_string("clipboard") - if (clipboard == "") then - minetest.chat_send_player(pname, "The clipboard is empty."); - return - end - clipboard = minetest.deserialize(clipboard) - if (clipboard.wagons == nil) then - minetest.chat_send_player(pname, "The clipboard is empty."); - return - end - - local wagons = {} - local n = 1 - for _, wagonProto in pairs(clipboard.wagons) do - local wagon = advtrains.create_wagon(wagonProto.type, pname) - advtrains.wagons[wagon].wagon_flipped = wagonProto.wagon_flipped - wagons[n] = wagon - n = n + 1 - end - - local id=advtrains.create_new_train_at(pointed_thing.under, plconnid, 0, wagons) - local train = advtrains.trains[id] - train.off_track = train.end_index