- Die dreizehn Erfolge samt Belohnungen, Meldungen und Spielstandfeld sind weg - Der bisherige Erfolgs-Bildschirm heißt Statistik und zeigt Kämpfe, Tagesaufgabe, Bestenliste, beste Karten und den CSV-Export Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QPgKvy5W9WRNFHjkm5QsHx
1117 lines
50 KiB
GDScript
1117 lines
50 KiB
GDScript
extends Node
|
|
## Oberflächentest mit echtem Fenster und Screenshots:
|
|
## DINGER_SHOTS=/pfad/zum/ordner godot --path . tests/ui_test.tscn
|
|
|
|
const SAVE := "user://test_ui_spielstand.json"
|
|
|
|
var main: Control
|
|
var shots := ""
|
|
var passed := 0
|
|
var failed := 0
|
|
|
|
|
|
func check(cond: bool, msg: String) -> void:
|
|
if cond:
|
|
passed += 1
|
|
else:
|
|
failed += 1
|
|
printerr("FEHLER: " + msg)
|
|
|
|
|
|
func frames(n: int = 2) -> void:
|
|
for i in n:
|
|
await get_tree().process_frame
|
|
|
|
|
|
func shot(name: String) -> void:
|
|
if shots == "":
|
|
return
|
|
await RenderingServer.frame_post_draw
|
|
get_viewport().get_texture().get_image().save_png(shots.path_join(name + ".png"))
|
|
|
|
|
|
func click_at(pos: Vector2) -> void:
|
|
var down := InputEventMouseButton.new()
|
|
down.position = pos
|
|
down.global_position = pos
|
|
down.button_index = MOUSE_BUTTON_LEFT
|
|
down.pressed = true
|
|
get_viewport().push_input(down)
|
|
var up: InputEventMouseButton = down.duplicate()
|
|
up.pressed = false
|
|
get_viewport().push_input(up)
|
|
await frames(2)
|
|
|
|
|
|
func click(node: Control) -> void:
|
|
check(node != null, "Klickziel vorhanden")
|
|
if node != null:
|
|
await click_at(node.get_global_rect().get_center())
|
|
|
|
|
|
func right_click() -> void:
|
|
var down := InputEventMouseButton.new()
|
|
down.position = Vector2(5, 5)
|
|
down.global_position = down.position
|
|
down.button_index = MOUSE_BUTTON_RIGHT
|
|
down.pressed = true
|
|
get_viewport().push_input(down)
|
|
var up: InputEventMouseButton = down.duplicate()
|
|
up.pressed = false
|
|
get_viewport().push_input(up)
|
|
await frames(2)
|
|
|
|
|
|
func key(code: int) -> void:
|
|
var down := InputEventKey.new()
|
|
down.keycode = code
|
|
down.pressed = true
|
|
get_viewport().push_input(down)
|
|
var up := InputEventKey.new()
|
|
up.keycode = code
|
|
up.pressed = false
|
|
get_viewport().push_input(up)
|
|
await frames(2)
|
|
|
|
|
|
func pad(button: int) -> void:
|
|
var ev := InputEventJoypadButton.new()
|
|
ev.button_index = button
|
|
ev.pressed = true
|
|
get_viewport().push_input(ev)
|
|
await frames(2)
|
|
|
|
|
|
## Mulligan-Maske wegklicken (Hand behalten), falls sie offen ist.
|
|
func clear_mulligan(scr) -> void:
|
|
if scr.mulligan_box.visible:
|
|
await click(scr.b_keep)
|
|
|
|
|
|
func hover(node: Control) -> void:
|
|
var ev := InputEventMouseMotion.new()
|
|
ev.position = node.get_global_rect().get_center()
|
|
ev.global_position = ev.position
|
|
get_viewport().push_input(ev)
|
|
await frames(2)
|
|
|
|
|
|
func screen():
|
|
return main.screen
|
|
|
|
|
|
## Jeder Abschnitt startet im Menü, auch wenn ein vorheriger abgebrochen ist.
|
|
func ensure_menu() -> void:
|
|
if main.net.connected:
|
|
main.net.leave()
|
|
if TranslationServer.get_locale().begins_with("en"):
|
|
main.set_language("de")
|
|
if not (screen() is MenuScreen):
|
|
main.show_screen(MenuScreen.new())
|
|
await frames(2)
|
|
|
|
|
|
func find_button(text: String, root: Node = null) -> Button:
|
|
if root == null:
|
|
root = screen()
|
|
for c in root.get_children():
|
|
if c is Button and (c.text == text or c.tr(c.text) == text) and c.is_visible_in_tree():
|
|
return c
|
|
var found := find_button(text, c)
|
|
if found != null:
|
|
return found
|
|
return null
|
|
|
|
|
|
func card_views(root: Node) -> Array:
|
|
var out := []
|
|
for c in root.get_children():
|
|
if c is CardView:
|
|
out.append(c)
|
|
out.append_array(card_views(c))
|
|
return out
|
|
|
|
|
|
## Wartet, bis keine Kachel mehr animiert wird (Angriffe verschieben Kacheln kurz).
|
|
func settle(scr) -> void:
|
|
for i in 40:
|
|
if not scr.tiles.values().any(func(t): return t.busy):
|
|
return
|
|
await frames(1)
|
|
|
|
|
|
func wait_for_human(scr) -> void:
|
|
var g: Game = scr.game
|
|
var wait := 0
|
|
while g.current() != g.human and g.winner == "" and wait < 600:
|
|
await frames(1)
|
|
wait += 1
|
|
await frames(1)
|
|
await clear_mulligan(scr)
|
|
|
|
|
|
func _ready() -> void:
|
|
Game.test_seed = 4242 # wiederholbare Partien und Booster
|
|
shots = OS.get_environment("DINGER_SHOTS")
|
|
var abs := ProjectSettings.globalize_path(SAVE)
|
|
for suffix in ["", ".bak", ".corrupt"]:
|
|
if FileAccess.file_exists(SAVE + suffix):
|
|
DirAccess.remove_absolute(abs + suffix)
|
|
if FileAccess.file_exists(SAVE.get_basename() + "_kampf.json"):
|
|
DirAccess.remove_absolute(abs.get_basename() + "_kampf.json")
|
|
main = load("res://scenes/main.tscn").instantiate()
|
|
main.save_path = SAVE
|
|
add_child(main)
|
|
await frames(3)
|
|
var fast := OS.get_environment("DINGER_FAST") != ""
|
|
var suite := [test_menu_und_regeln, test_gamepad_menue, test_booster, test_deckbau, test_gegnerauswahl, test_einstellungen,
|
|
test_statistik, test_kampagne, test_werkstatt, test_sprache, test_anleitung, test_anleitung2,
|
|
test_kampf_fortsetzen, test_gamepad_deckbau, test_deckcode, test_elementbooster]
|
|
if not fast:
|
|
suite += [test_kampf.bind(2, 3), test_kampf_abbrechen]
|
|
# Die Netzwerktests starten Bot-Prozesse und warten auf Verbindungen; das dauert Minuten.
|
|
# Sie laufen nur auf Wunsch: DINGER_NETZ=1 (oder gezielt über DINGER_ONLY).
|
|
if OS.get_environment("DINGER_NETZ") != "":
|
|
suite += [test_netzwerk, test_host_wechsel, test_zuschauer]
|
|
suite.append(test_profil_zuruecksetzen)
|
|
var only := OS.get_environment("DINGER_ONLY") # z. B. DINGER_ONLY=test_host_wechsel,test_zuschauer
|
|
if only != "":
|
|
suite = suite.filter(func(t: Callable): return t.get_method() in only.split(","))
|
|
for t in suite:
|
|
await ensure_menu()
|
|
await t.call()
|
|
for suffix in ["", ".bak", ".corrupt"]:
|
|
if FileAccess.file_exists(SAVE + suffix):
|
|
DirAccess.remove_absolute(abs + suffix)
|
|
print("%d Prüfungen bestanden, %d fehlgeschlagen" % [passed, failed])
|
|
get_tree().quit(1 if failed > 0 else 0)
|
|
|
|
|
|
func test_menu_und_regeln() -> void:
|
|
check(screen() is MenuScreen, "Menü sichtbar")
|
|
await shot("01_menu")
|
|
await click(find_button("Regeln"))
|
|
check(screen() is RulesScreen, "Regeln geöffnet")
|
|
await shot("02_regeln")
|
|
await click(find_button("Zurück"))
|
|
check(screen() is MenuScreen, "zurück im Menü")
|
|
|
|
|
|
func test_booster() -> void:
|
|
await click(find_button("Booster öffnen"))
|
|
var scr = screen()
|
|
check(scr is BoosterScreen, "Boosterbildschirm")
|
|
var coins: int = main.profile.coins
|
|
await click(scr.b_buy)
|
|
check(main.profile.coins == coins - Profile.BOOSTER_COST, "Booster bezahlt")
|
|
check(scr.cards.size() == 5 and scr.revealed.is_empty(), "5 verdeckte Karten")
|
|
await shot("03_booster_zu")
|
|
var backs: Array = scr.slots.get_children().filter(func(c): return c is BoosterScreen.CardBack)
|
|
await click(backs[0])
|
|
check(scr.revealed.size() == 1, "eine Karte aufgedeckt")
|
|
await click(scr.b_all)
|
|
check(scr.revealed.size() == 5, "alle aufgedeckt")
|
|
await shot("04_booster_offen")
|
|
check(Profile.load_or_new(SAVE).coins == main.profile.coins, "Kauf gespeichert")
|
|
var ids: Array = scr.cards.map(func(c): return c.id)
|
|
var better: Array = main.profile.deck_suggestions(ids)
|
|
check(scr.b_improve.visible == (not better.is_empty()), "Deck-Vorschlag nur bei passender Karte")
|
|
if scr.b_improve.visible:
|
|
var deck_before: Array = main.profile.deck.duplicate()
|
|
await click(scr.b_improve)
|
|
check(main.profile.deck != deck_before and main.profile.deck_valid()[0] and "im Deck" in scr.msg_label.text, "Karte ins Deck übernommen")
|
|
check(scr.b_buy.disabled == (main.profile.coins < Profile.BOOSTER_COST), "Kaufknopf folgt dem Münzstand")
|
|
await click(find_button("Zurück"))
|
|
check(screen() is MenuScreen, "zurück im Menü")
|
|
|
|
|
|
func test_deckbau() -> void:
|
|
await click(find_button("Deck bauen"))
|
|
var scr = screen()
|
|
check(scr is DeckScreen, "Deckbildschirm")
|
|
check(scr.deck.size() == 20, "Deck geladen")
|
|
check("Stärke" in scr.elems_label.text, "Deckstärke im Deckbau")
|
|
await shot("05_deck")
|
|
await click(find_button("Leeren"))
|
|
check(scr.deck.is_empty(), "geleert")
|
|
var first_id: String = card_views(scr.grid)[0].card.id
|
|
var allowed: int = mini(main.profile.collection[first_id], Game.MAX_COPIES)
|
|
await click(card_views(scr.grid)[0])
|
|
check(scr.deck == [first_id], "Karte hinzugefügt")
|
|
for i in allowed:
|
|
await click(card_views(scr.grid)[0])
|
|
check(scr.deck.count(first_id) == allowed and "Kopien" in scr.msg_label.text, "nur besessene Kopien (%d)" % allowed)
|
|
await click(find_button("Speichern"))
|
|
check(main.profile.deck.size() == 20 and scr.msg_label.text != "Deck gespeichert", "zu kleines Deck nicht gespeichert")
|
|
await click(find_button("Wasser"))
|
|
await click(card_views(scr.grid)[0])
|
|
await click(find_button("Erde"))
|
|
await click(card_views(scr.grid)[0])
|
|
check("Elemente" in scr.msg_label.text, "drittes Element abgelehnt")
|
|
await click(find_button("Alle"))
|
|
# Suche, Sortierung, fehlende Karten
|
|
var all_count := card_views(scr.grid).size()
|
|
scr.search_box.text = "Wächter"
|
|
scr.search_box.text_changed.emit("Wächter")
|
|
await frames(1)
|
|
var found := card_views(scr.grid)
|
|
check(found.size() > 0 and found.size() < all_count, "Suche filtert")
|
|
check(found.all(func(v): return "Wächter" in v.card.text() or "Wächter" in v.card.name), "Suche trifft Kartentext")
|
|
scr.search_box.text = ""
|
|
scr.search_box.text_changed.emit("")
|
|
scr.sort_box.select(1)
|
|
scr.sort_box.item_selected.emit(1)
|
|
await frames(1)
|
|
var names: Array = card_views(scr.grid).map(func(v): return v.card.name)
|
|
var sorted_names := names.duplicate()
|
|
sorted_names.sort()
|
|
check(names == sorted_names, "Sortierung nach Name")
|
|
scr.missing_box.button_pressed = true
|
|
await frames(1)
|
|
check(card_views(scr.grid).size() == Cards.all().size(), "Fehlende Karten eingeblendet")
|
|
var missing = card_views(scr.grid).filter(func(v): return main.profile.collection.get(v.card.id, 0) == 0)
|
|
check(not missing.is_empty(), "es gibt fehlende Karten")
|
|
await click(missing[0])
|
|
check("fehlt" in scr.msg_label.text, "fehlende Karte nicht ins Deck")
|
|
scr.missing_box.button_pressed = false
|
|
scr.sort_box.select(0)
|
|
scr.sort_box.item_selected.emit(0)
|
|
await frames(1)
|
|
var n: int = scr.deck.size()
|
|
await click(scr.deck_list.get_children()[0])
|
|
check(scr.deck.size() == n - 1, "Zeile entfernt Karte")
|
|
await hover(card_views(scr.grid)[0])
|
|
check(scr.preview.visible, "Vorschau bei Hover")
|
|
await shot("06_deck_bearbeitet")
|
|
# Slots: Deck 2 aus Deck 1 kopieren, speichern, aktiv setzen
|
|
await click(scr.slot_buttons[1])
|
|
if scr.slot != 1 or not scr.deck.is_empty():
|
|
print("DEBUG Slot: slot=", scr.slot, " deck=", scr.deck.size(), " rect=", scr.slot_buttons[1].get_global_rect(),
|
|
" hovered=", get_viewport().gui_get_hovered_control(), " decks1=", main.profile.decks[1].cards.size())
|
|
check(scr.slot == 1 and scr.deck.is_empty(), "Slot 2 leer")
|
|
scr.deck = main.profile.decks[0].cards.duplicate()
|
|
scr.refresh()
|
|
await click(find_button("Speichern"))
|
|
check(main.profile.decks[1].cards.size() == 20 and "gespeichert" in scr.msg_label.text, "Slot 2 gespeichert")
|
|
await click(find_button("Aktiv setzen"))
|
|
check(main.profile.active_deck == 1 and main.profile.deck_name() == "Deck 2", "Slot 2 aktiv")
|
|
check(Profile.load_or_new(SAVE).active_deck == 1, "aktiver Slot gespeichert")
|
|
scr.name_box.text = "Testdeck"
|
|
scr.name_box.text_submitted.emit("Testdeck")
|
|
check(main.profile.deck_name(1) == "Testdeck" and Profile.load_or_new(SAVE).deck_name(1) == "Testdeck", "Deck umbenannt")
|
|
await click(scr.slot_buttons[2])
|
|
check(scr.slot == 2 and scr.deck.is_empty(), "Slot 3 leer")
|
|
await click(find_button("Auto-Ausfüllen"))
|
|
check(scr.deck.size() == 20 and main.profile.deck_valid(2)[0], "Slot 3 automatisch gefüllt und spielbar")
|
|
await shot("25_deck_slots")
|
|
await click(scr.deck_list.get_children()[0]) # ungespeicherte Änderung: eine Karte entfernt
|
|
check(scr.dirty(), "Deck geändert")
|
|
await click(find_button("Zurück"))
|
|
check(scr.confirm.visible and screen() == scr, "Warnung bei ungespeicherten Änderungen")
|
|
await click(find_button("Weiter bearbeiten"))
|
|
check(not scr.confirm.visible, "weiter bearbeiten")
|
|
await click(find_button("Zurück"))
|
|
await click(find_button("Verwerfen"))
|
|
check(screen() is MenuScreen and main.profile.deck.size() == 20, "Änderungen verworfen")
|
|
|
|
|
|
func target_view(scr, valid: Array) -> Control:
|
|
for v in scr.enemy_views:
|
|
if v.creature in valid:
|
|
return v
|
|
for v in scr.own_views:
|
|
if v.creature in valid:
|
|
return v
|
|
for p in scr.hero_panels:
|
|
if p in valid:
|
|
return scr.hero_panels[p]
|
|
return null
|
|
|
|
|
|
func human_turn(scr) -> void:
|
|
var g: Game = scr.game
|
|
await clear_mulligan(scr)
|
|
for i in 12:
|
|
var playable: Array = scr.hand_views.filter(func(v): return g.can_play(g.human, v.card)[0])
|
|
if playable.is_empty():
|
|
break
|
|
var card: Cards.Card = playable[0].card
|
|
var energy: int = g.human.energy
|
|
await click(playable[0])
|
|
if scr.pending != null:
|
|
await click(target_view(scr, g.valid_targets(g.human, card.target_type())))
|
|
check(g.human.energy == energy - card.cost, "Karte gespielt: " + card.name)
|
|
for i in 12:
|
|
var ready: Array = scr.own_views.filter(func(v): return v.creature.can_attack())
|
|
if ready.is_empty() or g.winner != "":
|
|
break
|
|
var cr: Game.Creature = ready[0].creature
|
|
await settle(scr)
|
|
await hover(ready[0])
|
|
var under = get_viewport().gui_get_hovered_control()
|
|
await click(ready[0])
|
|
if scr.selected != cr:
|
|
print("DEBUG Auswahl fehlgeschlagen: rect=", ready[0].get_global_rect(), " scale=", ready[0].scale,
|
|
" busy=", ready[0].busy, " unter Maus=", under, " Meldung='", scr.msg_label.text,
|
|
"' Zug Mensch=", g.current().is_human, " kann=", cr.can_attack(), " pending=", scr.pending, " selected=", scr.selected)
|
|
check(scr.selected == cr, "Wesen gewählt")
|
|
var targets := []
|
|
for o in g.opponents:
|
|
if o.alive() and g.can_attack(cr, o)[0]:
|
|
targets.append(o)
|
|
for c in o.board:
|
|
if g.can_attack(cr, c)[0]:
|
|
targets.append(c)
|
|
await settle(scr)
|
|
await click(target_view(scr, targets))
|
|
check(scr.selected == null and cr.attacks_left < cr.attacks_per_turn(), "Angriff ausgeführt")
|
|
if g.winner == "":
|
|
await click(scr.b_end)
|
|
|
|
|
|
func start_battle(n_opp: int) -> void:
|
|
await click(find_button("Einzelspieler"))
|
|
check(screen() is OpponentSelectScreen, "Gegnerauswahl")
|
|
screen().count_slider.value = n_opp
|
|
await frames(1)
|
|
await click(find_button("Starten"))
|
|
|
|
|
|
func test_gegnerauswahl() -> void:
|
|
await click(find_button("Einzelspieler"))
|
|
var sel = screen()
|
|
check(sel is OpponentSelectScreen, "Gegnerauswahl geöffnet")
|
|
check("Deckstärke" in sel.rating_label.text and "Gegnerdecks" in sel.rating_label.text
|
|
and not ("Archetypen" in sel.rating_label.text or "KI" in sel.rating_label.text), "unter der Schwierigkeit nur die zwei Stärken")
|
|
check(find_button("Neu würfeln") == null and find_button("1 Gegner") == null and find_button("Starten") != null, "kein Würfeln und keine Gegnerknöpfe, nur Starten")
|
|
check(sel.count_slider.min_value == 1 and sel.count_slider.max_value == Game.MAX_OPPONENTS and sel.count_slider.step == 1, "Gegnerzahl als Schieberegler von 1 bis %d" % Game.MAX_OPPONENTS)
|
|
check(sel.opponents() == 1 and sel.count_label.text == "1 Gegner" and "Duell" in sel.info_label.text, "Regler beginnt beim Duell")
|
|
var rect: Rect2 = sel.count_slider.get_global_rect()
|
|
await click_at(Vector2(rect.end.x - 4, rect.get_center().y)) # ganz rechts anklicken
|
|
check(sel.opponents() == Game.MAX_OPPONENTS and sel.count_label.text == "%d Gegner" % Game.MAX_OPPONENTS, "Mausklick am rechten Rand stellt %d Gegner ein" % Game.MAX_OPPONENTS)
|
|
sel.count_slider.grab_focus()
|
|
await key(KEY_LEFT)
|
|
check(sel.opponents() == Game.MAX_OPPONENTS - 1, "Pfeiltaste links nimmt einen Gegner weg")
|
|
sel.count_slider.value = 4
|
|
await frames(1)
|
|
check(sel.opponents() == 4 and sel.count_label.text == "4 Gegner" and "5 am Tisch" in sel.info_label.text
|
|
and str(Profile.REWARD_WIN[4]) in sel.info_label.text, "Regler auf 4: fünf am Tisch mit Belohnung")
|
|
await click(find_button("Schwer"))
|
|
check(main.profile.settings.difficulty == "schwer" and Profile.load_or_new(SAVE).settings.difficulty == "schwer", "Schwer gewählt und gespeichert")
|
|
await shot("07_gegnerauswahl")
|
|
sel.count_slider.value = 1
|
|
await frames(1)
|
|
await click(find_button("Starten"))
|
|
var hard = screen()
|
|
check(hard is BattleScreen and hard.game.opponents.size() == 1, "Kampf mit einem Gegner gestartet")
|
|
var own := Game.deck_rating(main.profile.deck_cards())
|
|
var opp: Game.Player = hard.game.opponents[0]
|
|
var opp_rating := Game.deck_rating(opp.deck + opp.hand)
|
|
check(opp_rating >= own * 1.05 - 0.05 and hard.smart_ai, "Schwer: Gegnerdeck stärker (%.2f zu %.2f), Vorausschau-KI" % [opp_rating, own])
|
|
await give_up()
|
|
await click(find_button("Einzelspieler"))
|
|
await click(find_button("Leicht"))
|
|
await click(find_button("Starten"))
|
|
var easy = screen()
|
|
opp = easy.game.opponents[0]
|
|
check(Game.deck_rating(opp.deck + opp.hand) <= own * 1.0 + 0.15 and not easy.smart_ai, "Leicht: schwächeres Deck, einfache KI")
|
|
await give_up()
|
|
await click(find_button("Einzelspieler"))
|
|
await click(find_button("Normal"))
|
|
await click(find_button("Zurück"))
|
|
check(screen() is MenuScreen, "zurück im Menü")
|
|
for n in [1, 5]:
|
|
await start_battle(n)
|
|
var scr = screen()
|
|
check(scr is BattleScreen and scr.game.opponents.size() == n, "Kampf gegen %d gestartet" % n)
|
|
check(scr.game.players[0].max_energy == 1 and scr.game.opponents[0].life == Game.START_LIFE, "gleiche Regeln gegen %d" % n)
|
|
await shot("11_kampf_%d" % n)
|
|
await give_up()
|
|
|
|
|
|
## Kampf verlassen: nach Spielende über den Ergebnisdialog, sonst per Aufgeben.
|
|
func leave_battle() -> void:
|
|
var scr = screen()
|
|
if scr is BattleScreen and scr.game != null and scr.game.winner != "":
|
|
await frames(2)
|
|
await click(find_button("Zurück zum Menü"))
|
|
check(screen() is MenuScreen, "Ergebnisdialog führt ins Menü")
|
|
else:
|
|
await give_up()
|
|
|
|
|
|
func give_up() -> void:
|
|
var scr = screen()
|
|
await clear_mulligan(scr)
|
|
await click(find_button("Aufgeben"))
|
|
check(scr.confirm.visible, "Aufgeben fragt nach")
|
|
await click(find_button("Weiterspielen"))
|
|
check(not scr.confirm.visible and screen() == scr, "Weiterspielen bleibt im Kampf")
|
|
await click(find_button("Aufgeben"))
|
|
await click(find_button("Ja, aufgeben"))
|
|
check(screen() is MenuScreen, "Aufgeben führt ins Menü")
|
|
|
|
|
|
## Gamepad im Deckbau: Karten und Deckzeilen sind fokussierbar, A wirkt wie ein Klick, B geht zurück.
|
|
func test_gamepad_deckbau() -> void:
|
|
await click(find_button("Deck bauen"))
|
|
var scr = screen()
|
|
var before: int = scr.deck.size()
|
|
await pad(JOY_BUTTON_DPAD_DOWN)
|
|
check(get_viewport().gui_get_focus_owner() != null and main.pad_mode, "Gamepad setzt Fokus im Deckbau")
|
|
var row: Control = scr.deck_list.get_child(0)
|
|
row.grab_focus()
|
|
await frames(1)
|
|
check(row.has_focus() and scr.preview.visible, "Deckzeile fokussierbar, Vorschau folgt")
|
|
await pad(JOY_BUTTON_A)
|
|
check(scr.deck.size() == before - 1, "A entfernt die fokussierte Karte aus dem Deck")
|
|
var elems: Array = Game.deck_elements(scr.deck_cards())
|
|
var target: CardView = null
|
|
for v in scr.grid.views():
|
|
if not v.dim and v.card.elements.all(func(e): return e in elems):
|
|
target = v
|
|
break
|
|
target.grab_focus()
|
|
await frames(1)
|
|
check(target.has_focus() and scr.preview.visible and scr.preview.card == target.card, "Karte im Raster fokussierbar mit Vorschau")
|
|
var target_id: String = target.card.id
|
|
await pad(JOY_BUTTON_A) # das Raster wird danach neu aufgebaut, target ist dann freigegeben
|
|
check(scr.deck.size() == before and target_id in scr.deck, "A nimmt die fokussierte Karte ins Deck (%d Karten, Meldung '%s')" % [scr.deck.size(), scr.msg_label.text])
|
|
await shot("31_gamepad_deckbau")
|
|
await pad(JOY_BUTTON_B)
|
|
check(scr.confirm.visible, "B fragt bei ungespeicherten Änderungen nach")
|
|
await click(find_button("Verwerfen"))
|
|
check(screen() is MenuScreen, "Verwerfen führt ins Menü")
|
|
await hover(main)
|
|
|
|
|
|
## Deck-Code kopieren, einfügen und übernehmen.
|
|
func test_deckcode() -> void:
|
|
await click(find_button("Deck bauen"))
|
|
var scr = screen()
|
|
await click(find_button("Code"))
|
|
check(scr.code_dialog.visible and scr.code_box.text.begins_with(Profile.CODE_PREFIX), "Code-Dialog zeigt den Deck-Code")
|
|
await click(find_button("In Zwischenablage"))
|
|
check(DisplayServer.clipboard_get() == scr.code_box.text, "Code in der Zwischenablage")
|
|
await shot("32_deckcode")
|
|
scr.code_box.text = "DINGER1:f_funke*2,e_wall*1,x_nix*1"
|
|
await click(find_button("Übernehmen"))
|
|
check(scr.deck.size() == Game.DECK_SIZE and "Ungültiger Code" in scr.msg_label.text, "ungültiger Code wird abgelehnt")
|
|
scr.code_box.text = "DINGER1:f_funke*2,e_wall*1,fff_sonne*1"
|
|
await click(find_button("Übernehmen"))
|
|
check(scr.deck == ["f_funke", "f_funke", "e_wall"] and "Kern der Sonne" in scr.msg_label.text and not scr.code_dialog.visible, "Code übernommen, fehlende Karte gemeldet")
|
|
await click(find_button("Zurück"))
|
|
await click(find_button("Verwerfen"))
|
|
check(screen() is MenuScreen, "Deckbau verlassen")
|
|
|
|
|
|
## Elementbooster liefert nur Karten des Elements.
|
|
func test_elementbooster() -> void:
|
|
main.profile.coins = 300
|
|
await click(find_button("Booster öffnen"))
|
|
var scr = screen()
|
|
await click(find_button("Feuer"))
|
|
check(scr.cards.size() == 5 and scr.cards.all(func(c): return "Feuer" in c.elements) and main.profile.coins == 300 - Profile.ELEMENT_BOOSTER_COST, "Feuer-Booster: fünf Feuerkarten")
|
|
await click(find_button("Alle aufdecken"))
|
|
await shot("33_elementbooster")
|
|
await click(find_button("Zurück"))
|
|
|
|
|
|
## Kampf speichern, im Menü fortsetzen, Aufgeben löscht die Datei.
|
|
func test_kampf_fortsetzen() -> void:
|
|
await start_battle(1)
|
|
var scr = screen()
|
|
scr.ai_delay = 0.0
|
|
await wait_for_human(scr)
|
|
var kampf: String = main.battle_save_path()
|
|
check(FileAccess.file_exists(kampf), "Kampf wird laufend gespeichert")
|
|
await click(scr.b_end)
|
|
await wait_for_human(scr)
|
|
var turn: int = scr.game.turn
|
|
var life: int = scr.game.human.life
|
|
var hand: int = scr.game.human.hand.size()
|
|
await click(find_button("Aufgeben"))
|
|
await click(find_button("Speichern und zurück"))
|
|
check(screen() is MenuScreen and find_button("Kampf fortsetzen") != null, "Speichern führt ins Menü mit Fortsetzen-Knopf")
|
|
await click(find_button("Kampf fortsetzen"))
|
|
var scr2 = screen()
|
|
check(scr2 is BattleScreen and scr2.game.turn == turn and scr2.game.human.life == life and scr2.game.human.hand.size() == hand
|
|
and scr2.game.current() == scr2.game.human, "Kampf fortgesetzt mit gleichem Zug, Leben und Hand")
|
|
scr2.ai_delay = 0.0
|
|
await shot("30_kampf_fortgesetzt")
|
|
await give_up()
|
|
check(not FileAccess.file_exists(kampf) and find_button("Kampf fortsetzen") == null, "Aufgeben löscht den gespeicherten Kampf")
|
|
|
|
|
|
func test_einstellungen() -> void:
|
|
await click(find_button("Einstellungen"))
|
|
var scr = screen()
|
|
check(scr is SettingsScreen, "Einstellungen geöffnet")
|
|
scr.volume.value = 0.3
|
|
scr.speed.value = 2.0
|
|
scr.anim.button_pressed = false
|
|
await frames(1)
|
|
check(is_equal_approx(main.profile.settings.volume, 0.3) and is_equal_approx(main.profile.settings.ai_speed, 2.0), "Regler gespeichert")
|
|
check(main.profile.settings.animations == false, "Animationen abschaltbar")
|
|
check(is_equal_approx(Profile.load_or_new(SAVE).settings.volume, 0.3), "Einstellungen auf Platte")
|
|
scr.anim.button_pressed = true
|
|
scr.big_font.button_pressed = true
|
|
await frames(2)
|
|
check(main.profile.settings.big_font and Style.font_scale > 1.0 and screen() is SettingsScreen, "große Schrift aktiv")
|
|
screen().big_font.button_pressed = false
|
|
await frames(2)
|
|
check(is_equal_approx(Style.font_scale, 1.0), "normale Schrift")
|
|
var scr_b = screen()
|
|
await shot("13_einstellungen")
|
|
scr = scr_b
|
|
await click(find_button("Zurück"))
|
|
check(screen() is MenuScreen, "zurück im Menü")
|
|
|
|
|
|
func test_statistik() -> void:
|
|
await click(find_button("Statistik"))
|
|
check(screen() is StatsScreen, "Statistik geöffnet")
|
|
var csv := "user://statistik.csv"
|
|
if FileAccess.file_exists(csv):
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(csv))
|
|
await click(find_button("Statistik exportieren"))
|
|
check(FileAccess.file_exists(csv) and "Gespeichert" in screen().export_label.text, "Statistik exportiert")
|
|
await shot("14_statistik")
|
|
await click(find_button("Zurück"))
|
|
check(screen() is MenuScreen, "zurück im Menü")
|
|
|
|
|
|
func test_werkstatt() -> void:
|
|
await click(find_button("Werkstatt"))
|
|
var scr = screen()
|
|
check(scr is WorkshopScreen, "Werkstatt geöffnet")
|
|
var p: Profile = main.profile
|
|
p.dust = 0
|
|
var in_decks := {}
|
|
for d in p.decks:
|
|
for cid in d.cards:
|
|
in_decks[cid] = true
|
|
var free = scr.grid.views().filter(func(v): return p.collection.get(v.card.id, 0) > 0 and not in_decks.has(v.card.id))
|
|
check(not free.is_empty(), "eine freie Karte zum Zerlegen")
|
|
var card: Cards.Card = free[0].card
|
|
await click(free[0])
|
|
check(scr.selected == card, "Karte gewählt")
|
|
var before: int = p.collection[card.id]
|
|
await click(scr.b_dismantle)
|
|
check(p.collection[card.id] == before - 1 and p.dust == Profile.DUST_DISMANTLE[card.rarity], "zerlegt, Staub gutgeschrieben")
|
|
p.dust = 5000
|
|
scr.search_box.text = "Phönix"
|
|
scr.search_box.text_changed.emit("Phönix")
|
|
await frames(1)
|
|
var phoenix = scr.grid.views().filter(func(v): return v.card.id == "ff_phoenix")[0]
|
|
await click(phoenix)
|
|
await click(scr.b_craft)
|
|
check(p.collection.get("ff_phoenix", 0) == 1 and p.dust == 5000 - Profile.DUST_CRAFT["legendär"], "Phönix hergestellt")
|
|
check(Profile.load_or_new(SAVE).collection.get("ff_phoenix", 0) == 1, "Werkstatt gespeichert")
|
|
await shot("20_werkstatt")
|
|
await click(find_button("Zurück"))
|
|
check(screen() is MenuScreen, "zurück im Menü")
|
|
|
|
|
|
func test_gamepad_menue() -> void:
|
|
check(get_viewport().gui_get_focus_owner() == null, "ohne Gamepad kein Fokus")
|
|
await pad(JOY_BUTTON_DPAD_DOWN)
|
|
var f := get_viewport().gui_get_focus_owner()
|
|
check(f is Button and main.pad_mode, "Gamepad setzt den Fokus auf einen Knopf")
|
|
var down := InputEventJoypadButton.new()
|
|
down.button_index = JOY_BUTTON_DPAD_DOWN
|
|
down.pressed = true
|
|
Input.parse_input_event(down)
|
|
await frames(2)
|
|
var f2 := get_viewport().gui_get_focus_owner()
|
|
check(f2 is Button and f2 != f, "Steuerkreuz wechselt den Knopf")
|
|
var target_text: String = f2.text
|
|
check(InputMap.action_get_events("ui_accept").any(func(e): return e is InputEventJoypadButton), "A ist auf ui_accept gemappt")
|
|
var accept := InputEventJoypadButton.new()
|
|
accept.button_index = JOY_BUTTON_A
|
|
accept.pressed = true
|
|
get_viewport().push_input(accept)
|
|
await frames(1)
|
|
var release := InputEventJoypadButton.new()
|
|
release.button_index = JOY_BUTTON_A
|
|
release.pressed = false
|
|
get_viewport().push_input(release)
|
|
await frames(3)
|
|
check(not (screen() is MenuScreen) or target_text == "Beenden", "A öffnet den fokussierten Bildschirm (%s)" % target_text)
|
|
await hover(main)
|
|
check(not main.pad_mode and get_viewport().gui_get_focus_owner() == null, "Maus nimmt den Fokus wieder")
|
|
|
|
|
|
func test_anleitung2() -> void:
|
|
check(main.profile.tutorial_done and not main.profile.tutorial2_done, "Teil 1 erledigt, Teil 2 offen")
|
|
check(find_button("Anleitung 2: Fallen") != null, "Menü bietet Teil 2 an")
|
|
await click(find_button("Anleitung 2: Fallen"))
|
|
var scr = screen()
|
|
check(scr is BattleScreen and scr.tutorial and scr.tutorial_part == 2, "Anleitung 2 gestartet")
|
|
scr.ai_delay = 0.0
|
|
var g: Game = scr.game
|
|
check(g.opponents[0].name == "Mara" and g.human.hand.any(func(c): return c.id == "w_falle") and g.human.hand.any(func(c): return c.id == "w_reiter"), "Mara, Frostfalle und Wellenreiter auf der Hand")
|
|
await frames(2)
|
|
check(scr.mulligan_box.visible and scr.tutorial_step == 0, "Schritt 1: Mulligan-Maske")
|
|
await click(scr.b_keep)
|
|
check(scr.tutorial_step == 1 and "Frostfalle" in scr.tutorial_text.text, "Schritt 2: Falle legen")
|
|
await shot("29_anleitung2")
|
|
# Zug 1 hat nur 1 Energie: Zug beenden, dann Falle legen
|
|
await key(KEY_SPACE)
|
|
await wait_for_human(scr)
|
|
check(scr.highlight_layer.get_child_count() >= 1, "Falle hervorgehoben")
|
|
var idx: int = g.human.hand.map(func(c): return c.id).find("w_falle")
|
|
check(idx >= 0 and idx < 9, "Falle auf der Hand")
|
|
await key(KEY_1 + idx)
|
|
check(g.human.traps.size() == 1 and scr.tutorial_step == 2, "Falle gelegt, Schritt 3")
|
|
# Mara läuft in die Falle: zwei Züge abwarten
|
|
for i in 2:
|
|
await clear_mulligan(scr)
|
|
if g.current() == g.human and g.winner == "":
|
|
await key(KEY_SPACE)
|
|
await wait_for_human(scr)
|
|
if scr.tutorial_step >= 3:
|
|
break
|
|
check(scr.tutorial_step >= 3 and g.log.any(func(l): return l.begins_with("Falle von Du")), "Mara löst die Frostfalle aus, Schritt 4")
|
|
await give_up()
|
|
check(main.profile.tutorial2_done and find_button("Anleitung") != null, "Teil 2 erledigt")
|
|
|
|
|
|
func test_profil_zuruecksetzen() -> void:
|
|
await click(find_button("Einstellungen"))
|
|
await click(find_button("Profil zurücksetzen"))
|
|
var scr = screen()
|
|
check(scr.confirm.visible, "Rückfrage")
|
|
await click(find_button("Abbrechen"))
|
|
check(not scr.confirm.visible, "abgebrochen")
|
|
await click(find_button("Profil zurücksetzen"))
|
|
await click(find_button("Ja, zurücksetzen"))
|
|
check(screen() is MenuScreen and main.profile.coins == Profile.START_COINS and not main.profile.tutorial_done, "Profil zurückgesetzt")
|
|
check(Profile.load_or_new(SAVE).coins == Profile.START_COINS, "zurückgesetzt gespeichert")
|
|
|
|
|
|
func test_sprache() -> void:
|
|
await click(find_button("Einstellungen"))
|
|
var scr = screen()
|
|
scr.language.select(1)
|
|
scr.language.item_selected.emit(1)
|
|
await frames(2)
|
|
check(TranslationServer.get_locale().begins_with("en") and main.profile.settings.language == "en", "Sprache auf Englisch")
|
|
check(TranslationServer.translate("Zurück") == "Back" and TranslationServer.translate("Einzelspieler") == "Single player", "Übersetzung geladen")
|
|
check(TranslationServer.translate("Zug %d · Du bist dran") == "Turn %d · Your turn" and TranslationServer.translate("Nicht genug Energie") == "Not enough energy", "dynamische Texte übersetzt")
|
|
check(find_button("Back") != null, "Knöpfe übersetzt")
|
|
await shot("26_englisch")
|
|
await click(find_button("Back"))
|
|
check(find_button("Single player") != null and find_button("Settings") != null, "Menü auf Englisch")
|
|
check(screen().coins_label.text.begins_with("Coins:"), "zusammengesetzte Texte übersetzt")
|
|
await click(find_button("Settings"))
|
|
var scr2 = screen()
|
|
scr2.language.select(0)
|
|
scr2.language.item_selected.emit(0)
|
|
await frames(2)
|
|
check(find_button("Zurück") != null, "zurück auf Deutsch")
|
|
await click(find_button("Zurück"))
|
|
check(screen() is MenuScreen, "zurück im Menü")
|
|
|
|
|
|
func test_anleitung() -> void:
|
|
check(not main.profile.tutorial_done, "Anleitung noch offen")
|
|
await click(find_button("Anleitung"))
|
|
var scr = screen()
|
|
check(scr is BattleScreen and scr.tutorial, "Anleitung gestartet")
|
|
scr.ai_delay = 0.0
|
|
var g: Game = scr.game
|
|
check(g.players[0] == g.human and g.opponents[0].name == "Fenn" and g.opponents[0].perks.is_empty(), "Fenn ohne Merkmal, Mensch beginnt")
|
|
await frames(2)
|
|
check(scr.mulligan_box.visible, "Mulligan-Maske im ersten Zug")
|
|
var views = scr.mulligan_layer.get_children()
|
|
await click(views[0])
|
|
check(scr.mulligan_selected == [0], "Karte zum Tausch gewählt")
|
|
await shot("22_anleitung_mulligan")
|
|
await click(scr.b_swap)
|
|
check(not scr.mulligan_box.visible and g.human.mulligan_done, "getauscht")
|
|
check(g.log.any(func(l): return "tauscht 1 Karte" in l), "Tausch im Verlauf")
|
|
check(scr.tutorial_step == 0 and "Energie" in scr.tutorial_text.text, "Schritt 1 sichtbar")
|
|
var idx := -1
|
|
for i in g.human.hand.size():
|
|
if g.human.hand[i].is_creature() and g.human.hand[i].cost == 1:
|
|
idx = i
|
|
break
|
|
check(idx < 0 or scr.highlight_layer.get_child_count() >= 1, "spielbare Wesen hervorgehoben")
|
|
if idx >= 0:
|
|
var played_id: String = g.human.hand[idx].id
|
|
await key(KEY_1 + idx)
|
|
check(g.human.board.size() == 1, "Wesen per Taste gespielt")
|
|
check(scr.tutorial_step == 1, "Schritt 2 nach dem Ausspielen")
|
|
check(scr.highlight_layer.get_child_count() == 1 and scr.highlight_layer.get_child(0).get_rect().intersects(scr.b_end.get_rect()), "Zug-beenden-Knopf hervorgehoben")
|
|
# Rückgängig: Wesen zurück auf die Hand
|
|
check(scr.b_undo.visible, "Rückgängig angeboten")
|
|
var energy: int = g.human.energy
|
|
await click(scr.b_undo)
|
|
g = scr.game
|
|
check(g.human.board.is_empty() and g.human.hand.any(func(c): return c.id == played_id) and g.human.energy == energy + 1, "Rückgängig stellt Hand und Energie her")
|
|
check(not scr.b_undo.visible and g.log.back() == "Rückgängig.", "Rückgängig verbraucht")
|
|
await key(KEY_1 + idx)
|
|
check(g.human.board.size() == 1, "erneut gespielt")
|
|
await shot("22_anleitung")
|
|
# Gamepad: Zeiger bewegen, Karte spielen
|
|
await pad(JOY_BUTTON_DPAD_RIGHT)
|
|
check(scr.gp_zone == "hand" and scr.gp_index == 1 and scr.cursor_layer.get_child_count() == 1, "Gamepad-Zeiger auf zweiter Handkarte")
|
|
var pad_idx := -1
|
|
for i in g.human.hand.size():
|
|
if g.human.hand[i].is_creature() and g.can_play(g.human, g.human.hand[i])[0]:
|
|
pad_idx = i
|
|
break
|
|
if pad_idx >= 0:
|
|
while scr.gp_index != pad_idx:
|
|
await pad(JOY_BUTTON_DPAD_RIGHT)
|
|
var board_before: int = g.human.board.size()
|
|
await pad(JOY_BUTTON_A)
|
|
check(g.human.board.size() == board_before + 1, "Gamepad A spielt das Wesen")
|
|
scr.ai_delay = 0.75
|
|
await key(KEY_SPACE)
|
|
check(g.current() != g.human or g.turn >= 2, "Zug per Leertaste beendet")
|
|
await frames(2)
|
|
check(scr.b_skip.visible and not scr.b_end.visible, "Überspringen-Knopf während des Gegnerzugs")
|
|
await click(scr.b_skip)
|
|
var w := 0
|
|
while g.current() != g.human and g.winner == "" and w < 120:
|
|
await frames(1)
|
|
w += 1
|
|
check(g.current() == g.human and w < 60, "Gegnerzug übersprungen (%d Bilder)" % w)
|
|
scr.ai_delay = 0.0
|
|
await clear_mulligan(scr)
|
|
check(scr.tutorial_step >= 2 or idx < 0, "Schritt 3 im zweiten Zug")
|
|
var step_before: int = scr.tutorial_step
|
|
await click(scr.b_tut_next)
|
|
check(scr.tutorial_step >= step_before + 1, "Weiter-Knopf (Schritt %d)" % step_before)
|
|
await key(KEY_ESCAPE)
|
|
check(scr.confirm.visible, "Esc öffnet Aufgeben")
|
|
await key(KEY_ESCAPE)
|
|
check(not scr.confirm.visible, "Esc schließt den Dialog")
|
|
await give_up()
|
|
check(main.profile.tutorial_done, "Anleitung als erledigt gespeichert")
|
|
|
|
|
|
func test_netzwerk() -> void:
|
|
await click(find_button("Netzwerkspiel"))
|
|
var scr = screen()
|
|
check(scr is LobbyScreen, "Lobby geöffnet")
|
|
await click(find_button("Spiel eröffnen"))
|
|
check(main.net.is_host and main.net.connected, "Spiel eröffnet")
|
|
if FileAccess.file_exists("user://bot_quit"):
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path("user://bot_quit"))
|
|
var args := ["--headless", "--path", ProjectSettings.globalize_path("res://"), "tests/net_bot.tscn", "--", "--ip=127.0.0.1", "--name=Bot"]
|
|
var pid := OS.create_process(OS.get_executable_path(), args)
|
|
check(pid > 0, "Bot-Prozess gestartet")
|
|
var wait := 0
|
|
while main.net.names.size() < 2 and wait < 600:
|
|
await frames(1)
|
|
wait += 1
|
|
if main.net.names.size() < 2:
|
|
print("HINWEIS: Bot kam nicht, zweiter Versuch")
|
|
OS.kill(pid)
|
|
pid = OS.create_process(OS.get_executable_path(), args)
|
|
while main.net.names.size() < 2 and wait < 1500:
|
|
await frames(1)
|
|
wait += 1
|
|
check(main.net.names.size() == 2, "Bot ist beigetreten (Pfad %s)" % main.net.get_path())
|
|
await shot("23_lobby")
|
|
await click(find_button("Start"))
|
|
var b = screen()
|
|
check(b is BattleScreen and b.is_online() and not b.is_client(), "Netzwerkkampf als Host")
|
|
b.ai_delay = 0.0
|
|
var rounds := 0
|
|
while b.game != null and b.game.winner == "" and rounds < 2:
|
|
if b.game.current() == b.perspective:
|
|
await clear_mulligan(b)
|
|
if b.game.current() == b.perspective:
|
|
await click(b.b_end)
|
|
var w2 := 0
|
|
while b.game.current() != b.perspective and b.game.winner == "" and w2 < 900:
|
|
await frames(1)
|
|
w2 += 1
|
|
rounds += 1
|
|
if b.game.winner != "":
|
|
print("DEBUG Netz: Sieger=", b.game.winner, " Verlauf=", b.game.log.slice(maxi(0, b.game.log.size() - 12)))
|
|
check(b.game.turn >= 2 and b.game.winner == "", "Runden gespielt, Partie läuft (Zug %d)" % b.game.turn)
|
|
check(b.game.log.any(func(l): return l.begins_with("Bot spielt") or l.begins_with("Bot behält") or l.begins_with("Bot tauscht")), "Bot hat gehandelt")
|
|
await shot("24_netzwerk_kampf")
|
|
# Bot verlässt geordnet: Platz bleibt frei, Züge werden übersprungen
|
|
var quit_file := "user://bot_quit"
|
|
var f := FileAccess.open(quit_file, FileAccess.WRITE)
|
|
f.store_string("x")
|
|
f.close()
|
|
var w3 := 0
|
|
while main.net.waiting.is_empty() and w3 < 600:
|
|
await frames(1)
|
|
w3 += 1
|
|
check(main.net.waiting.has("Bot") and b.game.log.any(func(l): return "Verbindung verloren" in l), "Platz wird freigehalten")
|
|
var turn_before: int = b.game.turn
|
|
for i in 2:
|
|
await clear_mulligan(b)
|
|
if b.game.current() == b.perspective and b.game.winner == "":
|
|
await click(b.b_end)
|
|
var w4 := 0
|
|
while b.game.current() != b.perspective and b.game.winner == "" and w4 < 300:
|
|
await frames(1)
|
|
w4 += 1
|
|
check(b.game.turn >= turn_before + 1 and b.game.log.any(func(l): return "übersprungen" in l), "Züge des fehlenden Spielers werden übersprungen")
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(quit_file))
|
|
await frames(5)
|
|
var pid2 := OS.create_process(OS.get_executable_path(), args)
|
|
var w5 := 0
|
|
while not main.net.waiting.is_empty() and w5 < 900:
|
|
await frames(1)
|
|
w5 += 1
|
|
check(main.net.waiting.is_empty() and main.net.seats.size() == 2 and b.game.log.any(func(l): return l == "Bot ist zurück."), "Bot wieder verbunden, Platz zurück")
|
|
var turn2: int = b.game.turn
|
|
for i in 2:
|
|
await clear_mulligan(b)
|
|
if b.game.current() == b.perspective and b.game.winner == "":
|
|
await click(b.b_end)
|
|
var w6 := 0
|
|
while b.game.current() != b.perspective and b.game.winner == "" and w6 < 900:
|
|
await frames(1)
|
|
w6 += 1
|
|
check(b.game.turn >= turn2 + 1, "Partie läuft nach der Rückkehr weiter")
|
|
OS.kill(pid2)
|
|
await leave_battle()
|
|
check(screen() is MenuScreen and not main.net.connected, "Netzwerk getrennt, zurück im Menü")
|
|
|
|
|
|
func _bot_args(extra: Array) -> Array:
|
|
return ["--headless", "--path", ProjectSettings.globalize_path("res://"), "tests/net_bot.tscn", "--"] + extra
|
|
|
|
|
|
func _bot_quit(on: bool) -> void:
|
|
var path := "user://bot_quit"
|
|
if on:
|
|
var f := FileAccess.open(path, FileAccess.WRITE)
|
|
f.store_string("x")
|
|
f.close()
|
|
elif FileAccess.file_exists(path):
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(path))
|
|
|
|
|
|
## Verbindet sich mit dem Bot-Host (mehrere Versuche, bis er lauscht).
|
|
func _join_bot_host(watch: bool) -> void:
|
|
await click(find_button("Netzwerkspiel"))
|
|
var lobby = screen()
|
|
lobby.ip_box.text = "127.0.0.1"
|
|
for attempt in 8:
|
|
await click(find_button("Zuschauen" if watch else "Beitreten"))
|
|
var w := 0
|
|
while not main.net.connected and w < 180:
|
|
await frames(1)
|
|
w += 1
|
|
if main.net.connected:
|
|
return
|
|
main.net.leave()
|
|
await frames(30)
|
|
|
|
|
|
## Der Host (ein Bot) verschwindet: der einzige Mitspieler übernimmt und spielt zu Ende.
|
|
func test_host_wechsel() -> void:
|
|
_bot_quit(false)
|
|
var pid := OS.create_process(OS.get_executable_path(), _bot_args(["--host", "--name=BotHost"]))
|
|
check(pid > 0, "Bot-Host gestartet")
|
|
await frames(30)
|
|
await _join_bot_host(false)
|
|
var w := 0
|
|
while not (screen() is BattleScreen) and w < 900:
|
|
await frames(1)
|
|
w += 1
|
|
var b = screen()
|
|
check(b is BattleScreen and b.is_client(), "als Mitspieler beim Bot-Host im Kampf")
|
|
w = 0
|
|
while (b.game == null or main.net.backup.is_empty()) and w < 600:
|
|
await frames(1)
|
|
w += 1
|
|
check(b.game != null and main.net.i_am_successor and not main.net.backup.is_empty(), "Nachfolger kennt den vollen Spielstand")
|
|
main.net.rejoin_seconds = 3.0
|
|
_bot_quit(true)
|
|
w = 0
|
|
while not main.net.is_host and w < 900:
|
|
await frames(1)
|
|
w += 1
|
|
check(main.net.is_host and b.game == main.net.game and screen() == b and b.game.log.any(func(l): return "übernimmt als Host" in l),
|
|
"Host-Wechsel: Mitspieler führt das Spiel weiter")
|
|
check(main.net.waiting.has("BotHost"), "Platz des alten Hosts bleibt zunächst frei")
|
|
await shot("34_host_wechsel")
|
|
# Der alte Host kehrt nicht zurück: ein Zug wird übersprungen, nach der Frist scheidet er aus
|
|
b.ai_delay = 0.0
|
|
await clear_mulligan(b)
|
|
if b.game.current() == b.perspective:
|
|
await click(b.b_end)
|
|
w = 0
|
|
while b.game.winner == "" and w < 900:
|
|
await frames(1)
|
|
w += 1
|
|
check(b.game.log.any(func(l): return "übersprungen" in l), "Zug des fehlenden Hosts übersprungen")
|
|
check(b.game.winner != "" and b.game.winner_player == b.perspective and b.game.log.any(func(l): return "kehrt nicht zurück" in l),
|
|
"nach der Frist scheidet der alte Host aus, Partie gewonnen (Sieger '%s', Zug %d)" % [b.game.winner, b.game.turn])
|
|
await leave_battle()
|
|
_bot_quit(false)
|
|
check(screen() is MenuScreen and not main.net.connected, "nach dem Host-Wechsel zurück im Menü")
|
|
|
|
|
|
## Zuschauer: sieht die Partie zweier Bots ohne Hände und ohne eigene Züge.
|
|
func test_zuschauer() -> void:
|
|
_bot_quit(false)
|
|
var pid_h := OS.create_process(OS.get_executable_path(), _bot_args(["--host", "--name=BotHost"]))
|
|
await frames(30)
|
|
var pid_c := OS.create_process(OS.get_executable_path(), _bot_args(["--ip=127.0.0.1", "--name=Bot"]))
|
|
check(pid_h > 0 and pid_c > 0, "zwei Bots gestartet")
|
|
await _join_bot_host(true)
|
|
var w := 0
|
|
while not (screen() is BattleScreen) and w < 1200:
|
|
await frames(1)
|
|
w += 1
|
|
var b = screen()
|
|
check(b is BattleScreen and b.spectating(), "als Zuschauer im Kampf")
|
|
w = 0
|
|
while (b.game == null or b.game.turn < 2) and w < 900:
|
|
await frames(1)
|
|
w += 1
|
|
check(b.game != null and b.game.turn >= 2 and b.hand_views.is_empty() and not b.mulligan_box.visible and not b.b_end.visible,
|
|
"Zuschauer sieht die Partie ohne Hände und ohne Züge (Zug %d)" % (b.game.turn if b.game != null else 0))
|
|
await shot("35_zuschauer")
|
|
check(not b.b_end.visible and not b.b_undo.visible, "Zuschauer hat keine Zugknöpfe")
|
|
if screen() is BattleScreen: # die Bots spielen schnell, die Partie kann schon vorbei sein
|
|
await leave_battle()
|
|
else:
|
|
var w2 := 0
|
|
while not (screen() is MenuScreen) and w2 < 300:
|
|
await frames(1)
|
|
w2 += 1
|
|
check(screen() is MenuScreen and not main.net.connected, "Zuschauer zurück im Menü")
|
|
_bot_quit(true)
|
|
await frames(60)
|
|
_bot_quit(false)
|
|
|
|
|
|
func test_kampagne() -> void:
|
|
await click(find_button("Kampagne"))
|
|
var scr = screen()
|
|
check(scr is CampaignScreen, "Kampagne geöffnet")
|
|
await shot("15_kampagne")
|
|
check(find_button("Gesperrt") != null and find_button("Kämpfen") != null, "Stufen gesperrt und offen")
|
|
check(find_button("Kapitel 2").disabled and scr.perk_box == null, "Kapitel 2 und Merkmal noch gesperrt")
|
|
await click(find_button("Kämpfen"))
|
|
var battle = screen()
|
|
check(battle is BattleScreen and battle.stage == 0, "Kampagnenkampf gestartet")
|
|
check(battle.game.opponents.size() == 1 and battle.game.opponents[0].name == "Fenn", "Fenn ist der Gegner")
|
|
check(battle.game.opponents[0].perks == ["feuer_angriff"] and battle.game.log.any(func(l): return l.begins_with("Fenn: Feuerwesen")), "Boss-Merkmal aktiv")
|
|
await shot("16_kampagne_kampf")
|
|
await give_up()
|
|
# Kapitel 1 als abgeschlossen setzen: Kapitel 2 und Merkmalwahl
|
|
main.profile.campaign_stage = Campaign.STAGES.size()
|
|
await click(find_button("Kampagne"))
|
|
var scr2 = screen()
|
|
check(scr2.chapter == 2 and scr2.perk_box != null, "Kapitel 2 offen, Merkmal wählbar")
|
|
scr2.perk_box.select(1)
|
|
scr2.perk_box.item_selected.emit(1)
|
|
check(main.profile.perk == Game.PERKS.keys()[0], "Merkmal gewählt")
|
|
await shot("27_kampagne_kapitel2")
|
|
await click(find_button("Kämpfen"))
|
|
var b2 = screen()
|
|
check(b2 is BattleScreen and b2.stage == 10 and b2.game.opponents[0].perks.size() == 2, "Kapitel-2-Boss mit zwei Merkmalen")
|
|
check(b2.game.human.perks == [main.profile.perk], "eigenes Merkmal im Kampf")
|
|
await give_up()
|
|
main.profile.campaign_stage = 0
|
|
main.profile.perk = ""
|
|
main.save()
|
|
|
|
|
|
func test_kampf(n_opp: int, shot_turn: int) -> void:
|
|
await start_battle(n_opp)
|
|
var scr = screen()
|
|
check(scr is BattleScreen, "Kampfbildschirm")
|
|
scr.ai_delay = 0.0
|
|
var g: Game = scr.game
|
|
check(g.opponents.size() == n_opp and g.log[0].begins_with("Zugreihenfolge"), "Spiel gestartet, Reihenfolge ausgelost")
|
|
await wait_for_human(scr)
|
|
check(g.current() == g.human and g.human.mulligan_done, "Spieler ist dran, Mulligan erledigt")
|
|
check(scr.hand_views.size() == g.human.hand.size(), "Handkarten sichtbar")
|
|
await shot("07_kampf_start")
|
|
var coins: int = main.profile.coins
|
|
var guard := 0
|
|
while g.winner == "" and guard < 60:
|
|
guard += 1
|
|
var turn_before := g.turn
|
|
await human_turn(scr)
|
|
if g.winner != "":
|
|
break
|
|
check(g.current() != g.human or g.turn > turn_before, "Zug beendet")
|
|
var wait := 0
|
|
while g.current() != g.human and g.winner == "" and wait < 600:
|
|
await frames(1)
|
|
wait += 1
|
|
if guard == shot_turn:
|
|
await shot("08_kampf_zug%d" % (shot_turn + 1))
|
|
check(g.winner != "", "Spiel beendet")
|
|
await frames(3)
|
|
await shot("09_kampf_ende")
|
|
check(scr.reward > 0 and main.profile.coins >= coins + scr.reward, "Belohnung gutgeschrieben")
|
|
check(Profile.load_or_new(SAVE).coins == main.profile.coins, "Belohnung gespeichert")
|
|
await click(find_button("Zurück zum Menü"))
|
|
check(screen() is MenuScreen, "zurück im Menü")
|
|
|
|
|
|
func test_kampf_abbrechen() -> void:
|
|
await start_battle(5)
|
|
var scr = screen()
|
|
scr.ai_delay = 0.0
|
|
var g: Game = scr.game
|
|
await wait_for_human(scr)
|
|
check(g.opponents.size() == 5 and g.human.max_energy == 1, "5 Gegner")
|
|
# Falle legen und Kombo-Hinweis prüfen
|
|
g.human.hand.append(Cards.by_id("f_falle"))
|
|
g.human.energy = 10
|
|
var wolf := Game.Creature.new(Cards.by_id("f_wolf"), g.human, 9000)
|
|
g.human.board.append(wolf)
|
|
g.human.hand.append(Cards.by_id("w_reiter"))
|
|
scr.refresh()
|
|
var trap_view = scr.hand_views.filter(func(v): return v.card.id == "f_falle")[0]
|
|
await click(trap_view)
|
|
check(g.human.traps.size() == 1 and scr.trap_views.size() == 1, "Falle gelegt und sichtbar")
|
|
var reiter_view = scr.hand_views.filter(func(v): return v.card.id == "w_reiter")[0]
|
|
await hover(scr.log_box) # erst weg von der Hand, damit das Betreten sicher ausgelöst wird
|
|
await hover(reiter_view)
|
|
var hint_boxes = scr.preview_holder.get_children().filter(func(c): return c is RichTextLabel)
|
|
if hint_boxes.size() != 1:
|
|
print("DEBUG Hinweis: hints=", scr.combo_hints(Cards.by_id("w_reiter")), " kinder=", scr.preview_holder.get_children().map(func(c): return c.get_class()),
|
|
" brett=", g.human.board.map(func(c): return c.name), " hovered=", get_viewport().gui_get_hovered_control(), " reiter_pos=", reiter_view.get_global_rect())
|
|
check(hint_boxes.size() == 1 and "Feldkombo Dampf" in hint_boxes[0].text, "Kombo-Hinweis in der Vorschau")
|
|
await shot("21_kampf_falle_hinweis")
|
|
var spells: Array = scr.hand_views.filter(func(v): return v.card.target_type() != "" and g.can_play(g.human, v.card)[0])
|
|
if not spells.is_empty():
|
|
var card: Cards.Card = spells[0].card
|
|
await click(spells[0])
|
|
check(scr.pending == card, "Ziel wird erwartet")
|
|
await right_click()
|
|
check(scr.pending == null and card in g.human.hand, "Rechtsklick bricht ab")
|
|
await hover(scr.hand_views[0])
|
|
if scr.preview_holder.get_child_count() == 0:
|
|
print("DEBUG Hover: mulligan=", scr.mulligan_box.visible, " overlay=", scr.any_overlay(), " hand=", scr.hand_views.size(),
|
|
" dran=", g.current().name, " Sieger=", g.winner, " hovered=", get_viewport().gui_get_hovered_control())
|
|
check(scr.preview_holder.get_child_count() > 0, "Vorschau bei Hover")
|
|
await click(find_button("Lupe"))
|
|
check(scr.zoom_player == scr.others()[0], "Lupe öffnet die erste Spalte")
|
|
await shot("12_lupe")
|
|
await click(find_button("Schließen"))
|
|
check(scr.zoom_player == null, "Lupe geschlossen")
|
|
# Runden laufen lassen, damit die Gegner ihre Züge machen
|
|
for round in 4:
|
|
await click(scr.b_end)
|
|
var wait := 0
|
|
while g.current() != g.human and g.winner == "" and wait < 600:
|
|
await frames(1)
|
|
wait += 1
|
|
var ai_attacked: bool = g.log.any(func(l): return l.begins_with("Gegner") and " spielt " in l) \
|
|
and g.log.any(func(l): return " greift " in l)
|
|
check(ai_attacked, "Gegner spielen Karten und greifen an")
|
|
check(scr.tiles.size() == g.players.reduce(func(acc, p): return acc + p.board.size(), 0), "eine Kachel je Wesen")
|
|
await shot("10_kampf_fuenf")
|