Reset phone-game progress on every launch
This commit is contained in:
@@ -4,7 +4,6 @@ const Profile = preload("res://scripts/profile.gd")
|
||||
const Soundscape = preload("res://scripts/phone_soundscape.gd")
|
||||
const PhoneStage = preload("res://scripts/phone_stage.gd")
|
||||
const UI_FONT = preload("res://assets/fonts/Arimo-Bold.tres")
|
||||
const SAVE_PATH := "user://profile/phone_memory.cfg"
|
||||
const BG := Color("0b0a12")
|
||||
const CARD := Color("1c1826")
|
||||
const INK := Color("eee9dd")
|
||||
@@ -17,6 +16,9 @@ var story: Dictionary
|
||||
var facts: Dictionary = {}
|
||||
var endings: Dictionary = {}
|
||||
var completed := 0
|
||||
# Progress lives only for this application run. Scene tests use their own
|
||||
# working dictionaries and cannot contaminate the normal sequence of calls.
|
||||
var session_progress: Dictionary = {"facts": {}, "endings": {}, "loops": 0}
|
||||
var chapter := 1
|
||||
var test_mode := false
|
||||
var qa_mode := false
|
||||
@@ -85,21 +87,22 @@ func _ready() -> void:
|
||||
story = JSON.parse_string(FileAccess.get_file_as_string("res://data/phone_story.json"))
|
||||
voice_levels = JSON.parse_string(FileAccess.get_file_as_string("res://data/voice_levels.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")
|
||||
elif "--phone-session-qa" in OS.get_cmdline_user_args():
|
||||
call_deferred("run_session_qa")
|
||||
|
||||
func run_qa() -> void:
|
||||
var qa = load("res://scripts/phone_qa.gd").new()
|
||||
await qa.run(self)
|
||||
|
||||
func run_session_qa() -> void:
|
||||
var qa = load("res://scripts/phone_session_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
|
||||
@@ -360,8 +363,8 @@ func _unhandled_key_input(event: InputEvent) -> void:
|
||||
show_menu()
|
||||
|
||||
func continuation_chapter() -> int:
|
||||
# Old profiles without the new conversation must hear it, not receive an
|
||||
# invented memory. Existing discoveries and completed-call count stay intact.
|
||||
# A continuation needs the first conversation's setup; the call number
|
||||
# alone must never create knowledge of the letter.
|
||||
if not facts.has("key_letter") and not facts.has("key_custody"): return 1
|
||||
return mini(completed+1,10)
|
||||
|
||||
@@ -420,7 +423,7 @@ func show_settings() -> void:
|
||||
func show_test_menu() -> void:
|
||||
var box := menu_page("testing")
|
||||
box.add_child(stage.centered("Проверка сцен",34,INK))
|
||||
box.add_child(label("Отдельная сессия для тестирования. Основное сохранение не меняется.", 20, MUTED))
|
||||
box.add_child(label("Отдельная проверка. Память основного прохождения не меняется.", 20, MUTED))
|
||||
var choices := OptionButton.new()
|
||||
choices.custom_minimum_size.y = 48
|
||||
for entry in story.chapters:
|
||||
@@ -464,12 +467,11 @@ func dial_call(number: int, testing: bool, knowledge: int = 1, animate_in_qa: bo
|
||||
func begin_call(number: int, testing: bool, knowledge: int = 1, retained_facts: Variant = null) -> void:
|
||||
dial_epoch += 1
|
||||
dialing = false
|
||||
# A test never writes the normal profile, including learned facts.
|
||||
# Restore this run's normal progress; never reload a previous launch's file.
|
||||
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)
|
||||
facts = session_progress.facts.duplicate()
|
||||
endings = session_progress.endings.duplicate()
|
||||
completed = mini(session_progress.loops, 10)
|
||||
test_mode = testing
|
||||
if retained_facts != null: facts = retained_facts.duplicate()
|
||||
if testing and knowledge == 0: facts = {}
|
||||
@@ -713,8 +715,7 @@ func finish_task() -> void:
|
||||
|
||||
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("Не удалось сохранить память на диске.")
|
||||
session_progress = {"facts": facts.duplicate(), "endings": endings.duplicate(), "loops": completed}
|
||||
|
||||
func strike() -> void:
|
||||
if impacted: return
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
extends RefCounted
|
||||
## Run in a fresh process with --phone-session-qa and an isolated APPDATA
|
||||
## containing an old phone_memory.cfg. Unlike --phone-qa, production startup,
|
||||
## normal session snapshots and the animated redial are all enabled here.
|
||||
func run(game: Node) -> void:
|
||||
var qa = load("res://scripts/phone_qa.gd").new()
|
||||
qa.game = game
|
||||
DirAccess.make_dir_recursive_absolute(qa.directory())
|
||||
var old: Dictionary = game.Profile.read_profile("user://profile/phone_memory.cfg",game.story.facts,game.story.endings)
|
||||
qa.check(old.facts.has("lamp") and old.loops == 10,"Regression fixture contains previous-launch discoveries")
|
||||
qa.check(not game.qa_mode,"Exercise production startup rather than the ordinary QA bypass")
|
||||
qa.check(game.facts.is_empty() and game.endings.is_empty() and game.completed == 0,"Every process starts with empty progress despite an old save")
|
||||
qa.check(game.action_button("start").text == "Позвонить маме","Main menu starts the first call")
|
||||
qa.click("start")
|
||||
await game.get_tree().create_timer(2.6).timeout
|
||||
qa.check(game.chapter == 1 and game.facts.is_empty(),"First greeting has no inherited clues")
|
||||
qa.click("memory")
|
||||
qa.check(game.memory_content.get_parsed_text().contains("Мама ещё не рассказала"),"First-call memory shows the empty explanation")
|
||||
qa.click("close_memory")
|
||||
qa.finish("flat")
|
||||
qa.check(game.completed == 1 and game.session_progress.loops == 1,"Completed call stays in this run")
|
||||
qa.click("next")
|
||||
await game.get_tree().create_timer(2.6).timeout
|
||||
qa.check(game.chapter == 2 and game.facts.has("key_letter") and not game.facts.has("lamp"),"Redial retains only the first call's actual discoveries")
|
||||
qa.perform("lamp_search")
|
||||
qa.check(game.facts.has("lamp") and game.session_progress.facts.has("lamp"),"New flashlight discovery is remembered within this run")
|
||||
game.begin_call(3,false)
|
||||
qa.check(game.facts.has("lamp") and game.items.is_empty(),"Normal next call keeps knowledge while resetting physical items")
|
||||
qa.start(10,2)
|
||||
await game.get_tree().create_timer(2.6).timeout
|
||||
qa.check(game.facts.has("code") and not game.session_progress.facts.has("code"),"All-knowledge scene test cannot alter normal memory")
|
||||
game.begin_call(2,false)
|
||||
qa.check(game.facts.has("lamp") and not game.facts.has("code") and game.completed == 1,"Returning from a scene test restores only this run's normal progress")
|
||||
old = game.Profile.read_profile("user://profile/phone_memory.cfg",game.story.facts,game.story.endings)
|
||||
qa.check(old.loops == 10,"The legacy disk file is ignored, not used as session storage")
|
||||
var file := FileAccess.open(qa.directory().path_join("phone-session-result.json"),FileAccess.WRITE)
|
||||
file.store_string(JSON.stringify({"passed":qa.errors.is_empty(),"checks":qa.checks,"errors":qa.errors}," "))
|
||||
file.close()
|
||||
print("PHONE_SESSION_QA ","PASS" if qa.errors.is_empty() else "FAIL"," checks=",qa.checks," errors=",qa.errors)
|
||||
game.soundscape.stop()
|
||||
for player in [game.voice,game.siren,game.effect,game.hum,game.notification_sound]:
|
||||
player.stop()
|
||||
player.stream = null
|
||||
var exit_code := 0 if qa.errors.is_empty() else 1
|
||||
qa.game = null
|
||||
await game.get_tree().create_timer(0.1).timeout
|
||||
game.get_tree().quit(exit_code)
|
||||
Reference in New Issue
Block a user