Skip to content

Commit

Permalink
Cached auto update element, removed old code, cleaned up code, and di…
Browse files Browse the repository at this point in the history
…d some minor code improvements
  • Loading branch information
JohnDog3112 committed May 11, 2024
1 parent d59e580 commit 88ae544
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions doc/src/hexdoc_hexcasting/_templates/hexcasting_render.js.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ let options = {
};

function load_render(name) {
/*if (selected == name) {
return;
}*/

if (name == "animated" && selected != name) {
load_animated();
if (name == "animated") {
if (selected != name) {
cachedPatternImage = null;
load_animated();
}
} else {
render_images(options[name], last_palette, name + "-settings");
}
Expand Down Expand Up @@ -358,37 +358,38 @@ function checkEqual(ob1, ob2) {
}

let autoUpdateInterval = null;
function autoUpdateRenderer(interval) {
let real_interval = interval;
let cachedPatternImage = null;
function autoUpdateRenderer(interval = 500) {
if (autoUpdateInterval != null) {
clearInterval(autoUpdateInterval);
}

if (real_interval == null) {
real_interval = 500;
} else if (real_interval <= 0) {
if (interval <= 0) {
console.log(`Invalid interval for autoUpdateRenderer: ${interval}`);
return;
}

let old_settings = null;
autoUpdateInterval = setInterval(() => {
if (selected == "animated") {
return;
}
let first_pattern = document.querySelector("img.spell-viz");
if (first_pattern == null) return;
if (cachedPatternImage == null) {
cachedPatternImage = document.querySelector("img.spell-viz");
if (cachedPatternImage == null) return;
}

let styles = getStyles(first_pattern);
let styles = getStyles(cachedPatternImage);

let new_settings = options[selected](styles, last_palette);
if (!checkEqual(new_settings,old_settings)) {
console.log("update!");
console.log("updated pattern render from css");

old_settings = new_settings;

load_render(selected);
}

}, real_interval);
}, interval);
}

window.autoUpdateRenderer = autoUpdateRenderer;
Expand All @@ -403,9 +404,6 @@ let palette_options = {

let last_palette = "default";
export function load_palette(name) {
/*if (last_palette == name) {
return;
}*/

if (!palette_options[name]) {
return;
Expand Down

0 comments on commit 88ae544

Please sign in to comment.