@terrafirmagreg-team/recipe 1.2.40 → 1.2.42
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 +2 -2
- package/src/components/cards/calc-add-item.tsx +55 -0
- package/src/components/cards/card/index.tsx +2 -0
- package/src/components/cards/card/text.tsx +20 -4
- package/src/components/views/browser/card-grid.tsx +11 -23
- package/src/components/views/browser/frame.tsx +7 -10
- package/src/components/views/browser/item-view/index.tsx +8 -10
- package/src/components/views/browser/settings.tsx +6 -0
- package/src/components/views/browser/toolbar.tsx +7 -7
- package/src/components/views/browser/type-view.tsx +10 -10
- package/src/components/views/calc/calculator/index.tsx +4 -0
- package/src/components/views/calc/flow/index.tsx +42 -1
- package/src/components/views/calc/flow/picker-dialogs.tsx +15 -8
- package/src/components/views/calc/flow/toolbar.tsx +2 -0
- package/src/components/views/calc/flow/view-menu.tsx +13 -0
- package/src/components/views/calc/member-picker.tsx +7 -2
- package/src/components/views/calc/node-card/full.tsx +34 -5
- package/src/components/views/calc/node-card/menu.tsx +32 -0
- package/src/components/views/calc/recipe-picker/body.tsx +9 -9
- package/src/hooks/calc/flow/use-layout.ts +1 -1
- package/src/hooks/calc/flow/use-pickers.ts +14 -10
- package/src/hooks/calc/use-actions.ts +54 -31
- package/src/hooks/calc/use-recipe-ids.ts +33 -0
- package/src/hooks/use-card-grid.ts +14 -0
- package/src/lib/alloy/parse.ts +6 -3
- package/src/lib/browser/card-dim.test.ts +39 -0
- package/src/lib/browser/card-dim.ts +38 -0
- package/src/lib/browser/lookup.ts +3 -2
- package/src/lib/browser/row-match.test.ts +34 -0
- package/src/lib/browser/row-match.ts +8 -0
- package/src/lib/calc/flow.ts +3 -1
- package/src/lib/calc/member.test.ts +178 -0
- package/src/lib/calc/member.ts +90 -0
- package/src/lib/calc/scheme.test.ts +213 -0
- package/src/lib/calc/scheme.ts +8 -3
- package/src/lib/calc/tree/index.ts +5 -1
- package/src/lib/calc/tree/recipe.test.ts +88 -0
- package/src/lib/calc/tree/recipe.ts +19 -3
- package/src/lib/calc/wire.test.ts +70 -0
- package/src/lib/calc/wire.ts +6 -2
- package/src/lib/cards/model.test.ts +61 -1
- package/src/lib/cards/model.ts +9 -2
- package/src/types/calc-flow-props.ts +2 -0
- package/styles/calc.css +4 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Recipe, RecipeIngredient } from '@terrafirmagreg-team/recipe/lib/data/dto';
|
|
2
|
+
import { stackIdBase } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
|
|
2
3
|
import type {
|
|
3
4
|
CalcKind,
|
|
4
5
|
CalcMaterial,
|
|
@@ -46,7 +47,7 @@ function recipeTier(recipe: Recipe): number | undefined {
|
|
|
46
47
|
|
|
47
48
|
export function toCalcRecipe(recipe: Recipe): CalcRecipe {
|
|
48
49
|
const inputs: CalcRecipeInput[] = recipe.inputs.map((slot) => ({
|
|
49
|
-
id: slot.id,
|
|
50
|
+
id: slot.kind === 'tag' ? slot.id : stackIdBase(slot.id),
|
|
50
51
|
kind: slotKind(slot),
|
|
51
52
|
amount: slot.count && slot.count > 0 ? slot.count : 1,
|
|
52
53
|
catalyst: false,
|
|
@@ -56,7 +57,7 @@ export function toCalcRecipe(recipe: Recipe): CalcRecipe {
|
|
|
56
57
|
for (const widget of recipe.widgets) {
|
|
57
58
|
if (widget.type !== 'slot' || widget.role !== 'catalyst') continue;
|
|
58
59
|
inputs.push({
|
|
59
|
-
id: widget.id,
|
|
60
|
+
id: widget.kind === 'tag' ? widget.id : stackIdBase(widget.id),
|
|
60
61
|
kind: widget.kind === 'fluid' ? 'fluid' : 'item',
|
|
61
62
|
amount: 1,
|
|
62
63
|
catalyst: true,
|
|
@@ -76,7 +77,7 @@ export function toCalcRecipe(recipe: Recipe): CalcRecipe {
|
|
|
76
77
|
else merged.push({ ...input });
|
|
77
78
|
}
|
|
78
79
|
const outputs: CalcMaterial[] = recipe.outputs.map((slot) => ({
|
|
79
|
-
id: slot.id,
|
|
80
|
+
id: slot.kind === 'tag' ? slot.id : stackIdBase(slot.id),
|
|
80
81
|
kind: slotKind(slot),
|
|
81
82
|
amount: slot.count && slot.count > 0 ? slot.count : 1,
|
|
82
83
|
...(slot.chance !== undefined ? { chance: slot.chance } : {}),
|
|
@@ -103,3 +104,18 @@ export function recipeDivisor(
|
|
|
103
104
|
return amount > 0 ? amount : 1;
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
export async function resolveRecipeAmount(
|
|
108
|
+
recipeId: string,
|
|
109
|
+
materialId: string,
|
|
110
|
+
kind: CalcKind,
|
|
111
|
+
load: (id: string) => Promise<Recipe | undefined>,
|
|
112
|
+
fallback = 1,
|
|
113
|
+
): Promise<number> {
|
|
114
|
+
const body = await load(recipeId);
|
|
115
|
+
if (!body) return fallback;
|
|
116
|
+
const amount = toCalcRecipe(body)
|
|
117
|
+
.outputs.filter((out) => out.id === materialId && out.kind === kind)
|
|
118
|
+
.reduce((sum, out) => sum + out.amount * (out.chance ?? 1), 0);
|
|
119
|
+
return amount > 0 ? amount : fallback;
|
|
120
|
+
}
|
|
121
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import { wireEndMatches } from './wire';
|
|
4
|
+
import type { CalcNodeInput } from '@terrafirmagreg-team/recipe/types/calc';
|
|
5
|
+
|
|
6
|
+
const NBT = '{"Damage":0,"GT.Tool":{}}';
|
|
7
|
+
|
|
8
|
+
test('NBT input id matches a base output id', () => {
|
|
9
|
+
const input = {
|
|
10
|
+
id: `gtceu:duranium_hammer${NBT}`,
|
|
11
|
+
kind: 'item',
|
|
12
|
+
amount: 1,
|
|
13
|
+
catalyst: false,
|
|
14
|
+
} as CalcNodeInput;
|
|
15
|
+
assert.equal(
|
|
16
|
+
wireEndMatches(input, {
|
|
17
|
+
id: 'gtceu:duranium_hammer',
|
|
18
|
+
kind: 'item',
|
|
19
|
+
amount: 1,
|
|
20
|
+
}),
|
|
21
|
+
true,
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('tag members carrying NBT match a base output id', () => {
|
|
26
|
+
const input = {
|
|
27
|
+
id: 'gtceu:copper_hammer',
|
|
28
|
+
kind: 'item',
|
|
29
|
+
amount: 1,
|
|
30
|
+
catalyst: false,
|
|
31
|
+
tagId: '#forge:tools/hammers',
|
|
32
|
+
members: [
|
|
33
|
+
`gtceu:copper_hammer${NBT}`,
|
|
34
|
+
`gtceu:duranium_hammer${NBT}`,
|
|
35
|
+
],
|
|
36
|
+
} as CalcNodeInput;
|
|
37
|
+
assert.equal(
|
|
38
|
+
wireEndMatches(input, {
|
|
39
|
+
id: 'gtceu:duranium_hammer',
|
|
40
|
+
kind: 'item',
|
|
41
|
+
amount: 1,
|
|
42
|
+
}),
|
|
43
|
+
true,
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('kind mismatch and unrelated ids still fail', () => {
|
|
48
|
+
const input = {
|
|
49
|
+
id: 'gtceu:duranium_hammer',
|
|
50
|
+
kind: 'item',
|
|
51
|
+
amount: 1,
|
|
52
|
+
catalyst: false,
|
|
53
|
+
} as CalcNodeInput;
|
|
54
|
+
assert.equal(
|
|
55
|
+
wireEndMatches(input, {
|
|
56
|
+
id: 'gtceu:duranium_hammer',
|
|
57
|
+
kind: 'fluid',
|
|
58
|
+
amount: 1,
|
|
59
|
+
}),
|
|
60
|
+
false,
|
|
61
|
+
);
|
|
62
|
+
assert.equal(
|
|
63
|
+
wireEndMatches(input, {
|
|
64
|
+
id: 'gtceu:copper_hammer',
|
|
65
|
+
kind: 'item',
|
|
66
|
+
amount: 1,
|
|
67
|
+
}),
|
|
68
|
+
false,
|
|
69
|
+
);
|
|
70
|
+
});
|
package/src/lib/calc/wire.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stackIdBase } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
|
|
1
2
|
import type {
|
|
2
3
|
CalcMaterial,
|
|
3
4
|
CalcNode,
|
|
@@ -10,8 +11,11 @@ export function wireEndMatches(
|
|
|
10
11
|
out: CalcMaterial,
|
|
11
12
|
): boolean {
|
|
12
13
|
if (input.kind !== out.kind || !out.id) return false;
|
|
13
|
-
if (input.id === out.id) return true;
|
|
14
|
-
return
|
|
14
|
+
if (input.id && stackIdBase(input.id) === stackIdBase(out.id)) return true;
|
|
15
|
+
return (
|
|
16
|
+
!!input.tagId &&
|
|
17
|
+
!!input.members?.some((m) => stackIdBase(m) === stackIdBase(out.id))
|
|
18
|
+
);
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
export function resolveWireEnds(
|
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import { test } from 'node:test';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
countCoveredText,
|
|
5
|
+
slotCoveredLabel,
|
|
6
|
+
widgetTextColor,
|
|
7
|
+
} from '@terrafirmagreg-team/recipe/lib/cards/model';
|
|
8
|
+
import type {
|
|
9
|
+
RecipeSlotWidget,
|
|
10
|
+
RecipeTextWidget,
|
|
11
|
+
} from '@terrafirmagreg-team/recipe/lib/data/dto';
|
|
12
|
+
|
|
13
|
+
const slot = (over: Partial<RecipeSlotWidget>): RecipeSlotWidget => ({
|
|
14
|
+
type: 'slot',
|
|
15
|
+
x: 49,
|
|
16
|
+
y: 133,
|
|
17
|
+
w: 16,
|
|
18
|
+
h: 16,
|
|
19
|
+
role: 'renderOnly',
|
|
20
|
+
kind: 'item',
|
|
21
|
+
id: 'gtceu:bronze_block',
|
|
22
|
+
...over,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const textWidget = (over: Partial<RecipeTextWidget>): RecipeTextWidget => ({
|
|
26
|
+
type: 'text',
|
|
27
|
+
x: 54,
|
|
28
|
+
y: 142,
|
|
29
|
+
w: 12,
|
|
30
|
+
h: 9,
|
|
31
|
+
text: '',
|
|
32
|
+
...over,
|
|
33
|
+
});
|
|
4
34
|
|
|
5
35
|
test('widgetTextColor defaults uncolored shadowed text to white', () => {
|
|
6
36
|
assert.equal(widgetTextColor(undefined, true), 0xffffff);
|
|
@@ -19,3 +49,33 @@ test('widgetTextColor keeps explicit colors', () => {
|
|
|
19
49
|
test('widgetTextColor masks color to 24 bits', () => {
|
|
20
50
|
assert.equal(widgetTextColor(0x1ff0000, true), 0xff0000);
|
|
21
51
|
});
|
|
52
|
+
|
|
53
|
+
test('countCoveredText suppresses a count text overlapping its slot', () => {
|
|
54
|
+
const slots = [slot({ count: 24 })];
|
|
55
|
+
assert.equal(countCoveredText(textWidget({ text: '24' }), slots), true);
|
|
56
|
+
assert.equal(countCoveredText(textWidget({ text: 'x2' }), slots), false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('countCoveredText suppresses a component-carried count', () => {
|
|
60
|
+
const slots = [slot({ count: 24 })];
|
|
61
|
+
const widget = textWidget({ component: { text: '24' } });
|
|
62
|
+
assert.equal(countCoveredText(widget, slots), true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('countCoveredText ignores component text that is not a count', () => {
|
|
66
|
+
const slots = [slot({ count: 24 })];
|
|
67
|
+
const widget = textWidget({ component: { text: 'Bronze Tank' } });
|
|
68
|
+
assert.equal(countCoveredText(widget, slots), false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('countCoveredText requires overlap with the counted slot', () => {
|
|
72
|
+
const slots = [slot({ count: 24 })];
|
|
73
|
+
const widget = textWidget({ x: 200, component: { text: '24' } });
|
|
74
|
+
assert.equal(countCoveredText(widget, slots), false);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('slotCoveredLabel anchors a component-carried NC label', () => {
|
|
78
|
+
const target = slot({});
|
|
79
|
+
const widget = textWidget({ x: 50, component: { text: 'NC' } });
|
|
80
|
+
assert.equal(slotCoveredLabel(widget, [target]), target);
|
|
81
|
+
});
|
package/src/lib/cards/model.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dumpTextString } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
|
|
1
2
|
import type {
|
|
2
3
|
RecipeSlotWidget,
|
|
3
4
|
RecipeTextWidget,
|
|
@@ -47,6 +48,12 @@ export function cardStripGeo(
|
|
|
47
48
|
|
|
48
49
|
const COUNT_TEXT = /^x?(\d[\d\s.,]*)?\s*(mB|k|B|L|M)?$/i;
|
|
49
50
|
|
|
51
|
+
export function widgetText(widget: RecipeTextWidget): string {
|
|
52
|
+
return widget.component
|
|
53
|
+
? dumpTextString({}, widget.component) || widget.text
|
|
54
|
+
: widget.text;
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
export function slotOverlay(
|
|
51
58
|
widget: RecipeTextWidget,
|
|
52
59
|
slots: RecipeSlotWidget[],
|
|
@@ -60,7 +67,7 @@ export function countCoveredText(
|
|
|
60
67
|
widget: RecipeTextWidget,
|
|
61
68
|
slots: RecipeSlotWidget[],
|
|
62
69
|
): boolean {
|
|
63
|
-
const match = widget
|
|
70
|
+
const match = widgetText(widget)
|
|
64
71
|
.replace(/§./g, '')
|
|
65
72
|
.trim()
|
|
66
73
|
.match(COUNT_TEXT);
|
|
@@ -105,7 +112,7 @@ export function slotCoveredLabel(
|
|
|
105
112
|
widget: RecipeTextWidget,
|
|
106
113
|
slots: RecipeSlotWidget[],
|
|
107
114
|
): RecipeSlotWidget | undefined {
|
|
108
|
-
if (widget.
|
|
115
|
+
if (widgetText(widget).replace(/§./g, '').trim() !== 'NC') return undefined;
|
|
109
116
|
return slotOverlay(widget, slots);
|
|
110
117
|
}
|
|
111
118
|
|
|
@@ -32,6 +32,8 @@ export type CalcFlowProps = {
|
|
|
32
32
|
onModeChange: (mode: CalcViewMode) => void;
|
|
33
33
|
farCards: CalcFarMode;
|
|
34
34
|
onFarCardsChange: (mode: CalcFarMode) => void;
|
|
35
|
+
recipeIds: boolean;
|
|
36
|
+
onRecipeIdsChange: (show: boolean) => void;
|
|
35
37
|
treeReady?: boolean;
|
|
36
38
|
resetGen?: number;
|
|
37
39
|
canvasId?: string;
|