Added name to map and added default props
This commit is contained in:
parent
049a8f5c00
commit
4c667e9c5f
@ -13,7 +13,7 @@ function useDataSource(data, defaultSources) {
|
|||||||
if (data.type === "file") {
|
if (data.type === "file") {
|
||||||
url = URL.createObjectURL(data.file);
|
url = URL.createObjectURL(data.file);
|
||||||
} else if (data.type === "default") {
|
} else if (data.type === "default") {
|
||||||
url = defaultSources[data.name];
|
url = defaultSources[data.key];
|
||||||
}
|
}
|
||||||
setDataSource(url);
|
setDataSource(url);
|
||||||
|
|
||||||
|
@ -14,8 +14,9 @@ export const mapSources = {
|
|||||||
wood: woodImage,
|
wood: woodImage,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const maps = Object.keys(mapSources).map((name) => ({
|
export const maps = Object.keys(mapSources).map((key) => ({
|
||||||
name,
|
key,
|
||||||
|
name: key.charAt(0).toUpperCase() + key.slice(1),
|
||||||
gridX: 22,
|
gridX: 22,
|
||||||
gridY: 22,
|
gridY: 22,
|
||||||
width: 1024,
|
width: 1024,
|
||||||
|
@ -20,6 +20,14 @@ const defaultMapState = {
|
|||||||
drawActions: [],
|
drawActions: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const defaultMapProps = {
|
||||||
|
// Flags to determine what other people can edit
|
||||||
|
editFlags: [],
|
||||||
|
// Grid type
|
||||||
|
// TODO: add support for hex horizontal and hex vertical
|
||||||
|
gridType: "grid",
|
||||||
|
};
|
||||||
|
|
||||||
function SelectMapModal({
|
function SelectMapModal({
|
||||||
isOpen,
|
isOpen,
|
||||||
onRequestClose,
|
onRequestClose,
|
||||||
@ -52,6 +60,7 @@ function SelectMapModal({
|
|||||||
owner: userId,
|
owner: userId,
|
||||||
// Emulate the time increasing to avoid sort errors
|
// Emulate the time increasing to avoid sort errors
|
||||||
timestamp: Date.now() + i,
|
timestamp: Date.now() + i,
|
||||||
|
...defaultMapProps,
|
||||||
});
|
});
|
||||||
// Add a state for the map if there isn't one already
|
// Add a state for the map if there isn't one already
|
||||||
const state = await db.table("states").get(id);
|
const state = await db.table("states").get(id);
|
||||||
@ -84,6 +93,7 @@ function SelectMapModal({
|
|||||||
}
|
}
|
||||||
let fileGridX = defaultMapSize;
|
let fileGridX = defaultMapSize;
|
||||||
let fileGridY = defaultMapSize;
|
let fileGridY = defaultMapSize;
|
||||||
|
let name = "Unknown Map";
|
||||||
if (file.name) {
|
if (file.name) {
|
||||||
// Match against a regex to find the grid size in the file name
|
// Match against a regex to find the grid size in the file name
|
||||||
// e.g. Cave 22x23 will return [["22x22", "22", "x", "23"]]
|
// e.g. Cave 22x23 will return [["22x22", "22", "x", "23"]]
|
||||||
@ -97,6 +107,13 @@ function SelectMapModal({
|
|||||||
fileGridY = matchY;
|
fileGridY = matchY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Remove file extension
|
||||||
|
name = file.name.replace(/\.[^/.]+$/, "");
|
||||||
|
// Removed grid size expression
|
||||||
|
name = name.replace(/(\[ ?|\( ?)?\d+ ?(x|X) ?\d+( ?\]| ?\))?/, "");
|
||||||
|
// Clean string
|
||||||
|
name = name.replace(/ +/g, " ");
|
||||||
|
name = name.trim();
|
||||||
}
|
}
|
||||||
let image = new Image();
|
let image = new Image();
|
||||||
setImageLoading(true);
|
setImageLoading(true);
|
||||||
@ -105,6 +122,7 @@ function SelectMapModal({
|
|||||||
image.onload = function () {
|
image.onload = function () {
|
||||||
handleMapAdd({
|
handleMapAdd({
|
||||||
file,
|
file,
|
||||||
|
name,
|
||||||
type: "file",
|
type: "file",
|
||||||
gridX: fileGridX,
|
gridX: fileGridX,
|
||||||
gridY: fileGridY,
|
gridY: fileGridY,
|
||||||
@ -113,6 +131,7 @@ function SelectMapModal({
|
|||||||
id: shortid.generate(),
|
id: shortid.generate(),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
owner: userId,
|
owner: userId,
|
||||||
|
...defaultMapProps,
|
||||||
});
|
});
|
||||||
setImageLoading(false);
|
setImageLoading(false);
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
|
@ -42,7 +42,8 @@ export const tokenSources = {
|
|||||||
triangle,
|
triangle,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const tokens = Object.keys(tokenSources).map((name) => ({
|
export const tokens = Object.keys(tokenSources).map((key) => ({
|
||||||
name,
|
key,
|
||||||
|
name: key.charAt(0).toUpperCase() + key.slice(1),
|
||||||
type: "default",
|
type: "default",
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user