@pkhex-everywhere/react 0.7.2 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @pkhex-everywhere/react
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 45aa5c8: New `trade` calls move Pokémon between the loaded save and a partner save, the way link trades, the Time Capsule, Pal Park and Poké Transfer do. `trade.open()` loads the partner and reports the routes and empty box slots, `trade.preview()` shows what each Pokémon arrives as and refuses what the games refuse, and `trade.commit()` moves them and returns both saves. New `useTrade()` hook and `trade` topic.
8
+ - Updated dependencies [45aa5c8]
9
+ - @pkhex-everywhere/engine@0.8.1
10
+
11
+ ## 0.8.0
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [c5cd974]
16
+ - Updated dependencies [d03bb1c]
17
+ - Updated dependencies [5bfab1b]
18
+ - Updated dependencies [d8b8e64]
19
+ - Updated dependencies [74c1996]
20
+ - Updated dependencies [e6f46d6]
21
+ - @pkhex-everywhere/engine@0.8.0
22
+
3
23
  ## 0.7.2
4
24
 
5
25
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import type { Binary, ItemHandle, PokemonHandle, PokemonPatch, TrainerGender } from '@pkhex-everywhere/engine';
1
+ import type { Binary, ItemHandle, PokemonHandle, PokemonPatch, TradeOffer, TrainerGender } from '@pkhex-everywhere/engine';
2
2
  /** Requires a loaded save; throws `no-save` otherwise. Wrap in `<RequireGame>`. */
3
3
  export declare function useBox(): {
4
4
  /** Requires a loaded save; throws `no-save` otherwise. Wrap in `<RequireGame>`. */
@@ -65,6 +65,21 @@ export declare function usePokemon(at: PokemonHandle): {
65
65
  update: (patch: PokemonPatch) => Promise<void>;
66
66
  pokemon: import("@pkhex-everywhere/engine").PokemonSummary;
67
67
  };
68
+ export declare function useTrade(): {
69
+ /** Closes the open trade, dropping the partner save. Closing with no trade open does nothing. */
70
+ close: () => Promise<void>;
71
+ /** Moves the offered Pokémon: each leaves its slot and lands in the first empty box slots of the other save. Fails with `trade-refused`, writing nothing, when `trade.preview()` refuses any of them. Requires a loaded save; throws `no-save` otherwise. Wrap in `<RequireGame>`. */
72
+ commit: (offer: TradeOffer) => Promise<import("@pkhex-everywhere/engine").TradeResult>;
73
+ /**
74
+ * Opens a partner save next to the loaded one, to move Pokémon between them. It replaces the partner opened before, and stays open until `trade.close()`, even when another save is loaded. Requires a loaded save; throws `no-save` otherwise. Wrap in `<RequireGame>`.
75
+ *
76
+ * @param data The partner save file's bytes.
77
+ * @param fileName The file name to export the partner with. Defaults to the name of a `File`, or `partner.sav`.
78
+ * @param formatId The id of a save format from `game.formats()` to load the partner with, as in `game.load()`.
79
+ */
80
+ open: (data: Binary, fileName?: string | null, formatId?: string | null) => Promise<import("@pkhex-everywhere/engine").TradeSummary>;
81
+ trade: import("@pkhex-everywhere/engine").TradeSummary | null;
82
+ };
68
83
  /** Requires a loaded save; throws `no-save` otherwise. Wrap in `<RequireGame>`. */
69
84
  export declare function useTrainer(): {
70
85
  /** Sets which gym badges the trainer has, one value per badge in the order `trainer.badges` lists them. Throws `not-supported` when `trainer.badges` returns null, and `out-of-range` when the number of values doesn't match. Requires a loaded save; throws `no-save` otherwise. Wrap in `<RequireGame>`. */
package/dist/index.js CHANGED
@@ -220,6 +220,26 @@ function usePokemon(at) {
220
220
  }), [engine, key])
221
221
  };
222
222
  }
223
+ function useTrade() {
224
+ const engine = useEngine();
225
+ return {
226
+ trade: useQuery("trade.get"),
227
+ ...useMemo(() => ({
228
+ /** Closes the open trade, dropping the partner save. Closing with no trade open does nothing. */
229
+ close: () => engine.trade.close(),
230
+ /** Moves the offered Pokémon: each leaves its slot and lands in the first empty box slots of the other save. Fails with `trade-refused`, writing nothing, when `trade.preview()` refuses any of them. Requires a loaded save; throws `no-save` otherwise. Wrap in `<RequireGame>`. */
231
+ commit: (offer) => engine.trade.commit(offer),
232
+ /**
233
+ * Opens a partner save next to the loaded one, to move Pokémon between them. It replaces the partner opened before, and stays open until `trade.close()`, even when another save is loaded. Requires a loaded save; throws `no-save` otherwise. Wrap in `<RequireGame>`.
234
+ *
235
+ * @param data The partner save file's bytes.
236
+ * @param fileName The file name to export the partner with. Defaults to the name of a `File`, or `partner.sav`.
237
+ * @param formatId The id of a save format from `game.formats()` to load the partner with, as in `game.load()`.
238
+ */
239
+ open: (data, fileName, formatId) => engine.trade.open(data, fileName, formatId)
240
+ }), [engine])
241
+ };
242
+ }
223
243
  /** Requires a loaded save; throws `no-save` otherwise. Wrap in `<RequireGame>`. */
224
244
  function useTrainer() {
225
245
  const engine = useEngine();
@@ -259,4 +279,4 @@ function usePokemonDetails(at) {
259
279
  };
260
280
  }
261
281
  //#endregion
262
- export { EngineProvider, RequireGame, useBox, useEngine, useEngineStatus, useEvents, useInventory, useLoadedGame, useParty, usePokemon, usePokemonDetails, useQuery, useTrainer };
282
+ export { EngineProvider, RequireGame, useBox, useEngine, useEngineStatus, useEvents, useInventory, useLoadedGame, useParty, usePokemon, usePokemonDetails, useQuery, useTrade, useTrainer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pkhex-everywhere/react",
3
- "version": "0.7.2",
3
+ "version": "0.8.1",
4
4
  "description": "React hooks for @pkhex-everywhere/engine.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "homepage": "https://docs.pkhex-everywhere.fyi/docs/",
@@ -30,7 +30,7 @@
30
30
  "test": "vitest run"
31
31
  },
32
32
  "peerDependencies": {
33
- "@pkhex-everywhere/engine": "^0.7.2",
33
+ "@pkhex-everywhere/engine": "^0.8.1",
34
34
  "react": "^19.0.0"
35
35
  },
36
36
  "devDependencies": {