Skip to content

Commit

Permalink
feat: debug for raycast, raycast changes, small api changes (#41)
Browse files Browse the repository at this point in the history
* feat: debug for raycast, raycast changes, small api changes

* feat: useServerConfig

* feat: useServerConfig
  • Loading branch information
Stuyk authored Jun 9, 2024
1 parent e168c78 commit 0254ebf
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 69 deletions.
13 changes: 0 additions & 13 deletions docs/api/server/api/plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ useApi().register('my-cool-api', useMyCoolAPI());

This is all that's necessary to start working with other plugin APIs.

Below is dependent on load order, so your mileage may vary.

```ts
import { useRebar } from '@Server/index.js';

const Rebar = useRebar();
const myCoolAPI = Rebar.useApi().get('my-cool-api');

function someFunction(somePlayer: alt.Player) {
myCoolAPI.logPlayerName(somePlayer);
}
```

If you do not want to worry about load order. Consider the following pattern:

```ts
Expand Down
10 changes: 5 additions & 5 deletions docs/api/server/player/player-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ const rPlayer = Rebar.usePlayer(player);
// Commonly used raycast functions
const someVeh = await rPlayer.raycast.getFocusedEntity('vehicle');
const somePlayer = await rPlayer.raycast.getFocusedEntity('player');
const someAltvObject = await rPlayer.raycast.getFocusedEntity('object');
const someAltvObject = await rPlayer.raycast.getFocusedEntity('object', true); // Adding true draws a debug line in-game

// Get a world object and its position if available
const someWorldObject = await rPlayer.raycast.getFocusedObject();
console.log(someWorldObject.model, someWorldObject.pos, someWorldObject.scriptId);
// Get a world object, the raycast hit position, and the entity position
const someWorldObject = await rPlayer.raycast.getFocusedObject(false); // Passing `true` draws a debug line in-game
console.log(someWorldObject.model, someWorldObject.pos, someWorldObject.scriptId, someWorldObject.entityPos);

// Position where the player is looking, intersects with everything
const somePos = await rPlayer.raycast.getFocusedPosition();
const somePos = await rPlayer.raycast.getFocusedPosition(false); // Passing `true` draws a debug line in-game
```

## Player State
Expand Down
28 changes: 28 additions & 0 deletions docs/api/server/systems/useServerConfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# useServerConfig

The server config controls player-wide aspects such as radar display, vehicle class display, etc.

```ts
const serverConfig = Rebar.useServerConfig();

// Hide area name when moving around the world
serverConfig.set('hideAreaName', true);

// Hide health and armour on radar
serverConfig.set('hideHealthArmour', true);

// Hide minimap when a page is opened
serverConfig.set('hideMinimapInPage', true);

// Hide minimap when a player is on foot
serverConfig.set('hideMinimapOnFoot', true);

// Hide street name
serverConfig.set('hideStreetName', true);

// Hide vehicle class when entering a vehicle
serverConfig.set('hideVehicleClass', true);

// Hide vehicle name when entering a vehicle
serverConfig.set('hideVehicleName', true);
```
18 changes: 18 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## Version 20

### Code Changes

- Made `raycast.getFocusedObject()` return `entityPos`
- Clearly warn users using `api.get` for obtaining an API, and recommend async instead
- Added new `getMeta` API for getting plugin API as single import
- Added `debug` option to `raycast` functions to draw lines when a raycast is invoked
- Added `useServerConfig` to change what HUD elements, and other on screen elements a player sees

### Docs Changes

- Added `debug` to raycast docs
- Removed `get` from Plugin API examples, to let users focus on `async` instead
- Added `useServerConfig` to docs

---

## Version 19

### Code Changes
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "stuyk",
"type": "module",
"version": "19",
"version": "20",
"scripts": {
"dev": "nodemon -x pnpm start",
"dev:linux": "nodemon -x pnpm start:linux",
Expand Down Expand Up @@ -42,7 +42,7 @@
"typescript": "^5.4.5",
"vite": "^5.2.13",
"vue": "^3.4.27",
"vue-tsc": "^2.0.19"
"vue-tsc": "^2.0.21"
},
"prettier": {
"tabWidth": 4,
Expand Down
63 changes: 34 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/main/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,27 @@ export function useRebarClient() {
declare module 'alt-shared' {
// extending interface by interface merging
export interface ICustomGlobalMeta {
/**
* Only available client-side, client folder
*
* @type {ReturnType<typeof useRebarClient>}
* @memberof ICustomGlobalMeta
*/
RebarClient: ReturnType<typeof useRebarClient>;

/**
* Used for getting plugin APIs
*
* Only available client-side, client folder
*
* @type {ReturnType<typeof useClientApi>}
* @memberof ICustomGlobalMeta
*/
RebarClientPluginAPI: ReturnType<typeof useClientApi>;
}
}

alt.setMeta('RebarClient', useRebarClient());
alt.setMeta('RebarClientPluginAPI', useRebarClient().useClientApi());

alt.getMeta('');
1 change: 1 addition & 0 deletions src/main/client/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import './consoleCommand.js';
import './native.js';
import './notification.js';
import './raycasts.js';
import './serverConfig.js';
import './stats.js';
import './waypoint.js';

Expand Down
Loading

0 comments on commit 0254ebf

Please sign in to comment.