Advertisement
theTANCO

CellLabHelper.lua

Feb 8th, 2023 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.51 KB | None | 0 0
  1. -- This is a helper program made in ComputerCraft for a mobile game called Cell Lab. Run the program and click on 'Help' for more information.
  2. -- Before running this program, make sure you have the appropriate API programs by running the following commands:
  3. --   pastebin get Rac6Jxjg "/API/LibAppend.lua"
  4. --   pastebin get t2TvSiSU "/API/Class.lua"
  5. --   pastebin get KA2dK07y "/API/events.lua"
  6. -- You can get this program from https://pastebin.com/F4gH1cTA
  7.  
  8. require("/API/events")
  9. local types = {
  10.     "Phagocyte",
  11.     "Flagellocyte",
  12.     "Photocyte",
  13.     "Devorocyte",
  14.     "Lipocyte",
  15.     "Keratinocyte",
  16.     "Buoyocyte",
  17.     "Glueocyte",
  18.     "Virocyte",
  19.     "Nitrocyte",
  20.     "Myocyte",
  21.     "Neurocyte",
  22.     "Senseocyte",
  23.     "Stereocyte",
  24.     "Secrocyte",
  25.     "Stemocyte",
  26.     "Gamete",
  27.     "Ciliocyte"
  28. }
  29. local modes = {
  30.     init = 1,
  31.     splits = 0
  32. }
  33. local tree = {}
  34. local dragScroll = vector2.new()
  35. local divider = 24
  36. local display = {}
  37. display.size = vector2.new(term.getSize())
  38. if display.size.x < 42 or display.size.y < 14 then error("error: minimum screen size: 42x14 (current: " .. display.size.x .. "x" .. display.size.y .. ")", 0) end
  39. display.chart = {size = vector2.new(display.size.x-divider, display.size.y-1)}
  40. display.chart.win = window.create(term.current(), divider+1, 2, display.chart.size.x, display.chart.size.y)
  41. display.scroll = {
  42.     mode = 0,
  43.     tree = vector2.new(0, math.floor(display.chart.size.y/-2)+1)
  44. }
  45.  
  46. local buildTree = function()
  47.     local oldPos = 1
  48.     if #tree > 0 then
  49.         oldPos = tree[0][1].padding
  50.     end
  51.     local function makeTree(split, id, cell, parent, upAd, downAd)
  52.         tree[split][id] = {
  53.             cell = cell, parent = parent,
  54.             upAd = upAd, downAd = downAd,
  55.             child = {},
  56.             padding = id*2-1
  57.         }
  58.  
  59.         if split < modes.splits then
  60.             if not tree[split+1] then tree[split+1] = {} end
  61.             if modes[cell].split then
  62.                 makeTree(split+1, #tree[split+1]+1, modes[cell].child[1], id, modes[cell].childA[1] and modes[cell].adhesin, modes[cell].adhesin)
  63.                 tree[split][id].child[1] = #tree[split+1]
  64.  
  65.                 makeTree(split+1, #tree[split+1]+1, modes[cell].child[2], id, modes[cell].adhesin, modes[cell].childA[2] and modes[cell].adhesin)
  66.                 tree[split][id].child[2] = #tree[split+1]
  67.  
  68.                 tree[split][id].padding = math.floor((tree[split+1][tree[split][id].child[1] ].padding + tree[split+1][tree[split][id].child[2] ].padding) / 2)
  69.             else
  70.                 makeTree(split+1, #tree[split+1]+1, cell, id, tree[split][id].upAd, tree[split][id].downAd)
  71.                 tree[split][id].child[1] = #tree[split+1]
  72.                 tree[split][id].padding = tree[split+1][tree[split][id].child[1] ].padding
  73.             end
  74.         end
  75.     end
  76.     tree = {[0] = {}}
  77.     makeTree(0, 1, modes.init, nil, false, false)
  78.     display.scroll.tree.y = display.scroll.tree.y + (tree[0][1].padding - oldPos)
  79. end
  80.  
  81.  
  82. display.modesColumn = function()
  83.     term.setCursorPos(1, 1)
  84.     term.setBackgroundColor(colors.black)
  85.     term.setTextColor(colors.yellow)
  86.     term.write("M Cell Type   ASIC1AC2A")
  87. end
  88.  
  89. display.setColor = function(c)
  90.     term.setBackgroundColor(2^c)
  91.     if c == 15 then term.setTextColor(colors.white)
  92.     else term.setTextColor(colors.black) end
  93. end
  94.  
  95. display.mode = function(n)
  96.     local yPos = n+1-display.scroll.mode
  97.     local checkMark = function(b)
  98.         term.setBackgroundColor(colors.white)
  99.         term.setTextColor(colors.red)
  100.         if b then term.write(string.char(7))
  101.         else term.write(" ") end
  102.     end
  103.     if isBetween(yPos, 1, display.size.y+1) and modes[n] ~= nil then
  104.         term.setCursorPos(1, yPos)
  105.         display.setColor(modes[n].color)
  106.         term.write(string.pad(n, "0", 2))
  107.         display.setColor(modes[n].color)
  108.         if modes[n].color == 7 then term.setTextColor(colors.lightGray)
  109.         else term.setTextColor(colors.gray) end
  110.         term.write(types[modes[n].cellType])
  111.         term.setBackgroundColor(colors.black)
  112.         term.write(string.rep(" ", 12-types[modes[n].cellType]:len()))
  113.         checkMark(modes[n].adhesin)
  114.         checkMark(modes[n].split)
  115.         checkMark(n == modes.init)
  116.         for a = 1, 2 do
  117.             display.setColor(modes[modes[n].child[a]].color)
  118.             term.write(string.pad(modes[n].child[a], "0", 2))
  119.             checkMark(modes[n].childA[a])
  120.         end
  121.     end
  122. end
  123.  
  124. display.modesList = function()
  125.     for y = 1, display.size.y-1 do
  126.         display.mode(y+display.scroll.mode)
  127.     end
  128. end
  129.  
  130. display.envSettings = function()
  131.     term.setCursorPos(divider+1, 1)
  132.     term.setTextColor(colors.yellow)
  133.     term.setBackgroundColor(colors.black)
  134.     term.write("S:")
  135.     term.setBackgroundColor(colors.white)
  136.     term.setTextColor(colors.black)
  137.     term.write(string.pad(modes.splits, " ", 2))
  138.     term.setTextColor(colors.yellow)
  139.     term.setBackgroundColor(colors.black)
  140.     term.write(" C:")
  141.     term.setTextColor(colors.white)
  142.     term.write(#tree[#tree] .. "   ")
  143.     term.setCursorPos(display.size.x-5, 1)
  144.     term.blit("Help " .. string.char(215), "fffff0", "8888fe")
  145. end
  146.  
  147. display.topLine = function()
  148.     term.setCursorPos(1, 1)
  149.     term.setBackgroundColor(colors.black)
  150.     term.clearLine()
  151.     display.modesColumn()
  152.     term.write(" ")
  153.     display.envSettings()
  154. end
  155.  
  156. display.columnName = function(str, xPos)
  157.     str = tostring(str)
  158.     term.setBackgroundColor(colors.black)
  159.     term.setTextColor(colors.white)
  160.     term.setCursorPos(xPos, 1)
  161.     term.clearLine()
  162.     term.write(str)
  163.     os.pullEvent("mouse_click")
  164.     display.topLine()
  165. end
  166.  
  167. display.tree = function()
  168.     local oldTerm = term.redirect(display.chart.win)
  169.     term.setBackgroundColor(colors.black)
  170.     term.setTextColor(colors.white)
  171.  
  172.     local drawConnection = function(thisSplit, firstCell, secondCell, yPos)
  173.         local tCol, bCol = "", ""
  174.         if modes[firstCell.cell].color == modes[secondCell.cell].color then
  175.             -- If first and second cell colors are same print cell's background color with default dithering color.
  176.             bCol = string.rep(colors.toBlit(2^modes[firstCell.cell].color), 3)
  177.             if bCol == "fff" then tCol = "000"
  178.             else tCol = "fff" end
  179.         elseif yPos <= firstCell.padding + (secondCell.padding - firstCell.padding)/2 then
  180.             -- If less than or equal to parent's position, print first cell's background color with second cell's dithering color.
  181.             tCol = string.rep(colors.toBlit(2^modes[secondCell.cell].color), 3)
  182.             bCol = string.rep(colors.toBlit(2^modes[firstCell.cell].color), 3)
  183.         else -- If greater than parent's position, print second cell's background color with first cell's dithering color.
  184.             tCol = string.rep(colors.toBlit(2^modes[firstCell.cell].color), 3)
  185.             bCol = string.rep(colors.toBlit(2^modes[secondCell.cell].color), 3)
  186.         end
  187.         term.blit(string.rep(string.char(127), 3), tCol, bCol)
  188.     end
  189.  
  190.     for x = 1, display.chart.size.x+4, 4 do
  191.         local thisSplit = math.floor((x+display.scroll.tree.x-1)/4)
  192.         local thisCell = 1
  193.         for y = 1, display.chart.size.y do
  194.             local xPos, yPos = x-display.scroll.tree.x%4, y+display.scroll.tree.y
  195.             term.setCursorPos(xPos, y)
  196.             if isBetween(thisSplit, 0, modes.splits, true) and thisCell <= #tree[thisSplit] then
  197.                 while thisCell < #tree[thisSplit] and ((thisSplit == modes.splits and yPos > tree[thisSplit][thisCell].padding)
  198.                    or (thisSplit < modes.splits and yPos > tree[thisSplit+1][tree[thisSplit][thisCell].child[#tree[thisSplit][thisCell].child] ].padding)) do
  199.                     thisCell = thisCell + 1
  200.                 end
  201.                 if yPos == tree[thisSplit][thisCell].padding then
  202.                     -- If cell is here, print mode number.
  203.                     display.setColor(modes[tree[thisSplit][thisCell].cell].color)
  204.                     term.write("M" .. string.rep("0", 2-string.len(tree[thisSplit][thisCell].cell)) .. tree[thisSplit][thisCell].cell)
  205.                 elseif yPos > tree[thisSplit][thisCell].padding and thisCell < #tree[thisSplit] and tree[thisSplit][thisCell].downAd and tree[thisSplit][thisCell+1].upAd then
  206.                     -- If above this cell's second child's padding, print connection between this cell and next cell.
  207.                     drawConnection(thisSplit, tree[thisSplit][thisCell], tree[thisSplit][thisCell+1], yPos)
  208.                 elseif yPos < tree[thisSplit][thisCell].padding and thisCell > 1 and tree[thisSplit][thisCell-1].downAd and tree[thisSplit][thisCell].upAd then
  209.                     -- If above this cell's padding, print connection between previous cell and this cell.
  210.                     drawConnection(thisSplit, tree[thisSplit][thisCell-1], tree[thisSplit][thisCell], yPos)
  211.                 else term.write("   ") end
  212.                 term.setBackgroundColor(colors.black)
  213.                 if #tree[thisSplit][thisCell].child > 0 then -- If this cell has children...
  214.                     if modes[tree[thisSplit][thisCell].cell].split then -- ...and this cell splits...
  215.                         if yPos == tree[thisSplit+1][tree[thisSplit][thisCell].child[1] ].padding then
  216.                             -- ...print line to first child.
  217.                             term.blit(string.char(156), "8", "f")
  218.                         elseif yPos == tree[thisSplit+1][tree[thisSplit][thisCell].child[2] ].padding then
  219.                             -- ...print line to second child.
  220.                             term.blit(string.char(141), "8", "f")
  221.                         elseif yPos > tree[thisSplit+1][tree[thisSplit][thisCell].child[1] ].padding and yPos < tree[thisSplit+1][tree[thisSplit][thisCell].child[2] ].padding then
  222.                             -- ...print line between children.
  223.                             term.blit(string.char(149), "8", "f")
  224.                         else term.write(" ") end
  225.                     elseif yPos == tree[thisSplit][thisCell].padding then
  226.                         -- ... and this cell doesn't split, print straight line from parent to child.
  227.                         term.blit(string.char(140), "8", "f")
  228.                     else term.write(" ") end
  229.                 else term.write(" ") end
  230.             else term.write("    ") end
  231.         end
  232.     end
  233.     term.redirect(oldTerm)
  234. end
  235.  
  236. display.divider = function()
  237.     for y = 1, display.size.y do
  238.         term.setCursorPos(divider, y)
  239.         term.blit(string.char(149), "8", "f")
  240.     end
  241. end
  242.  
  243. display.all = function()
  244.     term.clear()
  245.     display.topLine()
  246.     display.modesList()
  247.     display.divider()
  248.     display.tree()
  249. end
  250.  
  251. display.help = function()
  252.     term.setCursorPos(1, 1)
  253.     local page = 1
  254.     local exitPos = vector2.new()
  255.  
  256.     local setLeftDivider = function(label, xPos)
  257.         if label == nil then display.modesColumn()
  258.         else
  259.             term.setCursorPos(xPos, 1)
  260.             term.setTextColor(colors.yellow)
  261.             term.write(label)
  262.         end
  263.         display.modesList()
  264.         display.divider()
  265.         return term.redirect(window.create(term.current(), divider+1, 1, display.size.x-divider, display.size.y))
  266.     end
  267.  
  268.     local setRightDivider = function()
  269.         display.envSettings()
  270.         display.tree()
  271.         display.divider()
  272.         return term.redirect(window.create(term.current(), 1, 1, divider-1, display.size.y))
  273.     end
  274.  
  275.     local fixTree = function()
  276.         local old = {
  277.             scroll = vector2.new(display.scroll.tree.x, display.scroll.tree.y),
  278.             init = modes.init,
  279.             splits = modes.splits,
  280.             color = {[1] = modes[1].color, [2] = modes[2].color},
  281.             adhesin = {[1] = modes[1].adhesin, [2] = modes[2].adhesin},
  282.             child = {[1] = modes[1].child, [2] = modes[2].child},
  283.             childA = {[1] = modes[1].childA, [2] = modes[2].childA}
  284.         }
  285.         display.scroll.tree = vector2.new(0, math.floor(display.chart.size.y/-2))
  286.         modes.init = 1
  287.         modes.splits = 3
  288.         modes[1].color = 0
  289.         modes[2].color = 1
  290.         modes[1].adhesin = true
  291.         modes[2].adhesin = true
  292.         modes[1].child = {1, 2}
  293.         modes[2].child = {2, 1}
  294.         modes[1].childA = {true, true}
  295.         modes[2].childA = {true, false}
  296.         buildTree()
  297.         return old
  298.     end
  299.  
  300.     local resetTree = function(old)
  301.         modes.init = old.init
  302.         modes.splits = old.splits
  303.         modes[1].color = old.color[1]
  304.         modes[2].color = old.color[2]
  305.         modes[1].adhesin = old.adhesin[1]
  306.         modes[2].adhesin = old.adhesin[2]
  307.         modes[1].child = old.child[1]
  308.         modes[2].child = old.child[2]
  309.         modes[1].childA = old.childA[1]
  310.         modes[2].childA = old.childA[2]
  311.         buildTree()
  312.         display.scroll.tree = vector2.new(old.scroll.x, old.scroll.y)
  313.     end
  314.  
  315.     local help = {
  316.         [1] = function() -- Introduction
  317.             term.setCursorPos(1, 1)
  318.             print("This program was made as a helper for the mobile game, Cell Lab. You will need to play that game to understand this program. It's purpose is to help visualize how cells will divide with the given paramaters, without taking survivability into account.")
  319.             term.setTextColor(colors.yellow)
  320.             print("\nTo go to the next page, scroll down on the Scroll Wheel.")
  321.             print("To go to the previous page, scroll up on the Scroll Wheel.")
  322.             write("To return to the program, Left Click on the ")
  323.             term.setBackgroundColor(colors.red)
  324.             term.setTextColor(colors.white)
  325.             write(string.char(215))
  326.             term.setBackgroundColor(colors.black)
  327.             term.setTextColor(colors.yellow)
  328.             write(".")
  329.             exitPos = vector2.new(term.getCursorPos())
  330.             exitPos.x = exitPos.x - 2
  331.         end,
  332.         [2] = function() -- Left of Divider
  333.             local reset = setLeftDivider()
  334.             write("The left side of the divider is your genome data. You can change these values by using Left or Right Click.")
  335.             term.redirect(reset)
  336.         end,
  337.         [3] = function() -- Column Labels
  338.             local reset = setLeftDivider()
  339.             write(string.char(27) .. " These are the column labels. Left Click any of these to reveal the full name of the label, except for '")
  340.             term.setTextColor(colors.yellow)
  341.             write("Cell Type")
  342.             term.setTextColor(colors.white)
  343.             write("' which is already the full name.")
  344.             term.redirect(reset)
  345.         end,
  346.         [4] = function() -- Mode
  347.             local reset = setLeftDivider("M", 1)
  348.             write("This is the 'Mode' column. It is the mutation id of your genome. Left or Right Click the mode number to change the color of that cell.")
  349.             term.redirect(reset)
  350.         end,
  351.         [5] = function() -- Cell Type
  352.             local reset = setLeftDivider("Cell Type", 3)
  353.             write("This column is the type of cell of the current mode. Left or Right Click to change the type of cell.")
  354.             term.redirect(reset)
  355.         end,
  356.         [6] = function() -- Make Adhesin
  357.             local reset = setLeftDivider("A", 15)
  358.             write("This is the 'Make Adhesin' column. It tells the cell's children to stick together or stay separated when the initial cell splits. This option is disabled by default. Left click to toggle this option.")
  359.             term.redirect(reset)
  360.         end,
  361.         [7] = function() -- Split
  362.             local reset = setLeftDivider("S", 16)
  363.             write("This is the 'Split' column. This determines if the cell actually splits in the next level. If not, it will have one child that is an exact copy of itself. This option is enabled by default. Left click to toggle this option.")
  364.             term.redirect(reset)
  365.         end,
  366.         [8] = function() -- Initial
  367.             local reset = setLeftDivider("I", 17)
  368.             write("This is the 'Initial' column. The mode with this option is the cell that the flow chart starts with. The initial cell is M01 by default. Left click this column to change the initial cell.")
  369.             term.redirect(reset)
  370.         end,
  371.         [9] = function() -- Child 1 Mode
  372.             local reset = setLeftDivider("C1", 18)
  373.             print("This is the 'Child 1' column. This is the mode that this cell's first child will become when it splits. Left or Right Click to change this option.")
  374.             term.redirect(reset)
  375.         end,
  376.         [10] = function() -- Child 1 Keep Adhesin
  377.             local reset = setLeftDivider("A", 20)
  378.             print("This is the 'Keep Adhesin' column for Child 1. This tells the first child cell to stay attached to the cell above it. This option is enabled by default. Left Click to toggle this option.")
  379.             term.redirect(reset)
  380.         end,
  381.         [11] = function() -- Child 2 Mode
  382.             local reset = setLeftDivider("C2", 21)
  383.             print("This is the 'Child 2' column. This is the mode that this cell's second child will become when it splits. Left or Right Click to change this option.")
  384.             term.redirect(reset)
  385.         end,
  386.         [12] = function() -- Child 2 Keep Adhesin
  387.             local reset = setLeftDivider("A", 23)
  388.             print("This is the 'Keep Adhesin' column for Child 2. This tells the second child cell to stay attached to the cell below it. This option is enabled by default. Left Click to toggle this option.")
  389.             term.redirect(reset)
  390.         end,
  391.         [13] = function() -- Right of Divider
  392.             local reset = setRightDivider()
  393.             print("The right side of the divider is the flow chart for the genome you created as well as some additional options at top of the screen.")
  394.             term.redirect(reset)
  395.         end,
  396.         [14] = function() -- Times to Split
  397.             local reset = setRightDivider()
  398.             write("The number after '")
  399.             term.setTextColor(colors.yellow)
  400.             write("S:")
  401.             term.setTextColor(colors.white)
  402.             write("' is how many times your initial cell will split. Left or Right Click the number to change the number of splits. The minimum is 0 and the maximum is automatically adjusted based on how many cells are in your final split.")
  403.             term.redirect(reset)
  404.         end,
  405.         [15] = function() -- Total Cells
  406.             local reset = setRightDivider()
  407.             write("The number after '")
  408.             term.setTextColor(colors.yellow)
  409.             write("C:")
  410.             term.setTextColor(colors.white)
  411.             write("' is how many cells are in your final split. The the maximum number of cells you can have in game is 1000. You will not be able to split anymore if you have 1000 or more cells in your final split.")
  412.             term.redirect(reset)
  413.         end,
  414.         [16] = function() -- Help
  415.             local reset = setRightDivider()
  416.             write("Left Click ")
  417.             term.setBackgroundColor(colors.lightGray)
  418.             term.setTextColor(colors.black)
  419.             write("Help")
  420.             term.setBackgroundColor(colors.black)
  421.             term.setTextColor(colors.white)
  422.             write(" to see this section, and to exit the program, Left Click ")
  423.             term.setBackgroundColor(colors.red)
  424.             term.setTextColor(colors.white)
  425.             write(string.char(215))
  426.             term.setBackgroundColor(colors.black)
  427.             term.setTextColor(colors.white)
  428.             write(".")
  429.             term.redirect(reset)
  430.         end,
  431.         [17] = function() -- Flow Chart 1
  432.             local old = fixTree()
  433.             local reset = setRightDivider()
  434.             print("The flow chart shows how cells will reproduce based on the genome you created on the left side of the divider. Click and drag with Left or Right Click to scroll through the chart with the mouse. Middle Click to reset the scroll position.")
  435.             term.redirect(reset)
  436.             resetTree(old)
  437.         end,
  438.         [18] = function() -- Flow Chart 2
  439.             local old = fixTree()
  440.             local reset = setRightDivider()
  441.             print("You can also scroll up and down using Scroll Wheel, and left and right by holding Shift while using Scroll Wheel. If you hold Ctrl you can scroll the entire height of the screen, and holding Shift and Ctrl scrolls the entire width of the right side of the divider.")
  442.             term.redirect(reset)
  443.             resetTree(old)
  444.         end,
  445.         [19] = function() -- Flow Chart Components
  446.             local old = fixTree()
  447.             local reset = setRightDivider()
  448.             print("'M##' is the mode number. The light gray lines connect the parents to their children. The dithered spaces between cells shows what cells are attached to each other.")
  449.             term.redirect(reset)
  450.             resetTree(old)
  451.         end
  452.     }
  453.     local updateScreen = function()
  454.         term.setBackgroundColor(colors.black)
  455.         term.setTextColor(colors.white)
  456.         term.clear()
  457.         help[page]()
  458.         if isBetween(page, 1, 13) then
  459.             exitPos = vector2.new(divider, 1)
  460.             term.setCursorPos(divider, 1)
  461.             term.setBackgroundColor(colors.red)
  462.             term.setTextColor(colors.white)
  463.             term.write(string.char(215))
  464.         elseif page > 12 then exitPos = vector2.new(display.size.x, 1) end
  465.     end
  466.     updateScreen(page)
  467.     while true do
  468.         events.getEvent()
  469.         if events.eventIs("mouse_scroll", 1, {"any"}, {"any"}) then
  470.             page = page + 1
  471.             if page > #help then page = 1 end
  472.             updateScreen(page)
  473.         elseif events.eventIs("mouse_scroll", -1, {"any"}, {"any"}) then
  474.             page = page - 1
  475.             if page < 1 then page = #help end
  476.             updateScreen(page)
  477.         elseif events.eventIs("mouse_up", 1, exitPos.x, exitPos.y) then
  478.             break
  479.         end
  480.     end
  481. end
  482.  
  483. local incrementValue = function(v, dir, lower, upper)
  484.     dir = dir % 3
  485.     if dir == 2 then dir = -1 end
  486.     v = v + dir
  487.     if v > upper then v = v - (upper - lower + 1)
  488.     elseif v < lower then v = v + (upper - lower + 1) end
  489.     return v
  490. end
  491.  
  492. local incrementMode = function(m, v, dir, lower, upper)
  493.     local child = 0
  494.     if dir > 3 then
  495.         if dir < 7 then child = 1
  496.         else child = 2 end
  497.     end
  498.     if child > 0 then modes[m][v][child] = incrementValue(modes[m][v][child], dir, lower, upper)
  499.     else modes[m][v] = incrementValue(modes[m][v], dir, lower, upper) end
  500.     if dir%3 ~= 0 then
  501.         display.mode(m)
  502.         buildTree()
  503.         display.envSettings()
  504.         display.tree()
  505.     end
  506. end
  507.  
  508. local toggleCheck = function(m, v)
  509.     local child = 0
  510.     if v == "a" then v = "adhesin"
  511.     elseif v == "s" then v = "split"
  512.     elseif v == "i" then v = "init"
  513.     elseif v:sub(1, 1) == "c" then
  514.         child = tonumber(v:sub(2, 2))
  515.         v = "childA"
  516.     else error("bad argument #2 to 'toggleCheck' (expected 'a', 's', 'i', 'c1' or 'c2', got " .. type(v) .. " '" .. tostring(v) .. "')", 2) end
  517.     if v == "init" then
  518.         local oldInit = modes.init
  519.         modes.init = m
  520.         display.mode(oldInit)
  521.     elseif v == "childA" then
  522.         if modes[m][v][child] then modes[m][v][child] = false
  523.         else modes[m][v][child] = true end
  524.     else
  525.         if modes[m][v] then modes[m][v] = false
  526.         else modes[m][v] = true end
  527.     end
  528.     display.mode(m)
  529.     buildTree()
  530.     display.envSettings()
  531.     display.tree()
  532. end
  533.  
  534. for a = 1, 40 do
  535.     modes[a] = {
  536.         cellType = 1,
  537.         color = (a-1)%16,
  538.         child = {[1] = a, [2] = a},
  539.         childA = {[1] = true, [2] = true},
  540.         adhesin = false,
  541.         split = true
  542.     }
  543. end
  544.  
  545. buildTree()
  546. display.all()
  547.  
  548. while true do
  549.     events.getEvent()
  550.     if events.eventIs("mouse_scroll", {"any"}, {"<", divider}, {"any"}) -- Scroll genome list.
  551.     and ((events[2] == -1 and display.scroll.mode > 0)
  552.     or (events[2] == 1 and display.scroll.mode < #modes-display.size.y+1)) then
  553.         display.scroll.mode = display.scroll.mode + events[2]
  554.         display.modesList()
  555.     elseif events.eventIs("mouse_scroll", {"any"}, {">", divider}, {">", 1}) then -- Scroll flow chart...
  556.         if events.isPressed("key", keys.leftShift) or events.isPressed("key", keys.rightShift) then -- ...horizontally...
  557.             if events.isPressed("key", keys.leftCtrl) or events.isPressed("key", keys.rightCtrl) then -- ...by the width of the chart.
  558.                 display.scroll.tree.x = display.scroll.tree.x + events[2] * display.chart.size.x
  559.             else display.scroll.tree.x = display.scroll.tree.x + events[2] end -- ...by one line.
  560.         elseif events.isPressed("key", keys.leftCtrl) or events.isPressed("key", keys.rightCtrl) then -- ...vertically by the height of the chart.
  561.             display.scroll.tree.y = display.scroll.tree.y + events[2] * display.chart.size.y
  562.         else display.scroll.tree.y = display.scroll.tree.y + events[2] end -- ...vertically by one line.
  563.         display.tree()
  564.     elseif events.eventIs("mouse_click", {"any"}, {"<", divider}, {"any"}) then -- Click actions left of the divider.
  565.         if events[4] == 1 and events[2] == 1 then -- Show full column names.
  566.             if isBetween(events[3], 0, 3) then display.columnName("Mode", 1)
  567.             elseif events[3] == 15 then display.columnName("Make Adhesin", 10)
  568.             elseif events[3] == 16 then display.columnName("Split", 16)
  569.             elseif events[3] == 17 then display.columnName("Initial", 17)
  570.             elseif isBetween(events[3], 17, 20) then display.columnName("Child 1", 13)
  571.             elseif events[3] == 20 then display.columnName("Keep Adhesin", 15)
  572.             elseif isBetween(events[3], 20, 23) then display.columnName("Child 2", 16)
  573.             elseif events[3] == 23 then display.columnName("Keep Adhesin", 18)
  574.             end
  575.         else -- Edit genome.
  576.             local clickedMode = events[4]-1+display.scroll.mode
  577.             if isBetween(events[3], 0, 3) then -- Change mode color.
  578.                 incrementMode(clickedMode, "color", events[2], 0, 15)
  579.                 if events[2] < 3 then
  580.                     for a, b in ipairs(modes) do
  581.                         local updateMode = false
  582.                         for c = 1, 2 do
  583.                             if b.child[c] == clickedMode and a ~= clickedMode then updateMode = true end
  584.                         end
  585.                         display.mode(a)
  586.                     end
  587.                 end
  588.             elseif isBetween(events[3], 2, 15) then incrementMode(clickedMode, "cellType", events[2], 1, #types) -- Change cell type.
  589.             elseif events[2] == 1 and events[3] == 15 then toggleCheck(clickedMode, "a") -- Toggle 'Make Adhesin'.
  590.             elseif events[2] == 1 and events[3] == 16 then toggleCheck(clickedMode, "s") -- Toggle splitting this cell.
  591.             elseif events[2] == 1 and events[3] == 17 then toggleCheck(clickedMode, "i") -- Change initial cell.
  592.             elseif isBetween(events[3], 17, 20) then incrementMode(clickedMode, "child", events[2]+3, 1, #modes) -- Change child 1 mode.
  593.             elseif events[2] == 1 and events[3] == 20 then toggleCheck(clickedMode, "c1") -- Toggle child 1 'Keep Adhesin'.
  594.             elseif isBetween(events[3], 20, 23) then incrementMode(clickedMode, "child", events[2]+6, 1, #modes) -- Change child 2 mode.
  595.             elseif events[2] == 1 and events[3] == 23 then toggleCheck(clickedMode, "c2") end -- Toggle child 2 'Keep Adhesin'.
  596.         end
  597.     elseif events.eventIs("mouse_click", {"any"}, {">", divider}, {"any"}) then -- Click actions right of the divider.
  598.         if events[4] == 1 then -- Environment options.
  599.             if isBetween(events[3], divider+2, divider+5) then -- Change number of splits.
  600.                 if events[2] == 1 and #tree[#tree] < 1000 then
  601.                     modes.splits = modes.splits + 1
  602.                     buildTree(true)
  603.                     display.envSettings()
  604.                     display.tree()
  605.                 elseif events[2] == 2 and modes.splits > 0 then
  606.                     modes.splits = modes.splits - 1
  607.                     buildTree(true)
  608.                     display.envSettings()
  609.                     display.tree()
  610.                 end
  611.             elseif isBetween(events[3], display.size.x-6, display.size.x-1) then -- Show help section.
  612.                 display.help()
  613.                 display.all()
  614.             elseif events[3] == display.size.x then -- Exit program.
  615.                 term.setBackgroundColor(colors.black)
  616.                 term.clear()
  617.                 term.setCursorPos(1, 1)
  618.                 error()
  619.             end
  620.         else -- Flow chart options.
  621.             if events[2] == 3 then -- Reset scroll position.
  622.                 display.scroll.tree = vector2.new(0, tree[0][1].padding-math.floor(display.chart.size.y/2))
  623.                 display.tree()
  624.             else dragScroll = vector2.new(events[3], events[4]) end -- Enable scrolling flow chart with mouse drag.
  625.         end
  626.     elseif events[1] == "mouse_up" and events[2] < 3 then dragScroll = vector2.new() -- Disable scrolling flow chart with mouse drag.
  627.     elseif events[1] == "mouse_drag" and events[2] < 3 and dragScroll.x > 0 and dragScroll.y > 0 then -- Scroll flow chart with mouse drag.
  628.         display.scroll.tree.x = display.scroll.tree.x + (dragScroll.x - events[3])
  629.         display.scroll.tree.y = display.scroll.tree.y + (dragScroll.y - events[4])
  630.         dragScroll = vector2.new(events[3], events[4])
  631.         display.tree()
  632.     end
  633. end
  634.  
  635. --[[ Changelog
  636. 2023/02/23:
  637. • Changed Vector2 to vector2 to reflect the changes made to "/API/LibAppend.lua".
  638. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement