add lots of logging everywhere

This commit is contained in:
Tomáš Mládek 2021-01-11 23:10:40 +01:00
parent 3ee9ae83ca
commit b23d471281
3 changed files with 45 additions and 12 deletions

View file

@ -22,6 +22,9 @@ export default defineComponent({
setup(props) { setup(props) {
const audio = ref<HTMLAudioElement | null>(null); const audio = ref<HTMLAudioElement | null>(null);
console.debug(`[AUDIOAREA] Initializing ${props.definition.src}...`);
console.debug(props.definition);
const MIN_SCALE = 0.02; const MIN_SCALE = 0.02;
const MIN_VOLUME_MULTIPLIER = 0.33; const MIN_VOLUME_MULTIPLIER = 0.33;
const vol_x = (1 - MIN_VOLUME_MULTIPLIER) / (1 - MIN_SCALE); const vol_x = (1 - MIN_VOLUME_MULTIPLIER) / (1 - MIN_SCALE);
@ -33,11 +36,17 @@ export default defineComponent({
const distance = Math.sqrt(Math.pow(x - props.definition.cx, 2) + Math.pow(y - props.definition.cy, 2)); const distance = Math.sqrt(Math.pow(x - props.definition.cx, 2) + Math.pow(y - props.definition.cy, 2));
if (distance < props.definition.radius) { if (distance < props.definition.radius) {
audio.value!.play(); if (audio.value!.paused) {
console.debug(`[AUDIOAREA] Entered audio area "${props.definition.src}", starting playback...`);
audio.value!.play();
}
const volume = (props.definition.radius - distance) / props.definition.radius; const volume = (props.definition.radius - distance) / props.definition.radius;
audio.value!.volume = volume * (props.bbox.z < 1 ? (props.bbox.z * vol_x + vol_b) : 1); audio.value!.volume = volume * (props.bbox.z < 1 ? (props.bbox.z * vol_x + vol_b) : 1);
} else { } else {
audio.value!.pause(); if (!audio.value!.paused) {
console.debug(`[AUDIOAREA] Left audio area "${props.definition.src}", pausing playback...`);
audio.value!.pause();
}
} }
}; };
watch(props.bbox, onBBoxChange, {deep: true}); watch(props.bbox, onBBoxChange, {deep: true});

View file

@ -76,15 +76,20 @@ export default defineComponent({
onMounted(async () => { onMounted(async () => {
const element = root.value as unknown as HTMLDivElement; const element = root.value as unknown as HTMLDivElement;
console.info("[SVG] Initializing.");
// Fetch & load SVG // Fetch & load SVG
console.info(`[SVG] Fetching "${props.url}..."`);
const fetchResult = await fetch(props.url); const fetchResult = await fetch(props.url);
console.debug("[SVG] Fetched, parsing...");
const svgParsed = new DOMParser().parseFromString(await fetchResult.text(), "image/svg+xml") as Document; const svgParsed = new DOMParser().parseFromString(await fetchResult.text(), "image/svg+xml") as Document;
console.debug("[SVG] Parsed.");
const svg = element.appendChild(svgParsed.firstElementChild as Element) as any; const svg = element.appendChild(svgParsed.firstElementChild as Element) as any;
// Set document background // Set document background
const pageColor = svg.getElementById("base")?.attributes.getNamedItem("pagecolor"); const pageColor = svg.getElementById("base")?.attributes.getNamedItem("pagecolor");
if (pageColor) { if (pageColor) {
console.debug(`[SVG] Found pageColor attribute: ${pageColor.value}`);
emit("setBackground", pageColor.value); emit("setBackground", pageColor.value);
} }
@ -97,8 +102,10 @@ export default defineComponent({
zoomDoubleClickSpeed: 1, zoomDoubleClickSpeed: 1,
onDoubleClick: function (e) { onDoubleClick: function (e) {
if (!document.fullscreenElement) { if (!document.fullscreenElement) {
console.debug("[SVG] Fullscreen requested.");
document.body.requestFullscreen(); document.body.requestFullscreen();
} else { } else {
console.debug("[SVG] Fullscreen exited.");
document.exitFullscreen(); document.exitFullscreen();
} }
@ -120,6 +127,7 @@ export default defineComponent({
}); });
function panToElement(target: SVGRectElement, smooth: boolean) { function panToElement(target: SVGRectElement, smooth: boolean) {
console.debug(`[SVG] Panning to element: #${target.id}`);
const transform = pz.getTransform(); const transform = pz.getTransform();
const currentRatio = svg.clientWidth * transform.scale / svg.viewBox.baseVal.width; const currentRatio = svg.clientWidth * transform.scale / svg.viewBox.baseVal.width;
const ratio = svg.clientWidth / svg.viewBox.baseVal.width; const ratio = svg.clientWidth / svg.viewBox.baseVal.width;
@ -151,9 +159,15 @@ export default defineComponent({
} }
} }
panToAnchor.value = (anchor: SVGRectElement) => {
panToElement(anchor, true);
};
// Pan to start element // Pan to start element
const start = processStart(svg); const start = processStart(svg);
if (start) { if (start) {
console.info("[SVG] Found start element.");
panToElement(start, false); panToElement(start, false);
window.addEventListener("keydown", (ev) => { window.addEventListener("keydown", (ev) => {
@ -164,20 +178,24 @@ export default defineComponent({
} }
// Anchors // Anchors
console.debug("[SVG] Processing anchors.");
anchors.value = processAnchors(svg); anchors.value = processAnchors(svg);
panToAnchor.value = (anchor: SVGRectElement) => { console.info(`[SVG] Found ${anchors.value.length} anchors.`);
panToElement(anchor, true);
};
// Audio areas // Audio areas
console.debug("[SVG] Processing audio areas.");
audioAreas.value = processAudio(svg); audioAreas.value = processAudio(svg);
console.info(`[SVG] Found ${audioAreas.value.length} audio areas.`);
// Videoscrolls // Videoscrolls
console.debug("[SVG] Processing video scrolls.");
scrolls.value = await processScrolls(svg); scrolls.value = await processScrolls(svg);
console.info(`[SVG] Found ${scrolls.value.length} video scrolls.`);
// Debug Stats // Debug Stats
let stats: Stats | undefined; let stats: Stats | undefined;
if (process.env.VUE_APP_DEMO) { if (process.env.VUE_APP_DEMO) {
console.info("[SVG] DEMO mode active, turning on stats & dev panel.");
stats = new Stats(); stats = new Stats();
document.body.appendChild(stats.dom); document.body.appendChild(stats.dom);
} else { } else {
@ -268,6 +286,7 @@ function processAnchors(document: XMLDocument): SVGRectElement[] {
if (anchor === null) { if (anchor === null) {
break; break;
} }
console.debug(`[SVG/ANCHORS] Found anchor #${anchor.id}.`);
anchor.classList.add("internal"); anchor.classList.add("internal");
result.push(anchor); result.push(anchor);
i++; i++;
@ -282,13 +301,15 @@ async function processScrolls(svg: XMLDocument): Promise<VideoScrollDef[]> {
Array.from(svg.getElementsByTagName("image")) Array.from(svg.getElementsByTagName("image"))
.filter((el) => Array.from(el.children).some((el) => el.tagName == "desc")) .filter((el) => Array.from(el.children).some((el) => el.tagName == "desc"))
.map(async (el) => { .map(async (el) => {
const descNode = el.children[0]; // to fix const descNode = Array.from(el.children).find((el) => el.tagName == "desc");
const [directionString, filesURL] = descNode.textContent!.split("\n"); console.debug(`[SVG/VIDEOSCROLLS] Found video scroll #${el.id}: ${descNode?.textContent}`);
const [directionString, filesURL] = descNode!.textContent!.split("\n");
if (!Object.values(VideoScrollDirection).includes(directionString as VideoScrollDirection)) { if (!Object.values(VideoScrollDirection).includes(directionString as VideoScrollDirection)) {
throw new Error("Unknown direction string."); throw new Error("Unknown direction string.");
} }
console.debug(`[SVG/VIDEOSCROLLS] Fetching ${filesURL}...`);
const fileFetch = await fetch(`content/${filesURL}`); const fileFetch = await fetch(`content/${filesURL}`);
const preURL = fileFetch.url.replace(/\/files.lst$/, ""); const preURL = fileFetch.url.replace(/\/files.lst$/, "");
const files = (await fileFetch.text()).split("\n").filter(Boolean).map((str) => `${preURL}/${str}`); const files = (await fileFetch.text()).split("\n").filter(Boolean).map((str) => `${preURL}/${str}`);
@ -322,15 +343,14 @@ async function processScrolls(svg: XMLDocument): Promise<VideoScrollDef[]> {
} }
function processAudio(svg: XMLDocument): AudioAreaDef[] { function processAudio(svg: XMLDocument): AudioAreaDef[] {
const ratio = (svg as any).clientWidth / (svg as any).viewBox.baseVal.width;
return Array.from(svg.getElementsByTagName("circle")) return Array.from(svg.getElementsByTagName("circle"))
.filter((el) => Array.from(el.children).some((el) => el.tagName == "desc")) .filter((el) => Array.from(el.children).some((el) => el.tagName == "desc"))
.map((el) => { .map((el) => {
el.classList.add("internal"); const descNode = Array.from(el.children).find((el) => el.tagName == "desc");
console.debug(`[SVG/AUDIOAREAS] Found audio area #${el.id}: ${descNode?.textContent}`);
const audioSrc = descNode!.textContent!.trim();
const descNode = el.children[0]; // to fix el.classList.add("internal");
const audioSrc = descNode.textContent!.trim();
return { return {
cx: el.cx.baseVal.value, cx: el.cx.baseVal.value,

View file

@ -59,12 +59,16 @@ export default defineComponent({
setup(props) { setup(props) {
const root = ref<Element | null>(null); const root = ref<Element | null>(null);
console.debug(`[VIDEOSCROLL] Initializing ${props.definition.files[0]}...`);
console.debug(props.definition);
onMounted(() => { onMounted(() => {
const observer = new IntersectionObserver((entries, observer) => { const observer = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => { entries.forEach((entry) => {
const element = entry.target as HTMLImageElement; const element = entry.target as HTMLImageElement;
if (entry.isIntersecting) { if (entry.isIntersecting) {
if (!element.src) { if (!element.src) {
console.debug(`[VIDEOSCROLL] Intersected, loading ${element.dataset.src}`);
element.src = element.dataset.src!; element.src = element.dataset.src!;
if (element.dataset.direction == "left" || element.dataset.direction == "right") { if (element.dataset.direction == "left" || element.dataset.direction == "right") {
element.style.height = "auto"; element.style.height = "auto";