7ef972e3b3
ci / verify (push) Successful in 47s
Character swapping is hub-only, and refused by the SERVER rather than merely greyed out in the menu. Allowing it inside a dungeon would be an instant, uninterruptible exit from danger -- strictly better than the one-second escape channel, which would make that channel pointless. Creating a character in a dungeon is refused for the same reason. Both are covered by diag_progression. Health regenerates at 0.5% of MAXIMUM per second. A percentage rather than a flat rate so it does not become irrelevant at level 15: a capped character regains 1.2 hp/s against a level 1's 0.5, and both take about 200 seconds to heal from nothing. No out-of-combat gate -- at this rate it cannot out-heal anything actually shooting at you, and a trickle that never stops is easier to reason about than a timer players have to learn. A fractional carry is needed because a tick heals well under one hit point, so truncating each tick would heal exactly nothing; there is a test for that specifically. The XP bar now states the percentage and the level it leads to, since a bar answers "how far" vaguely and a number answers it exactly. Recorded the two Stage 3 answers: 4 inventory slots, and the boss's food item is player-instanced now so the mechanism gets exercised rather than deferred. Writing the swap guard's test caught my own mistake: the first version created its spare character through the store, which has no opinion about where you are, so it bypassed the guard it was meant to prove and left a stray character behind that broke a later assertion. 200 tests. check.sh, test.sh, smoke.sh and both diagnostics pass.
134 lines
4.0 KiB
GDScript
134 lines
4.0 KiB
GDScript
extends CanvasLayer
|
|
## In-game system menu, opened with Escape.
|
|
##
|
|
## Exists because without it there is no way out of a session short of killing
|
|
## the process -- and "kill the process" is exactly the behaviour the escape
|
|
## channel is designed to discourage, so leaving it as the only exit would work
|
|
## against the rest of the design.
|
|
|
|
signal resumed
|
|
signal return_to_hub_requested
|
|
signal disconnect_requested
|
|
signal characters_requested
|
|
|
|
var _panel: VBoxContainer
|
|
var _hub_button: Button
|
|
var _characters_button: Button
|
|
var _disconnect_button: Button
|
|
var _note: Label
|
|
var _in_dungeon: bool = false
|
|
var _open: bool = false
|
|
|
|
|
|
func _ready() -> void:
|
|
layer = 20
|
|
var root := Control.new()
|
|
root.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
add_child(root)
|
|
|
|
# Dim the game behind the menu so it is obvious the world is still running.
|
|
var scrim := ColorRect.new()
|
|
scrim.color = Color(0.0, 0.0, 0.0, 0.55)
|
|
scrim.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
scrim.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
root.add_child(scrim)
|
|
|
|
var center := CenterContainer.new()
|
|
center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
root.add_child(center)
|
|
|
|
_panel = VBoxContainer.new()
|
|
_panel.custom_minimum_size = Vector2(320.0, 0.0)
|
|
_panel.add_theme_constant_override("separation", 10)
|
|
center.add_child(_panel)
|
|
|
|
var title := Label.new()
|
|
title.text = "PAUSED"
|
|
title.add_theme_font_size_override("font_size", 26)
|
|
_panel.add_child(title)
|
|
|
|
_note = Label.new()
|
|
_note.add_theme_font_size_override("font_size", 12)
|
|
_note.add_theme_color_override("font_color", Color(1.0, 0.7, 0.5))
|
|
_note.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
_note.custom_minimum_size = Vector2(320.0, 0.0)
|
|
_panel.add_child(_note)
|
|
|
|
_hub_button = _button("Return to hub", func() -> void:
|
|
return_to_hub_requested.emit()
|
|
close())
|
|
_characters_button = _button("Change character", func() -> void:
|
|
characters_requested.emit()
|
|
close())
|
|
_button("Resume", func() -> void: close())
|
|
_disconnect_button = _button("Disconnect to menu", func() -> void:
|
|
disconnect_requested.emit()
|
|
close())
|
|
_button("Quit game", func() -> void: get_tree().quit())
|
|
|
|
visible = false
|
|
|
|
|
|
func _button(text: String, on_press: Callable) -> Button:
|
|
var b := Button.new()
|
|
b.text = text
|
|
b.pressed.connect(on_press)
|
|
_panel.add_child(b)
|
|
return b
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("system_menu"):
|
|
toggle()
|
|
get_viewport().set_input_as_handled()
|
|
|
|
|
|
func toggle() -> void:
|
|
if _open:
|
|
close()
|
|
else:
|
|
open()
|
|
|
|
|
|
func open() -> void:
|
|
_open = true
|
|
visible = true
|
|
# Nothing is paused -- the server does not stop for one client's menu, so
|
|
# neither does the view. Only the mouse is freed.
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
|
|
func close() -> void:
|
|
_open = false
|
|
visible = false
|
|
|
|
|
|
func is_open() -> bool:
|
|
return _open
|
|
|
|
|
|
## The hub button is meaningless when you are already in the hub.
|
|
func set_in_dungeon(in_dungeon: bool) -> void:
|
|
if in_dungeon == _in_dungeon and not _note.text.is_empty():
|
|
return
|
|
_in_dungeon = in_dungeon
|
|
_hub_button.disabled = not in_dungeon
|
|
# Swapping is hub-only, and the server enforces that regardless of what
|
|
# this button does -- but a disabled button explains the rule, where a
|
|
# refusal after the fact just looks broken.
|
|
_characters_button.disabled = in_dungeon
|
|
_characters_button.text = "Change character (hub only)" if in_dungeon \
|
|
else "Change character"
|
|
if in_dungeon:
|
|
# Disconnecting is not an escape: the server keeps the body in the
|
|
# world, channelling out, for the same second the escape button costs.
|
|
# Saying so is the difference between a considered choice and a nasty
|
|
# surprise -- the mechanic only reads as fair if players know about it.
|
|
_note.text = "The world keeps running while this is open. " \
|
|
+ "Disconnecting does not save you: your ship stays in the dungeon " \
|
|
+ "for one second and can still be killed."
|
|
_disconnect_button.text = "Disconnect to menu (ship stays 1s)"
|
|
else:
|
|
_note.text = "The world keeps running while this is open."
|
|
_disconnect_button.text = "Disconnect to menu"
|