-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.3.0 - vertical mode & item icon & new data streaming system for sc…
…reen
- Loading branch information
1 parent
747d8ca
commit eaa027b
Showing
3 changed files
with
89 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"events":[],"handlers":[{"code":"--[[\n DU-Nested-Coroutines by Jericho\n Permit to easier avoid CPU Load Errors\n Source available here: https://github.com/Jericho1060/du-nested-coroutines\n]]--\n\nif coroutine.status(MainCoroutine) == \"dead\" then\n MainCoroutine = coroutine.create(runCoroutines)\nend\nif coroutine.status(MainCoroutine) == \"suspended\" then\n assert(coroutine.resume(MainCoroutine))\nend","filter":{"args":[],"signature":"onUpdate()","slotKey":"-4"},"key":"2"},{"code":"--[[\n\tLUA PARAMETERS\n]]\nfontSize = 20 --export: the size of the text for all the screen\nmaxVolumeForHub = 0--export: the max volume from a hub (can't get it from the lua) if 0, the content volume will be displayed on the screen\n--[[\n\tINIT\n]]\n\nlocal version = '1.1.0'\n\nsystem.print(\"------------------------------------\")\nsystem.print(\"DU-Container-Monitoring version \" .. version)\nsystem.print(\"------------------------------------\")\n\nlocal renderScript = [[\nlocal json = require('dkjson')\nlocal data = json.decode(getInput()) or {}\n\nlocal rx,ry = getResolution()\n\nlocal back=createLayer()\nlocal front=createLayer()\n\nfont_size = ]] .. fontSize .. [[\nlocal small=loadFont('Play',14)\nlocal smallBold=loadFont('Play-Bold',18)\nlocal itemName=loadFont('Play-Bold',font_size)\nlocal big=loadFont('Play',38)\n\nsetBackgroundColor( 15/255,24/255,29/255)\n\nsetDefaultStrokeColor( back,Shape_Line,0,0,0,0.5)\nsetDefaultShadow( back,Shape_Line,6,0,0,0,0.5)\n\nsetDefaultFillColor( front,Shape_BoxRounded,249/255,212/255,123/255,1)\nsetDefaultFillColor( front,Shape_Text,0,0,0,1)\nsetDefaultFillColor( front,Shape_Box,0.075,0.125,0.156,1)\nsetDefaultFillColor( front,Shape_Text,0.710,0.878,0.941,1)\n\nfunction format_number(a)local b=a;while true do b,k=string.gsub(b,\"^(-?%d+)(%d%d%d)\",'%1 %2')if k==0 then break end end;return b end\n\nfunction round(a,b)if b then return utils.round(a/b)*b end;return a>=0 and math.floor(a+0.5)or math.ceil(a-0.5)end\n\nfunction getRGBGradient(a,b,c,d,e,f,g,h,i,j)a=-1*math.cos(a*math.pi)/2+0.5;local k=0;local l=0;local m=0;if a>=.5 then a=(a-0.5)*2;k=e-a*(e-h)l=f-a*(f-i)m=g-a*(g-j)else a=a*2;k=b-a*(b-e)l=c-a*(c-f)m=d-a*(d-g)end;return k,l,m end\n\nfunction renderHeader(title)\n local h_factor = 12\n local h = 35\n if subtitle ~= nil and subtitle ~= \"\" and subtitle ~= \"-\" then\n h = 50\n end\n addLine( back,0,h+12,rx,h+12)\n addBox(front,0,12,rx,h)\n addText(front,small,\"Next query possible in \" .. round(data[3]) .. ' seconds',rx-250,35)\n addText(front,smallBold,title,44,35)\nend\n\nlocal storageBar = createLayer()\nsetDefaultFillColor(storageBar,Shape_Text,110/255,166/255,181/255,1)\nsetDefaultFillColor(storageBar,Shape_Box,0.075,0.125,0.156,1)\nsetDefaultFillColor(storageBar,Shape_Line,1,1,1,1)\n\nlocal colorLayer = createLayer()\nlocal percent_fill = 0\nlocal r = 110/255\nlocal g = 166/255\nlocal b = 181/255\nif data[1] > 0 then\n percent_fill = data[2]*100/data[1]\n if percent_fill > 100 then percent_fill = 100 end\n r,g,b = getRGBGradient(percent_fill/100,177/255,42/255,42/255,249/255,212/255,123/255,34/255,177/255,76/255)\nend\nsetDefaultFillColor(colorLayer,Shape_Box,r,g,b,1)\nsetDefaultFillColor(colorLayer,Shape_Text,r,g,b,1)\nsetDefaultTextAlign(colorLayer, AlignH_Center, AlignV_Middle)\n\nfunction renderProgressBar(percent)\n if data[1] > 0 then\n addText(colorLayer, itemName, format_number(round(percent*100)/100) ..\"%\", rx/2, 90)\n local w=(rx-90)*(percent)/100\n local x=44\n local y=55\n local h=25\n addBox(storageBar,x,y,rx-88,h)\n addBox(colorLayer,x+1,y+1,w,h-2)\n else\n addText(colorLayer, itemName, format_number(round(data[2]*100)/100) ..\" L\", rx/2, 80)\n end\nend\n\nfunction renderResistanceBar(title, quantity, x, y, w, h, withTitle)\n\n local quantity_x_pos = font_size * 6.7\n local percent_x_pos = font_size * 2\n\n addBox(storageBar,x,y,w,h)\n\n if withTitle then\n addText(storageBar, small, \"ITEMS\", x, y-5)\n setNextTextAlign(storageBar, AlignH_Right, AlignV_Middle)\n addText(storageBar, small, \"QUANTITY\", x+w-15, y-5)\n end\n\n local pos_y = y+(h/2)-2\n\n setNextTextAlign(storageBar, AlignH_Left, AlignV_Middle)\n addText(storageBar, itemName, title, x+10, pos_y)\n \n setNextTextAlign(storageBar, AlignH_Right, AlignV_Middle)\n addText(storageBar, itemName, format_number(quantity), w+30, pos_y)\nend\n\nrenderHeader('Container Monitoring v]] .. version .. [[')\n\nstart_h = 100\n\n\nlocal h = font_size + font_size / 2\nfor i,container in ipairs(data[4]) do\n renderResistanceBar(container[2], container[3], 44, start_h, rx-88, h, i==1)\n start_h = start_h+h+5\nend\nrenderProgressBar(percent_fill)\nrequestAnimationFrame(500)\n]]\n\nscreens = {}\nfor slot_name, slot in pairs(unit) do\n if type(slot) == \"table\"\n and type(slot.export) == \"table\"\n and slot.getClass\n then\n if slot.getClass():lower() == 'screenunit' then\n slot.slotname = slot_name\n table.insert(screens,slot)\n slot.setRenderScript(renderScript)\n end\n end\nend\nif #screens == 0 then\n system.print(\"No Screen Detected\")\n unit.exit()\nelse\n table.sort(screens, function(a,b) return a.slotname < b.slotname end)\n local plural = \"\"\n if #screens > 1 then plural = \"s\" end\n system.print(#screens .. \" screen\" .. plural .. \" Connected\")\nend\nif container == nil then\n system.print('No Container or Hub dectected')\n unit.exit()\nelse\n system.print('Storage connected')\nend\n\nscreen_data={0,0,0,{}}\nrequest_time = 0\n\n--[[\n DU-Nested-Coroutines by Jericho\n Permit to easier avoid CPU Load Errors\n Source available here: https://github.com/Jericho1060/du-nested-coroutines\n]]--\n\ncoroutinesTable = {}\n--all functions here will become a coroutine\nMyCoroutines = {\n function()\n request_time = math.ceil(container.updateContent())\n local max_vol = container.getMaxVolume()\n if max_vol == 0 then\n max_vol = maxVolumeForHub\n end\n screen_data[1] = max_vol\n screen_data[2] = container.getItemsVolume()\n screen_data[3] = request_time\n for _,s in pairs(screens) do\n s.setScriptInput(json.encode(screen_data))\n end\n end\n}\n\nfunction initCoroutines()\n for _,f in pairs(MyCoroutines) do\n local co = coroutine.create(f)\n table.insert(coroutinesTable, co)\n end\nend\n\ninitCoroutines()\n\nrunCoroutines = function()\n for i,co in ipairs(coroutinesTable) do\n if coroutine.status(co) == \"dead\" then\n coroutinesTable[i] = coroutine.create(MyCoroutines[i])\n end\n if coroutine.status(co) == \"suspended\" then\n assert(coroutine.resume(co))\n end\n end\nend\n\nMainCoroutine = coroutine.create(runCoroutines)","filter":{"args":[],"signature":"onStart()","slotKey":"-1"},"key":"1"},{"code":"local list = container.getContent()\nscreen_data[4] = {}\nfor k, v in ipairs(list) do\n local quantity = math.floor(v.quantity*100)/100\n local item = system.getItem(v.id)\n local item_data = {\n v.id,\n item.displayNameWithSize,\n quantity\n }\n table.insert(screen_data[4], item_data)\nend","filter":{"args":[],"signature":"onContentUpdate()","slotKey":"0"},"key":"0"}],"methods":[],"slots":{"0":{"name":"container","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","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":[]}},"-5":{"name":"library","type":{"events":[],"methods":[]}},"-4":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"player","type":{"events":[],"methods":[]}},"-2":{"name":"construct","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}}}} | ||
{"events":[],"handlers":[{"code":"--[[\n DU-Nested-Coroutines by Jericho\n Permit to easier avoid CPU Load Errors\n Source available here: https://github.com/Jericho1060/du-nested-coroutines\n]]--\n\nif coroutine.status(MainCoroutine) == \"dead\" then\n MainCoroutine = coroutine.create(runCoroutines)\nend\nif coroutine.status(MainCoroutine) == \"suspended\" then\n assert(coroutine.resume(MainCoroutine))\nend","filter":{"args":[],"signature":"onUpdate()","slotKey":"-4"},"key":"2"},{"code":"--[[\n\tLUA PARAMETERS\n]]\nfontSize = 20 --export: the size of the text for all the screen\nmaxVolumeForHub = 0 --export: the max volume from a hub (can't get it from the lua) if 0, the content volume will be displayed on the screen\n--vertical mode code based on a suggestion by Merl\nverticalMode = false --export: rotate the screen 90deg (bottom on right)\n--[[\n\tINIT\n]]\n\nlocal version = '1.3.0'\n\nsystem.print(\"------------------------------------\")\nsystem.print(\"DU-Container-Monitoring version \" .. version)\nsystem.print(\"------------------------------------\")\n\nlocal renderScript = [[\nlocal json = require('dkjson')\nlocal data = json.decode(getInput()) or {}\nlocal vmode = ]] .. tostring(verticalMode) .. [[\n\nif items == nil or data[1] then items = {} end\nlocal images = {}\n\nif data[5] ~= nil then\n items[data[5][1] ] = data[5]\n setOutput(data[5][1])\n data[5] = nil\nend\n\nfor _,item in ipairs(items) do\n if images[item[2] ] == nil then\n images[item[2] ] = loadImage(item[5])\n end\nend\n\nlocal rx,ry\nif vmode then\n\try,rx = getResolution()\nelse\n\trx,ry = getResolution()\nend\n\nlocal back=createLayer()\nlocal front=createLayer()\n\nfont_size = ]] .. fontSize .. [[\nlocal small=loadFont('Play',14)\nlocal smallBold=loadFont('Play-Bold',18)\nlocal itemName=loadFont('Play-Bold',font_size)\nlocal big=loadFont('Play',38)\n\nsetBackgroundColor( 15/255,24/255,29/255)\n\nsetDefaultStrokeColor( back,Shape_Line,0,0,0,0.5)\nsetDefaultShadow( back,Shape_Line,6,0,0,0,0.5)\n\nsetDefaultFillColor( front,Shape_BoxRounded,249/255,212/255,123/255,1)\nsetDefaultFillColor( front,Shape_Text,0,0,0,1)\nsetDefaultFillColor( front,Shape_Box,0.075,0.125,0.156,1)\nsetDefaultFillColor( front,Shape_Text,0.710,0.878,0.941,1)\n\nfunction format_number(a)local b=a;while true do b,k=string.gsub(b,\"^(-?%d+)(%d%d%d)\",'%1 %2')if k==0 then break end end;return b end\n\nfunction round(a,b)if b then return utils.round(a/b)*b end;return a>=0 and math.floor(a+0.5)or math.ceil(a-0.5)end\n\nfunction getRGBGradient(a,b,c,d,e,f,g,h,i,j)a=-1*math.cos(a*math.pi)/2+0.5;local k=0;local l=0;local m=0;if a>=.5 then a=(a-0.5)*2;k=e-a*(e-h)l=f-a*(f-i)m=g-a*(g-j)else a=a*2;k=b-a*(b-e)l=c-a*(c-f)m=d-a*(d-g)end;return k,l,m end\n\nfunction renderHeader(title)\n local h_factor = 12\n local h = 35\n if subtitle ~= nil and subtitle ~= \"\" and subtitle ~= \"-\" then\n h = 50\n end\n addLine( back,0,h+12,rx,h+12)\n addBox(front,0,12,rx,h)\n addText(front,small,\"Next query possible in \" .. round(data[4]) .. ' seconds',rx-250,35)\n addText(front,smallBold,title,44,35)\nend\n\nlocal storageBar = createLayer()\nsetDefaultFillColor(storageBar,Shape_Text,110/255,166/255,181/255,1)\nsetDefaultFillColor(storageBar,Shape_Box,0.075,0.125,0.156,1)\nsetDefaultFillColor(storageBar,Shape_Line,1,1,1,1)\n\nlocal colorLayer = createLayer()\nlocal imagesLayer = createLayer()\nif vmode then\n local from_top = 10\n setLayerTranslation(back, ry-from_top,0)\n setLayerRotation(back, math.rad(90))\n setLayerTranslation(front, ry-from_top,0)\n setLayerRotation(front, math.rad(90))\n setLayerTranslation(storageBar, ry-from_top,0)\n setLayerRotation(storageBar, math.rad(90))\n setLayerTranslation(colorLayer, ry-from_top,0)\n setLayerRotation(colorLayer, math.rad(90))\n setLayerTranslation(imagesLayer, ry-from_top,0)\n setLayerRotation(imagesLayer, math.rad(90))\nend\nlocal percent_fill = 0\nlocal r = 110/255\nlocal g = 166/255\nlocal b = 181/255\nif data[2] > 0 then\n percent_fill = data[3]*100/data[2]\n if percent_fill > 100 then percent_fill = 100 end\n r,g,b = getRGBGradient(percent_fill/100,177/255,42/255,42/255,249/255,212/255,123/255,34/255,177/255,76/255)\nend\nsetDefaultFillColor(colorLayer,Shape_Box,r,g,b,1)\nsetDefaultFillColor(colorLayer,Shape_Text,r,g,b,1)\nsetDefaultTextAlign(colorLayer, AlignH_Center, AlignV_Middle)\n\nfunction renderProgressBar(percent)\n if data[2] > 0 then\n addText(colorLayer, itemName, format_number(round(percent*100)/100) ..\"%\", rx/2, 90)\n local w=(rx-90)*(percent)/100\n local x=44\n local y=55\n local h=25\n addBox(storageBar,x,y,rx-88,h)\n addBox(colorLayer,x+1,y+1,w,h-2)\n else\n addText(colorLayer, itemName, format_number(round(data[3]*100)/100) ..\" L\", rx/2, 80)\n end\nend\n\nfunction renderResistanceBar(item_id, title, quantity, x, y, w, h, withTitle)\n\n local quantity_x_pos = font_size * 6.7\n local percent_x_pos = font_size * 2\n\n addBox(storageBar,x,y,w,h)\n\n if withTitle then\n addText(storageBar, small, \"ITEMS\", x, y-5)\n setNextTextAlign(storageBar, AlignH_Right, AlignV_Bottom)\n addText(storageBar, small, \"QUANTITY\", x+w-15, y-5)\n end\n if item_id and tonumber(item_id) > 0 and images[item_id] then\n addImage(imagesLayer, images[item_id], x+10, y+font_size*.1, font_size*1.3, font_size*1.2)\n end\n\n local pos_y = y+(h/2)-2\n\n setNextTextAlign(storageBar, AlignH_Left, AlignV_Middle)\n addText(storageBar, itemName, title, x+20+font_size, pos_y)\n \n setNextTextAlign(storageBar, AlignH_Right, AlignV_Middle)\n addText(storageBar, itemName, format_number(quantity), w+30, pos_y)\nend\n\nrenderHeader('Container Monitoring v]] .. version .. [[')\n\nstart_h = 100\n\n\nlocal h = font_size + font_size / 2\nfor i,item in ipairs(items) do\n if i <= #items then\n renderResistanceBar(item[2], item[3], item[4], 44, start_h, rx-88, h, i==1)\n end\n start_h = start_h+h+5\nend\n\nrenderProgressBar(percent_fill)\nrequestAnimationFrame(1)\n]]\n\nscreens = {}\ndatabank = nil\nfor slot_name, slot in pairs(unit) do\n if type(slot) == \"table\"\n and type(slot.export) == \"table\"\n and slot.getClass\n then\n if slot.getClass():lower() == 'screenunit' then\n slot.slotname = slot_name\n table.insert(screens,slot)\n slot.setRenderScript(renderScript)\n elseif slot.getClass():lower() == 'databankunit' then\n databank = slot\n end\n end\nend\nif #screens == 0 then\n system.print(\"No Screen Detected\")\n unit.exit()\nelse\n table.sort(screens, function(a,b) return a.slotname < b.slotname end)\n local plural = \"\"\n if #screens > 1 then plural = \"s\" end\n system.print(#screens .. \" screen\" .. plural .. \" Connected\")\nend\nif container == nil then\n system.print('No Container or Hub dectected')\n unit.exit()\nelse\n system.print('Storage connected')\nend\n\nscreen_data={0,0,0,{}}\nrequest_time = 0\nitems = {}\nupdate_screen = false\n\n--[[\n DU-Nested-Coroutines by Jericho\n Permit to easier avoid CPU Load Errors\n Source available here: https://github.com/Jericho1060/du-nested-coroutines\n]]--\n\ncoroutinesTable = {}\n--all functions here will become a coroutine\nMyCoroutines = {\n function()\n request_time = math.ceil(container.updateContent())\n local max_vol = container.getMaxVolume()\n if max_vol == 0 then\n max_vol = maxVolumeForHub\n end\n local screen_data = {update_screen, max_vol, container.getItemsVolume(), request_time, nil}\n if update_screen then\n for i,item in ipairs(items) do\n screen_data[5] = {\n i,\n item[1],\n item[2],\n item[3],\n item[4]\n }\n for _,s in pairs(screens) do\n s.setScriptInput(json.encode(screen_data))\n while tonumber(s.getScriptOutput()) ~= i do\n coroutine.yield(coroutinesTable[1])\n end\n end\n update_screen = false\n screen_data[1] = false\n end\n else\n for _,s in pairs(screens) do\n s.setScriptInput(json.encode(screen_data))\n end\n end\n end,\n}\n\nfunction initCoroutines()\n for _,f in pairs(MyCoroutines) do\n local co = coroutine.create(f)\n table.insert(coroutinesTable, co)\n end\nend\n\ninitCoroutines()\n\nrunCoroutines = function()\n for i,co in ipairs(coroutinesTable) do\n if coroutine.status(co) == \"dead\" then\n coroutinesTable[i] = coroutine.create(MyCoroutines[i])\n end\n if coroutine.status(co) == \"suspended\" then\n assert(coroutine.resume(co))\n end\n end\nend\n\nMainCoroutine = coroutine.create(runCoroutines)","filter":{"args":[],"signature":"onStart()","slotKey":"-1"},"key":"1"},{"code":"local list = container.getContent()\nscreen_data[4] = {}\nitems = {}\nfor _,v in ipairs(list) do\n local quantity = math.floor(v.quantity*100)/100\n local item = system.getItem(v.id)\n local item_data = {\n v.id,\n item.displayNameWithSize,\n quantity,\n item.iconPath\n }\n table.insert(items, item_data)\nend\nupdate_screen = true","filter":{"args":[],"signature":"onContentUpdate()","slotKey":"0"},"key":"0"}],"methods":[],"slots":{"0":{"name":"container","type":{"events":[],"methods":[]}},"1":{"name":"slot2","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","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":[]}},"-5":{"name":"library","type":{"events":[],"methods":[]}},"-4":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"player","type":{"events":[],"methods":[]}},"-2":{"name":"construct","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}}}} |
Oops, something went wrong.