Skip to content

Commit b54715f

Browse files
authored
Refactor/crafting system manager app (#75)
1 parent 2b27db5 commit b54715f

File tree

15 files changed

+1003
-362
lines changed

15 files changed

+1003
-362
lines changed

src/lang/en.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,36 @@
124124
"content": "Delete {systemName}? This action cannot be undone.",
125125
"title": "Fabricate | Delete crafting system"
126126
},
127+
"noSystemSelected": "No crafting system selected. Create a new system or select one from the left menu.",
127128
"readErrorPrompt": {
128129
"title": "Error Reading Crafting Systems",
129130
"content": "{errorMessage}. \n You can reset Fabricate to resolve the error, but this will delete all except the bundled crafting systems!"
130131
},
132+
"prompts": {
133+
"itemReadError":{
134+
"title": "Remove {type} {itemId}?",
135+
"content": "The {type} with UUID {itemId} was referenced by a Fabricate Item, but does not exist. Deleting references to it will allow Fabricate to load. Proceed?"
136+
},
137+
"removeComponent": {
138+
"title": "Remove {name}?",
139+
"content": "The component will be removed from the Crafting System, as well as any Recipes and Components that reference it. This action cannot be undone. Are you sure?"
140+
},
141+
"removeEssence": {
142+
"title": "Remove {name}?",
143+
"content": "The essence will be removed from the Crafting System, as well as any Recipes and Components that reference it. This action cannot be undone. Are you sure?"
144+
},
145+
"removeRecipe": {
146+
"title": "Remove {name}?",
147+
"content": "The recipe will be removed from the Crafting System. This action cannot be undone. Are you sure?"
148+
}
149+
},
131150
"tabs": {
132151
"recipes": {
152+
"title": "Recipes",
133153
"optionTooltip": "{size} Components"
134154
},
135155
"essences": {
156+
"title": "Essences",
136157
"description": "Essences are a quality of a component. They define something that the component has, not something that it is. Components might have multiple Essences in different quantities, all of which you can define for your system. Not every crafting system needs essences. However, if you do want to add them to components, you'll need to define them here first.",
137158
"create": "Add a new Essence",
138159
"tableHeadings": {
@@ -144,6 +165,15 @@
144165
"edit": "Edit essence",
145166
"delete": "Delete essence"
146167
}
168+
},
169+
"alchemy": {
170+
"title": "Alchemy"
171+
},
172+
"checks": {
173+
"title": "Checks"
174+
},
175+
"components": {
176+
"title": "Components"
147177
}
148178
}
149179
},

src/scripts/common/Combination.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ class Combination<T extends Identifiable> {
335335
return this;
336336
}
337337

338+
without(part: T) {
339+
const combination: Map<string, Unit<T>> = new Map(this._amounts);
340+
combination.delete(part.id);
341+
return new Combination<T>(combination);
342+
}
343+
338344
public multiply(factor: number) {
339345
const modifiedAmounts: Map<string, Unit<T>> = new Map(this._amounts);
340346
this.members.forEach((member: T) => {

src/scripts/foundry/DocumentManager.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,38 @@ interface DocumentManager {
1313

1414
}
1515

16+
class ItemNotFoundError extends Error {
17+
18+
private static readonly formatErrorMessage = (id: string) => `Item with id ${id} was not found. `;
19+
private readonly _itemUuid: string;
20+
21+
constructor(itemUuid: string) {
22+
super(ItemNotFoundError.formatErrorMessage(itemUuid));
23+
this._itemUuid = itemUuid;
24+
}
25+
26+
get itemUuid(): string {
27+
return this._itemUuid;
28+
}
29+
30+
}
31+
1632
class DefaultDocumentManager implements DocumentManager {
1733

1834
public async getDocumentByUuid(id: string): Promise<FabricateItemData> {
1935
const document = await fromUuid(id);
20-
return this.formatItemData(document);
36+
if (document) {
37+
return this.formatItemData(document);
38+
}
39+
throw new ItemNotFoundError(id);
2140
}
2241

2342
public async getDocumentsByUuid(ids: string[]): Promise<Map<string, FabricateItemData>> {
24-
const itemData = await Promise.all(ids.map(id => this.getDocumentByUuid(id)));
43+
const itemData = await Promise.all(ids.map(id => this.getDocumentByUuid(id).catch(e => e)));
44+
const firstErrorResult = itemData.find(result => result instanceof Error);
45+
if (firstErrorResult) {
46+
throw firstErrorResult;
47+
}
2548
return new Map(itemData.map(item => [item.uuid,item]));
2649
}
2750

@@ -36,4 +59,4 @@ class DefaultDocumentManager implements DocumentManager {
3659

3760
}
3861

39-
export { FabricateItemData, DocumentManager, DefaultDocumentManager }
62+
export { FabricateItemData, DocumentManager, DefaultDocumentManager, ItemNotFoundError }

0 commit comments

Comments
 (0)