-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventory-Screen-Interactive.json
1 lines (1 loc) · 16.6 KB
/
Inventory-Screen-Interactive.json
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":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"------------------ EDIT HERE! ------------------------- \n---------17 MAX ITEMS PER ROW 50% OF SCREEN -----------\n--------{NAME, UNIT MASS, COLOR, UNIT VOLUME}----------\nlocal itemList = {\n {\n cols = 5,\n title = 'Tier 1 Raw',\n {'Quartz',2.65,'rgba(0,255,255'},\n {'Bauxite',1.28095,'rgba(191,166,166'},\n {'Coal',1.346,'rgba(54,69,79'},\n {'Hematite',5.04,'rgba(255,255,0'}\n },\n {\n title = 'Tier 2 Raw',\n {'Malachite',4.0,'rgba(200,128,51'},\n {'Limestone',2.7108,'rgba(61,255,0'},\n {'Natron',1.55,'rgba(171,92,242'},\n {'Chromite',4.54,'rgba(138,153,199'}\n },\n {\n title = 'Tier 3 Raw',\n {'Acanthite',7.2,'rgba(192,192,192'},\n {'Garnierite',2.6,'rgba(80,208,80'},\n {'Pyrite',5.01,'rgba(255,255,48'},\n {'Petalite',2.41,'rgba(204,128,255'}\n },\n {\n title = 'Tier 4 Raw',\n {'Cobaltite',6.33,'rgba(240,144,160'},\n {'Cryolite',2.95,'rgba(144,224,80'},\n {'Kolbeckite',2.37,'rgba(230,230,230'},\n {'Gold Nuggets',19.3,'rgba(255,209,35'}\n },\n {\n title = 'Tier 5 Raw',\n {'Columbite',5.38,'rgba(155,194,201'},\n {'Illmenite',4.55,'rgba(191,194,199'},\n {'Vanadinite',6.95,'rgba(166,166,171'},\n {'Rhodonite',3.76,'rgba(156,122,199'},\n {'Thoramine',21.30,'rgba(255,0,0'}\n },\n {\n cols = 5,\n title = 'Tier 1 Refined',\n {'Silicon',2.33,'rgba(0,255,255'},\n {'Aluminium',2.70,'rgba(191,166,166'},\n {'Carbon',2.27,'rgba(54,69,79'},\n {'Iron',7.85,'rgba(255,255,0'}\n },\n {\n title = 'Tier 2 Refined',\n {'Copper',8.96,'rgba(200,128,51'},\n {'Calcium',1.55,'rgba(61,255,0'},\n {'Sodium',0.97,'rgba(171,92,242'},\n {'Chromium',7.19,'rgba(138,153,199'}\n },\n {\n title = 'Tier 3 Refined',\n {'Silver',10.49,'rgba(192,192,192'},\n {'Nickel',8.91,'rgba(80,208,80'},\n {'Sulfur',1.82,'rgba(255,255,48'},\n {'Lithium',0.53,'rgba(204,128,255'}\n },\n {\n title = 'Tier 4 Refined',\n {'Cobalt',8.90,'rgba(240,144,160'},\n {'Fluorine',1.70,'rgba(144,224,80'},\n {'Scandium',2.98,'rgba(230,230,230'},\n {'Gold',19.30,'rgba(255,209,35'}\n },\n {\n title = 'Tier 5 Refined',\n {'Niobium',8.57,'rgba(155,194,201'},\n {'Titanium',4.51,'rgba(191,194,199'},\n {'Vanadium',6.0,'rgba(166,166,171'},\n {'Manganese',7.21,'rgba(156,122,199'}\n },\n----------------- DEFAULT END -------------------\n {\n cols = 4,\n title = 'Fuels',\n {'Nitron Fuel',4.0,'rgba(155,194,201'},\n {'Kergon X2 Fuel',6.0,'rgba(155,194,201'},\n {'Kergon X4 Fuel',6.0,'rgba(155,194,201'},\n },\n {\n title = 'Tier 1 Products',\n {'Steel',8.05,'rgba(155,194,201'},\n {'Silumin',3.0,'rgba(155,194,201'},\n {'ALFE Alloy',3.0,'rgba(155,194,201'},\n {'Polycarbonate Plastic',1.4,'rgba(155,194,201'},\n {'Glass',2.5,'rgba(155,194,201'}\n },\n {\n title = 'Basics',\n {'Basic Screw',8.05,'rgba(155,194,201',1.0},\n {'Basic Pipe',2.4,'rgba(155,194,201',1.0},\n {'Basic Hydraulics',28.95,'rgba(155,194,201',10.0},\n {'Basic Burner',50.2,'rgba(155,194,201',10.0},\n {'Basic Reinforced Frame XS',12.88,'rgba(155,194,201',2.0},\n {'Basic Reinforced Frame S',70.84,'rgba(155,194,201',11.0},\n {'Basic Reinforced Frame M',476.56,'rgba(155,194,201',74.0},\n {'Basic Reinforced Frame L',3315.0,'rgba(155,194,201',515.0},\n {'Basic Reinforced Frame XL',23195.0,'rgba(155,194,201',3602.0},\n {'Basic Standard Frame XS',4.19,'rgba(155,194,201',2.0},\n {'Basic Standard Frame S',23.09,'rgba(155,194,201',11.0},\n {'Basic Standard Frame M',155.39,'rgba(155,194,201',74.0}\n },\n {\n title = 'Basics',\n {'Basic Standard Frame L',1080.0,'rgba(155,194,201',515.0},\n {'Basic Combustion Chamber XS',60.64,'rgba(155,194,201',9.6},\n {'Basic Combustion Chamber S',319.35,'rgba(155,194,201',49.6},\n {'Basic Combustion Chamber M',1700.0,'rgba(155,194,201',259.2},\n {'Basic Combustion Chamber L',15160.0,'rgba(155,194,201',1374.4},\n {'Basic Chemical Container XS',2.4,'rgba(155,194,201',1.0},\n {'Basic Chemical Container S',28.95,'rgba(155,194,201',10.0},\n {'Basic Chemical Container M',15160.0,'rgba(155,194,201',1374.4},\n {'Basic Chemical Container L',2.4,'rgba(155,194,201',1.0},\n {'Basic Chemical Container XL',28.95,'rgba(155,194,201',10.0}\n },\n {\n cols = 2,\n title = 'Basics',\n {'Basic Ionic Chamber XS',75.1,'rgba(155,194,201',7.3},\n {'Basic Ionic Chamber S',391.6,'rgba(155,194,201',38.2},\n {'Basic Ionic Chamber M',2070.0,'rgba(155,194,201',202.4},\n {'Basic Ionic Chamber L',11140.0,'rgba(155,194,201',1090.4},\n {'Basic Ionic Chamber XL',61230.0,'rgba(155,194,201',6000.8},\n {'Basic Gaz Cylinder XS',15.68,'rgba(155,194,201',9.6},\n {'Basic Gaz Cylinder S',81.38,'rgba(155,194,201',49.6},\n {'Basic Gaz Cylinder M',427.88,'rgba(155,194,201',259.2},\n {'Basic Mobile Panel XS',20.0,'rgba(155,194,201',9.6},\n {'Basic Mobile Panel S',103.0,'rgba(155,194,201',49.6},\n {'Basic Mobile Panel M',535.8,'rgba(155,194,201',259.2},\n {'Basic Mobile Panel L',2830.0,'rgba(155,194,201',1374.4},\n {'Basic Mobile Panel XL',15160.0,'rgba(155,194,201',7420.0},\n {'Basic Robotic Arm M',927.0,'rgba(155,194,201',249.2},\n {'Basic Robotic Arm L',4929.0,'rgba(155,194,201',1324.4},\n {'Basic Robotic Arm XL',26700.0,'rgba(155,194,201',7170.8}\n },\n {\n title='Basics Elec',\n {'Basic Component',2.25,'rgba(155,194,201',0.5},\n {'Basic Connector',3.75,'rgba(155,194,201',0.8},\n {'Basic Electronics',5.22,'rgba(155,194,201',4.0},\n {'Basic Power System',60.0,'rgba(155,194,201',9.2},\n {'Basic Power Transformer M',1020.0,'rgba(155,194,201',196.4},\n {'Basic Processor',14.83,'rgba(155,194,201',5.0},\n {'Basic Control System',9.25,'rgba(155,194,201',5.2},\n {'Basic Injector',20.3,'rgba(155,194,201',10.0},\n {'Basic Fixation',1.1198,'rgba(155,194,201',1.0},\n {'Basic Casing XS',1.339,'rgba(155,194,201',2},\n {'Basic LED',1.25,'rgba(155,194,201',1}\n },\n}\n------------------------------------------------------------------------\n--------------------------- DO NOT EDIT BELOW --------------------------\n------------------------------------------------------------------------\n-- Here we are gonna detect what is in the default slots, databank/core/screen.\nlocal core, screen = {};\nlocal slots = {slot1,slot2}\n\nfor i = 1, #slots do\n if slots[i].getElementClass() == 'CoreUnitStatic'\n or slots[i].getElementClass() == 'CoreUnitSpace'\n or slots[i].getElementClass() == 'CoreUnitDynamic' then\n core = slots[i]\n end\n if slots[i].getElementClass() == 'ScreenUnit' then\n screen = slots[i]\n end\nend\n\n-- Set the refresh time.\nrefresh = 10 --export\n\n-- Simple rounding function needed later.\nlocal round = function(number, decimals)\n local power = 10^decimals\n return math.floor(number * power) / power\nend\n-- HTML header and footer\nlocal htmlHead, htmlFoot = [[<html><head><style>\n .head {\n margin-top: -6px;\n font-size:50px;\n font-variant: small-caps;\n font-weight:bold\n }\n th, .head {\n -webkit-text-stroke-width: 2px;\n -webkit-text-stroke-color: #fff\n }\n body {\n text-align:center\n }\n table:nth-child(odd) {\n float:left\n }\n table:nth-child(even) {\n float:right\n }\n table {\n font-size:20px;\n width: calc(50% - 10px);\n margin:0 5px 10px 5px\n }\n th {\n font-size:28px\n }\n td, .bar {\n text-shadow: 1px 1px #000, 2px 2px #000;\n background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));\n box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.25), inset 0 1px rgba(255, 255, 255, 0.1);\n color:#fff\n }\n .amount {\n width:20%\n }\n .name {\n width:36%\n }\n .percent {\n width:44%;\n font-family:bank;\n letter-spacing:-1px\n }\n .blank td {\n padding:2px\n }\n</style></head><body>]], '</body></html>'\nlocal outHTML = function(name, color, amount, percent, barColor)\n\tif name:len() > 16 then\n name = name:sub(0,14)..'..'..name:sub(-2)\n end\n return [[<tr>\n <td class=\"name\" style=\"border: 1px solid ]]..color..',1); background-color:'..color..', 0.6)\"><div>'..name..[[</div></td>\n <td class=\"amount\" style=\"border: 1px solid ]]..color..',1); background-color:'..color..', 0.6)\">'..amount..[[</td>\n <td class=\"percent\" style=\"border: 1px solid ]]..color..[[,1);\">\n <div class=\"bar\" style=\"width: ]]..percent..'%; background-color: '.. barColor ..'\">'..percent..[[%</div>\n </td>\n </tr>\n <tr class=\"blank\"><td></td></tr>]]\nend\n\nlocal calc = function (maxHP, weight, mass, vol)\n local containerProficiency = 30 --export\n local hubVol = 1280000 --export\n local sizes = {\n -- Mining and Inventory, Inventory Manager, Container Proficiency.\n -- Containers, min - max Hitpoints, Base Volume, Base Weight\n -- TODO: Determing what size containers the Hub is connected to.\n -- for now its hardcoded, containers connected to hub x base volume.\n -- eg: medium, 64000 * 10 containers connected to hub\n {49.00,122.00,hubVol,55.80}, --Hub\n {123.00,998.00,1000,229.09}, --xs\n {998.00,7996.00,8000,1280}, --s\n {7996.00,17316.00,64000,7421.34}, --m\n {17316.00,50316.00,128000,14842.7} --l\n }\n for i = 1, #sizes do\n if (maxHP >= sizes[i][1] and maxHP <= sizes[i][2]) then\n -- displayed side by side after default ores.\n local amount = (weight - sizes[i][4]) / mass\n local maxLitres = sizes[i][3]\n local volume = maxLitres + (maxLitres * containerProficiency / 100)\n if vol then\n percent = amount * vol / volume\n amount = math.floor(amount)\n else\n -- No volume its ore or something display L/KL\n percent = amount / volume\n -- Convert L to KL\n if amount > 999999 then\n amount = round(amount / 1000000, 2)..'ML'\n elseif amount > 999 then\n amount = round(amount / 1000, 2) .. 'KL'\n else\n amount = round(amount, 2) .. 'L'\n end\n end\n if percent < 0.5 then\n -- I like red to blue....Empty -> half full.\n r = math.floor(255 *(1 - (percent) / 0.5) +0 * (percent) / 0.5)\n g = math.floor(0 *(1 - (percent) / 0.5) +0 * (percent) / 0.5)\n b = math.floor(0 *(1 - (percent) / 0.5) +255 * (percent) / 0.5)\n else\n -- then, blue to green, half full -> full.\n r = math.floor(0 *(1 - (percent - 0.5) / 0.5) +0 * (percent - 0.5) / 0.5)\n g = math.floor(0 *(1 - (percent - 0.5) / 0.5) +255 * (percent - 0.5) / 0.5)\n b = math.floor(255 *(1 - (percent - 0.5) / 0.5) +0 * (percent - 0.5) / 0.5)\n end\n percent = round(percent * 100, 1)\n return amount, percent, 'rgba('..r..','..g..','..b..',0.7)'\n end\n end\nend\n\nlocal getItems = function(current, section)\n local eleIds, containers = core.getElementIdList(), {}\n for i = 1, #eleIds do\n if core.getElementTypeById(eleIds[i]) == 'container'\n or core.getElementTypeById(eleIds[i]) == 'Hub Container' then\n local name = core.getElementNameById(eleIds[i])\n -- If not default container name, store.\n if not string.match(name, '%[') then\n -- Container name eg: Coal, Bauxite\n -- Name of containers, Max Hitpoints and Total Weight of container.\n table.insert(containers, {name, core.getElementMaxHitPointsById(eleIds[i]), core.getElementMassById(eleIds[i])})\n end\n end\n end\n local htmlBody = '<div class=\"head\">Inventory</div>'\n -- Here we are going to iterate though the list at given index (current)\n -- and stop at section.\n for i = current, section do\n local style = ''\n if i == 5 or i == 10 then\n style = 'style=\"float:none;margin:0 auto\"'\n end\n if itemList[i].title then\n htmlBody = htmlBody .. '<table '.. style ..'><tbody><tr><th colspan=3>'.. itemList[i].title..'</th></tr>'\n else\n htmlBody = htmlBody .. '<table '.. style ..'><tbody><tr><th colspan=3>List</th></tr>'\n end\n local tiers = itemList[i]\n for x = 1, #tiers do\n local oreName = tiers[x][1]\n for y = 1, #containers do\n local containerName = containers[y][1]\n if containerName == oreName then\n local amount, percent, barColor = calc(containers[y][2], containers[y][3], tiers[x][2], tiers[x][4])\n htmlBody = htmlBody .. outHTML(oreName, tiers[x][3], amount, percent, barColor)\n end\n end\n end\n htmlBody = htmlBody .. '</tbody></table>'\n end\n screen.setHTML(htmlHead .. htmlBody .. htmlFoot)\n return\nend\n-- Set time for update.\ntime = system.getTime()\nlocal page = 1\nlocal current = 1 -- Get from current index\nlocal section = current + itemList[current].cols - 1 -- Sections to display on single page.\n-- Store the amount of colums for the page so we know what to display when we press back.\nlocal numCols = {itemList[current].cols}\n\nfunction nextPage()\n if itemList[section+1] then\n page = page + 1;\n numCols[page] = itemList[section+1].cols\n current = section + 1\n section = section + numCols[page]\n time = system.getTime()\n getItems(current,section)\n return\n end\n return\nend\nfunction prevPage()\n if current <= 1 then\n return\n else\n page = page - 1\n current = current - numCols[page]\n section = current + numCols[page] - 1\n time = system.getTime()\n getItems(current,section)\n return\n end\nend\nfunction update()\n getItems(current,section)\n return\nend\nupdate()","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"0"},{"code":"if system.getTime() - time > refresh then\n time = system.getTime()\n update()\nend","filter":{"args":[],"signature":"update()","slotKey":"-2"},"key":"1"},{"code":"prevPage()","filter":{"args":[{"value":"strafeleft"}],"signature":"actionStart(action)","slotKey":"-2"},"key":"2"},{"code":"nextPage()","filter":{"args":[{"value":"straferight"}],"signature":"actionStart(action)","slotKey":"-2"},"key":"3"},{"code":"-- Hide programming board from UI\nunit.hide()\n-- Unload default Modules & Libraries from global.lua\nlocal unrequire = function(m)\n package.loaded[m] = nil\n _G[m] = nil\nend\nunrequire'json'\nunrequire'Navigator'\nunrequire'Helpers'\nunrequire'AxisCommand'\nunrequire'database'\nunrequire'cpml/sgui'\nunrequire'pl/init'\n-- Manually run the garbage collector\ncollectgarbage('collect')\n-- \"setpause\" controls how much memory has to be allocated before it starts a new cycle\n-- Default is 200, meaning it will run everytime the memory is doubled,\n-- 100 means it will run every allocation. we're gonna use 110\ncollectgarbage('setpause', 110)\n-- You want this above to run on every pb, before any timers.\n-- You can manually collect garbage withing your tick, bot not recommended, fix your code!","filter":{"args":[],"signature":"start()","slotKey":"-3"},"key":"4"}],"methods":[],"events":[]}