Skip to content

Commit

Permalink
Path Walking
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSheps committed Oct 17, 2018
1 parent 54a2b42 commit 11f2632
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
54 changes: 54 additions & 0 deletions BeStride.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ function BeStride:ChatCommand(input)
BeStride:buildMountTables()
elseif input == "map" then
BeStride:GetMaps()
elseif input == "testpathwalk" then
print("Path: settings.emptyrandom (" .. tostring(BeStride:DBGet("settings.emptyrandom")) ..")")
BeStride:DBSet("settings.emptyrandom",false)
print("Path: settings.emptyrandom (" .. tostring(BeStride:DBGet("settings.emptyrandom")) ..")")
print("Path: settings.repair.durability (" .. tostring(BeStride:DBGet("settings.repair.durability")) ..")")
BeStride:DBSet("settings.repair.durability",50)
print("Path: settings.repair.durability (" .. tostring(BeStride:DBGet("settings.repair.durability")) ..")")
print("Path: settings.repair.dura (" .. tostring(BeStride:DBGet("settings.repair.dura")) ..")")
BeStride:DBSet("settings.repair.dura",50)
print("Path: settings.repair.dura (" .. tostring(BeStride:DBGet("settings.repair.dura")) ..")")
else
BeStride_GUI:Frame(input)
end
Expand All @@ -301,6 +311,50 @@ function BeStride:GetMap(locID)
end
end

function BeStride:DBGet(path,parent)
local child,nextPath = strsplit(".",path,2)

if child ~= nil and parent ~= nil and nextPath == nil then
if parent[child] ~= nil then
return parent[child]
else
return nil
end
elseif child ~= nil and parent ~= nil and parent[child] ~= nil and nextPath ~= nil then
return BeStride:DBGet(nextPath,parent[child])
elseif child ~= nil and parent == nil and nextPath == nil then
return self.db.profile[child]
elseif child ~= nil and parent == nil and nextPath ~= nil then
if self.db.profile[child] ~= nil then
return BeStride:DBGet(nextPath,self.db.profile[child])
else
return nil
end
else
return nil
end
end

function BeStride:DBSet(path,value,parent)
local child,nextPath = strsplit(".",path,2)

if child ~= nil and parent ~= nil and nextPath == nil then
parent[child] = value
elseif child ~= nil and parent ~= nil and parent[child] == nil and nextPath ~= nil then
parent[child] = {}
BeStride:DBSet(nextPath,value,parent[child])
elseif child ~= nil and parent ~= nil and parent[child] ~= nil and nextPath ~= nil then
BeStride:DBSet(nextPath,value,parent[child])
elseif child ~= nil and parent == nil and nextPath == nil then
self.db.profile[child] = value
elseif child ~= nil and parent == nil and nextPath ~= nil then
if self.db.profile[child] == nil then
self.db.profile[child] = {}
end
BeStride:DBSet(nextPath,value,self.db.profile[child])
end
end

function BeStride:DBGetMount(mountType,mountID)
if self.db.profile.mounts[mountType][mountID] ~= nil then
return self.db.profile.mounts[mountType][mountID]
Expand Down
32 changes: 23 additions & 9 deletions BeStride_GUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local AceGUI = LibStub("AceGUI-3.0")
local BeStride_Frame = nil

BeStride_GUI = {
buttons = {}
elements = {}
}

function BeStride_GUI:Frame(tab)
Expand Down Expand Up @@ -139,7 +139,7 @@ function BeStride_GUI:DrawMountsSubTab(container,group)
for key,mount in pairs(mountTable[group]) do
--BeStride_Debug:Debug(mount["type"] .. ":" .. group)
--BeStride_Debug:Debug("Mount: " .. mountTable["master"][mount]["name"])
local mountCheck = BeStride_GUI:CreateMountButton(group,mount)
local mountCheck = BeStride_GUI:CreateMountCheckBox(group,mount)
if mountCheck ~= nil then
mounts[mountTable["master"][mount]["name"]] = mountCheck
end
Expand All @@ -153,7 +153,7 @@ function BeStride_GUI:DrawMountsSubTab(container,group)
scrollframe:AddChild(mountsGroup)
end

function BeStride_GUI:CreateMountButton(group,mountID)
function BeStride_GUI:CreateMountCheckBox(group,mountID)
local mount = mountTable.master[mountID]
if mount["isCollected"] and (mount["faction"]== nil or mount["faction"] == playerTable["faction"]["id"]) then
mountButton = AceGUI:Create("CheckBox")
Expand All @@ -173,19 +173,19 @@ function BeStride_GUI:DrawMountOptionTab(container, parent)
for name,setting in pairs(BeStride_Constants.Settings.Mount) do
local element = nil
if setting.element == "CheckBox" then
element = self:CreateSettingCheckBox(setting.label,parent,setting.dbvalue)
element = self:CreateSettingCheckBox(setting.name,setting.label,parent,setting.dbvalue)
elseif setting.element == "Slider" then
element = self:CreateSettingSlider(setting.label,parent,setting.dbvalue,setting.minDurability,setting.maxDurability,setting.increment,setting.disabled)
element = self:CreateSettingSlider(setting.name,setting.label,parent,setting.dbvalue,setting.minDurability,setting.maxDurability,setting.increment,setting.disabled)
elseif setting.element == "Group" and setting.children then
element = AceGUI:Create("SimpleGroup")
element:SetFullWidth(true)
for subName,subSetting in pairs(setting.children) do
print(" SubName: " .. subName)
local subElement = nil
if subSetting.element == "CheckBox" then
subElement = self:CreateSettingCheckBox(subSetting.label,setting.dbvalue,subSetting.dbvalue)
subElement = self:CreateSettingCheckBox(subSetting.name,subSetting.label,setting.dbvalue,subSetting.dbvalue)
elseif subSetting.element == "Slider" then
subElement = self:CreateSettingSlider(subSetting.label,setting.dbvalue,subSetting.dbvalue,subSetting.minDurability,subSetting.maxDurability,subSetting.increment,subSetting.disabled)
subElement = self:CreateSettingSlider(subSetting.name,subSetting.label,setting.dbvalue,subSetting.dbvalue,subSetting.minDurability,subSetting.maxDurability,subSetting.increment,subSetting.disabled)
end
element:AddChild(subElement)
end
Expand All @@ -197,17 +197,31 @@ function BeStride_GUI:DrawMountOptionTab(container, parent)
end
end

function BeStride_GUI:CreateSettingCheckBox(label,parent,setting)
function BeStride_GUI:CreateSettingCheckBox(name,label,parent,setting)
local element = AceGUI:Create("CheckBox")
element:SetLabel(label)
element:SetValue(BeStride:DBGetSetting(parent,setting))
element:SetFullWidth(true)
element:SetCallback("OnValueChanged",function (container) BeStride:DBSetSetting(parent,setting,container:GetValue()) end)

if setting.depends then
local disabled = nil
for key,value in pairs(setting.depends) do
if disabled == nil then
disabled = self.elements[value]:GetValue()
else
bit.band(disabled,self.elements[value]:GetValue())
end
end

element.SetDisabled(disabled)
end
print("Setting: " .. tostring(name) .. " Label: " .. label)
self.elements[name] = element
return element
end

function BeStride_GUI:CreateSettingSlider(label,parent,setting,minValue,maxValue,increment,disabled)
function BeStride_GUI:CreateSettingSlider(name,label,parent,setting,minValue,maxValue,increment,disabled)
local element = AceGUI:Create("Slider")
element:SetLabel(label)
element:SetValue(BeStride:DBGetSetting(parent,setting))
Expand Down

0 comments on commit 11f2632

Please sign in to comment.