Files
Ratdoku/scripts/Home.gd
T
Ratdoku Builder 7e6a338240 feat(daily): add daily rooms, streaks, and profile frames
A deterministic daily room rotates through the 30-level pool and tracks current and best streaks in save version 3. Daily wins are separate from campaign progress. The new Profile screen shows framed Crumb, stats, and selectable frames unlocked by rooms or best streak.
2026-12-02 22:29:32 -06:00

181 lines
5.9 KiB
GDScript

extends Control
signal play_pressed
signal guest_book_pressed
signal settings_pressed
signal rules_pressed
signal daily_pressed
signal profile_pressed
var progress_pill: Button
var primary: Button
var hint_label: Label
var daily_button: Button
var avatar_holder: CenterContainer
var avatar_frame_id := ""
func _ready() -> void:
var margin := MarginContainer.new()
margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
margin.add_theme_constant_override("margin_left", UI.MARGIN)
margin.add_theme_constant_override("margin_right", UI.MARGIN)
margin.add_theme_constant_override("margin_top", UI.safe_top())
margin.add_theme_constant_override("margin_bottom", UI.safe_bottom())
add_child(margin)
var column := VBoxContainer.new()
column.add_theme_constant_override("separation", 6)
margin.add_child(column)
var hub := HBoxContainer.new()
hub.add_theme_constant_override("separation", 0)
column.add_child(hub)
var left := CenterContainer.new()
left.custom_minimum_size = Vector2(56, 56)
avatar_holder = left
hub.add_child(left)
_build_avatar()
var center := CenterContainer.new()
center.size_flags_horizontal = Control.SIZE_EXPAND_FILL
hub.add_child(center)
progress_pill = UI.button("5 / 25 guests", false, 38)
progress_pill.custom_minimum_size = Vector2(130, 38)
progress_pill.add_theme_font_size_override("font_size", 13)
progress_pill.size_flags_vertical = Control.SIZE_SHRINK_CENTER
progress_pill.pressed.connect(func() -> void: guest_book_pressed.emit())
center.add_child(progress_pill)
var settings := UI.round_button("res://assets/icons/settings.svg", 48)
settings.tooltip_text = "Settings"
settings.pressed.connect(func() -> void: settings_pressed.emit())
var right := CenterContainer.new()
right.custom_minimum_size = Vector2(52, 52)
right.add_child(settings)
hub.add_child(right)
column.add_child(UI.spacer(4))
column.add_child(UI.heading("Ratdoku", 46))
column.add_child(UI.label("A cozy rat hotel puzzle", 15, Palette.MUTED))
daily_button = UI.button("Daily room", false, 40)
daily_button.custom_minimum_size = Vector2(0, 40)
daily_button.add_theme_font_size_override("font_size", 13)
daily_button.pressed.connect(func() -> void: daily_pressed.emit())
column.add_child(daily_button)
var top_space := Control.new()
top_space.size_flags_vertical = Control.SIZE_EXPAND_FILL
top_space.mouse_filter = Control.MOUSE_FILTER_IGNORE
column.add_child(top_space)
var card := UI.panel(Palette.CREAM, 26, 12)
card.custom_minimum_size = Vector2(160, 160)
card.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
var mascot := _make_mascot()
mascot.custom_minimum_size = Vector2(138, 138)
card.add_child(mascot)
column.add_child(card)
column.add_child(UI.label("Crumb, innkeeper", 12, Palette.MUTED))
hint_label = UI.label(UI.place_hint(), 11, Palette.MUTED)
column.add_child(hint_label)
var bottom_space := Control.new()
bottom_space.size_flags_vertical = Control.SIZE_EXPAND_FILL
bottom_space.mouse_filter = Control.MOUSE_FILTER_IGNORE
column.add_child(bottom_space)
primary = UI.button("Check in", true, 54)
primary.custom_minimum_size = Vector2(300, 54)
primary.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
primary.pressed.connect(func() -> void: play_pressed.emit())
column.add_child(primary)
var secondary := HBoxContainer.new()
secondary.alignment = BoxContainer.ALIGNMENT_CENTER
secondary.add_theme_constant_override("separation", 8)
column.add_child(secondary)
var book := UI.button("Guest Book", false, 46)
book.custom_minimum_size = Vector2(146, 46)
book.add_theme_font_size_override("font_size", 15)
book.pressed.connect(func() -> void: guest_book_pressed.emit())
secondary.add_child(book)
var rules := UI.button("House Rules", false, 46)
rules.custom_minimum_size = Vector2(146, 46)
rules.add_theme_font_size_override("font_size", 15)
rules.pressed.connect(func() -> void: rules_pressed.emit())
secondary.add_child(rules)
column.add_child(UI.label("No ads. No lives. Just rats.", 10, Palette.MUTED))
column.add_child(UI.label(Version.BUILD_LABEL, 9, Palette.MUTED))
SaveGame.progress_changed.connect(refresh)
SaveGame.settings_changed.connect(refresh)
refresh()
func refresh() -> void:
hint_label.text = UI.place_hint()
daily_button.text = _daily_text()
_refresh_avatar()
var guests := Guests.all()
var unlocked := SaveGame.unlocked_count(guests)
progress_pill.text = "%d / %d guests" % [unlocked, guests.size()]
var last := int(SaveGame.data.get("last_room", 0))
if last <= 0:
primary.text = "Check in"
elif last >= 30:
primary.text = "Replay Room 30"
else:
primary.text = "Continue Room %d" % (last + 1)
func _daily_text() -> String:
var streak := SaveGame.daily_streak()
if SaveGame.daily_completed_today():
return "Daily done · %d-day streak" % streak
if streak > 0:
return "Daily room · %d-day streak" % streak
return "Daily room · start a streak"
func _build_avatar() -> void:
var frame := Frames.frame_panel(SaveGame.selected_frame(), 56)
var avatar := Button.new()
avatar.custom_minimum_size = Vector2(44, 44)
avatar.flat = true
avatar.icon = load("res://art/crumb_head.png")
avatar.expand_icon = true
avatar.icon_alignment = HORIZONTAL_ALIGNMENT_CENTER
avatar.alignment = HORIZONTAL_ALIGNMENT_CENTER
avatar.tooltip_text = "Profile"
avatar.pressed.connect(func() -> void: profile_pressed.emit())
frame.add_child(avatar)
avatar_holder.add_child(frame)
avatar_frame_id = SaveGame.selected_frame()
func _refresh_avatar() -> void:
if avatar_frame_id == SaveGame.selected_frame():
return
for child in avatar_holder.get_children():
child.free()
_build_avatar()
func _make_mascot() -> Control:
if ResourceLoader.exists("res://art/crumb.png"):
var texture_rect := TextureRect.new()
texture_rect.texture = load("res://art/crumb.png")
texture_rect.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
texture_rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
return texture_rect
return RatPortrait.new()