From 99dbba64dde9661991358ac275413530d9e17e53 Mon Sep 17 00:00:00 2001 From: zombieFox Date: Wed, 17 Jun 2020 21:37:36 +0100 Subject: [PATCH] [refactor] improve update --- src/js/update.js | 79 +++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/src/js/update.js b/src/js/update.js index 537b042a..33933296 100644 --- a/src/js/update.js +++ b/src/js/update.js @@ -982,12 +982,20 @@ var update = (function() { arrayItem.accent.color[key] = 0; }; }; - arrayItem.accent.rgb = { - r: arrayItem.accent.color.r, - g: arrayItem.accent.color.g, - b: arrayItem.accent.color.b + if (arrayItem.accent.color) { + arrayItem.accent.rgb = { + r: arrayItem.accent.color.r, + g: arrayItem.accent.color.g, + b: arrayItem.accent.color.b + }; + delete arrayItem.accent.color; + } else if (!arrayItem.accent.rgb) { + arrayItem.accent.rgb = { + r: 0, + g: 0, + b: 0 + }; }; - delete arrayItem.accent.color; arrayItem.accent.hsl = { h: 0, s: 0, @@ -1013,26 +1021,35 @@ var update = (function() { } }; arrayItem.image = ""; - arrayItem.visual = { - display: arrayItem.display, - letter: arrayItem.letter, - image: "", - icon: arrayItem.icon + if (!arrayItem.visual) { + arrayItem.visual = { + display: arrayItem.display, + letter: arrayItem.letter, + image: "", + icon: arrayItem.icon + }; + delete arrayItem.display; + delete arrayItem.letter; + delete arrayItem.icon; + if (arrayItem.visual.letter == null) { + arrayItem.visual.letter = ""; + }; }; - delete arrayItem.display; - delete arrayItem.letter; - delete arrayItem.icon; - if (arrayItem.visual.letter == null) { - arrayItem.visual.letter = ""; + if (arrayItem.visual) { + if (arrayItem.visual.icon) { + if (arrayItem.visual.icon.label == null) { + arrayItem.visual.icon.label = ""; + }; + if (arrayItem.visual.icon.name == null) { + arrayItem.visual.icon.name = ""; + }; + if (arrayItem.visual.icon.prefix == null) { + arrayItem.visual.icon.prefix = ""; + }; + }; }; - if (arrayItem.visual.icon.label == null) { - arrayItem.visual.icon.label = ""; - }; - if (arrayItem.visual.icon.name == null) { - arrayItem.visual.icon.name = ""; - }; - if (arrayItem.visual.icon.prefix == null) { - arrayItem.visual.icon.prefix = ""; + if (arrayItem.visual.image == null) { + arrayItem.visual.image = ""; }; }); @@ -1066,10 +1083,18 @@ var update = (function() { b: 0 } }; - data.state.link.item.display.visual = data.state.link.item.display.letcon; - delete data.state.link.item.display.letcon; - data.state.link.item.display.visual.image = { - size: 3 + if (!data.state.link.item.display.visual) { + data.state.link.item.display.visual = data.state.link.item.display.letcon; + }; + if (data.state.link.item.display.letcon) { + delete data.state.link.item.display.letcon; + }; + if (data.state.link.item.display.visual) { + if (!data.state.link.item.display.visual.image) { + data.state.link.item.display.visual.image = { + size: 3 + }; + }; }; if (data.state.link.item.display.order == "letconname") { data.state.link.item.display.order = "visualname";