changeset 50:22011265a16f 1.2.0-b1

Updated and fixed for draenor xpack (patch 6.0) API changes
author syzler
date Sat, 07 Mar 2015 02:52:57 -0500
parents d29ceeeab123
children 9d3c8c1e84f3
files MyLilPony.lua MyLilPony.toc libMyLilPony/libMyLilPony_miscFunctions.lua libMyLilPony/libMyLilPony_mountFunctions.lua
diffstat 4 files changed, 80 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/MyLilPony.lua	Fri Sep 21 01:50:56 2012 -0400
+++ b/MyLilPony.lua	Sat Mar 07 02:52:57 2015 -0500
@@ -158,7 +158,7 @@
         end
     elseif MyLilPony.StringMatchIgnoreCase(arg, "^exact .+$")
         or MyLilPony.StringMatchIgnoreCase(arg, "^x .+$") then
-        local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$");
+        local param = MyLilPony.StringMatch(arg, "^[^ ]+ (.+)$");
         local result = MyLilPony.CallMountByName(param);
         if not result then
             MyLilPony.Log(format(L["msgNoMatchingMountsForName"], param));
@@ -166,7 +166,7 @@
     elseif MyLilPony.StringMatchIgnoreCase(arg, "^list .+$")
         or MyLilPony.StringMatchIgnoreCase(arg, "^find .+$")
         or MyLilPony.StringMatchIgnoreCase(arg, "^l .+$") then
-        local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$");
+        local param = MyLilPony.StringMatchIgnoreCase(arg, "^[^ ]+ (.+)$");
         local result = MyLilPony.ListMountsByPattern(param);
         if not result then
             MyLilPony.Log(format(L["msgNoMatchingMountsForPattern"], param));
--- a/MyLilPony.toc	Fri Sep 21 01:50:56 2012 -0400
+++ b/MyLilPony.toc	Sat Mar 07 02:52:57 2015 -0500
@@ -1,4 +1,4 @@
-## Interface: 50001
+## Interface: 60100
 ## Title: MyLilPony
 ## Version: @project-version@
 ## Author: Syzler
--- a/libMyLilPony/libMyLilPony_miscFunctions.lua	Fri Sep 21 01:50:56 2012 -0400
+++ b/libMyLilPony/libMyLilPony_miscFunctions.lua	Sat Mar 07 02:52:57 2015 -0500
@@ -51,6 +51,16 @@
     return buffs;
 end
 
+--- Performs case-sensitive string pattern matching.
+-- @param subject The string on which the pattern matching is performed.
+-- @param pattern The pattern to be matched.
+-- @returns The match result captures, the entire string if there are no captures, or nil if the subject is not a match.
+function MyLilPony.StringMatch(subject, pattern)
+    if subject == nil and pattern == nil then return true end
+    if subject == nil or pattern == nil then return false end
+    return string.match(subject, pattern);
+end
+
 --- Performs case-insensitive string pattern matching.
 -- @param subject The string on which the pattern matching is performed.
 -- @param pattern The pattern to be matched.
@@ -63,13 +73,29 @@
     return string.match(lSub, lPat);
 end
 
---- Calls a companion if a specified condition checks out.
--- @param companionType The type of companion to be called (e.g. "MOUNT").
--- @param companionNumber The slot number of the companion to be called.
+--- Calls a mount if a specified condition checks out.
+-- @param unused The type of companion to be called (e.g. "MOUNT").
+-- @param slotID The slot ID of the mount to be called.
 -- @param condition An optional Boolean condition.
-function MyLilPony.CallCompanion(companionType, companionNumber, condition)
+function MyLilPony.CallCompanion(unused, slotID, condition)
     if condition == nil or condition then
-        CallCompanion(companionType, companionNumber);
+        C_MountJournal.Summon(slotID);
+    end
+end
+
+--- Iterates over all known and non-hidden (i.e. not dead or opposite faction) mount slot IDs.
+-- @return A list of valid mount slot IDs.
+function MyLilPony.EnumerateKnownMountSlotIDs()
+    local countMounts = C_MountJournal.GetNumMounts();
+    local x = 1;
+    return function()
+        for i = x, countMounts do
+            local _, _, _, _, _, _, _, _, _, hidden, known = C_MountJournal.GetMountInfo(i);
+            if known and not hidden then
+                x = i + 1;
+                return i;
+            end
+        end
     end
 end
 
--- a/libMyLilPony/libMyLilPony_mountFunctions.lua	Fri Sep 21 01:50:56 2012 -0400
+++ b/libMyLilPony/libMyLilPony_mountFunctions.lua	Sat Mar 07 02:52:57 2015 -0500
@@ -42,7 +42,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMount()
     local filter = function (i)
-        local _, _, _, _, summoned = GetCompanionInfo("MOUNT", i);
+        local _, _, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned;
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -53,7 +53,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallFlyingMount()
     local filter = function (i)
-        local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned and MyLilPony.IsFlyingMount(id);
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -64,7 +64,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallGroundMount()
     local filter = function (i)
-        local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned and MyLilPony.IsGroundMount(id);
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -75,7 +75,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallAquaticMount()
     local filter = function (i)
-        local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned and MyLilPony.IsAquaticMount(id);
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -86,9 +86,9 @@
 -- @param slotNumber The slot number of the desired mount in the mount spellbook.
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountBySlot(slotNumber)
-    local countMounts = GetNumCompanions("MOUNT");
+    local countMounts = C_MountJournal.GetNumMounts();
     if slotNumber > 0 and slotNumber < countMounts+1 then
-        local _, _, _, _, summoned = GetCompanionInfo("MOUNT", slotNumber);
+        local _, _, _, summoned = C_MountJournal.GetMountInfo(i);
         MyLilPony.CallCompanion("MOUNT", slotNumber, not summoned);
         return true;
     end
@@ -101,9 +101,8 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountByName(mountName)
     local result = false;
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name, _, _, summoned = C_MountJournal.GetMountInfo(i);
         if name == mountName then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -120,7 +119,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountByPattern(mountNamePattern)
     local filter = function (i)
-        local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
+        local name, _, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern);
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -132,9 +131,9 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountById(id)
     local result = false;
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local creatureId, _, spellId, _, summoned = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local _, spellId, _, summoned = C_MountJournal.GetMountInfo(i);
+        local creatureId = C_MountJournal.GetMountInfoExtra(i);
         if id == creatureId or id == spellId then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -150,9 +149,8 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountBySpell(spellId)
     local result = false;
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         if id == spellId then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -168,9 +166,9 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountByCreature(creatureId)
     local result = false;
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local id, _, _, _, summoned = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local _, _, _, summoned = C_MountJournal.GetMountInfo(i);
+        local id = C_MountJournal.GetMountInfoExtra(i);
         if id == creatureId then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -190,9 +188,8 @@
 function MyLilPony.CallMountByMatch(unit)
     local result = false;
     local unitBuffs = MyLilPony.GetUnitBuffs(unit);
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         if unitBuffs[id] ~= nil then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -207,41 +204,38 @@
 -- @param filter A filter callback function which takes a single mount slot number and returns a Boolean value indicating whether or not the the indicated mount should be included.
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 -- @usage local filter = function (i)
---     local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
---     return not summoned and string.match(name, pattern);
+--     local name = C_MountJournal.GetMountInfo(i);
+--     return string.match(name, pattern);
 -- end
 -- MyLilPony.CallMountByFilter(filter);
 function MyLilPony.CallMountByFilter(filter)
-    local countMounts = GetNumCompanions("MOUNT");
-    if countMounts > 0 then
-        local results = {};
-        local countResults = 0;
-        
-        for i = 1, countMounts do
-            if filter(i) then
-                countResults = countResults + 1;
-                results[countResults] = i;
-            end
+    local mounts = {};
+    local x = 0;
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        if filter(i) then
+            x = x + 1;
+            mounts[x] = i;
         end
+    end
     
-        if countResults > 0 then
-            local i = random(1, countResults);
-            local _, _, _, _, summoned = GetCompanionInfo("MOUNT", results[i]);
-            MyLilPony.CallCompanion("MOUNT", results[i], not summoned);
-            return true;
-        end
+    if x > 0 then
+        local i = mounts[random(1, x)];
+        local _, _, _, summoned =  C_MountJournal.GetMountInfo(i);
+        MyLilPony.CallCompanion("MOUNT", i, not summoned);
+        return true;
     end
     return false;
 end
 
 --- Lists available mounts by name.
--- @return A list of mount names. Since this function returns all known mounts, the index of each entry in the list is also the mount's slot number.
+-- @return A list of mount names.
 function MyLilPony.ListMounts()
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
+    local x = 1;
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name = C_MountJournal.GetMountInfo(i);
         results[i] = name;
+        x = x + 1;
     end
     return results;
 end
@@ -250,10 +244,9 @@
 -- @return A list of ground mount names.
 function MyLilPony.ListGroundMounts()
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
     local x = 1;
-    for i = 1, countMounts do
-        local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name, id = C_MountJournal.GetMountInfo(i);
         if MyLilPony.IsGroundMount(id) then
             results[x] = name;
             x = x + 1;
@@ -266,10 +259,9 @@
 -- @return A list of flying mount names.
 function MyLilPony.ListFlyingMounts()
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
     local x = 1;
-    for i = 1, countMounts do
-        local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name, id = C_MountJournal.GetMountInfo(i);
         if MyLilPony.IsFlyingMount(id) then
             results[x] = name;
             x = x + 1;
@@ -282,10 +274,9 @@
 -- @return A list of aquatic mount names.
 function MyLilPony.ListAquaticMounts()
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
     local x = 1;
-    for i = 1, countMounts do
-        local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name, id = C_MountJournal.GetMountInfo(i);
         if MyLilPony.IsAquaticMount(id) then
             results[x] = name;
             x = x + 1;
@@ -299,10 +290,9 @@
 -- @return A list of matching mount names.
 function MyLilPony.ListMountsByPattern(mountNamePattern)
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
     local x = 1;
-    for i = 1, countMounts do
-        local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name = C_MountJournal.GetMountInfo(i);
         if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then
             results[x] = name;
             x = x + 1;
@@ -310,4 +300,3 @@
     end
     return results;
 end
-