From 342f640bda1195a99f22baca4502eba69c0580ea Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Wed, 27 Dec 2023 03:19:47 +0100 Subject: [PATCH] implement and simplify layout switching --- items/items.json | 50 ------------ scripts/autotracking/archipelago.lua | 52 ++---------- scripts/layout_switch.lua | 118 +++++++-------------------- 3 files changed, 37 insertions(+), 183 deletions(-) diff --git a/items/items.json b/items/items.json index 115a68f..a36cfed 100644 --- a/items/items.json +++ b/items/items.json @@ -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", diff --git a/scripts/autotracking/archipelago.lua b/scripts/autotracking/archipelago.lua index b35282f..86eabc2 100644 --- a/scripts/autotracking/archipelago.lua +++ b/scripts/autotracking/archipelago.lua @@ -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") @@ -105,16 +107,9 @@ 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 @@ -122,43 +117,8 @@ function onClear(slot_data) 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 = {} diff --git a/scripts/layout_switch.lua b/scripts/layout_switch.lua index 4a9f0cb..88324a0 100644 --- a/scripts/layout_switch.lua +++ b/scripts/layout_switch.lua @@ -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)