diff options
author | Ninjune x <enderknight537@gmail.com> | 2022-11-29 21:19:03 -0600 |
---|---|---|
committer | Ninjune x <enderknight537@gmail.com> | 2022-11-29 21:19:03 -0600 |
commit | ad055ba90a3055db32f04ff5163ff4e1c85dfdfa (patch) | |
tree | aee8962d031dffddd27fa702262a0ef7c66c08ce /render/downtimeGui.js | |
parent | 00f4ecbc69216d4aee44bcdac92955c4eb774298 (diff) | |
download | coleweight-ad055ba90a3055db32f04ff5163ff4e1c85dfdfa.tar.gz coleweight-ad055ba90a3055db32f04ff5163ff4e1c85dfdfa.tar.bz2 coleweight-ad055ba90a3055db32f04ff5163ff4e1c85dfdfa.zip |
Diffstat (limited to 'render/downtimeGui.js')
-rw-r--r-- | render/downtimeGui.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/render/downtimeGui.js b/render/downtimeGui.js new file mode 100644 index 0000000..538c590 --- /dev/null +++ b/render/downtimeGui.js @@ -0,0 +1,85 @@ +import settings from "../settings" +import constants from "../util/constants" +import { textGui } from "../util/helperFunctions" + +const downtimeMoveGui = new Gui() +const downtimeGui = new textGui() +let oldFuel = 0, + timeAtLastFuel = 0, + overallDowntime = 0, + trackingDowntime = false, + downtime = 0, + downtimeCount = 0, + uptime = 0 + + +export function openDowntimeGui() +{ + downtimeMoveGui.open() +} + + +register("dragged", (dx, dy, x, y) => { + if (!downtimeMoveGui.isOpen()) return + constants.downtimedata.x = x + constants.downtimedata.y = y + constants.downtimedata.save() +}) + +register('actionbar', (xp) => { + if(!settings.downtimeTracker) return + if(Player.getHeldItem() == null) return + let heldItem = Player.getHeldItem().getNBT().toObject()["tag"]["ExtraAttributes"], + newFuel = parseInt(heldItem["drill_fuel"]) // credit to DocilElm because I'm lazy. + + if(!newFuel) return + else if(oldFuel == 0) oldFuel = newFuel + else if(oldFuel !== newFuel) + { + if(timeAtLastFuel == 0) + { + timeAtLastFuel = Date.now() + return + } + downtime = Date.now() - timeAtLastFuel + overallDowntime += downtime + downtimeCount += 1 + timeAtLastFuel = Date.now() + trackingDowntime = true + oldFuel = newFuel + } +}).setCriteria('${*}+${xp} Mining ${*}') + + +register("renderOverlay", () => { + if (downtimeMoveGui.isOpen()) + { + let txt = "Drag to move." + Renderer.drawStringWithShadow(txt, Renderer.screen.getWidth()/2 - Renderer.getStringWidth(txt)/2, Renderer.screen.getHeight()/2) + downtimeGui.guiObject = {leftValues: ["Downtime", "Overall Downtime", "Average Downtime", "Uptime"], rightValues: [0, 0, 0, 0]} + downtimeGui.x = constants.downtimedata.x + downtimeGui.y = constants.downtimedata.y + downtimeGui.renderGui() + return + } + if (downtimeCount == 0 || !trackingDowntime || !settings.downtimeTracker) return + let avgDowntime = Math.ceil((overallDowntime/downtimeCount)*100) / 100 + downtimeGui.guiObject = {leftValues: ["Downtime", "Overall Downtime", "Average Downtime", "Uptime"], rightValues: [downtime, overallDowntime, avgDowntime, uptime]} + downtimeGui.x = constants.downtimedata.x + downtimeGui.y = constants.downtimedata.y + downtimeGui.renderGui() +}) + + +register("step", () => { + if((Date.now()-timeAtLastFuel)/1000 >= 60) + { + uptime = 0 + oldFuel = 0 + overallDowntime = 0 + timeAtLastFuel = 0 + trackingDowntime = false + } // over 60 seconds then stop making gui + else if(trackingDowntime) + uptime += 1 +}).setFps(1)
\ No newline at end of file |