Added new members to state db upgrade removed duplicated field from token state
Matched token default id with map default id as map can't be changed
This commit is contained in:
parent
bbb9279228
commit
b3b84d889b
@ -25,7 +25,6 @@ function Tokens({ onMapTokenStateCreate }) {
|
||||
onMapTokenStateCreate({
|
||||
id: shortid.generate(),
|
||||
tokenId: token.id,
|
||||
tokenType: token.type,
|
||||
owner: userId,
|
||||
size: token.defaultSize,
|
||||
label: "",
|
||||
|
@ -22,7 +22,7 @@ export function TokenDataProvider({ children }) {
|
||||
for (let defaultToken of defaultTokens) {
|
||||
defaultTokensWithIds.push({
|
||||
...defaultToken,
|
||||
id: `__default-${defaultToken.key}`,
|
||||
id: `__default-${defaultToken.name}`,
|
||||
owner: userId,
|
||||
});
|
||||
}
|
||||
|
@ -37,54 +37,55 @@ function loadVersions(db) {
|
||||
function mapTokenId(id) {
|
||||
switch (id) {
|
||||
case "__default-Axes":
|
||||
return "__default-barbarian";
|
||||
return "__default-Barbarian";
|
||||
case "__default-Bird":
|
||||
return "__default-druid";
|
||||
return "__default-Druid";
|
||||
case "__default-Book":
|
||||
return "__default-wizard";
|
||||
return "__default-Wizard";
|
||||
case "__default-Crown":
|
||||
return "__default-humanoid";
|
||||
return "__default-Humanoid";
|
||||
case "__default-Dragon":
|
||||
return "__default-dragon";
|
||||
return "__default-Dragon";
|
||||
case "__default-Eye":
|
||||
return "__default-warlock";
|
||||
return "__default-Warlock";
|
||||
case "__default-Fist":
|
||||
return "__default-monk";
|
||||
return "__default-Monk";
|
||||
case "__default-Horse":
|
||||
return "__default-fey";
|
||||
return "__default-Fey";
|
||||
case "__default-Leaf":
|
||||
return "__default-druid";
|
||||
return "__default-Druid";
|
||||
case "__default-Lion":
|
||||
return "__default-monstrosity";
|
||||
return "__default-Monstrosity";
|
||||
case "__default-Money":
|
||||
return "__default-humanoid";
|
||||
return "__default-Humanoid";
|
||||
case "__default-Moon":
|
||||
return "__default-cleric";
|
||||
return "__default-Cleric";
|
||||
case "__default-Potion":
|
||||
return "__default-sorcerer";
|
||||
return "__default-Sorcerer";
|
||||
case "__default-Shield":
|
||||
return "__default-paladin";
|
||||
return "__default-Paladin";
|
||||
case "__default-Skull":
|
||||
return "__default-undead";
|
||||
return "__default-Undead";
|
||||
case "__default-Snake":
|
||||
return "__default-beast";
|
||||
return "__default-Beast";
|
||||
case "__default-Sun":
|
||||
return "__default-cleric";
|
||||
return "__default-Cleric";
|
||||
case "__default-Swords":
|
||||
return "__default-fighter";
|
||||
return "__default-Fighter";
|
||||
case "__default-Tree":
|
||||
return "__default-plant";
|
||||
return "__default-Plant";
|
||||
case "__default-Triangle":
|
||||
return "__default-sorcerer";
|
||||
return "__default-Sorcerer";
|
||||
default:
|
||||
return "__default-fighter";
|
||||
return "__default-Fighter";
|
||||
}
|
||||
}
|
||||
for (let stateId in state.tokens) {
|
||||
state.tokens[stateId].tokenId = mapTokenId(
|
||||
state.tokens[stateId].tokenId
|
||||
);
|
||||
state.tokens[stateId].type = "default";
|
||||
state.tokens[stateId].lastEditedBy = "";
|
||||
state.tokens[stateId].rotation = 0;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -43,6 +43,9 @@ function Game() {
|
||||
handlePeerError
|
||||
);
|
||||
|
||||
const { putToken, getToken } = useContext(TokenDataContext);
|
||||
const { putMap, getMap } = useContext(MapDataContext);
|
||||
|
||||
/**
|
||||
* Map state
|
||||
*/
|
||||
@ -220,25 +223,24 @@ function Game() {
|
||||
function sendTokensToPeer(peer, state) {
|
||||
let sentTokens = {};
|
||||
for (let tokenState of Object.values(state.tokens)) {
|
||||
const token = getToken(tokenState.tokenId);
|
||||
if (
|
||||
tokenState.tokenType === "file" &&
|
||||
token &&
|
||||
token.type === "file" &&
|
||||
!(tokenState.tokenId in sentTokens)
|
||||
) {
|
||||
sentTokens[tokenState.tokenId] = true;
|
||||
const token = getToken(tokenState.tokenId);
|
||||
if (token) {
|
||||
// Omit file from token peer will request file if needed
|
||||
const { file, ...rest } = token;
|
||||
peer.connection.send({ id: "token", data: rest });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handleMapTokenStateCreate(tokenState) {
|
||||
// If file type token send the token to the other peers
|
||||
if (tokenState.tokenType === "file") {
|
||||
const token = getToken(tokenState.tokenId);
|
||||
if (token && token.type === "file") {
|
||||
const { file, ...rest } = token;
|
||||
for (let peer of Object.values(peers)) {
|
||||
peer.connection.send({ id: "token", data: rest });
|
||||
@ -301,9 +303,6 @@ function Game() {
|
||||
* Peer handlers
|
||||
*/
|
||||
|
||||
const { putToken, getToken } = useContext(TokenDataContext);
|
||||
const { putMap, getMap } = useContext(MapDataContext);
|
||||
|
||||
function handlePeerData({ data, peer }) {
|
||||
if (data.id === "sync") {
|
||||
if (currentMapState) {
|
||||
|
Loading…
Reference in New Issue
Block a user