Standard (Inter, Source Sans 3, Lora, Rokkitt), easy to read (Atkinson Hyperlegible, Lexend, Andika, OpenDyslexic) and themed title faces (Cinzel, IM Fell English, Uncial Antiqua, Orbitron, Special Elite). All OFL except Special Elite (Apache 2.0); licence files sit beside the fonts. FontCatalog builds faces, synthesising missing bold/italic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
123 lines
5.2 KiB
GDScript
123 lines
5.2 KiB
GDScript
extends TestBase
|
|
## 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
|
|
|
|
|
|
func _init() -> void:
|
|
if not require_sample():
|
|
return
|
|
ThemeStore.DIR = OS.get_temp_dir().path_join("tt_theme_test_%d/" % OS.get_process_id())
|
|
if not await start_main():
|
|
return
|
|
_test_apply()
|
|
_test_save_delete()
|
|
await _test_dialog()
|
|
_test_fonts()
|
|
_test_own_colours()
|
|
await _test_sparkles()
|
|
finish()
|
|
|
|
|
|
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_fonts() -> void:
|
|
for id: String in FontCatalog.FAMILIES:
|
|
var fam: Dictionary = FontCatalog.FAMILIES[id]
|
|
for k: String in ["regular", "bold", "italic"]:
|
|
if fam.has(k):
|
|
_check(ResourceLoader.exists(FontCatalog.DIR + fam[k]), "%s %s file exists" % [id, k])
|
|
for zoom: bool in [false, true]:
|
|
var f := FontCatalog.face(id, 700, true, zoom)
|
|
_check(f is FontVariation and (f as FontVariation).base_font != null, "%s builds a bold italic face" % id)
|
|
_check(FontCatalog.options("body").size() < FontCatalog.FAMILIES.size(), "title-only fonts aren't offered for text")
|
|
var t := BuiltinThemes.TAROT.duplicate(true)
|
|
t["font_body"] = "lexend"
|
|
t["font_display"] = "cinzel"
|
|
ThemeStore.apply(t)
|
|
_check(Style.BODY_FONT == "lexend" and Style.DISPLAY_FONT == "cinzel", "a theme sets both fonts")
|
|
t["font_body"] = "uncial"
|
|
ThemeStore.apply(t)
|
|
_check(Style.BODY_FONT == FontCatalog.DEFAULT_BODY, "a title-only font falls back for text")
|
|
ThemeStore.apply(BuiltinThemes.TAROT)
|
|
_check(Style.BODY_FONT == "atkinson", "Tarot uses Atkinson for text")
|
|
|
|
|
|
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")
|
|
|