Skip to content

Commit 3fd5fd9

Browse files
committed
Add warning message if MATI is not a path to material overrides script
1 parent 2df53a2 commit 3fd5fd9

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/pages/material-overrides.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,33 @@ export default function MaterialOverrides() {
1414
return;
1515
}
1616

17+
let pathWarning = false;
18+
1719
const text = await file.text();
1820
try {
1921
const jsonData = JSON.parse(text);
20-
22+
2123
if (jsonData.MATI.startsWith("[") && jsonData.MATI.endsWith(".pc_mi")) {
2224
jsonData.MATT = jsonData.MATI.replace(".pc_mi", ".pc_entitytype");
2325
jsonData.MATB = jsonData.MATI.replace(".pc_mi", ".pc_entityblueprint");
26+
} else {
27+
pathWarning = true;
2428
}
25-
29+
2630
const modified = appendOverrides(jsonData);
2731
const materialName = jsonData.Material.Instance[0].Name.replace("mi", "material");
28-
const blob = new Blob([JSON.stringify(modified, null, 2)], { type: "application/json" });
32+
const blob = new Blob([JSON.stringify(modified, null, 2)], { type: "application/json" });
2933

3034
const a = document.createElement("a");
3135
a.href = URL.createObjectURL(blob);
3236
a.download = `${materialName}.json`;
3337
a.click();
3438

35-
setMessage(`Generated ${materialName}.json`);
39+
let message = `Generated ${materialName}.json`;
40+
if (pathWarning) {
41+
message += "\nMATT and MATB could not be set due to MATI not being a path. Please set these manually.";
42+
}
43+
setMessage(message);
3644
} catch (err) {
3745
setMessage("Failed to process file: " + err.message);
3846
console.error(err);
@@ -64,7 +72,13 @@ export default function MaterialOverrides() {
6472
>
6573
<h2>Drop your material.json file here</h2>
6674
<p>and overrides will be automatically added into it.</p>
67-
{message && <p><strong>{message}</strong></p>}
75+
{message && (
76+
<div>
77+
{message.split("\n").map((line, index) => (
78+
<p key={index}><strong>{line}</strong></p>
79+
))}
80+
</div>
81+
)}
6882
</div>
6983
<p style={{ textAlign: "center", marginTop: "2rem" }}>
7084
Adapted from code originally created by{" "}

0 commit comments

Comments
 (0)