Follow a single turn
- Receive input. Read the direction from a key, tap or swipe. A wait action spends a turn while leaving Sol in the same cell.
- Check the new cell. Use the level’s walls and dimensions to decide whether Sol can move.
- Advance the patrols. Update the luggage carts and check where their paths meet the courier.
- Apply the job rules. Check the destination and carried parcel. The exit opens when the delivery requirements are met.
- Show the result. Draw the new state, give the player feedback and keep progress locally.
The hint system can call the same route rules for possible future turns. It can search ahead without moving Sol on the real deck.
GDScript line by line
Follow the line numbers, including the indent at the start of each line. Find the code the game will run first, then look for the function that reacts when you tap or change something.
Read scripts/cruise.gd line by line
-
extends ControlStarts with Godot's Control type. This script gets the abilities of that type and adds the game's own rules. -
const Rules = preload("res://scripts/route_rules.gd")Creates a constant named Rules. The expression prepares a resource at a fixed project path when the script is loaded. -
const Catalog = preload("res://scripts/catalog.gd")Creates a constant named Catalog. The expression prepares a resource at a fixed project path when the script is loaded. -
const Progress = preload("res://scripts/progress.gd")Creates a constant named Progress. The expression prepares a resource at a fixed project path when the script is loaded. -
const DeckBoard = preload("res://scripts/deck_board.gd")Creates a constant named DeckBoard. The expression prepares a resource at a fixed project path when the script is loaded. -
const LETTERING = preload("res://art/lettering_theme.tres")Creates a constant named LETTERING. The expression prepares a resource at a fixed project path when the script is loaded. -
const NAVY := Color("#102a3a")Creates a constant named NAVY. The expression builds a colour from these values. Godot infers the type from the first value. -
const PANEL := Color("#153243")Creates a constant named PANEL. The expression builds a colour from these values. Godot infers the type from the first value. -
const FOAM := Color("#f7efdb")Creates a constant named FOAM. The expression builds a colour from these values. Godot infers the type from the first value. -
const GOLD := Color("#ffd28a")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value. -
const MUTED := Color("#b2c9ca")Creates a constant named MUTED. The expression builds a colour from these values. Godot infers the type from the first value. -
const MINT := Color("#87e1d2")Creates a constant named MINT. The expression builds a colour from these values. Godot infers the type from the first value. -
const CORAL := Color("#f1ae9b")Creates a constant named CORAL. The expression builds a colour from these values. Godot infers the type from the first value. -
const ACCENTS := [MINT, GOLD, Color("#cfc6fa")]Creates a constant named ACCENTS. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const MARKS := ["A", "B", "C"]Creates a constant named MARKS. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const VIEW := Vector2(1280, 720)Creates a constant named VIEW. The expression packs x and y into one value. Godot infers the type from the first value. -
var levels: Array[Dictionary] = []Creates a variable named levels. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var level_index := 0Creates a variable named level_index. The expression uses the whole number 0. Godot infers the type from the first value. -
var level := {}Creates a variable named level. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value. -
var state := {}Creates a variable named state. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value. -
var last_completed := -1Creates a variable named last_completed. The expression reads -1. Godot infers the type from the first value. -
var sound_enabled := trueCreates a variable named sound_enabled. The expression uses the yes-or-no value true. Godot infers the type from the first value. -
var hint_direction := -1Creates a variable named hint_direction. The expression reads -1. Godot infers the type from the first value. -
var background: TextureRectDeclares background for later use. A colon followed by a type says which kind of value belongs here. -
var tint_layer: ColorRectDeclares tint_layer for later use. A colon followed by a type says which kind of value belongs here. -
var board: ControlDeclares board for later use. A colon followed by a type says which kind of value belongs here. -
var level_title: LabelDeclares level_title for later use. A colon followed by a type says which kind of value belongs here. -
var deck_title: LabelDeclares deck_title for later use. A colon followed by a type says which kind of value belongs here. -
var brief: LabelDeclares brief for later use. A colon followed by a type says which kind of value belongs here. -
var score: LabelDeclares score for later use. A colon followed by a type says which kind of value belongs here. -
var parcel: LabelDeclares parcel for later use. A colon followed by a type says which kind of value belongs here. -
var turn_label: LabelDeclares turn_label for later use. A colon followed by a type says which kind of value belongs here. -
var status: LabelDeclares status for later use. A colon followed by a type says which kind of value belongs here. -
var lock_help: LabelDeclares lock_help for later use. A colon followed by a type says which kind of value belongs here. -
var sound_button: ButtonDeclares sound_button for later use. A colon followed by a type says which kind of value belongs here. -
var finish_button: ButtonDeclares finish_button for later use. A colon followed by a type says which kind of value belongs here. -
var move_buttons: Array[Button] = []Creates a variable named move_buttons. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var sheet: ControlDeclares sheet for later use. A colon followed by a type says which kind of value belongs here. -
var sheet_title: LabelDeclares sheet_title for later use. A colon followed by a type says which kind of value belongs here. -
var sheet_copy: LabelDeclares sheet_copy for later use. A colon followed by a type says which kind of value belongs here. -
var sheet_entries: ControlDeclares sheet_entries for later use. A colon followed by a type says which kind of value belongs here. -
var sheet_back: ButtonDeclares sheet_back for later use. A colon followed by a type says which kind of value belongs here. -
var return_focus: ButtonDeclares return_focus for later use. A colon followed by a type says which kind of value belongs here. -
var sound_player: AudioStreamPlayerDeclares sound_player for later use. A colon followed by a type says which kind of value belongs here. -
var cue_move: AudioStreamWAVDeclares cue_move for later use. A colon followed by a type says which kind of value belongs here. -
var cue_pickup: AudioStreamWAVDeclares cue_pickup for later use. A colon followed by a type says which kind of value belongs here. -
var cue_deliver: AudioStreamWAVDeclares cue_deliver for later use. A colon followed by a type says which kind of value belongs here. -
func _ready() -> void:Godot calls this once after the scene and its children are ready. Use it to set up the room and connect controls. -
theme = LETTERINGStores the new value in theme. The expression reads LETTERING. -
levels = Catalog.read()Stores the new value in levels. The expression calls Catalog.read with the values in its parentheses. -
if levels.is_empty():Checks levels.is_empty(). The indented instructions below run only if this test passes. -
_label("The deck maps are missing. Open the complete project folder.", Rect2(45, 45, 1100, 80), 26, self)Calls _label with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var saved := Progress.restore()Creates a variable named saved. The expression calls Progress.restore with the values in its parentheses. Godot infers the type from the first value. -
last_completed = clampi(saved["done"], -1, levels.size() - 1)Stores the new value in last_completed. The expression keeps a whole number within the chosen bounds. -
sound_enabled = saved["sound"]Stores the new value in sound_enabled. The expression looks up the item or key written between the square brackets. -
_build_screen()Calls _build_screen with the values in its parentheses. -
_build_sheet()Calls _build_sheet with the values in its parentheses. -
_build_sound()Calls _build_sound with the values in its parentheses. -
_open_level(mini(last_completed + 1, levels.size() - 1))Calls _open_level with the values in its parentheses. -
move_buttons[0].grab_focus()Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
func _label(caption: String, rect: Rect2, font_size: int, parent: Control, colour: Color = FOAM, wrap := false) -> Label:Defines label, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var control := Label.new()Creates a variable named control. The expression creates a new Label object. Godot infers the type from the first value. -
control.text = captionUpdates control.text, which controls the words a player sees. The expression reads caption. -
control.position = rect.positionUpdates control.position, which controls the node's local x and y location. The expression reads rect.position. -
control.size = rect.sizeUpdates control.size, which controls the control's width and height. The expression reads rect.size. -
control.vertical_alignment = VERTICAL_ALIGNMENT_CENTERStores the new value in control.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_CENTER. -
control.add_theme_font_size_override("font_size", font_size)Calls control.add_theme_font_size_override with the values in its parentheses. -
control.add_theme_color_override("font_color", colour)Calls control.add_theme_color_override with the values in its parentheses. -
control.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates control.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
if wrap:Checks wrap. The indented instructions below run only if this test passes. -
control.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTStores the new value in control.autowrap_mode. The expression reads TextServer.AUTOWRAP_WORD_SMART. -
parent.add_child(control)Adds the new node to the scene tree so that Godot can run and draw it. -
return controlFinishes the function and hands its result back to the caller. The expression reads control. -
func _style(fill: Color, edge: Color, radius := 12, border := 1) -> StyleBoxFlat:Defines style, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var box := StyleBoxFlat.new()Creates a variable named box. The expression creates a new StyleBoxFlat object. Godot infers the type from the first value. -
box.bg_color = fillStores the new value in box.bg_color. The expression reads fill. -
box.border_color = edgeStores the new value in box.border_color. The expression reads edge. -
box.set_border_width_all(border)Calls box.set_border_width_all with the values in its parentheses. -
box.set_corner_radius_all(radius)Calls box.set_corner_radius_all with the values in its parentheses. -
return boxFinishes the function and hands its result back to the caller. The expression reads box. -
func _panel(rect: Rect2, parent: Control, fill: Color, edge: Color, radius := 15) -> Panel:Defines panel, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var panel := Panel.new()Creates a variable named panel. The expression creates a new Panel object. Godot infers the type from the first value. -
panel.position = rect.positionUpdates panel.position, which controls the node's local x and y location. The expression reads rect.position. -
panel.size = rect.sizeUpdates panel.size, which controls the control's width and height. The expression reads rect.size. -
panel.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates panel.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
panel.add_theme_stylebox_override("panel", _style(fill, edge, radius))Calls panel.add_theme_stylebox_override with the values in its parentheses. -
parent.add_child(panel)Adds the new node to the scene tree so that Godot can run and draw it. -
return panelFinishes the function and hands its result back to the caller. The expression reads panel. -
func _button(caption: String, rect: Rect2, parent: Control, callback: Callable, font_size: int = 17) -> Button:Defines button, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var control := Button.new()Creates a variable named control. The expression creates a new Button object. Godot infers the type from the first value. -
control.text = captionUpdates control.text, which controls the words a player sees. The expression reads caption. -
control.position = rect.positionUpdates control.position, which controls the node's local x and y location. The expression reads rect.position. -
control.size = rect.sizeUpdates control.size, which controls the control's width and height. The expression reads rect.size. -
control.add_theme_font_size_override("font_size", font_size)Calls control.add_theme_font_size_override with the values in its parentheses. -
control.add_theme_color_override("font_color", FOAM)Calls control.add_theme_color_override with the values in its parentheses. -
control.add_theme_color_override("font_hover_color", FOAM)Calls control.add_theme_color_override with the values in its parentheses. -
control.add_theme_color_override("font_pressed_color", NAVY)Calls control.add_theme_color_override with the values in its parentheses. -
control.add_theme_color_override("font_disabled_color", MUTED.darkened(0.26))Calls control.add_theme_color_override with the values in its parentheses. -
control.add_theme_stylebox_override("normal", _style(Color("#234958"), Color("#6a9398")))Calls control.add_theme_stylebox_override with the values in its parentheses. -
control.add_theme_stylebox_override("hover", _style(Color("#376878"), MINT))Calls control.add_theme_stylebox_override with the values in its parentheses. -
control.add_theme_stylebox_override("pressed", _style(MINT, FOAM))Calls control.add_theme_stylebox_override with the values in its parentheses. -
control.add_theme_stylebox_override("focus", _style(Color(1, 1, 1, 0), GOLD, 12, 2))Calls control.add_theme_stylebox_override with the values in its parentheses. -
control.add_theme_stylebox_override("disabled", _style(Color("#1b3846"), Color("#43616a")))Calls control.add_theme_stylebox_override with the values in its parentheses. -
control.pressed.connect(callback)Links a signal to the function that should run when the event happens. -
parent.add_child(control)Adds the new node to the scene tree so that Godot can run and draw it. -
return controlFinishes the function and hands its result back to the caller. The expression reads control. -
func _build_screen() -> void:Defines build screen, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var backdrop := ColorRect.new()Creates a variable named backdrop. The expression creates a new ColorRect object. Godot infers the type from the first value. -
backdrop.size = VIEWUpdates backdrop.size, which controls the control's width and height. The expression reads VIEW. -
backdrop.color = Color("#112b38")Stores the new value in backdrop.color. The expression builds a colour from these values. -
backdrop.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates backdrop.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
add_child(backdrop)Adds the new node to the scene tree so that Godot can run and draw it. -
background = TextureRect.new()Stores the new value in background. The expression creates a new TextureRect object. -
background.size = VIEWUpdates background.size, which controls the control's width and height. The expression reads VIEW. -
background.expand_mode = TextureRect.EXPAND_IGNORE_SIZEStores the new value in background.expand_mode. The expression reads TextureRect.EXPAND_IGNORE_SIZE. -
background.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVEREDStores the new value in background.stretch_mode. The expression reads TextureRect.STRETCH_KEEP_ASPECT_COVERED. -
background.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates background.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
add_child(background)Adds the new node to the scene tree so that Godot can run and draw it. -
tint_layer = ColorRect.new()Stores the new value in tint_layer. The expression creates a new ColorRect object. -
tint_layer.size = VIEWUpdates tint_layer.size, which controls the control's width and height. The expression reads VIEW. -
tint_layer.color = Color(0.015, 0.055, 0.085, 0.48)Stores the new value in tint_layer.color. The expression builds a colour from these values. -
tint_layer.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates tint_layer.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
add_child(tint_layer)Adds the new node to the scene tree so that Godot can run and draw it. -
_panel(Rect2(32, 26, 1216, 103), self, Color(0.04, 0.12, 0.18, 0.95), Color("#66828a"), 18)Calls _panel with the values in its parentheses. -
_label("MIDNIGHT DECK DASH", Rect2(54, 44, 778, 58), 42, self)Calls _label with the values in its parentheses. -
level_title = _label("", Rect2(739, 48, 478, 38), 27, self)Stores the new value in level_title. The expression calls _label with the values in its parentheses. -
level_title.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHTStores the new value in level_title.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_RIGHT. -
deck_title = _label("", Rect2(739, 87, 478, 23), 16, self, MINT)Stores the new value in deck_title. The expression calls _label with the values in its parentheses. -
deck_title.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHTStores the new value in deck_title.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_RIGHT. -
board = DeckBoard.new()Stores the new value in board. The expression creates a new DeckBoard object. -
board.position = Vector2(42, 151)Updates board.position, which controls the node's local x and y location. The expression packs x and y into one value. -
board.size = Vector2(795, 477)Updates board.size, which controls the control's width and height. The expression packs x and y into one value. -
board.direction_requested.connect(_move)Links a signal to the function that should run when the event happens. -
add_child(board)Adds the new node to the scene tree so that Godot can run and draw it. -
_panel(Rect2(863, 140, 385, 498), self, Color(0.055, 0.16, 0.23, 0.96), Color("#638a8e"), 15)Calls _panel with the values in its parentheses. -
_label("DELIVERY MANIFEST", Rect2(889, 153, 325, 29), 20, self, GOLD)Calls _label with the values in its parentheses. -
brief = _label("", Rect2(889, 187, 330, 76), 17, self, FOAM, true)Stores the new value in brief. The expression calls _label with the values in its parentheses. -
score = _label("", Rect2(889, 279, 329, 35), 24, self, MINT)Stores the new value in score. The expression calls _label with the values in its parentheses. -
parcel = _label("", Rect2(889, 317, 329, 26), 18, self)Stores the new value in parcel. The expression calls _label with the values in its parentheses. -
turn_label = _label("", Rect2(889, 347, 329, 24), 17, self, MUTED)Stores the new value in turn_label. The expression calls _label with the values in its parentheses. -
status = _label("", Rect2(889, 381, 329, 81), 17, self, FOAM, true)Stores the new value in status. The expression calls _label with the values in its parentheses. -
status.vertical_alignment = VERTICAL_ALIGNMENT_TOPStores the new value in status.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_TOP. -
lock_help = _label("Arrow keys, WASD or tap a neighbouring tile", Rect2(890, 593, 325, 25), 14, self, MUTED)Stores the new value in lock_help. The expression calls _label with the values in its parentheses. -
lock_help.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTERStores the new value in lock_help.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_CENTER. -
move_buttons.append(_button("↑", Rect2(1017, 456, 67, 53), self, _move.bind(Rules.NORTH), 26))Adds an item to the end of a list. -
move_buttons.append(_button("→", Rect2(1091, 519, 67, 53), self, _move.bind(Rules.EAST), 26))Adds an item to the end of a list. -
move_buttons.append(_button("↓", Rect2(1017, 519, 67, 53), self, _move.bind(Rules.SOUTH), 26))Adds an item to the end of a list. -
move_buttons.append(_button("←", Rect2(943, 519, 67, 53), self, _move.bind(Rules.WEST), 26))Adds an item to the end of a list. -
for i in range(move_buttons.size()):Repeats the indented instructions for each value in range(move_buttons.size()). -
move_buttons[i].tooltip_text = Rules.DIRECTIONS[i]Stores the new value in move_buttons[i].tooltip_text. The expression looks up the item or key written between the square brackets. -
move_buttons.append(_button("Wait", Rect2(1152, 457, 69, 52), self, _move.bind(Rules.WAIT), 16))Adds an item to the end of a list. -
finish_button = _button("Next job →", Rect2(953, 519, 204, 53), self, _advance, 22)Stores the new value in finish_button. The expression calls _button with the values in its parentheses. -
finish_button.hide()Makes this control invisible. -
_panel(Rect2(32, 654, 1216, 48), self, Color(0.04, 0.12, 0.18, 0.96), Color("#68878d"), 13)Calls _panel with the values in its parentheses. -
_button("Ship map", Rect2(40, 657, 120, 42), self, _show_map)Calls _button with the values in its parentheses. -
_button("How to play", Rect2(170, 657, 133, 42), self, _show_help)Calls _button with the values in its parentheses. -
_button("Route hint", Rect2(313, 657, 121, 42), self, _hint)Calls _button with the values in its parentheses. -
_button("Restart job", Rect2(444, 657, 128, 42), self, _restart)Calls _button with the values in its parentheses. -
sound_button = _button("", Rect2(582, 657, 130, 42), self, _toggle_sound)Stores the new value in sound_button. The expression calls _button with the values in its parentheses. -
_label("Square: parcel • Ring: station • OUT: crew check-in", Rect2(738, 660, 480, 30), 14, self, MUTED)Calls _label with the values in its parentheses. -
func _build_sheet() -> void:Defines build sheet, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
sheet = Control.new()Stores the new value in sheet. The expression creates a new Control object. -
sheet.size = VIEWUpdates sheet.size, which controls the control's width and height. The expression reads VIEW. -
sheet.mouse_filter = Control.MOUSE_FILTER_STOPUpdates sheet.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_STOP. -
add_child(sheet)Adds the new node to the scene tree so that Godot can run and draw it. -
var shade := ColorRect.new()Creates a variable named shade. The expression creates a new ColorRect object. Godot infers the type from the first value. -
shade.size = VIEWUpdates shade.size, which controls the control's width and height. The expression reads VIEW. -
shade.color = Color(0.015, 0.035, 0.055, 0.86)Stores the new value in shade.color. The expression builds a colour from these values. -
shade.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates shade.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
sheet.add_child(shade)Adds the new node to the scene tree so that Godot can run and draw it. -
_panel(Rect2(144, 69, 992, 583), sheet, Color("#102d3f"), Color("#8bbfb8"), 19)Calls _panel with the values in its parentheses. -
sheet_title = _label("", Rect2(180, 104, 900, 56), 37, sheet, GOLD)Stores the new value in sheet_title. The expression calls _label with the values in its parentheses. -
sheet_copy = _label("", Rect2(180, 168, 900, 155), 23, sheet, FOAM, true)Stores the new value in sheet_copy. The expression calls _label with the values in its parentheses. -
sheet_copy.vertical_alignment = VERTICAL_ALIGNMENT_TOPStores the new value in sheet_copy.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_TOP. -
sheet_entries = Control.new()Stores the new value in sheet_entries. The expression creates a new Control object. -
sheet_entries.position = Vector2(180, 223)Updates sheet_entries.position, which controls the node's local x and y location. The expression packs x and y into one value. -
sheet_entries.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates sheet_entries.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
sheet.add_child(sheet_entries)Adds the new node to the scene tree so that Godot can run and draw it. -
sheet_back = _button("Return to the deck", Rect2(180, 571, 228, 55), sheet, _close_sheet)Stores the new value in sheet_back. The expression calls _button with the values in its parentheses. -
sheet.hide()Makes this control invisible. -
func _open_sheet(title: String, copy: String) -> void:Defines open sheet, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
return_focus = get_viewport().gui_get_focus_owner() as ButtonFinishes the function and hands its result back to the caller. The expression reads _focus = get_viewport().gui_get_focus_owner() as Button. -
sheet_title.text = titleUpdates sheet_title.text, which controls the words a player sees. The expression reads title. -
sheet_copy.text = copyUpdates sheet_copy.text, which controls the words a player sees. The expression reads copy. -
for entry in sheet_entries.get_children():Repeats the indented instructions for each value in sheet_entries.get_children(). -
sheet_entries.remove_child(entry)Calls sheet_entries.remove_child with the values in its parentheses. -
entry.queue_free()Asks Godot to remove this node safely at the end of the frame. -
sheet.show()Makes this control visible. -
board.input_enabled = falseStores the new value in board.input_enabled. The expression uses the yes-or-no value false. -
_set_deck_focus(false)Calls _set_deck_focus with the values in its parentheses. -
sheet_back.grab_focus()Gives this control keyboard focus so Space, Enter or arrow keys can reach it. -
func _close_sheet() -> void:Defines close sheet, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
sheet.hide()Makes this control invisible. -
board.input_enabled = not Rules.is_complete(level, state)Stores the new value in board.input_enabled. The expression reads not Rules.is_complete(level, state). -
_set_deck_focus(true)Calls _set_deck_focus with the values in its parentheses. -
if is_instance_valid(return_focus) and return_focus.visible:Checks is_instance_valid(return_focus) and return_focus.visible. The indented instructions below run only if this test passes. -
return_focus.grab_focus()Finishes the function and hands its result back to the caller. The expression gives this control keyboard focus so Space, Enter or arrow keys can reach it. -
elif finish_button.visible:If the earlier branches did not run, checks finish_button.visible next. -
finish_button.grab_focus()Gives this control keyboard focus so Space, Enter or arrow keys can reach it. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
move_buttons[0].grab_focus()Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
func _set_deck_focus(enabled: bool) -> void:Defines set deck focus, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
for child in get_children():Repeats the indented instructions for each value in get_children(). -
if child is Button:Checks child is Button. The indented instructions below run only if this test passes. -
child.focus_mode = Control.FOCUS_ALL if enabled else Control.FOCUS_NONEStores the new value in child.focus_mode. The expression chooses one of two values by checking the condition in the middle. -
func _show_map() -> void:Defines show map, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
_open_sheet("Ship map", "Finish a job to unlock the next one. You can replay any open job.")Calls _open_sheet with the values in its parentheses. -
for i in range(levels.size()):Repeats the indented instructions for each value in range(levels.size()). -
var column := i / 3.0Creates a variable named column. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value. -
var x := float(floori(column)) * 306Creates a variable named x. The expression converts a suitable value to a number that can include a fractional part. Godot infers the type from the first value. -
var y := (i % 3) * 70Creates a variable named y. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value. -
var entry: Dictionary = levels[i]Creates a variable named entry. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
if i % 3 == 0:Checks i % 3 == 0. The indented instructions below run only if this test passes. -
_label(entry["deck"], Rect2(x, 0, 279, 36), 19, sheet_entries, GOLD)Calls _label with the values in its parentheses. -
var done := "✓ " if i <= last_completed else ""Creates a variable named done. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
var button := _button("%02d %s%s" % [i + 1, done, entry["name"]],Creates a variable named button. The expression calls _button with the values in its parentheses. Godot infers the type from the first value. -
Rect2(x, y + 45, 282, 54), sheet_entries, _choose.bind(i), 14)Describes a position and a size. -
button.disabled = i > last_completed + 1Updates button.disabled, which controls whether the control should ignore activation. The expression calculates a new value from the expressions on either side of the operator. -
if button.disabled:Checks button.disabled. The indented instructions below run only if this test passes. -
button.text = "%02d Locked" % (i + 1)Updates button.text, which controls the words a player sees. The expression uses the text inside the quotes. -
func _show_help() -> void:Defines show help, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
_open_sheet("How to play", "1. Move onto a square parcel to carry it. You can hold one at a time.\n"Calls _open_sheet with the values in its parentheses. -
+ "2. Match its letter to a round station. Bring every parcel to its station.\n"Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
+ "3. The coral ring shows where a cart moves next. Use Wait to let it pass.\n"Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
+ "4. A numbered lift moves you to its partner. OUT opens after every delivery.")Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
_label("On a phone, swipe the board or use the direction buttons. You can also tap a neighbouring tile.\n"Calls _label with the values in its parentheses. -
+ "On a keyboard, use arrows or WASD to move and the full stop key to wait. Press Tab and Enter for the menus.",Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
Rect2(0, 179, 880, 98), 19, sheet_entries, MINT, true)Describes a position and a size. -
func _choose(chosen: int) -> void:Defines choose, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
if chosen <= last_completed + 1:Checks chosen <= last_completed + 1. The indented instructions below run only if this test passes. -
_close_sheet()Calls _close_sheet with the values in its parentheses. -
_open_level(chosen)Calls _open_level with the values in its parentheses. -
move_buttons[0].grab_focus()Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
func _open_level(index: int) -> void:Defines open level, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
level_index = indexStores the new value in level_index. The expression reads index. -
level = levels[index]Stores the new value in level. The expression looks up the item or key written between the square brackets. -
state = Rules.initial_state(level)Stores the new value in state. The expression calls Rules.initial_state with the values in its parentheses. -
hint_direction = -1Stores the new value in hint_direction. The expression reads -1. -
var art_path := "res://art/%s.jpg" % level["art"]Creates a variable named art_path. The expression uses the text inside the quotes. Godot infers the type from the first value. -
var has_art := ResourceLoader.exists(art_path)Creates a variable named has_art. The expression calls ResourceLoader.exists with the values in its parentheses. Godot infers the type from the first value. -
background.texture = load(art_path) if has_art else nullStores the new value in background.texture. The expression reads a resource from the project when this instruction runs. -
tint_layer.visible = has_artUpdates tint_layer.visible, which controls whether the node should appear. The expression reads has_art. -
level_title.text = level["name"]Updates level_title.text, which controls the words a player sees. The expression looks up the item or key written between the square brackets. -
deck_title.text = "%s • Job %02d of %02d" % [level["deck"], index + 1, levels.size()]Updates deck_title.text, which controls the words a player sees. The expression uses the text inside the quotes. -
brief.text = level["brief"]Updates brief.text, which controls the words a player sees. The expression looks up the item or key written between the square brackets. -
_update("Step onto a marked parcel to begin. Try Route hint if you want a first move.")Calls _update with the values in its parentheses. -
func _update(message: String) -> void:Defines update, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var tint: Color = ACCENTS[floori(level_index / 3.0)]Creates a variable named tint. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
board.set_board(level, state, tint, hint_direction)Calls board.set_board with the values in its parentheses. -
deck_title.add_theme_color_override("font_color", tint)Calls deck_title.add_theme_color_override with the values in its parentheses. -
score.text = "%d / %d delivered" % [Rules.count_delivered(level, state), level["drops"].size()]Updates score.text, which controls the words a player sees. The expression uses the text inside the quotes. -
parcel.text = "Carrying: %s" % (MARKS[state["held"]] if state["held"] >= 0 else "nothing")Updates parcel.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle. -
turn_label.text = "Turns: %d" % state["turn"]Updates turn_label.text, which controls the words a player sees. The expression uses the text inside the quotes. -
status.text = messageUpdates status.text, which controls the words a player sees. The expression reads message. -
sound_button.text = "Sound: on" if sound_enabled else "Sound: off"Updates sound_button.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle. -
var won := Rules.is_complete(level, state)Creates a variable named won. The expression calls Rules.is_complete with the values in its parentheses. Godot infers the type from the first value. -
board.input_enabled = not won and not sheet.visibleStores the new value in board.input_enabled. The expression evaluates the test to see whether it is true or false. -
for button in move_buttons:Repeats the indented instructions for each value in move_buttons. -
button.visible = not wonUpdates button.visible, which controls whether the node should appear. The expression reads not won. -
finish_button.visible = wonUpdates finish_button.visible, which controls whether the node should appear. The expression reads won. -
finish_button.text = "Next job →" if level_index < levels.size() - 1 else "Jobs complete →"Updates finish_button.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle. -
lock_help.visible = not wonUpdates lock_help.visible, which controls whether the node should appear. The expression reads not won. -
func _move(direction: int) -> void:Defines move, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
if level.is_empty() or sheet.visible or Rules.is_complete(level, state):Checks level.is_empty() or sheet.visible or Rules.is_complete(level, state). The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
hint_direction = -1Stores the new value in hint_direction. The expression reads -1. -
var next := Rules.next_state(level, state, direction)Creates a variable named next. The expression calls Rules.next_state with the values in its parentheses. Godot infers the type from the first value. -
if next.is_empty():Checks next.is_empty(). The indented instructions below run only if this test passes. -
_update("That square is blocked this turn. Try a different direction or wait from a clear tile.")Calls _update with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var message := "Keep going. Match each parcel to the station with the same letter."Creates a variable named message. The expression uses the text inside the quotes. Godot infers the type from the first value. -
var cue := cue_moveCreates a variable named cue. The expression reads cue_move. Godot infers the type from the first value. -
if next["arrived"] != state["arrived"]:Checks next["arrived"] != state["arrived"]. The indented instructions below run only if this test passes. -
message = "Parcel %s delivered. Well done!" % MARKS[state["held"]]Stores the new value in message. The expression uses the text inside the quotes. -
cue = cue_deliverStores the new value in cue. The expression reads cue_deliver. -
elif next["held"] != state["held"]:If the earlier branches did not run, checks next["held"] != state["held"] next. -
message = "Parcel %s collected. Look for the %s station." % [MARKS[next["held"]], MARKS[next["held"]]]Stores the new value in message. The expression uses the text inside the quotes. -
cue = cue_pickupStores the new value in cue. The expression reads cue_pickup. -
elif direction == Rules.WAIT:If the earlier branches did not run, checks direction == Rules.WAIT next. -
message = "One turn waited. Check the carts' new positions."Stores the new value in message. The expression uses the text inside the quotes. -
elif level["lifts"].has(state["pos"] + Rules.STEPS[direction]):If the earlier branches did not run, checks level["lifts"].has(state["pos"] + Rules.STEPS[direction]) next. -
message = "Lift shortcut used. You’re at its matching number."Stores the new value in message. The expression uses the text inside the quotes. -
state = nextStores the new value in state. The expression reads next. -
if Rules.is_complete(level, state):Checks Rules.is_complete(level, state). The indented instructions below run only if this test passes. -
last_completed = maxi(last_completed, level_index)Stores the new value in last_completed. The expression calls maxi with the values in its parentheses. -
Progress.save(last_completed, sound_enabled)Calls Progress.save with the values in its parentheses. -
message = "Shift complete! Every parcel arrived and you reached Crew Check-in."Stores the new value in message. The expression uses the text inside the quotes. -
cue = cue_deliverStores the new value in cue. The expression reads cue_deliver. -
elif Rules.count_delivered(level, state) == level["drops"].size():If the earlier branches did not run, checks Rules.count_delivered(level, state) == level["drops"].size() next. -
message = "All parcels delivered. Head to OUT for Crew Check-in."Stores the new value in message. The expression uses the text inside the quotes. -
_update(message)Calls _update with the values in its parentheses. -
_play(cue)Calls _play with the values in its parentheses. -
if finish_button.visible:Checks finish_button.visible. The indented instructions below run only if this test passes. -
finish_button.grab_focus()Gives this control keyboard focus so Space, Enter or arrow keys can reach it. -
func _restart() -> void:Defines restart, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
_open_level(level_index)Calls _open_level with the values in its parentheses. -
move_buttons[0].grab_focus()Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
func _advance() -> void:Defines advance, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
if level_index + 1 < levels.size():Checks level_index + 1 < levels.size(). The indented instructions below run only if this test passes. -
_open_level(level_index + 1)Calls _open_level with the values in its parentheses. -
move_buttons[0].grab_focus()Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
_open_sheet("All jobs delivered", "Every parcel on the Midnight Deck Dash has arrived. Open the Ship map to replay any job.")Calls _open_sheet with the values in its parentheses. -
func _hint() -> void:Defines hint, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
if Rules.is_complete(level, state):Checks Rules.is_complete(level, state). The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var route := Rules.find_route(level, state)Creates a variable named route. The expression calls Rules.find_route with the values in its parentheses. Godot infers the type from the first value. -
if route.is_empty():Checks route.is_empty(). The indented instructions below run only if this test passes. -
_update("No route from this position. Restart the job for a fresh route.")Calls _update with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
hint_direction = route[0]Stores the new value in hint_direction. The expression looks up the item or key written between the square brackets. -
var message := "Suggested move: %s. About %d turns remain by the shortest safe route." % [Rules.DIRECTIONS[hint_direction], route.size()]Creates a variable named message. The expression uses the text inside the quotes. Godot infers the type from the first value. -
_update(message)Calls _update with the values in its parentheses. -
func _toggle_sound() -> void:Defines toggle sound, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
sound_enabled = not sound_enabledStores the new value in sound_enabled. The expression reads not sound_enabled. -
Progress.save(last_completed, sound_enabled)Calls Progress.save with the values in its parentheses. -
_update(status.text)Calls _update with the values in its parentheses. -
if sound_enabled:Checks sound_enabled. The indented instructions below run only if this test passes. -
_play(cue_pickup)Calls _play with the values in its parentheses. -
func _input(event: InputEvent) -> void:Godot calls this when input arrives. The event tells the game which key, pointer or touch action happened. -
if not is_instance_valid(sheet) or not event is InputEventKey or not event.pressed or event.echo:Checks not is_instance_valid(sheet) or not event is InputEventKey or not event.pressed or event.echo. The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
if sheet.visible:Checks sheet.visible. The indented instructions below run only if this test passes. -
if event.keycode == KEY_ESCAPE:Checks event.keycode == KEY_ESCAPE. The indented instructions below run only if this test passes. -
_close_sheet()Calls _close_sheet with the values in its parentheses. -
get_viewport().set_input_as_handled()Calls get_viewport with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var direction := -1Creates a variable named direction. The expression reads -1. Godot infers the type from the first value. -
match event.keycode:Compares event.keycode to the patterns below and runs the first matching branch. -
KEY_UP, KEY_W: direction = Rules.NORTHContinues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
KEY_RIGHT, KEY_D: direction = Rules.EASTContinues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
KEY_DOWN, KEY_S: direction = Rules.SOUTHContinues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
KEY_LEFT, KEY_A: direction = Rules.WESTContinues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
KEY_PERIOD: direction = Rules.WAITStores the new value in KEY_PERIOD: direction. The expression reads Rules.WAIT. -
if direction >= 0:Checks direction >= 0. The indented instructions below run only if this test passes. -
_move(direction)Calls _move with the values in its parentheses. -
get_viewport().set_input_as_handled()Calls get_viewport with the values in its parentheses. -
func _build_sound() -> void:Defines build sound, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
sound_player = AudioStreamPlayer.new()Stores the new value in sound_player. The expression creates a new AudioStreamPlayer object. -
sound_player.volume_db = -17Stores the new value in sound_player.volume_db. The expression reads -17. -
add_child(sound_player)Adds the new node to the scene tree so that Godot can run and draw it. -
cue_move = _make_sound([220.0], 0.07)Stores the new value in cue_move. The expression calls _make_sound with the values in its parentheses. -
cue_pickup = _make_sound([440.0, 550.0], 0.085)Stores the new value in cue_pickup. The expression calls _make_sound with the values in its parentheses. -
cue_deliver = _make_sound([392.0, 523.25, 659.25], 0.09)Stores the new value in cue_deliver. The expression calls _make_sound with the values in its parentheses. -
func _make_sound(frequencies: Array, duration: float) -> AudioStreamWAV:Defines make sound, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
const RATE := 22050Creates a constant named RATE. The expression uses the whole number 22050. Godot infers the type from the first value. -
var per_note := int(duration * RATE)Creates a variable named per_note. The expression converts a suitable value to a whole number. Godot infers the type from the first value. -
var wave := PackedByteArray()Creates a variable named wave. The expression calls PackedByteArray with the values in its parentheses. Godot infers the type from the first value. -
wave.resize(per_note * frequencies.size() * 2)Calls wave.resize with the values in its parentheses. -
for index in range(frequencies.size()):Repeats the indented instructions for each value in range(frequencies.size()). -
for sample in range(per_note):Repeats the indented instructions for each value in range(per_note). -
var elapsed := float(sample) / RATECreates a variable named elapsed. The expression converts a suitable value to a number that can include a fractional part. Godot infers the type from the first value. -
var envelope := sin(PI * float(sample) / per_note)Creates a variable named envelope. The expression calls sin with the values in its parentheses. Godot infers the type from the first value. -
var amplitude := sin(TAU * frequencies[index] * elapsed) * envelope * 9500.0Creates a variable named amplitude. The expression calls sin with the values in its parentheses. Godot infers the type from the first value. -
wave.encode_s16((index * per_note + sample) * 2, int(amplitude))Calls wave.encode_s16 with the values in its parentheses. -
var stream := AudioStreamWAV.new()Creates a variable named stream. The expression creates a new AudioStreamWAV object. Godot infers the type from the first value. -
stream.format = AudioStreamWAV.FORMAT_16_BITSStores the new value in stream.format. The expression reads AudioStreamWAV.FORMAT_16_BITS. -
stream.mix_rate = RATEStores the new value in stream.mix_rate. The expression reads RATE. -
stream.data = waveStores the new value in stream.data. The expression reads wave. -
return streamFinishes the function and hands its result back to the caller. The expression reads stream. -
func _play(cue: AudioStreamWAV) -> void:Defines play, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
if sound_enabled and cue != null and DisplayServer.get_name() != "headless":Checks sound_enabled and cue != null and DisplayServer.get_name() != "headless". The indented instructions below run only if this test passes. -
sound_player.stream = cueStores the new value in sound_player.stream. The expression reads cue. -
sound_player.play()Starts this sound or animation.
Read scripts/route_rules.gd line by line
-
extends RefCountedStarts with Godot's RefCounted type. This script gets the abilities of that type and adds the game's own rules. -
## Pure game rules. No screen, timer or input device is needed to test a route.A comment for the reader. Godot skips it when it runs the code. -
const WIDTH := 15Creates a constant named WIDTH. The expression uses the whole number 15. Godot infers the type from the first value. -
const HEIGHT := 9Creates a constant named HEIGHT. The expression uses the whole number 9. Godot infers the type from the first value. -
const NORTH := 0Creates a constant named NORTH. The expression uses the whole number 0. Godot infers the type from the first value. -
const EAST := 1Creates a constant named EAST. The expression uses the whole number 1. Godot infers the type from the first value. -
const SOUTH := 2Creates a constant named SOUTH. The expression uses the whole number 2. Godot infers the type from the first value. -
const WEST := 3Creates a constant named WEST. The expression uses the whole number 3. Godot infers the type from the first value. -
const WAIT := 4Creates a constant named WAIT. The expression uses the whole number 4. Godot infers the type from the first value. -
const STEPS := [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT, Vector2i.ZERO]Creates a constant named STEPS. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const DIRECTIONS := ["North", "East", "South", "West", "Wait"]Creates a constant named DIRECTIONS. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
static func tile(pair: Array) -> Vector2i:Defines tile, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
return Vector2i(int(pair[0]), int(pair[1]))Finishes the function and hands its result back to the caller. The expression packs whole-number x and y into one grid position. -
static func parse_level(raw: Dictionary) -> Dictionary:Defines parse level, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var level := {}Creates a variable named level. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value. -
level["name"] = str(raw["name"])Stores the new value in level["name"]. The expression turns a value into text for a player message. -
level["deck"] = str(raw["deck"])Stores the new value in level["deck"]. The expression turns a value into text for a player message. -
level["art"] = str(raw["art"])Stores the new value in level["art"]. The expression turns a value into text for a player message. -
level["brief"] = str(raw["brief"])Stores the new value in level["brief"]. The expression turns a value into text for a player message. -
level["start"] = tile(raw["start"])Stores the new value in level["start"]. The expression calls tile with the values in its parentheses. -
level["exit"] = tile(raw["exit"])Stores the new value in level["exit"]. The expression calls tile with the values in its parentheses. -
level["walls"] = {}Stores the new value in level["walls"]. The expression makes a dictionary that looks up values by key. -
level["pickups"] = []Stores the new value in level["pickups"]. The expression makes a list whose items keep their order. -
level["drops"] = []Stores the new value in level["drops"]. The expression makes a list whose items keep their order. -
level["carts"] = []Stores the new value in level["carts"]. The expression makes a list whose items keep their order. -
level["lifts"] = {}Stores the new value in level["lifts"]. The expression makes a dictionary that looks up values by key. -
level["period"] = 1Stores the new value in level["period"]. The expression uses the whole number 1. -
for pair in raw["walls"]:Repeats the indented instructions for each value in raw["walls"]. -
level["walls"][tile(pair)] = trueContinues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
for pair in raw["pickups"]:Repeats the indented instructions for each value in raw["pickups"]. -
level["pickups"].append(tile(pair))Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
for pair in raw["drops"]:Repeats the indented instructions for each value in raw["drops"]. -
level["drops"].append(tile(pair))Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
for route in raw["carts"]:Repeats the indented instructions for each value in raw["carts"]. -
var path := []Creates a variable named path. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
for pair in route:Repeats the indented instructions for each value in route. -
path.append(tile(pair))Adds an item to the end of a list. -
level["period"] = _lcm(level["period"], path.size())Stores the new value in level["period"]. The expression calls _lcm with the values in its parentheses. -
level["carts"].append(path)Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
for i in range(raw["lifts"].size()):Repeats the indented instructions for each value in range(raw["lifts"].size()). -
var first := tile(raw["lifts"][i][0])Creates a variable named first. The expression calls tile with the values in its parentheses. Godot infers the type from the first value. -
var second := tile(raw["lifts"][i][1])Creates a variable named second. The expression calls tile with the values in its parentheses. Godot infers the type from the first value. -
level["lifts"][first] = {"target": second, "number": i + 1}Stores the new value in level["lifts"][first]. The expression makes a dictionary that looks up values by key. -
level["lifts"][second] = {"target": first, "number": i + 1}Stores the new value in level["lifts"][second]. The expression makes a dictionary that looks up values by key. -
return levelFinishes the function and hands its result back to the caller. The expression reads level. -
static func initial_state(level: Dictionary) -> Dictionary:Defines initial state, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
return {"pos": level["start"], "held": -1, "arrived": 0, "turn": 0}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
static func walkable(level: Dictionary, position: Vector2i) -> bool:Defines walkable, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
return (position.x > 0 and position.y > 0 and position.x < WIDTH - 1Finishes the function and hands its result back to the caller. The expression evaluates the test to see whether it is true or false. -
and position.y < HEIGHT - 1 and not level["walls"].has(position))Continues the same instruction on a new line. This is one of the arguments, data entries or expressions started above. -
static func cart_positions(level: Dictionary, turn: int) -> Array:Defines cart positions, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var positions := []Creates a variable named positions. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
for path in level["carts"]:Repeats the indented instructions for each value in level["carts"]. -
positions.append(path[turn % path.size()])Adds an item to the end of a list. -
return positionsFinishes the function and hands its result back to the caller. The expression reads positions. -
static func _cart_blocks(level: Dictionary, entered: Vector2i, landing: Vector2i, turn: int) -> bool:Defines cart blocks, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
for path in level["carts"]:Repeats the indented instructions for each value in level["carts"]. -
var now: Vector2i = path[turn % path.size()]Creates a variable named now. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var next: Vector2i = path[(turn + 1) % path.size()]Creates a variable named next. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
# A cart occupies its square throughout each move. Players can always stepA comment for the reader. Godot skips it when it runs the code. -
# away from a square that a cart is about to enter.A comment for the reader. Godot skips it when it runs the code. -
if entered == now or entered == next or landing == now or landing == next:Checks entered == now or entered == next or landing == now or landing == next. The indented instructions below run only if this test passes. -
return trueFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value true. -
return falseFinishes the function and hands its result back to the caller. The expression uses the yes-or-no value false. -
static func next_state(level: Dictionary, state: Dictionary, direction: int) -> Dictionary:Defines next state, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
if direction < NORTH or direction > WAIT or is_complete(level, state):Checks direction < NORTH or direction > WAIT or is_complete(level, state). The indented instructions below run only if this test passes. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var entered: Vector2i = state["pos"] + STEPS[direction]Creates a variable named entered. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
if not walkable(level, entered):Checks not walkable(level, entered). The indented instructions below run only if this test passes. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var landing := enteredCreates a variable named landing. The expression reads entered. Godot infers the type from the first value. -
if direction != WAIT and level["lifts"].has(entered):Checks direction != WAIT and level["lifts"].has(entered). The indented instructions below run only if this test passes. -
landing = level["lifts"][entered]["target"]Stores the new value in landing. The expression looks up the item or key written between the square brackets. -
if _cart_blocks(level, entered, landing, state["turn"]):Checks _cart_blocks(level, entered, landing, state["turn"]). The indented instructions below run only if this test passes. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var held: int = state["held"]Creates a variable named held. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var arrived: int = state["arrived"]Creates a variable named arrived. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
if held >= 0 and level["drops"][held] == landing:Checks held >= 0 and level["drops"][held] == landing. The indented instructions below run only if this test passes. -
arrived |= 1 << heldContinues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
held = -1Stores the new value in held. The expression reads -1. -
if held == -1:Checks held == -1. The indented instructions below run only if this test passes. -
var parcel: int = level["pickups"].find(landing)Creates a variable named parcel. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
if parcel >= 0 and (arrived & (1 << parcel)) == 0:Checks parcel >= 0 and (arrived & (1 << parcel)) == 0. The indented instructions below run only if this test passes. -
held = parcelStores the new value in held. The expression reads parcel. -
return {"pos": landing, "held": held, "arrived": arrived, "turn": state["turn"] + 1}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
static func count_delivered(level: Dictionary, state: Dictionary) -> int:Defines count delivered, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var count := 0Creates a variable named count. The expression uses the whole number 0. Godot infers the type from the first value. -
for i in range(level["drops"].size()):Repeats the indented instructions for each value in range(level["drops"].size()). -
if (int(state["arrived"]) & (1 << i)) != 0:Checks (int(state["arrived"]) & (1 << i)) != 0. The indented instructions below run only if this test passes. -
count += 1Reads count, adds to its old value, then stores the result back in the same place. -
return countFinishes the function and hands its result back to the caller. The expression reads count. -
static func is_complete(level: Dictionary, state: Dictionary) -> bool:Defines is complete, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var all_arrived: int = (1 << level["drops"].size()) - 1Creates a variable named all_arrived. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
return state["pos"] == level["exit"] and state["arrived"] == all_arrivedFinishes the function and hands its result back to the caller. The expression evaluates the test to see whether it is true or false. -
static func _lcm(a: int, b: int) -> int:Defines lcm, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var x := maxi(a, b)Creates a variable named x. The expression calls maxi with the values in its parentheses. Godot infers the type from the first value. -
var y := mini(a, b)Creates a variable named y. The expression calls mini with the values in its parentheses. Godot infers the type from the first value. -
while y > 0:Keeps repeating while y > 0 stays true. The loop body should eventually change the result or leave with break. -
var remainder := x % yCreates a variable named remainder. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value. -
x = yStores the new value in x. The expression reads y. -
y = remainderStores the new value in y. The expression reads remainder. -
@warning_ignore("integer_division")This annotation gives Godot extra information about the declaration that follows. -
return a * b / maxi(1, x)Finishes the function and hands its result back to the caller. The expression calculates a new value from the expressions on either side of the operator. -
static func _code(level: Dictionary, state: Dictionary) -> int:Defines code, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var position: Vector2i = state["pos"]Creates a variable named position. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var phase: int = int(state["turn"]) % int(level["period"])Creates a variable named phase. The expression converts a suitable value to a whole number. The type after the colon says what kind of value it can hold. -
var parcel_state: int = int(state["held"]) + 1 + 4 * int(state["arrived"])Creates a variable named parcel_state. The expression converts a suitable value to a whole number. The type after the colon says what kind of value it can hold. -
return position.x + WIDTH * (position.y + HEIGHT * (parcel_state + 32 * phase))Finishes the function and hands its result back to the caller. The expression calculates a new value from the expressions on either side of the operator. -
static func find_route(level: Dictionary, state: Dictionary) -> Array[int]:Defines find route, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var route: Array[int] = []Creates a variable named route. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
if is_complete(level, state):Checks is_complete(level, state). The indented instructions below run only if this test passes. -
return routeFinishes the function and hands its result back to the caller. The expression reads route. -
var queue := [state]Creates a variable named queue. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
var parent := {_code(level, state): [-1, -1]}Creates a variable named parent. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value. -
var cursor := 0Creates a variable named cursor. The expression uses the whole number 0. Godot infers the type from the first value. -
var found := -1Creates a variable named found. The expression reads -1. Godot infers the type from the first value. -
while cursor < queue.size() and found == -1:Keeps repeating while cursor < queue.size() and found == -1 stays true. The loop body should eventually change the result or leave with break. -
var old: Dictionary = queue[cursor]Creates a variable named old. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
cursor += 1Reads cursor, adds to its old value, then stores the result back in the same place. -
var old_code := _code(level, old)Creates a variable named old_code. The expression calls _code with the values in its parentheses. Godot infers the type from the first value. -
for direction in range(STEPS.size()):Repeats the indented instructions for each value in range(STEPS.size()). -
var future := next_state(level, old, direction)Creates a variable named future. The expression calls next_state with the values in its parentheses. Godot infers the type from the first value. -
if future.is_empty():Checks future.is_empty(). The indented instructions below run only if this test passes. -
continueSkips the rest of this turn through the loop and moves on to the next item. -
var code := _code(level, future)Creates a variable named code. The expression calls _code with the values in its parentheses. Godot infers the type from the first value. -
if parent.has(code):Checks parent.has(code). The indented instructions below run only if this test passes. -
continueSkips the rest of this turn through the loop and moves on to the next item. -
parent[code] = [old_code, direction]Stores the new value in parent[code]. The expression makes a list whose items keep their order. -
if is_complete(level, future):Checks is_complete(level, future). The indented instructions below run only if this test passes. -
found = codeStores the new value in found. The expression reads code. -
breakLeaves the loop immediately and continues with code after the loop. -
queue.append(future)Adds an item to the end of a list. -
while found != -1:Keeps repeating while found != -1 stays true. The loop body should eventually change the result or leave with break. -
var link: Array = parent[found]Creates a variable named link. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
if link[1] >= 0:Checks link[1] >= 0. The indented instructions below run only if this test passes. -
route.append(link[1])Adds an item to the end of a list. -
found = link[0]Stores the new value in found. The expression looks up the item or key written between the square brackets. -
route.reverse()Calls route.reverse with the values in its parentheses. -
return routeFinishes the function and hands its result back to the caller. The expression reads route.
Read scripts/deck_board.gd line by line
-
extends ControlStarts with Godot's Control type. This script gets the abilities of that type and adds the game's own rules. -
signal direction_requested(direction: int)Defines an event this node can send. Listeners can connect functions to react when it happens. -
const Rules = preload("res://scripts/route_rules.gd")Creates a constant named Rules. The expression prepares a resource at a fixed project path when the script is loaded. -
const CELL := 53.0Creates a constant named CELL. The expression reads 53.0. Godot infers the type from the first value. -
const BOARD_INK := Color("#0e2230")Creates a constant named BOARD_INK. The expression builds a colour from these values. Godot infers the type from the first value. -
const FOAM := Color("#f7f1dc")Creates a constant named FOAM. The expression builds a colour from these values. Godot infers the type from the first value. -
const GOLD := Color("#ffd890")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value. -
const TURQUOISE := Color("#85eddf")Creates a constant named TURQUOISE. The expression builds a colour from these values. Godot infers the type from the first value. -
const CARGO := [Color("#f6be7f"), Color("#a9ded4"), Color("#dcc2fb")]Creates a constant named CARGO. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const MARKS := ["A", "B", "C"]Creates a constant named MARKS. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const ARROWS := ["↑", "→", "↓", "←", "WAIT"]Creates a constant named ARROWS. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const FONT = preload("res://art/lettering_theme.tres")Creates a constant named FONT. The expression prepares a resource at a fixed project path when the script is loaded. -
var level := {}Creates a variable named level. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value. -
var state := {}Creates a variable named state. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value. -
var hint_direction := -1Creates a variable named hint_direction. The expression reads -1. Godot infers the type from the first value. -
var accent := TURQUOISECreates a variable named accent. The expression reads TURQUOISE. Godot infers the type from the first value. -
var input_enabled := trueCreates a variable named input_enabled. The expression uses the yes-or-no value true. Godot infers the type from the first value. -
var drag_origin := Vector2.ZEROCreates a variable named drag_origin. The expression reads Vector2.ZERO. Godot infers the type from the first value. -
func _ready() -> void:Godot calls this once after the scene and its children are ready. Use it to set up the room and connect controls. -
mouse_filter = Control.MOUSE_FILTER_STOPUpdates mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_STOP. -
tooltip_text = "Tap a neighbouring tile or swipe in a direction. The luggage carts move after each successful action."Stores the new value in tooltip_text. The expression uses the text inside the quotes. -
func set_board(new_level: Dictionary, new_state: Dictionary, tint: Color, hint: int = -1) -> void:Defines set board, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
level = new_levelStores the new value in level. The expression reads new_level. -
state = new_stateStores the new value in state. The expression reads new_state. -
accent = tintStores the new value in accent. The expression reads tint. -
hint_direction = hintStores the new value in hint_direction. The expression reads hint. -
queue_redraw()Asks Godot to call _draw again on a later frame so the screen matches the new state. -
func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state. -
if level.is_empty() or state.is_empty():Checks level.is_empty() or state.is_empty(). The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var overall := Rect2(Vector2(-8, -8), size + Vector2(16, 16))Creates a variable named overall. The expression describes a position and a size. Godot infers the type from the first value. -
_panel(overall, BOARD_INK, Color("#526b78"), 8)Calls _panel with the values in its parentheses. -
for y in range(Rules.HEIGHT):Repeats the indented instructions for each value in range(Rules.HEIGHT). -
for x in range(Rules.WIDTH):Repeats the indented instructions for each value in range(Rules.WIDTH). -
_tile(Vector2i(x, y))Calls _tile with the values in its parentheses. -
_markers()Calls _markers with the values in its parentheses. -
_draw_carts()Calls _draw_carts with the values in its parentheses. -
_draw_crew()Calls _draw_crew with the values in its parentheses. -
if hint_direction >= 0:Checks hint_direction >= 0. The indented instructions below run only if this test passes. -
_draw_hint()Calls _draw_hint with the values in its parentheses. -
func _tile(cell: Vector2i) -> void:Defines tile, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var offset := Vector2(cell) * CELLCreates a variable named offset. The expression packs x and y into one value. Godot infers the type from the first value. -
if not Rules.walkable(level, cell):Checks not Rules.walkable(level, cell). The indented instructions below run only if this test passes. -
var outer := Rect2(offset + Vector2(1, 1), Vector2(CELL - 2, CELL - 2))Creates a variable named outer. The expression describes a position and a size. Godot infers the type from the first value. -
_panel(outer, Color("#2b4551"), Color("#4e6569"), 3)Calls _panel with the values in its parentheses. -
draw_line(offset + Vector2(6, 8), offset + Vector2(CELL - 7, 8), Color("#647575"), 1.0)Paints a line between two points with the chosen colour and width. -
draw_line(offset + Vector2(6, 43), offset + Vector2(CELL - 7, 43), Color("#1e3744"), 1.0)Paints a line between two points with the chosen colour and width. -
draw_circle(offset + Vector2(8, 8), 2, Color("#998b6e"), true, -1.0, true)Paints a filled circle or outline in this node's local coordinates. -
draw_circle(offset + Vector2(CELL - 9, 8), 2, Color("#998b6e"), true, -1.0, true)Paints a filled circle or outline in this node's local coordinates. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var floor_colour := Color("#132f3c") if (cell.x + cell.y) % 2 == 0 else Color("#153441")Creates a variable named floor_colour. The expression builds a colour from these values. Godot infers the type from the first value. -
draw_rect(Rect2(offset + Vector2(1, 1), Vector2(CELL - 2, CELL - 2)), floor_colour)Paints a rectangle at the given position and size. -
for seam in [14, 36]:Repeats the indented instructions for each value in [14, 36]. -
draw_line(offset + Vector2(2, seam), offset + Vector2(CELL - 2, seam), Color("#1b3c47"), 1.0)Paints a line between two points with the chosen colour and width. -
func _markers() -> void:Defines markers, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var exit_cell: Vector2i = level["exit"]Creates a variable named exit_cell. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var exit_pt := _centre(exit_cell)Creates a variable named exit_pt. The expression calls _centre with the values in its parentheses. Godot infers the type from the first value. -
var all_arrived: bool = Rules.count_delivered(level, state) == level["drops"].size()Creates a variable named all_arrived. The expression calls Rules.count_delivered with the values in its parentheses. The type after the colon says what kind of value it can hold. -
var exit_colour := accent if all_arrived else Color("#a7b4b8")Creates a variable named exit_colour. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
_panel(Rect2(exit_pt - Vector2(20, 19), Vector2(40, 38)), Color("#17354a"), exit_colour, 7)Calls _panel with the values in its parentheses. -
_text(exit_pt + Vector2(0, -4), "OUT", 12, exit_colour)Calls _text with the values in its parentheses. -
_text(exit_pt + Vector2(0, 12), "✓" if all_arrived else "·", 17, exit_colour)Calls _text with the values in its parentheses. -
for cell in level["lifts"]:Repeats the indented instructions for each value in level["lifts"]. -
var point := _centre(cell)Creates a variable named point. The expression calls _centre with the values in its parentheses. Godot infers the type from the first value. -
_panel(Rect2(point - Vector2(19, 19), Vector2(38, 38)), Color("#3e4159"), Color("#dcc2fb"), 7)Calls _panel with the values in its parentheses. -
_text(point + Vector2(0, -4), str(level["lifts"][cell]["number"]), 18, Color("#fff1ff"))Calls _text with the values in its parentheses. -
_text(point + Vector2(0, 12), "LIFT", 9, Color("#e8d7f0"))Calls _text with the values in its parentheses. -
for i in range(level["drops"].size()):Repeats the indented instructions for each value in range(level["drops"].size()). -
var point := _centre(level["drops"][i])Creates a variable named point. The expression calls _centre with the values in its parentheses. Godot infers the type from the first value. -
var delivered := (int(state["arrived"]) & (1 << i)) != 0Creates a variable named delivered. The expression evaluates the test to see whether it is true or false. Godot infers the type from the first value. -
var shade: Color = CARGO[i]Creates a variable named shade. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
_panel(Rect2(point - Vector2(18, 18), Vector2(36, 36)), Color("#233949"), shade, 18)Calls _panel with the values in its parentheses. -
_text(point, "✓" if delivered else MARKS[i], 20, shade)Calls _text with the values in its parentheses. -
for i in range(level["pickups"].size()):Repeats the indented instructions for each value in range(level["pickups"].size()). -
if state["held"] != i and (int(state["arrived"]) & (1 << i)) == 0:Checks state["held"] != i and (int(state["arrived"]) & (1 << i)) == 0. The indented instructions below run only if this test passes. -
_parcel(_centre(level["pickups"][i]), i, false)Calls _parcel with the values in its parentheses. -
func _parcel(point: Vector2, mark: int, mini: bool) -> void:Defines parcel, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var shade: Color = CARGO[mark]Creates a variable named shade. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var r := 11.0 if mini else 16.0Creates a variable named r. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
_panel(Rect2(point - Vector2(r, r), Vector2(2.0 * r, 2.0 * r)), shade, Color("#fff1d2"), 4)Calls _panel with the values in its parentheses. -
draw_line(point + Vector2(-r + 3, -r + 4), point + Vector2(r - 3, -r + 4), Color("#a98058"), 1.0)Paints a line between two points with the chosen colour and width. -
_text(point + Vector2(0, 1), MARKS[mark], 14 if mini else 19, BOARD_INK)Calls _text with the values in its parentheses. -
func _draw_carts() -> void:Defines draw carts, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var current := Rules.cart_positions(level, state["turn"])Creates a variable named current. The expression calls Rules.cart_positions with the values in its parentheses. Godot infers the type from the first value. -
var next := Rules.cart_positions(level, state["turn"] + 1)Creates a variable named next. The expression calls Rules.cart_positions with the values in its parentheses. Godot infers the type from the first value. -
# Mark every destination first so a current cart can cover its own mark.A comment for the reader. Godot skips it when it runs the code. -
for i in range(next.size()):Repeats the indented instructions for each value in range(next.size()). -
var point := _centre(next[i])Creates a variable named point. The expression calls _centre with the values in its parentheses. Godot infers the type from the first value. -
draw_arc(point, 18, 0, TAU, 22, Color("#d88c85"), 1.5, true)Calls draw_arc with the values in its parentheses. -
for i in range(current.size()):Repeats the indented instructions for each value in range(current.size()). -
var point := _centre(current[i])Creates a variable named point. The expression calls _centre with the values in its parentheses. Godot infers the type from the first value. -
_panel(Rect2(point - Vector2(18, 14), Vector2(36, 28)), Color("#df8b7d"), Color("#ffd5bd"), 8)Calls _panel with the values in its parentheses. -
_text(point, "CART", 10, BOARD_INK)Calls _text with the values in its parentheses. -
draw_circle(point + Vector2(-10, 16), 3, FOAM, true, -1.0, true)Paints a filled circle or outline in this node's local coordinates. -
draw_circle(point + Vector2(10, 16), 3, FOAM, true, -1.0, true)Paints a filled circle or outline in this node's local coordinates. -
func _draw_crew() -> void:Defines draw crew, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var point := _centre(state["pos"])Creates a variable named point. The expression calls _centre with the values in its parentheses. Godot infers the type from the first value. -
draw_circle(point + Vector2(0, 2), 20, Color("#0a1a2b"), true, -1.0, true)Paints a filled circle or outline in this node's local coordinates. -
draw_circle(point, 17, Color("#d7f5ea"), true, -1.0, true)Paints a filled circle or outline in this node's local coordinates. -
draw_circle(point, 15, accent, true, -1.0, true)Paints a filled circle or outline in this node's local coordinates. -
draw_line(point + Vector2(-10, -3), point + Vector2(10, -3), BOARD_INK, 2, true)Paints a line between two points with the chosen colour and width. -
_text(point + Vector2(0, 5), "CREW", 7, BOARD_INK)Calls _text with the values in its parentheses. -
var held: int = state["held"]Creates a variable named held. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
if held >= 0:Checks held >= 0. The indented instructions below run only if this test passes. -
_parcel(point + Vector2(15, 13), held, true)Calls _parcel with the values in its parentheses. -
func _draw_hint() -> void:Defines draw hint, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var tile: Vector2i = state["pos"] + Rules.STEPS[hint_direction]Creates a variable named tile. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var point := _centre(tile)Creates a variable named point. The expression calls _centre with the values in its parentheses. Godot infers the type from the first value. -
_panel(Rect2(point - Vector2(22, 22), Vector2(44, 44)), Color(0.07, 0.27, 0.35, 0.96), GOLD, 7)Calls _panel with the values in its parentheses. -
_text(point, ARROWS[hint_direction], 13 if hint_direction == Rules.WAIT else 27, GOLD)Calls _text with the values in its parentheses. -
func _centre(tile: Vector2i) -> Vector2:Defines centre, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
return (Vector2(tile) + Vector2(0.5, 0.5)) * CELLFinishes the function and hands its result back to the caller. The expression calculates a new value from the expressions on either side of the operator. -
func _text(point: Vector2, text: String, font_size: int, colour: Color) -> void:Defines text, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var face := FONT.default_fontCreates a variable named face. The expression reads FONT.default_font. Godot infers the type from the first value. -
var bounds := face.get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size)Creates a variable named bounds. The expression calls face.get_string_size with the values in its parentheses. Godot infers the type from the first value. -
var baseline := point.y + (face.get_ascent(font_size) - face.get_descent(font_size)) * 0.5Creates a variable named baseline. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value. -
draw_string(face, Vector2(point.x - bounds.x / 2.0, baseline), text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, colour)Paints a piece of text with a font at a position measured from the node's origin. -
func _panel(rect: Rect2, fill: Color, outline: Color, radius: int) -> void:Defines panel, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var paint := StyleBoxFlat.new()Creates a variable named paint. The expression creates a new StyleBoxFlat object. Godot infers the type from the first value. -
paint.bg_color = fillStores the new value in paint.bg_color. The expression reads fill. -
paint.border_color = outlineStores the new value in paint.border_color. The expression reads outline. -
paint.set_border_width_all(1)Calls paint.set_border_width_all with the values in its parentheses. -
paint.set_corner_radius_all(radius)Calls paint.set_corner_radius_all with the values in its parentheses. -
draw_style_box(paint, rect)Calls draw_style_box with the values in its parentheses. -
func _gui_input(event: InputEvent) -> void:Godot calls this when the control receives an input event such as a tap. -
if not input_enabled or state.is_empty():Checks not input_enabled or state.is_empty(). The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:Checks event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT. The indented instructions below run only if this test passes. -
if event.pressed:Checks event.pressed. The indented instructions below run only if this test passes. -
drag_origin = event.positionStores the new value in drag_origin. The expression reads event.position. -
accept_event()Calls accept_event with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var swipe: Vector2 = event.position - drag_originCreates a variable named swipe. The expression calculates a new value from the expressions on either side of the operator. The type after the colon says what kind of value it can hold. -
if swipe.length() >= 25.0:Checks swipe.length() >= 25.0. The indented instructions below run only if this test passes. -
if absf(swipe.x) > absf(swipe.y):Checks absf(swipe.x) > absf(swipe.y). The indented instructions below run only if this test passes. -
direction_requested.emit(Rules.EAST if swipe.x > 0 else Rules.WEST)Sends a signal to anything listening. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
direction_requested.emit(Rules.SOUTH if swipe.y > 0 else Rules.NORTH)Sends a signal to anything listening. -
accept_event()Calls accept_event with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var target := Vector2i((event.position / CELL).floor())Creates a variable named target. The expression packs whole-number x and y into one grid position. Godot infers the type from the first value. -
var difference: Vector2i = target - state["pos"]Creates a variable named difference. The expression looks up the item or key written between the square brackets. The type after the colon says what kind of value it can hold. -
var direction := Rules.STEPS.find(difference)Creates a variable named direction. The expression calls Rules.STEPS.find with the values in its parentheses. Godot infers the type from the first value. -
if direction >= 0 and direction < Rules.WAIT:Checks direction >= 0 and direction < Rules.WAIT. The indented instructions below run only if this test passes. -
direction_requested.emit(direction)Sends a signal to anything listening. -
accept_event()Calls accept_event with the values in its parentheses.
Read scripts/catalog.gd line by line
-
extends RefCountedStarts with Godot's RefCounted type. This script gets the abilities of that type and adds the game's own rules. -
const Rules = preload("res://scripts/route_rules.gd")Creates a constant named Rules. The expression prepares a resource at a fixed project path when the script is loaded. -
const COURSE_FILE := "res://levels/catalog.json"Creates a constant named COURSE_FILE. The expression uses the text inside the quotes. Godot infers the type from the first value. -
static func read() -> Array[Dictionary]:Defines read, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var deck_list: Array[Dictionary] = []Creates a variable named deck_list. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var source := FileAccess.open(COURSE_FILE, FileAccess.READ)Creates a variable named source. The expression tries to open a file and returns a handle, or null if opening fails. Godot infers the type from the first value. -
if source == null:Checks source == null. The indented instructions below run only if this test passes. -
push_error("The ship's course manifest could not be opened.")Reports an error message to help you find a problem. -
return deck_listFinishes the function and hands its result back to the caller. The expression reads deck_list. -
var json := JSON.new()Creates a variable named json. The expression creates a new JSON object. Godot infers the type from the first value. -
if json.parse(source.get_as_text()) != OK or not json.data is Array:Checks json.parse(source.get_as_text()) != OK or not json.data is Array. The indented instructions below run only if this test passes. -
push_error("The ship's course manifest could not be read.")Reports an error message to help you find a problem. -
return deck_listFinishes the function and hands its result back to the caller. The expression reads deck_list. -
for record in json.data:Repeats the indented instructions for each value in json.data. -
deck_list.append(Rules.parse_level(record))Adds an item to the end of a list. -
return deck_listFinishes the function and hands its result back to the caller. The expression reads deck_list.
Read scripts/progress.gd line by line
-
extends RefCountedStarts with Godot's RefCounted type. This script gets the abilities of that type and adds the game's own rules. -
const STORAGE := "user://deck_progress.cfg"Creates a constant named STORAGE. The expression uses the text inside the quotes. Godot infers the type from the first value. -
static func restore(storage: String = STORAGE) -> Dictionary:Defines restore, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var config := ConfigFile.new()Creates a variable named config. The expression creates a new ConfigFile object. Godot infers the type from the first value. -
if config.load(storage) != OK:Checks config.load(storage) != OK. The indented instructions below run only if this test passes. -
return {"done": -1, "sound": true}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var done: Variant = config.get_value("campaign", "complete", -1)Creates a variable named done. The expression calls config.get_value with the values in its parentheses. The type after the colon says what kind of value it can hold. -
var sound: Variant = config.get_value("settings", "sound", true)Creates a variable named sound. The expression calls config.get_value with the values in its parentheses. The type after the colon says what kind of value it can hold. -
return {"done": done if done is int else -1, "sound": sound if sound is bool else true}Finishes the function and hands its result back to the caller. The expression chooses one of two values by checking the condition in the middle. -
static func save(done: int, sound: bool, storage: String = STORAGE) -> Error:Defines save, a reusable set of instructions. Parameters between the parentheses receive inputs. A return type after the arrow tells you which kind of result to expect. -
var config := ConfigFile.new()Creates a variable named config. The expression creates a new ConfigFile object. Godot infers the type from the first value. -
config.set_value("campaign", "complete", done)Calls config.set_value with the values in its parentheses. -
config.set_value("settings", "sound", sound)Calls config.set_value with the values in its parentheses. -
return config.save(storage)Finishes the function and hands its result back to the caller. The expression calls config.save with the values in its parentheses.