Files
tidewall/tools/tutorial_check.gd
T
claudeandClaude Opus 5.5 b604ced923 A12: Tutorial
A short, skippable tutorial on an island of your own: leave the barge, glide
down, walk and jump, cut materials with the boathook, place a wall, aim and
fire, and get above the line the tide will reach after its next rise.

- MatchRules.tutorial(): one player, no bots, last_team_wins off (alone is
  not a win, only the tide or a fall ends it) and starting_kit (a dock
  carbine with a full magazine and 60 cartridges, Tuning.TUTORIAL_KIT).
  Both rules go in command logs; older logs read with the defaults.
- Tutorial watches the client's own view (predicted player, world copy,
  FX) and moves on when each step is done. Instructions name the player's
  own key bindings. TutorialCard shows it under the minimap.
- TutorialPilot plays it through ClientInput for --tutorial --autoplay,
  the tests and make tutorial-check (12 seeds, all finish).
- First launch offers it (welcome screen, remembered in settings); it is
  always on the main menu; Leave in the pause menu skips it. Finishing is
  saved. --tutorial on the command line.
- make tutorial-captures; PLAY.md, the man page, ARCHITECTURE.md and
  CLAUDE.md updated.

Closes #52

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 05:47:31 -05:00

67 lines
2.7 KiB
GDScript

## A12: plays the tutorial from start to end with its scripted player (TutorialPilot),
## through a real ClientSession on its offline server, as fast as it will go, on each
## seed asked for. Each seed must reach the last step within the time limit, with no
## script or engine error.
##
## tools/godot.sh --script res://tools/tutorial_check.gd -- [--seeds=N] [--first=N]
##
## Prints one JSON line per seed (the seconds each step took, in game time) and a
## verdict. Exits 1 on any failure.
extends SceneTree
## Game seconds a seed may take before it counts as stuck.
const LIMIT_SECONDS: float = 600.0
func _init() -> void:
var seeds: int = 5
var first: int = 1
for arg: String in OS.get_cmdline_user_args():
if arg.begins_with("--seeds=") and arg.trim_prefix("--seeds=").is_valid_int():
seeds = maxi(arg.trim_prefix("--seeds=").to_int(), 1)
elif arg.begins_with("--first=") and arg.trim_prefix("--first=").is_valid_int():
first = arg.trim_prefix("--first=").to_int()
else:
print("tutorial-check FAIL: unknown argument '%s'" % arg)
quit(2)
return
var errors: ErrorCounter = ErrorCounter.new()
OS.add_logger(errors)
var problems: Array[String] = []
for seed_value: int in range(first, first + seeds):
var result: Dictionary = play(seed_value, LIMIT_SECONDS)
print(JSON.stringify(result))
if not bool(result["finished"]):
problems.append("seed %d stopped at '%s'" % [seed_value, result["step"]])
OS.remove_logger(errors)
if errors.count() > 0:
problems.append("%d script or engine errors, first: %s" % [errors.count(), errors.first()])
for problem: String in problems:
print("tutorial-check FAIL: %s" % problem)
if problems.is_empty():
print("tutorial-check: ok (%d seeds played from the barge to the end)" % seeds)
quit(0 if problems.is_empty() else 1)
## Plays one seed's tutorial with the pilot, a tick a frame, for up to `limit` game
## seconds. Returns {"seed", "finished", "step", "seconds", "steps": {name: seconds}}.
static func play(seed_value: int, limit: float) -> Dictionary:
var session: ClientSession = ClientSession.new()
session.input.autoplay = true
session.play_tutorial(seed_value)
var delta: float = 1.0 / Tuning.TICK_RATE_HZ
var frames: int = 0
var most: int = roundi(limit * Tuning.TICK_RATE_HZ)
while frames < most and not session.tutorial.finished():
session.pump(delta)
frames += 1
var steps: Dictionary = {}
for index: int in Tutorial.DONE:
steps[Tutorial.STEP_NAMES[index]] = snappedf(session.tutorial.step_seconds[index], 0.1)
var result: Dictionary = {
"seed": seed_value, "finished": session.tutorial.finished(), "step": session.tutorial.step_name(),
"seconds": snappedf(float(frames) * delta, 0.1), "steps": steps,
}
session.free()
return result