Advertisement
kaibochan

buffer.lua

Feb 19th, 2025 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. local Cell = require("/apis/gui.cell")
  2.  
  3. local Buffer = {
  4.     __name = "Buffer",
  5.     width = 1,
  6.     height = 1,
  7.     cells = {},
  8. }
  9.  
  10. function Buffer:new(o)
  11.     o = o or {}
  12.  
  13.     -- set new object to inherit from prototype
  14.     setmetatable(o, self)
  15.     self.__index = self
  16.  
  17.     o.cells = {}
  18.     o:initializeCells()
  19.  
  20.     return o
  21. end
  22.  
  23. function Buffer:initializeCells()
  24.     local cell
  25.  
  26.     for x = 0, self.width - 1 do
  27.         for y = 0, self.height - 1 do
  28.             cell = Cell:new()
  29.             if not self.cells[x] then
  30.                 table.insert(self.cells, x, {[y] = cell})
  31.             else
  32.                 table.insert(self.cells[x], y, cell)
  33.             end
  34.         end
  35.     end
  36. end
  37.  
  38. function Buffer:fill(cell)
  39.     for x = 0, self.width - 1 do
  40.         for y = 0, self.height - 1 do
  41.             self.cells[x][y]:copy(cell)
  42.         end
  43.     end
  44. end
  45.  
  46. function Buffer:clear()
  47.     self:fill(Cell)
  48. end
  49.  
  50. return Buffer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement