Files
Ratdoku/scripts/Home.gd
T
Ratdoku Builder b4fd03a8a4 fix(daily): full 30-room rotation and reset-safe profile
Use a fixed shuffled order so every room appears once before repeats. Keep Profile Confirm/Cancel visible, clear locked avatar/frame on reset, and make Home's avatar caption dynamic.
2026-12-03 15:19:30 -06:00

207 lines
6.8 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends Control
signal play_pressed
signal guest_book_pressed
signal settings_pressed
signal rules_pressed
signal daily_pressed
signal profile_pressed
signal streak_pressed
var progress_pill: Button
var primary: Button
var hint_label: Label
var mascot_caption: Label
var daily_button: Button
var streak_button: Button
var avatar_holder: CenterContainer
var avatar_frame_id := ""
var avatar_portrait_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.size_flags_horizontal = Control.SIZE_EXPAND_FILL
daily_button.add_theme_font_size_override("font_size", 13)
daily_button.pressed.connect(func() -> void: daily_pressed.emit())
streak_button = UI.button("Streak ›", false, 40)
streak_button.custom_minimum_size = Vector2(96, 40)
streak_button.add_theme_font_size_override("font_size", 12)
streak_button.pressed.connect(func() -> void: streak_pressed.emit())
var daily_row := HBoxContainer.new()
daily_row.add_theme_constant_override("separation", 6)
daily_row.add_child(daily_button)
daily_row.add_child(streak_button)
column.add_child(daily_row)
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)
mascot_caption = UI.label("Crumb, innkeeper", 12, Palette.MUTED)
column.add_child(mascot_caption)
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()
var avatar_id := SaveGame.selected_avatar()
if avatar_id == "crumb":
mascot_caption.text = "Crumb, innkeeper"
else:
var guest := Guests.by_id(avatar_id)
mascot_caption.text = "%s · %s" % [
str(guest.get("name", avatar_id)),
str(guest.get("role", "Guest"))
]
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(Avatars.portrait_path(SaveGame.selected_avatar()))
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()
avatar_portrait_id = SaveGame.selected_avatar()
func _refresh_avatar() -> void:
if (
avatar_frame_id == SaveGame.selected_frame()
and avatar_portrait_id == SaveGame.selected_avatar()
):
return
for child in avatar_holder.get_children():
child.queue_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()