Quantcast

Made most possible functions and variables local (and rearranged them if necessary)

Kevin Lyles [06-20-10 - 02:53]
Made most possible functions and variables local (and rearranged them if necessary)
Filename
GemIds.lua
Upgrade.lua
WeightsWatcher.lua
config.lua
weights.lua
diff --git a/GemIds.lua b/GemIds.lua
index 2a48d56..dbbc3cc 100644
--- a/GemIds.lua
+++ b/GemIds.lua
@@ -3037,18 +3037,18 @@ GemIds = {
 	},
 }

-GemQualities = {}
+local GemQualities = {}

 for gemSource, gems in pairs(GemIds) do
 	for gemType, gems in pairs(gems) do
 		for gemQuality, gems in pairs(gems) do
 			for gemId, gemInfo in pairs(gems) do
 				GemQualities[gemId] = {
-						source = gemSource,
-						type = gemType,
-						quality = gemQuality,
-						info = gemInfo,
-					}
+					source = gemSource,
+					type = gemType,
+					quality = gemQuality,
+					info = gemInfo,
+				}
 			end
 		end
 	end
diff --git a/Upgrade.lua b/Upgrade.lua
index 6f92854..2f36d76 100644
--- a/Upgrade.lua
+++ b/Upgrade.lua
@@ -1,86 +1,3 @@
-function WeightsWatcher.Upgrade(dataType)
-	local oldMinorVersion, oldMajorVersion, newMinorVersion, newMajorVersion, vars, funcTable, direction, downgradeFunctions
-
-	if dataType == "account" then
-		vars = ww_vars
-		newMinorVersion = defaultVars.dataMinorVersion
-		newMajorVersion = defaultVars.dataMajorVersion
-		funcTable = upgradeAccountFunctions
-		downgradeFunctions = downgradeAccountFunctions
-	elseif dataType == "character" then
-		vars = ww_charVars
-		newMinorVersion = defaultCharVars.dataMinorVersion
-		newMajorVersion = defaultCharVars.dataMajorVersion
-		funcTable = upgradeCharFunctions
-		downgradeFunctions = downgradeCharFunctions
-	else
-		print("WeightsWatcher: error: invalid data type \"" .. dataType .. "\" passed to Upgrade().")
-		return nil
-	end
-
-	if vars then
-		oldMinorVersion = vars.dataMinorVersion
-		oldMajorVersion = vars.dataMajorVersion
-	end
-	if not oldMinorVersion then
-		oldMinorVersion = 0
-	end
-	if not oldMajorVersion then
-		oldMajorVersion = 0
-	end
-
-	if newMajorVersion == oldMajorVersion and newMinorVersion == oldMinorVersion then
-		return vars
-	end
-
-	if newMajorVersion > oldMajorVersion or (newMajorVersion == oldMajorVersion and newMinorVersion > oldMinorVersion) then
-		direction = "up"
-	else
-		direction = "down"
-		funcTable = stringsToFuncs(vars.downgradeFunctions)
-	end
-
-	if funcTable == nil then
-		print("WeightsWatcher: error: no " .. direction .. "grade function table found.")
-		return nil
-	end
-
-	if oldMajorVersion == 0 and oldMinorVersion == 0 then
-		print("WeightsWatcher: no " .. dataType .. " data found, loading defaults.")
-	else
-		print("WeightsWatcher: attempting to " .. direction .. "grade " .. dataType .. " data from version " .. oldMajorVersion .. "." .. oldMinorVersion .. " to " .. newMajorVersion .. "." .. newMinorVersion .. ".")
-	end
-
-	local newVars = deepTableCopy(vars)
-
-	while oldMajorVersion ~= newMajorVersion or oldMinorVersion ~= newMinorVersion do
-		if not funcTable[oldMajorVersion] or not funcTable[oldMajorVersion][oldMinorVersion] then
-			print("WeightsWatcher: error: No " .. dataType .. " data " .. direction .. "grade path found.")
-			return nil
-		end
-		newVars = funcTable[oldMajorVersion][oldMinorVersion](newVars)
-		if not newVars or not newVars.dataMinorVersion then
-			print("WeightsWatcher: " .. dataType .. " data " .. direction .. "grade error.")
-			return nil
-		elseif oldMinorVersion == newVars.dataMinorVersion and oldMajorVersion == newVars.dataMajorVersion then
-			print("WeightsWatcher: error: infinite loop in " .. dataType .. " data " .. direction .. "grade.")
-			return nil
-		end
-		oldMinorVersion = newVars.dataMinorVersion
-		if newVars.dataMajorVersion then
-			oldMajorVersion = newVars.dataMajorVersion
-		else
-			oldMajorVersion = 0
-		end
-	end
-
-	newVars.downgradeFunctions = downgradeFunctions
-
-	print("WeightsWatcher: successfully " .. direction .. "graded " .. dataType .. " data.")
-
-	return newVars
-end
-
 function deepTableCopy(object)
     local lookup_table = {}
     local function _copy(object)
@@ -99,7 +16,7 @@ function deepTableCopy(object)
     return _copy(object)
 end

-function stringsToFuncs(strTable)
+local function stringsToFuncs(strTable)
 	local funcTable = {}

 	if not strTable then
@@ -116,26 +33,26 @@ function stringsToFuncs(strTable)
 	return funcTable
 end

-function noop_up(vars)
+local function noop_up(vars)
 	vars.dataMinorVersion = vars.dataMinorVersion + 1
 	return vars
 end

-noop_down = [[
+local noop_down = [[
 	return function(vars)
 		vars.dataMinorVersion = vars.dataMinorVersion - 1
 		return vars
 	end
 ]]

-function noop_major_up(vars)
+local function noop_major_up(vars)
 	vars.dataMajorVersion = vars.dataMajorVersion + 1
 	vars.dataMinorVersion = 0

 	return vars
 end

-function upgradeAccountToFixStunResistChance(vars)
+local function upgradeAccountToFixStunResistChance(vars)
 	for _, class in ipairs(vars.weightsList) do
 		for _, weight in ipairs(vars.weightsList[class]) do
 			if weight["stun resistance (percent)"] ~= nil then
@@ -149,7 +66,7 @@ function upgradeAccountToFixStunResistChance(vars)
 	return vars
 end

-downgradeAccountFromFixStunResistChance = [[
+local downgradeAccountFromFixStunResistChance = [[
 	return function(vars)
 		for _, class in ipairs(vars.weightsList) do
 			for _, weight in ipairs(vars.weightsList[class]) do
@@ -165,7 +82,7 @@ downgradeAccountFromFixStunResistChance = [[
 	end
 ]]

-function upgradeAccountToDebugKey(vars)
+local function upgradeAccountToDebugKey(vars)
 	if vars.options.tooltip.showDebugInfo == nil then
 		vars.options.tooltip.showDebugInfo = "Never"
 	end
@@ -174,7 +91,7 @@ function upgradeAccountToDebugKey(vars)
 	return vars
 end

-function upgradeAccountToTriggers(vars)
+local function upgradeAccountToTriggers(vars)
 	if vars.savedTriggers then
 		for _, class in ipairs(vars.savedTriggers) do
 			for _, weight in ipairs(vars.savedTriggers[class]) do
@@ -209,7 +126,7 @@ function upgradeAccountToTriggers(vars)
 	return vars
 end

-downgradeAccountFromTriggers = [[
+local downgradeAccountFromTriggers = [[
 	return function(vars)
 		vars.savedTriggers = {}
 		for i, class in ipairs(vars.weightsList) do
@@ -227,7 +144,7 @@ downgradeAccountFromTriggers = [[
 	end
 ]]

-function upgradeAccountToUseEffectRatio(vars)
+local function upgradeAccountToUseEffectRatio(vars)
 	if not vars.options.useEffects then
 		vars.options.useEffects = {}
 	end
@@ -239,7 +156,7 @@ function upgradeAccountToUseEffectRatio(vars)
 	return vars
 end

-function upgradeAccountToWorkingMeleeDamage(vars)
+local function upgradeAccountToWorkingMeleeDamage(vars)
 	for _, class in ipairs(vars.weightsList) do
 		for _, weight in ipairs(vars.weightsList[class]) do
 			vars.weightsList[class][weight]["melee damage"] = vars.weightsList[class][weight]["weapon damage"]
@@ -251,7 +168,7 @@ function upgradeAccountToWorkingMeleeDamage(vars)
 	return vars
 end

-function upgradeAccountToWorkingResistances(vars)
+local function upgradeAccountToWorkingResistances(vars)
 	local resistances = {
 		"arcane",
 		"fire",
@@ -274,7 +191,7 @@ function upgradeAccountToWorkingResistances(vars)
 	return vars
 end

-function upgradeAccountToShowAlternateGemsTypoFix(vars)
+local function upgradeAccountToShowAlternateGemsTypoFix(vars)
 	if vars.options.tooltip.showAlternateGems == nil then
 		vars.options.tooltip.showAlternateGems = "Alt"
 	end
@@ -284,7 +201,7 @@ function upgradeAccountToShowAlternateGemsTypoFix(vars)
 	return vars
 end

-function upgradeAccountToShowAlternateGems(vars)
+local function upgradeAccountToShowAlternateGems(vars)
 	if vars.options.tooltip.showAlternateGems == nil then
 		vars.options.tooltip.showAlternateGems = "Alt"
 	end
@@ -293,7 +210,7 @@ function upgradeAccountToShowAlternateGems(vars)
 	return vars
 end

-function upgradeAccountToGemSources(vars)
+local function upgradeAccountToGemSources(vars)
 	if not vars.options.gems.types then
 		vars.options.gems.types = {}
 	end
@@ -351,7 +268,7 @@ function upgradeAccountToGemSources(vars)
 	return vars
 end

-downgradeAccountFromGemSources = [[
+local downgradeAccountFromGemSources = [[
 	return function(vars)
 		if not vars.options.gems.usedTypes then
 			vars.options.gems.usedTypes = {}
@@ -392,7 +309,7 @@ downgradeAccountFromGemSources = [[
 	end
 ]]

-function upgradeAccountToFixedConfigOptions(vars)
+local function upgradeAccountToFixedConfigOptions(vars)
 	if vars.options.breakSocketColors ~= nil then
 		vars.options.gems.breakSocketColors = vars.options.breakSocketColors
 		vars.options.breakSocketColors = nil
@@ -416,7 +333,7 @@ function upgradeAccountToFixedConfigOptions(vars)
 	return vars
 end

-downgradeAccountFromFixedConfigOptions = [[
+local downgradeAccountFromFixedConfigOptions = [[
 	return function(vars)
 		if vars.options.tooltip.normalizeWeights ~= nil then
 			vars.options.normalizeWeights = vars.options.tooltip.normalizeWeights
@@ -430,7 +347,7 @@ downgradeAccountFromFixedConfigOptions = [[
 	end
 ]]

-function upgradeAccountToPartitionedGems(vars)
+local function upgradeAccountToPartitionedGems(vars)
 	qualityConversion = {
 		[1] = 1,
 		[2] = 2,
@@ -468,7 +385,7 @@ function upgradeAccountToPartitionedGems(vars)
 	return vars
 end

-downgradeAccountFromPartitionedGems = [[
+local downgradeAccountFromPartitionedGems = [[
 	return function(vars)
 		qualityConversion = {
 			[1] = 1,
@@ -500,7 +417,7 @@ downgradeAccountFromPartitionedGems = [[
 	end
 ]]

-function upgradeAccountToShowDifferences(vars)
+local function upgradeAccountToShowDifferences(vars)
 	if vars.options.tooltip.showDifferences == nil then
 		vars.options.tooltip.showDifferences = true
 	end
@@ -509,7 +426,7 @@ function upgradeAccountToShowDifferences(vars)
 	return vars
 end

-function upgradeAccountToCorrectShowClassNames(vars)
+local function upgradeAccountToCorrectShowClassNames(vars)
 	if vars.options.tooltip.showClassNames == nil then
 		if vars.options.showClassNames == nil then
 			vars.options.tooltip.showClassNames = "Others"
@@ -523,7 +440,7 @@ function upgradeAccountToCorrectShowClassNames(vars)
 	return vars
 end

-function upgradeAccountToBetterMetaEffectNames(vars)
+local function upgradeAccountToBetterMetaEffectNames(vars)
 	local newName
 	local conversion = {
 		["armor from items percent"] = "armor from items (percent)",
@@ -563,7 +480,7 @@ function upgradeAccountToBetterMetaEffectNames(vars)
 	return vars
 end

-downgradeAccountFromBetterMetaEffectNames = [[
+local downgradeAccountFromBetterMetaEffectNames = [[
 	return function (vars)
 		local newName
 		local conversion = {
@@ -601,7 +518,7 @@ downgradeAccountFromBetterMetaEffectNames = [[
 	end
 ]]

-downgradeAccountToDevelopment = [[
+local downgradeAccountToDevelopment = [[
 	return function(vars)
 		vars.dataMajorVersion = 0
 		vars.dataMinorVersion = 10
@@ -610,7 +527,7 @@ downgradeAccountToDevelopment = [[
 	end
 ]]

-downgradeCharToDevelopment = [[
+local downgradeCharToDevelopment = [[
 	return function(vars)
 		vars.dataMajorVersion = 0
 		vars.dataMinorVersion = 2
@@ -619,7 +536,7 @@ downgradeCharToDevelopment = [[
 	end
 ]]

-function upgradeAccountToConfig(vars)
+local function upgradeAccountToConfig(vars)
 	local table = vars.options.tooltip
 	local conversion = {
 		[true] = "Always",
@@ -658,7 +575,7 @@ function upgradeAccountToConfig(vars)
 	return vars
 end

-downgradeAccountFromConfig = [[
+local downgradeAccountFromConfig = [[
 	return function(vars)
 		local table = vars.options.tooltip
 		local conversion = {
@@ -699,7 +616,7 @@ downgradeAccountFromConfig = [[
 	end
 ]]

-function upgradeAccountForceGemColors(vars)
+local function upgradeAccountForceGemColors(vars)
 	if vars.options.breakSocketColors == nil then
 		vars.options.breakSocketColors = true
 	end
@@ -711,7 +628,7 @@ function upgradeAccountForceGemColors(vars)
 	return vars
 end

-function upgradeAccountHideModKeyHints(vars)
+local function upgradeAccountHideModKeyHints(vars)
 	if vars.options.tooltip.hideHints == nil then
 		vars.options.tooltip.hideHints = false
 	end
@@ -720,7 +637,7 @@ function upgradeAccountHideModKeyHints(vars)
 	return vars
 end

-function upgradeAccountShowClassNames(vars)
+local function upgradeAccountShowClassNames(vars)
 	if not vars.options.tooltip.showClassNames then
 		vars.options.tooltip.showClassNames = "Others"
 	end
@@ -729,7 +646,7 @@ function upgradeAccountShowClassNames(vars)
 	return vars
 end

-function upgradeAccountToHandleModifierKeys(vars)
+local function upgradeAccountToHandleModifierKeys(vars)
 	if not vars.options.tooltip then
 		vars.options.tooltip = deepTableCopy(defaultVars.options.tooltip)
 	end
@@ -738,7 +655,7 @@ function upgradeAccountToHandleModifierKeys(vars)
 	return vars
 end

-function upgradeAccountToOrderedLists(vars)
+local function upgradeAccountToOrderedLists(vars)
 	local i, j = 1
 	local weightsListCopy = {}

@@ -767,7 +684,7 @@ function upgradeAccountToOrderedLists(vars)
 	return vars
 end

-downgradeAccountFromOrderedLists = [[
+local downgradeAccountFromOrderedLists = [[
 	return function(vars)
 		local weightsListCopy = {}

@@ -784,7 +701,7 @@ downgradeAccountFromOrderedLists = [[
 	end
 ]]

-function upgradeCharToOrderedLists(vars)
+local function upgradeCharToOrderedLists(vars)
 	local i = 1
 	local activeWeightsCopy = {}

@@ -810,7 +727,7 @@ function upgradeCharToOrderedLists(vars)
 	return vars
 end

-downgradeCharFromOrderedLists = [[
+local downgradeCharFromOrderedLists = [[
 	return function(vars)
 		local activeWeightsCopy = {}

@@ -827,7 +744,7 @@ downgradeCharFromOrderedLists = [[
 	end
 ]]

-function upgradeAccountToGemQuality(vars)
+local function upgradeAccountToGemQuality(vars)
 	if not vars.options.gemQualityLimit then
 		vars.options.gemQualityLimit = 9
 	end
@@ -836,7 +753,7 @@ function upgradeAccountToGemQuality(vars)
 	return vars
 end

-function upgradeAccountToNormalization(vars)
+local function upgradeAccountToNormalization(vars)
 	if not vars.options then
 		vars.options = {}
 	end
@@ -852,7 +769,7 @@ function copyDefaultAccountVars()
 	return deepTableCopy(defaultVars)
 end

-function createActiveWeights(class)
+local function createActiveWeights(class)
 	local activeWeights = {class}

 	activeWeights[class] = {}
@@ -863,7 +780,7 @@ function createActiveWeights(class)
 	return activeWeights
 end

-function copyDefaultCharVars()
+local function copyDefaultCharVars()
 	local charVars

 	charVars = deepTableCopy(defaultCharVars)
@@ -871,7 +788,7 @@ function copyDefaultCharVars()
 	return charVars
 end

-upgradeAccountFunctions = {
+local upgradeAccountFunctions = {
 	[0] = {
 		[0] = copyDefaultAccountVars,
 		[1] = upgradeAccountToNormalization,
@@ -903,7 +820,7 @@ upgradeAccountFunctions = {
 	},
 }

-downgradeAccountFunctions = {
+local downgradeAccountFunctions = {
 	[0] = {
 		[2] = noop_down,
 		[3] = noop_down,
@@ -934,7 +851,7 @@ downgradeAccountFunctions = {
 	},
 }

-upgradeCharFunctions = {
+local upgradeCharFunctions = {
 	[0] = {
 		[0] = copyDefaultCharVars,
 		[1] = upgradeCharToOrderedLists,
@@ -942,7 +859,7 @@ upgradeCharFunctions = {
 	},
 }

-downgradeCharFunctions = {
+local downgradeCharFunctions = {
 	[0] = {
 		[2] = downgradeCharFromOrderedLists,
 	},
@@ -950,3 +867,86 @@ downgradeCharFunctions = {
 		[0] = downgradeCharToDevelopment,
 	},
 }
+
+function WeightsWatcher.Upgrade(dataType)
+	local oldMinorVersion, oldMajorVersion, newMinorVersion, newMajorVersion, vars, funcTable, direction, downgradeFunctions
+
+	if dataType == "account" then
+		vars = ww_vars
+		newMinorVersion = defaultVars.dataMinorVersion
+		newMajorVersion = defaultVars.dataMajorVersion
+		funcTable = upgradeAccountFunctions
+		downgradeFunctions = downgradeAccountFunctions
+	elseif dataType == "character" then
+		vars = ww_charVars
+		newMinorVersion = defaultCharVars.dataMinorVersion
+		newMajorVersion = defaultCharVars.dataMajorVersion
+		funcTable = upgradeCharFunctions
+		downgradeFunctions = downgradeCharFunctions
+	else
+		print("WeightsWatcher: error: invalid data type \"" .. dataType .. "\" passed to Upgrade().")
+		return nil
+	end
+
+	if vars then
+		oldMinorVersion = vars.dataMinorVersion
+		oldMajorVersion = vars.dataMajorVersion
+	end
+	if not oldMinorVersion then
+		oldMinorVersion = 0
+	end
+	if not oldMajorVersion then
+		oldMajorVersion = 0
+	end
+
+	if newMajorVersion == oldMajorVersion and newMinorVersion == oldMinorVersion then
+		return vars
+	end
+
+	if newMajorVersion > oldMajorVersion or (newMajorVersion == oldMajorVersion and newMinorVersion > oldMinorVersion) then
+		direction = "up"
+	else
+		direction = "down"
+		funcTable = stringsToFuncs(vars.downgradeFunctions)
+	end
+
+	if funcTable == nil then
+		print("WeightsWatcher: error: no " .. direction .. "grade function table found.")
+		return nil
+	end
+
+	if oldMajorVersion == 0 and oldMinorVersion == 0 then
+		print("WeightsWatcher: no " .. dataType .. " data found, loading defaults.")
+	else
+		print("WeightsWatcher: attempting to " .. direction .. "grade " .. dataType .. " data from version " .. oldMajorVersion .. "." .. oldMinorVersion .. " to " .. newMajorVersion .. "." .. newMinorVersion .. ".")
+	end
+
+	local newVars = deepTableCopy(vars)
+
+	while oldMajorVersion ~= newMajorVersion or oldMinorVersion ~= newMinorVersion do
+		if not funcTable[oldMajorVersion] or not funcTable[oldMajorVersion][oldMinorVersion] then
+			print("WeightsWatcher: error: No " .. dataType .. " data " .. direction .. "grade path found.")
+			return nil
+		end
+		newVars = funcTable[oldMajorVersion][oldMinorVersion](newVars)
+		if not newVars or not newVars.dataMinorVersion then
+			print("WeightsWatcher: " .. dataType .. " data " .. direction .. "grade error.")
+			return nil
+		elseif oldMinorVersion == newVars.dataMinorVersion and oldMajorVersion == newVars.dataMajorVersion then
+			print("WeightsWatcher: error: infinite loop in " .. dataType .. " data " .. direction .. "grade.")
+			return nil
+		end
+		oldMinorVersion = newVars.dataMinorVersion
+		if newVars.dataMajorVersion then
+			oldMajorVersion = newVars.dataMajorVersion
+		else
+			oldMajorVersion = 0
+		end
+	end
+
+	newVars.downgradeFunctions = downgradeFunctions
+
+	print("WeightsWatcher: successfully " .. direction .. "graded " .. dataType .. " data.")
+
+	return newVars
+end
diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua
index 4059196..fd34779 100644
--- a/WeightsWatcher.lua
+++ b/WeightsWatcher.lua
@@ -1,4 +1,13 @@
-currentHooks = {}
+local currentHooks = {}
+
+local function splitItemLink(link)
+	local _, itemId, _, gemId1, gemId2, gemId3, gemId4, suffixId, uniqueId, linkLevel = strsplit(":", link)
+	-- Strip color codes
+	linkLevel = strsplit("|", linkLevel)
+	bareLink = strjoin(":", "item", itemId, "0:0:0:0:0", suffixId, uniqueId, linkLevel)
+
+	return bareLink, {{gemId1}, {gemId2}, {gemId3}, {gemId4}}
+end

 ww_normalStatsMetatable = {
 	-- Allows us to skip the nil check
@@ -221,6 +230,19 @@ function WeightsWatcher.ResetTables()
 	ww_unweighted_lines = setmetatable({}, metatable)
 end

+local function upgradeData(dataType, varsName)
+	local tempVars
+
+	tempVars = WeightsWatcher.Upgrade(dataType)
+	if tempVars then
+		_G[varsName] = tempVars
+		return true
+	else
+		WeightsWatcher.Broken(dataType)
+		return false
+	end
+end
+
 function WeightsWatcher.OnInitialize()
 	loadGeneralInfo()

@@ -283,19 +305,6 @@ StaticPopupDialogs["WW_INVALID_CHARACTER_DATA"] = {
 	hideOnEscape = false,
 }

-function upgradeData(dataType, varsName)
-	local tempVars
-
-	tempVars = WeightsWatcher.Upgrade(dataType)
-	if tempVars then
-		_G[varsName] = tempVars
-		return true
-	else
-		WeightsWatcher.Broken(dataType)
-		return false
-	end
-end
-
 function WeightsWatcher.Broken(dataType)
 	if dataType == "account" then
 		StaticPopup_Show("WW_INVALID_ACCOUNT_DATA")
@@ -355,15 +364,6 @@ function WeightsWatcher.OnDisable()
 	currentHooks = {}
 end

-function splitItemLink(link)
-	local _, itemId, _, gemId1, gemId2, gemId3, gemId4, suffixId, uniqueId, linkLevel = strsplit(":", link)
-	-- Strip color codes
-	linkLevel = strsplit("|", linkLevel)
-	bareLink = strjoin(":", "item", itemId, "0:0:0:0:0", suffixId, uniqueId, linkLevel)
-
-	return bareLink, {{gemId1}, {gemId2}, {gemId3}, {gemId4}}
-end
-
 local function checkForTitansGrip()
 	if WeightsWatcher.playerClass ~= "WARRIOR" then
 		return false
diff --git a/config.lua b/config.lua
index 57609ff..cf988e4 100644
--- a/config.lua
+++ b/config.lua
@@ -1,3 +1,12 @@
+local function printHelp()
+	print("WeightsWatcher help:")
+	print("Type /weightswatcher <arg> (or /ww <arg>)")
+	print("  config      opens the main configuration window")
+	print("  weights   opens the weights configuration window")
+	print("  version    displays version information")
+	print("  help         displays this message")
+end
+
 function commandHandler(msg)
 	if msg == "config" then
 		ww_weights:Hide()
@@ -29,13 +38,10 @@ function commandHandler(msg)
 	end
 end

-function printHelp()
-	print("WeightsWatcher help:")
-	print("Type /weightswatcher <arg> (or /ww <arg>)")
-	print("  config      opens the main configuration window")
-	print("  weights   opens the weights configuration window")
-	print("  version    displays version information")
-	print("  help         displays this message")
+local function GemQualityDropDownOnClick(choice, dropdown)
+	UIDropDownMenu_SetSelectedValue(dropdown, choice.value, false)
+	ww_vars.options.gems.qualityLimit = choice.value
+	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
 end

 function GemQualityDropDownInitialize(dropdown)
@@ -51,10 +57,9 @@ function GemQualityDropDownInitialize(dropdown)
 	end
 end

-function GemQualityDropDownOnClick(choice, dropdown)
+local function ModifierKeyDropDownOnClick(choice, dropdown)
 	UIDropDownMenu_SetSelectedValue(dropdown, choice.value, false)
-	ww_vars.options.gems.qualityLimit = choice.value
-	ww_weightIdealCache = setmetatable({}, ww_weightIdealCacheMetatable)
+	ww_vars.options.tooltip[dropdown:GetText()] = choice.value
 end

 function ModifierKeyDropDownInitialize(dropdown)
@@ -70,9 +75,9 @@ function ModifierKeyDropDownInitialize(dropdown)
 	end
 end

-function ModifierKeyDropDownOnClick(choice, dropdown)
+local function ShowClassNameDropDownOnClick(choice, dropdown)
 	UIDropDownMenu_SetSelectedValue(dropdown, choice.value, false)
-	ww_vars.options.tooltip[dropdown:GetText()] = choice.value
+	ww_vars.options.tooltip.showClassNames = choice.value
 end

 function ShowClassNameDropDownInitialize(dropdown)
@@ -87,8 +92,3 @@ function ShowClassNameDropDownInitialize(dropdown)
 		UIDropDownMenu_AddButton(info)
 	end
 end
-
-function ShowClassNameDropDownOnClick(choice, dropdown)
-	UIDropDownMenu_SetSelectedValue(dropdown, choice.value, false)
-	ww_vars.options.tooltip.showClassNames = choice.value
-end
diff --git a/weights.lua b/weights.lua
index cbd2462..eb2c3e2 100644
--- a/weights.lua
+++ b/weights.lua
@@ -1,72 +1,3 @@
-StaticPopupDialogs["WW_CONFIRM_DISCARD_CHANGES"] = {
-	text = "You have unsaved changes for this weight.",
-	button1 = "Discard",
-	button3 = "Save",
-	button2 = "Cancel",
-	OnAccept = function(self, func)
-			func()
-		end,
-	OnAlt = function(self, func)
-			configSaveWeight()
-			func()
-		end,
-	showAlert = true,
-	timeout = 0,
-	whileDead = true,
-	hideOnEscape = true,
-}
-
-StaticPopupDialogs["WW_CONFIRM_WEIGHT_DELETE"] = {
-	text = "Are you sure you want to delete the %s weight named \"%s\"?",
-	button1 = "Delete",
-	button2 = "Cancel",
-	OnAccept = function()
-			deleteWeight()
-		end,
-	showAlert = true,
-	timeout = 0,
-	whileDead = true,
-	hideOnEscape = true,
-}
-
-StaticPopupDialogs["WW_CONFIRM_RESTORE_DEFAULTS"] = {
-	text = "Are you sure you want to restore default weights?\n\nWeights whose names are white will be overwritten (the others will be left as they are).",
-	button1 = "Restore Defaults",
-	button2 = "Cancel",
-	OnAccept = function()
-			for _, class in ipairs(defaultVars.weightsList) do
-				for _, weight in ipairs(defaultVars.weightsList[class]) do
-					setWeight(class, weight, defaultVars.weightsList[class][weight])
-					ww_weightCache[class][weight] = nil
-					ww_weightIdealCache[class][weight] = nil
-				end
-			end
-			if ww_weights.rightPanel:IsShown() then
-				configSelectWeight(ww_weights.rightPanel.weightFrame)
-			end
-		end,
-	showAlert = true,
-	timeout = 0,
-	whileDead = true,
-	hideOnEscape = true,
-}
-
-StaticPopupDialogs["WW_WEIGHT_EXISTS"] = {
-	text = "The %s weight named \"%s\" already exists.  Pick a different name.",
-	button1 = "Okay",
-	enterClicksFirstButton = true,
-	showAlert = true,
-	timeout = 0,
-	whileDead = true,
-	hideOnEscape = true,
-}
-
--- initializes weights config frames and variables
-function initializeWeightsConfig()
-	loadClassButtons()
-	loadStatButtons()
-end
-
 function validateNumber(newChar, newText)
 	if string.find(newChar, "^%d$") then
 		return true
@@ -303,7 +234,7 @@ function configSaveWeight()
 	ww_weights.rightPanel.resetButton:Disable()
 end

-function deleteWeight()
+local function deleteWeight()
 	local point, relativeTo, relativePoint, xOffset, yOffset, removed
 	local weight = ww_weights.rightPanel.weightFrame

@@ -426,8 +357,51 @@ function setWeight(class, weight, statList)
 	ww_vars.weightsList[class][weight] = deepTableCopy(statList)
 end

+-- Creates a tiered list that can be scrolled
+-- template is a table of key-value pairs with keys as the categories and values as a table of elements
+-- scrollFrame is the scrollframe that controls scrolledFrame
+-- NOTE: scrollFrame must have an OnShow handler that updates the scrollbar
+-- scrolledFrame is the frame that will hold everything
+-- elementType is the element template type
+-- elementHeight is the height of each element
+local function createScrollableTieredList(template, scrollFrame, scrolledFrame, elementType, elementHeight)
+	local categoryFrame, elementFrame
+
+	scrollFrame.categories = {}
+	scrollFrame.shown = {}
+	scrollFrame.elementHeight = elementHeight
+	for i, category in ipairs(template) do
+		--for each category print the header and then the print the list of stats
+		categoryFrame = CreateFrame("Frame", "WW_" .. category, scrolledFrame, "ww_categoryFrame")
+		categoryFrame.text:SetText(category)
+		categoryFrame.name = category
+		categoryFrame.length = 1
+		if i == 1 then
+			categoryFrame:SetPoint("TOPLEFT")
+		else
+			categoryFrame:SetPoint("TOPLEFT", scrollFrame.categories[i - 1], "BOTTOMLEFT")
+		end
+		table.insert(scrollFrame.categories, categoryFrame)
+		table.insert(scrollFrame.shown, categoryFrame.text)
+		categoryFrame.position = #(scrollFrame.shown)
+		for j, element in ipairs(template[category]) do
+			elementFrame = CreateFrame("Frame", "WW_" .. element, scrollFrame.categories[i], elementType)
+			elementFrame.position = j
+			elementFrame.category = categoryFrame
+			elementFrame.text:SetText(element)
+			elementFrame.name = template[category][element] or element
+			elementFrame:SetPoint("TOPLEFT", 0, -elementHeight * j)
+			table.insert(scrollFrame.shown, elementFrame)
+			categoryFrame.length = categoryFrame.length + 1
+		end
+
+		categoryFrame:SetHeight(elementHeight * categoryFrame.length)
+		categoryFrame.collapsed = false
+	end
+end
+
 --loads the various class buttons onto the config frame
-function loadClassButtons()
+local function loadClassButtons()
 	local classes, revClassLookup, newClass = {}, {}

 	for i, class in ipairs(ww_vars.weightsList) do
@@ -469,7 +443,7 @@ function loadClassButtons()
 	end
 end

-function loadStatButtons()
+local function loadStatButtons()
 	local stats = {}

 	createScrollableTieredList(trackedStats, ww_weights.rightPanel.scrollFrame, ww_weights.rightPanel.scrollContainer, "ww_statFrame", 22)
@@ -503,47 +477,10 @@ function loadStatButtons()
 	ww_weights.rightPanel.scrollFrame.stats = stats
 end

--- Creates a tiered list that can be scrolled
--- template is a table of key-value pairs with keys as the categories and values as a table of elements
--- scrollFrame is the scrollframe that controls scrolledFrame
--- NOTE: scrollFrame must have an OnShow handler that updates the scrollbar
--- scrolledFrame is the frame that will hold everything
--- elementType is the element template type
--- elementHeight is the height of each element
-function createScrollableTieredList(template, scrollFrame, scrolledFrame, elementType, elementHeight)
-	local categoryFrame, elementFrame
-
-	scrollFrame.categories = {}
-	scrollFrame.shown = {}
-	scrollFrame.elementHeight = elementHeight
-	for i, category in ipairs(template) do
-		--for each category print the header and then the print the list of stats
-		categoryFrame = CreateFrame("Frame", "WW_" .. category, scrolledFrame, "ww_categoryFrame")
-		categoryFrame.text:SetText(category)
-		categoryFrame.name = category
-		categoryFrame.length = 1
-		if i == 1 then
-			categoryFrame:SetPoint("TOPLEFT")
-		else
-			categoryFrame:SetPoint("TOPLEFT", scrollFrame.categories[i - 1], "BOTTOMLEFT")
-		end
-		table.insert(scrollFrame.categories, categoryFrame)
-		table.insert(scrollFrame.shown, categoryFrame.text)
-		categoryFrame.position = #(scrollFrame.shown)
-		for j, element in ipairs(template[category]) do
-			elementFrame = CreateFrame("Frame", "WW_" .. element, scrollFrame.categories[i], elementType)
-			elementFrame.position = j
-			elementFrame.category = categoryFrame
-			elementFrame.text:SetText(element)
-			elementFrame.name = template[category][element] or element
-			elementFrame:SetPoint("TOPLEFT", 0, -elementHeight * j)
-			table.insert(scrollFrame.shown, elementFrame)
-			categoryFrame.length = categoryFrame.length + 1
-		end
-
-		categoryFrame:SetHeight(elementHeight * categoryFrame.length)
-		categoryFrame.collapsed = false
-	end
+-- initializes weights config frames and variables
+function initializeWeightsConfig()
+	loadClassButtons()
+	loadStatButtons()
 end

 function toggleCollapse(categoryFrame, scrollFrame)
@@ -581,6 +518,10 @@ function toggleCollapse(categoryFrame, scrollFrame)
 	scrollFrame:GetScript("OnShow")(scrollFrame)
 end

+local function DropDownOnClick(choice, dropdown)
+	UIDropDownMenu_SetSelectedValue(dropdown, choice.value, false)
+end
+
 function ClassDropDownInitialize(dropdown)
 	local info = {}

@@ -594,6 +535,65 @@ function ClassDropDownInitialize(dropdown)
 	end
 end

-function DropDownOnClick(choice, dropdown)
-	UIDropDownMenu_SetSelectedValue(dropdown, choice.value, false)
-end
+StaticPopupDialogs["WW_CONFIRM_DISCARD_CHANGES"] = {
+	text = "You have unsaved changes for this weight.",
+	button1 = "Discard",
+	button3 = "Save",
+	button2 = "Cancel",
+	OnAccept = function(self, func)
+			func()
+		end,
+	OnAlt = function(self, func)
+			configSaveWeight()
+			func()
+		end,
+	showAlert = true,
+	timeout = 0,
+	whileDead = true,
+	hideOnEscape = true,
+}
+
+StaticPopupDialogs["WW_CONFIRM_WEIGHT_DELETE"] = {
+	text = "Are you sure you want to delete the %s weight named \"%s\"?",
+	button1 = "Delete",
+	button2 = "Cancel",
+	OnAccept = function()
+			deleteWeight()
+		end,
+	showAlert = true,
+	timeout = 0,
+	whileDead = true,
+	hideOnEscape = true,
+}
+
+StaticPopupDialogs["WW_CONFIRM_RESTORE_DEFAULTS"] = {
+	text = "Are you sure you want to restore default weights?\n\nWeights whose names are white will be overwritten (the others will be left as they are).",
+	button1 = "Restore Defaults",
+	button2 = "Cancel",
+	OnAccept = function()
+			for _, class in ipairs(defaultVars.weightsList) do
+				for _, weight in ipairs(defaultVars.weightsList[class]) do
+					setWeight(class, weight, defaultVars.weightsList[class][weight])
+					ww_weightCache[class][weight] = nil
+					ww_weightIdealCache[class][weight] = nil
+				end
+			end
+			if ww_weights.rightPanel:IsShown() then
+				configSelectWeight(ww_weights.rightPanel.weightFrame)
+			end
+		end,
+	showAlert = true,
+	timeout = 0,
+	whileDead = true,
+	hideOnEscape = true,
+}
+
+StaticPopupDialogs["WW_WEIGHT_EXISTS"] = {
+	text = "The %s weight named \"%s\" already exists.  Pick a different name.",
+	button1 = "Okay",
+	enterClicksFirstButton = true,
+	showAlert = true,
+	timeout = 0,
+	whileDead = true,
+	hideOnEscape = true,
+}