# TouchLines Sandbox Report

Date: 2026-07-03

## Folders

- `test/current-game/` - isolated copy of the current game. Copied with state and saves, but without the active `.state.lock`.
- `test/touchlines/` - shallow clone of `https://github.com/brenosss/touchlines`.

## TouchLines revision

- Commit: `5c5c71a`
- Commit date: `2026-06-26 11:21:57 -0300`
- Commit subject: `Shorten GitHub CTA label in pt-BR`

## Setup done

- Ran `npm install` in `test/touchlines`.
- Copied `src/example_data` to `src/Data` in `test/touchlines`.
- The current-game test copy now uses its own PHP session name, `YSPWEBTEST`, scoped to `/test/current-game/`.
- Sandbox passwords were set to username for `jdc`, `adam`, `111`, and `222`.

## Current game copy checks

All passed:

- `php -l index.php`
- `php -l code/api.php`
- `php -l code/.lib/app_version.php`
- `php -l code/.lib/http.php`
- `php -l code/.lib/manager_progression.php`
- `node --check code/assets/js/app.js`

Quick login check:

- `111 / 111` loads manager season `s6693822ee4` with a pending round 4 match.

## New engine viewer prototype

- Added a `VIEW` button next to `SIM MATCH` in `test/current-game`.
- `VIEW` opens a browser-side 2D sandbox simulator inspired by TouchLines concepts: player movement, passing, dribbling, shooting, score clock and event log.
- This does not advance the league, update saves, or write match results. It is only for testing the visual/engine feel before any real integration.
- 2026-07-03 11:50 CEST: Fixed the test viewer canvas so it cannot collapse to zero height. The viewer now draws the first frame immediately and writes a render error into the match log if the animation loop fails.
- 2026-07-03: Replaced the crude VIEW loop with a more TouchLines-style browser engine in `test/current-game`: formation-based player anchors, real squad/formation loading through `managerTeamDetails`, pass-lane scoring, through balls, pressure/tackles, xG-ish shot decisions, ball flight, possession/shots/passes/tackles HUD and a horizontal tactical pitch renderer. This is still a sandbox viewer and does not write league results.
- 2026-07-03: Fixed goalkeeper decisions in the VIEW sandbox. Goalkeepers no longer use the outfield shooting decision tree; they look for short defender/midfielder distribution first and only clear long when pressured.
- 2026-07-03: Added searchable client debug logging for the VIEW sandbox. The browser sends engine events to `api.php?action=clientDebugLog`; the backend writes JSONL when possible and also stores the latest entries in `.state.json` under `clientDebugLog`.
- 2026-07-03: Added stuck detection to the VIEW sandbox. Search for `stuck_overlap`, `stalled_owner`, `stalled_activity`, or `render_error` when the match clock keeps running but the engine looks frozen. Overlapping outfield players are nudged apart automatically after the stuck event is logged.
- 2026-07-03: Tuned VIEW match balance down after high-scoring tests. Shot decisions now need better chances, xG/shot-on-target/goal conversion are lower, keepers matter more, carries advance less, and tackles/interceptions are slightly stronger.
- 2026-07-03: Added per-tick contact resolution for player collisions. Players can still contest the ball closely, but they are pushed apart immediately instead of staying stacked for several match minutes. Repeated contacts are logged as `repeated_contact`.
- 2026-07-03: Split the VIEW match lower panel into `EVENTS` and `REPORTER`. The event feed keeps the fast match actions, while the reporter gives shorter match-read comments every few minutes and after major moments. `BACK TO LEAGUE` is hidden during live VIEW playback and returns after full time or render errors.
- 2026-07-03: Added a live pressure bar above the `EVENTS` and `REPORTER` panels. It uses possession, ball territory, shots/on-target and current ball owner to show which side has momentum. Away pressure fills left, home pressure fills right.
- 2026-07-03: Added a spinning ball marker to the live pressure bar. The marker sits on the current outer edge of the pressure value and follows the bar as momentum moves.

## Debug logging

Search examples from the project root:

```bash
rg "stuck_overlap|stalled_owner|stalled_activity|render_error" test/current-game/code/.state.json
rg "tl_pass|tl_shot|tl_event|tl_owner" test/current-game/code/.state.json
```

Useful event types:

- `tl_start` - VIEW engine started, with fixture, formation and player positions.
- `tl_owner` - ball ownership changed.
- `tl_pass` - pass attempt with quality, distance and interception info.
- `tl_shot` - shot attempt with xG-ish values and target info.
- `tl_event` - visible match-log event.
- `stuck_overlap` - two outfield players stayed on top of each other too long.
- `repeated_contact` - two players kept colliding after normal contact resolution.
- `stalled_owner` - ball owner held the ball without meaningful movement too long.
- `stalled_activity` - match time kept running without events too long.
- `render_error`, `window_error`, `unhandled_rejection` - frontend/runtime errors.

## License note

TouchLines is AGPL-3.0. The current `test/current-game` viewer uses its architecture as a reference, but it does not import the TouchLines TypeScript modules directly. Copying TouchLines source into the live game would require a deliberate license decision first.

## TouchLines checks

- `npm install` completed.
- NPM reported `1 high severity vulnerability` in the TouchLines dependency tree.
- `npm run typecheck` failed because `.bin/tsc` symlinks cannot be resolved on this mount.
- Direct TypeScript check with `node node_modules/typescript/bin/tsc --noEmit` ran, but the repo currently has many TypeScript errors.
- Local Bun binary from the npm package cannot run here: `Operation not permitted`.
- `npm rebuild bun core-js` also failed on this mount with `EPERM: operation not permitted, readlink ... node_modules/.bin/bun`.

## First technical reading

TouchLines has a useful engine shape for our purpose:

- `src/GameEngine/Domain/SimulateMatch.ts` exposes a headless `simulateMatch(...)` function.
- `src/GameEngine/Domain/gameState.ts` contains the tick loop and player movement/execution.
- `src/GameEngine/Domain/DecisionTree.ts` contains player decisions: carry, shoot, pass, through ball, dribble, tackle, press, support run, hold shape.
- `src/GraficsEngine/PixiPitch.tsx` is the Pixi rendering layer.

## Initial conclusion

TouchLines is not ready as a drop-in replacement. It can be used as an engine reference or as a separate prototype, but direct integration needs an adapter and cleanup first.

The likely next step is to build a small adapter in `test/current-game/` that maps our player objects to TouchLines-style squad objects, runs a single headless match, and converts the output back to our existing match JSON format.

To actually run TouchLines with its own scripts, use a real Bun install outside this network mount or move `test/touchlines` to a local filesystem where executable symlinks work.
