-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProductionTimeScreenUpdate.lua
More file actions
1 lines (1 loc) · 4.46 KB
/
ProductionTimeScreenUpdate.lua
File metadata and controls
1 lines (1 loc) · 4.46 KB
1
{"slots":{"0":{"name":"core","type":{"events":[],"methods":[]}},"1":{"name":"databank","type":{"events":[],"methods":[]}},"2":{"name":"screen","type":{"events":[],"methods":[]}},"3":{"name":"screen","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"function FormatTimeString(seconds)\n\tlocal hours = math.floor(seconds/3600)\n\tlocal minutes = math.floor(seconds/60%60+0.5)\n\tlocal seconds = math.floor(seconds%60)\n\tif seconds < 0 or hours < 0 or minutes < 0 then\n\t\treturn \"0s\"\n\tend\n\tif hours > 0 then \n\t\treturn hours .. \"h \" .. minutes .. \"m \"\n\telseif minutes > 0 then\n\t\treturn minutes .. \"m \"\n\tend\nend\n\nLastAmount = {}\nunit.setTimer(\"draw\",1)","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"0"},{"code":"\t\n\tcontent = \"<svg width='100vw' height='100vh' style='position:absolute; top:0; left:0'>\"\n\t-- Let's draw a title bar\n\tlocal titleHeight = 15\n\tcontent = content .. '<rect width=\"100vw\" height=\"' .. titleHeight .. 'vh\" x=\"0\" y=\"0\" style=\"fill:rgb(255,255,255);stroke-width:1;stroke:black;\" />'\n\tcontent = content .. \"<text x='50%' y='\" .. titleHeight/2 + 2 .. \"%' font-size='8vh' fill='black' text-anchor='middle' font-family='Montserrat'>Production Queue</text>\"\n\t-- Prepare some stuff\n\tlocal padding = 2\n\tlocal y = titleHeight + padding*2\n\tlocal yMovement = 6\n\t\n\t-- Column stuff\n\tlocal nameColWidth = 20\n\tlocal nameColX = 10\n\tlocal recipeColWidth = 40\n\tlocal recipeColX = nameColX + nameColWidth + recipeColWidth/2\n\tlocal timeColWidth = 20\n\tlocal timeColX = nameColX + nameColWidth + recipeColWidth + 10\n\t\n\tfor key, databank in pairs(unit) do\n\t\tif type(databank) == \"table\" and type(databank.export) == \"table\" and databank.getStringValue then \n\t\t\tlocal toRemove = {}\n\t\t\tlocal users = json.decode(databank.getStringValue(\"users\"))\n\t\t\tif users == nil then\n\t\t\t\tusers = {}\n\t\t\tend\n\t\t\tfor k,v in pairs(users) do\n\t\t\t\tif v.hide == nil then\n\t\t\t\t\t-- Name\n\t\t\t\t\tlocal fill = \"white\"\n\t\t\t\t\tif v.name == system.getPlayerName(unit.getMasterPlayerId()) then\n\t\t\t\t\t\tfill = \"green\"\n\t\t\t\t\tend\n\t\t\t\t\tcontent = content .. \"<text x='\" .. nameColX .. \"' y='\" .. y .. \"%' font-size='4vh' font-weight='bold' fill='\" .. fill .. \"' text-anchor='left' font-family='Montserrat'>\" .. v.name .. \"</text>\"\n\t\t\t\t\t-- Recipe\n\t\t\t\t\tcontent = content .. \"<text x='\" .. recipeColX .. \"%' y='\" .. y .. \"%' font-size='4vh' font-weight='bold' fill='orange' text-anchor='middle' font-family='Montserrat'>\" .. v.amount * v.outputQuantity .. \" \" .. v.recipe .. \"</text>\"\n\t\t\t\t\t-- Time\n\t\t\t\t\tlocal timeRemaining = v.amount*v.duration\n\t\t\t\t\tlocal fillColor = \"orange\"\n\t\t\t\t\t\n\t\t\t\t\tlocal userStart = databank.getStringValue(v.name .. v.starttime)\n\t\t\t\t\tif userStart ~= nil and userStart ~= \"\" then\n\t\t\t\t\t\ttimeRemaining = v.amount*v.duration+tonumber(userStart) - system.getTime()\n\t\t\t\t\t\tif timeRemaining <= 0 then\n\t\t\t\t\t\t\t-- Remove them from next iteration\n\t\t\t\t\t\t\ttable.insert(toRemove,k)\n\t\t\t\t\t\tend\n\t\t\t\t\t\tfillColor = \"green\"\n\t\t\t\t\tend\n\t\t\t\t\t\n\t\t\t\t\tcontent = content .. \"<text x='\" .. timeColX .. \"%' y='\" .. y .. \"%' font-size='4vh' font-weight='bold' fill='\" .. fillColor.. \"' text-anchor='right' font-family='Montserrat'>\" .. FormatTimeString(timeRemaining) .. \"</text>\"\n\t\t\t\t\t\n\t\t\t\t\ty = y + yMovement\n\t\t\t\tend\n\t\t\tend\n\t\t\tlocal removed = false\n\t\t\tfor k,v in pairs(toRemove) do\n\t\t\t\tdatabank.setStringValue(users[v].name .. users[v].starttime,\"\")\n\t\t\t\tusers[v] = nil\n\t\t\t\tremoved = true\n\t\t\tend\n\t\tend\n\tend\n\t\n\t\n\tif removed then -- Race condition here. Hope for the best. \n\t\tdatabank.setStringValue(\"users\",json.encode(users))\n\tend\n\t\n\tcontent = content .. \"</svg>\"\n\tscreen.setHTML(content)","filter":{"args":[{"value":"draw"}],"signature":"tick(timerId)","slotKey":"-1"},"key":"1"}],"methods":[],"events":[]}