Posted 29 September 2012 - 02:35 PM
Right now, Peripherals only really work when attached directly. Would it be at all possible to make it so that a peripheral could be attached via Bundled Cables, and have them interface with the Peripheral library exactly like normal?
For the issue of multiple peripherals, you could implement them as a list. Directly connected peripherals (placed beside the block) act as the first and only peripheral in the list.
When a cable is connected, however, you can access the peripherals on the cable by an index. They are sorted by the distance on the cable. Where the distance is the same, the peripheral with the lowest X, Y or Z will be ordered lower - ie, if the cable distance is the same, and the blocks have the same X co-ordinate but different Y co-ordinates, the block with the lower Y will go on the list first)
You would probably want to cache this list in some manner, since presumably doing all that cable checking and searching every call would be a waste of resources.
Some additions to the API would need to be made, most likely:
Then we can easily connect monitors via cables and whatnot.
For the issue of multiple peripherals, you could implement them as a list. Directly connected peripherals (placed beside the block) act as the first and only peripheral in the list.
When a cable is connected, however, you can access the peripherals on the cable by an index. They are sorted by the distance on the cable. Where the distance is the same, the peripheral with the lowest X, Y or Z will be ordered lower - ie, if the cable distance is the same, and the blocks have the same X co-ordinate but different Y co-ordinates, the block with the lower Y will go on the list first)
You would probably want to cache this list in some manner, since presumably doing all that cable checking and searching every call would be a waste of resources.
Some additions to the API would need to be made, most likely:
-- Change:
peripheral.wrap(side[,number=1]) -- Returns the peripheral at the given index on that side. (or nil, if number is out of bounds)
-- Add:
peripheral.all(side) -- Returns a table of all peripherals on that side. k=number, v=peripheral type.
Then we can easily connect monitors via cables and whatnot.