Follow a market turn
- Receive an action. Read a move, a pickup or a request to hand over the order.
- Check the rules. Confirm the path is open, the right stall is under Nia and there is room in the basket.
- Apply the action. Move Nia, collect an item or hand over the matching basket at the collection counter. A valid action costs one turn.
- Refresh the market. Update the map, basket and order slip. At the end of the shift, keep the best badge on this device.
The hint uses the same move and order rules to compare possible routes. It shows the next action from a shortest route it finds.
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/market.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/market_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/shift_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 StreetBoard = preload("res://scripts/street_board.gd")Creates a constant named StreetBoard. The expression prepares a resource at a fixed project path when the script is loaded. -
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. -
const INK := Color("#102e36")Creates a constant named INK. The expression builds a colour from these values. Godot infers the type from the first value. -
const WHITE := Color("#f8e9ca")Creates a constant named WHITE. The expression builds a colour from these values. Godot infers the type from the first value. -
const MINT := Color("#a6e3cb")Creates a constant named MINT. The expression builds a colour from these values. Godot infers the type from the first value. -
const GOLD := Color("#ffd196")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value. -
const MUTED := Color("#bdd2ca")Creates a constant named MUTED. The expression builds a colour from these values. Godot infers the type from the first value. -
const EDGE := Color("#6e9690")Creates a constant named EDGE. The expression builds a colour from these values. Godot infers the type from the first value. -
var shifts: Array[Dictionary] = []Creates a variable named shifts. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
var shift_index := 0Creates a variable named shift_index. The expression uses the whole number 0. Godot infers the type from the first value. -
var shift := {}Creates a variable named shift. 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 medals := {}Creates a variable named medals. The expression makes a dictionary that looks up values by key. Godot infers the type from the first value. -
var hint := -1Creates a variable named hint. The expression reads -1. Godot infers the type from the first value. -
var backdrops := {}Creates a variable named backdrops. The expression makes a dictionary that looks up values by key. 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 board: ControlDeclares board for later use. A colon followed by a type says which kind of value belongs here. -
var group_label: LabelDeclares group_label for later use. A colon followed by a type says which kind of value belongs here. -
var title: LabelDeclares title for later use. A colon followed by a type says which kind of value belongs here. -
var mission: LabelDeclares mission for later use. A colon followed by a type says which kind of value belongs here. -
var order: LabelDeclares order for later use. A colon followed by a type says which kind of value belongs here. -
var basket: LabelDeclares basket for later use. A colon followed by a type says which kind of value belongs here. -
var turns: LabelDeclares turns 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 next_button: ButtonDeclares next_button for later use. A colon followed by a type says which kind of value belongs here. -
var overlay: ControlDeclares overlay for later use. A colon followed by a type says which kind of value belongs here. -
var overlay_title: LabelDeclares overlay_title for later use. A colon followed by a type says which kind of value belongs here. -
var overlay_text: LabelDeclares overlay_text for later use. A colon followed by a type says which kind of value belongs here. -
var overlay_buttons: Array[Button] = []Creates a variable named overlay_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 overlay_close: ButtonDeclares overlay_close for later use. A colon followed by a type says which kind of value belongs here. -
var action_buttons: Array[Button] = []Creates a variable named action_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 focused_before: ControlDeclares focused_before 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. -
shifts = Catalog.read()Stores the new value in shifts. The expression calls Catalog.read with the values in its parentheses. -
medals = Progress.read()["medals"]Stores the new value in medals. The expression calls Progress.read with the values in its parentheses. -
for backdrop in ["market", "rainy"]:Repeats the indented instructions for each value in ["market", "rainy"]. -
var path := "res://art/%s.jpg" % backdropCreates a variable named path. The expression uses the text inside the quotes. Godot infers the type from the first value. -
if ResourceLoader.exists(path):Checks ResourceLoader.exists(path). The indented instructions below run only if this test passes. -
backdrops[backdrop] = load(path)Stores the new value in backdrops[backdrop]. The expression reads a resource from the project when this instruction runs. -
_build_interface()Calls _build_interface with the values in its parentheses. -
if shifts.is_empty():Checks shifts.is_empty(). The indented instructions below run only if this test passes. -
status.text = "The shift list could not load. Import the complete project folder."Updates status.text, which controls the words a player sees. The expression uses the text inside the quotes. -
for button in action_buttons:Repeats the indented instructions for each value in action_buttons. -
button.disabled = trueUpdates button.disabled, which controls whether the control should ignore activation. The expression uses the yes-or-no value true. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
_open_shift(mini(_unlocked(), shifts.size() - 1))Calls _open_shift with the values in its parentheses. -
action_buttons[1].grab_focus()Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
func _style(fill: Color, border: Color, radius: int = 12, line: int = 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 style := StyleBoxFlat.new()Creates a variable named style. The expression creates a new StyleBoxFlat object. Godot infers the type from the first value. -
style.bg_color = fillStores the new value in style.bg_color. The expression reads fill. -
style.border_color = borderStores the new value in style.border_color. The expression reads border. -
style.set_corner_radius_all(radius)Calls style.set_corner_radius_all with the values in its parentheses. -
style.set_border_width_all(line)Calls style.set_border_width_all with the values in its parentheses. -
return styleFinishes the function and hands its result back to the caller. The expression reads style. -
func _panel(frame: Rect2, parent: Control, ink: Color, border: Color = EDGE, radius: int = 17) -> 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 = frame.positionUpdates panel.position, which controls the node's local x and y location. The expression reads frame.position. -
panel.size = frame.sizeUpdates panel.size, which controls the control's width and height. The expression reads frame.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(ink, border, 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 _label(value: String, frame: Rect2, font_size: int, parent: Control, ink: Color = WHITE, wrap: bool = 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 label := Label.new()Creates a variable named label. The expression creates a new Label object. Godot infers the type from the first value. -
label.position = frame.positionUpdates label.position, which controls the node's local x and y location. The expression reads frame.position. -
label.size = frame.sizeUpdates label.size, which controls the control's width and height. The expression reads frame.size. -
label.text = valueUpdates label.text, which controls the words a player sees. The expression reads value. -
label.vertical_alignment = VERTICAL_ALIGNMENT_CENTERStores the new value in label.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_CENTER. -
label.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates label.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
label.add_theme_font_size_override("font_size", font_size)Calls label.add_theme_font_size_override with the values in its parentheses. -
label.add_theme_color_override("font_color", ink)Calls label.add_theme_color_override with the values in its parentheses. -
if wrap:Checks wrap. The indented instructions below run only if this test passes. -
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMARTStores the new value in label.autowrap_mode. The expression reads TextServer.AUTOWRAP_WORD_SMART. -
parent.add_child(label)Adds the new node to the scene tree so that Godot can run and draw it. -
return labelFinishes the function and hands its result back to the caller. The expression reads label. -
func _button(value: String, frame: 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 button := Button.new()Creates a variable named button. The expression creates a new Button object. Godot infers the type from the first value. -
button.position = frame.positionUpdates button.position, which controls the node's local x and y location. The expression reads frame.position. -
button.size = frame.sizeUpdates button.size, which controls the control's width and height. The expression reads frame.size. -
button.text = valueUpdates button.text, which controls the words a player sees. The expression reads value. -
button.add_theme_font_size_override("font_size", font_size)Calls button.add_theme_font_size_override with the values in its parentheses. -
button.add_theme_color_override("font_color", WHITE)Calls button.add_theme_color_override with the values in its parentheses. -
button.add_theme_color_override("font_hover_color", WHITE)Calls button.add_theme_color_override with the values in its parentheses. -
button.add_theme_color_override("font_pressed_color", INK)Calls button.add_theme_color_override with the values in its parentheses. -
button.add_theme_color_override("font_disabled_color", MUTED.darkened(0.33))Calls button.add_theme_color_override with the values in its parentheses. -
button.add_theme_stylebox_override("normal", _style(Color("#31575b"), Color("#719792")))Calls button.add_theme_stylebox_override with the values in its parentheses. -
button.add_theme_stylebox_override("hover", _style(Color("#3b6d6e"), MINT))Calls button.add_theme_stylebox_override with the values in its parentheses. -
button.add_theme_stylebox_override("pressed", _style(MINT, WHITE))Calls button.add_theme_stylebox_override with the values in its parentheses. -
button.add_theme_stylebox_override("focus", _style(Color.TRANSPARENT, GOLD, 12, 2))Calls button.add_theme_stylebox_override with the values in its parentheses. -
button.add_theme_stylebox_override("disabled", _style(Color("#1f4149"), Color("#36585b")))Calls button.add_theme_stylebox_override with the values in its parentheses. -
button.pressed.connect(callback)Links a signal to the function that should run when the event happens. -
parent.add_child(button)Adds the new node to the scene tree so that Godot can run and draw it. -
return buttonFinishes the function and hands its result back to the caller. The expression reads button. -
func _build_interface() -> void:Defines build interface, 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 colour := ColorRect.new()Creates a variable named colour. The expression creates a new ColorRect object. Godot infers the type from the first value. -
colour.size = VIEWUpdates colour.size, which controls the control's width and height. The expression reads VIEW. -
colour.color = Color("#325862")Stores the new value in colour.color. The expression builds a colour from these values. -
colour.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates colour.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
add_child(colour)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. -
_panel(Rect2(22, 18, 1236, 91), self, Color(0.044, 0.123, 0.151, 0.97))Calls _panel with the values in its parentheses. -
_label("MARKET DAY LONDON", Rect2(48, 33, 670, 54), 44, self)Calls _label with the values in its parentheses. -
group_label = _label("", Rect2(803, 22, 423, 27), 19, self, MINT)Stores the new value in group_label. The expression calls _label with the values in its parentheses. -
group_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHTStores the new value in group_label.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_RIGHT. -
title = _label("", Rect2(773, 50, 453, 40), 30, self)Stores the new value in title. The expression calls _label with the values in its parentheses. -
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHTStores the new value in title.horizontal_alignment. The expression reads HORIZONTAL_ALIGNMENT_RIGHT. -
board = StreetBoard.new()Stores the new value in board. The expression creates a new StreetBoard object. -
board.position = Vector2(22, 125)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(702, 506)Updates board.size, which controls the control's width and height. The expression packs x and y into one value. -
board.action_selected.connect(_take_action)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(737, 125, 521, 506), self, Color(0.062, 0.161, 0.192, 0.98))Calls _panel with the values in its parentheses. -
mission = _label("", Rect2(758, 141, 475, 88), 20, self, WHITE, true)Stores the new value in mission. The expression calls _label with the values in its parentheses. -
mission.vertical_alignment = VERTICAL_ALIGNMENT_TOPStores the new value in mission.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_TOP. -
turns = _label("", Rect2(758, 236, 475, 27), 17, self, MUTED)Stores the new value in turns. The expression calls _label with the values in its parentheses. -
_panel(Rect2(757, 275, 482, 61), self, Color("#285355"), Color("#6d9590"), 12)Calls _panel with the values in its parentheses. -
order = _label("", Rect2(774, 280, 448, 52), 20, self, WHITE)Stores the new value in order. The expression calls _label with the values in its parentheses. -
basket = _label("", Rect2(758, 343, 475, 44), 18, self, MINT)Stores the new value in basket. The expression calls _label with the values in its parentheses. -
var moves := ["↑ North", "→ East", "↓ South", "← West"]Creates a variable named moves. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
for index in range(moves.size()):Repeats the indented instructions for each value in range(moves.size()). -
action_buttons.append(_button(moves[index], Rect2(754 + index * 122, 401, 115, 54), self, _take_action.bind(index), 17))Adds an item to the end of a list. -
action_buttons.append(_button("Pick up", Rect2(754, 466, 235, 51), self, _take_action.bind(Rules.PICK), 19))Adds an item to the end of a list. -
action_buttons.append(_button("Hand over", Rect2(999, 466, 235, 51), self, _take_action.bind(Rules.HANDOVER), 19))Adds an item to the end of a list. -
status = _label("", Rect2(758, 531, 475, 83), 18, self, MINT, 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. -
_panel(Rect2(22, 645, 1236, 56), self, Color(0.044, 0.123, 0.151, 0.98))Calls _panel with the values in its parentheses. -
_button("Shifts", Rect2(36, 652, 105, 42), self, _show_shifts)Calls _button with the values in its parentheses. -
_button("How to play", Rect2(151, 652, 145, 42), self, _show_help)Calls _button with the values in its parentheses. -
_button("Route hint", Rect2(306, 652, 137, 42), self, _show_hint)Calls _button with the values in its parentheses. -
_button("Restart shift", Rect2(453, 652, 149, 42), self, _restart)Calls _button with the values in its parentheses. -
_label("Tap neighbouring tiles or use arrow keys", Rect2(625, 653, 381, 40), 16, self, MUTED)Calls _label with the values in its parentheses. -
next_button = _button("Next shift →", Rect2(1010, 652, 233, 42), self, _next_shift)Stores the new value in next_button. The expression calls _button with the values in its parentheses. -
_build_overlay()Calls _build_overlay with the values in its parentheses. -
func _build_overlay() -> void:Defines build overlay, 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. -
overlay = Control.new()Stores the new value in overlay. The expression creates a new Control object. -
overlay.size = VIEWUpdates overlay.size, which controls the control's width and height. The expression reads VIEW. -
overlay.mouse_filter = Control.MOUSE_FILTER_STOPUpdates overlay.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_STOP. -
add_child(overlay)Adds the new node to the scene tree so that Godot can run and draw it. -
var veil := ColorRect.new()Creates a variable named veil. The expression creates a new ColorRect object. Godot infers the type from the first value. -
veil.size = VIEWUpdates veil.size, which controls the control's width and height. The expression reads VIEW. -
veil.color = Color(0.013, 0.03, 0.05, 0.76)Stores the new value in veil.color. The expression builds a colour from these values. -
veil.mouse_filter = Control.MOUSE_FILTER_IGNOREUpdates veil.mouse_filter, which controls how this control participates in pointer and touch input. The expression reads Control.MOUSE_FILTER_IGNORE. -
overlay.add_child(veil)Adds the new node to the scene tree so that Godot can run and draw it. -
_panel(Rect2(173, 103, 934, 517), overlay, Color("#173940"), EDGE, 20)Calls _panel with the values in its parentheses. -
overlay_title = _label("", Rect2(206, 132, 840, 53), 34, overlay)Stores the new value in overlay_title. The expression calls _label with the values in its parentheses. -
overlay_text = _label("", Rect2(206, 194, 869, 300), 22, overlay, WHITE, true)Stores the new value in overlay_text. The expression calls _label with the values in its parentheses. -
overlay_text.vertical_alignment = VERTICAL_ALIGNMENT_TOPStores the new value in overlay_text.vertical_alignment. The expression reads VERTICAL_ALIGNMENT_TOP. -
for index in range(9):Repeats the indented instructions for each value in range(9). -
var rect := Rect2(206 + (index % 3) * 290, 260 + floori(index / 3.0) * 72, 272, 60)Creates a variable named rect. The expression describes a position and a size. Godot infers the type from the first value. -
overlay_buttons.append(_button("", rect, overlay, _choose_shift.bind(index)))Adds an item to the end of a list. -
overlay_close = _button("Back to market", Rect2(206, 541, 190, 46), overlay, _close_overlay, 18)Stores the new value in overlay_close. The expression calls _button with the values in its parentheses. -
overlay.hide()Makes this control invisible. -
func _unlocked() -> int:Defines unlocked, 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 next := 0Creates a variable named next. The expression uses the whole number 0. Godot infers the type from the first value. -
while next < shifts.size() and int(medals.get(next, 0)) > 0:Keeps repeating while next < shifts.size() and int(medals.get(next, 0)) > 0 stays true. The loop body should eventually change the result or leave with break. -
next += 1Reads next, adds to its old value, then stores the result back in the same place. -
return nextFinishes the function and hands its result back to the caller. The expression reads next. -
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. -
overlay_title.text = "How to run a market shift"Updates overlay_title.text, which controls the words a player sees. The expression uses the text inside the quotes. -
overlay_text.text = "Check the customer's order. Move Nia to a stall and select Pick up. Her basket has three spaces. Each legal move, pickup or handover spends one turn. An invalid action spends none.\n\nGo back to the collection counter with the exact items and select Hand over. Finish every bundle to complete the shift. Reaching the turn target earns a gold mark.\n\nTap an adjacent tile or use the arrow keys. Press P to pick up and H to hand over. Choose Route hint for the next move."Updates overlay_text.text, which controls the words a player sees. The expression uses the text inside the quotes. -
for button in overlay_buttons:Repeats the indented instructions for each value in overlay_buttons. -
button.hide()Makes this control invisible. -
_show_overlay()Calls _show_overlay with the values in its parentheses. -
func _show_shifts() -> void:Defines show shifts, 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. -
overlay_title.text = "Pick a market shift"Updates overlay_title.text, which controls the words a player sees. The expression uses the text inside the quotes. -
overlay_text.text = "Complete each shift to unlock the next. A star marks a shift finished on target."Updates overlay_text.text, which controls the words a player sees. The expression uses the text inside the quotes. -
for index in range(overlay_buttons.size()):Repeats the indented instructions for each value in range(overlay_buttons.size()). -
var button := overlay_buttons[index]Creates a variable named button. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value. -
if index >= shifts.size():Checks index >= shifts.size(). The indented instructions below run only if this test passes. -
button.hide()Makes this control invisible. -
continueSkips the rest of this turn through the loop and moves on to the next item. -
var mark: int = medals.get(index, 0)Creates a variable named mark. The expression looks up a named or indexed value, using a fallback when the call gives one. The type after the colon says what kind of value it can hold. -
button.text = "%02d %s%s" % [index + 1, shifts[index]["name"], " ★" if mark == 2 else " ✓" if mark == 1 else ""]Updates button.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle. -
button.disabled = index > _unlocked()Updates button.disabled, which controls whether the control should ignore activation. The expression reads index > _unlocked(). -
button.show()Makes this control visible. -
_show_overlay()Calls _show_overlay with the values in its parentheses. -
func _show_overlay() -> void:Defines show overlay, 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. -
focused_before = get_viewport().gui_get_focus_owner()Stores the new value in focused_before. The expression calls get_viewport with the values in its parentheses. -
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_NONEStores the new value in child.focus_mode. The expression reads Control.FOCUS_NONE. -
overlay.show()Makes this control visible. -
overlay_close.grab_focus()Gives this control keyboard focus so Space, Enter or arrow keys can reach it. -
func _close_overlay() -> void:Defines close overlay, 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. -
overlay.hide()Makes this control invisible. -
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_ALLStores the new value in child.focus_mode. The expression reads Control.FOCUS_ALL. -
if is_instance_valid(focused_before):Checks is_instance_valid(focused_before). The indented instructions below run only if this test passes. -
focused_before.grab_focus()Gives this control keyboard focus so Space, Enter or arrow keys can reach it. -
func _choose_shift(index: int) -> void:Defines choose shift, 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 index <= _unlocked():Checks index <= _unlocked(). The indented instructions below run only if this test passes. -
_close_overlay()Calls _close_overlay with the values in its parentheses. -
_open_shift(index)Calls _open_shift with the values in its parentheses. -
func _open_shift(index: int) -> void:Defines open shift, 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. -
shift_index = clampi(index, 0, shifts.size() - 1)Stores the new value in shift_index. The expression keeps a whole number within the chosen bounds. -
shift = shifts[shift_index]Stores the new value in shift. The expression looks up the item or key written between the square brackets. -
state = Rules.start(shift)Stores the new value in state. The expression calls Rules.start with the values in its parentheses. -
hint = -1Stores the new value in hint. The expression reads -1. -
background.texture = backdrops.get("rainy", backdrops.get("market")) if shift["group"] == "After the Rain" else backdrops.get("market")Stores the new value in background.texture. The expression looks up a named or indexed value, using a fallback when the call gives one. -
title.text = shift["name"]Updates title.text, which controls the words a player sees. The expression looks up the item or key written between the square brackets. -
group_label.text = "%s · %02d / %02d" % [shift["group"], shift_index + 1, shifts.size()]Updates group_label.text, which controls the words a player sees. The expression uses the text inside the quotes. -
mission.text = shift["brief"]Updates mission.text, which controls the words a player sees. The expression looks up the item or key written between the square brackets. -
_refresh("Find the first stall on your list.")Calls _refresh with the values in its parentheses. -
func _refresh(message: String) -> void:Defines refresh, 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 complete := Rules.is_complete(shift, state)Creates a variable named complete. The expression calls Rules.is_complete with the values in its parentheses. Godot infers the type from the first value. -
turns.text = "Turn %d / target %d · %d of %d bundles ready" % [state["turns"], shift["par"], state["order"], shift["orders"].size()]Updates turns.text, which controls the words a player sees. The expression uses the text inside the quotes. -
order.text = "All orders collected" if complete else "Order %d %s" % [int(state["order"]) + 1, Rules.describe_items(Rules.needed(shift, state))]Updates order.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle. -
basket.text = "Basket %d / %d %s" % [Rules.load_size(state), Rules.CAPACITY, Rules.describe_items(state["bag"])]Updates basket.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. -
next_button.disabled = not completeUpdates next_button.disabled, which controls whether the control should ignore activation. The expression reads not complete. -
next_button.text = "View market shifts" if shift_index == shifts.size() - 1 else "Next shift →"Updates next_button.text, which controls the words a player sees. The expression chooses one of two values by checking the condition in the middle. -
for index in range(action_buttons.size()):Repeats the indented instructions for each value in range(action_buttons.size()). -
var button := action_buttons[index]Creates a variable named button. The expression looks up the item or key written between the square brackets. Godot infers the type from the first value. -
button.disabled = completeUpdates button.disabled, which controls whether the control should ignore activation. The expression reads complete. -
button.modulate = GOLD if index == hint else WHITEUpdates button.modulate, which controls the colour and transparency used to tint this node and its children. The expression chooses one of two values by checking the condition in the middle. -
board.update_board(shift, state, hint)Calls board.update_board with the values in its parentheses. -
func _take_action(action: int) -> void:Defines take action, 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 shift.is_empty() or overlay.visible or Rules.is_complete(shift, state):Checks shift.is_empty() or overlay.visible or Rules.is_complete(shift, 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 next := Rules.step(shift, state, action)Creates a variable named next. The expression calls Rules.step 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. -
_refresh(Rules.reason(shift, state, action))Calls _refresh with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
state = nextStores the new value in state. The expression reads next. -
hint = -1Stores the new value in hint. The expression reads -1. -
if Rules.is_complete(shift, state):Checks Rules.is_complete(shift, state). The indented instructions below run only if this test passes. -
var mark := 2 if state["turns"] <= shift["par"] else 1Creates a variable named mark. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
medals[shift_index] = maxi(mark, int(medals.get(shift_index, 0)))Stores the new value in medals[shift_index]. The expression calls maxi with the values in its parentheses. -
var result := "Gold! All orders handed over on target." if mark == 2 else "Shift complete. All orders collected."Creates a variable named result. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
var saved := Progress.write(medals) == OKCreates a variable named saved. The expression calls Progress.write with the values in its parentheses. Godot infers the type from the first value. -
_refresh(result if saved else result + " Progress could not be saved.")Calls _refresh with the values in its parentheses. -
elif action == Rules.HANDOVER:If the earlier branches did not run, checks action == Rules.HANDOVER next. -
_refresh("Bundle collected. The next shopping list is ready.")Calls _refresh with the values in its parentheses. -
elif action == Rules.PICK:If the earlier branches did not run, checks action == Rules.PICK next. -
var item := Rules.stall_index(shift, state["tile"])Creates a variable named item. The expression calls Rules.stall_index with the values in its parentheses. Godot infers the type from the first value. -
_refresh("%s added. Head to collection when your order is ready." % Rules.ITEM_NAMES[item])Calls _refresh with the values in its parentheses. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
var tile: Vector2i = state["tile"]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. -
_refresh("Nia is at the collection counter." if Rules.tile_at(shift, tile) == "C" else "Nia moved one tile.")Calls _refresh with the values in its parentheses. -
func _show_hint() -> void:Defines show 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 shift.is_empty():Checks shift.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 Rules.is_complete(shift, state):Checks Rules.is_complete(shift, state). The indented instructions below run only if this test passes. -
_refresh("This shift is complete.")Calls _refresh with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var route := Rules.shortest_route(shift, state)Creates a variable named route. The expression calls Rules.shortest_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. -
_refresh("Restart the shift to try a different route.")Calls _refresh with the values in its parentheses. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
hint = route[0]Stores the new value in hint. The expression looks up the item or key written between the square brackets. -
_refresh("Hint: %s. %d turns from here by a shortest route." % [Rules.ACTION_NAMES[hint], route.size()])Calls _refresh with the values in its parentheses. -
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. -
if not shift.is_empty():Checks not shift.is_empty(). The indented instructions below run only if this test passes. -
_open_shift(shift_index)Calls _open_shift with the values in its parentheses. -
func _next_shift() -> void:Defines next shift, 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 not Rules.is_complete(shift, state):Checks not Rules.is_complete(shift, state). The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
if shift_index < shifts.size() - 1:Checks shift_index < shifts.size() - 1. The indented instructions below run only if this test passes. -
_open_shift(shift_index + 1)Calls _open_shift with the values in its parentheses. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
_show_shifts()Calls _show_shifts 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 event is InputEventKey or not event.pressed or event.echo:Checks 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 event.keycode == KEY_ESCAPE and overlay.visible:Checks event.keycode == KEY_ESCAPE and overlay.visible. The indented instructions below run only if this test passes. -
_close_overlay()Calls _close_overlay 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. -
if overlay.visible or shift.is_empty():Checks overlay.visible or shift.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 action := -1Creates a variable named action. 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:Starts the instructions for this branch. The indented lines belong together. -
action = 0Stores the new value in action. The expression uses the whole number 0. -
KEY_RIGHT, KEY_D:Starts the instructions for this branch. The indented lines belong together. -
action = 1Stores the new value in action. The expression uses the whole number 1. -
KEY_DOWN, KEY_S:Starts the instructions for this branch. The indented lines belong together. -
action = 2Stores the new value in action. The expression uses the whole number 2. -
KEY_LEFT, KEY_A:Starts the instructions for this branch. The indented lines belong together. -
action = 3Stores the new value in action. The expression uses the whole number 3. -
KEY_P:Starts the instructions for this branch. The indented lines belong together. -
action = Rules.PICKStores the new value in action. The expression reads Rules.PICK. -
KEY_H:Starts the instructions for this branch. The indented lines belong together. -
action = Rules.HANDOVERStores the new value in action. The expression reads Rules.HANDOVER. -
if action >= 0:Checks action >= 0. The indented instructions below run only if this test passes. -
_take_action(action)Calls _take_action with the values in its parentheses. -
get_viewport().set_input_as_handled()Calls get_viewport with the values in its parentheses.
Read scripts/market_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. -
const WIDTH := 7Creates a constant named WIDTH. The expression uses the whole number 7. Godot infers the type from the first value. -
const HEIGHT := 6Creates a constant named HEIGHT. The expression uses the whole number 6. Godot infers the type from the first value. -
const CAPACITY := 3Creates a constant named CAPACITY. The expression uses the whole number 3. Godot infers the type from the first value. -
const MOVE := [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]Creates a constant named MOVE. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const ITEMS := ["apple", "bread", "flower"]Creates a constant named ITEMS. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const ITEM_NAMES := ["Apple", "Bread", "Flower"]Creates a constant named ITEM_NAMES. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const STALL_CODES := "ABF"Creates a constant named STALL_CODES. The expression uses the text inside the quotes. Godot infers the type from the first value. -
const PICK := 4Creates a constant named PICK. The expression uses the whole number 4. Godot infers the type from the first value. -
const HANDOVER := 5Creates a constant named HANDOVER. The expression uses the whole number 5. Godot infers the type from the first value. -
const ACTION_COUNT := 6Creates a constant named ACTION_COUNT. The expression uses the whole number 6. Godot infers the type from the first value. -
const ACTION_NAMES := ["Move north", "Move east", "Move south", "Move west", "Pick up the stall item", "Hand over the order"]Creates a constant named ACTION_NAMES. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
static func start(shift: Dictionary) -> Dictionary:Defines start, 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 y in range(HEIGHT):Repeats the indented instructions for each value in range(HEIGHT). -
var x: int = str(shift["rows"][y]).find("C")Creates a variable named x. The expression turns a value into text for a player message. The type after the colon says what kind of value it can hold. -
if x >= 0:Checks x >= 0. The indented instructions below run only if this test passes. -
return {"tile": Vector2i(x, y), "bag": [0, 0, 0], "order": 0, "turns": 0}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
return {}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
static func is_complete(shift: 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. -
return int(state["order"]) >= shift["orders"].size()Finishes the function and hands its result back to the caller. The expression converts a suitable value to a whole number. -
static func tile_at(shift: Dictionary, tile: Vector2i) -> String:Defines tile at, 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 tile.x < 0 or tile.y < 0 or tile.x >= WIDTH or tile.y >= HEIGHT:Checks tile.x < 0 or tile.y < 0 or tile.x >= WIDTH or tile.y >= HEIGHT. The indented instructions below run only if this test passes. -
return "#"Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
return str(shift["rows"][tile.y])[tile.x]Finishes the function and hands its result back to the caller. The expression turns a value into text for a player message. -
static func count_items(items: Array) -> Array:Defines count items, 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 counts := [0, 0, 0]Creates a variable named counts. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
for item in items:Repeats the indented instructions for each value in items. -
var index := ITEMS.find(item)Creates a variable named index. The expression calls ITEMS.find with the values in its parentheses. Godot infers the type from the first value. -
if index >= 0:Checks index >= 0. The indented instructions below run only if this test passes. -
counts[index] += 1Reads counts[index], adds to its old value, then stores the result back in the same place. -
return countsFinishes the function and hands its result back to the caller. The expression reads counts. -
static func needed(shift: Dictionary, state: Dictionary) -> Array:Defines needed, 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 is_complete(shift, state):Checks is_complete(shift, state). The indented instructions below run only if this test passes. -
return [0, 0, 0]Finishes the function and hands its result back to the caller. The expression makes a list whose items keep their order. -
return count_items(shift["orders"][state["order"]])Finishes the function and hands its result back to the caller. The expression calls count_items with the values in its parentheses. -
static func stall_index(shift: Dictionary, tile: Vector2i) -> int:Defines stall index, 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 STALL_CODES.find(tile_at(shift, tile))Finishes the function and hands its result back to the caller. The expression calls STALL_CODES.find with the values in its parentheses. -
static func load_size(state: Dictionary) -> int:Defines load size, 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 bag: Array = state["bag"]Creates a variable named bag. 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 int(bag[0]) + int(bag[1]) + int(bag[2])Finishes the function and hands its result back to the caller. The expression converts a suitable value to a whole number. -
static func describe_items(counts: Array) -> String:Defines describe items, 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 labels: Array[String] = []Creates a variable named labels. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
for i in range(ITEM_NAMES.size()):Repeats the indented instructions for each value in range(ITEM_NAMES.size()). -
var count := int(counts[i])Creates a variable named count. The expression converts a suitable value to a whole number. Godot infers the type from the first value. -
if count > 0:Checks count > 0. The indented instructions below run only if this test passes. -
labels.append("%d × %s" % [count, ITEM_NAMES[i]])Adds an item to the end of a list. -
return " · ".join(labels) if not labels.is_empty() else "Empty"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 reason(shift: Dictionary, state: Dictionary, action: int) -> String:Defines reason, 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 is_complete(shift, state):Checks is_complete(shift, state). The indented instructions below run only if this test passes. -
return "This shift is complete."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
var tile: Vector2i = state["tile"]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. -
if action >= 0 and action < MOVE.size():Checks action >= 0 and action < MOVE.size(). The indented instructions below run only if this test passes. -
return "That tile is blocked. Try an open lane." if tile_at(shift, tile + MOVE[action]) == "#" else ""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. -
if action == PICK:Checks action == PICK. The indented instructions below run only if this test passes. -
var item := stall_index(shift, tile)Creates a variable named item. The expression calls stall_index with the values in its parentheses. Godot infers the type from the first value. -
if item < 0:Checks item < 0. The indented instructions below run only if this test passes. -
return "Stand on a stall tile to pick up its item."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
if load_size(state) >= CAPACITY:Checks load_size(state) >= CAPACITY. The indented instructions below run only if this test passes. -
return "Your basket is full. Head back to hand over this bundle."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
if state["bag"][item] >= needed(shift, state)[item]:Checks state["bag"][item] >= needed(shift, state)[item]. The indented instructions below run only if this test passes. -
return "You have enough of this item for the current order."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
return ""Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
if action == HANDOVER:Checks action == HANDOVER. The indented instructions below run only if this test passes. -
if tile_at(shift, tile) != "C":Checks tile_at(shift, tile) != "C". The indented instructions below run only if this test passes. -
return "Bring the bundle back to the collection counter."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
if state["bag"] != needed(shift, state):Checks state["bag"] != needed(shift, state). The indented instructions below run only if this test passes. -
return "Check the shopping list. The current order is not ready."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
return ""Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
return "Choose a movement or collection button."Finishes the function and hands its result back to the caller. The expression uses the text inside the quotes. -
static func step(shift: Dictionary, state: Dictionary, action: int) -> Dictionary:Defines step, 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 not reason(shift, state, action).is_empty():Checks not reason(shift, state, action).is_empty(). 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 next := state.duplicate()Creates a variable named next. The expression copies the collection so a later change can leave the original alone. Godot infers the type from the first value. -
next["turns"] = int(state["turns"]) + 1Stores the new value in next["turns"]. The expression converts a suitable value to a whole number. -
if action < MOVE.size():Checks action < MOVE.size(). The indented instructions below run only if this test passes. -
next["tile"] = state["tile"] + MOVE[action]Stores the new value in next["tile"]. The expression looks up the item or key written between the square brackets. -
elif action == PICK:If the earlier branches did not run, checks action == PICK next. -
var bag: Array = state["bag"].duplicate()Creates a variable named bag. 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. -
bag[stall_index(shift, state["tile"])] += 1Continues this part of the script. Read the expression on this line in the context of the nearby declaration or function. -
next["bag"] = bagStores the new value in next["bag"]. The expression reads bag. -
else:Runs the indented fallback instructions if none of the earlier tests passed. -
next["bag"] = [0, 0, 0]Stores the new value in next["bag"]. The expression makes a list whose items keep their order. -
next["order"] = int(state["order"]) + 1Stores the new value in next["order"]. The expression converts a suitable value to a whole number. -
return nextFinishes the function and hands its result back to the caller. The expression reads next. -
static func state_key(state: Dictionary) -> int:Defines state key, 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["tile"]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 bag: Array = state["bag"]Creates a variable named bag. 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 tile.y * WIDTH + tile.x + WIDTH * HEIGHT * (int(bag[0]) + 4 * int(bag[1]) + 16 * int(bag[2]) + 64 * int(state["order"]))Finishes the function and hands its result back to the caller. The expression looks up the item or key written between the square brackets. -
static func shortest_route(shift: Dictionary, state: Dictionary) -> Array[int]:Defines shortest 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(shift, state):Checks is_complete(shift, 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 start_key := state_key(state)Creates a variable named start_key. The expression calls state_key with the values in its parentheses. Godot infers the type from the first value. -
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 := {start_key: ""}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 found := -1Creates a variable named found. The expression reads -1. 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. -
while cursor < queue.size() and found < 0:Keeps repeating while cursor < queue.size() and found < 0 stays true. The loop body should eventually change the result or leave with break. -
var current: Dictionary = queue[cursor]Creates a variable named current. 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 current_key := state_key(current)Creates a variable named current_key. The expression calls state_key with the values in its parentheses. Godot infers the type from the first value. -
for action in range(ACTION_COUNT):Repeats the indented instructions for each value in range(ACTION_COUNT). -
var next := step(shift, current, action)Creates a variable named next. The expression calls step 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. -
continueSkips the rest of this turn through the loop and moves on to the next item. -
var key := state_key(next)Creates a variable named key. The expression calls state_key with the values in its parentheses. Godot infers the type from the first value. -
if parent.has(key):Checks parent.has(key). 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[key] = Vector2i(current_key, action)Stores the new value in parent[key]. The expression packs whole-number x and y into one grid position. -
if is_complete(shift, next):Checks is_complete(shift, next). The indented instructions below run only if this test passes. -
found = keyStores the new value in found. The expression reads key. -
breakLeaves the loop immediately and continues with code after the loop. -
queue.append(next)Adds an item to the end of a list. -
if found < 0:Checks found < 0. 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. -
while found != start_key:Keeps repeating while found != start_key stays true. The loop body should eventually change the result or leave with break. -
var link: Vector2i = 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. -
route.append(link.y)Adds an item to the end of a list. -
found = link.xStores the new value in found. The expression reads link.x. -
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/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 SAVE := "user://market_day_progress.cfg"Creates a constant named SAVE. The expression uses the text inside the quotes. Godot infers the type from the first value. -
static func read(path: String = SAVE) -> 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 file := ConfigFile.new()Creates a variable named file. The expression creates a new ConfigFile object. Godot infers the type from the first value. -
if file.load(path) != OK:Checks file.load(path) != OK. The indented instructions below run only if this test passes. -
return {"medals": {}}Finishes the function and hands its result back to the caller. The expression makes a dictionary that looks up values by key. -
var medals: Variant = file.get_value("shifts", "medals", {})Creates a variable named medals. The expression calls file.get_value with the values in its parentheses. The type after the colon says what kind of value it can hold. -
return {"medals": medals if medals is Dictionary else {}}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 write(medals: Dictionary, path: String = SAVE) -> Error:Defines write, 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 file := ConfigFile.new()Creates a variable named file. The expression creates a new ConfigFile object. Godot infers the type from the first value. -
file.set_value("shifts", "version", 1)Calls file.set_value with the values in its parentheses. -
file.set_value("shifts", "medals", medals)Calls file.set_value with the values in its parentheses. -
return file.save(path)Finishes the function and hands its result back to the caller. The expression calls file.save with the values in its parentheses.
Read scripts/shift_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 MANIFEST := "res://levels/shifts.json"Creates a constant named MANIFEST. 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 file := FileAccess.open(MANIFEST, FileAccess.READ)Creates a variable named file. The expression tries to open a file and returns a handle, or null if opening fails. Godot infers the type from the first value. -
var shifts: Array[Dictionary] = []Creates a variable named shifts. The expression makes a list whose items keep their order. The type after the colon says what kind of value it can hold. -
if file == null:Checks file == null. The indented instructions below run only if this test passes. -
return shiftsFinishes the function and hands its result back to the caller. The expression reads shifts. -
var decoded: Variant = JSON.parse_string(file.get_as_text())Creates a variable named decoded. The expression tries to turn JSON text back into a value. The type after the colon says what kind of value it can hold. -
if not decoded is Array:Checks not decoded is Array. The indented instructions below run only if this test passes. -
return shiftsFinishes the function and hands its result back to the caller. The expression reads shifts. -
for shift in decoded:Repeats the indented instructions for each value in decoded. -
if shift is Dictionary:Checks shift is Dictionary. The indented instructions below run only if this test passes. -
shifts.append(shift)Adds an item to the end of a list. -
return shiftsFinishes the function and hands its result back to the caller. The expression reads shifts.
Read scripts/street_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 action_selected(action: int)Defines an event this node can send. Listeners can connect functions to react when it happens. -
const Rules = preload("res://scripts/market_rules.gd")Creates a constant named Rules. The expression prepares a resource at a fixed project path when the script is loaded. -
const CELL := Vector2(88, 60)Creates a constant named CELL. The expression packs x and y into one value. Godot infers the type from the first value. -
const STEP := Vector2(94, 66)Creates a constant named STEP. The expression packs x and y into one value. Godot infers the type from the first value. -
const ORIGIN := Vector2(26, 63)Creates a constant named ORIGIN. The expression packs x and y into one value. Godot infers the type from the first value. -
const FACE := Color("#fdf0d6")Creates a constant named FACE. The expression builds a colour from these values. Godot infers the type from the first value. -
const DIM := Color("#aebfc1")Creates a constant named DIM. The expression builds a colour from these values. Godot infers the type from the first value. -
const GOLD := Color("#ffc97d")Creates a constant named GOLD. The expression builds a colour from these values. Godot infers the type from the first value. -
const STALL := [Color("#c86c55"), Color("#b68548"), Color("#8668a0")]Creates a constant named STALL. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const STALL_TEXT := ["APPLES", "BAKERY", "FLOWERS"]Creates a constant named STALL_TEXT. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
const PAVE := [Color("#244b50"), Color("#294f54")]Creates a constant named PAVE. The expression makes a list whose items keep their order. Godot infers the type from the first value. -
var shift: Dictionary = {}Creates a variable named shift. The expression makes a dictionary that looks up values by key. The type after the colon says what kind of value it can hold. -
var game: Dictionary = {}Creates a variable named game. The expression makes a dictionary that looks up values by key. The type after the colon says what kind of value it can hold. -
var hinted := -1Creates a variable named hinted. The expression reads -1. Godot infers the type from the first value. -
func update_board(new_shift: Dictionary, new_state: Dictionary, hint: int) -> void:Defines update 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. -
shift = new_shiftStores the new value in shift. The expression reads new_shift. -
game = new_stateStores the new value in game. The expression reads new_state. -
hinted = hintStores the new value in hinted. The expression reads hint. -
queue_redraw()Asks Godot to call _draw again on a later frame so the screen matches the new state. -
func panel(rect: Rect2, fill: Color, edge: Color, roundness: int, line: int = 1) -> 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 style := StyleBoxFlat.new()Creates a variable named style. The expression creates a new StyleBoxFlat object. Godot infers the type from the first value. -
style.bg_color = fillStores the new value in style.bg_color. The expression reads fill. -
style.border_color = edgeStores the new value in style.border_color. The expression reads edge. -
style.set_corner_radius_all(roundness)Calls style.set_corner_radius_all with the values in its parentheses. -
style.set_border_width_all(line)Calls style.set_border_width_all with the values in its parentheses. -
draw_style_box(style, rect)Calls draw_style_box with the values in its parentheses. -
func caption(label: String, centre: Vector2, font_size: int = 18, ink: Color = FACE) -> void:Defines caption, 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 font := ThemeDB.fallback_fontCreates a variable named font. The expression reads ThemeDB.fallback_font. Godot infers the type from the first value. -
var text_size := font.get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size)Creates a variable named text_size. The expression calls font.get_string_size with the values in its parentheses. Godot infers the type from the first value. -
var baseline := centre + Vector2(-text_size.x / 2.0, font.get_ascent(font_size) - text_size.y / 2.0)Creates 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(font, baseline, label, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, ink)Paints a piece of text with a font at a position measured from the node's origin. -
func _draw() -> void:Godot calls this when the node needs drawing. The instructions inside paint the current state. -
panel(Rect2(Vector2.ZERO, size), Color(0.046, 0.125, 0.15, 0.97), Color("#7b9390"), 19)Calls panel with the values in its parentheses. -
caption("BRIAR LANE • STREET MAP", Vector2(size.x * 0.5, 32), 20)Calls caption with the values in its parentheses. -
if shift.is_empty():Checks shift.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 current: Vector2i = game["tile"]Creates a variable named current. 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 target := Vector2i(-1, -1)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. -
if hinted >= 0 and hinted < Rules.MOVE.size():Checks hinted >= 0 and hinted < Rules.MOVE.size(). The indented instructions below run only if this test passes. -
target = current + Rules.MOVE[hinted]Stores the new value in target. The expression looks up the item or key written between the square brackets. -
elif hinted == Rules.PICK or hinted == Rules.HANDOVER:If the earlier branches did not run, checks hinted == Rules.PICK or hinted == Rules.HANDOVER next. -
target = currentStores the new value in target. The expression reads current. -
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). -
var tile := Vector2i(x, y)Creates a variable named tile. The expression packs whole-number x and y into one grid position. Godot infers the type from the first value. -
var p := ORIGIN + Vector2(x, y) * STEPCreates a variable named p. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value. -
_draw_square(Rect2(p, CELL), tile, target)Calls _draw_square with the values in its parentheses. -
caption("A Apples · B Bakery · F Flowers · C Collection", Vector2(size.x / 2, 480), 16, DIM)Calls caption with the values in its parentheses. -
func _draw_square(rect: Rect2, tile: Vector2i, target: Vector2i) -> void:Defines draw square, 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 code := Rules.tile_at(shift, tile)Creates a variable named code. The expression calls Rules.tile_at with the values in its parentheses. Godot infers the type from the first value. -
var item := Rules.stall_index(shift, tile)Creates a variable named item. The expression calls Rules.stall_index with the values in its parentheses. Godot infers the type from the first value. -
var fill: Color = PAVE[(tile.x + tile.y) % 2]Creates a variable named fill. 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 code == "#":Checks code == "#". The indented instructions below run only if this test passes. -
fill = Color("#142b32")Stores the new value in fill. The expression builds a colour from these values. -
elif code == "C":If the earlier branches did not run, checks code == "C" next. -
fill = Color("#2a786f")Stores the new value in fill. The expression builds a colour from these values. -
elif item >= 0:If the earlier branches did not run, checks item >= 0 next. -
fill = STALL[item]Stores the new value in fill. The expression looks up the item or key written between the square brackets. -
var is_current: bool = game["tile"] == tileCreates a variable named is_current. The expression evaluates the test to see whether it is true or false. The type after the colon says what kind of value it can hold. -
var stroke := GOLD if target == tile else Color("#729398") if is_current else Color("#4a7175")Creates a variable named stroke. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
panel(rect, fill, stroke, 11, 3 if target == tile else 1)Calls panel with the values in its parentheses. -
var midpoint := rect.get_center()Creates a variable named midpoint. The expression calls rect.get_center with the values in its parentheses. Godot infers the type from the first value. -
if code == "#":Checks code == "#". The indented instructions below run only if this test passes. -
var water: bool = shift["group"] == "After the Rain"Creates a variable named water. The expression evaluates the test to see whether it is true or false. The type after the colon says what kind of value it can hold. -
var ink := Color("#71949e") if water else Color("#556c71")Creates a variable named ink. The expression builds a colour from these values. Godot infers the type from the first value. -
for j in range(3):Repeats the indented instructions for each value in range(3). -
var at := midpoint + Vector2(0, (j - 1) * 8)Creates a variable named at. The expression calculates a new value from the expressions on either side of the operator. Godot infers the type from the first value. -
draw_line(at + Vector2(-15, 0), at + Vector2(15, 0), ink, 1.6, true)Paints a line between two points with the chosen colour and width. -
caption("Puddle" if water else "Closed", midpoint + Vector2(0, 19), 11, DIM)Calls caption with the values in its parentheses. -
elif item >= 0 or code == "C":If the earlier branches did not run, checks item >= 0 or code == "C" next. -
caption(code, midpoint + Vector2(0, -9), 21)Calls caption with the values in its parentheses. -
caption(STALL_TEXT[item] if item >= 0 else "COLLECT", midpoint + Vector2(0, 14), 11)Calls caption with the values in its parentheses. -
if is_current:Checks is_current. The indented instructions below run only if this test passes. -
var origin := rect.position + Vector2(13, 12) if item >= 0 or code == "C" else midpointCreates a variable named origin. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
var radius := 10.0 if item >= 0 or code == "C" else 18.0Creates a variable named radius. The expression chooses one of two values by checking the condition in the middle. Godot infers the type from the first value. -
draw_circle(origin, radius + 1.0, Color("#fbe9ba"), true, -1.0, true)Paints a filled circle or outline in this node's local coordinates. -
draw_circle(origin, radius - 1.5, Color("#bb5441"), true, -1.0, true)Paints a filled circle or outline in this node's local coordinates. -
caption("N" if radius < 12 else "NIA", origin, 12 if radius < 12 else 13)Calls caption 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 shift.is_empty():Checks shift.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 not event is InputEventMouseButton or event.button_index != MOUSE_BUTTON_LEFT or not event.pressed:Checks not event is InputEventMouseButton or event.button_index != MOUSE_BUTTON_LEFT or not event.pressed. The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var p: Vector2 = event.position - ORIGINCreates a variable named p. 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 p.x < 0.0 or p.y < 0.0 or p.x >= Rules.WIDTH * STEP.x or p.y >= Rules.HEIGHT * STEP.y:Checks p.x < 0.0 or p.y < 0.0 or p.x >= Rules.WIDTH * STEP.x or p.y >= Rules.HEIGHT * STEP.y. The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var tile := Vector2i(floori(p.x / STEP.x), floori(p.y / STEP.y))Creates a variable named tile. The expression packs whole-number x and y into one grid position. Godot infers the type from the first value. -
if (p - Vector2(tile) * STEP).x >= CELL.x or (p - Vector2(tile) * STEP).y >= CELL.y:Checks (p - Vector2(tile) * STEP).x >= CELL.x or (p - Vector2(tile) * STEP).y >= CELL.y. The indented instructions below run only if this test passes. -
returnFinishes the function right here. Any later instructions in this function are skipped. -
var current: Vector2i = game["tile"]Creates a variable named current. 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.MOVE.find(tile - current)Creates a variable named direction. The expression calls Rules.MOVE.find with the values in its parentheses. Godot infers the type from the first value. -
if direction >= 0:Checks direction >= 0. The indented instructions below run only if this test passes. -
action_selected.emit(direction)Sends a signal to anything listening. -
elif tile == current:If the earlier branches did not run, checks tile == current next. -
var code := Rules.tile_at(shift, tile)Creates a variable named code. The expression calls Rules.tile_at with the values in its parentheses. Godot infers the type from the first value. -
if code == "C":Checks code == "C". The indented instructions below run only if this test passes. -
action_selected.emit(Rules.HANDOVER)Sends a signal to anything listening. -
elif Rules.stall_index(shift, tile) >= 0:If the earlier branches did not run, checks Rules.stall_index(shift, tile) >= 0 next. -
action_selected.emit(Rules.PICK)Sends a signal to anything listening. -
accept_event()Calls accept_event with the values in its parentheses.