From b19033b224f4f8ec33f10ba40327f1d811c04fbb Mon Sep 17 00:00:00 2001 From: orwell96 Date: Thu, 2 Feb 2017 16:40:51 +0100 Subject: LuaAutomation - Basic component implementation Implements the base code for LuaAutomation, an ATC rail and a punch-operated 'operation panel' as well as interface for passive components. Changes in advtrains code where neccessary. Supported passive components are light signals, switches and mesecon switches --- advtrains/advtrains_luaautomation/chatcmds.lua | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 advtrains/advtrains_luaautomation/chatcmds.lua (limited to 'advtrains/advtrains_luaautomation/chatcmds.lua') diff --git a/advtrains/advtrains_luaautomation/chatcmds.lua b/advtrains/advtrains_luaautomation/chatcmds.lua new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 948482a99e4aae4d51ff97879432140645959f46 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Thu, 2 Feb 2017 21:14:20 +0100 Subject: LuaAutomation: Add interrupt to the ingame API and implement initialization code handling and env management --- advtrains/advtrains_luaautomation/chatcmds.lua | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'advtrains/advtrains_luaautomation/chatcmds.lua') diff --git a/advtrains/advtrains_luaautomation/chatcmds.lua b/advtrains/advtrains_luaautomation/chatcmds.lua index e69de29..1a3f167 100644 --- a/advtrains/advtrains_luaautomation/chatcmds.lua +++ b/advtrains/advtrains_luaautomation/chatcmds.lua @@ -0,0 +1,70 @@ +--chatcmds.lua +--Registers commands to modify the init and step code for LuaAutomation + +local function get_init_form(env) + local err = env.init_err or "" + local code = env.init_code or "" + atprint(err) + 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).."]" + .."label[0,9.8;"..err.."]" + return form +end + +core.register_chatcommand("env_setup", { + params = "", + description = "Set up and modify AdvTrains LuaAutomation environment", + privs = {atlatc=true}, + 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)) + return true + end, +}) + +core.register_chatcommand("env_create", { + params = "", + description = "Create an AdvTrains LuaAutomation environment", + privs = {atlatc=true}, + func = function(name, param) + if not param or param=="" then return false, "Name required!" end + if atlatc.envs[param] then return false, "Environment already exists!" end + atlatc.envs[param] = atlatc.env_new(param) + return true, "Created environment '"..param.."'. Use '/env_setup "..param.."' to define global initialization code, or start building LuaATC components!" + end, +}) + + +minetest.register_on_player_receive_fields(function(player, formname, fields) + + local pname=player:get_player_name() + if not minetest.check_player_privs(pname, {atlatc=true}) then return end + + local envname=string.match(formname, "^atlatc_delconfirm_(.+)$") + if envname and fields.sure=="YES" then + atlatc.envs[envname]=nil + minetest.chat_send_player(pname, "Environment deleted!") + return + end + + envname=string.match(formname, "^atlatc_envsetup_(.+)$") + if not envname then return end + + local env=atlatc.envs[envname] + if not env then return end + + if fields.del then + minetest.show_formspec(pname, "atlatc_delconfirm_"..envname, "field[sure;"..minetest.formspec_escape("SURE TO DELETE ENVIRONMENT "..envname.."? Type YES (all uppercase) to continue or just quit form to cancel.")..";]") + return + end + + env.init_err=nil + if fields.code then + env.init_code=fields.code + end + if fields.run then + env:run_initcode() + minetest.show_formspec(pname, formname, get_init_form(env)) + end +end) -- cgit v1.2.3 From a72dda17be2175d5df8f1b7dd28e5ddeabe1494d Mon Sep 17 00:00:00 2001 From: orwell96 Date: Fri, 3 Feb 2017 15:40:44 +0100 Subject: Add quick position lookup by punching nodes --- advtrains/advtrains_luaautomation/chatcmds.lua | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'advtrains/advtrains_luaautomation/chatcmds.lua') 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) -- cgit v1.2.3