Files
Diabolo/Demon_v0.19/tests.gd
T

462 lines
21 KiB
GDScript

extends RefCounted
func check(condition):
if not condition:
push_error('QA check failed: '+str(get_stack()))
Engine.get_main_loop().quit(1)
func advance(g,seconds: float):
for i in range(ceili(seconds*60)):
g.advance_spawns(1.0/60.0)
func prepare_work(g):
advance(g,3.0)
check(g.souls.size()==1 and not g.souls[0].entering)
var id=g.souls[0].id
g.player.position=g.souls[0].node.position
g.grab(id)
check(g.held==id)
g.souls[0].node.position=g.STATION
g.player.position=g.STATION+Vector3(0,0,1)
g.release_soul()
check(g.working==id and g.held==-1)
check(g.development.placement_clock>0)
g.development.advance_placement(.81)
check(g.development.placement_clock==0 and g.souls[0].node.position.is_equal_approx(g.STATION))
func run(g):
check(g.paused and not g.game_started and not g.hud.visible)
check(g.menu.current_page=="main" and g.souls.is_empty())
check(g.avatar.get_meta("approved_model")=="infernal_v01")
check(g.avatar.clips.size()==3)
var skeleton=g.avatar.find_children("*","Skeleton3D",true,false)[0]
check(skeleton.get_bone_count()==166)
g.avatar.set_walking(true);g.avatar.animator.speed_scale=1;g.avatar.animator.advance(.3)
check(g.avatar.animator.current_animation==g.avatar.clips["Walk"])
g.avatar.strike(.45);g.avatar.animator.advance(.10)
check(g.avatar.striking and g.avatar.animator.current_animation==g.avatar.clips["Whip"])
g.avatar._process(0);check(is_zero_approx(g.avatar.animator.speed_scale))
g.avatar.striking=false;g.avatar.set_walking(false);g.avatar.refresh()
check(g.get_meta("lava_channels")==6)
check(g.stage_effects.bokeh.material_override.shader==preload("res://focus_bokeh.gdshader"))
print("PASS: approved 166-bone succubus, Idle/Walk/Whip clips, hit playback, pause; six framed lava channels")
check(g.menu.main_start.text=="Новая игра")
check(g.menu.main_settings.text=="Настройки")
check(g.menu.main_exit.text=="Выйти")
check(g.menu.main_exit.pressed.get_connections().size()==1)
check(g.coins==0 and g.done==0 and g.speed_level==0 and g.power_level==0 and not g.automatic)
g.menu.main_settings.pressed.emit()
check(g.menu.current_page=="settings")
g.menu.volume_slider.value=25
check(is_equal_approx(g.whip_volume,0.25))
check(is_equal_approx(g.audio_player.volume_db,-3.0+linear_to_db(0.25)))
check(is_zero_approx(AudioServer.get_bus_volume_db(0)))
g.menu.mute_check.button_pressed=true
check(g.muted and AudioServer.is_bus_mute(0))
g.menu.mute_check.button_pressed=false
g.menu.volume_slider.value=75
g.menu.vsync_check.button_pressed=false
check(not g.vsync)
g.menu.vsync_check.button_pressed=true
check(g.vsync)
g.menu.settings_back.pressed.emit()
check(g.menu.current_page=="main" and not g.game_started)
print("PASS: main-menu buttons, settings, volume/mute, VSync, return")
var clips=[]
for path in DirAccess.get_files_at("res://audio"):
if path.get_extension() in ["mp3","wav","ogg"]: clips.append(path)
clips.sort()
check(clips==["burn_female.ogg","burn_male.ogg","cemetery_ambience_loop.ogg","whip.mp3"])
check(g.audio_player.stream.resource_path=="res://audio/whip.mp3")
check(g.audio_player.stream.get_length()>0.3)
check(not g.audio_player.stream.loop)
check(g.audio_player.pitch_scale==1.0)
check(g.ambience_player.stream.loop)
check(g.ambience_player.stream.get_length()>230 and g.ambience_player.stream.get_length()<245)
print("PASS: whip, ambience and male/female groans; loop enabled; whip pitch unchanged")
var codec=preload("res://progression.gd")
var saved={"build_id":"test-build-A","coins":123,"done":8,"speed":2,"power":1,"auto":true,"development":{"tier":2,"selected":1,"xp":140,"points":1,"action":1}}
var path="res://qa/progress-test.json"
DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path("res://qa"))
check(codec.write_save(path,saved)==OK)
check(codec.read_save(path,"test-build-A")==saved)
check(codec.read_save(path,"test-build-B")==codec.defaults("test-build-B"))
check(codec.decode({"coins":999,"done":99},"new")==codec.defaults("new"))
check(codec.decode(null,"new")==codec.defaults("new"))
check(codec.decode({"build_id":"new","speed":999,"power":-5,"coins":"bad"},"new").speed==3)
print("PASS: same-build disk save restored; different-build/legacy/corrupt save reset")
g.menu.main_start.pressed.emit()
check(g.game_started and not g.paused and g.hud.visible and not g.menu.visible)
check(g.souls.size()==1 and g.souls[0].node.position==g.GATE_SPAWN)
check(g.get_meta("endless_room_count")==363)
check(g.life.imps.size()==4 and g.life.neighbours.size()==24)
for imp in g.life.imps+g.life.neighbours:check(imp.model.get_meta("species")=="imp")
var previous=g.life.neighbours[0].root.position
g.time+=1;g.life.update(.1)
check(g.life.neighbours[0].root.position.distance_to(previous)>.1)
check(g.get_meta("dressing_parts")==0 and g.architecture.braziers.size()==6)
print("PASS: four local imps, 24 animated neighbouring imps, dense instanced service details")
var old_yaw=g.orbit.yaw
var press=InputEventMouseButton.new();press.button_index=MOUSE_BUTTON_MIDDLE;press.pressed=true
g._unhandled_input(press)
check(g.orbit.dragging and Input.mouse_mode==Input.MOUSE_MODE_CAPTURED)
var motion=InputEventMouseMotion.new();motion.relative=Vector2(100,1000)
g._input(motion);g.orbit.update(1)
check(not is_equal_approx(g.orbit.yaw,old_yaw) and is_equal_approx(g.orbit.pitch,1.15))
var release=InputEventMouseButton.new();release.button_index=MOUSE_BUTTON_MIDDLE;release.pressed=false
g._input(release)
check(not g.orbit.dragging and Input.mouse_mode==Input.MOUSE_MODE_VISIBLE)
g.orbit.begin();g.set_pause(true)
check(not g.orbit.dragging and Input.mouse_mode==Input.MOUSE_MODE_VISIBLE)
g.set_pause(false);g.orbit.yaw=old_yaw;g.orbit.pitch=.68;g.orbit.update(1)
print("PASS: 363 cells, middle-button orbit, pitch clamp, release and pause restore cursor")
var first_id=g.souls[0].id
g.player.position=g.GATE_SPAWN
g.grab(first_id)
check(g.held==-1)
advance(g,0.5)
check(g.gate.position.y>0 and g.souls[0].entering)
advance(g,3)
check(g.souls[0].node.position.is_equal_approx(g.GATE_EXIT))
check(not g.souls[0].entering and is_zero_approx(g.gate.position.y))
check(g.souls[0].visual.position.y>.45)
check(g.souls[0].visual.animator.current_animation==g.souls[0].visual.clips["Float"])
for bar in g.gate.get_children():
if bar is MeshInstance3D:check(bar.material_override.shader==preload("res://gate_clip.gdshader"))
for i in range(20): g.spawn_soul()
advance(g,20)
check(g.souls.size()==1 and g.souls[0].id==first_id)
print("PASS: portcullis opens, one sinner exits, no grab during entry or timer duplicates")
g.player.position=g.souls[0].node.position
var solver=preload("res://separation.gd")
solver.resolve(g)
check(g.player.position.distance_to(g.souls[0].node.position)>=0.96)
g.life.imps[0].root.position=g.player.position
solver.resolve(g)
check(g.life.imps[0].root.position.distance_to(g.player.position)>=0.65)
print("PASS: player, soul and decorative imp are separated even from identical starting positions")
g.player.position=g.souls[0].node.position
g.grab(first_id)
var up=InputEventMouseButton.new();up.button_index=MOUSE_BUTTON_LEFT;up.pressed=false
g._unhandled_input(up)
check(g.held==first_id)
g.player.position=g.STATION+Vector3(-2.1,0,0);g.souls[0].node.position=g.STATION+Vector3(-2.0,0,0)
g._process(.016)
check(g.working==first_id and g.held==-1 and g.development.placement_clock>0)
print("PASS: Float pose, one-click telekinetic following, automatic animated placement; gate clipped above arch")
g.set_pause(true)
check(g.menu.current_page=="pause")
g.menu.pause_settings.pressed.emit()
check(g.menu.current_page=="settings")
var escape=InputEventKey.new()
escape.keycode=KEY_ESCAPE
escape.pressed=true
g._unhandled_input(escape)
check(g.menu.current_page=="pause" and g.paused)
g.menu.pause_main.pressed.emit()
check(g.menu.current_page=="main" and not g.hud.visible)
g.coins=777;g.done=25;g.development.xp=420;g.speed_level=2
var old_soul=g.souls[0].node
g.menu.main_start.pressed.emit()
check(not g.paused and g.souls.size()==1 and g.souls[0].node!=old_soul)
check(g.coins==0 and g.done==0 and g.development.xp==0 and g.speed_level==0 and g.development.selected==0)
print("PASS: New Game clears progression, skills, station and previous soul; pause still resumes")
prepare_work(g)
for i in range(4):
g.hit_clock=0
g.hit()
check(g.done==0 and g.souls.size()==1)
g.hit_clock=0
g.hit()
check(g.done==1 and g.coins==10 and g.working==-1 and g.souls.is_empty())
check(g.life.burns.size()==1)
check(g.voice_player.stream==g.MALE_GROAN)
g.complete_soul()
check(g.coins==10)
g.life.update(1.0)
check(g.life.burns.size()==1)
g.life.update(1.1)
check(g.life.burns.is_empty())
check(not g.quote.visible and not g.status.visible and not g.dossier.visible)
check(g.life.imps.size()==4)
g.set_pause(true)
advance(g,5.0)
check(g.souls.is_empty())
g.menu.resume_button.pressed.emit()
advance(g,0.5)
check(g.souls.is_empty())
advance(g,2.5)
check(g.souls.size()==1 and g.souls[0].kind==1)
check(g.development.xp==20 and g.development.points==0)
check(is_instance_valid(g.development.bubble))
check(g.development.bubble.get_child(0).text==g.LINES[1])
g.development.purchase_station(2)
check(g.development.tier==0)
g.development.purchase_station(1)
check(g.coins==10 and g.development.tier==0)
for expected in range(1,5):
prepare_work(g)
for i in range(5):
g.hit_clock=0;g.hit()
advance(g,3)
check(g.coins==50 and g.development.points==1 and g.development.xp==100)
check(g.voice_player.stream==g.FEMALE_GROAN)
g.development.purchase_skill("speed")
check(g.speed_level==1 and g.development.points==0 and g.coins==50)
g.development.purchase_skill("action")
check(g.development.action_level==0)
g.development.purchase_station(1)
check(g.coins==0 and g.development.selected==1)
for tool in [1,2,3]:
g.development.selected=tool;g.player.position=g.STATION
solver.resolve_equipment(g,g.player,.4)
check(g.player.position.distance_to(g.STATION)>1.4)
g.development.selected=1
print("PASS: all apparatus footprints prevent player overlap, including empty devices")
prepare_work(g)
g.development.purchase_station(0)
check(g.development.selected==1)
g.development.step(1.01,true)
check(g.development.stage==1 and g.working>=0)
check(g.development.action_bar.value>=33 and g.development.action_bar.value<35)
g.development.motion.update(0.5,true)
check(g.souls[0].visual.scale.y>1.05)
g.development.step(1,true)
check(g.development.action_bar.value>65 and g.development.action_bar.value<68)
g.development.step(0.1,false)
check(g.development.elapsed==0)
g.set_pause(true)
g.development.step(3,true)
check(g.working>=0)
g.set_pause(false)
g.development.step(2.01,true)
check(g.coins==10 and g.working==-1)
check(g.development.action_bar.value==100)
g.coins=280
g.development.purchase_station(2)
check(g.coins==180)
advance(g,3);prepare_work(g)
g.player.position=Vector3(-6,0,4)
g.development.step(6,true)
check(g.working>=0 and g.development.elapsed==0)
g.player.position=g.STATION
g.development.step(PI/4,true)
g.development.motion.update(0.1,true)
check(g.development.motion.submerged and g.development.motion.splash_count==1)
g.development.elapsed=0;g.development.crank.rotation.z=0
g.development.step(4.9,true)
check(g.working>=0)
g.development.step(0.11,true)
check(g.working==-1 and g.coins==190)
g.development.purchase_station(3)
check(g.coins==10)
advance(g,3);prepare_work(g)
g.development.step(10,true)
check(g.working>=0 and g.development.stage==0)
g.development.activate()
check(g.development.stage==1 and is_instance_valid(g.development.second_door))
g.development.step(0.36,true)
g.development.step(2,true)
g.development.motion.update(1,true)
check(g.development.motion.heat>0.5)
check(g.working>=0 and g.development.flame.visible)
g.development.step(1.01,true)
check(g.working==-1 and g.coins==20)
check(g.development.release_clock>2)
g.development.purchase_station(0)
check(g.development.selected==3)
g.development.points=1
g.development.purchase_skill("action")
check(g.development.action_level==1 and g.development.points==0)
var state=g.progress_snapshot()
check(codec.decode(state,g.build_id)==state)
check(codec.decode(state,"next-build")==codec.defaults("next-build"))
print("PASS: speech bubble, 10 coin / 20 XP rewards, level points, separate skills, station prices and prerequisites")
print("PASS: all four stations, rack tension reset and 2s hold, 5s wheel, maiden close then fire; pause and range gates")
print("PASS: rack stretches, wheel submerges head and splashes, maiden heats and stays locked while soul burns, correct voice selection")
print("ALL TESTS PASSED — DEMON 0.12")
g.get_tree().quit()
func click(g,control):
await g.get_tree().process_frame
var point=control.get_global_rect().get_center()
var motion=InputEventMouseMotion.new()
motion.position=point
motion.global_position=point
Input.parse_input_event(motion)
for pressed in [true,false]:
var event=InputEventMouseButton.new()
event.position=point
event.global_position=point
event.button_index=MOUSE_BUTTON_LEFT
event.pressed=pressed
event.button_mask=MOUSE_BUTTON_MASK_LEFT if pressed else 0
Input.parse_input_event(event)
await g.get_tree().process_frame
func run_ui(g):
await g.get_tree().create_timer(0.3).timeout
await click(g,g.menu.main_settings)
check(g.menu.current_page=="settings")
await click(g,g.menu.volume_slider)
check(g.whip_volume>0.45 and g.whip_volume<0.55)
await click(g,g.menu.ambience_slider)
check(g.ambience_volume>0.45 and g.ambience_volume<0.55)
await click(g,g.menu.mute_check)
check(g.muted)
await click(g,g.menu.settings_back)
check(g.menu.current_page=="main")
await click(g,g.menu.main_start)
check(g.game_started and not g.paused and g.souls.size()==1)
await click(g,g.development.tree_icon)
check(g.development.tree_panel.visible and g.paused)
await click(g,g.development.tree_panel.get_child(1).get_child(-1))
check(not g.paused and not g.development.tree_panel.visible)
var old_yaw=g.orbit.yaw
var middle=InputEventMouseButton.new();middle.position=Vector2(900,500);middle.global_position=middle.position;middle.button_index=MOUSE_BUTTON_MIDDLE;middle.pressed=true;middle.button_mask=MOUSE_BUTTON_MASK_MIDDLE
Input.parse_input_event(middle)
await g.get_tree().process_frame
check(g.orbit.dragging)
var turn=InputEventMouseMotion.new();turn.relative=Vector2(120,30);turn.button_mask=MOUSE_BUTTON_MASK_MIDDLE
Input.parse_input_event(turn)
await g.get_tree().process_frame
check(absf(g.orbit.yaw-old_yaw)>.5)
middle=InputEventMouseButton.new();middle.button_index=MOUSE_BUTTON_MIDDLE;middle.pressed=false;middle.position=Vector2(20,20)
Input.parse_input_event(middle)
await g.get_tree().process_frame
check(not g.orbit.dragging and Input.mouse_mode==Input.MOUSE_MODE_VISIBLE)
g.orbit.yaw=old_yaw;g.orbit.pitch=.68
print("PASS: real viewport MMB drag rotates camera and release over HUD restores cursor")
g.coins=50;g.development.purchase_station(1)
prepare_work(g)
var motion=InputEventMouseMotion.new();motion.position=Vector2(950,620);motion.global_position=motion.position
Input.parse_input_event(motion)
await g.get_tree().process_frame
var oldkey=InputEventKey.new();oldkey.physical_keycode=KEY_E;oldkey.pressed=true;Input.parse_input_event(oldkey)
await g.get_tree().create_timer(0.2).timeout
check(g.development.elapsed==0)
oldkey=InputEventKey.new();oldkey.physical_keycode=KEY_E;oldkey.pressed=false;Input.parse_input_event(oldkey)
var right=InputEventMouseButton.new();right.position=motion.position;right.global_position=motion.position;right.button_index=MOUSE_BUTTON_RIGHT;right.pressed=true;right.button_mask=MOUSE_BUTTON_MASK_RIGHT
Input.parse_input_event(right)
await g.get_tree().create_timer(1.2).timeout
check(g.development.stage==1 and g.working>=0)
await g.get_tree().create_timer(2.2).timeout
check(g.done==1 and g.life.burns.size()==1)
right=InputEventMouseButton.new();right.position=motion.position;right.global_position=motion.position;right.button_index=MOUSE_BUTTON_RIGHT;right.pressed=false
Input.parse_input_event(right)
await g.get_tree().create_timer(2.1).timeout
check(g.life.burns.is_empty())
print("PASS: pentagram opens/closes modal tree; E does nothing; actual held RMB completes rack; burn effect cleans up")
var cash=g.coins
var previous_level=g.workshop.Economy.level(g.development.xp)
var previous_points=g.development.points
for i in range(2):
for down in [true,false]:
var boost=InputEventKey.new();boost.keycode=KEY_F5;boost.physical_keycode=KEY_F5;boost.pressed=down
Input.parse_input_event(boost)
await g.get_tree().process_frame
var boosted_level=mini(10,previous_level+2)
check(g.coins==cash+2000 and g.workshop.Economy.level(g.development.xp)==boosted_level and g.development.points==previous_points+boosted_level-previous_level)
g.development.purchase_skill("speed")
var spent_points=g.development.points
g.development.test_boost()
check(g.speed_level==1 and g.development.points==spent_points+(1 if boosted_level<10 else 0))
var boosted_xp=g.development.xp;var boosted_points=g.development.points
g.development.reward()
check(g.development.xp==mini(g.workshop.Economy.XP_THRESHOLDS.back(),boosted_xp+20) and g.development.points==boosted_points)
check(g.Progression.decode(g.progress_snapshot(),g.build_id)==g.progress_snapshot())
print("PASS: F5 adds 1000 gold and souls plus one level per press, caps level at 10, preserves skills and persists save")
var key=InputEventKey.new()
key.keycode=KEY_ESCAPE
key.pressed=true
Input.parse_input_event(key)
await g.get_tree().process_frame
key=InputEventKey.new()
key.keycode=KEY_ESCAPE
key.pressed=false
Input.parse_input_event(key)
check(g.paused and g.menu.current_page=="pause")
await click(g,g.menu.pause_main)
check(g.menu.current_page=="main")
print("PASS: real viewport mouse input — settings, slider, mute, back, start, Esc, main menu")
print("UI_EXIT_CLICK: invoking the actual Exit button")
await click(g,g.menu.main_exit)
func run_audio(g):
# Exercise the actual Vorbis loop silently, close to the hour-long boundary.
g.ambience_fade=1.0
g.whip_volume=0.25
g.ambience_volume=0.70
g.set_sound_muted(true)
check(g.ambience_player.stream.loop and is_zero_approx(g.ambience_player.stream.loop_offset))
check(is_equal_approx(g.audio_player.volume_db,-3.0+linear_to_db(0.25)))
check(is_equal_approx(g.ambience_player.volume_db,linear_to_db(0.70)))
g.ambience_player.play(g.ambience_player.stream.get_length()-0.15)
await g.get_tree().create_timer(0.8).timeout
check(g.ambience_player.playing)
check(g.ambience_player.get_playback_position()<2.0)
g.start_game()
g.set_pause(true)
check(not g.ambience_player.stream_paused)
var before=g.ambience_player.get_playback_position()
await g.get_tree().create_timer(0.15).timeout
check(g.ambience_player.get_playback_position()>before)
g.return_to_main_menu()
check(g.ambience_player.playing)
g.menu.main_settings.pressed.emit()
g.menu.ambience_slider.value=20
check(is_equal_approx(g.ambience_volume,0.20))
check(is_equal_approx(g.whip_volume,0.25))
g.menu.voice_slider.value=30
check(is_equal_approx(g.voice_volume,0.3) and is_equal_approx(g.voice_player.volume_db,linear_to_db(0.3)))
for clip in [g.MALE_GROAN,g.FEMALE_GROAN]:
g.voice_player.stream=clip;g.voice_player.stream_paused=false;g.voice_player.play()
await g.get_tree().create_timer(0.10).timeout
check(g.voice_player.playing and g.voice_player.get_playback_position()>0)
g.voice_player.stop()
for kind in range(11):
for variant in range(2):
var clip=load("res://audio/dialogue/voice_%02d_%d.ogg" % [kind,variant])
check(clip is AudioStreamOggVorbis and clip.get_length()>1.3 and not clip.loop)
for kind in [0,4,10]:
g.paused=false
g.dialogue.player.stream=load("res://audio/dialogue/voice_%02d_0.ogg" % kind)
g.dialogue.player.stream_paused=false;g.dialogue.player.play()
await g.get_tree().create_timer(.1).timeout
check(g.dialogue.player.playing)
g.dialogue.stop()
g.paused=true
print("PASS: 22 nonverbal voice variants; male, female and succubus streams decode/play")
print("PASS: male and female groans decode/play; independent voice volume; master mute remains active")
for placed in [true,false]:
g.workshop.play_build_sound(placed)
var player=g.workshop.build_player
check(player.stream.get_length()>.3)
check(is_equal_approx(player.volume_db,-3.0+linear_to_db(g.whip_volume)))
player.play()
await g.get_tree().create_timer(.08).timeout
check(player.playing and player.get_playback_position()>0)
player.stop()
print("PASS: original placement and deletion effects decode/play; effects volume and master mute")
var pop=AudioStreamPlayer.new();g.add_child(pop)
pop.stream=preload("res://audio/infernal_pop.wav").duplicate()
pop.stream.loop_mode=AudioStreamWAV.LOOP_FORWARD;pop.stream.loop_end=int(pop.stream.get_length()*pop.stream.mix_rate)
check(pop.stream.get_length()>7.9)
pop.play(7.85)
await g.get_tree().create_timer(.45).timeout
check(pop.playing and pop.get_playback_position()<1.0)
pop.stop();pop.queue_free()
print("PASS: original pop loop decodes/plays and wraps; no third-party music")
g.ambience_player.stop()
print("PASS: real Ogg playback wraps at the end; ambience continues through pause/menu; independent levels and master mute")
g.get_tree().quit()