2020-04-26 20:48:01 +10:00
|
|
|
import React from "react";
|
2020-06-30 21:23:45 +10:00
|
|
|
import {
|
|
|
|
|
Flex,
|
|
|
|
|
Box,
|
|
|
|
|
Label,
|
|
|
|
|
Input,
|
|
|
|
|
Checkbox,
|
|
|
|
|
IconButton,
|
|
|
|
|
Select,
|
|
|
|
|
} from "theme-ui";
|
2020-04-26 17:25:04 +10:00
|
|
|
|
|
|
|
|
import ExpandMoreIcon from "../../icons/ExpandMoreIcon";
|
2020-04-26 12:57:36 +10:00
|
|
|
|
2020-06-28 14:00:36 +10:00
|
|
|
import { isEmpty } from "../../helpers/shared";
|
|
|
|
|
|
2020-05-31 16:25:05 +10:00
|
|
|
import Divider from "../Divider";
|
|
|
|
|
|
2020-07-15 17:17:11 +10:00
|
|
|
const qualitySettings = [
|
|
|
|
|
{ id: "low", name: "Low" },
|
|
|
|
|
{ id: "medium", name: "Medium" },
|
|
|
|
|
{ id: "high", name: "High" },
|
|
|
|
|
{ id: "ultra", name: "Ultra High" },
|
|
|
|
|
{ id: "original", name: "Original" },
|
|
|
|
|
];
|
|
|
|
|
|
2020-04-26 13:47:54 +10:00
|
|
|
function MapSettings({
|
|
|
|
|
map,
|
|
|
|
|
mapState,
|
|
|
|
|
onSettingsChange,
|
|
|
|
|
onStateSettingsChange,
|
2020-04-26 17:25:04 +10:00
|
|
|
showMore,
|
|
|
|
|
onShowMoreChange,
|
2020-04-26 13:47:54 +10:00
|
|
|
}) {
|
|
|
|
|
function handleFlagChange(event, flag) {
|
|
|
|
|
if (event.target.checked) {
|
|
|
|
|
onStateSettingsChange("editFlags", [...mapState.editFlags, flag]);
|
|
|
|
|
} else {
|
|
|
|
|
onStateSettingsChange(
|
|
|
|
|
"editFlags",
|
|
|
|
|
mapState.editFlags.filter((f) => f !== flag)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-26 19:45:36 +10:00
|
|
|
|
2020-07-17 16:32:20 +10:00
|
|
|
function getMapSize() {
|
|
|
|
|
let size = 0;
|
|
|
|
|
if (map.quality === "original") {
|
|
|
|
|
size = map.file.length;
|
|
|
|
|
} else {
|
|
|
|
|
size = map.resolutions[map.quality].file.length;
|
|
|
|
|
}
|
|
|
|
|
size /= 1000000; // Bytes to Megabytes
|
|
|
|
|
return `${size.toFixed(2)}MB`;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-28 15:44:36 +10:00
|
|
|
const mapEmpty = !map || isEmpty(map);
|
|
|
|
|
const mapStateEmpty = !mapState || isEmpty(mapState);
|
|
|
|
|
|
2020-04-26 12:57:36 +10:00
|
|
|
return (
|
2020-04-26 13:47:54 +10:00
|
|
|
<Flex sx={{ flexDirection: "column" }}>
|
|
|
|
|
<Flex>
|
|
|
|
|
<Box mt={2} mr={1} sx={{ flexGrow: 1 }}>
|
|
|
|
|
<Label htmlFor="gridX">Columns</Label>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name="gridX"
|
|
|
|
|
value={(map && map.gridX) || 0}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
onSettingsChange("gridX", parseInt(e.target.value))
|
|
|
|
|
}
|
2020-06-28 15:44:36 +10:00
|
|
|
disabled={mapEmpty || map.type === "default"}
|
2020-04-26 13:47:54 +10:00
|
|
|
min={1}
|
2020-04-26 19:21:44 +10:00
|
|
|
my={1}
|
2020-04-26 13:47:54 +10:00
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box mt={2} ml={1} sx={{ flexGrow: 1 }}>
|
|
|
|
|
<Label htmlFor="gridY">Rows</Label>
|
|
|
|
|
<Input
|
|
|
|
|
type="number"
|
|
|
|
|
name="gridY"
|
|
|
|
|
value={(map && map.gridY) || 0}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
onSettingsChange("gridY", parseInt(e.target.value))
|
|
|
|
|
}
|
2020-06-28 15:44:36 +10:00
|
|
|
disabled={mapEmpty || map.type === "default"}
|
2020-04-26 13:47:54 +10:00
|
|
|
min={1}
|
2020-04-26 19:21:44 +10:00
|
|
|
my={1}
|
2020-04-26 13:47:54 +10:00
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</Flex>
|
2020-04-26 17:25:04 +10:00
|
|
|
{showMore && (
|
|
|
|
|
<>
|
|
|
|
|
<Box mt={2} sx={{ flexGrow: 1 }}>
|
2020-05-31 16:25:05 +10:00
|
|
|
<Label htmlFor="name">Name</Label>
|
|
|
|
|
<Input
|
|
|
|
|
name="name"
|
|
|
|
|
value={(map && map.name) || ""}
|
|
|
|
|
onChange={(e) => onSettingsChange("name", e.target.value)}
|
2020-06-28 15:44:36 +10:00
|
|
|
disabled={mapEmpty || map.type === "default"}
|
2020-05-31 16:25:05 +10:00
|
|
|
my={1}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
2020-06-30 21:23:45 +10:00
|
|
|
<Flex my={2} sx={{ alignItems: "center" }}>
|
|
|
|
|
<Box sx={{ width: "50%" }}>
|
|
|
|
|
<Label>Grid Type</Label>
|
2020-07-01 08:44:07 +10:00
|
|
|
<Select
|
|
|
|
|
defaultValue="Square"
|
|
|
|
|
my={1}
|
|
|
|
|
disabled={mapEmpty || map.type === "default"}
|
|
|
|
|
>
|
2020-06-30 21:23:45 +10:00
|
|
|
<option>Square</option>
|
2020-07-01 08:44:07 +10:00
|
|
|
<option disabled>Hex (Coming Soon)</option>
|
2020-06-30 21:23:45 +10:00
|
|
|
</Select>
|
|
|
|
|
</Box>
|
|
|
|
|
<Label sx={{ width: "50%" }} ml={2}>
|
2020-05-31 16:25:05 +10:00
|
|
|
<Checkbox
|
2020-07-01 08:43:34 +10:00
|
|
|
checked={!mapEmpty && map.showGrid}
|
2020-06-28 15:44:36 +10:00
|
|
|
disabled={mapEmpty || map.type === "default"}
|
2020-05-31 16:25:05 +10:00
|
|
|
onChange={(e) => onSettingsChange("showGrid", e.target.checked)}
|
|
|
|
|
/>
|
|
|
|
|
Show Grid
|
|
|
|
|
</Label>
|
2020-06-30 21:23:45 +10:00
|
|
|
</Flex>
|
2020-07-17 12:50:52 +10:00
|
|
|
{map.type !== "default" && (
|
|
|
|
|
<Flex my={2} sx={{ alignItems: "center" }}>
|
|
|
|
|
<Box sx={{ width: "50%" }}>
|
2020-07-17 16:32:31 +10:00
|
|
|
<Label>Quality</Label>
|
2020-07-17 12:50:52 +10:00
|
|
|
<Select
|
|
|
|
|
my={1}
|
|
|
|
|
value={!mapEmpty && map.quality}
|
|
|
|
|
disabled={mapEmpty}
|
|
|
|
|
onChange={(e) => onSettingsChange("quality", e.target.value)}
|
|
|
|
|
>
|
|
|
|
|
{qualitySettings.map((quality) => (
|
|
|
|
|
<option
|
|
|
|
|
key={quality.id}
|
|
|
|
|
value={quality.id}
|
|
|
|
|
disabled={
|
|
|
|
|
quality.id !== "original" &&
|
|
|
|
|
!map.resolutions[quality.id]
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{quality.name}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
</Box>
|
|
|
|
|
<Label sx={{ width: "50%" }} ml={2}>
|
2020-07-17 16:32:20 +10:00
|
|
|
Size: {getMapSize()}
|
2020-07-17 12:50:52 +10:00
|
|
|
</Label>
|
|
|
|
|
</Flex>
|
|
|
|
|
)}
|
2020-05-31 16:25:05 +10:00
|
|
|
<Divider fill />
|
|
|
|
|
<Box my={2} sx={{ flexGrow: 1 }}>
|
2020-07-01 08:43:06 +10:00
|
|
|
<Label>Allow Others to Edit</Label>
|
2020-04-26 19:21:44 +10:00
|
|
|
<Flex my={1}>
|
2020-04-29 21:12:57 +10:00
|
|
|
<Label>
|
|
|
|
|
<Checkbox
|
2020-06-28 15:44:36 +10:00
|
|
|
checked={!mapStateEmpty && mapState.editFlags.includes("fog")}
|
|
|
|
|
disabled={mapStateEmpty}
|
2020-04-29 21:12:57 +10:00
|
|
|
onChange={(e) => handleFlagChange(e, "fog")}
|
|
|
|
|
/>
|
|
|
|
|
Fog
|
|
|
|
|
</Label>
|
2020-04-26 17:25:04 +10:00
|
|
|
<Label>
|
|
|
|
|
<Checkbox
|
2020-06-28 15:44:36 +10:00
|
|
|
checked={
|
|
|
|
|
!mapStateEmpty && mapState.editFlags.includes("drawing")
|
|
|
|
|
}
|
|
|
|
|
disabled={mapStateEmpty}
|
2020-04-29 21:32:23 +10:00
|
|
|
onChange={(e) => handleFlagChange(e, "drawing")}
|
2020-04-26 17:25:04 +10:00
|
|
|
/>
|
|
|
|
|
Drawings
|
|
|
|
|
</Label>
|
|
|
|
|
<Label>
|
|
|
|
|
<Checkbox
|
2020-06-28 15:44:36 +10:00
|
|
|
checked={
|
|
|
|
|
!mapStateEmpty && mapState.editFlags.includes("tokens")
|
|
|
|
|
}
|
|
|
|
|
disabled={mapStateEmpty}
|
2020-04-26 17:25:04 +10:00
|
|
|
onChange={(e) => handleFlagChange(e, "tokens")}
|
|
|
|
|
/>
|
|
|
|
|
Tokens
|
|
|
|
|
</Label>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
onShowMoreChange(!showMore);
|
|
|
|
|
}}
|
|
|
|
|
sx={{
|
|
|
|
|
transform: `rotate(${showMore ? "180deg" : "0"})`,
|
|
|
|
|
alignSelf: "center",
|
|
|
|
|
}}
|
|
|
|
|
aria-label={showMore ? "Show Less" : "Show More"}
|
|
|
|
|
title={showMore ? "Show Less" : "Show More"}
|
|
|
|
|
>
|
|
|
|
|
<ExpandMoreIcon />
|
|
|
|
|
</IconButton>
|
2020-04-26 12:57:36 +10:00
|
|
|
</Flex>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MapSettings;
|