From 9eef8fd6e0f239dd2d3ba85a937777a86aabdb3a Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 17 Feb 2026 21:58:22 +0100 Subject: [PATCH] Util.go_to_screen_by_id --- inc/desition/desition.go_to_home.lua | 8 +------- inc/desition/desition.go_to_office.lua | 8 +------- inc/desition/desition.go_to_toilet.lua | 8 +------- inc/desition/desition.go_to_walking_to_home.lua | 8 +------- inc/desition/desition.go_to_walking_to_office.lua | 8 +------- inc/system/system.util.lua | 10 ++++++++++ 6 files changed, 15 insertions(+), 35 deletions(-) diff --git a/inc/desition/desition.go_to_home.lua b/inc/desition/desition.go_to_home.lua index 3bcdd99..89ed3a4 100644 --- a/inc/desition/desition.go_to_home.lua +++ b/inc/desition/desition.go_to_home.lua @@ -2,13 +2,7 @@ DesitionManager.register({ id = "go_to_home", label = "Go to Home", handle = function() - local screen_index = Context.screen_indices_by_id["home"] - if screen_index then - Context.current_screen = screen_index - Context.selected_desition_index = 1 - else - PopupWindow.show({"Error: Screen 'home' not found or not indexed!"}) - end + Util.go_to_screen_by_id("home") end, condition = function() return true end }) diff --git a/inc/desition/desition.go_to_office.lua b/inc/desition/desition.go_to_office.lua index ff0c32f..75b47ac 100644 --- a/inc/desition/desition.go_to_office.lua +++ b/inc/desition/desition.go_to_office.lua @@ -2,13 +2,7 @@ DesitionManager.register({ id = "go_to_office", label = "Go to Office", handle = function() - local screen_index = Context.screen_indices_by_id["office"] - if screen_index then - Context.current_screen = screen_index - Context.selected_desition_index = 1 - else - PopupWindow.show({"Error: Screen 'office' not found or not indexed!"}) - end + Util.go_to_screen_by_id("office") end, condition = function() return true end }) diff --git a/inc/desition/desition.go_to_toilet.lua b/inc/desition/desition.go_to_toilet.lua index e3d5d52..7127b94 100644 --- a/inc/desition/desition.go_to_toilet.lua +++ b/inc/desition/desition.go_to_toilet.lua @@ -2,13 +2,7 @@ DesitionManager.register({ id = "go_to_toilet", label = "Go to Toilet", handle = function() - local screen_index = Context.screen_indices_by_id["toilet"] - if screen_index then - Context.current_screen = screen_index - Context.selected_desition_index = 1 - else - PopupWindow.show({"Error: Screen 'toilet' not found or not indexed!"}) - end + Util.go_to_screen_by_id("toilet") end, condition = function() return true end }) diff --git a/inc/desition/desition.go_to_walking_to_home.lua b/inc/desition/desition.go_to_walking_to_home.lua index 4bfe117..46cc488 100644 --- a/inc/desition/desition.go_to_walking_to_home.lua +++ b/inc/desition/desition.go_to_walking_to_home.lua @@ -2,13 +2,7 @@ DesitionManager.register({ id = "go_to_walking_to_home", label = "Go to Walking to home", handle = function() - local screen_index = Context.screen_indices_by_id["walking_to_home"] - if screen_index then - Context.current_screen = screen_index - Context.selected_desition_index = 1 - else - PopupWindow.show({"Error: Screen 'walking_to_home' not found or not indexed!"}) - end + Util.go_to_screen_by_id("walking_to_home") end, condition = function() return true end }) diff --git a/inc/desition/desition.go_to_walking_to_office.lua b/inc/desition/desition.go_to_walking_to_office.lua index f424b0a..458b3a8 100644 --- a/inc/desition/desition.go_to_walking_to_office.lua +++ b/inc/desition/desition.go_to_walking_to_office.lua @@ -2,13 +2,7 @@ DesitionManager.register({ id = "go_to_walking_to_office", label = "Go to Walking to office", handle = function() - local screen_index = Context.screen_indices_by_id["walking_to_office"] - if screen_index then - Context.current_screen = screen_index - Context.selected_desition_index = 1 - else - PopupWindow.show({"Error: Screen 'walking_to_office' not found or not indexed!"}) - end + Util.go_to_screen_by_id("walking_to_office") end, condition = function() return true end }) diff --git a/inc/system/system.util.lua b/inc/system/system.util.lua index 0bbcf5e..139a377 100644 --- a/inc/system/system.util.lua +++ b/inc/system/system.util.lua @@ -2,4 +2,14 @@ Util = {} function Util.safeindex(array, index) return ((index - 1 + #array) % #array) + 1 +end + +function Util.go_to_screen_by_id(screen_id) + local screen_index = Context.screen_indices_by_id[screen_id] + if screen_index then + Context.current_screen = screen_index + Context.selected_desition_index = 1 -- Reset selected decision on new screen + else + PopupWindow.show({"Error: Screen '" .. screen_id .. "' not found or not indexed!"}) + end end \ No newline at end of file