Compare commits

..

1 Commits

Author SHA1 Message Date
87d4f5843b Merge pull request 'beta1 release' (#46) from develop into master
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: http://git.teletype.hu/games/impostor/pulls/46
2026-03-22 22:49:23 +00:00
31 changed files with 176 additions and 180 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,3 @@
.claude
.local
impostor.lua
impostor.original.lua

View File

@@ -10,6 +10,7 @@ globals = {
"Discussion",
"Util",
"Decision",
"Situation",
"Screen",
"Sprite",
"UI",
@@ -65,10 +66,6 @@ globals = {
"map",
"time",
"RLE",
"mouse",
"Mouse",
"print",
"musicator_generate_pattern",
}

View File

@@ -6,7 +6,6 @@ init/init.context.lua
system/system.util.lua
system/system.print.lua
system/system.input.lua
system/system.mouse.lua
system/system.asciiart.lua
system/system.rle.lua
logic/logic.meter.lua
@@ -39,7 +38,10 @@ sprite/sprite.matrix_architect.lua
sprite/sprite.matrix_neo.lua
sprite/sprite.matrix_oraculum.lua
sprite/sprite.matrix_trinity.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

View File

@@ -0,0 +1,16 @@
Decision.register({
id = "have_a_coffee",
label = "Have a Coffee",
handle = function()
local new_situation_id = Situation.apply("drink_coffee", Context.game.current_screen)
local level = Ascension.get_level()
local disc_id = "coworker_disc_0"
-- TODO: Add more discussions for levels above 3
if level >= 1 and level <= 3 then
local suffix = Context.have_done_work_today and ("_asc_" .. level) or ("_" .. level)
disc_id = "coworker_disc" .. suffix
end
Discussion.start(disc_id, "game")
Context.game.current_situation = new_situation_id
end,
})

View File

@@ -134,7 +134,6 @@ end
--- @param decisions table A table of decision items.<br/>
--- @param selected_decision_index number The current index of the selected decision.<br/>
--- @return number selected_decision_index The updated index of the selected decision.
--- @return boolean mouse_confirmed True if the user clicked the center to confirm.
function Decision.update(decisions, selected_decision_index)
if Input.left() then
Audio.sfx_beep()
@@ -143,27 +142,5 @@ function Decision.update(decisions, selected_decision_index)
Audio.sfx_beep()
selected_decision_index = Util.safeindex(decisions, selected_decision_index + 1)
end
if Mouse.clicked() then
local mx = Mouse.x()
local my = Mouse.y()
local bar_height = 16
local bar_y = Config.screen.height - bar_height
if my >= bar_y then
if mx < 15 then
Audio.sfx_beep()
Mouse.consume()
selected_decision_index = Util.safeindex(decisions, selected_decision_index - 1)
elseif mx > Config.screen.width - 15 then
Audio.sfx_beep()
Mouse.consume()
selected_decision_index = Util.safeindex(decisions, selected_decision_index + 1)
else
Mouse.consume()
return selected_decision_index, true
end
end
end
return selected_decision_index, false
return selected_decision_index
end

View File

@@ -23,7 +23,7 @@ Context = {}
--- * have_met_sumphore (boolean) Whether the player has talked to the homeless guy.<br/>
--- * have_been_to_office (boolean) Whether the player has been to the office.<br/>
--- * have_done_work_today (boolean) Whether the player has done work today.<br/>
--- * game (table) Current game progress state. Contains: `current_screen` (string) active screen ID<br/>
--- * game (table) Current game progress state. Contains: `current_screen` (string) active screen ID, `current_situation` (string|nil) active situation ID.<br/>
function Context.initial_data()
return {
current_menu_item = 1,
@@ -48,6 +48,7 @@ function Context.initial_data()
have_met_sumphore = false,
game = {
current_screen = "home",
current_situation = nil,
},
day_count = 1,
delta_time = 0,

View File

@@ -3,12 +3,12 @@ Util = {}
Meter = {}
Minigame = {}
Decision = {}
Situation = {}
Screen = {}
Map = {}
UI = {}
Print = {}
Input = {}
Mouse = {}
Sprite = {}
Audio = {}
Focus = {}

View File

@@ -4,5 +4,5 @@
-- desc: Life of a programmer
-- site: https://git.teletype.hu/games/impostor
-- license: MIT License
-- version: 1.0-beta2
-- version: 1.0-beta1
-- script: lua

View File

@@ -8,6 +8,7 @@ local _screens = {}
--- @param screen_data.name string Display name of the screen.
--- @param screen_data.decisions table Array of decision ID strings available on this screen.
--- @param screen_data.background string Map ID used as background.
--- @param[opt] screen_data.situations table Array of situation ID strings. Defaults to {}.
--- @param[opt] screen_data.init function Called when the screen is entered. Defaults to noop.
--- @param[opt] screen_data.update function Called each frame while screen is active. Defaults to noop.
--- @param[opt] screen_data.draw function Called after the focus overlay to draw screen-specific overlays. Defaults to noop.
@@ -15,6 +16,9 @@ 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
if not screen_data.init then
screen_data.init = function() end
end
@@ -39,6 +43,7 @@ end
--- * name (string) Display name.<br/>
--- * decisions (table) Array of decision ID strings.<br/>
--- * background (string) Map ID used as background.<br/>
--- * situations (table) Array of situation ID strings.<br/>
--- * init (function) Called when the screen is entered.<br/>
--- * update (function) Called each frame while screen is active.
function Screen.get_by_id(screen_id)
@@ -53,6 +58,7 @@ end
--- * name (string) Display name of the screen.<br/>
--- * decisions (table) Array of decision ID strings available on this screen.<br/>
--- * background (string) Map ID used as background.<br/>
--- * situations (table) Array of situation ID strings.<br/>
--- * init (function) Called when the screen is entered.<br/>
--- * update (function) Called each frame while screen is active.<br/>
function Screen.get_all()

View File

@@ -240,12 +240,9 @@ Screen.register({
end
end
elseif state == STATE_CHOICE then
local menu_x = (Config.screen.width - 60) / 2
local menu_y = (Config.screen.height - 20) / 2
local confirmed
selected_choice, confirmed = UI.update_menu(MysteriousManScreen.choices, selected_choice, menu_x, menu_y)
selected_choice = UI.update_menu(MysteriousManScreen.choices, selected_choice)
if Input.select() or confirmed then
if Input.select() then
Audio.sfx_select()
if selected_choice == 1 then
MysteriousManScreen.wake_up()

View File

@@ -6,6 +6,9 @@ Screen.register({
"go_to_walking_to_home",
"have_a_coffee",
},
situations = {
"drink_coffee",
},
init = function()
Audio.music_play_room_work()
end,

View File

@@ -16,7 +16,7 @@ Screen.register({
end,
update = function()
if not Context.stat_screen_active then return end
if Input.select() or Input.select() then
if Input.select() or Input.player_interact() then
Focus.stop()
Context.stat_screen_active = false
Meter.show()

View File

@@ -0,0 +1,6 @@
Situation.register({
id = "drink_coffee",
handle = function()
Audio.sfx_select()
end,
})

View File

@@ -0,0 +1,84 @@
--- @section Situation
local _situations = {}
--- Registers a situation definition.
--- @within Situation
--- @param situation table The situation data table.
--- @param situation.id string Unique situation identifier.<br/>
--- @param[opt] situation.screen_id string ID of the screen this situation belongs to.<br/>
--- @param[opt] situation.handle function Called when the situation is applied. Defaults to noop.<br/>
--- @param[opt] situation.update function Called each frame while situation is active. Defaults to noop.<br/>
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 not situation.update then
situation.update = function() end
end
if _situations[situation.id] then
trace("Warning: Overwriting situation with id: " .. situation.id)
end
_situations[situation.id] = situation
end
--- Gets a situation by ID.
--- @within Situation
--- @param id string The situation ID.
--- @return result table The situation table or nil. </br>
--- Fields: </br>
--- * id (string) Unique situation identifier.<br/>
--- * screen_id (string) ID of the screen this situation belongs to.<br/>
--- * handle (function) Called when the situation is applied.<br/>
--- * update (function) Called each frame while situation is active.<br/>
function Situation.get_by_id(id)
return _situations[id]
end
--- Gets all registered situations, optionally filtered by screen ID.
--- @within Situation
--- @param screen_id string Optional. If provided, returns situations associated with this screen ID.
--- @return result table A table containing all registered situation data, indexed by their IDs, or an array filtered by screen_id. </br>
--- Fields: </br>
--- * id (string) Unique situation identifier.<br/>
--- * screen_id (string) ID of the screen this situation belongs to.<br/>
--- * handle (function) Called when the situation is applied.<br/>
--- * update (function) Called each frame while situation is active.<br/>
function Situation.get_all(screen_id)
if screen_id then
local filtered_situations = {}
for _, situation in pairs(_situations) do
if situation.screen_id == screen_id then
table.insert(filtered_situations, situation)
end
end
return filtered_situations
end
return _situations
end
--- Applies a situation, checking screen compatibility and returning the new situation ID if successful.
--- @within Situation
--- @param id string The situation ID to apply.
--- @param current_screen_id string The ID of the currently active screen.
--- @return string|nil The ID of the applied situation if successful, otherwise nil.
function Situation.apply(id, current_screen_id)
local situation = Situation.get_by_id(id)
local screen = Screen.get_by_id(current_screen_id)
if not situation then
trace("Error: No situation found with id: " .. id)
return nil
end
if Util.contains(screen.situations, id) then
situation.handle()
return id
else
trace("Info: Situation " .. id .. " cannot be applied to current screen (id: " .. current_screen_id .. ").")
return nil
end
end

View File

@@ -3,9 +3,12 @@ local INPUT_KEY_UP = 0
local INPUT_KEY_DOWN = 1
local INPUT_KEY_LEFT = 2
local INPUT_KEY_RIGHT = 3
local INPUT_KEY_A = 4
local INPUT_KEY_B = 5
local INPUT_KEY_Y = 7
local INPUT_KEY_SPACE = 48
local INPUT_KEY_BACKSPACE = 51
local INPUT_KEY_ENTER = 50
--- Checks if Up is pressed.
--- @within Input
@@ -19,9 +22,22 @@ function Input.left() return btnp(INPUT_KEY_LEFT) end
--- Checks if Right is pressed.
--- @within Input
function Input.right() return btnp(INPUT_KEY_RIGHT) end
--- Checks if Space is pressed.
--- @within Input
function Input.space() return keyp(INPUT_KEY_SPACE) end
--- Checks if Select is pressed.
--- @within Input
function Input.select() return btnp(INPUT_KEY_Y) or keyp(INPUT_KEY_SPACE) or Mouse.clicked() end
--- Checks if Back is pressed.
function Input.select() return btnp(INPUT_KEY_A) or keyp(INPUT_KEY_SPACE) end
--- Checks if Menu Confirm is pressed.
--- @within Input
function Input.back() return keyp(INPUT_KEY_BACKSPACE) end
function Input.menu_confirm() return btnp(INPUT_KEY_A) or keyp(INPUT_KEY_ENTER) end
--- Checks if Player Interact is pressed.
--- @within Input
function Input.player_interact() return btnp(INPUT_KEY_B) or keyp(INPUT_KEY_ENTER) end
--- Checks if Menu Back is pressed.
--- @within Input
function Input.menu_back() return btnp(INPUT_KEY_Y) or keyp(INPUT_KEY_BACKSPACE) end
--- Checks if Toggle Popup is pressed.
--- @within Input
function Input.toggle_popup() return keyp(INPUT_KEY_ENTER) end

View File

@@ -17,7 +17,6 @@ end
--- @within Main
function TIC()
init_game()
Mouse.update()
local now = time()
if Context.last_frame_time == 0 then

View File

@@ -1,43 +0,0 @@
--- @section Mouse
local _mx, _my = 0, 0
local _mleft, _mleft_prev = false, false
local _consumed = false
--- Updates mouse state. Call once per frame.
--- @within Mouse
function Mouse.update()
_mleft_prev = _mleft
_consumed = false
local mt = {mouse()}
_mx, _my, _mleft = mt[1], mt[2], mt[3]
end
--- Returns current mouse X position.
--- @within Mouse
function Mouse.x() return _mx end
--- Returns current mouse Y position.
--- @within Mouse
function Mouse.y() return _my end
--- Returns true if the mouse button was just pressed this frame (and not yet consumed).
--- @within Mouse
function Mouse.clicked() return _mleft and not _mleft_prev and not _consumed end
--- Returns true if the mouse button is held down.
--- @within Mouse
function Mouse.held() return _mleft end
--- Marks the current click as consumed so Mouse.clicked() won't fire again this frame.
--- @within Mouse
function Mouse.consume() _consumed = true end
--- Returns true if the mouse is within the given rectangle.
--- @within Mouse
--- @param x number Left edge.
--- @param y number Top edge.
--- @param w number Width.
--- @param h number Height.
function Mouse.in_rect(x, y, w, h)
return _mx >= x and _mx < x + w and _my >= y and _my < y + h
end

View File

@@ -38,12 +38,8 @@ end
--- @within UI
--- @param items table A table of menu items.<br/>
--- @param selected_item number The current index of the selected item.<br/>
--- @param[opt] x number Menu x position (required for mouse support).<br/>
--- @param[opt] y number Menu y position (required for mouse support).<br/>
--- @param[opt] centered boolean Whether the menu is centered horizontally.<br/>
--- @return number selected_item The updated index of the selected item.
--- @return boolean mouse_confirmed True if the user clicked on a menu item.
function UI.update_menu(items, selected_item, x, y, centered)
function UI.update_menu(items, selected_item)
if Input.up() then
Audio.sfx_beep()
selected_item = selected_item - 1
@@ -57,29 +53,7 @@ function UI.update_menu(items, selected_item, x, y, centered)
selected_item = 1
end
end
if x ~= nil and y ~= nil and Mouse.clicked() then
local mx = Mouse.x()
local my = Mouse.y()
local menu_x = x
if centered then
local max_w = 0
for _, item in ipairs(items) do
local w = print(item.label, 0, -10, 0, false, 1, false)
if w > max_w then max_w = w end
end
menu_x = (Config.screen.width - max_w) / 2
end
for i, _ in ipairs(items) do
local item_y = y + (i - 1) * 10
if my >= item_y and my < item_y + 10 and mx >= menu_x - 8 then
Mouse.consume()
return i, true
end
end
end
return selected_item, false
return selected_item
end
--- Draws a bordered textbox with scrolling text.

View File

@@ -107,9 +107,9 @@ function AudioTestWindow.update()
AudioTestWindow.menuitems = AudioTestWindow.generate_menuitems(
AudioTestWindow.list_func, AudioTestWindow.index_func
)
elseif Input.select() then
elseif Input.menu_confirm() then
AudioTestWindow.menuitems[AudioTestWindow.index_menu].decision()
elseif Input.back() then
elseif Input.menu_back() then
AudioTestWindow.back()
end
end

View File

@@ -65,7 +65,7 @@ end
--- Updates configuration window logic.
--- @within ConfigurationWindow
function ConfigurationWindow.update()
if Input.back() then
if Input.menu_back() then
GameWindow.set_state("menu")
return
end
@@ -94,7 +94,7 @@ function ConfigurationWindow.update()
control.set(new_value)
end
elseif control.type == "action_item" then
if Input.select() then
if Input.menu_confirm() then
control.action()
end
end

View File

@@ -26,7 +26,7 @@ end
--- @within ContinuedWindow
function ContinuedWindow.update()
ContinuedWindow.timer = ContinuedWindow.timer - 1
if ContinuedWindow.timer <= 0 or Input.select() or Input.select() then
if ContinuedWindow.timer <= 0 or Input.select() or Input.menu_confirm() then
Window.set_current("menu")
MenuWindow.refresh_menu_items()
end

View File

@@ -52,7 +52,7 @@ function EndWindow.update()
end
end
if Input.select() then
if Input.menu_confirm() then
Audio.sfx_select()
if Context._end.selection == 1 then
Context._end.state = "ending"
@@ -69,7 +69,7 @@ function EndWindow.update()
end
end
elseif Context._end.state == "ending" then
if Input.select() then
if Input.menu_confirm() then
Window.set_current("menu")
MenuWindow.refresh_menu_items()
end

View File

@@ -38,7 +38,7 @@ end
--- @within GameWindow
function GameWindow.update()
Focus.update()
if Input.back() then
if Input.menu_back() then
Window.set_current("menu")
MenuWindow.refresh_menu_items()
return
@@ -48,6 +48,14 @@ function GameWindow.update()
if not screen or not screen.update then return end
screen.update()
-- Handle current situation updates
if Context.game.current_situation then
local current_situation_obj = Situation.get_by_id(Context.game.current_situation)
if current_situation_obj and type(current_situation_obj.update) == "function" then
current_situation_obj.update()
end
end
if Context.stat_screen_active then return end
-- Fetch and filter decisions locally
@@ -60,7 +68,7 @@ function GameWindow.update()
_selected_decision_index = 1
end
local new_selected_decision_index, mouse_confirmed = Decision.update(
local new_selected_decision_index = Decision.update(
_available_decisions,
_selected_decision_index
)
@@ -69,7 +77,7 @@ function GameWindow.update()
_selected_decision_index = new_selected_decision_index
end
if Input.select() or mouse_confirmed then
if Input.select() then
local selected_decision = _available_decisions[_selected_decision_index]
if selected_decision and selected_decision.handle then
Audio.sfx_select()

View File

@@ -31,7 +31,7 @@ function BriefIntroWindow.update()
lines = lines + 1
end
if BriefIntroWindow.y < -lines * 8 or Input.select() or Input.select() then
if BriefIntroWindow.y < -lines * 8 or Input.select() or Input.menu_confirm() then
Window.set_current("menu")
end
end

View File

@@ -30,7 +30,7 @@ end
--- @within TitleIntroWindow
function TitleIntroWindow.update()
TitleIntroWindow.timer = TitleIntroWindow.timer - 1
if TitleIntroWindow.timer <= 0 or Input.select() or Input.select() then
if TitleIntroWindow.timer <= 0 or Input.select() or Input.menu_confirm() then
Window.set_current("intro_ttg")
end
end

View File

@@ -28,12 +28,12 @@ function TTGIntroWindow.update()
end
-- Count menu_back presses during the intro
if Input.back() then
if Input.menu_back() then
TTGIntroWindow.space_count = TTGIntroWindow.space_count + 1
end
TTGIntroWindow.timer = TTGIntroWindow.timer - 1
if TTGIntroWindow.timer <= 0 or Input.select() then
if TTGIntroWindow.timer <= 0 or Input.menu_confirm() then
-- Evaluate exactly 3 presses at the end of the intro
if TTGIntroWindow.space_count == 3 then
Context.test_mode = true

View File

@@ -1,6 +1,5 @@
--- @section MenuWindow
local _menu_items = {}
local _click_timer = 0
--- Draws the menu window.
--- @within MenuWindow
@@ -23,28 +22,9 @@ end
--- Updates the menu window logic.
--- @within MenuWindow
function MenuWindow.update()
local menu_h = #_menu_items * 10
local y = 10 + (Config.screen.height - 10 - 10 - menu_h) / 2
Context.current_menu_item = UI.update_menu(_menu_items, Context.current_menu_item)
if _click_timer > 0 then
_click_timer = _click_timer - Context.delta_time
if _click_timer <= 0 then
_click_timer = 0
local selected_item = _menu_items[Context.current_menu_item]
if selected_item and selected_item.decision then
selected_item.decision()
end
end
return
end
local new_item, mouse_confirmed = UI.update_menu(_menu_items, Context.current_menu_item, 0, y, true)
Context.current_menu_item = new_item
if mouse_confirmed then
Audio.sfx_select()
_click_timer = 0.5
elseif Input.select() then
if Input.menu_confirm() then
local selected_item = _menu_items[Context.current_menu_item]
if selected_item and selected_item.decision then
Audio.sfx_select()
@@ -135,5 +115,4 @@ function MenuWindow.refresh_menu_items()
table.insert(_menu_items, {label = "Exit", decision = MenuWindow.exit})
Context.current_menu_item = 1
_click_timer = 0
end

View File

@@ -355,17 +355,6 @@ function MinigameDDRWindow.update()
right = Input.right()
}
if Mouse.clicked() then
local mx = Mouse.x()
local my = Mouse.y()
for _, target in ipairs(mg.target_arrows) do
if mx >= target.x and mx < target.x + mg.arrow_size and
my >= mg.target_y and my < mg.target_y + mg.arrow_size then
input_map[target.dir] = true
end
end
end
for dir, pressed in pairs(input_map) do
if pressed and mg.input_cooldowns[dir] == 0 then
mg.input_cooldowns[dir] = mg.input_cooldown_duration

View File

@@ -83,14 +83,7 @@ function MinigameButtonMashWindow.update()
return
end
local mouse_on_button = false
if Mouse.clicked() then
local dx = Mouse.x() - mg.button_x
local dy = Mouse.y() - mg.button_y
mouse_on_button = (dx * dx + dy * dy) <= (mg.button_size * mg.button_size)
end
if Input.select() or mouse_on_button then
if Input.select() then
Audio.sfx_drum_high()
mg.bar_fill = mg.bar_fill + mg.fill_per_press

View File

@@ -95,14 +95,7 @@ function MinigameRhythmWindow.update()
if mg.press_cooldown > 0 then
mg.press_cooldown = mg.press_cooldown - 1
end
local mouse_on_button = false
if Mouse.clicked() then
local dx = Mouse.x() - mg.button_x
local dy = Mouse.y() - mg.button_y
mouse_on_button = (dx * dx + dy * dy) <= (mg.button_size * mg.button_size)
end
if (Input.select() or mouse_on_button) and mg.press_cooldown == 0 then
if Input.select() and mg.press_cooldown == 0 then
mg.button_pressed_timer = mg.button_press_duration
mg.press_cooldown = mg.press_cooldown_duration
local target_left = mg.target_center - (mg.target_width / 2)

View File

@@ -28,7 +28,7 @@ end
--- @within PopupWindow
function PopupWindow.update()
if Context.popup.show then
if Input.select() or Input.back() then
if Input.menu_confirm() or Input.menu_back() then
PopupWindow.hide()
end
end