Add diff modes

This commit is contained in:
Wayland-Smithy 2022-04-07 21:06:16 -07:00
parent 808c9ba4fe
commit b0b1215d7f
2 changed files with 59 additions and 3 deletions

View file

@ -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";

View file

@ -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();
}