Skip to content

Commit

Permalink
Initial working prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcraig committed May 28, 2019
0 parents commit 5db3fa9
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.lua]
indent_style = space
indent_size = 2
7 changes: 7 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# These are supported funding model platforms

github: davidcraig # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: privatesniper
open_collective: # Replace with a single Open Collective username
ko_fi: privatesniper
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SniperTips_HunterPetFood

Adds quality ratings to food items in bags based on how much happiness they provide to your current pet.
8 changes: 8 additions & 0 deletions SniperTips_HunterPetFood.toc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Interface: 80100
## Version: 1.0.0
## Title: SniperTips_HunterPetFood
## Author: PrivateSniper
## Notes: Adds hunter pet information about food to tooltips.
## Dependencies: Ace3, SniperTips

main.lua
150 changes: 150 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
local SniperTips_HunterPetFood = LibStub("AceAddon-3.0"):NewAddon('SniperTips_HunterPetFood');
local LibTooltip = LibStub("SniperTips-1.0");
local tipColour = { 0.6, 0.2, 0.2 }
SniperTips_HunterPetFood.kbDEBUG = true

SniperTips_HunterPetFood.Globals = {
["TitleColour"] = {
["escape"] = "|cFFABD473",
["rgb"] = { 0.67, 0.83, 0.45 },
["rgba"] = { 0.67, 0.83, 0.45, 1 },
},
-- 170, 141, 114
["Ratings"] = {
["NA"] = {
["escape"] = "|cFF9D9D9D",
["rgba"] = { 0.62, 0.62, 0.62, 1 }
},
["Bad"] = {
["escape"] = "|cFFFFFFFF",
["rgba"] = { 1.00, 1.00, 1.00, 1 }
},
["Good"] = {
["escape"] = "|cFF00A7DD",
["rgba"] = { 0.00, 0.44, 0.87, 1 }
},
["Epic"] = {
["escape"] = "|cFFA335EE",
["rgba"] = { 0.64, 0.21, 0.93, 1 }
}
},
["NA"] = "N/A",
["Bad"] = "Bad",
["Good"] = "Good",
["Epic"] = "Epic",
}

function SniperTips_HunterPetFood:Dump(str, obj)
if ViragDevTool_AddData and SniperTips_HunterPetFood.kbDEBUG then
ViragDevTool_AddData(obj, str)
end
end

---------------------------------------------------
-- Methods to determine if the addon should load --
---------------------------------------------------

-- Only load the addon if on a classic realm.
function SniperTips_HunterPetFood:IsClassicRealm()
-- Game is classic if GetPetHappiness global function exists.
if _G['GetPetHappiness'] ~= nil then
return true
end

-- return false -- TODO: once happy with classic logic
return true
end

--Only load the addon if player is a hunter
function SniperTips_HunterPetFood:PlayerClassIsHunter()
_, englishClass, _ = UnitClass('player');
return englishClass == 'HUNTER'
end

-- Combine the above two checks into a single function.
function SniperTips_HunterPetFood:AddonShouldLoad()
return SniperTips_HunterPetFood:PlayerClassIsHunter() and SniperTips_HunterPetFood:IsClassicRealm()
end

----------------
-- Core Logic --
----------------

function SniperTips_HunterPetFood:HandleItem(self, itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType,
itemSubType, itemStackCount, itemEquipLoc, itemIcon, itemSellPrice, itemClassID, itemSubClassID, bindType, expacID,
itemSetID, isCraftingReagent)

-- Get the item ID
local id = string.match(itemLink, "item:(%d*)")

local rating, ratingColour = SniperTips_HunterPetFood:GetFoodRating(id)

SniperTips_HunterPetFood:Dump('rating', rating)

if (rating ~= nil and ratingColour ~= nil) then
--self:AddDoubleLine("Food Rating: ",rating,unpack(SniperTips_HunterPetFood.Globals.TitleColour),unpack(ratingColour));
self:AddDoubleLine(
SniperTips_HunterPetFood.Globals.TitleColour.escape.."Food Rating: ",
ratingColour..rating
);
end
end

----------------------
-- Hunter Pet Logic --
----------------------

function SniperTips_HunterPetFood:GetFoodRating(itemId)
local petExists = UnitExists("pet")
local petFoodRatings = {
["Boar"] = {
-- TODO: !important: 20 and 60 are placeholder values
["2681"] = { ["good"] = 13, ["bad"] = 22, ["na"] = 60 },
["117"] = { ["good"] = 13, ["bad"] = 22, ["na"] = 60 },
},
["Wolf"] = {
-- TODO: Also placeholder values for development
["2681"] = { ["good"] = 13, ["bad"] = 22, ["na"] = 60 },
["769"] = { ["good"] = 13, ["bad"] = 22, ["na"] = 60 },
}
}

if (petExists) then
-- Get the pet type: eg. Boar
local petType = UnitCreatureFamily("pet");
-- Get the pet level.
local petLevel = UnitLevel("pet");

-- Lookup the item id against the pet type
ratings = petFoodRatings[petType][itemId] or nil;

if (ratings ~= nil) then
-- return the rating (coloured)
if (petLevel >= ratings.na) then
rating = SniperTips_HunterPetFood.Globals.NA
ratingColour = SniperTips_HunterPetFood.Globals.Ratings.NA.escape
elseif (petLevel >= ratings.bad) then
rating = SniperTips_HunterPetFood.Globals.Bad
ratingColour = SniperTips_HunterPetFood.Globals.Ratings.Bad.escape
elseif (petLevel >= ratings.good) then
rating = SniperTips_HunterPetFood.Globals.Good
ratingColour = SniperTips_HunterPetFood.Globals.Ratings.Good.escape
else
rating = SniperTips_HunterPetFood.Globals.Epic
ratingColour = SniperTips_HunterPetFood.Globals.Ratings.Epic.escape
end

return rating, ratingColour
end
end

return nil, nil
end

------------------
-- Registration --
------------------

if (SniperTips_HunterPetFood:AddonShouldLoad()) then
LibTooltip:AddItemHandler(SniperTips_HunterPetFood)
end
4 changes: 4 additions & 0 deletions pkgmeta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ignore:
- README.md
- .editorconfig
- .github

0 comments on commit 5db3fa9

Please sign in to comment.