Permalink
Browse files

Auto update noclip bind. Disable if empty

Updates noclip bind when the user settings are updated.
Disables noclip bind if user set the bind to "".
  • Loading branch information...
Silverfeelin committed Nov 16, 2018
1 parent 6dedc5f commit dcd59c8dae0ab630b2874a60264e11b355a58e92
Showing with 20 additions and 10 deletions.
  1. +20 −10 scripts/wedit/controller.lua
@@ -149,13 +149,23 @@ end
function controller.updateUserConfig()
-- Load config data
local cfg = controller.getUserConfig()
for k in pairs(wedit.user) do
wedit.user[k] = nil
end
for k,v in pairs(cfg) do
wedit.user[k] = v
end
if controller.noclipBind then
if cfg.noclipBind == "" then
controller.noclipBind:unbind()
else
controller.noclipBind:rebind()
controller.noclipBind:change(cfg.noclipBind)
end
end
if wedit.getUserConfigData("clearSchematics") then
storage.weditSchematics = {}
controller.setUserConfig("clearSchematics", false)
@@ -187,6 +197,8 @@ function controller.init()
status.setStatusProperty("wedit.matmodPicker.open", nil)
status.setStatusProperty("wedit.materialPicker.open", nil)
-- Holds the noclip toggle Bind
controller.noclipBind = nil
-- Default noclip status (on tech selection or character load)
controller.noclipping = false
-- Selected liquid ID. Expected to have name and liquidId at all times.
@@ -226,7 +238,8 @@ function controller.init()
-- #region NoClip Binds
-- Set up noclip using Keybinds.
Bind.create(wedit.getUserConfigData("noclipBind"), function()
local noclipBind = wedit.getUserConfigData("noclipBind");
controller.noclipBind = Bind.create(noclipBind, function()
controller.noclipping = not controller.noclipping
if controller.noclipping then
tech.setParentState("fly")
@@ -239,22 +252,19 @@ function controller.init()
v:unbind()
end
end
end)
end, false, noclipBind == "")
local adjustPosition = function(offset)
local pos = mcontroller.position()
mcontroller.setPosition({pos[1] + offset[1], pos[2] + offset[2]})
mcontroller.setVelocity({0,0})
end
controller.noclipBinds = {}
table.insert(controller.noclipBinds, Bind.create("up", function() adjustPosition({0,wedit.getUserConfigData("noclipSpeed")}) end, true))
table.insert(controller.noclipBinds, Bind.create("down", function() adjustPosition({0,-wedit.getUserConfigData("noclipSpeed")}) end, true))
table.insert(controller.noclipBinds, Bind.create("left", function() adjustPosition({-wedit.getUserConfigData("noclipSpeed"),0}) end, true))
table.insert(controller.noclipBinds, Bind.create("right", function() adjustPosition({wedit.getUserConfigData("noclipSpeed"),0}) end, true))
table.insert(controller.noclipBinds, Bind.create("up=false down=false left=false right=false", function() mcontroller.setVelocity({0,0}) end, false))
for _,v in ipairs(controller.noclipBinds) do
v:unbind()
end
table.insert(controller.noclipBinds, Bind.create("up", function() adjustPosition({0,wedit.getUserConfigData("noclipSpeed")}) end, true, true))
table.insert(controller.noclipBinds, Bind.create("down", function() adjustPosition({0,-wedit.getUserConfigData("noclipSpeed")}) end, true, true))
table.insert(controller.noclipBinds, Bind.create("left", function() adjustPosition({-wedit.getUserConfigData("noclipSpeed"),0}) end, true, true))
table.insert(controller.noclipBinds, Bind.create("right", function() adjustPosition({wedit.getUserConfigData("noclipSpeed"),0}) end, true, true))
table.insert(controller.noclipBinds, Bind.create("up=false down=false left=false right=false", function() mcontroller.setVelocity({0,0}) end, false, true))
-- #endregion

0 comments on commit dcd59c8

Please sign in to comment.