aboutsummaryrefslogtreecommitdiff
path: root/advtrains/advtrains_luaautomation
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/advtrains_luaautomation')
-rw-r--r--advtrains/advtrains_luaautomation/chatcmds.lua24
1 files changed, 19 insertions, 5 deletions
diff --git a/advtrains/advtrains_luaautomation/chatcmds.lua b/advtrains/advtrains_luaautomation/chatcmds.lua
index 1a3f167..2d0c69d 100644
--- a/advtrains/advtrains_luaautomation/chatcmds.lua
+++ b/advtrains/advtrains_luaautomation/chatcmds.lua
@@ -1,12 +1,26 @@
--chatcmds.lua
--Registers commands to modify the init and step code for LuaAutomation
-local function get_init_form(env)
+--position helper.
+--punching a node will result in that position being saved and inserted into a text field on the top of init form.
+local punchpos={}
+
+minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
+ local pname=player:get_player_name()
+ punchpos[pname]=pos
+end)
+
+local function get_init_form(env, pname)
local err = env.init_err or ""
local code = env.init_code or ""
- atprint(err)
+ local ppos=punchpos[pname]
+ local pp=""
+ if ppos then
+ pp="POS"..minetest.pos_to_string(ppos)
+ end
local form = "size[10,10]button[0,0;2,1;run;Run InitCode]button[2,0;2,1;cls;Clear S]"
- .."button[4,0;2,1;save;Save] button[6,0;2,1;del;Delete Env.] textarea[0.2,1;10,10;code;Environment initialization code;"..minetest.formspec_escape(code).."]"
+ .."button[4,0;2,1;save;Save] button[6,0;2,1;del;Delete Env.] field[8.1,0.5;2,1;punchpos;Last punched position;"..pp.."]"
+ .."textarea[0.2,1;10,10;code;Environment initialization code;"..minetest.formspec_escape(code).."]"
.."label[0,9.8;"..err.."]"
return form
end
@@ -18,7 +32,7 @@ core.register_chatcommand("env_setup", {
func = function(name, param)
local env=atlatc.envs[param]
if not env then return false,"Invalid environment name!" end
- minetest.show_formspec(name, "atlatc_envsetup_"..param, get_init_form(env))
+ minetest.show_formspec(name, "atlatc_envsetup_"..param, get_init_form(env, name))
return true
end,
})
@@ -65,6 +79,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
if fields.run then
env:run_initcode()
- minetest.show_formspec(pname, formname, get_init_form(env))
+ minetest.show_formspec(pname, formname, get_init_form(env, pname))
end
end)
n class="hl com">This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #pragma once #include <map> #include <queue> #include <string> #include <fstream> #include <thread> #include <mutex> #include "irrlichttypes.h" class ILogOutput; enum LogLevel { LL_NONE, // Special level that is always printed LL_ERROR, LL_WARNING, LL_ACTION, // In-game actions LL_INFO, LL_VERBOSE, LL_MAX, }; typedef u8 LogLevelMask; #define LOGLEVEL_TO_MASKLEVEL(x) (1 << x) class Logger { public: void addOutput(ILogOutput *out); void addOutput(ILogOutput *out, LogLevel lev); void addOutputMasked(ILogOutput *out, LogLevelMask mask); void addOutputMaxLevel(ILogOutput *out, LogLevel lev); LogLevelMask removeOutput(ILogOutput *out); void setLevelSilenced(LogLevel lev, bool silenced); void registerThread(const std::string &name); void deregisterThread(); void log(LogLevel lev, const std::string &text); // Logs without a prefix void logRaw(LogLevel lev, const std::string &text); void setTraceEnabled(bool enable) { m_trace_enabled = enable; } bool getTraceEnabled() { return m_trace_enabled; } static LogLevel stringToLevel(const std::string &name); static const std::string getLevelLabel(LogLevel lev); private: