diff options
author | Kristian Lyngstol <kly@kly.no> | 2016-03-12 21:42:55 +0000 |
---|---|---|
committer | Kristian Lyngstol <kly@kly.no> | 2016-03-12 21:42:55 +0000 |
commit | 7f35a9a4593d946f626cea8c56e4568a7a7fe0d7 (patch) | |
tree | 72d11d15ec8737da7881b0e67a9a696acb26c4c3 /web/nms.gathering.org/js/nms-map-handlers.js | |
parent | d38e6ba26931cffd6c09128dfeb7321bc224ede3 (diff) |
NMSjs: Massive rework of map drawing
Still half-way done, but it's looking better.
Confirmed working right now: Comment spotter and disco.
Diffstat (limited to 'web/nms.gathering.org/js/nms-map-handlers.js')
-rw-r--r-- | web/nms.gathering.org/js/nms-map-handlers.js | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js index eaa62fd..ce1d6db 100644 --- a/web/nms.gathering.org/js/nms-map-handlers.js +++ b/web/nms.gathering.org/js/nms-map-handlers.js @@ -2,8 +2,7 @@ * Map handlers/updaters for NMS. * * These are functions used to determine how the map should look in NMS. - * They represent vastly different information, but in a uniform way. I - * suppose this is the c++-type of object orientation... + * They represent vastly different information, but in a uniform way. * * The idea is that these updaters only parse information that's fetched by * NMS - they do not request additional information. E.g., ping data is @@ -11,6 +10,10 @@ * displayed. This might seem redundant, but it means any handler can * utilize information from any aspect of NMS, and thus opens NMS up to the * world of intelligent maps base don multiple data sources. + * + * Warning: This paradigm will change. Handlers will be expected to + * register their own callbacks for nmsData. Work in progress. + * */ /* @@ -257,7 +260,6 @@ function tempInit() function pingUpdater() { if (!nms.ping_data || !nms.ping_data["switches"]) { - resetColors(); return; } for (var sw in nms.switches_now["switches"]) { @@ -291,35 +293,36 @@ function commentUpdater() { var realnow = Date.now(); var now = Math.floor(realnow / 1000); - for (var sw in nms.switches_now["switches"]) { + if (nmsData.comments == undefined || nmsData.comments.comments == undefined) { + return + } + for (var sw in nmsData.comments.comments) { var c = "white"; - var s = nms.switches_now["switches"][sw]; - if (s["comments"] && s["comments"].length > 0) { - var then = 0; - var active = 0; - var persist = 0; - c = "yellow"; - for (var v in s["comments"]) { - var then_test = parseInt(s["comments"][v]["time"]); - if (then_test > then && s["comments"][v]["state"] != "inactive") - then = then_test; - if (s["comments"][v]["state"] == "active") { - active++; - } - if (s["comments"][v]["state"] == "persist") - persist++; - } - if (then > (now - (60*15))) { - c = red; - } else if (active > 0) { - c = orange; - } else if (persist > 0) { - c = blue; - } else { - c = green; + var s = nmsData.comments.comments[sw]; + var then = 0; + var active = 0; + var persist = 0; + c = "yellow"; + for (var v in s["comments"]) { + var then_test = parseInt(s["comments"][v]["time"]); + if (then_test > then && s["comments"][v]["state"] != "inactive") + then = then_test; + if (s["comments"][v]["state"] == "active") { + active++; } + if (s["comments"][v]["state"] == "persist") + persist++; } - setSwitchColor(sw, c); + if (then > (now - (60*15))) { + c = red; + } else if (active > 0) { + c = orange; + } else if (persist > 0) { + c = blue; + } else { + c = green; + } + nmsMap.setSwitchColor(sw, c); } } @@ -337,11 +340,15 @@ function commentInit() */ function randomizeColors() { - for (var i in nms.switches_now.linknets) { +/* for (var i in nms.switches_now.linknets) { setLinknetColors(i, getRandomColor(), getRandomColor()); } - for (var sw in nms.switches_now.switches) { - setSwitchColor(sw, getRandomColor()); +*/ + if (nmsData.switches == undefined || nmsData.switches.switches == undefined) { + return; + } + for (var sw in nmsData.switches.switches) { + nmsMap.setSwitchColor(sw, getRandomColor()); } } |