diff --git a/.luacheckrc b/.luacheckrc index 0def48a..f16500d 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -4,6 +4,7 @@ globals = { "Util", "Decision", + "Situation", "Screen", "UI", "Print", diff --git a/impostor.inc b/impostor.inc index 9f86ad7..44ae875 100644 --- a/impostor.inc +++ b/impostor.inc @@ -5,7 +5,10 @@ init/init.minigames.lua init/init.meters.lua system/system.util.lua init/init.windows.lua +situation/situation.manager.lua +situation/situation.drink_coffee.lua decision/decision.manager.lua +decision/decision.have_a_coffee.lua decision/decision.go_to_home.lua decision/decision.go_to_toilet.lua decision/decision.go_to_walking_to_office.lua diff --git a/inc/decision/decision.have_a_coffee.lua b/inc/decision/decision.have_a_coffee.lua new file mode 100644 index 0000000..e92e940 --- /dev/null +++ b/inc/decision/decision.have_a_coffee.lua @@ -0,0 +1,8 @@ +Decision.register({ + id = "have_a_coffee", + label = "Have a Coffee", + handle = function() + Situation.apply("drink_coffee") + end, + condition = function() return true end +}) diff --git a/inc/init/init.modules.lua b/inc/init/init.modules.lua index d0f06e2..58d56e6 100644 --- a/inc/init/init.modules.lua +++ b/inc/init/init.modules.lua @@ -12,6 +12,7 @@ Util = {} Meters = {} Minigames = {} Decision = {} +Situation = {} Screen = {} Map = {} UI = {} diff --git a/inc/screen/screen.manager.lua b/inc/screen/screen.manager.lua index 9a54f95..42b50f3 100644 --- a/inc/screen/screen.manager.lua +++ b/inc/screen/screen.manager.lua @@ -1,17 +1,12 @@ local _screens = {} -function Screen.get_screens_array() - local screens_array = {} - for _, screen_data in pairs(_screens) do - table.insert(screens_array, screen_data) - end - return screens_array -end - function Screen.register(screen_data) if _screens[screen_data.id] then trace("Warning: Overwriting screen with id: " .. screen_data.id) end + if not screen_data.situations then + screen_data.situations = {} + end _screens[screen_data.id] = screen_data end diff --git a/inc/screen/screen.office.lua b/inc/screen/screen.office.lua index ad0e61a..b3bb3c7 100644 --- a/inc/screen/screen.office.lua +++ b/inc/screen/screen.office.lua @@ -6,5 +6,9 @@ Screen.register({ "play_rhythm", "play_ddr", "go_to_walking_to_home", - } + "have_a_coffee", + }, + situations = { + "drink_coffee", + }, }) diff --git a/inc/situation/situation.drink_coffee.lua b/inc/situation/situation.drink_coffee.lua new file mode 100644 index 0000000..d791d0e --- /dev/null +++ b/inc/situation/situation.drink_coffee.lua @@ -0,0 +1,6 @@ +Situation.register({ + id = "drink_coffee", + handle = function() + Audio.sfx_select() + end, +}) diff --git a/inc/situation/situation.manager.lua b/inc/situation/situation.manager.lua new file mode 100644 index 0000000..dfc8abf --- /dev/null +++ b/inc/situation/situation.manager.lua @@ -0,0 +1,36 @@ +local _situations = {} + +function Situation.register(situation) + if not situation or not situation.id then + PopupWindow.show({"Error: Invalid situation object registered (missing id)!"}) + return + end + if not situation.handle then + situation.handle = function() end + end + if _situations[situation.id] then + trace("Warning: Overwriting situation with id: " .. situation.id) + end + _situations[situation.id] = situation +end + +function Situation.get(id) + return _situations[id] +end + +function Situation.apply(id) + local situation = Situation.get(id) + if not situation then + trace("Error: No situation found with id: " .. id) + return + end + + local current_screen_obj = Screen.get_by_id(Context.current_screen) + if current_screen_obj and not current_screen_obj.situations[id] then + trace("Info: Situation " .. id .. " cannot be applied to current screen (id: " .. Context.current_screen .. ").") + return + end + + situation.handle() +end +