Skip to content

Commit

Permalink
implement and simplify layout switching
Browse files Browse the repository at this point in the history
  • Loading branch information
black-sliver committed Dec 27, 2023
1 parent 942a342 commit 342f640
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 183 deletions.
50 changes: 0 additions & 50 deletions items/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,56 +221,6 @@
}
]
},
// LAYOUTS
{
"name": "Progressive Breaker Layout",
"type": "toggle",
"img": "images/icons/icon_attack.png",
"disabled_img": "images/icons/icon_attack_grey.png",
"codes": "progbreakerLayout"
},
{
"name": "Progressive Slide Layout",
"type": "toggle",
"img": "images/icons/icon_slide.png",
"disabled_img": "images/icons/icon_slide_grey.png",
"codes": "progslideLayout"
},
{
"name": "Split Kicks Layout",
"type": "toggle",
"img": "images/icons/icon_HeliacalPower.png",
"disabled_img": "images/icons/icon_HeliacalPower_grey.png",
"codes": "splitkickLayout"
},
{
"name": "Progressive Breaker and Progressive Slide Layout",
"type": "toggle",
"img": "images/icons/icon_HeliacalPower.png",
"disabled_img": "images/icons/icon_HeliacalPower_grey.png",
"codes": "progbreakerprogslideLayout"
},
{
"name": "Progressive Breaker and Split Kick Layout",
"type": "toggle",
"img": "images/icons/icon_HeliacalPower.png",
"disabled_img": "images/icons/icon_HeliacalPower_grey.png",
"codes": "progbreakersplitkickLayout"
},
{
"name": "Progressive Slide and Split Kick Layout",
"type": "toggle",
"img": "images/icons/icon_HeliacalPower.png",
"disabled_img": "images/icons/icon_HeliacalPower_grey.png",
"codes": "progslidesplitkickLayout"
},
{
"name": "All Progressives and Split Kick Layout",
"type": "toggle",
"img": "images/icons/icon_HeliacalPower.png",
"disabled_img": "images/icons/icon_HeliacalPower_grey.png",
"codes": "progsandsplitLayout"
},
// EXAMPLE CODE
{
"name": "Progressive",
Expand Down
52 changes: 6 additions & 46 deletions scripts/autotracking/archipelago.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ function onClear(slot_data)
obj.Active = slot_data.obscure_logic
end
end


pauseLayoutUpdate = true -- pause updating until all codes are set since update is expensive

if slot_data.progressive_breaker then
print("slot_data.progressive_breaker: " .. tostring(slot_data.progressive_breaker))
local obj = Tracker:FindObjectForCode("op_progbreaker")
Expand All @@ -105,60 +107,18 @@ function onClear(slot_data)
end
end

--if slot_data.split_sun_greaves then
--print("slot_data.split_sun_greaves: " .. tostring(slot_data.split_sun_greaves))
--local obj = Tracker:FindObjectForCode("op_splitkick_on")
--if obj then
--obj.Active = slot_data.split_sun_greaves
--end
--end

if slot_data.split_sun_greaves then
print("slot_data.split_sun_greaves: " .. tostring(slot_data.split_sun_greaves))
-- op_splitkick is progressive because both stages are used for visibility_rules
if slot_data.split_sun_greaves == false then
Tracker:FindObjectForCode("op_splitkick_on").CurrentStage = 0
elseif slot_data.split_sun_greaves == true then
Tracker:FindObjectForCode("op_splitkick_on").CurrentStage = 1
end
end

-- Layout Toggles
if slot_data.progressive_breaker and slot_data.progressive_slide and slot_data.split_sun_greaves then
local obj = Tracker:FindObjectForCode("progsandsplitLayout")
if obj then
obj.Active = slot_data.progressive_breaker and slot_data.progressive_slide and slot_data.split_sun_greaves
end
elseif slot_data.progressive_breaker and slot_data.progressive_slide then
local obj = Tracker:FindObjectForCode("progbreakerprogslideLayout")
if obj then
obj.Active = slot_data.progressive_breaker and slot_data.progressive_slide
end
elseif slot_data.progressive_breaker and slot_data.split_sun_greaves then
local obj = Tracker:FindObjectForCode("progbreakersplitkickLayout")
if obj then
obj.Active = slot_data.progressive_breaker and slot_data.split_sun_greaves
end
elseif slot_data.progressive_slide and slot_data.split_sun_greaves then
local obj = Tracker:FindObjectForCode("progslidesplitkickLayout")
if obj then
obj.Active = slot_data.progressive_slide and slot_data.split_sun_greaves
end
elseif slot_data.progressive_breaker then
local obj = Tracker:FindObjectForCode("progbreakerLayout")
if obj then
obj.Active = slot_data.progressive_breaker
end
elseif slot_data.progressive_slide then
local obj = Tracker:FindObjectForCode("progslideLayout")
if obj then
obj.Active = slot_data.progressive_slide
end
elseif slot_data.split_sun_greaves then
local obj = Tracker:FindObjectForCode("splitkickLayout")
if obj then
obj.Active = slot_data.split_sun_greaves
end
end
pauseLayoutUpdate = false
updateLayout() -- actually update

LOCAL_ITEMS = {}
GLOBAL_ITEMS = {}
Expand Down
118 changes: 31 additions & 87 deletions scripts/layout_switch.lua
Original file line number Diff line number Diff line change
@@ -1,95 +1,39 @@
-- LAYOUT SWITCHING
-- change layout depending on options

local currentLayoutNum = 1 -- standard

function apLayoutChange1()
local progBreaker = Tracker:FindObjectForCode("progbreakerLayout")
if (string.find(Tracker.ActiveVariantUID, "standard")) then
if progBreaker.Active then
Tracker:AddLayouts("layouts/items_only_progbreaker.json")
--Tracker:AddLayouts("layouts/broadcast_horizontal_AP.json") -- ADD LATER
else
Tracker:AddLayouts("layouts/items_standard.json")
end
function updateLayout()
if pauseLayoutUpdate then -- global set from AP autotracking to pause updating
return -- update deferred
end
end

function apLayoutChange2()
local progSlide = Tracker:FindObjectForCode("progslideLayout")
if (string.find(Tracker.ActiveVariantUID, "standard")) then
if progSlide.Active then
Tracker:AddLayouts("layouts/items_only_progslide.json")
--Tracker:AddLayouts("layouts/broadcast_horizontal_AP.json") -- ADD LATER
else
Tracker:AddLayouts("layouts/items_standard.json")
end
end
end

function apLayoutChange3()
local splitKick = Tracker:FindObjectForCode("splitkickLayout")
if (string.find(Tracker.ActiveVariantUID, "standard")) then
if splitKick.Active then
Tracker:AddLayouts("layouts/items_only_splitkick.json")
--Tracker:AddLayouts("layouts/broadcast_horizontal_AP.json") -- ADD LATER
else
Tracker:AddLayouts("layouts/items_standard.json")
end
end
end

function apLayoutChange4()
local progBprogS = Tracker:FindObjectForCode("progbreakerprogslideLayout")
if (string.find(Tracker.ActiveVariantUID, "standard")) then
if progBprogS.Active then
Tracker:AddLayouts("layouts/items_progbreaker_and_progslide.json")
--Tracker:AddLayouts("layouts/broadcast_horizontal_AP.json") -- ADD LATER
else
Tracker:AddLayouts("layouts/items_standard.json")
end
end
end

function apLayoutChange5()
local progBsplitK = Tracker:FindObjectForCode("progbreakersplitkickLayout")
if (string.find(Tracker.ActiveVariantUID, "standard")) then
if progBsplitK.Active then
Tracker:AddLayouts("layouts/items_progbreaker_and_splitkick.json")
--Tracker:AddLayouts("layouts/broadcast_horizontal_AP.json") -- ADD LATER
else
Tracker:AddLayouts("layouts/items_standard.json")
end
end
end

function apLayoutChange6()
local progSsplitK = Tracker:FindObjectForCode("progslidesplitkickLayout")
if (string.find(Tracker.ActiveVariantUID, "standard")) then
if progSsplitK.Active then
Tracker:AddLayouts("layouts/items_progslide_and_splitkick.json")
--Tracker:AddLayouts("layouts/broadcast_horizontal_AP.json") -- ADD LATER
else
Tracker:AddLayouts("layouts/items_standard.json")
end
end
end

function apLayoutChange7()
local progBSsplitK = Tracker:FindObjectForCode("progsandsplitLayout")
if (string.find(Tracker.ActiveVariantUID, "standard")) then
if progBSsplitK.Active then
Tracker:AddLayouts("layouts/items_progs_and_split.json")
--Tracker:AddLayouts("layouts/broadcast_horizontal_AP.json") -- ADD LATER
else
Tracker:AddLayouts("layouts/items_standard.json")
end
-- read toggles
local progBreaker = Tracker:ProviderCountForCode("op_progbreaker") > 0
local progSlide = Tracker:ProviderCountForCode("op_progslide") > 0
local splitKicks = Tracker:ProviderCountForCode("op_splitkick_on") > 0
-- encode 3 toggles into a 3 bit integer (8 states), +1 for Lua array starting at 1
local layoutNum = 1 + (progBreaker and 1 or 0) + (progSlide and 2 or 0) + (splitKicks and 4 or 0)
print(tostring(currentLayoutNum) .. " -> " .. tostring(layoutNum))
if layoutNum == currentLayoutNum then
return -- unchanged
end
-- select layout from number
local layoutNames = {
"layouts/items_standard.json",
"layouts/items_only_progbreaker.json",
"layouts/items_only_progslide.json",
"layouts/items_progbreaker_and_progslide.json",
"layouts/items_only_splitkick.json",
"layouts/items_progbreaker_and_splitkick.json",
"layouts/items_progslide_and_splitkick.json",
"layouts/items_progs_and_split.json",
}
local layoutName = layoutNames[layoutNum]
-- load layout
Tracker:AddLayouts(layoutName)
currentLayoutNum = layoutNum -- remember what is currently loaded
end

ScriptHost:AddWatchForCode("useApLayout1", "progbreakerLayout", apLayoutChange1)
ScriptHost:AddWatchForCode("useApLayout2", "progslideLayout", apLayoutChange2)
ScriptHost:AddWatchForCode("useApLayout3", "splitkickLayout", apLayoutChange3)
ScriptHost:AddWatchForCode("useApLayout4", "progbreakerprogslideLayout", apLayoutChange4)
ScriptHost:AddWatchForCode("useApLayout5", "progbreakersplitkickLayout", apLayoutChange5)
ScriptHost:AddWatchForCode("useApLayout6", "progslidesplitkickLayout", apLayoutChange6)
ScriptHost:AddWatchForCode("useApLayout7", "progsandsplitLayout", apLayoutChange7)
ScriptHost:AddWatchForCode("op_progbreaker", "op_progbreaker", updateLayout)
ScriptHost:AddWatchForCode("op_progslide", "op_progslide", updateLayout)
ScriptHost:AddWatchForCode("op_splitkick", "op_splitkick", updateLayout)

0 comments on commit 342f640

Please sign in to comment.