Merge branch 'master' into react-to-drag-and-drop

This commit is contained in:
Danielv123 committed 2024-05-04 20:49:29 +02:00
commit b6113a1007
23 files changed
+252 -48

No files matched your search

+2 -2
View File
@@ -3,7 +3,7 @@
"description": "Clusterio web interface implementation",
"author": "Hornwitser",
"license": "MIT",
"version": "2.0.0-alpha.17",
"version": "2.0.0-alpha.18",
"browser": "src/index.ts",
"main": "dist/browser/src/index.js",
"scripts": {
@@ -17,7 +17,7 @@
},
"dependencies": {
"@ant-design/icons": "^5.1.4",
"@clusterio/lib": "^2.0.0-alpha.17",
"@clusterio/lib": "^2.0.0-alpha.18",
"@swc/core": "^1.4.0",
"antd": "^5.13.0",
"assert": "^2.0.0",
@@ -424,7 +424,15 @@ function InputColor(props: {
value: lib.ModSettingColor,
onChange: (value: lib.ModSettingColor) => void,
}) {
const value = props.value;
// In certain edge cases it's possible a value for this mod setting does not exist
// or is of the wrong type. Fallback to black if this is the case.
function isColor(input: unknown) {
if (typeof input !== "object" || input === null) {
return false;
}
return "r" in input && "g" in input && "b" in input && "a" in input;
}
const value = isColor(props.value) ? props.value : { r: 0, g: 0, b: 0, a: 1 };
return <ColorPicker
defaultFormat="rgb"
defaultValue={`rgba(${value.r * 255}, ${value.g * 255}, ${value.b * 255}, ${value.a}`}
@@ -774,7 +782,7 @@ export default function ModPackViewPage() {
continue;
}
}
if (modifiedModPack!.settings[scope].get(settingName)!.value !== value) {
if (modifiedModPack!.settings[scope].get(settingName)?.value !== value) {
pushChange({ type: "settings.set", scope, name: settingName, value: { value }});
}
}