jaml-ui 0.24.3 → 0.24.4

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.
@@ -13,6 +13,7 @@ const SEARCH_WORKER_CODE = `
13
13
  let MotelyWasm = null;
14
14
  let MotelyWasmEvents = null;
15
15
  let activeSearch = null;
16
+ let activeSearchRunId = 0;
16
17
 
17
18
  self.addEventListener('message', async function(e) {
18
19
  const msg = e.data;
@@ -35,21 +36,27 @@ self.addEventListener('message', async function(e) {
35
36
  if (!MotelyWasm) { self.postMessage({ type: 'error', message: 'Not initialized' }); return; }
36
37
  const validation = MotelyWasm.validateJaml(msg.jaml);
37
38
  if (validation !== 'valid') { self.postMessage({ type: 'error', message: validation }); return; }
39
+ const runId = ++activeSearchRunId;
38
40
 
39
41
  function cleanup() {
40
42
  MotelyWasmEvents.notifyResult = () => {};
41
43
  MotelyWasmEvents.notifyProgress = () => {};
42
44
  MotelyWasmEvents.notifyComplete = () => {};
43
- activeSearch = null;
45
+ if (runId === activeSearchRunId) {
46
+ activeSearch = null;
47
+ }
44
48
  }
45
49
 
46
50
  MotelyWasmEvents.notifyResult = function(seed, score, tallyColumns) {
51
+ if (runId !== activeSearchRunId) return;
47
52
  self.postMessage({ type: 'result', seed, score, tallyColumns: Array.from(tallyColumns) });
48
53
  };
49
54
  MotelyWasmEvents.notifyProgress = function(searched, matching) {
55
+ if (runId !== activeSearchRunId) return;
50
56
  self.postMessage({ type: 'progress', searched: searched.toString(), matching: matching.toString() });
51
57
  };
52
58
  MotelyWasmEvents.notifyComplete = function(status, searched, matched) {
59
+ if (runId !== activeSearchRunId) return;
53
60
  cleanup();
54
61
  self.postMessage({ type: 'complete', status, searched: searched.toString(), matched: matched.toString() });
55
62
  };
@@ -80,6 +87,10 @@ self.addEventListener('message', async function(e) {
80
87
  }
81
88
 
82
89
  if (msg.type === 'stop') {
90
+ activeSearchRunId++;
91
+ MotelyWasmEvents.notifyResult = () => {};
92
+ MotelyWasmEvents.notifyProgress = () => {};
93
+ MotelyWasmEvents.notifyComplete = () => {};
83
94
  if (activeSearch) { activeSearch.cancel(); activeSearch = null; }
84
95
  self.postMessage({ type: 'cancelled' });
85
96
  }
@@ -150,8 +161,14 @@ export function useSearch(motelyWasmUrl) {
150
161
  speedRef.current = { lastSearched: 0n, lastTime: 0, ema: 0 };
151
162
  setState((s) => ({
152
163
  ...s,
153
- status: msg.status === "Completed" ? "completed" : "error",
154
- error: msg.status !== "Completed" ? msg.status : null,
164
+ status: msg.status === "Completed"
165
+ ? "completed"
166
+ : msg.status === "Cancelled"
167
+ ? "cancelled"
168
+ : "error",
169
+ error: msg.status === "Completed" || msg.status === "Cancelled"
170
+ ? null
171
+ : msg.status,
155
172
  totalSearched: BigInt(msg.searched),
156
173
  matchingSeeds: BigInt(msg.matched),
157
174
  seedsPerSecond: 0,
@@ -177,6 +194,10 @@ export function useSearch(motelyWasmUrl) {
177
194
  const worker = workerRef.current;
178
195
  if (!worker)
179
196
  return;
197
+ if (!motelyWasmUrl) {
198
+ setState((s) => ({ ...s, status: "error", error: "motelyWasmUrl is required to start search" }));
199
+ return;
200
+ }
180
201
  speedRef.current = { lastSearched: 0n, lastTime: 0, ema: 0 };
181
202
  setState({ ...INITIAL_STATE, status: "running", tallyLabels: state.tallyLabels });
182
203
  const send = () => worker.postMessage(payload);
@@ -193,7 +214,7 @@ export function useSearch(motelyWasmUrl) {
193
214
  }
194
215
  };
195
216
  }
196
- }, [state.tallyLabels]);
217
+ }, [motelyWasmUrl, state.tallyLabels]);
197
218
  const start = useCallback((jaml, count) => {
198
219
  sendStart({ type: "start", mode: "random", jaml, count });
199
220
  }, [sendStart]);
@@ -1,17 +1,13 @@
1
- // UI Options derived from local constants (Blueprint retired)
2
- export const DECK_OPTIONS = ['Red', 'Blue', 'Yellow', 'Green', 'Black', 'Magic', 'Nebula', 'Ghost', 'Abandoned', 'Checkered', 'Painted', 'Anaglyph', 'Plasma', 'Erratic'];
3
- export const STAKE_OPTIONS = ['White', 'Red', 'Green', 'Black', 'Blue', 'Purple', 'Orange', 'Gold'];
1
+ import { CLAUSE_TYPE_KEYS, DECK_VALUES, EDITION_VALUES, ENHANCEMENT_VALUES, RANK_VALUES, SEAL_VALUES, SOURCE_KEYS, STAKE_VALUES, SUIT_VALUES, } from '../jaml/jamlSchema.js';
2
+ // UI options derived from the shipped JAML schema wherever possible.
3
+ export const DECK_OPTIONS = [...DECK_VALUES];
4
+ export const STAKE_OPTIONS = [...STAKE_VALUES];
4
5
  export const ANTE_OPTIONS = [1, 2, 3, 4, 5, 6, 7, 8];
5
6
  export const SLOT_OPTIONS = [1, 2, 3, 4, 5];
6
- export const RANK_OPTIONS = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace'];
7
- export const SUIT_OPTIONS = ['Spades', 'Hearts', 'Diamonds', 'Clubs'];
8
- export const ENHANCEMENT_OPTIONS = ['Bonus', 'Mult', 'Wild', 'Glass', 'Steel', 'Lucky', 'Stone', 'Gold'];
9
- export const EDITION_OPTIONS = ['Foil', 'Holographic', 'Polychrome', 'Negative'];
10
- export const SEAL_OPTIONS = ['Gold', 'Red', 'Blue', 'Purple'];
11
- export const CLAUSE_TYPES = [
12
- 'Joker', 'Tarot', 'Planet', 'Spectral', 'Voucher', 'Tag', 'Boss', 'Standardcard', 'StandardCard'
13
- ];
14
- export const SOURCE_OPTIONS = [
15
- 'shop', 'arcana_pack', 'celestial_pack', 'spectral_pack', 'buffoon_pack', 'standard_pack',
16
- 'uncommon_tag', 'rare_tag', 'top_up_tag', 'emperor', 'vagabond', 'judgement', 'wraith'
17
- ];
7
+ export const RANK_OPTIONS = [...RANK_VALUES];
8
+ export const SUIT_OPTIONS = [...SUIT_VALUES];
9
+ export const ENHANCEMENT_OPTIONS = [...ENHANCEMENT_VALUES];
10
+ export const EDITION_OPTIONS = [...EDITION_VALUES];
11
+ export const SEAL_OPTIONS = [...SEAL_VALUES];
12
+ export const CLAUSE_TYPES = [...CLAUSE_TYPE_KEYS];
13
+ export const SOURCE_OPTIONS = [...SOURCE_KEYS];
@@ -1,7 +1,5 @@
1
- export const CLAUSE_TYPES = [
2
- 'joker', 'soulJoker', 'voucher', 'tarotCard', 'planetCard',
3
- 'spectralCard', 'standardCard', 'tag', 'boss', 'event'
4
- ];
1
+ import { CLAUSE_TYPE_KEYS } from './jamlSchema.js';
2
+ export const CLAUSE_TYPES = [...CLAUSE_TYPE_KEYS];
5
3
  export const ARRAY_KEYS = ['antes', 'tags', 'labels'];
6
4
  export const JAML_KEYWORDS = [
7
5
  'must', 'should', 'mustNot', 'any', 'Any', ...CLAUSE_TYPES, ...ARRAY_KEYS