Advertisement
Fusion1227

[SINGLEPLAYER] TrainSignalNetwork API

Oct 27th, 2023 (edited)
1,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ----/ TrainSignalNetwork class /---------------------------------------------
  2.  
  3.  
  4. local instances = {}
  5.  
  6.  
  7. --/ constructors /--
  8.  
  9.  
  10. function new(id1, id2)
  11.     local self = {}
  12.     self.subNetwork1 = {
  13.         id = id1,
  14.         signalState = false,
  15.     }
  16.     self.subNetwork2 = {
  17.         id = id2,
  18.         signalState = false,
  19.     }
  20.     return self
  21. end
  22.  
  23.  
  24. --/ functions /--
  25.  
  26.  
  27. function findFromComputerId(id)
  28.     for _, tsn in pairs(instances) do
  29.         if tsn.subNetwork1.id == id then
  30.             return tsn, tsn.subNetwork1, tsn.subNetwork2 -- the entire system, the relevant sub-system, and the other sub-system
  31.         elseif tsn.subNetwork2.id == id then
  32.             return tsn, tsn.subNetwork2, tsn.subNetwork1 -- the entire system, the relevant sub-system, and the other sub-system
  33.         end
  34.     end
  35. end
  36.  
  37.  
  38. ----/ linked computer ids /---------------------------------------------
  39.  
  40.  
  41. --[[  
  42.     Each array represents a train signal network, and the numbers are computer ids
  43. ]]
  44.  
  45. local linkedIds = {
  46.     -- {120, 114},
  47.     {3, 5},
  48.     {8, 9},
  49. }
  50.  
  51.  
  52. ----/ make systems from linked ids /---------------------------------------------
  53.  
  54.  
  55. for _, list in pairs(linkedIds) do
  56.     local trainSignalNetwork = new(unpack(list))
  57.     table.insert(instances, trainSignalNetwork)
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement