@terrafirmagreg-team/recipe 1.2.43 → 1.2.44
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/package.json +4 -3
- package/src/components/cards/calc-add-item.tsx +2 -1
- package/src/components/views/browser/frame.tsx +36 -9
- package/src/components/views/browser/query-controls.tsx +6 -1
- package/src/components/views/browser/type-view.tsx +21 -2
- package/src/components/views/calc/calculator/help.tsx +6 -6
- package/src/components/views/calc/calculator/index.tsx +29 -6
- package/src/components/views/calc/edge.tsx +197 -113
- package/src/components/views/calc/flow/index.tsx +120 -39
- package/src/components/views/calc/flow/notes.tsx +282 -0
- package/src/components/views/calc/flow/toolbar.tsx +46 -1
- package/src/components/views/calc/flow/view-menu.tsx +11 -0
- package/src/components/views/calc/material-picker.tsx +112 -0
- package/src/components/views/calc/node-card/badges.tsx +2 -2
- package/src/components/views/calc/node-card/full.tsx +13 -2
- package/src/components/views/calc/node-card/menu.tsx +0 -17
- package/src/components/views/calc/node-card/port-cells.tsx +4 -4
- package/src/components/views/calc/node-card/ports.tsx +6 -1
- package/src/components/views/calc/recipe-picker/body.tsx +21 -5
- package/src/components/views/calc/recipe-picker/footer.tsx +1 -28
- package/src/hooks/calc/flow/use-handlers.ts +21 -14
- package/src/hooks/calc/flow/use-layout.ts +7 -7
- package/src/hooks/calc/flow/use-shift-held.ts +25 -0
- package/src/hooks/calc/use-actions.ts +126 -61
- package/src/hooks/calc/use-amounts.ts +8 -5
- package/src/hooks/calc/use-data.ts +11 -8
- package/src/hooks/calc/use-history.ts +98 -0
- package/src/hooks/calc/use-pipe-edit.ts +21 -0
- package/src/hooks/calc/use-snap.ts +17 -0
- package/src/hooks/calc/use-storage.ts +2 -1
- package/src/hooks/use-add-to-calc.ts +2 -1
- package/src/hooks/use-item-press.ts +4 -2
- package/src/hooks/use-query.ts +22 -1
- package/src/hooks/use-session.ts +2 -0
- package/src/lib/browser/row-search.test.ts +55 -0
- package/src/lib/browser/row-search.ts +24 -0
- package/src/lib/calc/flow.ts +31 -26
- package/src/lib/calc/member.test.ts +5 -5
- package/src/lib/calc/pack.ts +6 -6
- package/src/lib/calc/{wire.test.ts → pipe.test.ts} +5 -5
- package/src/lib/calc/{wire.ts → pipe.ts} +9 -9
- package/src/lib/calc/route/index.ts +1 -0
- package/src/lib/calc/scheme.test.ts +7 -7
- package/src/lib/calc/scheme.ts +16 -15
- package/src/lib/calc/storage/entry.test.ts +66 -0
- package/src/lib/calc/storage/entry.ts +29 -7
- package/src/lib/calc/storage/store.ts +3 -1
- package/src/lib/calc/tree/share.test.ts +102 -0
- package/src/lib/calc/tree/share.ts +43 -13
- package/src/lib/links.ts +3 -0
- package/src/types/calc-flow-props.ts +13 -2
- package/src/types/calc.ts +23 -3
- package/src/types/index.ts +3 -0
- package/styles/calc.css +65 -39
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import { isCalcState, migrateCalcState } from './entry';
|
|
4
|
+
import type {
|
|
5
|
+
CalcCard,
|
|
6
|
+
CalculatorState,
|
|
7
|
+
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
8
|
+
|
|
9
|
+
const CARDS: CalcCard[] = [
|
|
10
|
+
{ id: 'c1', materialId: 'gtceu:copper', kind: 'item', recipeId: null, crafts: 1 },
|
|
11
|
+
{ id: 'c2', materialId: 'gtceu:tin', kind: 'item', recipeId: null, crafts: 1 },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
test('isCalcState accepts canonical pipes', () => {
|
|
15
|
+
assert.equal(
|
|
16
|
+
isCalcState({
|
|
17
|
+
cards: CARDS,
|
|
18
|
+
pipes: [{ from: 'c1', to: 'c2', input: 0 }],
|
|
19
|
+
tagSelections: {},
|
|
20
|
+
}),
|
|
21
|
+
true,
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('isCalcState accepts legacy wires', () => {
|
|
26
|
+
assert.equal(
|
|
27
|
+
isCalcState({
|
|
28
|
+
cards: CARDS,
|
|
29
|
+
wires: [{ from: 'c1', to: 'c2', input: 0 }],
|
|
30
|
+
tagSelections: {},
|
|
31
|
+
}),
|
|
32
|
+
true,
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('isCalcState rejects a state without pipes or wires', () => {
|
|
37
|
+
assert.equal(
|
|
38
|
+
isCalcState({ cards: CARDS, tagSelections: {} }),
|
|
39
|
+
false,
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('migrateCalcState normalizes legacy wires into pipes', () => {
|
|
44
|
+
const migrated = migrateCalcState({
|
|
45
|
+
cards: CARDS,
|
|
46
|
+
wires: [
|
|
47
|
+
{ from: 'c1', to: 'c2', input: 0, amount: 8 },
|
|
48
|
+
{ from: 'c2', to: 'ghost', input: 0 },
|
|
49
|
+
],
|
|
50
|
+
tagSelections: {},
|
|
51
|
+
} as unknown as CalculatorState);
|
|
52
|
+
assert.deepEqual(migrated.pipes, [
|
|
53
|
+
{ from: 'c1', to: 'c2', input: 0, amount: 8 },
|
|
54
|
+
]);
|
|
55
|
+
assert.equal((migrated as { wires?: unknown }).wires, undefined);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('migrateCalcState keeps canonical pipes', () => {
|
|
59
|
+
const migrated = migrateCalcState({
|
|
60
|
+
cards: CARDS,
|
|
61
|
+
pipes: [{ from: 'c1', to: 'c2', input: 3 }],
|
|
62
|
+
tagSelections: {},
|
|
63
|
+
notes: [],
|
|
64
|
+
});
|
|
65
|
+
assert.deepEqual(migrated.pipes, [{ from: 'c1', to: 'c2', input: 3 }]);
|
|
66
|
+
});
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
CALC_NOTE_COLORS,
|
|
3
|
+
type CalculatorState,
|
|
4
|
+
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
2
5
|
|
|
3
6
|
const MAX_HISTORY = 5;
|
|
4
7
|
|
|
@@ -31,35 +34,54 @@ const isCardRow = (row: unknown): boolean =>
|
|
|
31
34
|
((row as { kind?: unknown }).kind === 'item' ||
|
|
32
35
|
(row as { kind?: unknown }).kind === 'fluid');
|
|
33
36
|
|
|
34
|
-
const
|
|
37
|
+
const isPipeRow = (row: unknown): boolean =>
|
|
35
38
|
!!row &&
|
|
36
39
|
typeof row === 'object' &&
|
|
37
40
|
typeof (row as { from?: unknown }).from === 'string' &&
|
|
38
41
|
typeof (row as { to?: unknown }).to === 'string' &&
|
|
39
42
|
typeof (row as { input?: unknown }).input === 'number';
|
|
40
43
|
|
|
44
|
+
const pipeRows = (row: Record<string, unknown>): unknown =>
|
|
45
|
+
Array.isArray(row.pipes) ? row.pipes : row.wires;
|
|
46
|
+
|
|
47
|
+
const isNoteRow = (row: unknown): boolean =>
|
|
48
|
+
!!row &&
|
|
49
|
+
typeof row === 'object' &&
|
|
50
|
+
typeof (row as { id?: unknown }).id === 'string' &&
|
|
51
|
+
typeof (row as { text?: unknown }).text === 'string' &&
|
|
52
|
+
typeof (row as { pos?: unknown }).pos === 'object' &&
|
|
53
|
+
((row as { color?: unknown }).color === undefined ||
|
|
54
|
+
(CALC_NOTE_COLORS as readonly unknown[]).includes(
|
|
55
|
+
(row as { color?: unknown }).color,
|
|
56
|
+
));
|
|
57
|
+
|
|
41
58
|
export function isCalcState(value: unknown): value is CalculatorState {
|
|
42
59
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
43
60
|
const row = value as Record<string, unknown>;
|
|
61
|
+
const pipes = pipeRows(row);
|
|
44
62
|
return (
|
|
45
63
|
Array.isArray(row.cards) &&
|
|
46
64
|
row.cards.every(isCardRow) &&
|
|
47
|
-
Array.isArray(
|
|
48
|
-
|
|
65
|
+
Array.isArray(pipes) &&
|
|
66
|
+
pipes.every(isPipeRow) &&
|
|
49
67
|
!!row.tagSelections &&
|
|
50
|
-
typeof row.tagSelections === 'object'
|
|
68
|
+
typeof row.tagSelections === 'object' &&
|
|
69
|
+
(row.notes === undefined ||
|
|
70
|
+
(Array.isArray(row.notes) && row.notes.every(isNoteRow)))
|
|
51
71
|
);
|
|
52
72
|
}
|
|
53
73
|
|
|
54
74
|
export function migrateCalcState(state: CalculatorState): CalculatorState {
|
|
55
75
|
const cards = Array.isArray(state.cards) ? state.cards.filter(isCardRow) : [];
|
|
56
76
|
const ids = new Set(cards.map((card) => card.id));
|
|
77
|
+
const stored = state.pipes ?? (state as { wires?: unknown }).wires;
|
|
57
78
|
return {
|
|
58
79
|
cards,
|
|
59
|
-
|
|
60
|
-
(
|
|
80
|
+
pipes: (Array.isArray(stored) ? stored.filter(isPipeRow) : []).filter(
|
|
81
|
+
(pipe) => ids.has(pipe.from) && ids.has(pipe.to),
|
|
61
82
|
),
|
|
62
83
|
tagSelections: state.tagSelections,
|
|
84
|
+
notes: Array.isArray(state.notes) ? state.notes.filter(isNoteRow) : [],
|
|
63
85
|
};
|
|
64
86
|
}
|
|
65
87
|
|
|
@@ -85,7 +85,9 @@ function writeHistoryRaw(key: string, entries: CalcTreeEntry[]): void {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
function syncHistory(key: string, tabs: CalcTreeEntry[]): void {
|
|
88
|
-
const live = tabs.filter(
|
|
88
|
+
const live = tabs.filter(
|
|
89
|
+
(tab) => tab.state.cards.length || tab.state.notes.length,
|
|
90
|
+
);
|
|
89
91
|
if (!live.length) return;
|
|
90
92
|
const prev = readCalcHistory(key);
|
|
91
93
|
const ids = new Set(live.map((tab) => tab.id));
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import { deflateSync, strToU8 } from 'fflate';
|
|
4
|
+
import { decodeCalcState, encodeCalcState } from './share';
|
|
5
|
+
import type { CalculatorState } from '@terrafirmagreg-team/recipe/types/calc';
|
|
6
|
+
|
|
7
|
+
const STATE: CalculatorState = {
|
|
8
|
+
cards: [
|
|
9
|
+
{
|
|
10
|
+
id: 'c1',
|
|
11
|
+
materialId: 'gtceu:amethyst_rod',
|
|
12
|
+
kind: 'item',
|
|
13
|
+
recipeId: 'gtceu:lathe/lathe_amethyst_to_rod',
|
|
14
|
+
crafts: 4,
|
|
15
|
+
pos: { x: 100, y: 200 },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: 'c2',
|
|
19
|
+
materialId: 'gtceu:amethyst_gem',
|
|
20
|
+
kind: 'item',
|
|
21
|
+
recipeId: null,
|
|
22
|
+
crafts: 1,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
pipes: [{ from: 'c1', to: 'c2', input: 0, amount: 8 }],
|
|
26
|
+
tagSelections: { 'tfg:rods': 'gtceu:amethyst_rod' },
|
|
27
|
+
notes: [
|
|
28
|
+
{ id: 'n_a', text: 'LV tier only', pos: { x: 10.4, y: -20.6 } },
|
|
29
|
+
{
|
|
30
|
+
id: 'n_b',
|
|
31
|
+
text: 'многострочная\nзаметка',
|
|
32
|
+
pos: { x: 0, y: 0 },
|
|
33
|
+
color: 'emerald',
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
test('calc share round-trips cards, pipes, tags and notes', () => {
|
|
39
|
+
const decoded = decodeCalcState(encodeCalcState(STATE));
|
|
40
|
+
assert.ok(decoded);
|
|
41
|
+
assert.equal(decoded.cards.length, 2);
|
|
42
|
+
assert.equal(decoded.cards[0]?.id, 'c0');
|
|
43
|
+
assert.equal(decoded.cards[0]?.materialId, 'gtceu:amethyst_rod');
|
|
44
|
+
assert.equal(decoded.cards[0]?.crafts, 4);
|
|
45
|
+
assert.deepEqual(decoded.cards[0]?.pos, { x: 100, y: 200 });
|
|
46
|
+
assert.equal(decoded.cards[1]?.recipeId, null);
|
|
47
|
+
assert.deepEqual(decoded.pipes, [
|
|
48
|
+
{ from: 'c0', to: 'c1', input: 0, out: undefined, amount: 8 },
|
|
49
|
+
]);
|
|
50
|
+
assert.deepEqual(decoded.tagSelections, STATE.tagSelections);
|
|
51
|
+
assert.equal(decoded.notes.length, 2);
|
|
52
|
+
assert.equal(decoded.notes[0]?.id, 'n_a');
|
|
53
|
+
assert.equal(decoded.notes[0]?.text, 'LV tier only');
|
|
54
|
+
assert.deepEqual(decoded.notes[0]?.pos, { x: 10, y: -21 });
|
|
55
|
+
assert.equal(decoded.notes[1]?.text, 'многострочная\nзаметка');
|
|
56
|
+
assert.equal(decoded.notes[0]?.color, undefined);
|
|
57
|
+
assert.equal(decoded.notes[1]?.color, 'emerald');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('calc share decodes legacy payloads without notes', () => {
|
|
61
|
+
const { notes: _drop, ...legacy } = STATE;
|
|
62
|
+
const decoded = decodeCalcState(encodeCalcState(legacy as CalculatorState));
|
|
63
|
+
assert.ok(decoded);
|
|
64
|
+
assert.deepEqual(decoded.notes, []);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('calc share drops malformed note rows but keeps valid ones', () => {
|
|
68
|
+
const encoded = encodeCalcState(STATE);
|
|
69
|
+
const decoded = decodeCalcState(encoded);
|
|
70
|
+
assert.ok(decoded);
|
|
71
|
+
assert.equal(decoded.notes.length, 2);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('calc share decodes legacy wire payloads', () => {
|
|
75
|
+
const payload = {
|
|
76
|
+
v: 2,
|
|
77
|
+
d: ['gtceu:amethyst_rod', 'gtceu:amethyst_gem'],
|
|
78
|
+
c: [
|
|
79
|
+
[0, 0, -1, 1, 100, 200, 1],
|
|
80
|
+
[1, 0, -1, 1, 0, 0, 0],
|
|
81
|
+
],
|
|
82
|
+
w: [[0, 1, 2, 1, 64]],
|
|
83
|
+
g: {},
|
|
84
|
+
n: [],
|
|
85
|
+
};
|
|
86
|
+
const u8 = deflateSync(strToU8(JSON.stringify(payload)));
|
|
87
|
+
let bin = '';
|
|
88
|
+
for (let i = 0; i < u8.length; i += 8192) {
|
|
89
|
+
bin += String.fromCharCode(...u8.subarray(i, i + 8192));
|
|
90
|
+
}
|
|
91
|
+
const encoded = `x${btoa(bin).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')}`;
|
|
92
|
+
const decoded = decodeCalcState(encoded);
|
|
93
|
+
assert.ok(decoded);
|
|
94
|
+
assert.deepEqual(decoded.pipes, [
|
|
95
|
+
{ from: 'c0', to: 'c1', input: 2, out: 1, amount: 64 },
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('calc share rejects garbage', () => {
|
|
100
|
+
assert.equal(decodeCalcState(''), null);
|
|
101
|
+
assert.equal(decodeCalcState('!!!not-base64!!!'), null);
|
|
102
|
+
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { deflateSync, inflateSync, strFromU8, strToU8 } from 'fflate';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import {
|
|
3
|
+
CALC_NOTE_COLORS,
|
|
4
|
+
type CalcCard,
|
|
5
|
+
type CalcNote,
|
|
6
|
+
type CalculatorState,
|
|
7
|
+
type CalcPipe,
|
|
6
8
|
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
7
9
|
|
|
8
10
|
function encodeUrlSafe(base64: string): string {
|
|
@@ -47,12 +49,12 @@ export function encodeCalcState(state: CalculatorState): string {
|
|
|
47
49
|
];
|
|
48
50
|
return row;
|
|
49
51
|
});
|
|
50
|
-
const
|
|
51
|
-
const from = indexOf.get(
|
|
52
|
-
const to = indexOf.get(
|
|
52
|
+
const pipes = state.pipes.flatMap((pipe) => {
|
|
53
|
+
const from = indexOf.get(pipe.from);
|
|
54
|
+
const to = indexOf.get(pipe.to);
|
|
53
55
|
return from === undefined || to === undefined
|
|
54
56
|
? []
|
|
55
|
-
: [[from, to,
|
|
57
|
+
: [[from, to, pipe.input, pipe.out ?? 0, pipe.amount ?? 0]];
|
|
56
58
|
});
|
|
57
59
|
const tagSelections: Record<string, number> = {};
|
|
58
60
|
for (const [tagId, memberId] of Object.entries(state.tagSelections)) {
|
|
@@ -62,8 +64,17 @@ export function encodeCalcState(state: CalculatorState): string {
|
|
|
62
64
|
v: 2,
|
|
63
65
|
d: [...dict.keys()],
|
|
64
66
|
c: cards,
|
|
65
|
-
|
|
67
|
+
p: pipes,
|
|
66
68
|
g: tagSelections,
|
|
69
|
+
n: (state.notes ?? []).map((note) => [
|
|
70
|
+
note.id,
|
|
71
|
+
note.text,
|
|
72
|
+
Math.round(note.pos.x),
|
|
73
|
+
Math.round(note.pos.y),
|
|
74
|
+
...(note.color && note.color !== 'amber'
|
|
75
|
+
? [CALC_NOTE_COLORS.indexOf(note.color)]
|
|
76
|
+
: []),
|
|
77
|
+
]),
|
|
67
78
|
};
|
|
68
79
|
const packed = deflateSync(strToU8(JSON.stringify(payload)));
|
|
69
80
|
return `x${encodeUrlSafe(btoa(u8ToBinary(packed)))}`;
|
|
@@ -79,8 +90,10 @@ export function decodeCalcState(encoded: string): CalculatorState | null {
|
|
|
79
90
|
v?: number;
|
|
80
91
|
d?: string[];
|
|
81
92
|
c?: number[][];
|
|
93
|
+
p?: number[][];
|
|
82
94
|
w?: number[][];
|
|
83
95
|
g?: Record<string, number>;
|
|
96
|
+
n?: unknown[][];
|
|
84
97
|
};
|
|
85
98
|
if (payload.v !== 2 || !Array.isArray(payload.d)) return null;
|
|
86
99
|
const dict = payload.d;
|
|
@@ -107,13 +120,13 @@ export function decodeCalcState(encoded: string): CalculatorState | null {
|
|
|
107
120
|
: undefined,
|
|
108
121
|
});
|
|
109
122
|
}
|
|
110
|
-
const
|
|
111
|
-
for (const row of payload.w ?? []) {
|
|
123
|
+
const pipes: CalcPipe[] = [];
|
|
124
|
+
for (const row of payload.p ?? payload.w ?? []) {
|
|
112
125
|
if (!Array.isArray(row)) continue;
|
|
113
126
|
const from = cards[row[0]!];
|
|
114
127
|
const to = cards[row[1]!];
|
|
115
128
|
if (!from || !to) continue;
|
|
116
|
-
|
|
129
|
+
pipes.push({
|
|
117
130
|
from: from.id,
|
|
118
131
|
to: to.id,
|
|
119
132
|
input: Number(row[2]) || 0,
|
|
@@ -127,7 +140,24 @@ export function decodeCalcState(encoded: string): CalculatorState | null {
|
|
|
127
140
|
const memberId = id(memberIdx);
|
|
128
141
|
if (tagId && memberId) tagSelections[tagId] = memberId;
|
|
129
142
|
}
|
|
130
|
-
|
|
143
|
+
const notes: CalcNote[] = [];
|
|
144
|
+
for (const row of payload.n ?? []) {
|
|
145
|
+
if (!Array.isArray(row)) continue;
|
|
146
|
+
const noteId = row[0];
|
|
147
|
+
const text = row[1];
|
|
148
|
+
if (typeof noteId !== 'string' || typeof text !== 'string') continue;
|
|
149
|
+
const colorIdx = Number(row[4]);
|
|
150
|
+
notes.push({
|
|
151
|
+
id: noteId,
|
|
152
|
+
text,
|
|
153
|
+
pos: { x: Number(row[2]) || 0, y: Number(row[3]) || 0 },
|
|
154
|
+
color:
|
|
155
|
+
colorIdx > 0 && colorIdx < CALC_NOTE_COLORS.length
|
|
156
|
+
? CALC_NOTE_COLORS[colorIdx]
|
|
157
|
+
: undefined,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return { cards, pipes, tagSelections, notes };
|
|
131
161
|
} catch {
|
|
132
162
|
return null;
|
|
133
163
|
}
|
package/src/lib/links.ts
CHANGED
|
@@ -68,6 +68,7 @@ export function recipeHref(
|
|
|
68
68
|
['mix', opts?.tool === 'alloy' ? opts?.mix : undefined],
|
|
69
69
|
['tab', opts?.tab],
|
|
70
70
|
['search', opts?.search],
|
|
71
|
+
['rsearch', opts?.rsearch],
|
|
71
72
|
[
|
|
72
73
|
'rpage',
|
|
73
74
|
opts?.rpage && opts.rpage > 1 ? Math.floor(opts.rpage) : undefined,
|
|
@@ -84,10 +85,12 @@ export function recipeCalcHref(
|
|
|
84
85
|
lang: Lang | undefined,
|
|
85
86
|
tree?: string,
|
|
86
87
|
version?: string,
|
|
88
|
+
rsearch?: string,
|
|
87
89
|
): string {
|
|
88
90
|
const query = recipeQuery([
|
|
89
91
|
['tool', 'calc'],
|
|
90
92
|
['tree', tree],
|
|
93
|
+
['rsearch', rsearch],
|
|
91
94
|
['version', version ?? hrefVersion(dataset)],
|
|
92
95
|
]);
|
|
93
96
|
const href = `${recipeBasePath(dataset)}?${query}`;
|
|
@@ -8,13 +8,14 @@ import type {
|
|
|
8
8
|
import type {
|
|
9
9
|
CalcCard,
|
|
10
10
|
CalcNode,
|
|
11
|
-
|
|
11
|
+
CalcNote,
|
|
12
|
+
CalcPipe,
|
|
12
13
|
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
13
14
|
import type { RecipeSession } from '@terrafirmagreg-team/recipe/types';
|
|
14
15
|
|
|
15
16
|
export type CalcFlowProps = {
|
|
16
17
|
nodes: CalcNode[];
|
|
17
|
-
|
|
18
|
+
pipes: CalcPipe[];
|
|
18
19
|
flows?: readonly (number | undefined)[];
|
|
19
20
|
cards: CalcCard[];
|
|
20
21
|
dataset: DatasetRef;
|
|
@@ -34,6 +35,16 @@ export type CalcFlowProps = {
|
|
|
34
35
|
onFarCardsChange: (mode: CalcFarMode) => void;
|
|
35
36
|
recipeIds: boolean;
|
|
36
37
|
onRecipeIdsChange: (show: boolean) => void;
|
|
38
|
+
snap: boolean;
|
|
39
|
+
onSnapChange: (snap: boolean) => void;
|
|
40
|
+
notes: CalcNote[];
|
|
41
|
+
onAddNote?: (pos: { x: number; y: number }) => void;
|
|
42
|
+
history?: {
|
|
43
|
+
canUndo: boolean;
|
|
44
|
+
canRedo: boolean;
|
|
45
|
+
onUndo: () => void;
|
|
46
|
+
onRedo: () => void;
|
|
47
|
+
};
|
|
37
48
|
treeReady?: boolean;
|
|
38
49
|
resetGen?: number;
|
|
39
50
|
canvasId?: string;
|
package/src/types/calc.ts
CHANGED
|
@@ -42,7 +42,7 @@ export type CalcCard = {
|
|
|
42
42
|
pos?: { x: number; y: number };
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
export type
|
|
45
|
+
export type CalcPipe = {
|
|
46
46
|
from: string;
|
|
47
47
|
to: string;
|
|
48
48
|
input: number;
|
|
@@ -50,10 +50,29 @@ export type CalcWire = {
|
|
|
50
50
|
amount?: number;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
export const CALC_NOTE_COLORS = [
|
|
54
|
+
'amber',
|
|
55
|
+
'slate',
|
|
56
|
+
'sky',
|
|
57
|
+
'emerald',
|
|
58
|
+
'rose',
|
|
59
|
+
'violet',
|
|
60
|
+
] as const;
|
|
61
|
+
|
|
62
|
+
export type CalcNoteColor = (typeof CALC_NOTE_COLORS)[number];
|
|
63
|
+
|
|
64
|
+
export type CalcNote = {
|
|
65
|
+
id: string;
|
|
66
|
+
text: string;
|
|
67
|
+
pos: { x: number; y: number };
|
|
68
|
+
color?: CalcNoteColor;
|
|
69
|
+
};
|
|
70
|
+
|
|
53
71
|
export type CalculatorState = {
|
|
54
72
|
cards: CalcCard[];
|
|
55
|
-
|
|
73
|
+
pipes: CalcPipe[];
|
|
56
74
|
tagSelections: Record<string, string>;
|
|
75
|
+
notes: CalcNote[];
|
|
57
76
|
};
|
|
58
77
|
|
|
59
78
|
export type CalcNodeInput = {
|
|
@@ -61,9 +80,10 @@ export type CalcNodeInput = {
|
|
|
61
80
|
kind: CalcKind;
|
|
62
81
|
amount: number;
|
|
63
82
|
catalyst: boolean;
|
|
83
|
+
chance?: number;
|
|
64
84
|
tagId?: string;
|
|
65
85
|
members?: string[];
|
|
66
|
-
|
|
86
|
+
connected: boolean;
|
|
67
87
|
covered: number;
|
|
68
88
|
};
|
|
69
89
|
|
package/src/types/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type RecipeHrefOpts = {
|
|
|
22
22
|
solo?: string;
|
|
23
23
|
tab?: string;
|
|
24
24
|
search?: string;
|
|
25
|
+
rsearch?: string;
|
|
25
26
|
rpage?: number;
|
|
26
27
|
type?: string;
|
|
27
28
|
relation?: RecipeRelation;
|
|
@@ -127,6 +128,8 @@ export type RecipeSession = {
|
|
|
127
128
|
tree?: string;
|
|
128
129
|
query: string;
|
|
129
130
|
setQuery: (query: string) => void;
|
|
131
|
+
rquery: string;
|
|
132
|
+
setRquery: (query: string) => void;
|
|
130
133
|
rpage: number;
|
|
131
134
|
nav: RecipeHrefOpts;
|
|
132
135
|
index: RecipeCompactIndex | null;
|
package/styles/calc.css
CHANGED
|
@@ -192,11 +192,16 @@
|
|
|
192
192
|
font-size: 6px;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
.calc-edge--
|
|
195
|
+
.calc-edge--pipe.selected .chevron-edge__base,
|
|
196
196
|
.react-flow__edge.selected .chevron-edge__base {
|
|
197
197
|
stroke: var(--color-primary);
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
.calc-edge--pipe.selected .chevron-edge__case,
|
|
201
|
+
.react-flow__edge.selected .chevron-edge__case {
|
|
202
|
+
stroke: color-mix(in oklab, var(--color-primary) 45%, var(--color-border));
|
|
203
|
+
}
|
|
204
|
+
|
|
200
205
|
.calc-flow .react-flow__node:not(.dragging) {
|
|
201
206
|
transition: transform 240ms ease;
|
|
202
207
|
}
|
|
@@ -237,73 +242,94 @@
|
|
|
237
242
|
display: none;
|
|
238
243
|
}
|
|
239
244
|
|
|
240
|
-
.calc-edge-
|
|
241
|
-
|
|
245
|
+
.calc-edge-hotspot {
|
|
246
|
+
width: 14px;
|
|
247
|
+
height: 14px;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.calc-edge-del {
|
|
251
|
+
display: flex;
|
|
242
252
|
align-items: center;
|
|
243
|
-
|
|
253
|
+
justify-content: center;
|
|
254
|
+
width: 13px;
|
|
255
|
+
height: 13px;
|
|
244
256
|
border-radius: 4px;
|
|
257
|
+
border: 1px solid var(--color-destructive);
|
|
258
|
+
background: var(--color-popover);
|
|
259
|
+
color: var(--color-destructive);
|
|
260
|
+
pointer-events: none;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.calc-edge-edit {
|
|
264
|
+
display: flex;
|
|
265
|
+
flex-direction: column;
|
|
266
|
+
gap: 4px;
|
|
267
|
+
min-width: 118px;
|
|
268
|
+
border-radius: 6px;
|
|
245
269
|
border: 1px solid var(--color-border);
|
|
246
|
-
background: var(--color-
|
|
247
|
-
padding:
|
|
270
|
+
background: var(--color-popover);
|
|
271
|
+
padding: 4px 6px;
|
|
248
272
|
font-size: 9px;
|
|
249
273
|
line-height: 1.3;
|
|
250
|
-
color: var(--color-
|
|
251
|
-
|
|
274
|
+
color: var(--color-foreground);
|
|
275
|
+
box-shadow:
|
|
276
|
+
0 4px 12px -2px rgb(0 0 0 / 0.2),
|
|
277
|
+
0 0 0 1px rgb(0 0 0 / 0.05);
|
|
252
278
|
pointer-events: all;
|
|
253
279
|
}
|
|
254
280
|
|
|
255
|
-
.calc-edge-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
color: var(--color-foreground);
|
|
261
|
-
border-color: var(--color-muted-foreground);
|
|
281
|
+
.calc-edge-edit__head {
|
|
282
|
+
display: flex;
|
|
283
|
+
align-items: center;
|
|
284
|
+
gap: 4px;
|
|
285
|
+
min-width: 0;
|
|
262
286
|
}
|
|
263
287
|
|
|
264
|
-
.calc-edge-
|
|
265
|
-
|
|
288
|
+
.calc-edge-edit__name {
|
|
289
|
+
min-width: 0;
|
|
266
290
|
overflow: hidden;
|
|
267
291
|
text-overflow: ellipsis;
|
|
268
292
|
white-space: nowrap;
|
|
269
|
-
|
|
293
|
+
font-weight: 600;
|
|
270
294
|
}
|
|
271
295
|
|
|
272
|
-
.calc-edge-
|
|
273
|
-
display:
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
font-weight: 600;
|
|
277
|
-
line-height: 1;
|
|
296
|
+
.calc-edge-edit__row {
|
|
297
|
+
display: flex;
|
|
298
|
+
align-items: center;
|
|
299
|
+
gap: 5px;
|
|
278
300
|
}
|
|
279
301
|
|
|
280
|
-
.calc-edge-
|
|
281
|
-
|
|
302
|
+
.calc-edge-edit__label {
|
|
303
|
+
flex-shrink: 0;
|
|
304
|
+
color: var(--color-muted-foreground);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.calc-edge-edit__input {
|
|
308
|
+
flex: 1;
|
|
309
|
+
min-width: 0;
|
|
282
310
|
border-radius: 4px;
|
|
283
311
|
border: 1px solid var(--color-primary);
|
|
284
312
|
background: var(--color-card);
|
|
285
|
-
padding:
|
|
286
|
-
font-size:
|
|
313
|
+
padding: 0 4px;
|
|
314
|
+
font-size: 10px;
|
|
287
315
|
outline: none;
|
|
288
316
|
}
|
|
289
317
|
|
|
290
|
-
.calc-
|
|
291
|
-
|
|
318
|
+
.calc-edge-edit__unit {
|
|
319
|
+
flex-shrink: 0;
|
|
320
|
+
color: var(--color-muted-foreground);
|
|
292
321
|
}
|
|
293
322
|
|
|
294
|
-
.calc-flow--shift
|
|
295
|
-
|
|
296
|
-
.calc-edge-label
|
|
297
|
-
.calc-edge-label__amount {
|
|
298
|
-
display: none;
|
|
323
|
+
.calc-flow--shift .react-flow__edge {
|
|
324
|
+
cursor: pointer;
|
|
299
325
|
}
|
|
300
326
|
|
|
301
|
-
.calc-flow--shift .
|
|
302
|
-
|
|
327
|
+
.calc-flow--shift .chevron-edge--hover .chevron-edge__base {
|
|
328
|
+
stroke: var(--color-destructive);
|
|
303
329
|
}
|
|
304
330
|
|
|
305
|
-
.calc-flow--shift .
|
|
306
|
-
stroke: var(--color-
|
|
331
|
+
.calc-flow--shift .chevron-edge--hover .chevron-edge__case {
|
|
332
|
+
stroke: color-mix(in oklab, var(--color-destructive) 55%, var(--color-border));
|
|
307
333
|
}
|
|
308
334
|
|
|
309
335
|
.react-flow__node.calc-node--dim {
|