WoWInterface SVN SimpleCalc

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /trunk
    from Rev 1 to Rev 2
    Reverse comparison

Rev 1 → Rev 2

SimpleCalc/README.txt New file
0,0 → 1,43
SimpleCalc - Copyright (c) 2008 GuildWorks.co.uk
 
--[ Description ]--
 
SimpleCalc is a simple mathematical calculator addon for World of Warcraft.
In essence, it's a slash-based utility which allows you to do maths!
 
Example usage and response:
 
/calc 10415 - 9843 + 12
[SimpleCalc] 10415 - 9843 + 12 = 584
 
A selection of in-game values has been added to make life easier when doing certain calculations. You can use keywords in place of numbers for the following values:
 
* honour / honor - Total honour points available to spend
* justice (or jp) - Total justice points available to spend
* valor (or vp) - Total valor points available to spend
* conquest (or cp) - Total conquest points available to spend
* vpcap - Amount of valor that can be earned that week
* cpcap - Amount of conquest that can be earned that week
* achieves (or ap) - Your total achieve points
* health - Your maximum Health points
* mana (or power) - Your maximum Mana, Rage, Focus, Energy, or Runic Power
* gold - Total gold (1g 50s would be displayed as 1.5 gold)
* silver - Total silver (1g 50s would be displayed as 150 silver)
* copper - Total copper (1g 50s would be displayed as 15,000 copper)
 
For example:
 
/calc 1650 + 2200 - honour
[SimpleCalc] 1650 + 2200 - honour = 3078
 
SimpleCalc works on equations left to right, so '10 * 3 + 2' would be broken
down into two sums: '10 * 3', then '30 + 2'. Support for brackets is not yet
in place, but this shouldn't affect every day calculations.
 
Comments, suggestions and bug reports are most welcome!
 
 
--[ License ]--
 
SimpleCalc is provided under the MIT license. In essence, do what you will
with this software, but please give credit to the original author.
SimpleCalc/SimpleCalc.xml New file
0,0 → 1,9
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
<Frame>
<Scripts>
<OnLoad>
SimpleCalc_OnLoad(self);
</OnLoad>
</Scripts>
</Frame>
</Ui>
SimpleCalc/SimpleCalc.lua New file
0,0 → 1,206
-- Initialise SimpleCalc
scversion = GetAddOnMetadata("SimpleCalc", "Version");
function SimpleCalc_OnLoad(self)
 
-- Register our slash commands
SLASH_SIMPLECALC1="/simplecalc";
SLASH_SIMPLECALC2="/calc";
SlashCmdList["SIMPLECALC"]=SimpleCalc_ParseParameters;
 
-- Initialise our variables
if (not calcVariables) then
calcVariables={};
end
 
-- Let the user know that we're here
DEFAULT_CHAT_FRAME:AddMessage("[+] SimpleCalc (v "..scversion..") initiated! Type: /calc for help.", 1, 1, 1);
 
-- Request Conquest Point info from server
RequestPVPRewards()
end
 
-- Parse any user-passed parameters
function SimpleCalc_ParseParameters(paramStr)
 
local params={};
 
local i=0;
local a=nil;
local b=nil;
local result=0;
local paramCount=0;
local GetArenaCurrency = function() return select(2,GetCurrencyInfo(390)) or 0 end
local GetHonorCurrency = function() return select(2,GetCurrencyInfo(392)) or 0 end
local GetJusticeCurrency = function() return select(2,GetCurrencyInfo(395)) or 0 end
local GetValorCurrency = function() return select(2,GetCurrencyInfo(396)) or 0 end
local GetValorCap = function() return select(5,GetCurrencyInfo(396))/100 - select(4,GetCurrencyInfo(396)) or 0 end
local GetArenaCap = function() return select(2,GetPVPRewards()) - select(1,GetPVPRewards()) or 0 end
RequestPVPRewards()
 
paramStr=string.lower(paramStr);
for param in string.gmatch(paramStr, "[^%s]+") do
 
i=i+1;
paramCount=paramCount+1;
 
-- Make sure that we've been passed a number or a variable
if (i==1 or i==3) then
-- Take a copy of our parameter
if (i==1) then
paramOriginal=param;
end
-- Check whether we have a number
if (string.match(param, '[^%d\.-]')) then
-- If we have something other than a number, see whether it's a recognised game value
if (param=='honour' or param=='honor') then
param=GetHonorCurrency();
elseif (param=='conquest' or param=='cp') then
param=GetArenaCurrency();
elseif (param=='jp' or param=='justice') then
param=GetJusticeCurrency();
elseif (param=='valor' or param=='vp') then
param=GetValorCurrency();
elseif (param=='vpcap') then
param=GetValorCap();
elseif (param=='cpcap') then
param=GetArenaCap();
elseif (param=='achieves' or param=='ap') then
param=GetTotalAchievementPoints();
elseif (param=='health') then
param=UnitHealthMax('player')
elseif (param=='power' or param=='mana') then
param=UnitPowerMax('player')
elseif (param=='copper') then
param=GetMoney();
elseif (param=='silver') then
param=GetMoney() / 100;
elseif (param=='gold') then
param=GetMoney() / 10000;
elseif (calcVariables[param]) then -- Check whether this is a user defined variable
param=calcVariables[param];
end
end
end
 
if (i==1) then
a=param;
elseif (i==2) then
symbol=param;
elseif (i==3) then
b=param;
 
-- Make sure that we're dealing with numbers
if (symbol~='=' and not tonumber(a)) then
SimpleCalc_Error(paramStr .. ': \'' .. a .. '\' isn\'t a recognised variable, and doesn\'t look like a number!');
return false
elseif (symbol~='=' and not tonumber(b)) then
SimpleCalc_Error(paramStr .. ': \'' .. b .. '\' isn\'t a recognised variable, and doesn\'t look like a number!');
return false
end
 
-- Perform the operation
-- Can't find any way around doing things this way...
if (symbol=='+') then
result=a + b;
elseif (symbol=='-') then
result=a - b;
elseif (symbol=='*') then
result=a * b;
elseif (symbol=='/') then
result=a / b;
elseif (symbol=='^') then
result=a ^ b;
elseif (symbol=='=' and paramCount==3) then
-- Make sure that we're dealing with a number
if (tonumber(b)==nil) then
SimpleCalc_Error('Can\'t set value \'' .. b .. '\' as it doesn\'t look like a number!');
return false
end
calcVariable = paramOriginal;
result = b;
elseif (symbol=='=') then
SimpleCalc_Error('When setting variables, the variable name must be the first parameter');
else
SimpleCalc_Error('Unrecognised symbol: ' .. symbol);
if (symbol=='x') then
SimpleCalc_Error('Perhaps you meant '*' (multiply)?');
end
return false;
end
 
-- Reset for another loop
i=1;
symbol=nil;
a=result;
b=nil;
 
end
 
end
 
if (symbol and not b) then
SimpleCalc_Error('Unbalanced parameter count. Trailing symbol: ' .. symbol .. '?');
end
 
if (paramCount >= 3) then
if (not calcVariable) then
SimpleCalc_Message(paramStr .. ' = ' .. numberFormat(result));
elseif (calcVariable) then
-- Show any calculations performed
if (paramCount > 3) then
paramStr=string.sub(paramStr, string.find(paramStr, '= ') + 2);
SimpleCalc_Message(paramStr .. ' = ' .. numberFormat(result));
end
-- Set or unset the variable and inform the user
if (result ~= 0) then
calcVariables[calcVariable]=result;
SimpleCalc_Message('Set ' .. calcVariable .. ' to ' .. numberFormat(result));
else
calcVariables[calcVariable]=nil;
SimpleCalc_Message('Unset variable ' .. calcVariable);
end
calcVariable=nil;
end
elseif (calcVariables[paramStr]) then
SimpleCalc_Message('Variable \'' .. paramStr .. '\' is set to ' .. numberFormat(calcVariables[paramStr]));
else
SimpleCalc_Usage();
end
 
end
 
 
-- Inform the user of our their options
function SimpleCalc_Usage()
SimpleCalc_Message("SimpleCalc (v "..scversion..") - Simple mathematical calculator");
SimpleCalc_Message("Usage: /calc <value> <symbol> <value>");
SimpleCalc_Message("Usage: /calc <variable> = <value>");
SimpleCalc_Message("Example: 1650 + 2200 - honor (note the spaces)");
SimpleCalc_Message("value - A numeric or game value (honor, conquest, valor, justice, health, mana (or power), copper, silver, gold)");
SimpleCalc_Message("symbol - A mathematical symbol (+, -, /, *, ^)");
SimpleCalc_Message("variable - A name to store a value under for future use");
end
 
-- Output errors
function SimpleCalc_Error(message)
DEFAULT_CHAT_FRAME:AddMessage("[SimpleCalc] " .. message, 0.8, 0.2, 0.2);
end
 
 
-- Output messages
function SimpleCalc_Message(message)
DEFAULT_CHAT_FRAME:AddMessage("[SimpleCalc] " .. message, 0.5, 0.5, 1);
end
 
 
-- Number formatting function, taken from http://lua-users.org/wiki/FormattingNumbers
function numberFormat(amount)
local formatted=amount;
while true do
formatted, k=string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2');
if (k==0) then
break;
end
end
return formatted;
end
\ No newline at end of file
SimpleCalc/LICENSE.txt New file
0,0 → 1,22
Copyright (c) 2008 GuildWorks.co.uk
 
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
 
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
SimpleCalc/SimpleCalc.toc New file
0,0 → 1,8
## Interface: 40300
## Title: SimpleCalc
## Notes: A simple mathematical calculator. Type /calc for help!
## SavedVariables: calcVariables
## Author: guildworks (Updated by Bruescrues)
## Version: 0.6b
SimpleCalc.lua
SimpleCalc.xml