Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaaznar committed Oct 11, 2015
1 parent cf7f8ac commit 8852029
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
38 changes: 15 additions & 23 deletions ActionControls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require "MatchingGame"
-----------------------------------------------------------------------------------------------
-- Packages
-----------------------------------------------------------------------------------------------
local KeyBindingUtils = Apollo.GetPackage("Blaz:Lib:KeyBindingUtils-0.2").tPackage
local LuaUtils = Apollo.GetPackage("Blaz:Lib:LuaUtils-0.1").tPackage
local SimpleLog = Apollo.GetPackage("Blaz:Lib:SimpleLog-0.1").tPackage
local LuaUtils = Apollo.GetPackage("Blaz:Lib:LuaUtils-0.2").tPackage:new()
local SimpleLog = Apollo.GetPackage("Blaz:Lib:SimpleLog-0.1").tPackage:new()
local KeyBindingUtils = Apollo.GetPackage("Blaz:Lib:KeyBindingUtils-0.2").tPackage:new(nil, SimpleLog)
local InputKey = Apollo.GetPackage("Blaz:Lib:InputKey-0.1").tPackage

-----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -44,14 +44,13 @@ local ActionControls = {}
-----------------------------------------------------------------------------------------------
-- Initialization
-----------------------------------------------------------------------------------------------
function ActionControls:new(o, logInst, keyBindingUtilsInst)
function ActionControls:new(o, logInst)
o = o or {}
setmetatable(o, self)
self.__index = self

-- variables
o.log = logInst
o.keyBindingUtils = keyBindingUtilsInst
o.log = SimpleLog

o.immediateMouseOverUnit = nil
o.lastTargetUnit = nil
Expand All @@ -71,14 +70,12 @@ function ActionControls:new(o, logInst, keyBindingUtilsInst)
inCombatTargetingMode = EnumInCombatTargetingMode.None,
}

o.defaultSettings = table.ShallowCopy(o.settings)
o.defaultSettings = LuaUtils:ShallowCopy(o.settings)

o.bindings = nil

o.model = {}



return o
end

Expand All @@ -90,7 +87,7 @@ function ActionControls:Init()
local strConfigureButtonText = "Action Controls"
local tDependencies = {
"Blaz:Lib:KeyBindingUtils-0.2",
"Blaz:Lib:LuaUtils-0.1",
"Blaz:Lib:LuaUtils-0.2",
"Blaz:Lib:SimpleLog-0.1"
}
Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies)
Expand Down Expand Up @@ -204,8 +201,8 @@ end

function ActionControls:RestoreUserSettings(t)
xpcall(function ()
local settings = table.ShallowCopy(self.settings)
table.ShallowMerge(t, settings)
local settings = LuaUtils:ShallowCopy(self.settings)
LuaUtils:ShallowMerge(t, settings)

self:ValidateUserSettings(settings)

Expand Down Expand Up @@ -307,7 +304,7 @@ function ActionControls:ReadKeyBindings()
end

function ActionControls:GetBoundKeysForAction(bindings, ...)
local foundBindings = self.keyBindingUtils:GetBindingListByActionNames(bindings, unpack(arg))
local foundBindings = KeyBindingUtils:GetBindingListByActionNames(bindings, unpack(arg))

if foundBindings == nil or table.getn(foundBindings) == 0 then
self.log:Debug("GetBoundCharsForAction(...) - no bindings found.")
Expand Down Expand Up @@ -603,7 +600,7 @@ end
function ActionControls:GenerateModel()
self.model = {}

self.model.settings = table.ShallowCopy(self.settings)
self.model.settings = LuaUtils:ShallowCopy(self.settings)
self.model.explicitMouseLook = {}
end

Expand Down Expand Up @@ -743,15 +740,15 @@ function ActionControls:IsKeyAlreadyBound(inputKey)
function ()
local bindings = GameLib.GetKeyBindings()

local sprintBinding = self.keyBindingUtils:GetBindingByActionName(bindings, "SprintModifier")
local sprintBinding = KeyBindingUtils:GetBindingByActionName(bindings, "SprintModifier")
local sprintInputKey = inputKey:newFromArInput(sprintBinding.arInputs[1])
if sprintInputKey.eDevice ~= 0 and
sprintInputKey:GetModifierFlag(sprintInputKey.nCode) == inputKey.eModifier then
self.log:Info("Key '%s' is already bound to '%s'", tostring(sprintInputKey), tostring(sprintBinding.strActionLocalized))
return true
end

local existingBinding = self.keyBindingUtils:GetBinding(bindings, inputKey)
local existingBinding = KeyBindingUtils:GetBinding(bindings, inputKey)
if existingBinding ~= nil then
self.log:Info("Key '%s' is already bound to '%s'", tostring(inputKey), tostring(existingBinding.strActionLocalized))
return
Expand Down Expand Up @@ -826,10 +823,5 @@ end
-----------------------------------------------------------------------------------------------
-- ActionControls Instance
-----------------------------------------------------------------------------------------------
local logInst = SimpleLog:new()
local keyBindingUtilsInst = KeyBindingUtils:new(nil, logInst)

local actionControlsInst = ActionControls:new(nil, logInst, keyBindingUtilsInst)

actionControlsInst:Init()

local actionControlsInst = ActionControls:new(nil, SimpleLog)
actionControlsInst:Init()
2 changes: 1 addition & 1 deletion ActionControls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="4" TAnchorPoint="0" TAnchorOffset="3" RAnchorPoint="1" RAnchorOffset="-5" BAnchorPoint="0" BAnchorOffset="34" RelativeToClient="1" Font="CRB_HeaderTiny" Text="Instructions" BGColor="UI_WindowBGDefault" TextColor="UI_TextHoloTitle" Template="Default" TooltipType="OnCursor" Name="LblInfo" TooltipColor="" TextId="" Visible="1" DT_VCENTER="1" DT_CENTER="1" DT_RIGHT="0"/>
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="9" TAnchorPoint="0" TAnchorOffset="44" RAnchorPoint="0" RAnchorOffset="322" BAnchorPoint="0" BAnchorOffset="84" RelativeToClient="1" Font="CRB_InterfaceMedium" Text="1. Go to Options-&gt;Controls-&gt;Automatic Mouse Look and turn on all (or some) of the options." BGColor="UI_WindowBGDefault" TextColor="UI_TextHoloTitle" Template="Default" TooltipType="OnCursor" Name="LblInfo2" TooltipColor="" TextId="" Visible="1" DT_VCENTER="0" Tooltip="" DT_WORDBREAK="1"/>
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="9" TAnchorPoint="0" TAnchorOffset="89" RAnchorPoint="0" RAnchorOffset="322" BAnchorPoint="0" BAnchorOffset="165" RelativeToClient="1" Font="CRB_InterfaceMedium" Text="2. Go to Options-&gt;Keybindings and set the last column of the keybindings (Mouse Look) for the alternate keybindings you want to use when Mouse Look is active." BGColor="UI_WindowBGDefault" TextColor="UI_TextHoloTitle" Template="Default" TooltipType="OnCursor" Name="LblInfo4" TooltipColor="" TextId="" Visible="1" DT_VCENTER="0" Tooltip="" DT_WORDBREAK="1"/>
<Control Class="Button" Base="BK3:btnHolo_Check" Font="CRB_InterfaceMedium" ButtonType="Check" RadioGroup="" LAnchorPoint="0" LAnchorOffset="15" TAnchorPoint="0" TAnchorOffset="182" RAnchorPoint="1" RAnchorOffset="-13" BAnchorPoint="0" BAnchorOffset="217" DT_VCENTER="1" DT_CENTER="0" BGColor="white" TextColor="UI_BtnTextHoloNormal" NormalTextColor="UI_BtnTextBlueNormal" PressedTextColor="UI_BtnTextBluePressed" FlybyTextColor="UI_BtnTextBlueFlyBy" PressedFlybyTextColor="UI_BtnTextBluePressedFlyBy" DisabledTextColor="UI_BtnTextBlueDisabled" TooltipType="OnCursor" Name="ChkCloseWindowsOnMovement" TooltipColor="" Text="Close windows while moving" TextId="" DrawAsCheckbox="1" DrawHotkey="0" Tooltip="Will automatically close all windows interrupting Automatic Mouse Look when any of the movement keys are pressed." GlobalRadioGroup="" RadioDisallowNonSelection="0" ProcessRightClick="0" Border="0" Picture="0" AutoScaleText="0" TooltipId="" CheckboxRight="0">
<Control Class="Button" Base="BK3:btnHolo_Check" Font="CRB_InterfaceMedium" ButtonType="Check" RadioGroup="" LAnchorPoint="0" LAnchorOffset="15" TAnchorPoint="0" TAnchorOffset="182" RAnchorPoint="1" RAnchorOffset="-13" BAnchorPoint="0" BAnchorOffset="217" DT_VCENTER="1" DT_CENTER="0" BGColor="white" TextColor="UI_BtnTextHoloNormal" NormalTextColor="UI_BtnTextBlueNormal" PressedTextColor="UI_BtnTextBluePressed" FlybyTextColor="UI_BtnTextBlueFlyBy" PressedFlybyTextColor="UI_BtnTextBluePressedFlyBy" DisabledTextColor="UI_BtnTextBlueDisabled" TooltipType="OnCursor" Name="ChkCloseWindowsOnMovement" TooltipColor="" Text="Auto close windows when moving" TextId="" DrawAsCheckbox="1" DrawHotkey="0" Tooltip="Will automatically close all windows interrupting Automatic Mouse Look when any of the movement keys are pressed." GlobalRadioGroup="" RadioDisallowNonSelection="0" ProcessRightClick="0" Border="0" Picture="0" AutoScaleText="0" TooltipId="" CheckboxRight="0">
<Event Name="ButtonUncheck" Function="ChkCloseWindowsOnMovement_OnButtonUncheck"/>
<Event Name="ButtonCheck" Function="ChkCloseWindowsOnMovement_OnButtonCheck"/>
</Control>
Expand Down
16 changes: 13 additions & 3 deletions LibLuaUtils.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
local LuaUtils = {}

function table.ShallowCopy(t)
function LuaUtils:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self

-- initialize variables here

return o
end

function LuaUtils:ShallowCopy(t)
local t2 = {}

for k,v in pairs(t) do
Expand All @@ -9,7 +19,7 @@ function table.ShallowCopy(t)
return t2
end

function table.ShallowMerge(table1, intoTable2)
function LuaUtils:ShallowMerge(table1, intoTable2)
for k,v in pairs(table1) do
intoTable2[k] = v
end
Expand Down Expand Up @@ -261,4 +271,4 @@ function LuaUtils:DataDumper(value, varname, fastmode, ident)
end
end

Apollo.RegisterPackage(LuaUtils, "Blaz:Lib:LuaUtils-0.1", 1, {})
Apollo.RegisterPackage(LuaUtils, "Blaz:Lib:LuaUtils-0.2", 1, {})
1 change: 1 addition & 0 deletions toc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<Script Name="LibLuaUtils.lua"/>
<Script Name="LibSimpleLog.lua"/>
<Script Name="ActionControls.lua"/>
<Form Name="ActionControls.xml"/>
</Addon>

0 comments on commit 8852029

Please sign in to comment.