@eveshipfit/dogma-engine 11.0.1 → 11.1.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
@@ -112,6 +112,37 @@ To make rendering a fit easier, these are calculated by this library, and presen
112
112
  Their identifier is always a negative value, to visually separate them.
113
113
  What additional attributes exist are defined in [EVEShipFit/sde-patched](https://github.com/EVEShipFit/sde-patched) repository.
114
114
 
115
+ ## Validation
116
+
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
+
121
+ Each violation has:
122
+
123
+ - `target`: what the rule is about.
124
+ - `ship`, for what the ship carries as a whole.
125
+ - `item`, with the `index` into `items`.
126
+ - `charge`, with the `index` into `items` of the item holding it.
127
+ - `rule`: the rule, and the values that failed it. `type` says which:
128
+ - `resource`: `resource` ran out, `used` of `available`.
129
+ One of `cpu`, `powergrid`, `calibration`, `drone_bay`, `drone_bandwidth`, `launched_drones`, `fighter_bay`, `fighter_tubes`, `light_fighter_tubes`, `support_fighter_tubes`, `heavy_fighter_tubes`, `cargo_bay` or `charge_capacity`.
130
+ - `slots`: more items in the `slot` rack than the ship has, `used` of `available`.
131
+ One of `high`, `medium`, `low`, `rig`, `subsystem`, `service`, `turret` or `launcher`; the last two are hardpoints a weapon takes on top of its slot.
132
+ - `wrong_slot`: the item belongs in the `expected` rack.
133
+ - `slot_taken`: another item of the fit is in this slot too.
134
+ - `wrong_slot_index`: an implant or booster outside the slot it occupies, which is `expected`.
135
+ - `subsystem_taken`: another subsystem covers the same part of the ship.
136
+ - `skill`: the character is missing `type_id`, or has it at `level` where the item asks for `required`.
137
+ - `rig_size`: a rig of size `item` where the `ship` takes another.
138
+ - `ship_restricted`: the item cannot go on this ship at all.
139
+ - `capital_item`: a capital item on a ship that is not a capital.
140
+ - `max_group`: `used` of `group_id` are `limit` (`fitted`, `online` or `active`), where `allowed` may be.
141
+ This is what keeps a second propulsion module from running: an afterburner and a microwarpdrive share a group.
142
+ - `max_type`: `used` of `type_id` are fitted, where `allowed` may be.
143
+ - `charge_group`: a charge of a group the module does not take.
144
+ - `charge_size`: a charge of size `charge` where the `module` takes another.
145
+
115
146
  ## Usage
116
147
 
117
148
  The engine is published for Rust, Javascript and Python; all three calculate the same way.
@@ -131,7 +162,7 @@ cargo add esf-dogma-engine esf-data
131
162
 
132
163
  ```rust
133
164
  use esf_data::{InfoSde, Sde};
134
- use esf_dogma_engine::{Fit, Options, beacon, calculate};
165
+ use esf_dogma_engine::{Fit, Options, beacon, calculate, validate};
135
166
 
136
167
  let bytes = std::fs::read("sde.dat")?;
137
168
  let sde = Sde::new(&bytes)?;
@@ -157,6 +188,9 @@ let calculation = calculate(&info, &fit, &Options::default());
157
188
  let with_sources = calculate(&info, &fit, &Options { sources: true, ..Default::default() });
158
189
  // Or if you have a beacon in space (like wormhole effects):
159
190
  let with_beacon = calculate(&info, &Fit { incoming: beacon(&info, beacon_type_id), ..fit }, &Options::default());
191
+
192
+ // What EVE would not let you fly:
193
+ let violations = validate(&info, &fit, &calculation);
160
194
  ```
161
195
 
162
196
  ### Javascript (WebAssembly)
@@ -170,7 +204,7 @@ npm install @eveshipfit/dogma-engine @eveshipfit/sde
170
204
  ```
171
205
 
172
206
  ```js
173
- import init, { init as initPanicHook, load_sde, load_eft, calculate, beacon } from "@eveshipfit/dogma-engine";
207
+ import init, { init as initPanicHook, load_sde, load_eft, calculate, validate, beacon } from "@eveshipfit/dogma-engine";
174
208
 
175
209
  await init();
176
210
  initPanicHook();
@@ -190,6 +224,9 @@ const withSources = calculate(fit, { sources: true });
190
224
  const withBeacon = calculate({ ...fit, incoming: beacon(beaconTypeId) });
191
225
  /* Or if you have an EFT, the text format EVE copies a fit to the clipboard in: */
192
226
  const imported = calculate(load_eft("[Rifter, My Rifter]\n200mm AutoCannon I"));
227
+
228
+ /* What EVE would not let you fly; it calculates the fit itself: */
229
+ const violations = validate(fit);
193
230
  ```
194
231
 
195
232
  ### Python
@@ -228,6 +265,9 @@ with_sources = dogma.calculate(fit, {"sources": True})
228
265
  with_beacon = dogma.calculate({**fit, "incoming": dogma.beacon(beacon_type_id)})
229
266
  # Or if you have an EFT, the text format EVE copies a fit to the clipboard in:
230
267
  imported = dogma.calculate(dogma.load_eft("[Rifter, My Rifter]\n200mm AutoCannon I"))
268
+
269
+ # What EVE would not let you fly; it calculates the fit itself:
270
+ violations = dogma.validate(fit)
231
271
  ```
232
272
 
233
273
  Fits and calculations are plain dicts, typed with `TypedDict` in `esf_dogma_engine.types`.
@@ -31,3 +31,9 @@ export function load_names(bytes: Uint8Array): number;
31
31
  * error, as the first buffer is borrowed for the rest of the session.
32
32
  */
33
33
  export function load_sde(bytes: Uint8Array): number;
34
+
35
+ /**
36
+ * Report the fitting rules the fit breaks. Calculates the fit itself, as
37
+ * every rule reads the values after skills and modules changed them.
38
+ */
39
+ export function validate(js_fit: any): any;
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./esf_dogma_engine_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- beacon, calculate, init, load_eft, load_names, load_sde
8
+ beacon, calculate, init, load_eft, load_names, load_sde, validate
9
9
  } from "./esf_dogma_engine_bg.js";
@@ -77,6 +77,20 @@ export function load_sde(bytes) {
77
77
  }
78
78
  return ret[0];
79
79
  }
80
+
81
+ /**
82
+ * Report the fitting rules the fit breaks. Calculates the fit itself, as
83
+ * every rule reads the values after skills and modules changed them.
84
+ * @param {any} js_fit
85
+ * @returns {any}
86
+ */
87
+ export function validate(js_fit) {
88
+ const ret = wasm.validate(js_fit);
89
+ if (ret[2]) {
90
+ throw takeFromExternrefTable0(ret[1]);
91
+ }
92
+ return takeFromExternrefTable0(ret[0]);
93
+ }
80
94
  export function __wbg_Error_67e7344beaa85059(arg0, arg1) {
81
95
  const ret = Error(getStringFromWasm0(arg0, arg1));
82
96
  return ret;
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "EVEShipFit Team <info@eveship.fit>"
6
6
  ],
7
7
  "description": "Library to calculate statistics for EVE Online ship fits",
8
- "version": "11.0.1",
8
+ "version": "11.1.0",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",