Skip to content

Add JavaScript APIs for crosshair enable/disable/query#111

Merged
dyfios merged 4 commits into
v3.0from
copilot/add-javascript-apis-for-crosshair
Apr 3, 2026
Merged

Add JavaScript APIs for crosshair enable/disable/query#111
dyfios merged 4 commits into
v3.0from
copilot/add-javascript-apis-for-crosshair

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

The crosshair feature (CameraManager.crosshairEnabled) had no JavaScript-accessible surface, making programmatic crosshair control impossible from world scripts.

Changes

  • Camera.cs (JS API) — Three new static methods on the Camera API class:

    • EnableCrosshair() → sets crosshairEnabled = true, returns bool
    • DisableCrosshair() → sets crosshairEnabled = false, returns bool
    • IsCrosshairEnabled() → returns current crosshair state as bool

    Each method guards against null ActiveWorld/cameraManager, logging a warning and returning false if unavailable.

  • javascript-api.md — Added "Camera Control" section documenting the full Camera API surface including the new crosshair methods with usage examples.

Usage

// Enable on entering first-person mode
Camera.AttachToEntity(playerEntity);
Camera.EnableCrosshair();

// Toggle based on state
function updateHUD(isAiming) {
    if (isAiming) {
        Camera.EnableCrosshair();
    } else {
        Camera.DisableCrosshair();
    }
}

// Query current state
var active = Camera.IsCrosshairEnabled();

Copilot AI linked an issue Apr 3, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add JavaScript APIs for crosshair feature Add JavaScript APIs for crosshair enable/disable/query Apr 3, 2026
Copilot AI requested a review from dyfios April 3, 2026 00:28
@dyfios dyfios marked this pull request as ready for review April 3, 2026 00:31
Copilot AI review requested due to automatic review settings April 3, 2026 00:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds JavaScript-accessible crosshair controls to the existing Camera JS API, enabling world scripts to programmatically enable/disable and query crosshair state.

Changes:

  • Added Camera.EnableCrosshair(), Camera.DisableCrosshair(), and Camera.IsCrosshairEnabled() to the JS-exposed Camera API.
  • Documented the Camera API surface (including new crosshair methods) in docs/api/javascript-api.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
docs/api/javascript-api.md Adds a new Camera documentation section and example usage for crosshair + camera operations.
Assets/Runtime/Handlers/JavascriptHandler/APIs/WorldBrowserUtilities/Scripts/Camera.cs Introduces three new static JS API methods to set/query cameraManager.crosshairEnabled with null-guards.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +203 to +207
if (StraightFour.StraightFour.ActiveWorld == null ||
StraightFour.StraightFour.ActiveWorld.cameraManager == null)
{
Logging.LogWarning("[Camera:EnableCrosshair] Camera manager not available.");
return false;
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null-guard checks both ActiveWorld and cameraManager, but the warning message only mentions the camera manager. To make diagnostics clearer, consider logging whether the world is missing vs. the camera manager is missing (or adjust the message to reflect both conditions).

Copilot uses AI. Check for mistakes.
Comment thread docs/api/javascript-api.md Outdated
Comment on lines +234 to +241
/// <returns>Whether or not the crosshair is enabled.</returns>
public static bool IsCrosshairEnabled()
{
if (StraightFour.StraightFour.ActiveWorld == null ||
StraightFour.StraightFour.ActiveWorld.cameraManager == null)
{
Logging.LogWarning("[Camera:IsCrosshairEnabled] Camera manager not available.");
return false;
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsCrosshairEnabled() returns false both when the crosshair is actually disabled and when the camera manager/world is unavailable, which makes it impossible for scripts to distinguish "disabled" from "could not query". Since this is a newly introduced API, consider returning a nullable boolean (bool?) and returning null when unavailable (or providing a separate availability indicator).

Suggested change
/// <returns>Whether or not the crosshair is enabled.</returns>
public static bool IsCrosshairEnabled()
{
if (StraightFour.StraightFour.ActiveWorld == null ||
StraightFour.StraightFour.ActiveWorld.cameraManager == null)
{
Logging.LogWarning("[Camera:IsCrosshairEnabled] Camera manager not available.");
return false;
/// <returns>Whether or not the crosshair is enabled, or null if the camera manager is unavailable.</returns>
public static bool? IsCrosshairEnabled()
{
if (StraightFour.StraightFour.ActiveWorld == null ||
StraightFour.StraightFour.ActiveWorld.cameraManager == null)
{
Logging.LogWarning("[Camera:IsCrosshairEnabled] Camera manager not available.");
return null;

Copilot uses AI. Check for mistakes.
dyfios and others added 2 commits April 2, 2026 20:49
…lities/Scripts/Camera.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dyfios dyfios changed the base branch from main to v3.0 April 3, 2026 00:54
@dyfios dyfios merged commit 8679c94 into v3.0 Apr 3, 2026
3 of 4 checks passed
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.

Add JavaScript APIs for crosshair feature

3 participants