@eveshipfit/dogma-engine 11.2.0 → 13.0.0

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/README.md CHANGED
@@ -74,6 +74,7 @@ All identifiers are those from the SDE.
74
74
 
75
75
  - `sources` (optional, default false): report per attribute what its value was calculated from.
76
76
  Leave it off unless you show it; it makes the calculation several times bigger.
77
+ - `validate` (optional, default false): also report the fitting rules the fit breaks, as `violations`.
77
78
 
78
79
  ### Calculation
79
80
 
@@ -85,6 +86,8 @@ All identifiers are those from the SDE.
85
86
  - `id`: which buff, as `dbuffCollections` in the SDE numbers them.
86
87
  - `value`: how strong it is, in whatever the buff's operation reads.
87
88
  - `outgoing`: what the fit hands to other fits, in the shape `incoming` takes.
89
+ - `violations`: the fitting rules the fit breaks; only with the `validate` option.
90
+ Absent means they were not looked for, an empty list means none were broken.
88
91
 
89
92
  Each result has:
90
93
 
@@ -114,9 +117,12 @@ What additional attributes exist are defined in [EVEShipFit/sde-patched](https:/
114
117
 
115
118
  ## Validation
116
119
 
117
- `validate()` checks if the fit violates any rules that would prevent you from flying it in-game.
118
- It returns the violations, grouped by the kind of rule and, within a kind, in the order of `items`.
119
- An empty list means the fit breaks no rules.
120
+ The `validate` option checks if the fit violates any rules that would prevent you from flying it in-game.
121
+ The calculation then carries `violations`, grouped by the kind of rule and, within a kind, in the order of `items`.
122
+ An empty list means the fit breaks no rules; absent means the option was off.
123
+
124
+ Every rule reads the values after skills and modules changed them, so validation is part of `calculate()`
125
+ rather than a call of its own; asking for both costs one calculation, not two.
120
126
 
121
127
  Each violation has:
122
128
 
@@ -162,7 +168,7 @@ cargo add esf-dogma-engine esf-data
162
168
 
163
169
  ```rust
164
170
  use esf_data::{InfoSde, Sde};
165
- use esf_dogma_engine::{Fit, Options, beacon, calculate, validate};
171
+ use esf_dogma_engine::{Fit, Options, beacon, calculate};
166
172
 
167
173
  let bytes = std::fs::read("sde.dat")?;
168
174
  let sde = Sde::new(&bytes)?;
@@ -189,8 +195,8 @@ let with_sources = calculate(&info, &fit, &Options { sources: true, ..Default::d
189
195
  // Or if you have a beacon in space (like wormhole effects):
190
196
  let with_beacon = calculate(&info, &Fit { incoming: beacon(&info, beacon_type_id), ..fit }, &Options::default());
191
197
 
192
- // What EVE would not let you fly:
193
- let violations = validate(&info, &fit, &calculation);
198
+ // What EVE would not let you fly, in `violations` of the calculation:
199
+ let validated = calculate(&info, &fit, &Options { validate: true, ..Default::default() });
194
200
  ```
195
201
 
196
202
  ### Javascript (WebAssembly)
@@ -199,24 +205,24 @@ The WebAssembly variant is published on npm as
199
205
  [`@eveshipfit/dogma-engine`](https://www.npmjs.com/package/@eveshipfit/dogma-engine).
200
206
  [`@eveshipfit/sde`](https://www.npmjs.com/package/@eveshipfit/sde) ships `sde.dat` in its `dist` folder; serve or bundle that file.
201
207
 
202
- The package is built for bundlers (Vite, webpack 5, ...), which load the `.wasm` themselves.
208
+ The package is an ES module with TypeScript types included, and it runs anywhere: under a bundler
209
+ (Vite, webpack, ...), from a CDN, or in a plain `<script type="module">`.
210
+ Its default export loads the WebAssembly and has to be awaited once before any other function is called.
203
211
 
204
212
  ```bash
205
213
  npm install @eveshipfit/dogma-engine @eveshipfit/sde
206
214
  ```
207
215
 
208
216
  ```js
209
- import {
210
- init,
217
+ import wasmInit, {
211
218
  load_sde,
212
219
  load_eft,
213
220
  save_eft,
214
221
  calculate,
215
- validate,
216
222
  beacon,
217
223
  } from "@eveshipfit/dogma-engine";
218
224
 
219
- init();
225
+ await wasmInit();
220
226
 
221
227
  const sde = await fetch("/sde.dat").then((response) => response.arrayBuffer());
222
228
  const buildNumber = load_sde(new Uint8Array(sde));
@@ -236,8 +242,8 @@ const imported = calculate(load_eft("[Rifter, My Rifter]\n200mm AutoCannon I"));
236
242
  /* And to write a fit back out as EFT: */
237
243
  const eft = save_eft(fit);
238
244
 
239
- /* What EVE would not let you fly; it calculates the fit itself: */
240
- const violations = validate(fit);
245
+ /* What EVE would not let you fly, in `violations` of the calculation: */
246
+ const validated = calculate(fit, { validate: true });
241
247
  ```
242
248
 
243
249
  ### Python
@@ -279,8 +285,8 @@ imported = dogma.calculate(dogma.load_eft("[Rifter, My Rifter]\n200mm AutoCannon
279
285
  # And to write a fit back out as EFT:
280
286
  eft = dogma.save_eft(fit)
281
287
 
282
- # What EVE would not let you fly; it calculates the fit itself:
283
- violations = dogma.validate(fit)
288
+ # What EVE would not let you fly, in `violations` of the calculation:
289
+ validated = dogma.calculate(fit, {"validate": True})
284
290
  ```
285
291
 
286
292
  Fits and calculations are plain dicts, typed with `TypedDict` in `esf_dogma_engine.types`.
@@ -366,7 +372,7 @@ This is done with [wasm-pack](https://rustwasm.github.io/wasm-pack/):
366
372
 
367
373
  ```bash
368
374
  cargo install wasm-pack
369
- wasm-pack build crates/esf-wasm --release --out-dir ../../pkg
375
+ wasm-pack build crates/esf-wasm --release --target web --out-dir ../../pkg
370
376
  ```
371
377
 
372
378
  In the `pkg` folder is now a NPM module to use.
@@ -340,6 +340,10 @@ export interface Calculation {
340
340
  * All outgoing projections (effects and buffs).
341
341
  */
342
342
  outgoing?: Projection;
343
+ /**
344
+ * The fitting rules the fit breaks; only with `Options::validate`.
345
+ */
346
+ violations?: Violation[];
343
347
  }
344
348
 
345
349
  /**
@@ -374,6 +378,10 @@ export interface Options {
374
378
  * Report per attribute the modifiers its value was calculated from.
375
379
  */
376
380
  sources?: boolean;
381
+ /**
382
+ * Report the fitting rules the fit breaks.
383
+ */
384
+ validate?: boolean;
377
385
  }
378
386
 
379
387
  /**
@@ -437,8 +445,6 @@ export function beacon(type_id: number): Projection;
437
445
  */
438
446
  export function calculate(fit: Fit, options?: Options | null): Calculation;
439
447
 
440
- export function init(): void;
441
-
442
448
  /**
443
449
  * Load a fit from EFT, the text format EVE copies a fit to the clipboard in.
444
450
  */
@@ -462,8 +468,47 @@ export function load_sde(bytes: Uint8Array): number;
462
468
  */
463
469
  export function save_eft(fit: Fit): string;
464
470
 
471
+ export function set_panic_hook(): void;
472
+
473
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
474
+
475
+ export interface InitOutput {
476
+ readonly memory: WebAssembly.Memory;
477
+ readonly beacon: (a: number) => [number, number, number];
478
+ readonly calculate: (a: any, b: number) => [number, number, number];
479
+ readonly load_eft: (a: number, b: number) => [number, number, number];
480
+ readonly load_names: (a: number, b: number) => [number, number, number];
481
+ readonly load_sde: (a: number, b: number) => [number, number, number];
482
+ readonly save_eft: (a: any) => [number, number, number, number];
483
+ readonly set_panic_hook: () => void;
484
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
485
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
486
+ readonly __wbindgen_exn_store: (a: number) => void;
487
+ readonly __externref_table_alloc: () => number;
488
+ readonly __wbindgen_externrefs: WebAssembly.Table;
489
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
490
+ readonly __externref_table_dealloc: (a: number) => void;
491
+ readonly __wbindgen_start: () => void;
492
+ }
493
+
494
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
495
+
465
496
  /**
466
- * Report the fitting rules the fit breaks. Calculates the fit itself, as
467
- * every rule reads the values after skills and modules changed them.
497
+ * Instantiates the given `module`, which can either be bytes or
498
+ * a precompiled `WebAssembly.Module`.
499
+ *
500
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
501
+ *
502
+ * @returns {InitOutput}
503
+ */
504
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
505
+
506
+ /**
507
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
508
+ * for everything else, calls `WebAssembly.instantiate` directly.
509
+ *
510
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
511
+ *
512
+ * @returns {Promise<InitOutput>}
468
513
  */
469
- export function validate(fit: Fit): Violation[];
514
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;