Skip to content

Commit

Permalink
Auto update noclip bind. Disable if empty
Browse files Browse the repository at this point in the history
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 dcd59c8
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions scripts/wedit/controller.lua
Expand Up @@ -149,13 +149,23 @@ end
function controller.updateUserConfig() function controller.updateUserConfig()
-- Load config data -- Load config data
local cfg = controller.getUserConfig() local cfg = controller.getUserConfig()

for k in pairs(wedit.user) do for k in pairs(wedit.user) do
wedit.user[k] = nil wedit.user[k] = nil
end end
for k,v in pairs(cfg) do for k,v in pairs(cfg) do
wedit.user[k] = v wedit.user[k] = v
end 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 if wedit.getUserConfigData("clearSchematics") then
storage.weditSchematics = {} storage.weditSchematics = {}
controller.setUserConfig("clearSchematics", false) controller.setUserConfig("clearSchematics", false)
Expand Down Expand Up @@ -187,6 +197,8 @@ function controller.init()
status.setStatusProperty("wedit.matmodPicker.open", nil) status.setStatusProperty("wedit.matmodPicker.open", nil)
status.setStatusProperty("wedit.materialPicker.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) -- Default noclip status (on tech selection or character load)
controller.noclipping = false controller.noclipping = false
-- Selected liquid ID. Expected to have name and liquidId at all times. -- Selected liquid ID. Expected to have name and liquidId at all times.
Expand Down Expand Up @@ -226,7 +238,8 @@ function controller.init()
-- #region NoClip Binds -- #region NoClip Binds


-- Set up noclip using Keybinds. -- 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 controller.noclipping = not controller.noclipping
if controller.noclipping then if controller.noclipping then
tech.setParentState("fly") tech.setParentState("fly")
Expand All @@ -239,22 +252,19 @@ function controller.init()
v:unbind() v:unbind()
end end
end end
end) end, false, noclipBind == "")


local adjustPosition = function(offset) local adjustPosition = function(offset)
local pos = mcontroller.position() local pos = mcontroller.position()
mcontroller.setPosition({pos[1] + offset[1], pos[2] + offset[2]}) mcontroller.setPosition({pos[1] + offset[1], pos[2] + offset[2]})
mcontroller.setVelocity({0,0}) mcontroller.setVelocity({0,0})
end end
controller.noclipBinds = {} controller.noclipBinds = {}
table.insert(controller.noclipBinds, Bind.create("up", function() adjustPosition({0,wedit.getUserConfigData("noclipSpeed")}) end, true)) 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)) 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)) 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)) 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)) table.insert(controller.noclipBinds, Bind.create("up=false down=false left=false right=false", function() mcontroller.setVelocity({0,0}) end, false, true))
for _,v in ipairs(controller.noclipBinds) do
v:unbind()
end


-- #endregion -- #endregion


Expand Down

0 comments on commit dcd59c8

Please sign in to comment.