2026-10-29 22:31:17 +02:00
extends Node3D
## Phone prototype: one physical task at a time; only heard facts persist.
const Profile = preload ( " res://scripts/profile.gd " )
const SAVE_PATH := " user://profile/phone_memory.cfg "
const BG := Color ( " 10171d " )
const CARD := Color ( " 19232c " )
const INK := Color ( " eee9dd " )
const MUTED := Color ( " a2afb9 " )
const ACCENT := Color ( " e3bd7b " )
const RED := Color ( " db8b80 " )
const GREEN := Color ( " 9bc4b0 " )
var story : Dictionary
var facts : Dictionary = { }
var endings : Dictionary = { }
var completed := 0
var chapter := 1
var test_mode := false
var qa_mode := false
var running := false
var impacted := false
var elapsed := 0.0
var start_tick := 0
var place := " flat "
var items : Dictionary = { }
var done : Dictionary = { }
var fired : Dictionary = { }
var events : Array = [ ]
var busy : Dictionary = { }
var busy_start := 0.0
var busy_end := 0.0
var reply_at := 0.0
var replied := false
var outcome := " "
var heard : Array [ String ] = [ ]
var archive : Array = [ ]
var voice_cache : Dictionary = { }
var voice_enabled := true
var master_volume := 0.65
var ui : Control
var overlay : Control
var command_list : VBoxContainer
var transcript : VBoxContainer
var transcript_scroll : ScrollContainer
var journal : RichTextLabel
var clock_label : Label
var status_label : Label
var place_label : Label
var objects_label : Label
var task_label : Label
var title_label : Label
var phase_label : Label
var busy_bar : ProgressBar
var cancel_button : Button
var last_caption : Label
var voice : AudioStreamPlayer
var room : AudioStreamPlayer
var siren : AudioStreamPlayer
var effect : AudioStreamPlayer
var hum : AudioStreamPlayer
2026-10-29 22:36:22 +02:00
var notification_sound : AudioStreamPlayer
var notification_card : PanelContainer
var inbox_button : Button
var notifications : Array = [ ]
var notification_cursor := 0
var unread := 0
var toast_until := 0.0
var viewing_messages := false
2026-10-29 22:31:17 +02:00
var wave_bars : Array [ ColorRect ] = [ ]
var screen_fade : ColorRect
func _ready ( ) - > void :
story = JSON . parse_string ( FileAccess . get_file_as_string ( " res://data/phone_story.json " ) )
qa_mode = " --phone-qa " in OS . get_cmdline_user_args ( )
if not qa_mode :
var saved := Profile . read_profile ( SAVE_PATH , story . facts , story . endings )
facts = saved . facts
endings = saved . endings
completed = mini ( saved . loops , 10 )
make_audio ( )
make_ui ( )
show_menu ( )
if qa_mode :
call_deferred ( " run_qa " )
func run_qa ( ) - > void :
var qa = load ( " res://scripts/phone_qa.gd " ) . new ( )
await qa . run ( self )
func style ( color : Color , border : Color = Color . TRANSPARENT , radius : int = 16 ) - > StyleBoxFlat :
var box := StyleBoxFlat . new ( )
box . bg_color = color
box . border_color = border
box . set_border_width_all ( 1 )
box . set_corner_radius_all ( radius )
box . content_margin_left = 18
box . content_margin_right = 18
box . content_margin_top = 14
box . content_margin_bottom = 14
return box
func label ( text : String , size : int = 20 , color : Color = INK ) - > Label :
var node := Label . new ( )
node . text = text
node . add_theme_font_size_override ( " font_size " , size )
node . add_theme_color_override ( " font_color " , color )
node . autowrap_mode = TextServer . AUTOWRAP_WORD_SMART
return node
func button ( text : String , id : String , callback : Callable ) - > Button :
var node := Button . new ( )
node . text = text
node . set_meta ( " action " , id )
node . custom_minimum_size . y = 48
node . autowrap_mode = TextServer . AUTOWRAP_WORD_SMART
node . add_theme_stylebox_override ( " normal " , style ( Color ( " 25323c " ) , Color ( " 35434e " ) , 10 ) )
node . add_theme_stylebox_override ( " hover " , style ( Color ( " 35434b " ) , ACCENT , 10 ) )
node . add_theme_stylebox_override ( " pressed " , style ( Color ( " 435049 " ) , GREEN , 10 ) )
node . add_theme_stylebox_override ( " disabled " , style ( Color ( " 1b252c " ) , Color ( " 2b353d " ) , 10 ) )
node . add_theme_color_override ( " font_color " , INK )
node . add_theme_color_override ( " font_hover_color " , INK )
node . add_theme_color_override ( " font_disabled_color " , Color ( " 65717b " ) )
node . pressed . connect ( callback )
return node
func column ( parent : Node , width : float = 0 ) - > VBoxContainer :
var box := VBoxContainer . new ( )
box . add_theme_constant_override ( " separation " , 12 )
box . size_flags_vertical = Control . SIZE_EXPAND_FILL
box . custom_minimum_size . x = width
parent . add_child ( box )
return box
func panel ( parent : Node , width : float = 0 ) - > VBoxContainer :
var shell := PanelContainer . new ( )
shell . custom_minimum_size . x = width
shell . size_flags_vertical = Control . SIZE_EXPAND_FILL
shell . add_theme_stylebox_override ( " panel " , style ( CARD ) )
parent . add_child ( shell )
return column ( shell )
func make_ui ( ) - > void :
var layer := CanvasLayer . new ( )
add_child ( layer )
ui = Control . new ( )
ui . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
var theme := Theme . new ( )
theme . default_font_size = 19
ui . theme = theme
layer . add_child ( ui )
var background := ColorRect . new ( )
background . color = BG
background . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
ui . add_child ( background )
var margins := MarginContainer . new ( )
margins . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
for edge in [ " left " , " right " , " top " , " bottom " ] :
margins . add_theme_constant_override ( " margin_ " + edge , 24 )
ui . add_child ( margins )
var root := column ( margins )
var top := HBoxContainer . new ( )
root . add_child ( top )
var brand := label ( " ДО ОТБОЯ / НЕ КЛАДИ ТРУБКУ " , 22 , ACCENT )
brand . size_flags_horizontal = Control . SIZE_EXPAND_FILL
top . add_child ( brand )
2026-10-29 22:36:22 +02:00
inbox_button = button ( " Сообщения " , " messages " , show_messages )
inbox_button . custom_minimum_size . x = 185
inbox_button . size_flags_vertical = Control . SIZE_SHRINK_CENTER
top . add_child ( inbox_button )
2026-10-29 22:31:17 +02:00
var menu_button := button ( " Меню " , " menu " , func ( ) : show_menu ( ) )
menu_button . custom_minimum_size . x = 120
menu_button . size_flags_vertical = Control . SIZE_SHRINK_CENTER
top . add_child ( menu_button )
var body := HBoxContainer . new ( )
body . add_theme_constant_override ( " separation " , 18 )
body . size_flags_vertical = Control . SIZE_EXPAND_FILL
root . add_child ( body )
var left := panel ( body , 268 )
left . add_child ( label ( " ИСХОДЯЩИЙ ЗВОНОК " , 15 , MUTED ) )
left . add_child ( label ( " Мама " , 44 ) )
status_label = label ( " Нет соединения " , 18 , GREEN )
left . add_child ( status_label )
clock_label = label ( " " , 32 , ACCENT )
left . add_child ( clock_label )
var waveform := HBoxContainer . new ( )
waveform . alignment = BoxContainer . ALIGNMENT_CENTER
waveform . custom_minimum_size . y = 52
waveform . add_theme_constant_override ( " separation " , 4 )
left . add_child ( waveform )
for i in range ( 25 ) :
var bar := ColorRect . new ( )
bar . color = GREEN
bar . custom_minimum_size = Vector2 ( 4 , 5 )
bar . size_flags_vertical = Control . SIZE_SHRINK_CENTER
waveform . add_child ( bar )
wave_bars . append ( bar )
place_label = label ( " Квартира · вечер " , 18 )
left . add_child ( place_label )
objects_label = label ( " " , 16 , MUTED )
left . add_child ( objects_label )
left . add_child ( HSeparator . new ( ) )
left . add_child ( label ( " ТЫ ПОМНИШЬ " , 15 , ACCENT ) )
journal = RichTextLabel . new ( )
journal . size_flags_vertical = Control . SIZE_EXPAND_FILL
journal . bbcode_enabled = false
journal . add_theme_font_size_override ( " normal_font_size " , 17 )
journal . add_theme_color_override ( " default_color " , MUTED )
left . add_child ( journal )
left . add_child ( label ( " Вещи остаются у мамы. \n Между звонками — только память. " , 15 , MUTED ) )
var middle := column ( body )
middle . size_flags_horizontal = Control . SIZE_EXPAND_FILL
title_label = label ( " Обычный вечер " , 34 )
middle . add_child ( title_label )
phase_label = label ( " " , 17 , MUTED )
middle . add_child ( phase_label )
transcript_scroll = ScrollContainer . new ( )
transcript_scroll . size_flags_vertical = Control . SIZE_EXPAND_FILL
transcript_scroll . horizontal_scroll_mode = ScrollContainer . SCROLL_MODE_DISABLED
middle . add_child ( transcript_scroll )
transcript = column ( transcript_scroll )
transcript . size_flags_horizontal = Control . SIZE_EXPAND_FILL
last_caption = label ( " Ты узнаёшь происходящее только по её словам. " , 17 , MUTED )
middle . add_child ( last_caption )
var right := panel ( body , 390 )
right . add_child ( label ( " СКАЗАТЬ МАМЕ " , 15 , ACCENT ) )
task_label = label ( " Одно действие за раз " , 21 )
right . add_child ( task_label )
busy_bar = ProgressBar . new ( )
busy_bar . custom_minimum_size . y = 5
busy_bar . show_percentage = false
right . add_child ( busy_bar )
cancel_button = button ( " Перебить и изменить просьбу " , " cancel " , cancel_task )
right . add_child ( cancel_button )
var command_scroll := ScrollContainer . new ( )
command_scroll . size_flags_vertical = Control . SIZE_EXPAND_FILL
command_scroll . horizontal_scroll_mode = ScrollContainer . SCROLL_MODE_DISABLED
right . add_child ( command_scroll )
command_list = column ( command_scroll )
command_list . size_flags_horizontal = Control . SIZE_EXPAND_FILL
right . add_child ( label ( " Она слышит твой голос. \n Ты не управляешь её руками. " , 15 , MUTED ) )
screen_fade = ColorRect . new ( )
screen_fade . color = Color ( 0 , 0 , 0 , 0 )
screen_fade . mouse_filter = Control . MOUSE_FILTER_IGNORE
screen_fade . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
ui . add_child ( screen_fade )
2026-10-29 22:36:22 +02:00
notification_card = PanelContainer . new ( )
notification_card . set_anchors_and_offsets_preset ( Control . PRESET_TOP_RIGHT )
notification_card . offset_left = - 500
notification_card . offset_right = - 24
notification_card . offset_top = 82
notification_card . add_theme_stylebox_override ( " panel " , style ( Color ( " 35434a " ) , ACCENT , 16 ) )
notification_card . z_index = 100
notification_card . visible = false
ui . add_child ( notification_card )
2026-10-29 22:31:17 +02:00
refresh ( )
func clear_children ( parent : Node ) - > void :
for child in parent . get_children ( ) :
parent . remove_child ( child )
child . queue_free ( )
func close_overlay ( ) - > void :
2026-10-29 22:36:22 +02:00
viewing_messages = false
2026-10-29 22:31:17 +02:00
if is_instance_valid ( overlay ) :
ui . remove_child ( overlay )
overlay . queue_free ( )
overlay = null
2026-10-29 22:36:22 +02:00
func show_messages ( ) - > void :
var box := modal ( )
viewing_messages = true
unread = 0
refresh_inbox_button ( )
notification_card . visible = false
box . add_child ( label ( str ( story . friend ) + " · подруга " , 34 ) )
box . add_child ( label ( " Звонок с мамой продолжается. Время идёт. " if running else " Сообщения за последний звонок " , 18 , ACCENT ) )
var scroll := ScrollContainer . new ( )
scroll . custom_minimum_size = Vector2 ( 780 , 430 )
scroll . horizontal_scroll_mode = ScrollContainer . SCROLL_MODE_DISABLED
box . add_child ( scroll )
var messages := column ( scroll )
messages . size_flags_horizontal = Control . SIZE_EXPAND_FILL
if notifications . is_empty ( ) :
messages . add_child ( label ( " Пока нет новых сообщений. " , 22 , MUTED ) )
for entry in notifications :
var card := PanelContainer . new ( )
card . add_theme_stylebox_override ( " panel " , style ( Color ( " 26343c " ) ) )
messages . add_child ( card )
var content := column ( card )
content . add_child ( label ( " Аня · %02d : %02d " % [ int ( entry . at ) / 60 , int ( entry . at ) % 60 ] , 16 , ACCENT ) )
content . add_child ( label ( entry . text , 23 ) )
box . add_child ( button ( " Вернуться к маме " if running else " Назад " , " close_messages " , func ( ) :
close_overlay ( )
if impacted : show_ending ( ) ) )
scroll_inbox_to_latest . call_deferred ( scroll )
func scroll_inbox_to_latest ( scroll : ScrollContainer ) - > void :
await get_tree ( ) . process_frame
if is_instance_valid ( scroll ) :
scroll . scroll_vertical = int ( scroll . get_v_scroll_bar ( ) . max_value )
func refresh_inbox_button ( ) - > void :
inbox_button . text = " Сообщения " + ( " · %d " % unread if unread > 0 else " " )
func update_notifications ( second : float ) - > void :
if not running and not impacted : return
while notification_cursor < story . notifications . size ( ) :
var entry : Dictionary = story . notifications [ notification_cursor ]
if second < float ( entry . at ) : break
notifications . append ( entry . duplicate ( ) )
notification_cursor + = 1
unread + = 1
notification_sound . play ( )
refresh_inbox_button ( )
if viewing_messages :
show_messages ( )
else :
show_notification ( entry , second )
if notification_card . visible and second > = toast_until :
notification_card . visible = false
func show_notification ( entry : Dictionary , second : float ) - > void :
clear_children ( notification_card )
var content := column ( notification_card )
var heading := HBoxContainer . new ( )
content . add_child ( heading )
var sender := label ( str ( story . friend ) + " · СООБЩЕНИЕ " , 16 , ACCENT )
sender . size_flags_horizontal = Control . SIZE_EXPAND_FILL
heading . add_child ( sender )
var dismiss := button ( " × " , " dismiss_push " , func ( ) : notification_card . visible = false )
dismiss . autowrap_mode = TextServer . AUTOWRAP_OFF
dismiss . custom_minimum_size = Vector2 ( 52 , 36 )
heading . add_child ( dismiss )
var message := button ( entry . text , " open_push " , show_messages )
message . custom_minimum_size . y = 76
content . add_child ( message )
content . add_child ( label ( " Открыть переписку · время звонка идёт " if running else " Открыть переписку " , 14 , MUTED ) )
notification_card . visible = true
notification_card . size = Vector2 ( 476 , 0 )
fit_notification . call_deferred ( )
toast_until = second + ( 12.0 if notification_cursor == 5 else 7.0 )
func fit_notification ( ) - > void :
notification_card . size = Vector2 ( 476 , notification_card . get_combined_minimum_size ( ) . y )
2026-10-29 22:31:17 +02:00
func modal ( ) - > VBoxContainer :
close_overlay ( )
var shade := PanelContainer . new ( )
shade . set_anchors_and_offsets_preset ( Control . PRESET_FULL_RECT )
shade . add_theme_stylebox_override ( " panel " , style ( Color ( " 10171d " ) , Color . TRANSPARENT , 0 ) )
ui . add_child ( shade )
overlay = shade
var center := CenterContainer . new ( )
shade . add_child ( center )
var shell := PanelContainer . new ( )
shell . custom_minimum_size . x = 860
shell . add_theme_stylebox_override ( " panel " , style ( CARD , Color ( " 35434e " ) , 22 ) )
center . add_child ( shell )
return column ( shell )
func show_menu ( ) - > void :
var box := modal ( )
box . add_child ( label ( " ДО ОТБОЯ " , 17 , ACCENT ) )
box . add_child ( label ( " Не клади трубку " , 48 ) )
box . add_child ( label ( " Девяносто секунд рядом с мамой. \n Десять звонков. Только голос, память и то, что удалось услышать. " , 22 ) )
box . add_child ( label ( " Ты — Катя. Мама — Нина. Ты далеко от её квартиры. \n В первом звонке вы просто разговариваете. Потом всё повторится. " , 19 , MUTED ) )
if running :
box . add_child ( label ( " Звонок продолжается, пока открыто меню. " , 18 , RED ) )
box . add_child ( button ( " Вернуться к звонку " , " resume " , close_overlay ) )
else :
box . add_child ( button ( " Позвонить маме " if completed == 0 else " Продолжить · звонок %d " % mini ( completed + 1 , 10 ) , " start " , func ( ) : begin_call ( mini ( completed + 1 , 10 ) , false ) ) )
box . add_child ( button ( " Проверка сцен · выбрать любой из 10 звонков " , " testing " , show_test_menu ) )
box . add_child ( button ( " Звук и титры " , " settings " , show_settings ) )
box . add_child ( label ( " 0.2 · 102 реплики · черновая русская озвучка Windows Speech \n Прогресс сохраняется после находок и законченных звонков. " , 16 , MUTED ) )
func show_settings ( ) - > void :
var box := modal ( )
box . add_child ( label ( " Звук и титры " , 34 ) )
var enabled := CheckButton . new ( )
enabled . text = " Озвучка реплик "
enabled . button_pressed = voice_enabled
enabled . toggled . connect ( func ( value ) :
voice_enabled = value
if not value : voice . stop ( ) )
box . add_child ( enabled )
box . add_child ( label ( " Общая громкость " , 20 ) )
var slider := HSlider . new ( )
slider . min_value = 0
slider . max_value = 1
slider . step = 0.05
slider . value = master_volume
slider . value_changed . connect ( func ( value ) :
master_volume = value
AudioServer . set_bus_volume_db ( 0 , linear_to_db ( maxf ( 0.0001 , value ) ) ) )
box . add_child ( slider )
box . add_child ( label ( " Все фразы доступны в субтитрах. \n Голоса: Microsoft Irina, временный локальный синтез. \n ElevenLabs отклонил генерацию: Free Tier подключённого аккаунта отключён. \n Взрыв: Synthesized explosion — qubodup / Iwan Gabovitch, CC0. \n Остальные звуки: оригинальный процедурный синтез проекта. \n Полные источники — AUDIO_CREDITS.md рядом с игрой. " , 20 , MUTED ) )
box . add_child ( button ( " Назад " , " back_menu " , show_menu ) )
func show_test_menu ( ) - > void :
var box := modal ( )
box . add_child ( label ( " Проверка сцен " , 34 ) )
box . add_child ( label ( " Отдельная сессия для тестирования. Основное сохранение не меняется. " , 20 , MUTED ) )
var choices := OptionButton . new ( )
choices . custom_minimum_size . y = 48
for entry in story . chapters :
choices . add_item ( " %02d · %s " % [ entry . number , entry . title ] )
choices . set_meta ( " test_chapter " , true )
box . add_child ( choices )
var knowledge := OptionButton . new ( )
knowledge . custom_minimum_size . y = 48
knowledge . add_item ( " Начать без знаний " )
knowledge . add_item ( " Использовать мою память " )
knowledge . add_item ( " Все знания для проверки маршрутов " )
knowledge . set_meta ( " test_knowledge " , true )
box . add_child ( knowledge )
box . add_child ( button ( " Начать проверку " , " test_start " , func ( ) :
begin_call ( choices . selected + 1 , true , knowledge . selected ) ) )
box . add_child ( button ( " Назад " , " back_menu " , show_menu ) )
func begin_call ( number : int , testing : bool , knowledge : int = 1 ) - > void :
# A test never writes the normal profile, including learned facts.
if not qa_mode :
var saved := Profile . read_profile ( SAVE_PATH , story . facts , story . endings )
facts = saved . facts
endings = saved . endings
completed = mini ( saved . loops , 10 )
test_mode = testing
if testing and knowledge == 0 : facts = { }
if testing and knowledge == 2 :
facts = { }
for key in story . facts : facts [ key ] = true
chapter = clampi ( number , 1 , 10 )
close_overlay ( )
voice . stop ( )
effect . stop ( )
hum . stop ( )
2026-10-29 22:36:22 +02:00
notification_sound . stop ( )
notification_card . visible = false
notifications . clear ( )
notification_cursor = 0
unread = 0
refresh_inbox_button ( )
2026-10-29 22:31:17 +02:00
siren . stop ( )
room . play ( )
room . volume_db = - 28
screen_fade . color . a = 0
elapsed = 0
place = " flat "
items = { }
done = { }
fired = { }
busy = { }
heard . clear ( )
archive . clear ( )
outcome = " "
impacted = false
running = true
clear_children ( transcript )
start_tick = Time . get_ticks_msec ( )
events = [ ]
if chapter == 1 :
for beat in story . intro : events . append ( beat . duplicate ( ) )
else :
var entry : Dictionary = story . chapters [ chapter - 1 ]
var opening_at := voice_length ( " greeting " ) + 0.2
events . append ( { " at " : opening_at , " line " : entry . opening } )
events . append ( { " at " : opening_at + 0.3 + voice_length ( entry . opening ) , " line " : entry . reply } )
say ( " greeting " )
refresh ( )
func _process ( _delta : float ) - > void :
2026-10-29 22:36:22 +02:00
if not running and not impacted : return
var second := maxf ( 0 , ( Time . get_ticks_msec ( ) - start_tick ) / 1000.0 )
if running :
elapsed = second
advance ( )
update_notifications ( second )
2026-10-29 22:31:17 +02:00
func advance ( ) - > void :
if not running : return
# Resolve scheduled events chronologically, even if a frame spans several
# boundaries. An action completed at 44 s still counts after a 46 s frame;
# a laptop action completing at 46 s is cancelled by the 45 s power cut.
var target := elapsed
var alarm_at := 43.0 if chapter == 1 else 24.0
while running :
var next_time := 90.0
var kind := " impact "
for entry in [ { " at " : alarm_at , " id " : " alarm " } , { " at " : 45.0 , " id " : " power " } , { " at " : 85.0 , " id " : " hum " } ] :
if not fired . has ( entry . id ) and float ( entry . at ) < next_time :
next_time = entry . at
kind = entry . id
if not events . is_empty ( ) and float ( events [ 0 ] . at ) < next_time :
next_time = events [ 0 ] . at
kind = " dialogue "
if not busy . is_empty ( ) :
if not replied and reply_at < next_time :
next_time = reply_at
kind = " reply "
if busy_end < next_time :
next_time = busy_end
kind = " finish "
if next_time > target : break
elapsed = next_time
match kind :
" impact " :
strike ( )
return
" alarm " :
fired . alarm = true
siren . play ( )
if chapter != 1 : system_caption ( " На мамином конце слышна сирена. " )
" power " :
fired . power = true
system_caption ( " Щелчок. Гул холодильника исчезает. " )
room . volume_db = - 35
if not busy . is_empty ( ) and busy . get ( " power " , false ) :
busy = { }
say ( " late_mail " )
elif chapter != 1 : say ( " power " )
refresh_commands ( )
" hum " :
fired . hum = true
hum . play ( )
say ( " hum " )
" dialogue " :
var event : Dictionary = events . pop_front ( )
if busy . is_empty ( ) and not fired . has ( " hum " ) : say ( event . line )
" reply " :
replied = true
say ( busy . response )
" finish " : finish_task ( )
elapsed = target
refresh_live ( )
func command_allowed ( action : Dictionary ) - > bool :
if not running or chapter == 1 or elapsed > = 90 or not busy . is_empty ( ) : return false
if action . get ( " once " , false ) and done . has ( action . id ) : return false
if action . has ( " places " ) and place not in action . places : return false
if action . get ( " power " , false ) and elapsed > = 45 : return false
for key in action . get ( " facts " , [ ] ) :
if not facts . has ( key ) : return false
for key in action . get ( " unknown " , [ ] ) :
if facts . has ( key ) : return false
for key in action . get ( " items " , [ ] ) :
if not items . has ( key ) : return false
for key in action . get ( " missing " , [ ] ) :
if items . has ( key ) : return false
return true
func action_duration ( action : Dictionary ) - > float :
var length := maxf ( float ( action . seconds ) , voice_length ( action . request ) + voice_length ( action . response ) + 0.35 )
if action . get ( " needs_light " , false ) and elapsed > = 45 and not items . has ( " lamp " ) :
length + = 7
return length
func choose_action ( id : String ) - > void :
# Re-check state, time, and the visible control when a queued click arrives.
if running : elapsed = ( Time . get_ticks_msec ( ) - start_tick ) / 1000.0
if is_instance_valid ( overlay ) : return
var control := action_button ( id )
if control == null or control . disabled : return
var selected : Dictionary = { }
for action in story . actions :
if action . id == id : selected = action
if id == " question " :
var entry : Dictionary = story . chapters [ chapter - 1 ]
selected = { " id " : " question " , " label " : " Спросить маму " , " seconds " : 8 , " request " : entry . question , " response " : entry . answer , " once " : true }
if selected . is_empty ( ) or not command_allowed ( selected ) : return
events . clear ( )
busy = selected . duplicate ( true )
busy_start = elapsed
busy_end = elapsed + action_duration ( selected )
reply_at = maxf ( elapsed + voice_length ( selected . request ) + 0.15 , busy_end - voice_length ( selected . response ) )
replied = false
say ( selected . request )
if selected . get ( " needs_light " , false ) and elapsed > = 45 and not items . has ( " lamp " ) :
system_caption ( " Без фонаря мама будет искать на ощупь. Это займёт дольше. " )
refresh_commands ( )
func finish_task ( ) - > void :
var action := busy . duplicate ( true )
busy = { }
done [ action . id ] = true
for key in action . get ( " learn " , [ ] ) :
if not facts . has ( key ) :
facts [ key ] = true
system_caption ( " Ты запомнила: " + str ( story . facts [ key ] ) )
for key in action . get ( " give " , [ ] ) : items [ key ] = true
if action . has ( " move " ) :
place = action . move
if place == " alcove " and not items . has ( " connected " ) :
system_caption ( " Голос рассыпается. Связь здесь слабее. " )
save_progress ( )
refresh ( )
func cancel_task ( ) - > void :
if not running or busy . is_empty ( ) : return
busy = { }
voice . stop ( )
say ( " cancel " )
system_caption ( " Мама остановилась. Потраченное время не вернуть. " )
refresh_commands ( )
func save_progress ( ) - > void :
if qa_mode or test_mode : return
var result := Profile . write_profile ( SAVE_PATH , facts , endings , completed )
if result != OK : system_caption ( " Не удалось сохранить память на диске. " )
func strike ( ) - > void :
if impacted : return
impacted = true
running = false
busy = { }
events . clear ( )
voice . stop ( )
room . stop ( )
siren . stop ( )
hum . stop ( )
effect . stream = load ( " res://assets/audio/impact_cc0.wav " )
effect . play ( )
outcome = " connected " if place == " alcove " and items . has ( " connected " ) else place
endings [ outcome ] = true
if not test_mode :
completed = maxi ( completed , chapter )
save_progress ( )
screen_fade . color = Color ( 0 , 0 , 0 , 0.94 )
status_label . text = " Соединение прервано "
refresh_commands ( )
2026-10-29 22:36:22 +02:00
if viewing_messages : show_messages ( )
2026-10-29 22:31:17 +02:00
if qa_mode : return
var epoch := start_tick
await get_tree ( ) . create_timer ( 2.0 ) . timeout
if epoch != start_tick or not impacted : return
screen_fade . color . a = 0.15
if outcome == " connected " :
say ( " after_alive " )
await get_tree ( ) . create_timer ( voice_length ( " after_alive " ) + 1.0 ) . timeout
else :
say ( " after_call " )
await get_tree ( ) . create_timer ( voice_length ( " after_call " ) + 0.8 ) . timeout
2026-10-29 22:36:22 +02:00
if epoch == start_tick and impacted and not viewing_messages : show_ending ( )
2026-10-29 22:31:17 +02:00
func show_ending ( ) - > void :
var entry : Dictionary = story . endings [ outcome ]
var box := modal ( )
box . add_child ( label ( " ЗВОНОК ОБОРВАН · 01:30 " , 17 , RED ) )
box . add_child ( label ( entry . title , 42 ) )
box . add_child ( label ( entry . text , 23 ) )
box . add_child ( label ( " Знаний: %d / %d · Звонок: %d / 10 " % [ facts . size ( ) , story . facts . size ( ) , chapter ] , 18 , MUTED ) )
if chapter == 10 :
box . add_child ( label ( " Ты могла выбирать слова и действия. \n Ты не могла остановить то, что происходило с домом. " , 22 , ACCENT ) )
box . add_child ( button ( " Перезвонить · следующая итерация " if chapter < 10 else " Ещё один звонок " , " next " , func ( ) : continue_call ( ) ) )
box . add_child ( button ( " Повторить этот звонок " , " retry " , func ( ) : continue_call ( true ) ) )
box . add_child ( button ( " Прочитать разговор " , " transcript " , show_transcript ) )
2026-10-29 22:36:22 +02:00
box . add_child ( button ( " Сообщения от подруги " , " ending_messages " , show_messages ) )
2026-10-29 22:31:17 +02:00
box . add_child ( button ( " В меню" , " end_menu " , show_menu ) )
func continue_call ( retry : bool = false ) - > void :
# Test discoveries persist across test redials but never reach the disk save.
var remembered := facts . duplicate ( )
var number := chapter if retry else mini ( chapter + 1 , 10 )
var was_test := test_mode
begin_call ( number , was_test )
if was_test :
facts = remembered
refresh ( )
func show_transcript ( ) - > void :
var box := modal ( )
box . add_child ( label ( " Последний разговор " , 32 ) )
var text := RichTextLabel . new ( )
text . custom_minimum_size = Vector2 ( 780 , 470 )
text . add_theme_font_size_override ( " normal_font_size " , 21 )
for entry in archive :
text . append_text ( " %02d : %02d %s \n %s \n \n " % [ int ( entry . at ) / 60 , int ( entry . at ) % 60 , entry . speaker , entry . text ] )
box . add_child ( text )
box . add_child ( button ( " Назад " , " back_ending " , show_ending ) )
func refresh ( ) - > void :
if not is_instance_valid ( journal ) : return
var entry : Dictionary = story . chapters [ chapter - 1 ]
title_label . text = entry . title
phase_label . text = ( " ПРОВЕРКА · " if test_mode else " " ) + " Звонок %02d / 10 · %s " % [ chapter , entry . note ]
journal . text = " Пока только её голос. " if facts . is_empty ( ) else " "
for key in story . facts :
if facts . has ( key ) : journal . append_text ( str ( story . facts [ key ] ) + " \n \n " )
refresh_commands ( )
refresh_live ( )
func refresh_commands ( ) - > void :
if not is_instance_valid ( command_list ) : return
clear_children ( command_list )
cancel_button . visible = running and not busy . is_empty ( )
if not running :
command_list . add_child ( label ( " Линия молчит. " , 22 , MUTED ) )
return
if chapter == 1 :
command_list . add_child ( label ( " Вы просто разговариваете. " , 25 ) )
command_list . add_child ( label ( " Вечер. Знакомый голос. Кажется, на всё ещё есть время. " , 20 , MUTED ) )
return
if not busy . is_empty ( ) :
command_list . add_child ( label ( " Мама выполняет твою просьбу. Можно дождаться ответа или перебить её. " , 22 , MUTED ) )
return
var entry : Dictionary = story . chapters [ chapter - 1 ]
if not done . has ( " question " ) :
command_list . add_child ( button ( " « " + str ( story . lines [ entry . question ] . text ) + " » " , " question " , func ( ) : choose_action ( " question " ) ) )
for action in story . actions :
if command_allowed ( action ) :
var id : String = action . id
var b := button ( str ( action . label ) + " · ~ %d с " % ceili ( action_duration ( action ) ) , id , func ( ) : choose_action ( id ) )
command_list . add_child ( b )
if place == " flat " and not items . has ( " keys " ) :
command_list . add_child ( label ( " Чтобы открыть входную дверь, мама ищет ключи. " , 16 , MUTED ) )
func refresh_live ( ) - > void :
clock_label . text = " Разговор " if chapter == 1 else " %02d : %02d " % [ mini ( int ( elapsed ) , 90 ) / 60 , mini ( int ( elapsed ) , 90 ) % 60 ]
status_label . text = " Плохая связь " if place == " alcove " and not items . has ( " connected " ) else " На линии "
if not running : status_label . text = " Соединение прервано "
var names := { " flat " : " В квартире" , " inner " : " Внутренний коридор " , " landing " : " Лестничная площадка " , " alcove " : " Боковой тамбур " }
place_label . text = names [ place ] + ( " · темно " if elapsed > = 45 else " " )
var held : Array [ String ] = [ ]
for key in items :
held . append ( { " keys " : " ключи " , " lamp " : " фонарь " , " spare " : " запасной ключ " , " connected " : " телефон на полке " } [ key ] )
objects_label . text = " У мамы: " + ( " , " . join ( held ) if not held . is_empty ( ) else " телефон " )
task_label . text = str ( busy . label ) if not busy . is_empty ( ) else " Она слушает тебя "
busy_bar . visible = not busy . is_empty ( )
if not busy . is_empty ( ) : busy_bar . value = clampf ( ( elapsed - busy_start ) / ( busy_end - busy_start ) * 100 , 0 , 100 )
for i in range ( wave_bars . size ( ) ) :
var bar := wave_bars [ i ]
bar . custom_minimum_size . y = 5 + ( absf ( sin ( elapsed * 8.0 + i * 1.8 ) ) * 30 if voice . playing else absf ( sin ( elapsed + i ) ) * 3 )
bar . color = ACCENT if elapsed > = 85 else GREEN
func action_button ( id : String , node : Node = null ) - > Button :
if node == null : node = ui
if node is Button and node . is_visible_in_tree ( ) and node . get_meta ( " action " , " " ) == id :
return node
for child in node . get_children ( ) :
var found := action_button ( id , child )
if found != null : return found
return null
func voice_stream ( id : String ) - > AudioStream :
if not voice_cache . has ( id ) :
var path := " res://assets/voice/ %s .wav " % id
if ResourceLoader . exists ( path ) : voice_cache [ id ] = load ( path )
else : return null
return voice_cache [ id ]
func voice_length ( id : String ) - > float :
var stream := voice_stream ( id )
return stream . get_length ( ) if stream != null else maxf ( 2.0 , str ( story . lines [ id ] . text ) . length ( ) / 13.0 )
func say ( id : String ) - > void :
var entry : Dictionary = story . lines [ id ]
heard . append ( id )
add_caption ( entry . speaker , entry . text )
voice . stop ( )
if voice_enabled :
voice . bus = " Phone " if entry . speaker == " Мама " else " Master "
voice . stream = voice_stream ( id )
if voice . stream != null : voice . play ( )
func system_caption ( text : String ) - > void :
add_caption ( " " , text )
func add_caption ( speaker : String , text : String ) - > void :
archive . append ( { " at " : elapsed , " speaker " : speaker , " text " : text } )
var card := PanelContainer . new ( )
card . add_theme_stylebox_override ( " panel " , style ( Color ( " 222d36 " ) if speaker == " Мама " else Color ( " 16211f " ) , Color . TRANSPARENT , 12 ) )
transcript . add_child ( card )
var content := column ( card )
if not speaker . is_empty ( ) : content . add_child ( label ( speaker . to_upper ( ) + " · %02d : %02d " % [ int ( elapsed ) / 60 , int ( elapsed ) % 60 ] , 14 , ACCENT if speaker == " Мама " else GREEN ) )
content . add_child ( label ( text , 21 if not speaker . is_empty ( ) else 16 , INK if not speaker . is_empty ( ) else MUTED ) )
last_caption . text = " Слышен мамин голос " if speaker == " Мама " else " "
# Layout happens after this frame; scroll only once its size has updated.
call_deferred ( " scroll_to_latest " )
func scroll_to_latest ( ) - > void :
await get_tree ( ) . process_frame
transcript_scroll . scroll_vertical = int ( transcript_scroll . get_v_scroll_bar ( ) . max_value )
func make_audio ( ) - > void :
voice = AudioStreamPlayer . new ( )
room = AudioStreamPlayer . new ( )
siren = AudioStreamPlayer . new ( )
effect = AudioStreamPlayer . new ( )
hum = AudioStreamPlayer . new ( )
2026-10-29 22:36:22 +02:00
notification_sound = AudioStreamPlayer . new ( )
for player in [ voice , room , siren , effect , hum , notification_sound ] : add_child ( player )
2026-10-29 22:31:17 +02:00
AudioServer . add_bus ( )
var bus := AudioServer . bus_count - 1
AudioServer . set_bus_name ( bus , " Phone " )
var high := AudioEffectHighPassFilter . new ( )
high . cutoff_hz = 220
var low := AudioEffectLowPassFilter . new ( )
low . cutoff_hz = 3600
AudioServer . add_bus_effect ( bus , high )
AudioServer . add_bus_effect ( bus , low )
voice . volume_db = - 2
room . stream = load ( " res://assets/audio/room.wav " )
room . volume_db = - 28
room . finished . connect ( func ( ) :
if running : room . play ( ) )
siren . stream = load ( " res://assets/audio/siren.wav " )
siren . volume_db = - 23
siren . finished . connect ( func ( ) :
if running and fired . has ( " alarm " ) : siren . play ( ) )
effect . volume_db = - 12
hum . stream = load ( " res://assets/audio/approach.wav " )
hum . volume_db = - 25
2026-10-29 22:36:22 +02:00
notification_sound . stream = load ( " res://assets/audio/click.wav " )
notification_sound . volume_db = - 16
2026-10-29 22:31:17 +02:00
AudioServer . set_bus_volume_db ( 0 , linear_to_db ( master_volume ) )