From b54bbd99947514fa75c01b5feae5623a1181e394 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 11 May 2023 03:50:42 -0500 Subject: [PATCH] Fixed flipped array --- inventory_monitor.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/inventory_monitor.js b/inventory_monitor.js index 853bb2d..701d50d 100644 --- a/inventory_monitor.js +++ b/inventory_monitor.js @@ -16,14 +16,16 @@ function update(){ item=line.split(" ") itemID=item[1] itemAmt=item[0] - itemHQ=item[2] - //console.log(itemID+" x"+itemAmt+" "+(itemHQ?"":"HQ")) + hq=(item[2]!==undefined)?item[2].replace("\r",""):"" + itemHQ=hq==="0"?false:true + //console.log(itemID+" x"+itemAmt+" "+(itemHQ)) if(firstLoad){ - finalData=[{"id":itemID,"amt":itemAmt,"hq":Boolean(itemHQ)},...finalData] + finalData=[...finalData,{"id":Number(itemID),"amt":Number(itemAmt),"hq":itemHQ}] }else - if (finalData[i]!==undefined){ - if (finalData[i].id!==itemID||finalData[i].amt!==itemAmt||finalData[i].hq!==Boolean(itemHQ)){ - finalData[i]={"id":itemID,"amt":itemAmt,"hq":Boolean(itemHQ)} + if (finalData[i]!==undefined&&(Number.isInteger(finalData[i].id)^Number.isInteger(itemID))){ + if (finalData[i].id!=Number(itemID)||finalData[i].amt!==Number(itemAmt)||finalData[i].hq!==Boolean(itemHQ)){ + console.log(JSON.stringify(finalData[i])+" !== "+JSON.stringify({"id":Number(itemID),"amt":Number(itemAmt),"hq":Boolean(itemHQ)})) + finalData[i]={"id":Number(itemID),"amt":Number(itemAmt),"hq":Boolean(itemHQ)} changed=true; } }