@terrafirmagreg-team/recipe 1.2.11 → 1.2.13
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 +3 -3
- package/src/components/views/browser/axis-switcher.tsx +11 -3
- package/src/components/views/browser/index.tsx +6 -2
- package/src/components/views/browser/item-panel/index.tsx +5 -2
- package/src/components/views/browser/item-panel-grid/index.tsx +7 -1
- package/src/components/views/browser/toolbar.tsx +5 -2
- package/src/components/views/calc/calculator/index.tsx +3 -0
- package/src/components/views/calc/flow/index.tsx +10 -2
- package/src/components/views/calc/flow/picker-dialogs.tsx +122 -5
- package/src/components/views/calc/node-card/full.tsx +0 -1
- package/src/components/views/calc/node-card/menu.tsx +17 -1
- package/src/components/views/calc/node-card/port-cells.tsx +23 -6
- package/src/components/views/calc/node-card/port-rails.tsx +1 -3
- package/src/hooks/calc/flow/use-handlers.ts +14 -6
- package/src/hooks/calc/flow/use-layout.ts +5 -0
- package/src/hooks/calc/flow/use-pickers.ts +15 -0
- package/src/hooks/calc/flow/use-viewport.ts +1 -1
- package/src/hooks/calc/use-actions.ts +144 -4
- package/src/hooks/calc/use-defaults.ts +4 -0
- package/src/hooks/calc/use-resolver.ts +1 -0
- package/src/hooks/calc/use-storage.ts +6 -1
- package/src/hooks/use-index.ts +10 -0
- package/src/hooks/use-left-sidebar-tree.ts +4 -1
- package/src/lib/calc/defaults.ts +43 -5
- package/src/lib/calc/flow.ts +32 -14
- package/src/lib/calc/scheme.ts +24 -16
- package/src/lib/calc/storage/index.ts +1 -0
- package/src/lib/calc/storage/keys.ts +1 -1
- package/src/lib/calc/storage/store.ts +62 -0
- package/src/lib/calc/tree/recipe.ts +1 -0
- package/src/lib/calc/wire.ts +39 -0
- package/src/lib/calc/worker/resolve.ts +7 -0
- package/src/lib/client-index/chrome.ts +56 -38
- package/src/lib/client-index/index.ts +1 -1
- package/src/lib/links.ts +2 -1
- package/src/types/calc-flow-props.ts +1 -0
- package/src/types/calc.ts +2 -1
- package/styles/calc.css +4 -0
|
@@ -186,6 +186,68 @@ export function writeCalcStorage(
|
|
|
186
186
|
writeCalcTabs(key, [...tabs, entry], entry.id);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
const migrated = new Set<string>();
|
|
190
|
+
|
|
191
|
+
function mergeEntries(lists: CalcTreeEntry[][]): CalcTreeEntry[] {
|
|
192
|
+
const byId = new Map<string, CalcTreeEntry>();
|
|
193
|
+
for (const list of lists) {
|
|
194
|
+
for (const entry of list) {
|
|
195
|
+
const prev = byId.get(entry.id);
|
|
196
|
+
if (!prev || (entry.savedAt ?? 0) > (prev.savedAt ?? 0)) {
|
|
197
|
+
byId.set(entry.id, entry);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return [...byId.values()];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function legacyKeys(prefix: string): string[] {
|
|
205
|
+
const keys: string[] = [];
|
|
206
|
+
for (let i = 0; i < window.localStorage.length; i += 1) {
|
|
207
|
+
const name = window.localStorage.key(i);
|
|
208
|
+
if (name && name.startsWith(prefix)) keys.push(name);
|
|
209
|
+
}
|
|
210
|
+
return keys;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function migrateCalcStorage(key: string): void {
|
|
214
|
+
if (typeof window === 'undefined' || migrated.has(key)) return;
|
|
215
|
+
migrated.add(key);
|
|
216
|
+
try {
|
|
217
|
+
const tabKeys = legacyKeys(`${key}/`);
|
|
218
|
+
const histKeys = legacyKeys(`${historyKey(key)}/`);
|
|
219
|
+
if (!tabKeys.length && !histKeys.length) return;
|
|
220
|
+
if (tabKeys.length) {
|
|
221
|
+
const lists = [readCalcTabs(key)].filter((list) => list.length);
|
|
222
|
+
for (const legacy of tabKeys) {
|
|
223
|
+
const tabs = readCalcTabs(legacy);
|
|
224
|
+
if (tabs.length) lists.push(tabs);
|
|
225
|
+
}
|
|
226
|
+
writeTabsRaw(key, mergeEntries(lists));
|
|
227
|
+
}
|
|
228
|
+
if (histKeys.length) {
|
|
229
|
+
const lists = [readCalcHistory(key)].filter((list) => list.length);
|
|
230
|
+
for (const legacy of histKeys) {
|
|
231
|
+
const entries = readJSON(
|
|
232
|
+
window.localStorage.getItem(legacy),
|
|
233
|
+
isCalcHistory,
|
|
234
|
+
);
|
|
235
|
+
if (entries) {
|
|
236
|
+
migrateEntries(entries);
|
|
237
|
+
lists.push(entries);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
writeHistoryRaw(key, mergeEntries(lists));
|
|
241
|
+
}
|
|
242
|
+
for (const legacy of [...tabKeys, ...histKeys]) {
|
|
243
|
+
window.localStorage.removeItem(legacy);
|
|
244
|
+
}
|
|
245
|
+
emitCalcStorage();
|
|
246
|
+
} catch {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
189
251
|
export function subscribeCalcStorage(listener: () => void): () => void {
|
|
190
252
|
if (typeof window === 'undefined') return () => {};
|
|
191
253
|
window.addEventListener(CALC_STATE_EVENT, listener);
|
|
@@ -80,6 +80,7 @@ export function toCalcRecipe(recipe: Recipe): CalcRecipe {
|
|
|
80
80
|
kind: slotKind(slot),
|
|
81
81
|
amount: slot.count && slot.count > 0 ? slot.count : 1,
|
|
82
82
|
...(slot.chance !== undefined ? { chance: slot.chance } : {}),
|
|
83
|
+
...(slot.kind === 'tag' ? { tagId: slot.id } : {}),
|
|
83
84
|
}));
|
|
84
85
|
const tier = recipeTier(recipe);
|
|
85
86
|
return {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CalcMaterial,
|
|
3
|
+
CalcNode,
|
|
4
|
+
CalcNodeInput,
|
|
5
|
+
CalcWire,
|
|
6
|
+
} from '@terrafirmagreg-team/recipe/types/calc';
|
|
7
|
+
|
|
8
|
+
export function wireEndMatches(
|
|
9
|
+
input: CalcNodeInput,
|
|
10
|
+
out: CalcMaterial,
|
|
11
|
+
): boolean {
|
|
12
|
+
if (input.kind !== out.kind || !out.id) return false;
|
|
13
|
+
if (input.id === out.id) return true;
|
|
14
|
+
return !!input.tagId && !!input.members?.includes(out.id);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function resolveWireEnds(
|
|
18
|
+
src: CalcNode,
|
|
19
|
+
dst: CalcNode,
|
|
20
|
+
wire: CalcWire,
|
|
21
|
+
): { inputIndex: number; outIndex: number } | null {
|
|
22
|
+
const hinted = dst.inputs[wire.input];
|
|
23
|
+
if (hinted?.id) {
|
|
24
|
+
const outIndex = src.outputs.findIndex((out) =>
|
|
25
|
+
wireEndMatches(hinted, out),
|
|
26
|
+
);
|
|
27
|
+
if (outIndex >= 0) return { inputIndex: wire.input, outIndex };
|
|
28
|
+
}
|
|
29
|
+
for (let i = 0; i < dst.inputs.length; i += 1) {
|
|
30
|
+
if (i === wire.input) continue;
|
|
31
|
+
const input = dst.inputs[i];
|
|
32
|
+
if (!input?.id) continue;
|
|
33
|
+
const outIndex = src.outputs.findIndex((out) =>
|
|
34
|
+
wireEndMatches(input, out),
|
|
35
|
+
);
|
|
36
|
+
if (outIndex >= 0) return { inputIndex: i, outIndex };
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
@@ -32,6 +32,13 @@ export async function runResolve(input: ResolveInput) {
|
|
|
32
32
|
for (const id of input.tags ?? []) {
|
|
33
33
|
if (id && !state.tagMap.has(id)) wantedTag.add(id);
|
|
34
34
|
}
|
|
35
|
+
for (const recipe of state.recipeMap.values()) {
|
|
36
|
+
for (const slot of recipe.inputs) {
|
|
37
|
+
if (slot.tagId && !state.tagMap.has(slot.tagId)) {
|
|
38
|
+
wantedTag.add(slot.tagId);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
35
42
|
wantedRecipes.forEach((id) => {
|
|
36
43
|
if (state.recipeMap.has(id) || state.deadIds.has(id)) {
|
|
37
44
|
wantedRecipes.delete(id);
|
|
@@ -112,49 +112,30 @@ async function clientRecipeGroups(
|
|
|
112
112
|
|
|
113
113
|
const loadChrome = createDatasetCache(
|
|
114
114
|
async (dataset: DatasetRef, lang: string): Promise<RecipeChrome> => {
|
|
115
|
-
const [items, fluids, creative, categories, usedIds
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
loadClientTagMembers(dataset, 'item'),
|
|
123
|
-
loadClientTagMembers(dataset, 'block'),
|
|
124
|
-
]);
|
|
115
|
+
const [items, fluids, creative, categories, usedIds] = await Promise.all([
|
|
116
|
+
loadClientRegistryOrder(dataset, 'item'),
|
|
117
|
+
loadClientRegistryOrder(dataset, 'fluid'),
|
|
118
|
+
loadClientTabs(dataset),
|
|
119
|
+
loadDatasetRecipeCategories(dataset),
|
|
120
|
+
clientUsedIds(dataset),
|
|
121
|
+
]);
|
|
125
122
|
const tabs = creative.tabs;
|
|
126
123
|
const tabItems = Object.keys(creative.members).length
|
|
127
124
|
? creative.members
|
|
128
125
|
: undefined;
|
|
129
126
|
const types = categories.map((row) => row.id);
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
const [groups, mods, categoryNames, tabNames] = await Promise.all([
|
|
128
|
+
clientRecipeGroups(dataset, lang),
|
|
129
|
+
loadClientModNames(dataset, lang),
|
|
130
|
+
clientNamedCategories(dataset, lang, types, categories),
|
|
131
|
+
clientDumpLang(dataset, lang).then((map) => {
|
|
132
|
+
const names: Record<string, string> = {};
|
|
133
|
+
for (const tab of tabs) {
|
|
134
|
+
names[tab.id] = creativeTabName(map, tab.display.name ?? tab.id);
|
|
135
|
+
}
|
|
136
|
+
return names;
|
|
137
|
+
}),
|
|
133
138
|
]);
|
|
134
|
-
const nameIds = [
|
|
135
|
-
...items,
|
|
136
|
-
...fluids,
|
|
137
|
-
...tagIds,
|
|
138
|
-
...(usedIds ?? []),
|
|
139
|
-
...Object.values(tabItems ?? {}).flat(),
|
|
140
|
-
...tabs.flatMap((tab) =>
|
|
141
|
-
tab.icon ? [stackIdFromRef(tab.icon)] : [],
|
|
142
|
-
),
|
|
143
|
-
];
|
|
144
|
-
const [groups, mods, entityNames, categoryNames, tabNames] =
|
|
145
|
-
await Promise.all([
|
|
146
|
-
clientRecipeGroups(dataset, lang),
|
|
147
|
-
loadClientModNames(dataset, lang),
|
|
148
|
-
clientEntityNames(dataset, lang, nameIds),
|
|
149
|
-
clientNamedCategories(dataset, lang, types, categories),
|
|
150
|
-
clientDumpLang(dataset, lang).then((map) => {
|
|
151
|
-
const names: Record<string, string> = {};
|
|
152
|
-
for (const tab of tabs) {
|
|
153
|
-
names[tab.id] = creativeTabName(map, tab.display.name ?? tab.id);
|
|
154
|
-
}
|
|
155
|
-
return names;
|
|
156
|
-
}),
|
|
157
|
-
]);
|
|
158
139
|
return {
|
|
159
140
|
items,
|
|
160
141
|
...(usedIds.length ? { usedIds } : {}),
|
|
@@ -165,12 +146,41 @@ const loadChrome = createDatasetCache(
|
|
|
165
146
|
...(groups.length ? { groups } : {}),
|
|
166
147
|
mods,
|
|
167
148
|
names: {
|
|
168
|
-
[lang]: { ...tabNames, ...categoryNames
|
|
149
|
+
[lang]: { ...tabNames, ...categoryNames },
|
|
169
150
|
},
|
|
170
151
|
};
|
|
171
152
|
},
|
|
172
153
|
);
|
|
173
154
|
|
|
155
|
+
const loadEntityNames = createDatasetCache(
|
|
156
|
+
async (
|
|
157
|
+
dataset: DatasetRef,
|
|
158
|
+
chrome: RecipeChrome,
|
|
159
|
+
lang: string,
|
|
160
|
+
): Promise<Record<string, string>> => {
|
|
161
|
+
const [itemTags, blockTags] = await Promise.all([
|
|
162
|
+
loadClientTagMembers(dataset, 'item'),
|
|
163
|
+
loadClientTagMembers(dataset, 'block'),
|
|
164
|
+
]);
|
|
165
|
+
const tagIds = new Set([
|
|
166
|
+
...Object.keys(itemTags ?? {}),
|
|
167
|
+
...Object.keys(blockTags ?? {}),
|
|
168
|
+
]);
|
|
169
|
+
const nameIds = [
|
|
170
|
+
...chrome.items,
|
|
171
|
+
...(chrome.fluids ?? []),
|
|
172
|
+
...tagIds,
|
|
173
|
+
...(chrome.usedIds ?? []),
|
|
174
|
+
...Object.values(chrome.tabItems ?? {}).flat(),
|
|
175
|
+
...(chrome.tabs ?? []).flatMap((tab) =>
|
|
176
|
+
tab.icon ? [stackIdFromRef(tab.icon)] : [],
|
|
177
|
+
),
|
|
178
|
+
];
|
|
179
|
+
return clientEntityNames(dataset, lang, nameIds);
|
|
180
|
+
},
|
|
181
|
+
(dataset, _chrome, lang) => `${dataset.id}/${dataset.version ?? ''} ${lang}`,
|
|
182
|
+
);
|
|
183
|
+
|
|
174
184
|
export function loadRecipeChromeClient(
|
|
175
185
|
dataset: DatasetRef,
|
|
176
186
|
lang: string,
|
|
@@ -178,3 +188,11 @@ export function loadRecipeChromeClient(
|
|
|
178
188
|
return loadChrome(dataset, lang);
|
|
179
189
|
}
|
|
180
190
|
|
|
191
|
+
export function loadRecipeEntityNames(
|
|
192
|
+
dataset: DatasetRef,
|
|
193
|
+
chrome: RecipeChrome,
|
|
194
|
+
lang: string,
|
|
195
|
+
): Promise<Record<string, string>> {
|
|
196
|
+
return loadEntityNames(dataset, chrome, lang);
|
|
197
|
+
}
|
|
198
|
+
|
package/src/lib/links.ts
CHANGED
|
@@ -92,7 +92,7 @@ export function recipeStackHref(
|
|
|
92
92
|
dataset: DatasetRef,
|
|
93
93
|
lang: Lang,
|
|
94
94
|
id: string,
|
|
95
|
-
opts?: Pick<RecipeHrefOpts, 'tab' | 'search'> & {
|
|
95
|
+
opts?: Pick<RecipeHrefOpts, 'tab' | 'search' | 'relation'> & {
|
|
96
96
|
kind?: 'item' | 'fluid' | 'tag';
|
|
97
97
|
tagKind?: string;
|
|
98
98
|
},
|
|
@@ -100,6 +100,7 @@ export function recipeStackHref(
|
|
|
100
100
|
const kept = {
|
|
101
101
|
tab: opts?.tab,
|
|
102
102
|
search: opts?.search,
|
|
103
|
+
relation: opts?.relation,
|
|
103
104
|
};
|
|
104
105
|
if (opts?.kind === 'tag' || id.startsWith('#')) {
|
|
105
106
|
const bare = id.startsWith('#') ? id.slice(1) : id;
|
package/src/types/calc.ts
CHANGED
|
@@ -10,11 +10,11 @@ export type CalcMaterial = {
|
|
|
10
10
|
amount: number;
|
|
11
11
|
|
|
12
12
|
chance?: number;
|
|
13
|
+
tagId?: string;
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
export type CalcRecipeInput = CalcMaterial & {
|
|
16
17
|
catalyst: boolean;
|
|
17
|
-
tagId?: string;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export type CalcRecipe = {
|
|
@@ -62,6 +62,7 @@ export type CalcNodeInput = {
|
|
|
62
62
|
amount: number;
|
|
63
63
|
catalyst: boolean;
|
|
64
64
|
tagId?: string;
|
|
65
|
+
members?: string[];
|
|
65
66
|
wired: boolean;
|
|
66
67
|
covered: number;
|
|
67
68
|
};
|
package/styles/calc.css
CHANGED
|
@@ -197,6 +197,10 @@
|
|
|
197
197
|
transition: transform 240ms ease;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
.calc-flow:has(.react-flow__node.dragging) .react-flow__node {
|
|
201
|
+
transition: none;
|
|
202
|
+
}
|
|
203
|
+
|
|
200
204
|
.calc-flow .react-flow__node-calcMaterial[style*='--calc-delay'] {
|
|
201
205
|
animation: calc-node-in 200ms ease-out both;
|
|
202
206
|
animation-delay: var(--calc-delay, 0ms);
|