Skip to content

chore: simplify mouse input press actions#1647

Merged
hatayama merged 1 commit into
v3-betafrom
refactor/hatayama/extract-mouse-input-press-actions
Jul 9, 2026
Merged

chore: simplify mouse input press actions#1647
hatayama merged 1 commit into
v3-betafrom
refactor/hatayama/extract-mouse-input-press-actions

Conversation

@hatayama

@hatayama hatayama commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Isolate click and long-press execution from mouse input tool orchestration.
  • Preserve runtime coordinate conversion, button timing, cleanup, and response behavior.

User Impact

  • No user-visible behavior change is intended.
  • Click and long-press input remain visible to gameplay updates and retain the same release, timeout, Pause Point, and overlay behavior.

Changes

  • Move ExecuteClick, ExecuteLongPress, runtime InputToScreen, and button mapping to stateless MouseInputPressActionExecutor.
  • Keep the runtime Screen.height coordinate contract and its rationale with the moved conversion helper.
  • Dispatch the two press actions directly from SimulateMouseInputUseCase without wrappers.
  • Extend the async CancellationToken source guard to the new executor.
  • Reduce SimulateMouseInputUseCase from 580 to 318 lines.

Refactor Safety

  • This is a pure move plus direct type qualification and the minimum private-instance to internal-static visibility changes required by the dispatch boundary.
  • Input application order, press lifetime, try/finally, CancellationToken.None cleanup, ConfigureAwait(false), overlay mutations, response fields/messages, and button mapping are unchanged.
  • The executor has no instance or mutable static state and has no dependency back to the use case.
  • Similar click and long-press flows remain explicit instead of introducing flag/delegate machinery solely to reduce repeated statements.
  • No schema, public API, wire shape, or protocol declaration changed.

Verification

  • Baseline response factory plus mouse input PlayMode tests: 14/14 passed.
  • After extraction, the same PlayMode tests: 14/14 passed.
  • Assembly dependency, PlayMode preflight, and static source guard fixtures: 111/111 passed.
  • Unity compile: 0 errors, 0 warnings.
  • git diff --check: passed.

Follow-up

  • R2-42 Stage 3 will move delta, scroll, and smooth-delta execution and leave the use case as the tool-level orchestrator.

Review in cubic

Move click and long-press sequencing, runtime coordinate conversion,
and button mapping behind one stateless executor so the use case keeps
only tool orchestration. Preserve the async source guard for the move.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb7c3d44-e71d-4fd5-b287-c49ac98929f2

📥 Commits

Reviewing files that changed from the base of the PR and between 041dd24 and 68c11e7.

⛔ Files ignored due to path filters (1)
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputPressActionExecutor.cs.meta is excluded by none and included by none
📒 Files selected for processing (3)
  • Assets/Tests/Editor/StaticFacadeStateGuardTests.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputPressActionExecutor.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/SimulateMouseInputUseCase.cs

📝 Walkthrough

Walkthrough

This PR extracts click and long-press mouse simulation logic from SimulateMouseInputUseCase into a new MouseInputPressActionExecutor class under the Input System build. SimulateMouseInputUseCase now delegates to the new executor and removes its previous inline implementations. A test allowlist is extended accordingly.

Changes

Mouse Press Executor Extraction

Layer / File(s) Summary
New MouseInputPressActionExecutor
Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputPressActionExecutor.cs
Adds coordinate conversion, ExecuteClick/ExecuteLongPress methods with duration validation, mouse position scheduling, button down/up simulation, overlay state tracking, timeout/pause/cleanup handling via try/finally, and button enum mapping.
Delegation and cleanup in use case
Packages/src/Editor/FirstPartyTools/SimulateMouseInput/SimulateMouseInputUseCase.cs
ExecuteAsync now awaits MouseInputPressActionExecutor.ExecuteClick/ExecuteLongPress; removes the local Execute* implementations, coordinate conversion helper, ToRuntimeMouseButton, and the RuntimeMouseButton using-alias.
Async guard test allowlist update
Assets/Tests/Editor/StaticFacadeStateGuardTests.cs
Adds the new executor file path to AsyncCancellationTokenGuardPaths so its async methods are checked for a CancellationToken ct parameter.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UseCase as SimulateMouseInputUseCase
  participant Executor as MouseInputPressActionExecutor
  participant InputSystem as Unity Input System
  participant Cleanup as MouseInputMainThreadCleanup

  UseCase->>Executor: ExecuteClick / ExecuteLongPress(request)
  Executor->>Executor: validate duration, convert coordinates
  Executor->>InputSystem: schedule mouse position update
  Executor->>InputSystem: simulate button down
  Executor->>Executor: await press applied, await duration
  alt timed out
    Executor->>Cleanup: schedule timed-out cleanup
  else paused
    Executor->>Executor: clear overlay state, return interrupted
  else completed
    Executor->>Cleanup: ReleaseButtonIfPossible / ButtonUp
  end
  Executor-->>UseCase: response
Loading

Possibly related PRs

  • hatayama/unity-cli-loop#1516: Builds on the same SimulateMouseInputUseCase click/long-press handler refactor that now delegates to MouseInputPressActionExecutor.
  • hatayama/unity-cli-loop#1594: Also updates the StaticFacadeStateGuardTests async-method cancellation-token allowlist affecting input-simulation targets.
  • hatayama/unity-cli-loop#1636: Also updates StaticFacadeStateGuardTests for a newly extracted mouse press executor implementation.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main refactor: simplifying mouse input press actions.
Description check ✅ Passed The description is clearly related and matches the refactor details in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/hatayama/extract-mouse-input-press-actions

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hatayama
hatayama merged commit d96d6cd into v3-beta Jul 9, 2026
10 checks passed
@hatayama
hatayama deleted the refactor/hatayama/extract-mouse-input-press-actions branch July 9, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant