diff SkeletonKey/ActionTypes.lua @ 16:cdd387d39137

filename refactor
author Nenue
date Fri, 29 Jul 2016 21:18:15 -0400
parents
children 500f9b2bd9ac
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SkeletonKey/ActionTypes.lua	Fri Jul 29 21:18:15 2016 -0400
@@ -0,0 +1,79 @@
+-- SkeletonKey
+-- ActionTypes.lua
+-- Created: 7/29/2016 9:14 PM
+-- %file-revision%
+--
+local kb, print, wrap = LibStub('LibKraken').register(KeyBinder)
+
+local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
+
+local PETACTION_SCRIPT = {
+  [PET_ACTION_MOVE_TO] = {SLASH_PET_MOVE_TO1, 'pet_move_to'},
+  [PET_ACTION_ATTACK] = {SLASH_PET_ATTACK1, 'pet_attack'},
+  [PET_ACTION_FOLLOW] = {SLASH_PET_FOLLOW1, 'pet_follow'},
+  [PET_ACTION_WAIT] = {SLASH_PET_STAY1, 'pet_stay'},
+  [PET_MODE_AGGRESSIVE] = {SLASH_PET_AGGRESSIVE1, 'pet_aggressive'},
+  [PET_MODE_DEFENSIVE] = {SLASH_PET_DEFENSIVE1, 'pet_defensive'},
+  [PET_MODE_PASSIVE] = {SLASH_PET_PASSIVE1, 'pet_passive'},
+  [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'},
+}
+
+--- Caps Lock derivatives
+local ACTION_HANDLERS = {}
+ACTION_HANDLERS['mount'] = function(id, name)
+  return "/script C_MountJournal.SummonByID("..id..")"
+end
+ACTION_HANDLERS['macro'] = "%s"
+ACTION_HANDLERS['equipset'] = "/script UseEquipmentSet(%d)"
+ACTION_HANDLERS['spell'] = "/cast %s"
+ACTION_HANDLERS['petaction'] = function(id, name)
+  return PETACTION_SCRIPT[name] or "/cast ".. name
+end
+
+ACTION_HANDLERS['battlepet'] = SLASH_SUMMON_BATTLE_PET1 .. " %s"
+ACTION_HANDLERS['item'] = "/use %s"
+local professionMappings = {
+  [5] = 3,
+  [7] = 4,
+  [9] = 5,
+  [10] = 6
+}
+
+
+--- Generates the command strings needed to assign different abilities
+kb.RegisterAction = function(actionType, id, name)
+  local macroText, macroName, command = '', '', ''
+
+  if actionType == 'spell' then
+    if kb.ProfessionCache[id] then
+      command = CLICK_KEYBINDER_KEY .. "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum
+    else
+      command = CLICK_KEYBINDER_KEY ..name
+    end
+  else
+
+    if type(ACTION_SCRIPT[actionType]) == 'function' then
+      macroName, macroText = ACTION_SCRIPT[actionType](id, name)
+    else
+      macroName = actionType .. ' ' .. name
+      macroText = ACTION_SCRIPT[actionType]:format(name)
+    end
+
+    local baseName, iterative = macroName, 1
+    while (macros[macroName] and macros[macroName][1] ~= macroText) do
+      print(' * cannot use|cFF00FF00', macroName, '|r"'.. (macros[macroName][1] or '') .. '"')
+      macroName = baseName .. '_' .. iterative
+      iterative = iterative + 1
+    end
+    if macroName ~= baseName then
+      print(' * Creating|cFF00FF00', macroName)
+    else
+      print(' * Re-using|cFF00FF00', macroName)
+    end
+    command = 'CLICK KeyBinderMacro:'.. macroName
+    macros[macroName] = {macroText, command }
+  end
+
+  print('RegisterAction', actionType, id, '->', command , macroText)
+  return macroName, macroText, command
+end
\ No newline at end of file