extends SceneTree ## Theme sets: applying built-ins sets Style tokens and fills, saving and ## deleting a user set, and the Theme dialog building its editors. ## Run: godot --headless --path . -s res://tests/test_theme.gd -- --sample var _failures := 0 var main: Main func _init() -> void: if not OS.get_cmdline_user_args().has("--sample"): print("Run with -- --sample so the test can't touch saved data.") quit(2) return ThemeStore.DIR = OS.get_temp_dir().path_join("tt_theme_test_%d/" % OS.get_process_id()) main = load("res://ui/main.tscn").instantiate() root.add_child(main) await _frames(5) _test_apply() _test_save_delete() await _test_dialog() _test_own_colours() await _test_sparkles() print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) quit(1 if _failures else 0) func _test_apply() -> void: _check(ThemeStore.current.get("id") == "tarot", "Tarot is the default set") _check(Style.BG == Color("#2c0744"), "Tarot sets the background colour") _check(Style.fill_texture(Style.BG_FILL) != null, "Tarot's background is a gradient") _check(BoardView.pattern_texture("stars") != null and BoardView.pattern_texture("none") == null, "patterns build") ThemeStore.apply(BuiltinThemes.FELT) _check(Style.BG == Color("#1f4a39"), "Felt falls back to the original colours") _check(Style.PATTERN == "dots", "Felt uses dots") _check(Style.panel_box() is StyleBoxFlat, "a solid panel fill is a flat box") ThemeStore.apply(BuiltinThemes.TAROT) _check(Style.panel_box() is StyleBoxTexture, "a gradient panel fill is a texture box") var cols := ThemeStore.resolved_colors(BuiltinThemes.FELT) _check(cols.size() == ThemeStore.TOKENS.size(), "resolved colours cover every token") func _test_save_delete() -> void: var t := BuiltinThemes.TAROT.duplicate(true) t["name"] = "Night Sky" var id := ThemeStore.save(t) _check(id != "tarot", "saving a built-in makes a new id: " + id) _check(ThemeStore.find(id).get("name") == "Night Sky", "the saved set is found") _check(ThemeStore.all().size() == BuiltinThemes.all().size() + 1, "the saved set is listed") ThemeStore.delete("tarot") _check(ThemeStore.find("tarot").get("builtin", false), "built-ins can't be deleted") ThemeStore.delete(id) _check(ThemeStore.all().size() == BuiltinThemes.all().size(), "the user set is deleted") func _test_dialog() -> void: var d := ThemeDialog.new(main) main.add_child(d) await _frames() _check(d._content.find_children("*", "FillEditor", true, false).size() == 2, "background and panel fill editors") var basic := d._content.find_children("*", "ColorPickerButton", true, false).size() d._more = true d._rebuild() await _frames() var all := d._content.find_children("*", "ColorPickerButton", true, false).size() _check(all > basic, "More colours shows more swatches (%d > %d)" % [all, basic]) var fe := d._content.find_children("*", "FillEditor", true, false)[0] as FillEditor fe._set_kind(1) _check((fe.fill["colors"] as Array).size() >= 2 and d._dirty, "a gradient gets two colours and marks the set changed") d.close() await _frames() func _test_own_colours() -> void: var t := RollTable.new() t.id = "a" t.color = "#2f8a4f" var e := TableEntry.new("e1", "x") e.add_pipe("b") e.pipe_color["b"] = "#c04a86" t.entries.append(e) var back := RollTable.from_dict(t.to_dict()) _check(back.color == "#2f8a4f", "a card's colour survives saving") _check(back.entries[0].pipe_color.get("b") == "#c04a86", "a thread's colour survives saving") back.entries[0].remove_pipe("b") _check(back.entries[0].pipe_color.is_empty(), "deleting a thread drops its colour") var card := main.card_for(main.data.tables[0].id) if card and card.frame: main.data.get_table(card.table.id).color = "#b8382c" card.rebuild() _check(card.frame.material == CardFrame.material_for(Color("#b8382c")), "the frame takes the card's colour") func _test_sparkles() -> void: var card := main.card_for(main.data.tables[0].id) var layer := card.get_parent() var before := layer.find_children("*", "CPUParticles2D", false, false).size() card.sparkle(card.table.entries[0].id) _check(layer.find_children("*", "CPUParticles2D", false, false).size() == before + 1, "a landing result bursts sparkles") var pipes := main.board.pipes pipes.pulse_key = pipes._paths.keys()[0] if not pipes._paths.is_empty() else "" await _frames() _check(pipes._trail != null and pipes._trail.emitting, "the pulse trails sparkles") pipes.pulse_key = "" await _frames() _check(not pipes._trail.emitting, "the trail stops with the pulse") func _frames(n: int = 2) -> void: for i in n: await process_frame func _check(ok: bool, what: String) -> void: if not ok: _failures += 1 print("FAIL ", what)