-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpb_screen.lua.config
More file actions
1 lines (1 loc) · 10.7 KB
/
pb_screen.lua.config
File metadata and controls
1 lines (1 loc) · 10.7 KB
1
{"slots":{"0":{"name":"slot1","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":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-3":{"name":"player","type":{"events":[],"methods":[]}},"-2":{"name":"construct","type":{"events":[],"methods":[]}},"-4":{"name":"system","type":{"events":[],"methods":[]}},"-5":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"unit.hideWidget()\n\nfunctions = {}\nfunctions.iterate = function()\n iterations = 0\n elementsIdList = core.getElementIdList()\n sorted = {}\n\n for index,id in ipairs(elementsIdList) do\n local class = core.getElementClassById(id):sub(0,8):lower()\n local name = getName(core.getElementItemIdById(id), true)\n if class == \"industry\" then\n info = core.getElementIndustryInfoById(id)\n local outputs = info.currentProducts\n if outputs and outputs[1] and outputs[1].id then\n local itemId = outputs[1].id\n local current = 0 \n local maintain = 0\n local itemname = getName(itemId, false)\n local state = info.state\n system.print(state .. \" - \" .. itemname)\n\n if false and state ~= 2 and (manager_items[itemId] == nil and manager_items[\"\" .. itemID] == nil) and (linecook_items[itemId] == nil and linecook_items[\"\" .. itemId] == nil) then\n -- this machine is doing nothing that we care about, so ignore it\n else\n if info.currentProductAmount > 0 then\n current = mceil(info.currentProductAmount)\n if current > 99999 then\n current = mfloor(current / 16777216) \n end\n end\n if info.maintainProductAmount > 0 then\n maintain = mceil(info.maintainProductAmount)\n end\n\n\n\n if state == 1 then state = \"`I\" \n elseif state == 2 then state = \"`R\" \n elseif state == 3 then state = \"`W\" \n elseif state == 4 or state == 5 then state = \"`J\" \n elseif state == 6 then state = \"`P\" \n elseif state == 7 then state = \"!!\" \n else state = \"?UNKNOWN?\" end\n\n table.insert(sorted, \n getLine(id) \n .. \",\" .. name\n .. \",\" .. state\n .. \",\" .. current \n .. \",\" .. maintain \n .. \",\" .. itemname \n )\n end\n end\n end\n\n iterations = iterations + 1\n if iterations >= 50 then\n iterations = 0\n -- coroutine.yield(functions.iterate)\n end\n end\n table.sort(sorted)\n output = \"\"\n total = 0\n\n for i,line in pairs(sorted) do\n local len = string.len(line) + 1\n if total + len <= 1024 then\n output = output .. line .. \"\\n\"\n total = total + len\n end\n end\n\n if output == \"\" then output = \" ... pending ... \" end\n screen.activate()\n screen.setScriptInput(output)\n system.print(\"output set\")\nend\n\nlines = {}\nfunction getLine(id)\n if lines[id] == nil or lines[id] == \"\" then\n lines[id] = databank.getStringValue(\"slot\" .. id)\n lines[id] = lines[id]:gsub(\"linecook\", \"||\")\n end\n return lines[id]\nend\n\nfunction ping()\n databank.setIntValue(pingkey, mfloor(system.getArkTime()))\nend\n\npingkey = \"ping:\" .. unit.getName()\nunit.setTimer(\"ping\", 10)\n\nscreen.setScriptInput(\" ... pending ... \")\nscreen.activate()\n\nmanager_items = deserialize(databank.getStringValue(\"chef\"))\nlinecook_items = deserialize(databank.getStringValue(\"linecook\"))\n\n-- do not change the below\nnestco={}function nestco:new(a)local b={}setmetatable(b,self)self.__index=self;b.functions=a or{}b.coroutines={}function b.update()return b:_update()end;function b.init()return b:_init()end;function b.run()return b:_run()end;function b.update()return b:_update()end;b.init()b.main=coroutine.create(b.run)return b end;function nestco:_init()for c,d in pairs(self.functions)do self.coroutines[c]=coroutine.create(d)end end;function nestco:_run()for c,e in pairs(self.coroutines)do local f=coroutine.status(e)if f==\"dead\"then self.coroutines[c]=coroutine.create(self.functions[c])elseif f==\"suspended\"then assert(coroutine.resume(e))end end end;function nestco:_update()local f=coroutine.status(self.main)if f==\"dead\"then self.main=coroutine.create(self.run)elseif f==\"suspended\"then assert(coroutine.resume(self.main))end end\nNestCo = nestco:new(functions)\nunit.setTimer(\"update\", 1)\n-- do not chang the above\n\n","filter":{"args":[],"signature":"onStart()","slotKey":"-1"},"key":"0"},{"code":"NestCo.update()","filter":{"args":[{"value":"update"}],"signature":"onTimer(tag)","slotKey":"-1"},"key":"1"},{"code":"screen.deactivate()","filter":{"args":[],"signature":"onStop()","slotKey":"-1"},"key":"2"},{"code":"ping()","filter":{"args":[{"value":"ping"}],"signature":"onTimer(tag)","slotKey":"-1"},"key":"3"},{"code":"mceil = math.ceil\nmfloor = math.floor\n\ncore = nil\ndatabank = nil\nscreen = nil\nindustries = {}\nlights = {}\n\nfor slot_name, slot in pairs(unit) do\n if type(slot) == \"table\" and type(slot.export) == \"table\" and slot.getClass then\n slotClass = slot.getClass():lower()\n if slotClass:sub(0,8) == \"coreunit\" then\n core = slot\n -- system.print(\"core found\")\n elseif slotClass == \"databankunit\" then\n databank = slot\n -- system.print(\"databank found\")\n elseif slotClass:sub(0,8) == \"industry\" then\n slotId = slot.getLocalId()\n industry = {\n id=slotId,\n slot=slot\n }\n table.insert(industries, industry)\n elseif slotClass == \"lightunit\" then\n system.print(slotClass .. \" \" .. slot.getName())\n lights[slot.getName()] = slot\n elseif slotClass == \"screenunit\" then\n screen = slot\n slot.activate()\n -- system.print(\"screen found\")\n elseif slotClass == \"manualswitchunit\" then\n local name = slot.getName()\n buttons[name] = slot\n\n button_names[button_count] = name\n button_count = button_count + 1\n\n slot.deactivate()\n end\n end\nend\n\nnames = {}\nfunction getName(id, isIndustry) \n if id == nil then return \"nil Id\" end\n if names[id] == nil then\n name = system.getItem(id).locDisplayNameWithSize\n name = name:gsub(\" xs$\", \" XS\")\n name = name:gsub(\" s$\", \" S\")\n name = name:gsub(\" m$\", \" M\")\n name = name:gsub(\" l$\", \" L\")\n name = name:gsub(\" xl$\", \" XL\")\n name = name:gsub(\" product$\", \" Product\")\n name = name:gsub(\" industry \", \" I \")\n name = name:gsub(\" Industry \", \" I \")\n \n if isIndustry then\n name = name:gsub(\"^Basic \", \"\")\n name = name:gsub(\"^Uncommon \", \"\")\n name = name:gsub(\"^Advanced \", \"\")\n name = name:gsub(\" M$\", \"\")\n name = name:gsub(\" I$\", \"\")\n else\n --[[name = name:gsub(\"^Basic \", \"B. \")\n name = name:gsub(\"^Uncommon \", \"U. \")\n name = name:gsub(\"^Advanced \", \"A. \")]]\n end\n\n names[id] = name\n end\n return names[id]\nend\n","filter":{"args":[],"signature":"onStart()","slotKey":"-5"},"key":"4"},{"code":"local concat = table.concat\nlocal sFormat=string.format\n\nlocal function internalSerialize(table, tC, t)\n t[tC] = \"{\"\n tC = tC + 1\n if #table == 0 then\n local hasValue = false\n for key, value in pairs(table) do\n hasValue = true\n local keyType = type(key)\n if keyType == \"string\" then\n t[tC] = sFormat(\"[%q]=\", key)\n elseif keyType == \"number\" then\n t[tC] = \"[\" .. key .. \"]=\"\n elseif keyType == \"boolean\" then\n t[tC] = \"[\" .. tostring(key) .. \"]=\"\n else\n t[tC] = \"notsupported=\"\n end\n tC = tC + 1\n\n local check = type(value)\n if check == \"table\" then\n tC = internalSerialize(value, tC, t)\n elseif check == \"string\" then\n t[tC] = sFormat(\"%q\", value)\n elseif check == \"number\" then\n t[tC] = value\n elseif check == \"boolean\" then\n t[tC] = tostring(value)\n else\n t[tC] = '\"Not Supported\"'\n end\n t[tC + 1] = \",\"\n tC = tC + 2\n end\n if hasValue then\n tC = tC - 1\n end\n else\n for i = 1, #table do\n local value = table[i]\n local check = type(value)\n if check == \"table\" then\n tC = internalSerialize(value, tC, t)\n elseif check == \"string\" then\n t[tC] = sFormat(\"%q\", value)\n elseif check == \"number\" then\n t[tC] = value\n elseif check == \"boolean\" then\n t[tC] = tostring(value)\n else\n t[tC] = '\"Not Supported\"'\n end\n t[tC + 1] = \",\"\n tC = tC + 2\n end\n tC = tC - 1\n end\n t[tC] = \"}\"\n return tC\nend\n\nfunction serialize(value)\n local t = {}\n local check = type(value)\n\n if check == \"table\" then\n internalSerialize(value, 1, t)\n elseif check == \"string\" then\n return sFormat(\"%q\", value)\n elseif check == \"number\" then\n return value\n elseif check == \"boolean\" then\n return tostring(value)\n else\n return '\"Not Supported\"'\n end\n\n return concat(t)\nend\n\nfunction deserialize(s)\n return load(\"return \" .. s)()\nend\n","filter":{"args":[],"signature":"onStart()","slotKey":"-5"},"key":"5"}],"methods":[],"events":[]}