Change map state drawShapes and fogShapes name

This commit is contained in:
Mitchell McCaffrey 2021-08-06 08:21:19 +10:00
parent d1e62e850a
commit b300418d78
10 changed files with 52 additions and 28 deletions

View File

@ -104,8 +104,8 @@ function Map({
}));
}
const drawShapes = Object.values(mapState?.drawShapes || {});
const fogShapes = Object.values(mapState?.fogShapes || {});
const drawShapes = Object.values(mapState?.drawings || {});
const fogShapes = Object.values(mapState?.fogs || {});
function handleToolAction(action: string) {
if (action === "eraseAll") {

View File

@ -113,7 +113,7 @@ function MapContols({
const disabledSettings: Partial<Record<keyof Settings, string[]>> = {
drawing: [],
};
if (mapState && isEmpty(mapState.drawShapes)) {
if (mapState && isEmpty(mapState.drawings)) {
disabledSettings.drawing?.push("erase");
}

View File

@ -52,8 +52,8 @@ function MapEditBar({
for (let state of selectedMapStates) {
if (
Object.values(state.tokens).length > 0 ||
Object.values(state.drawShapes).length > 0 ||
Object.values(state.fogShapes).length > 0 ||
Object.values(state.drawings).length > 0 ||
Object.values(state.fogs).length > 0 ||
Object.values(state.notes).length > 0
) {
_hasMapState = true;

View File

@ -252,9 +252,9 @@ function SelectionMenu({
data: {
tokens: {},
notes: {},
drawShapes: {},
drawings: {},
editFlags: [],
fogShapes: {},
fogs: {},
mapId: mapState.mapId,
},
};

View File

@ -55,8 +55,8 @@ const MapDataContext =
const defaultMapState: Omit<MapState, "mapId"> = {
tokens: {},
drawShapes: {},
fogShapes: {},
drawings: {},
fogs: {},
// Flags to determine what other people can edit
editFlags: ["drawing", "tokens", "notes", "fog"],
notes: {},

View File

@ -50,9 +50,9 @@ function useMapActions(
): MapState {
for (let mapAction of actions) {
if (mapAction.type === "drawings") {
mapState.drawShapes = mapAction.action.execute(mapState.drawShapes);
mapState.drawings = mapAction.action.execute(mapState.drawings);
} else if (mapAction.type === "fogs") {
mapState.fogShapes = mapAction.action.execute(mapState.fogShapes);
mapState.fogs = mapAction.action.execute(mapState.fogs);
} else if (mapAction.type === "tokens") {
mapState.tokens = mapAction.action.execute(mapState.tokens);
} else if (mapAction.type === "notes") {
@ -68,9 +68,9 @@ function useMapActions(
): MapState {
for (let mapAction of actions) {
if (mapAction.type === "drawings") {
mapState.drawShapes = mapAction.action.undo(mapState.drawShapes);
mapState.drawings = mapAction.action.undo(mapState.drawings);
} else if (mapAction.type === "fogs") {
mapState.fogShapes = mapAction.action.undo(mapState.fogShapes);
mapState.fogs = mapAction.action.undo(mapState.fogs);
} else if (mapAction.type === "tokens") {
mapState.tokens = mapAction.action.undo(mapState.tokens);
} else if (mapAction.type === "notes") {

View File

@ -55,8 +55,8 @@ export function getDefaultMaps(userId: string): {
const state: MapState = {
mapId: id,
tokens: {},
drawShapes: {},
fogShapes: {},
drawings: {},
fogs: {},
editFlags: ["drawing", "tokens", "notes"],
notes: {},
};

View File

@ -7,8 +7,8 @@ export type EditFlag = "drawing" | "tokens" | "notes" | "fog";
export type MapState = {
tokens: TokenStates;
drawShapes: DrawingState;
fogShapes: FogState;
drawings: DrawingState;
fogs: FogState;
editFlags: Array<EditFlag>;
notes: Notes;
mapId: string;

View File

@ -847,9 +847,40 @@ export const versions: Record<number, VersionCallback> = {
});
});
},
// v1.10.0 - Delete groups again
38(v, onUpgrade) {
v.stores({}).upgrade((tx) => {
onUpgrade?.(38);
tx.table("maps")
.toCollection()
.modify((map) => {
delete map.group;
});
tx.table("tokens")
.toCollection()
.modify((token) => {
delete token.group;
});
});
},
// v1.10.0 - Rename drawShapes and fogShapes in state
39(v, onUpgrade) {
v.stores({}).upgrade((tx) => {
onUpgrade?.(39);
tx.table("states")
.toCollection()
.modify((state) => {
state.drawings = state.drawShapes;
state.fogs = state.fogShapes;
delete state.drawShapes;
delete state.fogShapes;
});
});
},
};
export const latestVersion = 37;
export const latestVersion = 39;
/**
* Load versions onto a database up to a specific version number

View File

@ -15,10 +15,10 @@ export const MapStateSchema: any = {
tokens: {
$ref: "#/definitions/TokenStates",
},
drawShapes: {
drawings: {
$ref: "#/definitions/DrawingState",
},
fogShapes: {
fogs: {
$ref: "#/definitions/FogState",
},
editFlags: {
@ -35,14 +35,7 @@ export const MapStateSchema: any = {
type: "string",
},
},
required: [
"drawShapes",
"editFlags",
"fogShapes",
"mapId",
"notes",
"tokens",
],
required: ["drawings", "editFlags", "fogs", "mapId", "notes", "tokens"],
type: "object",
definitions: {
TokenStates: {