This simple library consolidates various useful tricks and techniques I have picked up over my years of LUA coding and used in various of my addon projects. New functions will be included as needed/requested.
To use the library first add it to your addon manifest: ## DependsOn: LibPhinixFunctions>=9
Then define it somewhere in your addon where you want to use it: local PF = LibPhinixFunctions
Functions can them be called like so:
(Here 'color' and 'text' would be value you pass the function. See below for more info.) PF.TColor(color, text)
Chat commands:
/pfdebug on -Enables debug text output.
/pfdebug off -Disables debug text output (default ).
CURRENT AVAILABLE FUNCTIONS:
PF.SubExtendedASCII(iString) --Convert accented letters to standard ASCII equivalent using extended ASCII lookup table.
Warning: Spoiler
Code:
iString = Input string to convert accented characters from.
local oString (output string) = PF.SubExtendedASCII(iString)
Can also do:
aString = PF.SubExtendedASCII(aString)
PF.Hex2RGB(hex) --Gets { r=r, g=g, b=b, a=a } table for LibAddonMenu colopicker from hex color value.
Warning: Spoiler
Gets the RGB value needed for LibAddonMenu color picker settings from a hex format variable used in text string coloring.
For example, you have a saved variable such as Addon.ASV.textColor = "ffffff" you use to set text labels: Label:SetText("|c"..Addon.ASV.textColor..SomeText.."|r")
If you want to allow users to pick the color used through LibAddonMenu colorpicker you can make the GetFunc Hex2RGB(textColor):
PF.RGB2Hex(rgb) --Gets hex color format string from LibAddonMenu { r=r, g=g, b=b, a=a } colopicker or { [1]=r, [2]=g, [3]=b, [4]=a } saved variable table.
Warning: Spoiler
Works opposite to the above, used for the SetFunc in LibAddonMenu color picker to save the chosen color to a hex variable for use in addons.
Code:
setFunc = function(r, g, b, a)
local color = { r=r, g=g, b=b, a=a }
Addon.ASV.textColor = PF.RGB2Hex(color)
end,
PF.TColor(color, text) --Wraps the color tags with the passed color around the given text.
Warning: Spoiler
color: String, hex format color string, for example "ffffff".
text: The text to format with the given color.
Example: PF.TColor("ff0000", "This is red.")
Returns: "|cff0000This is red.|r"
PF.Contains(nTable, element) --Determined if a given element exists in a given table.
Warning: Spoiler
nTable: Table, source to search for element.
element: String or number to find in the table.
Example: Does the given table contain a key with the given value?
local SourceTable = {[1]="alpha", [2]="beta", [3]="gamma"}
PF.GetKey(nTable, "alpha")
returns: true
PF.GetKey(nTable, element, all) --Returns the table key(s) that contains a given element value.
Warning: Spoiler
nTable: Table, source to search for element.
element: String or number to find in the table.
all: Int, 1 to return first match or 2 for table.
Example 1: Return the key that contains the string (only returns first match of multiple if all = 1 or nil.
local SourceTable = {[1]="alpha", [2]="beta", [3]="gamma"}
PF.GetKey(nTable, "alpha")
returns: 1
Example 2: Return table of keys that contain the value.
local SourceTable = {[1]=3, [2]=2, [3]=1, [4]=3}
PF.GetKey(nTable, 3, 2)
returns: {[1]=true, [4]=true}
Possible use:
Code:
local SourceTable = {[1]=3, [2]=2, [3]=1, [4]=3}
local checkKeys = PF.GetKey(SourceTable, 3, 2)
for k, v in pairs(SourceTable) do
if checkKeys[k] then
d("Key "..k.." contains value 3")
end
end
Prints:
Key 4 contains value 3
Key 1 contains value 3
PF.CountKeys(nTable) --Count the key/value pairs in a hashed table (when #table returns 0).
Warning: Spoiler
nTable: Table, source to search for element.
Example: Count the key/value pairs in a hashed table.
local SourceTable = {["name1"]="alpha", ["name2"]="beta", ["name3"]="gamma"}
PF.CountKeys(nTable)
returns: 3
PF.Round(number, decimals) --Round number to decimals number of places.
Warning: Spoiler
number: The number to round.
decimals: The number of decimals to round to. 0 = Nearest integer.
Example: PF.Round(42.185, 2) = 42.19
NOTE: Value of decimals must be a whole number >= 0.
t12: Int, 1 or nil if you want 12 hour format time return, 2 for 24 hour 'military' time.
dUSA: Int, 1 or nil for USA format date MM-DD-YYYY, 2 for DD-MM-YYYY.
sepH: Int, 1 or nil for '/' date separator, 2 for '-'.
nCap: Int, 1 or nil for lower case 'am/pm' in time string, 2 to capitalize.
Example 1: local datestamp, timestamp = PF.GetDateTime():
Returns: datestamp = 3/12/2019 (string), timestamp = 2:46pm (string)
Example 2: local datestamp, timestamp = PF.GetDateTime(2, 2, 2):
Returns: datestamp = 12-03-2019 (string), timestamp = 14:46 (string)
OPTIONAL: Declare additional variables for day, month, year return.
Example: local datestamp, timestamp, day, month, year = PF.GetDateTime():
Returns: datestamp = 03/12/2019 (string), timestamp = 2:46pm (string), day = 12 (number), month = 3 (number), year = 2019 (number)
PF.GetSorted(sTable, sMode, sFunc) --Returns an indexed table of sorted values based on selection (key/value/sub-value).
Warning: Spoiler
sTable: Table, source table to sort.
sMode:
1: Return sorted table of values.
2: Return sorted table of keys.
string: Return sorted table of sub-values of the given name.
sFunc: Optional custom LUA table.sort function
Example 1: Return sorted table of values.
local SourceTable = {[1]="gamma", [2]="alpha", [3]="beta"}
PF.GetSorted(SourceTable)
returns: {[1]="alpha", [2]="beta", [3]="gamma"}
Example 2: Return sorted table of keys.
local SourceTable = {["gamma"]=1, ["alpha"]=2, ["beta"]=3}
PF.GetSorted(SourceTable, 2)
returns: {[1]="alpha", [2]="beta", [3]="gamma"}
Example 3: Return sorted table of sub-values.
local SourceTable = {[1]={v1="gamma",v2="beta"}, [2]={v1="alpha",v2="delta"}, [3]={v1="charlie",v2="epsilon"}}
PF.GetSorted(SourceTable, "v1")
returns: {[1]="alpha", [2]="charlie", [3]="gamma"}
Example 4: Use custom LUA table.sort function on values.
local SourceTable = {[1]="gamma", [2]="alpha", [3]="beta"}
PF.GetSorted(SourceTable, nil, function(a, b) return a < b end)
returns: {[1]=2, [2]=3, [3]=1}
I hope you find some of these shortcuts helpful!
Gold donations are always welcome!
PC NA: @IllusoryID
Version 16:
- Updated API for Waking Flame update.
Version 15:
- Updated API and version number to Blackwood.
- Removed unnecessary language format code (duplicate of ZOS function).
- Minor code maintenance.
Version 14:
- Updated API for Flames of Ambition.
Version 13:
- Updated API for Stonethorn.
Version 12:
- Slightly modified extended ASCII looking to account for the game treating non-standard ASCII as punctuation and thus stripping letter from non-English clients when using LUA string functions like gsub('%p','') etc.
Version 11:
- Added new function 'SubExtendedASCII' which will accept an input string and return it with extended ASCII accented characters replaced with standard ASCII non-accented equivalents.
- Updated API version for Greymoor.
Version 10:
- Incremented version to avoid possible issues with other versions floating around.
Version 9:
- Updated API for Harrowstorm.
- Properly converted library to not require LibStub.
- Removed deprecated functions & did some maintenance.
Version 8:
- Updated API for Dragonhold.
Version 7:
- Updated API for Scalebreaker.
Version 6:
- API bump for Elsweyr and properly classified as library in manifest.
Version 5:
- Added support for both LibAddonMenu { r=r, g=g, b=b, a=a } colopicker or { [1]=r, [2]=g, [3]=b, [4]=a } saved variable table input format to RGB2Hex function.
Version 4:
- Minor corrections to the time function.
- Modified RGB2Hex to account for out-of-order rgba table input.
Version 3:
- Added new option to sort by custom LUA table.sort function to GetSorted.
Version 2:
- Changed function notation to avoid potential value mismatches.
- Updated safety checks for nil values and other precautions.
- Updated comments to correct typos and better describe usage scenarios.
- Added current status of debug option to no-option /pfdebug command.
Not sure if you knew that but you can stiop using LibStub with new libraries:
You could simply use the games ##AddOnVersion: <signed integer> tag now.
The highest version will be loaded, all other ignored (like LibStub does).
You only need a global variable for your lib defined like LibPhinixFunctions = LibPhinixFunctions or {} to be safe.
Not sure if you knew that but you can stiop using LibStub with new libraries:
You could simply use the games ##AddOnVersion: <signed integer> tag now.
The highest version will be loaded, all other ignored (like LibStub does).
You only need a global variable for your lib defined like LibPhinixFunctions = LibPhinixFunctions or {} to be safe.
Oh, when did that change? Thanks for the info!
The only pain now is I have to go back and change the "local PF = LibStub('LibPhinixFunctions')" to "local PF = LibPhinixFunctions" in about a dozen addons.
Yep, sorry have not seen your lib earlier.
This changed about major 2 patches ago I think.
Be sure to only use an integer value as ##AddOnVersion:.
No decimal places!
e.g.
##AddOnVersion: 1
##AddOnVersion: 11 -- version 1.1 in other notation
##AddOnVersion: 1.1 won't load!
Originally Posted by Phinix
Originally Posted by Baertram
Not sure if you knew that but you can stiop using LibStub with new libraries:
You could simply use the games ##AddOnVersion: <signed integer> tag now.
The highest version will be loaded, all other ignored (like LibStub does).
You only need a global variable for your lib defined like LibPhinixFunctions = LibPhinixFunctions or {} to be safe.
Oh, when did that change? Thanks for the info!
The only pain now is I have to go back and change the "local PF = LibStub('LibPhinixFunctions')" to "local PF = LibPhinixFunctions" in about a dozen addons.
Version 9 with LibStub support but also with global variable
LibPhinixFunctions
-> SavedVariables were renamed to LibPhinixFunctions_SV
Both ESO Master Recipe List and SALTI use LibPhinixFunctions -- and respective UI errors are displayed for each of the two add-ons immediately after the character appears on the HUD. The .../Saved Variables folder currently contains a file named LibPhinixFunctions.lua. It does not contain one named LibPhinixFunctions_SV. Please advise.
I just re-uploaded after incrementing the version number to 10, which should override any other versions out there.
I looked at Baertram's fix he made while I was AFK from modding and it doesn't seem like it should cause problems, but still being dependent on LibStub is asking for compatibility trouble.
The new version I just uploaded does not require LibStub. Please let me know if you still experience errors after updating.
Anyone else keep getting constant UI errors with the latest version of this, to the point of making the game unplayable? Disappeared again after removing this add-on + Master Recipe List which was the only addon I had that depend on this
Anyone else keep getting constant UI errors with the latest version of this, to the point of making the game unplayable? Disappeared again after removing this add-on + Master Recipe List which was the only addon I had that depend on this
Would be probably better if you explain or post which errors you have
Anyone else keep getting constant UI errors with the latest version of this, to the point of making the game unplayable? Disappeared again after removing this add-on + Master Recipe List which was the only addon I had that depend on this
A redundant language formatting function was removed from this library in the last update, and the code of several of my other addons has been changed where they previously used it.
If you updated this library but are still using old versions my other addons (Master Recipe List for example), then it will generate errors as it is attempting to use the function that was removed.
The solution is to ensure all your addons are up to date as this has been resolved in the latest versions of all my addons. I highly recommend downloading Minion (the official esoui.com addon manager) which will let you update all your installed addons easily with the push of a button.
Otherwise it is easy to miss some of them and situations like this can and do emerge from time to time.
Anyone else keep getting constant UI errors with the latest version of this, to the point of making the game unplayable? Disappeared again after removing this add-on + Master Recipe List which was the only addon I had that depend on this
A redundant language formatting function was removed from this library in the last update, and the code of several of my other addons has been changed where they previously used it.
If you updated this library but are still using old versions my other addons (Master Recipe List for example), then it will generate errors as it is attempting to use the function that was removed.
The solution is to ensure all your addons are up to date as this has been resolved in the latest versions of all my addons. I highly recommend downloading Minion (the official esoui.com addon manager) which will let you update all your installed addons easily with the push of a button.
Otherwise it is easy to miss some of them and situations like this can and do emerge from time to time.
Yes, looks like I had overlooked the update to Master Recipe, I had the 1.56.59 version
@HowellQagan - So long as it is removed in a clean way there should be no consequences to addons that were using it. For example, I have removed this dependency from most of my addons (to reduce lib clutter), by adding the functions they use from this lib directly to those addons. In most cases I add them to each addon's global space. For example for in EZReport, I add them in EZMaint.lua as EZReport.TColor, etc. Since EZMaint loads before all other files that use these functions according to the manifest .txt load order, the addon knows where to find them. You just have to then change any instance of "local pTC = LibPhinixFunctions.TColor" to "local pTC = EZReport.Tcolor" or whatever you localize the functions to.
Hope that helps! Also, still don't have Giladil, but would love her on my travels.
@HowellQagan - So long as it is removed in a clean way there should be no consequences to addons that were using it.
Nice, thanks.
Originally Posted by Phinix
Also, still don't have Giladil, but would love her on my travels.
Well... it turns out that it tracks the gifting eligibility not per account but per server... ZOS be fkin weird sometimes with their logic. Never made any characters on NA so now I have to wait 30 days to be able to gift... ggwp
@HowellQagan - Wow that's a little annoying. I appreciate your willingness to go through all the hassle. I will imagine Giladil is on a boat back from her ragpicking excursions abroad, and ETA a month or so she'll be back for many ragpicking adventures back on Tamriel.
HELP REQUESTED! Creating, maintaining, and providing patch-day compatibility with in-game troubleshooting and prompt feedback for so many projects really is a full time job. The support I receive from the community is what keeps me going, and it is the only form of compensation I receive. Not only will your contribution enable more feature additions and personalized support for my existing projects, but it will sponsor new exciting content in the future, which will remain now and forever free for all to enjoy! There are several ways you can contribute, either directly through Paypal or Ko-Fi, by subscribing to my Patreon, or through the GoFundMe page I set up for my dad. All contributions are deeply appreciated and sorely needed. Thanks from our family to yours, and I hope something I made helps enhance your enjoyment of the Elder Scrolls Online.