@momo2555/koppeliajs 0.0.137 → 0.0.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -10,6 +10,6 @@ import { Device } from "./scripts/device.js";
10
10
  import { Play } from "./scripts/play.js";
11
11
  import { Resident } from "./scripts/resident.js";
12
12
  import { updateRoute, routeType } from './stores/routeStore.js';
13
- import { audioManager, AudioManager } from '.,/stores/audioManager.js';
13
+ import { audioManager, AudioManager } from './stores/audioManager.js';
14
14
  export { KBase, GrowableElement, Button, ResizableText };
15
15
  export { updateRoute, routeType, Koppelia, Console, Message, Device, Play, audioManager, Resident, AudioManager };
package/dist/index.js CHANGED
@@ -11,6 +11,6 @@ import { Device } from "./scripts/device.js";
11
11
  import { Play } from "./scripts/play.js";
12
12
  import { Resident } from "./scripts/resident.js";
13
13
  import { updateRoute, routeType } from './stores/routeStore.js';
14
- import { audioManager, AudioManager } from '.,/stores/audioManager.js';
14
+ import { audioManager, AudioManager } from './stores/audioManager.js';
15
15
  export { KBase, GrowableElement, Button, ResizableText }; // Compoenents
16
16
  export { updateRoute, routeType, Koppelia, Console, Message, Device, Play, audioManager, Resident, AudioManager }; // libraries and store
@@ -3,7 +3,7 @@ export declare class AudioManager {
3
3
  /**
4
4
  * Play an audio by id (creates it if doesn't exist)
5
5
  */
6
- play(id: string, loop?: boolean): void;
6
+ play(id: string, loop?: boolean, url?: string): void;
7
7
  /**
8
8
  * Pause a specific audio by id
9
9
  */
@@ -2,40 +2,68 @@ import { writable } from 'svelte/store';
2
2
  class AudioInstance {
3
3
  audio;
4
4
  id;
5
+ path;
6
+ loop;
5
7
  constructor(id, loop = false) {
6
8
  this.id = id;
7
- this.audio = new Audio(`/audios/${id}.mp3`);
8
- this.audio.loop = loop;
9
+ this.path = `/audios/${id}.mp3`;
10
+ this.loop = loop;
11
+ }
12
+ fetch() {
13
+ this.audio = new Audio(this.path);
14
+ this.audio.loop = this.loop;
9
15
  }
10
16
  play() {
11
- this.audio.play().catch(err => console.error(`Error playing ${this.id}:`, err));
17
+ if (this.audio != undefined) {
18
+ this.audio.play().catch(err => console.error(`Error playing ${this.id}:`, err));
19
+ }
12
20
  }
13
21
  pause() {
14
- this.audio.pause();
22
+ if (this.audio != undefined) {
23
+ this.audio.pause();
24
+ }
15
25
  }
16
26
  stop() {
17
- this.audio.pause();
18
- this.audio.currentTime = 0;
27
+ if (this.audio != undefined) {
28
+ this.audio.pause();
29
+ this.audio.currentTime = 0;
30
+ }
19
31
  }
20
32
  setLoop(loop) {
21
- this.audio.loop = loop;
33
+ if (this.audio != undefined) {
34
+ this.audio.loop = loop;
35
+ }
22
36
  }
23
37
  isPlaying() {
24
- return !this.audio.paused;
38
+ if (this.audio != undefined) {
39
+ return !this.audio.paused;
40
+ }
25
41
  }
26
42
  getId() {
27
43
  return this.id;
28
44
  }
29
45
  }
46
+ class AudioUrlInstance extends AudioInstance {
47
+ constructor(id, url, loop) {
48
+ super(id, loop);
49
+ this.path = url;
50
+ }
51
+ }
30
52
  export class AudioManager {
31
53
  players = new Map();
32
54
  /**
33
55
  * Play an audio by id (creates it if doesn't exist)
34
56
  */
35
- play(id, loop = false) {
57
+ play(id, loop = false, url) {
36
58
  let player = this.players.get(id);
37
59
  if (!player) {
38
- player = new AudioInstance(id, loop);
60
+ if (url !== undefined) {
61
+ player = new AudioUrlInstance(id, url, loop);
62
+ }
63
+ else {
64
+ player = new AudioInstance(id, loop);
65
+ }
66
+ player.fetch();
39
67
  this.players.set(id, player);
40
68
  }
41
69
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo2555/koppeliajs",
3
- "version": "0.0.137",
3
+ "version": "0.0.139",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",
@@ -64,4 +64,4 @@
64
64
  "fs": "^0.0.1-security",
65
65
  "uuid": "^11.1.0"
66
66
  }
67
- }
67
+ }