@novely/core 0.28.3 → 0.29.1

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
@@ -86,7 +86,7 @@ interface CharacterHandle {
86
86
  type AudioHandle = {
87
87
  stop: () => void;
88
88
  pause: () => void;
89
- play: () => void;
89
+ play: (loop: boolean) => void;
90
90
  };
91
91
  type Context = {
92
92
  id: string;
@@ -108,7 +108,7 @@ type Context = {
108
108
  audio: {
109
109
  voice: (source: string) => void;
110
110
  voiceStop: () => void;
111
- music: (source: string, method: 'music' | 'sound', loop?: boolean) => AudioHandle;
111
+ music: (source: string, method: 'music' | 'sound') => AudioHandle;
112
112
  /**
113
113
  * Stop all sounds
114
114
  */
@@ -418,7 +418,7 @@ type StateFunction<S extends State> = {
418
418
  type ValidAction = ['choice', number] | ['clear', Set<keyof DefaultActionProxy>?, Set<string>?, {
419
419
  music: Set<string>;
420
420
  sounds: Set<string>;
421
- }?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['say', string, TextContent<string, State>] | ['end'] | ['showBackground', string | NonEmptyRecord<BackgroundImage>] | ['playMusic', string] | ['stopMusic', string] | ['playSound', audio: string, loop?: boolean] | ['voice', string] | ['stopVoice'] | ['jump', string] | ['showCharacter', string, keyof Character['emotions'], string?, string?] | ['hideCharacter', string, string?, string?, number?] | ['animateCharacter', string, number, ...string[]] | ['wait', (number | ((state: State) => number))] | ['function', FunctionAction<string, State>] | ['input', string, (meta: ActionInputOnInputMeta<string, State>) => void, ActionInputSetup?] | ['custom', CustomHandler<string, State>] | ['vibrate', ...number[]] | ['next'] | ['text', ...TextContent<string, State>[]] | ['exit'] | ['preload', string] | ['block', string] | ValidAction[];
421
+ }?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['say', string, TextContent<string, State>] | ['end'] | ['showBackground', string | NonEmptyRecord<BackgroundImage>] | ['playMusic', string] | ['stopMusic', string] | ['pauseMusic', string] | ['playSound', audio: string, loop?: boolean] | ['pauseSound', string] | ['stopSound', string] | ['voice', string] | ['stopVoice'] | ['jump', string] | ['showCharacter', string, keyof Character['emotions'], string?, string?] | ['hideCharacter', string, string?, string?, number?] | ['animateCharacter', string, number, ...string[]] | ['wait', (number | ((state: State) => number))] | ['function', FunctionAction<string, State>] | ['input', string, (meta: ActionInputOnInputMeta<string, State>) => void, ActionInputSetup?] | ['custom', CustomHandler<string, State>] | ['vibrate', ...number[]] | ['next'] | ['text', ...TextContent<string, State>[]] | ['exit'] | ['preload', string] | ['block', string] | ValidAction[];
422
422
  type Story = Record<string, ValidAction[]>;
423
423
  type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
424
424
  type FunctionableValue<T> = T | (() => T);
@@ -538,8 +538,10 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
538
538
  end: () => ValidAction;
539
539
  showBackground: <T extends string | BackgroundImage>(background: T extends string ? T : T extends Record<PropertyKey, unknown> ? NonEmptyRecord<T> : never) => ValidAction;
540
540
  playMusic: (audio: string) => ValidAction;
541
+ pauseMusic: (audio: string) => ValidAction;
541
542
  stopMusic: (audio: string) => ValidAction;
542
543
  playSound: (audio: string, loop?: boolean) => ValidAction;
544
+ pauseSound: (audio: string) => ValidAction;
543
545
  stopSound: (audio: string) => ValidAction;
544
546
  /**
545
547
  * Plays voice
@@ -486,7 +486,9 @@ var Novely = (() => {
486
486
  if (target !== params[0]) {
487
487
  return false;
488
488
  }
489
- return _action === closing || _action === action;
489
+ const musicGonnaBePaused = action === "playMusic" && _action === "pauseMusic";
490
+ const soundGonnaBePaused = action === "playSound" && _action === "pauseSound";
491
+ return musicGonnaBePaused || soundGonnaBePaused || _action === closing || _action === action;
490
492
  });
491
493
  if (skip)
492
494
  continue;
@@ -1323,7 +1325,11 @@ var Novely = (() => {
1323
1325
  push();
1324
1326
  },
1325
1327
  playMusic({ ctx, push }, [source]) {
1326
- ctx.audio.music(source, "music", true).play();
1328
+ ctx.audio.music(source, "music").play(true);
1329
+ push();
1330
+ },
1331
+ pauseMusic({ ctx, push }, [source]) {
1332
+ ctx.audio.music(source, "music").pause();
1327
1333
  push();
1328
1334
  },
1329
1335
  stopMusic({ ctx, push }, [source]) {
@@ -1331,7 +1337,11 @@ var Novely = (() => {
1331
1337
  push();
1332
1338
  },
1333
1339
  playSound({ ctx, push }, [source, loop]) {
1334
- ctx.audio.music(source, "sound", loop || false).play();
1340
+ ctx.audio.music(source, "sound").play(loop || false);
1341
+ push();
1342
+ },
1343
+ pauseSound({ ctx, push }, [source]) {
1344
+ ctx.audio.music(source, "sound").pause();
1335
1345
  push();
1336
1346
  },
1337
1347
  stopSound({ ctx, push }, [source]) {