Files
Ratdoku/scripts/Rulebook.gd
T
Ratdoku Builder f957cd3c4e v0.2.0-alpha: Guest Book and House Rules
Adds the Guest Book, Settings, House Rules, and guest unlocks on the 20-room board. Rats still use the shared Crumb token.
2026-12-02 10:32:45 -06:00

179 lines
6.7 KiB
GDScript
Raw 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 back_pressed
const BoardScene = preload("res://scenes/Board.tscn")
var tutorial_board: Board
var tutorial_status: Label
func _ready() -> void:
var margin := MarginContainer.new()
margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
margin.add_theme_constant_override("margin_left", 24)
margin.add_theme_constant_override("margin_right", 24)
margin.add_theme_constant_override("margin_top", 18)
margin.add_theme_constant_override("margin_bottom", 18)
add_child(margin)
var column := VBoxContainer.new()
column.add_theme_constant_override("separation", 12)
margin.add_child(column)
var top := HBoxContainer.new()
top.add_theme_constant_override("separation", 10)
column.add_child(top)
var back := UI.button("‹", false, 44)
back.custom_minimum_size = Vector2(48, 44)
back.add_theme_font_size_override("font_size", 30)
back.pressed.connect(func() -> void: back_pressed.emit())
top.add_child(back)
var title := UI.label("House Rules", 30)
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
top.add_child(title)
var scroll := ScrollContainer.new()
scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
column.add_child(scroll)
var content := VBoxContainer.new()
content.size_flags_horizontal = Control.SIZE_EXPAND_FILL
content.add_theme_constant_override("separation", 10)
scroll.add_child(content)
content.add_child(_heading("Welcome to the Rat Hotel"))
content.add_child(_body("Crumb runs a small hotel for travelling rats. Every guest wants a room of their own — and a little space from the neighbours."))
content.add_child(_heading("The four house rules"))
content.add_child(_rule_row("One guest per room", "Each coloured room holds exactly one rat.", "region"))
content.add_child(_rule_row("One guest per floor", "Each row holds exactly one rat.", "row"))
content.add_child(_rule_row("One guest per corridor", "Each column holds exactly one rat.", "col"))
content.add_child(_rule_row("No shared walls or corners", "Rats cannot touch, not even diagonally.", "touch"))
content.add_child(_heading("Checking in"))
content.add_child(_body("Tap or left-click to mark a cell with an X. Tap an X or a guest to clear it. Press and hold on mobile, or right-click on PC, to check a guest in. A gold ring fills while you hold."))
content.add_child(_body("Gold-ringed guests are already checked in and cannot be moved. Undo is unlimited."))
content.add_child(_heading("Try a tiny room"))
content.add_child(_body("One guest is already checked in. Place the other four. No guessing required."))
var board_center := CenterContainer.new()
content.add_child(board_center)
tutorial_board = BoardScene.instantiate() as Board
tutorial_board.custom_minimum_size = Vector2(300, 300)
tutorial_board.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
tutorial_board.solved.connect(_on_tutorial_solved)
board_center.add_child(tutorial_board)
var controls := HBoxContainer.new()
controls.alignment = BoxContainer.ALIGNMENT_CENTER
controls.add_theme_constant_override("separation", 10)
content.add_child(controls)
var reset := UI.button("Reset", false, 48)
reset.custom_minimum_size = Vector2(120, 48)
reset.pressed.connect(_on_tutorial_reset)
controls.add_child(reset)
var hint := UI.button("Hint", true, 48)
hint.custom_minimum_size = Vector2(120, 48)
hint.pressed.connect(_on_tutorial_hint)
controls.add_child(hint)
tutorial_status = UI.label("Tap a cell to mark X. Hold or right-click to check in.", 14, Palette.MUTED)
content.add_child(tutorial_status)
content.add_child(_heading("Housekeeping tips"))
content.add_child(_body("Start with the smallest room. Mark Xs as you place guests — the board does it for you. If a room's open cells all sit in one row, that row's guest belongs to that room. Every room has exactly one solution, and it never requires guessing."))
content.add_child(_body("If you get stuck, the Hint button reveals one correct guest. In the real rooms, Crumb's hints are always free."))
content.add_child(_heading("Questions"))
content.add_child(_body("Why can't the rats touch? Every guest is a little grumpy after a long journey and wants their own space."))
content.add_child(_body("Why do some guests have gold rings? They checked in early. They are part of the puzzle, not a mistake."))
var gap := Control.new()
gap.custom_minimum_size = Vector2(0, 20)
content.add_child(gap)
var tutorial := _load_tutorial()
if not tutorial.is_empty():
tutorial_board.set_level(tutorial)
func _heading(text: String) -> Label:
var label := UI.label(text, 24)
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
return label
func _body(text: String, font_size: int = 16) -> Label:
var label := UI.label(text, font_size, Palette.MUTED)
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
return label
func _rule_row(title: String, body: String, mode: String) -> PanelContainer:
var panel := UI.panel(Palette.PAPER, 20, 12)
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 12)
panel.add_child(row)
var diagram := MiniDiagram.new()
diagram.mode = mode
diagram.custom_minimum_size = Vector2(130, 130)
row.add_child(diagram)
var text := VBoxContainer.new()
text.size_flags_horizontal = Control.SIZE_EXPAND_FILL
text.alignment = BoxContainer.ALIGNMENT_CENTER
row.add_child(text)
var heading := UI.label(title, 19)
heading.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
text.add_child(heading)
var detail := UI.label(body, 14, Palette.MUTED)
detail.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
text.add_child(detail)
return panel
func _load_tutorial() -> Dictionary:
if not FileAccess.file_exists("res://data/tutorial.json"):
return {}
var file := FileAccess.open("res://data/tutorial.json", FileAccess.READ)
if file == null:
return {}
var parsed = JSON.parse_string(file.get_as_text())
file.close()
if typeof(parsed) == TYPE_DICTIONARY:
return parsed
return {}
func _on_tutorial_reset() -> void:
tutorial_board.restart()
tutorial_status.text = "Tap a cell to mark X. Hold or right-click to check in."
tutorial_status.add_theme_color_override("font_color", Palette.MUTED)
func _on_tutorial_hint() -> void:
if tutorial_board.hint():
tutorial_status.text = "Crumb tapped the right room."
tutorial_status.add_theme_color_override("font_color", Palette.MUTED)
else:
tutorial_status.text = "Everyone is already checked in."
tutorial_status.add_theme_color_override("font_color", Palette.MUTED)
func _on_tutorial_solved() -> void:
tutorial_status.text = "Everyone checked in. Nicely done."
tutorial_status.add_theme_color_override("font_color", Palette.INK)