aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_luaautomation')
-rw-r--r--advtrains_luaautomation/active_common.lua38
-rw-r--r--advtrains_luaautomation/chatcmds.lua28
2 files changed, 60 insertions, 6 deletions
diff --git a/advtrains_luaautomation/active_common.lua b/advtrains_luaautomation/active_common.lua
index 63ccfcd..311ec04 100644
--- a/advtrains_luaautomation/active_common.lua
+++ b/advtrains_luaautomation/active_common.lua
@@ -12,16 +12,42 @@ function ac.save()
return {nodes = ac.nodes}
end
+function ac.get_player_default_environment(player)
+ local meta = player:get_meta()
+ local env = meta:get_string("atlatc_default_env")
+
+ if not atlatc.envs[env] then
+ -- Set the first key for the user as default environment
+ for envname, _ in pairs(atlatc.envs) do
+ meta:set_string("atlatc_default_env", envname)
+ return envname
+ end
+
+ -- We don't have any environments
+ return nil
+ end
+
+ return env
+end
+function ac.set_player_default_environment(player, env)
+ if atlatc.envs[env] then
+ local meta = player:get_meta()
+ meta:set_string("atlatc_default_env", env)
+ return true
+ end
+ return false
+end
+
function ac.after_place_node(pos, player)
+ local env = ac.get_player_default_environment(player)
+ if env then
+ local ph = minetest.pos_to_string(pos)
+ ac.nodes[ph] = { env = env }
+ end
+
local meta=minetest.get_meta(pos)
meta:set_string("formspec", ac.getform(pos, meta))
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
- ac.nodes[ph]={env=en}
- return
- end
end
function ac.getform(pos, meta_p)
local meta = meta_p or minetest.get_meta(pos)
diff --git a/advtrains_luaautomation/chatcmds.lua b/advtrains_luaautomation/chatcmds.lua
index 7691013..5f0da13 100644
--- a/advtrains_luaautomation/chatcmds.lua
+++ b/advtrains_luaautomation/chatcmds.lua
@@ -110,6 +110,34 @@ core.register_chatcommand("env_subscriptions", {
end,
})
+core.register_chatcommand("env_default", {
+ params = "[environment name]",
+ description = S("Set or get your default LuaATC environment."),
+ privs = {atlatc=true},
+ func = function(name, param)
+ local player = minetest.get_player_by_name(name)
+ if not player then
+ return false, S("You're not online!")
+ end
+
+ param = string.trim(param)
+ if param == "" then
+ local env = atlatc.active.get_player_default_environment(player)
+ if env then
+ return true, S("Your default environment is '@1'.", env)
+ else
+ return false, S("No avaliable environemnt! Create one with /env_create.")
+ end
+ end
+
+ if atlatc.active.set_player_default_environment(player, param) then
+ return true, S("Default environment set to '@1'.", param)
+ else
+ return false, S("Invalid environment name!")
+ end
+ end,
+})
+
minetest.register_on_player_receive_fields(function(player, formname, fields)
local pname=player:get_player_name()