Skip to content
Snippets Groups Projects
Commit ea422199 authored by Tiger Wang's avatar Tiger Wang Committed by Tiger Wang
Browse files

Add bi/trifurcation and deletion support with @bearbin

parent dc9d0619
No related branches found
No related tags found
No related merge requests found
import { computeErasureIntervals, combineErasureIntervals } from "./erasure.js"
import { connect } from "./room.js"
import XMPP from "./connection/XMPP2.js"
import { connect } from "./room.js"
const DEFAULT_ROOM = "imperial"
let room = null
let secureLine = null
let divulgedUpTo = new Map();
const pointPresenceMap = new Map()
function eraseEverythingAtPosition(x, y, radius, room) {
const mousePos = [x, y]
......@@ -85,14 +86,49 @@ const onRoomConnect = (room_) => {
room.addEventListener(
"removedIntervalsChange",
({ detail: { id, intervals, points } }) => {
room.erasureIntervals[id] = combineErasureIntervals(
const currentIntervals = combineErasureIntervals(
room.erasureIntervals[id] || {},
intervals,
)
room.erasureIntervals[id] = currentIntervals;
if (pointPresenceMap.get(id) === undefined) {
pointPresenceMap.set(id, Array(points.length).fill(true))
}
for (const point in currentIntervals) {
deletePoint(id, parseInt(point))
}
},
)
}
const deletePoint = (lineID, offset) => {
const bLine = pointPresenceMap.get(lineID)
if (!bLine[offset]) {
return
}
if (offset > 0 && bLine[offset - 1] && offset < (bLine.length - 1) && bLine[offset + 1]) {
secureLine.sneakilySendTheOtherTeamOur(JSON.stringify({
"type": "BIFURCATE",
"identifier": lineID,
"start_offset": offset,
"end_offset": offset
}))
}
secureLine.sneakilySendTheOtherTeamOur(JSON.stringify({
"type": "DELETE",
"identifier": lineID,
"offset": offset
}))
bLine[offset] = false
}
const tryRoomConnect = async (roomID) => {
return await connect(roomID)
.then(onRoomConnect)
......
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