Fixed saving of weights that don't exactly convert to binary
Kevin Lyles [07-29-10 - 00:10]
Fixed saving of weights that don't exactly convert to binary
Fixed validateNumber
Bumped version to 1.2b10
diff --git a/WeightsWatcher.toc b/WeightsWatcher.toc
index 59444be..e8ec3ec 100644
--- a/WeightsWatcher.toc
+++ b/WeightsWatcher.toc
@@ -2,7 +2,7 @@
## Title: Weights Watcher
## Notes: Ranks gear according to customizable stat weights
## Author: The Flying Squirrels
-## Version: 1.2b9
+## Version: 1.2b10
## OptionalDeps: AtlasLoot
## SavedVariables: ww_vars
## SavedVariablesPerCharacter: ww_charVars
diff --git a/weights.lua b/weights.lua
index 6813f15..f6ab71b 100644
--- a/weights.lua
+++ b/weights.lua
@@ -2,13 +2,13 @@ function ww_validateNumber(newChar, newText)
if string.find(newChar, "^%d$") then
return true
elseif newChar == '.' then
- local first = newText:find("%.", 1, true)
- local second = newText:find("%.", first + 1, true)
+ local first = newText:find(".", 1, true)
+ local second = newText:find(".", first + 1, true)
if not second then
return true
end
elseif newChar == '-' then
- if not string.find(newText, "%-", 2) then
+ if not string.find(newText, "-", 2, true) then
return true
end
end
@@ -211,7 +211,7 @@ function ww_configSaveWeight()
if ww_weights.rightPanel.changedStats then
for statValue, statName in pairs(ww_weights.rightPanel.changedStats) do
- number = statValue:GetNumber()
+ number = tonumber(statValue:GetText())
if number == 0 then
number = nil
end
diff --git a/weights.xml b/weights.xml
index 91f2d24..545bbc3 100644
--- a/weights.xml
+++ b/weights.xml
@@ -187,10 +187,13 @@
</OnLoad>
<OnTextChanged>
local text = self:GetText()
- if self:GetNumber() ~= 0 or text:match("^[0.]+$") or text == "" then
- self.number = text
+ local number = tonumber(text)
+ if number then
+ self.number = number
+ elseif text:match("^[0.]*$") then
+ self.number = 0
end
- if self:GetNumber() == ww_weights.rightPanel.statList[self:GetParent().statName] or (self:GetNumber() == 0 and not ww_weights.rightPanel.statList[self:GetParent().statName]) then
+ if number == ww_weights.rightPanel.statList[self:GetParent().statName] or (number == 0 and ww_weights.rightPanel.statList[self:GetParent().statName] == nil) then
ww_weights.rightPanel.changedStats[self] = nil
local changed = false
for _ in pairs(ww_weights.rightPanel.changedStats) do
@@ -213,7 +216,7 @@
</OnTextChanged>
<OnChar>
if ww_validateNumber(text, self:GetText()) then
- self.number = self:GetText()
+ self.number = tonumber(self:GetText()) or 0
else
local cursorPosition = self:GetCursorPosition() - 1
self:SetText(self.number)