Skip to content

Commit

Permalink
Refactor lock question set - lock switch code
Browse files Browse the repository at this point in the history
  • Loading branch information
sekodev committed Jan 18, 2024
1 parent 62c7ddc commit ca834aa
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 123 deletions.
68 changes: 67 additions & 1 deletion libs/commonMethods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function commonMethods.useLock(infoGroup, tableTimers, locksAvailable, textNumLo
end

-- Show number of locks available to use
function commonMethods.showLocksAvailable(targetGroup, yTopInfoBox, locksAvailable)
local function showLocksAvailable(targetGroup, yTopInfoBox, locksAvailable)
local fontLogo = composer.getVariable( "fontLogo" )

local colorTextDefault = themeData.colorTextDefault
Expand All @@ -306,6 +306,72 @@ function commonMethods.showLocksAvailable(targetGroup, yTopInfoBox, locksAvailab
targetGroup:insert(imageLock.textNumAvailable)
end

-- Change lock state and show information based on taps/clicks
function commonMethods.switchLock(buttonLock, infoGroup, locksAvailable, soundLock, fontLockUsed)
local lockInfoAvailable = composer.getVariable( "lockInfoAvailable" )
local colorPadlock = themeData.colorPadlock

-- Only change the flag as activated
-- This change will be used later on button press("Play") and scene change
if (buttonLock.isActivated) then
buttonLock.isActivated = false
buttonLock.alpha = buttonLock.alphaInactive
buttonLock:setFillColor( unpack(colorPadlock) )
else
audio.play( soundLock, {channel = 2} )

-- Check to see if information about lock system will be shown
-- If player discarded the message and chose "Don't show again", don't show info box
if (lockInfoAvailable) then
if (locksAvailable > 0) then
buttonLock.isActivated = true
buttonLock.alpha = 1
end

local infoText
local isPromptAvailable = true
if (locksAvailable > 0) then
infoText = sozluk.getString("lockInformation")
else
infoText = sozluk.getString("lockInformationNA")
isPromptAvailable = false
end

-- Declare options for information box creation
local optionsInfoBox = {
infoFont = fontLockUsed,
infoText = infoText,
isPromptAvailable = isPromptAvailable,
stringPromptPreference = "lockInfoAvailable",
}
yTopFrame = utils.showInformationBox(infoGroup, optionsInfoBox)
showLocksAvailable(infoGroup, yTopFrame, locksAvailable)
else
if (locksAvailable > 0) then
buttonLock.isActivated = true
buttonLock.alpha = 1
else
local infoText
local isPromptAvailable = true
if (locksAvailable <= 0) then
infoText = sozluk.getString("lockInformationNA")
isPromptAvailable = false
end

-- Declare options for information box creation
local optionsInfoBox = {
infoFont = fontLockUsed,
infoText = infoText,
isPromptAvailable = isPromptAvailable,
stringPromptPreference = "lockInfoAvailable",
}
yTopFrame = utils.showInformationBox(infoGroup, optionsInfoBox)
showLocksAvailable(infoGroup, yTopFrame, locksAvailable)
end
end
end
end

-- Handle touch events for navigation buttons
-- Calls assigned function when corresponding option is selected
local function handleNavigationTouch(event)
Expand Down
63 changes: 2 additions & 61 deletions screens/endScreen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -201,67 +201,8 @@ function handleTouch(event)
if (event.target.id == "shareSocial") then
event.target:setFillColor( unpack(themeData.colorButtonDefault) )
elseif (event.target.id == "lockQuestionSet") then
local lockInfoAvailable = composer.getVariable( "lockInfoAvailable" )

-- Only change the flag as activated
-- This change will be used later on button press("Play") and scene change
if (event.target.isActivated) then
event.target.isActivated = false
event.target.alpha = event.target.alphaInactive
event.target:setFillColor( unpack(themeData.colorPadlock) )
else
audio.play( tableSoundFiles["lockQuestionSet"], {channel = 2} )

-- Check to see if information about lock system will be shown
-- If player discarded the message and chose "Don't show again", don't show info box
if (lockInfoAvailable) then
if (locksAvailable > 0) then
event.target.isActivated = true
event.target.alpha = 1
end

local infoText
local isPromptAvailable = true
if (locksAvailable > 0) then
infoText = sozluk.getString("lockInformation")
else
infoText = sozluk.getString("lockInformationNA")
isPromptAvailable = false
end

-- Declare options for information box creation
local optionsInfoBox = {
infoFont = fontLogo,
infoText = infoText,
isPromptAvailable = isPromptAvailable,
stringPromptPreference = "lockInfoAvailable",
}
yTopFrame = utils.showInformationBox(infoGroup, optionsInfoBox)
commonMethods.showLocksAvailable(infoGroup, yTopFrame, locksAvailable)
else
if (locksAvailable > 0) then
event.target.isActivated = true
event.target.alpha = 1
else
local infoText
local isPromptAvailable = true
if (locksAvailable <= 0) then
infoText = sozluk.getString("lockInformationNA")
isPromptAvailable = false
end

-- Declare options for information box creation
local optionsInfoBox = {
infoFont = fontLogo,
infoText = infoText,
isPromptAvailable = isPromptAvailable,
stringPromptPreference = "lockInfoAvailable",
}
yTopFrame = utils.showInformationBox(infoGroup, optionsInfoBox)
commonMethods.showLocksAvailable(infoGroup, yTopFrame, locksAvailable)
end
end
end
commonMethods.switchLock(event.target, infoGroup, locksAvailable,
tableSoundFiles["lockQuestionSet"], fontLogo)
end
end
end
Expand Down
63 changes: 2 additions & 61 deletions screens/menuScreen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,67 +250,8 @@ function handleTouch(event)
if (event.target.id == "shareSocial" or "rateGame" == event.target.id) then
event.target:setFillColor( unpack(themeData.colorButtonDefault) )
elseif (event.target.id == "lockQuestionSet") then
local lockInfoAvailable = composer.getVariable( "lockInfoAvailable" )

-- Only change the flag as activated
-- This change will be used later on button press("Play") and scene change
if (event.target.isActivated) then
event.target.isActivated = false
event.target.alpha = event.target.alphaInactive
event.target:setFillColor( unpack(themeData.colorPadlock) )
else
audio.play( tableSoundFiles["lockQuestionSet"], {channel = 2} )

-- Check to see if information about lock system will be shown
-- If player discarded the message and chose "Don't show again", don't show info box
if (lockInfoAvailable) then
if (locksAvailable > 0) then
event.target.isActivated = true
event.target.alpha = 1
end

local infoText
local isPromptAvailable = true
if (locksAvailable > 0) then
infoText = sozluk.getString("lockInformation")
else
infoText = sozluk.getString("lockInformationNA")
isPromptAvailable = false
end

-- Declare options for information box creation
local optionsInfoBox = {
infoFont = fontLogo,
infoText = infoText,
isPromptAvailable = isPromptAvailable,
stringPromptPreference = "lockInfoAvailable",
}
yTopFrame = utils.showInformationBox(infoGroup, optionsInfoBox)
commonMethods.showLocksAvailable(infoGroup, yTopFrame, locksAvailable)
else
if (locksAvailable > 0) then
event.target.isActivated = true
event.target.alpha = 1
else
local infoText
local isPromptAvailable = true
if (locksAvailable <= 0) then
infoText = sozluk.getString("lockInformationNA")
isPromptAvailable = false
end

-- Declare options for information box creation
local optionsInfoBox = {
infoFont = fontLogo,
infoText = infoText,
isPromptAvailable = isPromptAvailable,
stringPromptPreference = "lockInfoAvailable",
}
yTopFrame = utils.showInformationBox(infoGroup, optionsInfoBox)
commonMethods.showLocksAvailable(infoGroup, yTopFrame, locksAvailable)
end
end
end
commonMethods.switchLock(event.target, infoGroup, locksAvailable,
tableSoundFiles["lockQuestionSet"], fontLogo)
end
end
end
Expand Down

0 comments on commit ca834aa

Please sign in to comment.