Added map resolutions to map send

This commit is contained in:
Mitchell McCaffrey 2020-07-13 21:49:40 +10:00
parent a96d177cc5
commit 8332aab328

View File

@ -49,7 +49,7 @@ function Game() {
); );
const { putToken, getToken } = useContext(TokenDataContext); const { putToken, getToken } = useContext(TokenDataContext);
const { putMap, getMap } = useContext(MapDataContext); const { putMap, getMap, updateMap } = useContext(MapDataContext);
/** /**
* Map state * Map state
@ -119,8 +119,8 @@ function Game() {
// Omit file from map change, receiver will request the file if // Omit file from map change, receiver will request the file if
// they have an outdated version // they have an outdated version
if (mapData.type === "file") { if (mapData.type === "file") {
const { file, ...rest } = mapData; const { file, resolutions, ...rest } = mapData;
peer.connection.send({ id: "map", data: rest }); peer.connection.send({ id: "map", data: { ...rest, resolutions: [] } });
} else { } else {
peer.connection.send({ id: "map", data: mapData }); peer.connection.send({ id: "map", data: mapData });
} }
@ -325,7 +325,9 @@ function Game() {
if (cachedMap && cachedMap.lastModified === newMap.lastModified) { if (cachedMap && cachedMap.lastModified === newMap.lastModified) {
setCurrentMap(cachedMap); setCurrentMap(cachedMap);
} else { } else {
peer.connection.send({ id: "mapRequest", data: newMap.id }); putMap(newMap).then(() => {
peer.connection.send({ id: "mapRequest", data: newMap.id });
});
} }
} else { } else {
setCurrentMap(newMap); setCurrentMap(newMap);
@ -334,18 +336,28 @@ function Game() {
// Send full map data including file // Send full map data including file
if (data.id === "mapRequest") { if (data.id === "mapRequest") {
const map = getMap(data.data); const map = getMap(data.data);
peer.connection.send({ id: "mapResponse", data: map }); peer.connection.send({
id: "mapResponse",
data: { id: map.id, resolutions: map.resolutions },
});
peer.connection.send({
id: "mapResponse",
data: { id: map.id, file: map.file },
});
} }
// A new map response with a file attached // A new map response with a file attached
if (data.id === "mapResponse") { if (data.id === "mapResponse") {
if (data.data && data.data.type === "file") { let update = {};
const newMap = { ...data.data, file: data.data.file }; if (data.data.file) {
putMap(newMap).then(() => { update.file = data.data.file;
setCurrentMap(newMap);
});
} else {
setCurrentMap(data.data);
} }
if (data.data.resolutions) {
update.resolutions = data.data.resolutions;
}
const map = getMap(data.data.id);
updateMap(map.id, update).then(() => {
setCurrentMap({ ...map, ...update });
});
} }
if (data.id === "mapState") { if (data.id === "mapState") {
setCurrentMapState(data.data); setCurrentMapState(data.data);