Skip to content
Snippets Groups Projects
Commit 47324068 authored by Yuriy Maksymets's avatar Yuriy Maksymets
Browse files

Merging intervals locally

parent 91c1a8c8
No related branches found
No related tags found
No related merge requests found
......@@ -36,17 +36,11 @@ function eraseAt(x, y, room) {
ERASERRADIUS,
)
console.log(prevPathIntervals, newPathIntervals)
const erasureIntervalsForPath = combineErasureIntervals(
prevPathIntervals,
newPathIntervals,
)
// if (!TEST_ERASE_INTERVAL[pathID]) TEST_ERASE_INTERVAL[pathID] = {}
// TEST_ERASE_INTERVAL[pathID] = erasureIntervalsForPath
console.log("erasureIntervalsForPath")
console.log(erasureIntervalsForPath)
Object.keys(erasureIntervalsForPath).forEach((pointID) =>
room.extendErasureIntervals(
pathID,
......@@ -55,11 +49,6 @@ function eraseAt(x, y, room) {
),
)
// room.dispatchEvent(
// new CustomEvent("removedIntervalsChange", {
// detail: { id: pathID, points },
// }),
// )
points.forEach((point) => {
const distanceToPoint = getDistance(mousePos, point)
if (distanceToPoint <= ERASERRADIUS) {
......@@ -184,9 +173,9 @@ function needToDrawLastPoint(points, pathID) {
function generatePointsForPathElem(pathElem, pathID, dataPoints) {
const points = dataPoints
document.getElementById("console").innerText = JSON.stringify(
TEST_ERASE_INTERVAL,
)
// document.getElementById("console").innerText = JSON.stringify(
// TEST_ERASE_INTERVAL,
// )
const appendToWholePath = (subPath) => {
if (!(subPath && subPath.length)) return
const subpathElem = generateSvgForSubpath(subPath)
......@@ -322,11 +311,10 @@ function handleRoomConnectionEstablished(room) {
room.addEventListener(
"removedIntervalsChange",
({ detail: { id, intervals, points } }) => {
console.log("got the event for id", id)
console.log(intervals)
TEST_ERASE_INTERVAL[id] = intervals
console.log(pathElems, id, points)
TEST_ERASE_INTERVAL[id] = combineErasureIntervals(
TEST_ERASE_INTERVAL[id] || {},
intervals,
)
addOrUpdatePathElem(pathElems, id, points)
},
)
......@@ -425,12 +413,12 @@ function handleRoomConnectionEstablished(room) {
}
HTML.roomConnectButton.addEventListener("click", roomConnectButtonOnClick)
let pid = room.addPath([100, 100])
room.extendPath(pid, [800, 200])
room.extendPath(pid, [100, 300])
room.extendPath(pid, [800, 400])
room.extendPath(pid, [800, 450])
room.extendPath(pid, [800, 500])
// let pid = room.addPath([100, 100])
// room.extendPath(pid, [800, 200])
// room.extendPath(pid, [100, 300])
// room.extendPath(pid, [800, 400])
// room.extendPath(pid, [800, 450])
// room.extendPath(pid, [800, 500])
}
function handleRoomConnectionError(err) {
......
......@@ -49,11 +49,8 @@ class Room extends EventTarget {
const pathIntervals = yGetOrSet(this.sharedMergeIntervals, pathID, Y.Map)
const pointIntervals = yGetOrSet(pathIntervals, pointID, Y.Array)
// pointIntervals.delete(0, pointIntervals.length)
newIntervals.forEach((newInterval) => pointIntervals.push([newInterval]))
console.log("pointIntervals")
console.log(pointIntervals.toArray())
pointIntervals.delete(0, pointIntervals.length)
pointIntervals.push(newIntervals)
}
getPaths() {
......@@ -106,11 +103,8 @@ class Room extends EventTarget {
_generateRemovedIntervals(id) {
const intervals = this.sharedMergeIntervals.get(id)
if (!intervals) return []
console.log(intervals)
const json = intervals.toJSON()
console.log("json")
console.log(json)
return typeof json === "string" ? JSON.parse(json) : json
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment