mirror of
https://github.com/Mestima/wanda.git
synced 2025-12-15 21:59:43 +00:00
added keybinds support
This commit is contained in:
125
data/modmain.lua
125
data/modmain.lua
@ -1,14 +1,123 @@
|
||||
GLOBAL.setmetatable(env,{__index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end})
|
||||
local G = GLOBAL
|
||||
|
||||
local function GetConfig(name, default)
|
||||
local opt = GetModConfigData(name)
|
||||
if (not opt) then
|
||||
opt = default
|
||||
local agelesskey = GetModConfigData("ageless_key")
|
||||
local backstepkey = GetModConfigData("backstep_key")
|
||||
local backtrekkey = GetModConfigData("backtrek_key")
|
||||
local keybinds = GetModConfigData("key_binds")
|
||||
|
||||
local function IsInGameplay()
|
||||
return G.ThePlayer ~= nil and G.TheFrontEnd:GetActiveScreen().name == "HUD"
|
||||
end
|
||||
|
||||
local function GetWatch(watchType)
|
||||
if keybinds ~= true then return end
|
||||
local items = G.ThePlayer.replica.inventory:GetItems()
|
||||
local backpack = G.ThePlayer.replica.inventory:GetEquippedItem(G.EQUIPSLOTS.BODY)
|
||||
local watchbag = nil
|
||||
for k, v in pairs(items) do
|
||||
if v.prefab == "pocketwatchpack" then
|
||||
watchbag = v
|
||||
end
|
||||
end
|
||||
if (type(opt) == "table") then
|
||||
opt = opt.option_data
|
||||
local watchbagitems = watchbag and watchbag.replica.container and watchbag.replica.container:GetItems() or nil
|
||||
local packitems = backpack and backpack.replica.container and backpack.replica.container:GetItems() or nil
|
||||
local watch = nil
|
||||
for k, v in pairs(items) do
|
||||
if v.prefab == watchType and v:HasTag("pocketwatch_inactive") then
|
||||
watch = v
|
||||
break
|
||||
end
|
||||
end
|
||||
if watch ~= nil or (packitems == nil and watchbagitems == nil) then return watch end
|
||||
if (packitems ~= nil) then
|
||||
for k, v in pairs(packitems) do
|
||||
if v.prefab == watchType and v:HasTag("pocketwatch_inactive") then
|
||||
watch = v
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if watch ~= nil or watchbagitems == nil then return watch end
|
||||
for k, v in pairs(watchbagitems) do
|
||||
if v.prefab == watchType and v:HasTag("pocketwatch_inactive") then
|
||||
watch = v
|
||||
break
|
||||
end
|
||||
end
|
||||
return watch
|
||||
end
|
||||
|
||||
if agelesskey ~= "None" then
|
||||
if keybinds == true then
|
||||
local keybind = G["KEY_"..agelesskey]
|
||||
G.TheInput:AddKeyDownHandler(keybind, function()
|
||||
if not IsInGameplay() then return end
|
||||
local pocketwatch = GetWatch("pocketwatch_heal")
|
||||
if pocketwatch == nil or not G.ThePlayer:HasTag("pocketwatchcaster") then return end
|
||||
act = G.ACTIONS.CAST_POCKETWATCH
|
||||
local buffact = G.BufferedAction(G.ThePlayer, target, act, pocketwatch)
|
||||
if not G.TheWorld.ismastersim then
|
||||
local function cb()
|
||||
G.SendRPCToServer(G.RPC.ControllerUseItemOnSelfFromInvTile, act.code, pocketwatch, target)
|
||||
end
|
||||
if G.ThePlayer.components.locomotor then
|
||||
buffact.preview_cb = cb
|
||||
else
|
||||
cb()
|
||||
end
|
||||
end
|
||||
G.ThePlayer.components.playercontroller:DoAction(buffact)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
if backstepkey ~= "None" then
|
||||
if keybinds == true then
|
||||
local keybind2 = G["KEY_"..backstepkey]
|
||||
G.TheInput:AddKeyDownHandler(keybind2, function()
|
||||
if not IsInGameplay() then return end
|
||||
local pocketwatch = GetWatch("pocketwatch_warp")
|
||||
if pocketwatch == nil or not G.ThePlayer:HasTag("pocketwatchcaster") then return end
|
||||
act = G.ACTIONS.CAST_POCKETWATCH
|
||||
local buffact = G.BufferedAction(G.ThePlayer, target, act, pocketwatch)
|
||||
if not G.TheWorld.ismastersim then
|
||||
local function cb()
|
||||
G.SendRPCToServer(G.RPC.ControllerUseItemOnSelfFromInvTile, act.code, pocketwatch, target)
|
||||
end
|
||||
if G.ThePlayer.components.locomotor then
|
||||
buffact.preview_cb = cb
|
||||
else
|
||||
cb()
|
||||
end
|
||||
end
|
||||
G.ThePlayer.components.playercontroller:DoAction(buffact)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
if backtrekkey ~= "None" then
|
||||
if keybinds == true then
|
||||
local keybind3 = G["KEY_"..backtrekkey]
|
||||
G.TheInput:AddKeyDownHandler(keybind3, function()
|
||||
if not IsInGameplay() then return end
|
||||
local pocketwatch = GetWatch("pocketwatch_recall")
|
||||
if pocketwatch == nil or not G.ThePlayer:HasTag("pocketwatchcaster") then return end
|
||||
act = G.ACTIONS.CAST_POCKETWATCH
|
||||
local buffact = G.BufferedAction(G.ThePlayer, target, act, pocketwatch)
|
||||
if not G.TheWorld.ismastersim then
|
||||
local function cb()
|
||||
G.SendRPCToServer(G.RPC.ControllerUseItemOnSelfFromInvTile, act.code, pocketwatch, target)
|
||||
end
|
||||
if G.ThePlayer.components.locomotor then
|
||||
buffact.preview_cb = cb
|
||||
else
|
||||
cb()
|
||||
end
|
||||
end
|
||||
G.ThePlayer.components.playercontroller:DoAction(buffact)
|
||||
end)
|
||||
end
|
||||
return opt
|
||||
end
|
||||
|
||||
local lang = {
|
||||
@ -34,7 +143,7 @@ local lang = {
|
||||
}
|
||||
}
|
||||
|
||||
local language = GetConfig("lang", "eng")
|
||||
local language = GetModConfigData("lang")
|
||||
|
||||
PrefabFiles = { "pocketwatchpack" }
|
||||
Assets = {
|
||||
|
||||
Reference in New Issue
Block a user