2020-05-03 05:52:01 -04:00
|
|
|
import Dexie from "dexie";
|
|
|
|
|
|
|
|
import blobToBuffer from "./helpers/blobToBuffer";
|
|
|
|
|
|
|
|
function loadVersions(db) {
|
2020-05-03 08:12:39 -04:00
|
|
|
// v1.2.0
|
2020-05-03 05:52:01 -04:00
|
|
|
db.version(1).stores({
|
|
|
|
maps: "id, owner",
|
|
|
|
states: "mapId",
|
|
|
|
tokens: "id, owner",
|
|
|
|
user: "key",
|
|
|
|
});
|
2020-05-03 08:12:39 -04:00
|
|
|
// v1.2.1 - Move from blob files to array buffers
|
2020-05-03 05:52:01 -04:00
|
|
|
db.version(2)
|
|
|
|
.stores({})
|
2020-05-03 08:12:39 -04:00
|
|
|
.upgrade(async (tx) => {
|
|
|
|
const maps = await Dexie.waitFor(tx.table("maps").toArray());
|
|
|
|
let mapBuffers = {};
|
|
|
|
for (let map of maps) {
|
|
|
|
mapBuffers[map.id] = await Dexie.waitFor(blobToBuffer(map.file));
|
|
|
|
}
|
2020-05-03 05:52:01 -04:00
|
|
|
return tx
|
|
|
|
.table("maps")
|
|
|
|
.toCollection()
|
|
|
|
.modify((map) => {
|
2020-05-03 08:12:39 -04:00
|
|
|
map.file = mapBuffers[map.id];
|
2020-05-03 05:52:01 -04:00
|
|
|
});
|
|
|
|
});
|
2020-05-18 02:31:32 -04:00
|
|
|
// v1.3.0 - Added new default tokens
|
|
|
|
db.version(3)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("states")
|
|
|
|
.toCollection()
|
|
|
|
.modify((state) => {
|
|
|
|
function mapTokenId(id) {
|
|
|
|
switch (id) {
|
|
|
|
case "__default-Axes":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Barbarian";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Bird":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Druid";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Book":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Wizard";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Crown":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Humanoid";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Dragon":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Dragon";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Eye":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Warlock";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Fist":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Monk";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Horse":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Fey";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Leaf":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Druid";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Lion":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Monstrosity";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Money":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Humanoid";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Moon":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Cleric";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Potion":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Sorcerer";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Shield":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Paladin";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Skull":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Undead";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Snake":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Beast";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Sun":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Cleric";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Swords":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Fighter";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Tree":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Plant";
|
2020-05-18 02:31:32 -04:00
|
|
|
case "__default-Triangle":
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Sorcerer";
|
2020-05-18 02:31:32 -04:00
|
|
|
default:
|
2020-05-24 01:18:30 -04:00
|
|
|
return "__default-Fighter";
|
2020-05-18 02:31:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let stateId in state.tokens) {
|
|
|
|
state.tokens[stateId].tokenId = mapTokenId(
|
|
|
|
state.tokens[stateId].tokenId
|
|
|
|
);
|
2020-05-24 01:18:30 -04:00
|
|
|
state.tokens[stateId].lastEditedBy = "";
|
|
|
|
state.tokens[stateId].rotation = 0;
|
2020-05-18 02:31:32 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-05-31 02:25:05 -04:00
|
|
|
// v1.3.1 - Added show grid option
|
|
|
|
db.version(4)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("maps")
|
|
|
|
.toCollection()
|
|
|
|
.modify((map) => {
|
|
|
|
map.showGrid = false;
|
|
|
|
});
|
|
|
|
});
|
2020-06-28 02:13:06 -04:00
|
|
|
// v1.4.0 - Added fog subtraction
|
|
|
|
db.version(5)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("states")
|
|
|
|
.toCollection()
|
|
|
|
.modify((state) => {
|
|
|
|
for (let fogAction of state.fogDrawActions) {
|
|
|
|
if (fogAction.type === "add" || fogAction.type === "edit") {
|
|
|
|
for (let shape of fogAction.shapes) {
|
|
|
|
shape.data.holes = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-07-18 02:57:47 -04:00
|
|
|
// v1.4.2 - Added map resolutions
|
|
|
|
db.version(6)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("maps")
|
|
|
|
.toCollection()
|
|
|
|
.modify((map) => {
|
|
|
|
map.resolutions = {};
|
|
|
|
map.quality = "original";
|
|
|
|
});
|
|
|
|
});
|
2020-08-05 20:07:10 -04:00
|
|
|
// v1.5.0 - Fixed default token rogue spelling
|
|
|
|
db.version(7)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("states")
|
|
|
|
.toCollection()
|
|
|
|
.modify((state) => {
|
|
|
|
for (let id in state.tokens) {
|
|
|
|
if (state.tokens[id].tokenId === "__default-Rouge") {
|
|
|
|
state.tokens[id].tokenId = "__default-Rogue";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-08-06 22:28:50 -04:00
|
|
|
// v1.5.0 - Added map snap to grid option
|
|
|
|
db.version(8)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("maps")
|
|
|
|
.toCollection()
|
|
|
|
.modify((map) => {
|
|
|
|
map.snapToGrid = true;
|
|
|
|
});
|
|
|
|
});
|
2020-08-27 03:30:17 -04:00
|
|
|
// v1.5.1 - Added lock, visibility and modified to tokens
|
|
|
|
db.version(9)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("states")
|
|
|
|
.toCollection()
|
|
|
|
.modify((state) => {
|
|
|
|
for (let id in state.tokens) {
|
|
|
|
state.tokens[id].lastModifiedBy = state.tokens[id].lastEditedBy;
|
|
|
|
delete state.tokens[id].lastEditedBy;
|
|
|
|
state.tokens[id].lastModified = Date.now();
|
|
|
|
state.tokens[id].locked = false;
|
|
|
|
state.tokens[id].visible = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-08-27 05:09:16 -04:00
|
|
|
// v1.5.1 - Added token prop category and remove isVehicle bool
|
|
|
|
db.version(10)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("tokens")
|
|
|
|
.toCollection()
|
|
|
|
.modify((token) => {
|
|
|
|
token.category = token.isVehicle ? "vehicle" : "character";
|
|
|
|
delete token.isVehicle;
|
|
|
|
});
|
|
|
|
});
|
2020-09-11 02:56:40 -04:00
|
|
|
// v1.5.2 - Added automatic cache invalidation to maps
|
|
|
|
db.version(11)
|
|
|
|
.stores({})
|
2020-10-01 01:05:30 -04:00
|
|
|
.upgrade((tx) => {
|
2020-09-11 02:56:40 -04:00
|
|
|
return tx
|
|
|
|
.table("maps")
|
|
|
|
.toCollection()
|
|
|
|
.modify((map) => {
|
|
|
|
map.lastUsed = map.lastModified;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// v1.5.2 - Added automatic cache invalidation to tokens
|
|
|
|
db.version(12)
|
|
|
|
.stores({})
|
2020-10-01 01:05:30 -04:00
|
|
|
.upgrade((tx) => {
|
2020-09-11 02:56:40 -04:00
|
|
|
return tx
|
|
|
|
.table("tokens")
|
|
|
|
.toCollection()
|
|
|
|
.modify((token) => {
|
|
|
|
token.lastUsed = token.lastModified;
|
|
|
|
});
|
|
|
|
});
|
2020-10-02 01:19:10 -04:00
|
|
|
// v1.6.0 - Added map grouping and grid scale and offset
|
2020-10-01 01:05:30 -04:00
|
|
|
db.version(13)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("maps")
|
|
|
|
.toCollection()
|
|
|
|
.modify((map) => {
|
|
|
|
map.group = "";
|
2020-10-02 01:19:10 -04:00
|
|
|
map.grid = {
|
|
|
|
size: { x: map.gridX, y: map.gridY },
|
|
|
|
scale: { x: 1, y: 1 },
|
|
|
|
offset: { x: 0, y: 0 },
|
|
|
|
type: "square",
|
|
|
|
};
|
|
|
|
delete map.gridX;
|
|
|
|
delete map.gridY;
|
|
|
|
delete map.gridType;
|
2020-10-01 01:05:30 -04:00
|
|
|
});
|
|
|
|
});
|
2020-10-01 08:32:21 -04:00
|
|
|
// v1.6.0 - Added token grouping
|
|
|
|
db.version(14)
|
|
|
|
.stores({})
|
|
|
|
.upgrade((tx) => {
|
|
|
|
return tx
|
|
|
|
.table("tokens")
|
|
|
|
.toCollection()
|
|
|
|
.modify((token) => {
|
|
|
|
token.group = "";
|
|
|
|
});
|
|
|
|
});
|
2020-05-03 05:52:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the dexie database used in DatabaseContext
|
|
|
|
export function getDatabase(options) {
|
|
|
|
let db = new Dexie("OwlbearRodeoDB", options);
|
|
|
|
loadVersions(db);
|
|
|
|
return db;
|
|
|
|
}
|