diff --git a/web/_js/main.js b/web/_js/main.js index f899c849..c25d0990 100644 --- a/web/_js/main.js +++ b/web/_js/main.js @@ -137,6 +137,35 @@ async function init(){ if(initOverlap){ initOverlap(); } + } else if(mode.startsWith("diff")){ + wrapper.className = wrapper.className.replace(/ drawMode/g, ""); + try { + let liveResp = await fetch("https://place-atlas.stefanocoding.me/atlas.json"); + let liveJson = await liveResp.json(); + let liveAtlasReduced = liveJson.reduce(function(a, c) { + a[c.id] = c; + return a; + },{}); + if(mode.endsWith("only")){ + atlas = atlas.filter(function(entry) { + return JSON.stringify(entry) !== JSON.stringify(liveAtlasReduced[entry.id]); + }); + } + atlas = atlas.map(function(entry) { + if(liveAtlasReduced[entry.id] === undefined){ + entry.diff = "add"; + }else if(JSON.stringify(entry) !== JSON.stringify(liveAtlasReduced[entry.id])){ + entry.diff = "edit"; + } + return entry; + }); + //TEMP FOR TIME TRAVEL + atlasBackup = atlas; + } catch (error) { + console.log("Diff mode failed to load, reverting to normal view - " + error); + } finally { + initView(); + } } function changeOverlapMode(){ @@ -164,7 +193,7 @@ async function init(){ const toggleMode = document.getElementById("toggleMode"); toggleMode.onclick = changeOverlapMode; - toggleMode.innerHTML = modeMap[mode]; + toggleMode.innerHTML = modeMap[mode] || "Overlap"; document.getElementById("loading").style.display = "none"; diff --git a/web/_js/view.js b/web/_js/view.js index 8857e668..827f6917 100644 --- a/web/_js/view.js +++ b/web/_js/view.js @@ -114,8 +114,23 @@ function renderBackground(atlas){ backgroundContext.closePath(); - backgroundContext.strokeStyle = "rgba(255, 255, 255, 0.8)"; + var bgStrokeStyle; + switch (atlas[i].diff) { + case "add": + bgStrokeStyle = "rgba(0, 255, 0, 1)"; + backgroundContext.lineWidth = 2; + break; + case "edit": + bgStrokeStyle = "rgba(255, 255, 0, 1)"; + backgroundContext.lineWidth = 2; + break; + default: + bgStrokeStyle = "rgba(255, 255, 255, 0.8)"; + break; + } + backgroundContext.strokeStyle = bgStrokeStyle; backgroundContext.stroke(); + backgroundContext.lineWidth = 1; } } @@ -691,7 +706,19 @@ function initView(){ context.globalCompositeOperation = "source-over"; - context.strokeStyle = "rgba(0, 0, 0, 1)"; + var hoverStrokeStyle; + switch (hovered[i].diff) { + case "add": + hoverStrokeStyle = "rgba(0, 155, 0, 1)"; + break; + case "edit": + hoverStrokeStyle = "rgba(155, 155, 0, 1)"; + break; + default: + hoverStrokeStyle = "rgba(0, 0, 0, 1)"; + break; + } + context.strokeStyle = hoverStrokeStyle; //context.lineWidth = zoom; context.stroke(); }