Skip to content

Commit

Permalink
built the main state controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuller committed Nov 20, 2010
1 parent 7df3fe1 commit 1999905
Showing 1 changed file with 81 additions and 58 deletions.
139 changes: 81 additions & 58 deletions core/majorTom.lua
Original file line number Diff line number Diff line change
@@ -1,80 +1,103 @@
--[[
majorTom.lua
this is a long way to go for a bowie reference
--]]

local MajorTom = CreateFrame('Frame', nil, UIParent, 'SecureHandlerStateTemplate'); MajorTom:SetAllPoints(UIParent)
local controller = CreateFrame('Frame', nil, UIParent, 'SecureHandlerStateTemplate')
controller:SetAllPoints(UIParent)

--main controller state
MajorTom:SetAttribute('_onstate-majorTom', [[
self:SetAttribute('currentState') = self:GetAttribute('state-groundControl') or newstate
self:RunAttribute('updateFrames', self:GetAttribute('currentState'))
controller:SetAttribute('_onstate-groundControl', [[
local prevstate = self:GetAttribute('state-main')
local newstate = self:GetAttribute('state-majorTom') or newstate
if prevstate ~= newstate then
self:SetAttribute('state-main', newstate)
end
]])

--override state
MajorTom:SetAttribute('_onstate-groundControl', [[
self:SetAttribute('currentState') = newstate or self:GetAttribute('state-groundControl')
self:RunAttribute('updateFrames', self:GetAttribute('currentState'))
]])
controller:SetAttribute('_onstate-majorTom', [[
local prevstate = self:GetAttribute('state-main')
local newstate = newstate or self:GetAttribute('state-groundControl')
--update all frames
MajorTom:SetAttribute('updateFrames' [[
local currentState = ...
if myFrames then
for _, frame in pairs(myFrames) do
self:RunAttribute('updateFrame', frame, currentState)
end
if prevstate ~= newstate then
self:SetAttribute('state-main', newstate)
end
]])

--updates the given frame (parameters: frame, currentState)
MajorTim:SetAttribute('updateFrame', [[
local frame, currentState = ...
frame:RunAttribute('update', currentState)
--current state (majorTom or groundControl)
controller:SetAttribute('_onstate-main', [[
self:ChildUpdate('state-main', newstate)
]])

--lock state
controller:SetAttribute('_onstate-lock', [[
self:ChildUpdate('state-lock', newstate)
]])

--adds the given frame to control by majorTom
MajorTom:SetAttribute('addFrame', [[
local newFrame = ...
if not myFrames then myFrames = table.new(...) end
myFrames[newFrame:GetAttribute('id')] = newFrame
newFrame:SetParent(self)
self:RunAttribute('updateFrame', newFrame, self:GetAttribute('currentState'))
controller:SetAttribute('addFrame', [[
local f = self:GetFrameRef('addFrame')
if not myFrames then
myFrames = table.new()
end
myFrames[f:GetAttribute('id')] = f
f:SetParent(self)
f:SetAttribute('state-main', self:GetAttribute('state-main'))
f:SetAttribute('state-lock', self:GetAttribute('state-lock'))
]])

--removes the frame from control by majorTom
MajorTom:SetAttribute('delFrame', [[
local delFrame = ...
if myFrames then
myFrames[delFrame:GetAttribute('id')] = nil
controller:SetAttribute('remFrame', [[
local f = ...
if myFrames then
myFrames[f:GetAttribute('id')] = nil
end
]])

--add frame to state control
function MajorTom:AddFrame(frame)
self:SetFrameRef('addFrame', frame)
self:Execute([[ self:RunAttribute('addFrame', self:GetFrameRef('addFrame')) ]])
end

--remove frame from state control
function MajorTom:RemoveFrame(frame)
self:SetFrameRef('delFrame', frame)
self:Execute([[ self:RunAttribute('delFrame', self:GetFrameRef('delFrame')) ]])
end

--updates the state driver for majorTom
function MajorTom:SetStateDriver(values)
RegisterStateDriver(self, 'state-majorTom', values)
-- self:SetAttribute('state-majorTom', SecureCmdOptionParse(values))
end

--updates the override state for majorTom (groundControl)
function MajorTom:SetOverrideState(state)
self:SetAttribute('state-groundControl', state)
end

do
local _, TCFB = ...
TCFB.MajorTom = MajorTom
end
local TCFB = select(2, ...)
TCFB.MajorTom = {
--add frame to state control
addFrame = function(self, frame)
controller:SetFrameRef('addFrame', frame)
controller:Execute([[
self:RunAttribute('addFrame', self:GetFrameRef('addFrame'))
]])
end,

--remove frame from state control
removeFrame = function(self, frame)
controller:SetFrameRef('remFrame', frame)
controller:Execute([[
self:RunAttribute('remFrame', self:GetFrameRef('remFrame'))
]])
end,

--updates the state driver for groundControl
setStateDriver = function(self, values)
self.stateDriver = stateDriver
RegisterStateDriver(controller, 'groundControl', values)
--controller:SetAttribute('state-groundControl', SecureCmdOptionParse(values))
end,

getStateDriver = function(self, values)
return self.stateDriver
end,

--updates the override state for groundControl (majorTom)
setOverrideState = function(self, state)
controller:SetAttribute('state-majorTom', state)
end,

getState = function(self)
return controller:GetAttribute('state-main')
end,

--enables|disables the lock state
setLock = function(self, enable)
controller:SetAttribute('state-lock', enable and true or false)
end,
}

0 comments on commit 1999905

Please sign in to comment.