Skip to content

Commit

Permalink
feat: add plugin sounds folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed May 1, 2024
1 parent 154958a commit 804b45e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
22 changes: 20 additions & 2 deletions docs/plugins/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ If you wish to create plugins then you need to understand the basic structure of
2. Create these additional folders under the new folder you created
1. `client`
2. `server`
3. `translate`
4. `webview`
3. `sounds`
4. `translate`
5. `webview`

## client

Expand Down Expand Up @@ -43,6 +44,23 @@ const { t } = useTranslate('en');
alt.log(t('example.hello-from-server'));
```

## sounds

Sounds are custom `.ogg` files that can be played as an asset using the `Rebar.player.useAudio` function.

Here's a simple example of playing a sound called `test.ogg` which is in the `sounds folder`.

```ts
import * as alt from 'alt-server';
import { useRebar } from '@Server/index.js';

const Rebar = useRebar();

alt.on('playerConnect', async (player) => {
Rebar.player.useAudio(player).playSound('http://assets/sounds/test.ogg');
});
```

## translate

Translations can be used on `client-side`, `server-side`, or `webview` as long as you import the translation file.
Expand Down
3 changes: 3 additions & 0 deletions docs/plugins/what-is-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Plugins can be found in the `src/plugins` directory, and each plugin should have
│ └───index.ts
├───server
│ └───index.ts
├───sounds
│ ├───alert_a.ogg
│ └───alert_b.ogg
├───translate
│ └───index.ts
└───webview
Expand Down
34 changes: 34 additions & 0 deletions scripts/copyFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as fs from 'fs';
import glob from 'fast-glob';

const filesToCopy = {
'src/plugins/**/sounds/**/*.ogg': {
destination: 'resources',
keyword: 'sounds',
},
};

function copyFiles() {
const folders = Object.keys(filesToCopy);
for (let folder of folders) {
const files = glob.sync(folder);
const { destination, keyword } = filesToCopy[folder];

for (let file of files) {
const splitPath = file.split('/');

while (!splitPath[0].includes(keyword)) {
splitPath.shift();
}

if (!splitPath) {
continue;
}

const finalPath = destination + '/' + splitPath.join('/');
fs.copyFileSync(file, finalPath);
}
}
}

copyFiles();

0 comments on commit 804b45e

Please sign in to comment.