SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --v2.1 |
| 1 | + | --v4 |
| 2 | local function update() | |
| 3 | - | shell.run("delete","lg")
|
| 3 | + | shell.run("delete","lgame")
|
| 4 | - | shell.run("pastebin","get","sSF7NPYC","lg")
|
| 4 | + | shell.run("pastebin","get","z3p689g1","lgame")
|
| 5 | os.reboot() | |
| 6 | end | |
| 7 | - | local args = {...}
|
| 7 | + | -- function syscal = setmetatable({}, {__index = function(self,idx)
|
| 8 | -- return function(...) | |
| 9 | -- local retval = table.pack(coroutine.yeild("syscall", idx, ...))
| |
| 10 | -- if retval[1] then return table.unpack(retval, 2, retval.n) | |
| 11 | -- else error(retval[2],2) end | |
| 12 | -- end | |
| 13 | -- end, __newindex = function() end}) | |
| 14 | local args = {...}
| |
| 15 | - | local bg = colors.black |
| 15 | + | |
| 16 | - | sprites = {}
|
| 16 | + | |
| 17 | end | |
| 18 | local tname = nil | |
| 19 | function getVersion() | |
| 20 | return "5.1" | |
| 21 | end | |
| 22 | - | term.redirect(m) |
| 22 | + | |
| 23 | sx,sy = nil | |
| 24 | buttons = {}
| |
| 25 | tname = name | |
| 26 | pixels = {}
| |
| 27 | local bg = colors.black | |
| 28 | sprites = {}
| |
| 29 | inputs = {}
| |
| 30 | oterm = term.current() | |
| 31 | if (name == "term") then | |
| 32 | sx,sy = term.getSize() | |
| 33 | local previous = term | |
| 34 | else | |
| 35 | m = peripheral.wrap(name) | |
| 36 | local previous = term.redirect(m) | |
| 37 | sx,sy = m.getSize() | |
| 38 | end | |
| 39 | end | |
| 40 | function createScene(x,y,w,h,visible) | |
| 41 | local window = window.create(term.current(), x, y, w,h,visible) | |
| 42 | local scene = {oterm=oterm,x=x,y=y,window = window, bg=colors.black,w=w,h=h,buttons = {}, pixels = {}, sprites = {}, inputs = {},
| |
| 43 | drawText = function (self, x,y,color,colorb,text) | |
| 44 | term.setCursorPos(x,y) | |
| 45 | term.setTextColor(color) | |
| 46 | term.setBackgroundColor(colorb) | |
| 47 | term.write(text) | |
| 48 | end, | |
| 49 | clearScreen = function () | |
| 50 | term.clear() | |
| 51 | end, | |
| 52 | setBackgroundColor = function (color) | |
| 53 | term.setBackgroundColor(color) | |
| 54 | end, | |
| 55 | setTextColor = function(color) | |
| 56 | term.setTextColor(color) | |
| 57 | end, | |
| 58 | drawBT = function(self,name,x,xe,y,ye,color,colorb,text) | |
| 59 | term.setBackgroundColor(colorb) | |
| 60 | term.setTextColor(color) | |
| 61 | for i=x,xe do | |
| 62 | for g=y,ye do | |
| 63 | term.setCursorPos(i,g) | |
| 64 | term.write(" ")
| |
| 65 | end | |
| 66 | end | |
| 67 | textline = (y + ye) / 2 | |
| 68 | textline = string.format("%.1f", textline)
| |
| 69 | textline = tonumber(textline) | |
| 70 | lines = {}
| |
| 71 | for word in string.gmatch(text,"[^\n]+") do | |
| 72 | table.insert(lines,word) | |
| 73 | end | |
| 74 | if (#lines > 1) then | |
| 75 | for w=1,#lines do | |
| 76 | term.setCursorPos(x,y+w) | |
| 77 | term.write(lines[w]) | |
| 78 | end | |
| 79 | else | |
| 80 | term.setCursorPos(x,textline) | |
| 81 | term.write(text) | |
| 82 | end | |
| 83 | table.insert(self.buttons,name..";"..x..";"..xe..";"..y..";"..ye) | |
| 84 | end, | |
| 85 | isButton = function(self,x,y) | |
| 86 | for i=1,#self.buttons do | |
| 87 | local parts = {}
| |
| 88 | for word in string.gmatch(self.buttons[i],"[^;]+") do | |
| 89 | table.insert(parts,word) | |
| 90 | end | |
| 91 | name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]) | |
| 92 | if (bx-1 < x and x < bxe + 1 ) then | |
| 93 | if (by-1 < y and bye+1 > y) then | |
| 94 | return name | |
| 95 | end | |
| 96 | end | |
| 97 | end | |
| 98 | return self.buttons[1] | |
| 99 | end, | |
| 100 | fill = function(self, x,x2,y,y2,color) | |
| 101 | term.setBackgroundColor(color) | |
| 102 | for i=x,x2 do | |
| 103 | for g=y,y2 do | |
| 104 | term.setCursorPos(i,g) | |
| 105 | self.pixels[x..y] = color | |
| 106 | term.write(" ")
| |
| 107 | end | |
| 108 | end | |
| 109 | end, | |
| 110 | drawRect = function(self,x,x2,y,y2,color) | |
| 111 | term.setBackgroundColor(color) | |
| 112 | for i=x,x2 do | |
| 113 | term.setCursorPos(i,y) | |
| 114 | self.pixels[x..y] = color | |
| 115 | term.write(" ")
| |
| 116 | end | |
| 117 | for i=y,y2 do | |
| 118 | term.setCursorPos(x2,i) | |
| 119 | self.pixels[x..y] = color | |
| 120 | term.write(" ")
| |
| 121 | end | |
| 122 | paintutils.drawLine(x2,y2,x,y2,color) | |
| 123 | paintutils.drawLine(x,y2,x,y,color) | |
| 124 | end, | |
| 125 | fillScreen = function(self,color) | |
| 126 | term.setBackgroundColor(color) | |
| 127 | term.clear() | |
| 128 | self.pixels = {}
| |
| 129 | end, | |
| 130 | drawImage = function(x,y,name) | |
| 131 | image = paintutils.loadImage(name) | |
| 132 | paintutils.drawImage(image,x,y) | |
| 133 | end, | |
| 134 | getSize = function(self) | |
| 135 | local sizet = {}
| |
| 136 | sizet.x = self.w | |
| 137 | - | function getInput(x,y) |
| 137 | + | sizet.y = self.h |
| 138 | return sizet | |
| 139 | end, | |
| 140 | drawInput = function(self,name,x,x2,y,y2,limit) | |
| 141 | term.setBackgroundColor(colors.gray) | |
| 142 | term.setTextColor(colors.white) | |
| 143 | for i=x,x2 do | |
| 144 | for g=y,y2 do | |
| 145 | term.setCursorPos(i,g) | |
| 146 | term.write(" ")
| |
| 147 | - | local text = limitRead(limit) |
| 147 | + | |
| 148 | end | |
| 149 | table.insert(self.inputs,name..";"..x..";"..x2..";"..y..";"..y2..";"..limit) | |
| 150 | end, | |
| 151 | isInput = function(self,x,y) | |
| 152 | for i=1,#self.inputs do | |
| 153 | local parts = {}
| |
| 154 | for word in string.gmatch(self.inputs[i],"[^;]+") do | |
| 155 | table.insert(parts,word) | |
| 156 | end | |
| 157 | name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]) | |
| 158 | if (bx-1 < x and x < bxe + 1 ) then | |
| 159 | if (by-1 < y and bye+1 > y) then | |
| 160 | return name | |
| 161 | end | |
| 162 | end | |
| 163 | end | |
| 164 | return false | |
| 165 | end, | |
| 166 | getInput = function(self,x,y) | |
| 167 | for i=1,#self.inputs do | |
| 168 | local parts = {}
| |
| 169 | for word in string.gmatch(self.inputs[i],"[^;]+") do | |
| 170 | table.insert(parts,word) | |
| 171 | end | |
| 172 | name,bx,bxe,by,bye,limit = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]),tonumber(parts[6]) | |
| 173 | if (bx-1 < x and x < bxe + 1 ) then | |
| 174 | if (by-1 < y and bye+1 > y) then | |
| 175 | term.setCursorPos(bx,by) | |
| 176 | local text = limitRead(limit) | |
| 177 | return text | |
| 178 | end | |
| 179 | end | |
| 180 | end | |
| 181 | return false | |
| 182 | end, | |
| 183 | lggSetDefBG = function(self,color) | |
| 184 | self.bg = color | |
| 185 | end, | |
| 186 | drawSprite = function(self,name,x,y,iname) | |
| 187 | image = paintutils.loadImage(iname) | |
| 188 | paintutils.drawImage(image,x,y) | |
| 189 | table.insert(self.sprites,name..";"..x..";"..y..";"..iname) | |
| 190 | end, | |
| 191 | changeImage = function(self,name,iname) | |
| 192 | for h=1,#self.sprites do | |
| 193 | local parts = {}
| |
| 194 | for word in string.gmatch(self.sprites[h],"[^;]+") do | |
| 195 | table.insert(parts,word) | |
| 196 | end | |
| 197 | if (parts[1] == name) then | |
| 198 | self.sprites[h] = parts[1]..";"..parts[2]..";"..parts[3]..";"..iname | |
| 199 | end | |
| 200 | end | |
| 201 | end, | |
| 202 | moveSprite = function(self,name,x,y,fill) | |
| 203 | for h=1,#self.sprites do | |
| 204 | local parts = {}
| |
| 205 | term.setBackgroundColor(colors.black) | |
| 206 | for word in string.gmatch(self.sprites[h],"[^;]+") do | |
| 207 | table.insert(parts,word) | |
| 208 | end | |
| 209 | if (parts[1] == name) then | |
| 210 | local iname = nil | |
| 211 | local name,ox,oy,iname = parts[1],tonumber(parts[2]),tonumber(parts[3]),parts[4] | |
| 212 | image = paintutils.loadImage(iname) | |
| 213 | term.setCursorPos(10,1) | |
| 214 | term.setBackgroundColor(colors.black) | |
| 215 | if (fill) then | |
| 216 | for i=ox,ox+getWidth(image) do | |
| 217 | for g=oy,oy+getHeight(image) do | |
| 218 | if (pixels[i..g] ~= nil) then | |
| 219 | term.setCursorPos(i,g) | |
| 220 | term.setBackgroundColor(pixels[i..g]) | |
| 221 | term.write(" ")
| |
| 222 | else | |
| 223 | term.setCursorPos(i,g) | |
| 224 | term.setBackgroundColor(bg) | |
| 225 | term.write(" ")
| |
| 226 | end | |
| 227 | end | |
| 228 | end | |
| 229 | end | |
| 230 | paintutils.drawImage(image,x,y) | |
| 231 | table.remove(self.sprites,h) | |
| 232 | table.insert(self.sprites,name..";"..x..";"..y..";"..iname) | |
| 233 | else | |
| 234 | end | |
| 235 | end | |
| 236 | - | function limitRead(limX, rChar,color,colorb) |
| 236 | + | return false |
| 237 | - | term.setBackgroundColor(colors.gray) |
| 237 | + | end, |
| 238 | - | term.setTextColor(colors.white) |
| 238 | + | getSpriteColider = function(self,name) |
| 239 | for h=1,#self.sprites do | |
| 240 | local parts = {}
| |
| 241 | term.setBackgroundColor(colors.black) | |
| 242 | for word in string.gmatch(self.sprites[h],"[^;]+") do | |
| 243 | table.insert(parts,word) | |
| 244 | end | |
| 245 | if (parts[1] == name) then | |
| 246 | local iname = nil | |
| 247 | local name,ox,oy,iname = parts[1],tonumber(parts[2]),tonumber(parts[3]),parts[4] | |
| 248 | image = paintutils.loadImage(iname) | |
| 249 | local sizet = {}
| |
| 250 | sizet.x = ox | |
| 251 | sizet.y = oy | |
| 252 | sizet.x2 = ox + getWidth(image) | |
| 253 | sizet.y2 = oy + getHeight(image) | |
| 254 | return sizet | |
| 255 | else | |
| 256 | end | |
| 257 | end | |
| 258 | return false | |
| 259 | end, | |
| 260 | isColiding = function(self,name, name2) | |
| 261 | for h=1,#self.sprites do | |
| 262 | local parts = {}
| |
| 263 | term.setBackgroundColor(colors.black) | |
| 264 | for word in string.gmatch(self.sprites[h],"[^;]+") do | |
| 265 | table.insert(parts,word) | |
| 266 | end | |
| 267 | if (parts[1] == name) then | |
| 268 | local iname = nil | |
| 269 | local nameo,ox,oy,iname = parts[1],tonumber(parts[2]),tonumber(parts[3]),parts[4] | |
| 270 | - | elseif event == "key" and p1 == 259 then --backspace |
| 270 | + | image = paintutils.loadImage(iname) |
| 271 | local sizet = {}
| |
| 272 | sizet.x = ox | |
| 273 | sizet.y = oy | |
| 274 | sizet.x2 = ox + getWidth(image) | |
| 275 | sizet.y2 = oy + getHeight(image) | |
| 276 | local allCord = {}
| |
| 277 | for a=sizet.x,sizet.x2 do | |
| 278 | for b=sizet.y,sizet.y2 do | |
| 279 | table.insert(allCord,a..";"..b) | |
| 280 | end | |
| 281 | end | |
| 282 | for g=1,#self.sprites do | |
| 283 | local parts2 = {}
| |
| 284 | for word2 in string.gmatch(self.sprites[g],"[^;]+") do | |
| 285 | table.insert(parts2,word2) | |
| 286 | end | |
| 287 | local nameo2,ox2,oy2,iname2 = parts2[1],tonumber(parts2[2]),tonumber(parts2[3]),parts2[4] | |
| 288 | - | elseif event == "key" and p1 == 257 then --enter |
| 288 | + | image2 = paintutils.loadImage(iname2) |
| 289 | ox22 = ox2 + getWidth(image2) | |
| 290 | oy22 = oy2 + getHeight(image2) | |
| 291 | if (nameo2 == name2) then | |
| 292 | local allCord2 = {}
| |
| 293 | for a=ox2,ox22 do | |
| 294 | for b=oy2,oy22 do | |
| 295 | table.insert(allCord2,a..";"..b) | |
| 296 | end | |
| 297 | end | |
| 298 | for i=1,#allCord do | |
| 299 | for g=1,#allCord2 do | |
| 300 | if (allCord[i] == allCord2[g]) then | |
| 301 | return true | |
| 302 | end | |
| 303 | end | |
| 304 | end | |
| 305 | end | |
| 306 | end | |
| 307 | end | |
| 308 | end | |
| 309 | return false | |
| 310 | end, | |
| 311 | draw = function(self) | |
| 312 | self.window.setVisible(true) | |
| 313 | self.window.restoreCursor() | |
| 314 | self.window.redraw() | |
| 315 | term.redirect(self.window) | |
| 316 | end, | |
| 317 | focus = function(self) | |
| 318 | self.window.restoreCursor() | |
| 319 | term.redirect(self.window) | |
| 320 | end, | |
| 321 | unfocus = function(self) | |
| 322 | if (tname == "term") then | |
| 323 | term.redirect(self.oterm) | |
| 324 | else | |
| 325 | term.redirect(m) | |
| 326 | end | |
| 327 | end, | |
| 328 | hide = function(self) | |
| 329 | self.window.setVisible(false) | |
| 330 | if (tname == "term") then | |
| 331 | term.redirect(self.oterm) | |
| 332 | else | |
| 333 | term.redirect(m) | |
| 334 | end | |
| 335 | paintutils.drawFilledBox(self.x, self.y, self.w, self.h, self.bg) | |
| 336 | ||
| 337 | end, | |
| 338 | getPos = function() | |
| 339 | return self.window.getPosition() | |
| 340 | end, | |
| 341 | rePos = function(self,x,y,h2,w2) | |
| 342 | if (h2 and w2) then | |
| 343 | self.window.reposition(x,y,h2,w2) | |
| 344 | else | |
| 345 | self.window.reposition(x,y) | |
| 346 | - | end |
| 346 | + | |
| 347 | end | |
| 348 | } | |
| 349 | if (visible) then | |
| 350 | term.redirect(window) | |
| 351 | end | |
| 352 | return scene | |
| 353 | end | |
| 354 | function exit() | |
| 355 | term.native() | |
| 356 | end | |
| 357 | function drawText(x,y,color,colorb,text) | |
| 358 | term.setCursorPos(x,y) | |
| 359 | term.setTextColor(color) | |
| 360 | term.setBackgroundColor(colorb) | |
| 361 | term.write(text) | |
| 362 | end | |
| 363 | function clearScreen() | |
| 364 | term.clear() | |
| 365 | end | |
| 366 | function setBackgroundColor(color) | |
| 367 | term.setBackgroundColor(color) | |
| 368 | end | |
| 369 | function setTextColor(color) | |
| 370 | term.setTextColor(color) | |
| 371 | end | |
| 372 | function drawBT(name,x,xe,y,ye,color,colorb,text) | |
| 373 | term.setBackgroundColor(colorb) | |
| 374 | term.setTextColor(color) | |
| 375 | for i=x,xe do | |
| 376 | for g=y,ye do | |
| 377 | term.setCursorPos(i,g) | |
| 378 | term.write(" ")
| |
| 379 | end | |
| 380 | end | |
| 381 | textline = (y + ye) / 2 | |
| 382 | textline = string.format("%.1f", textline)
| |
| 383 | textline = tonumber(textline) | |
| 384 | lines = {}
| |
| 385 | for word in string.gmatch(text,"[^\n]+") do | |
| 386 | table.insert(lines,word) | |
| 387 | end | |
| 388 | if (#lines > 1) then | |
| 389 | for w=1,#lines do | |
| 390 | term.setCursorPos(x,y+w) | |
| 391 | term.write(lines[w]) | |
| 392 | end | |
| 393 | else | |
| 394 | term.setCursorPos(x,textline) | |
| 395 | term.write(text) | |
| 396 | end | |
| 397 | table.insert(buttons,name..";"..x..";"..xe..";"..y..";"..ye) | |
| 398 | end | |
| 399 | function isButton(x,y) | |
| 400 | for i=1,#buttons do | |
| 401 | local parts = {}
| |
| 402 | for word in string.gmatch(buttons[i],"[^;]+") do | |
| 403 | table.insert(parts,word) | |
| 404 | end | |
| 405 | name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]) | |
| 406 | if (bx-1 < x and x < bxe + 1 ) then | |
| 407 | if (by-1 < y and bye+1 > y) then | |
| 408 | return name | |
| 409 | end | |
| 410 | end | |
| 411 | end | |
| 412 | return false | |
| 413 | end | |
| 414 | function clearBTNS() | |
| 415 | buttons = {}
| |
| 416 | end | |
| 417 | function fill(x,x2,y,y2,color) | |
| 418 | term.setBackgroundColor(color) | |
| 419 | for i=x,x2 do | |
| 420 | for g=y,y2 do | |
| 421 | term.setCursorPos(i,g) | |
| 422 | pixels[x..y] = color | |
| 423 | term.write(" ")
| |
| 424 | end | |
| 425 | end | |
| 426 | end | |
| 427 | function drawRect(x,x2,y,y2,color) | |
| 428 | term.setBackgroundColor(color) | |
| 429 | for i=x,x2 do | |
| 430 | term.setCursorPos(i,y) | |
| 431 | pixels[x..y] = color | |
| 432 | term.write(" ")
| |
| 433 | end | |
| 434 | for i=y,y2 do | |
| 435 | term.setCursorPos(x2,i) | |
| 436 | pixels[x..y] = color | |
| 437 | term.write(" ")
| |
| 438 | end | |
| 439 | paintutils.drawLine(x2,y2,x,y2,color) | |
| 440 | paintutils.drawLine(x,y2,x,y,color) | |
| 441 | end | |
| 442 | function fillScreen(color) | |
| 443 | term.setBackgroundColor(color) | |
| 444 | term.clear() | |
| 445 | pixels = {}
| |
| 446 | end | |
| 447 | function drawImage(x,y,name) | |
| 448 | image = paintutils.loadImage(name) | |
| 449 | paintutils.drawImage(image,x,y) | |
| 450 | end | |
| 451 | function getSize() | |
| 452 | local sizet = {}
| |
| 453 | sizet.x = sx | |
| 454 | sizet.y = sy | |
| 455 | return sizet | |
| 456 | end | |
| 457 | function drawInput(name,x,x2,y,y2,limit) | |
| 458 | term.setBackgroundColor(colors.gray) | |
| 459 | term.setTextColor(colors.white) | |
| 460 | for i=x,x2 do | |
| 461 | for g=y,y2 do | |
| 462 | term.setCursorPos(i,g) | |
| 463 | term.write(" ")
| |
| 464 | end | |
| 465 | end | |
| 466 | table.insert(inputs,name..";"..x..";"..x2..";"..y..";"..y2..";"..limit) | |
| 467 | end | |
| 468 | function isInput(x,y) | |
| 469 | for i=1,#inputs do | |
| 470 | local parts = {}
| |
| 471 | for word in string.gmatch(inputs[i],"[^;]+") do | |
| 472 | table.insert(parts,word) | |
| 473 | end | |
| 474 | name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]) | |
| 475 | if (bx-1 < x and x < bxe + 1 ) then | |
| 476 | if (by-1 < y and bye+1 > y) then | |
| 477 | return name | |
| 478 | end | |
| 479 | end | |
| 480 | end | |
| 481 | return false | |
| 482 | end | |
| 483 | function getInput(x,y,safe) | |
| 484 | for i=1,#inputs do | |
| 485 | local parts = {}
| |
| 486 | for word in string.gmatch(inputs[i],"[^;]+") do | |
| 487 | table.insert(parts,word) | |
| 488 | end | |
| 489 | name,bx,bxe,by,bye,limit = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]),tonumber(parts[6]) | |
| 490 | if (bx-1 < x and x < bxe + 1 ) then | |
| 491 | if (by-1 < y and bye+1 > y) then | |
| 492 | term.setCursorPos(bx,by) | |
| 493 | local text = limitRead(limit, safe) | |
| 494 | return text | |
| 495 | end | |
| 496 | end | |
| 497 | end | |
| 498 | return false | |
| 499 | end | |
| 500 | function lggSetDefBG(color) | |
| 501 | bg = color | |
| 502 | end | |
| 503 | function drawSprite(name,x,y,iname) | |
| 504 | image = paintutils.loadImage(iname) | |
| 505 | paintutils.drawImage(image,x,y) | |
| 506 | table.insert(sprites,name..";"..x..";"..y..";"..iname) | |
| 507 | end | |
| 508 | function moveSprite(name,x,y) | |
| 509 | for h=1,#sprites do | |
| 510 | local parts = {}
| |
| 511 | term.setBackgroundColor(colors.black) | |
| 512 | for word in string.gmatch(sprites[h],"[^;]+") do | |
| 513 | table.insert(parts,word) | |
| 514 | end | |
| 515 | if (parts[1] == name) then | |
| 516 | local iname = nil | |
| 517 | local name,ox,oy,iname = parts[1],tonumber(parts[2]),tonumber(parts[3]),parts[4] | |
| 518 | image = paintutils.loadImage(iname) | |
| 519 | term.setCursorPos(10,1) | |
| 520 | term.setBackgroundColor(colors.black) | |
| 521 | for i=ox,ox+getWidth(image) do | |
| 522 | for g=oy,oy+getHeight(image) do | |
| 523 | if (pixels[i..g] ~= nil) then | |
| 524 | term.setCursorPos(i,g) | |
| 525 | term.setBackgroundColor(pixels[i..g]) | |
| 526 | term.write(" ")
| |
| 527 | else | |
| 528 | term.setCursorPos(i,g) | |
| 529 | term.setBackgroundColor(bg) | |
| 530 | term.write(" ")
| |
| 531 | end | |
| 532 | end | |
| 533 | end | |
| 534 | paintutils.drawImage(image,x,y) | |
| 535 | table.remove(sprites,h) | |
| 536 | table.insert(sprites,name..";"..x..";"..y..";"..iname) | |
| 537 | else | |
| 538 | end | |
| 539 | end | |
| 540 | return false | |
| 541 | end | |
| 542 | function getSpriteColider(name) | |
| 543 | for h=1,#sprites do | |
| 544 | local parts = {}
| |
| 545 | term.setBackgroundColor(colors.black) | |
| 546 | for word in string.gmatch(sprites[h],"[^;]+") do | |
| 547 | table.insert(parts,word) | |
| 548 | end | |
| 549 | if (parts[1] == name) then | |
| 550 | local iname = nil | |
| 551 | local name,ox,oy,iname = parts[1],tonumber(parts[2]),tonumber(parts[3]),parts[4] | |
| 552 | image = paintutils.loadImage(iname) | |
| 553 | local sizet = {}
| |
| 554 | sizet.x = ox | |
| 555 | sizet.y = oy | |
| 556 | sizet.x2 = ox + getWidth(image) | |
| 557 | sizet.y2 = oy + getHeight(image) | |
| 558 | return sizet | |
| 559 | else | |
| 560 | end | |
| 561 | end | |
| 562 | return false | |
| 563 | end | |
| 564 | function isColiding(name, name2) | |
| 565 | for h=1,#sprites do | |
| 566 | local parts = {}
| |
| 567 | term.setBackgroundColor(colors.black) | |
| 568 | for word in string.gmatch(sprites[h],"[^;]+") do | |
| 569 | table.insert(parts,word) | |
| 570 | end | |
| 571 | if (parts[1] == name) then | |
| 572 | local iname = nil | |
| 573 | local nameo,ox,oy,iname = parts[1],tonumber(parts[2]),tonumber(parts[3]),parts[4] | |
| 574 | image = paintutils.loadImage(iname) | |
| 575 | local sizet = {}
| |
| 576 | sizet.x = ox | |
| 577 | sizet.y = oy | |
| 578 | sizet.x2 = ox + getWidth(image) | |
| 579 | sizet.y2 = oy + getHeight(image) | |
| 580 | local allCord = {}
| |
| 581 | for a=sizet.x,sizet.x2 do | |
| 582 | for b=sizet.y,sizet.y2 do | |
| 583 | table.insert(allCord,a..";"..b) | |
| 584 | end | |
| 585 | end | |
| 586 | for g=1,#sprites do | |
| 587 | local parts2 = {}
| |
| 588 | for word2 in string.gmatch(sprites[g],"[^;]+") do | |
| 589 | table.insert(parts2,word2) | |
| 590 | end | |
| 591 | local nameo2,ox2,oy2,iname2 = parts2[1],tonumber(parts2[2]),tonumber(parts2[3]),parts2[4] | |
| 592 | image2 = paintutils.loadImage(iname2) | |
| 593 | ox22 = ox2 + getWidth(image2) | |
| 594 | oy22 = oy2 + getHeight(image2) | |
| 595 | if (nameo2 == name2) then | |
| 596 | local allCord2 = {}
| |
| 597 | for a=ox2,ox22 do | |
| 598 | for b=oy2,oy22 do | |
| 599 | table.insert(allCord2,a..";"..b) | |
| 600 | end | |
| 601 | end | |
| 602 | for i=1,#allCord do | |
| 603 | for g=1,#allCord2 do | |
| 604 | if (allCord[i] == allCord2[g]) then | |
| 605 | return true | |
| 606 | end | |
| 607 | end | |
| 608 | end | |
| 609 | end | |
| 610 | end | |
| 611 | end | |
| 612 | end | |
| 613 | return false | |
| 614 | end | |
| 615 | ||
| 616 | ||
| 617 | ||
| 618 | ||
| 619 | ||
| 620 | ||
| 621 | ||
| 622 | ||
| 623 | ||
| 624 | ||
| 625 | ||
| 626 | ||
| 627 | ||
| 628 | ||
| 629 | ||
| 630 | ||
| 631 | ||
| 632 | ||
| 633 | -- FUNC | |
| 634 | function limitRead(limX, safe, rChar) | |
| 635 | term.setBackgroundColor(colors.gray) | |
| 636 | term.setTextColor(colors.white) | |
| 637 | term.setCursorBlink(true) | |
| 638 | local origX, origY = term.getCursorPos() | |
| 639 | local returnString = "" | |
| 640 | while true do | |
| 641 | local xPos, yPos = term.getCursorPos() | |
| 642 | local event, p1, p2 = os.pullEvent() | |
| 643 | if event == "char" then | |
| 644 | if safe and p1 == "-" or safe and p1 == "." or safe and p1 == "," then | |
| 645 | else | |
| 646 | returnString = returnString..p1 | |
| 647 | if not rChar then | |
| 648 | if not limX then | |
| 649 | write(p1) | |
| 650 | else | |
| 651 | if string.len(returnString) >= limX then | |
| 652 | term.setCursorPos(origX, origY) | |
| 653 | write(string.sub(returnString, (string.len(returnString)-limX)+1)) | |
| 654 | elseif string.len(returnString) < limX then | |
| 655 | write(p1) | |
| 656 | end | |
| 657 | end | |
| 658 | else | |
| 659 | if not limX then | |
| 660 | write(rChar) | |
| 661 | else | |
| 662 | if string.len(returnString) >= limX then | |
| 663 | term.setCursorPos(origX, origY) | |
| 664 | write(string.rep(rChar, limX)) | |
| 665 | elseif string.len(returnString) < limX then | |
| 666 | write(rChar) | |
| 667 | end | |
| 668 | end | |
| 669 | end | |
| 670 | end | |
| 671 | elseif event == "key" and p1 == keys.backspace and string.len(returnString) > 0 then --backspace | |
| 672 | returnString = string.sub(returnString, 1, (string.len(returnString))-1) | |
| 673 | term.setCursorPos(xPos-1,yPos) | |
| 674 | write(" ")
| |
| 675 | term.setCursorPos(origX, origY) | |
| 676 | if string.len(returnString) >= limX then | |
| 677 | if not rChar then | |
| 678 | write(string.sub(returnString, (string.len(returnString)-limX)+1)) | |
| 679 | else | |
| 680 | write(string.rep(rChar,limX)) | |
| 681 | end | |
| 682 | else | |
| 683 | if not rChar then | |
| 684 | write(returnString) | |
| 685 | else | |
| 686 | write(string.rep(rChar, string.len(returnString))) | |
| 687 | end | |
| 688 | end | |
| 689 | elseif event == "key" and p1 == keys.enter then --enter | |
| 690 | break | |
| 691 | end | |
| 692 | end | |
| 693 | term.setCursorBlink(false) | |
| 694 | return returnString | |
| 695 | end | |
| 696 | function getHeight( image ) | |
| 697 | --# init the image start and end variables, these are what track where the start and end are | |
| 698 | local imgStart = #image --# we need to start at the end so we can apply math.min | |
| 699 | local imgEnd = 0 --# we need to start at the start so we can apply math.max | |
| 700 | --# loop through the table | |
| 701 | for index,imageLine in ipairs(image) do | |
| 702 | --# create a variable to hold if the line has a pixel | |
| 703 | local isLine = false | |
| 704 | --# loop through the pixels in the line | |
| 705 | for i,pixel in ipairs(imageLine) do | |
| 706 | --# if the pixel is drawable | |
| 707 | if pixel ~= 0 then | |
| 708 | --# record that there is a pixel, and exit the loop, no need to check anymore, we know there is at least 1 | |
| 709 | isLine = true | |
| 710 | break | |
| 711 | end | |
| 712 | end | |
| 713 | --# if the line has pixels, check if its the start or end | |
| 714 | if isLine then | |
| 715 | imgStart = math.min(imgStart,index) | |
| 716 | imgEnd = math.max(imgEnd,index) | |
| 717 | end | |
| 718 | end | |
| 719 | --# return the height of the image, which is the end plus the start, plus 1 because tables start at index 1 not 0 | |
| 720 | return imgEnd - imgStart + 1 | |
| 721 | end | |
| 722 | function getWidth(img) | |
| 723 | --# the max width | |
| 724 | local maxWidth = 0 | |
| 725 | --# loop through the image | |
| 726 | for i,line in pairs(img) do | |
| 727 | --# the variable to hold where the line starts | |
| 728 | local lineStart = #line --# start it at the end so we can apply math.min | |
| 729 | --# the variable to hold where the line ends | |
| 730 | local lineEnd = 0 --# start at the start so we can apply math.max | |
| 731 | --# loop the line | |
| 732 | for index,v in pairs(line) do | |
| 733 | --# if its a pixel | |
| 734 | if v ~= 0 then | |
| 735 | --# check if its the start or the end of the line | |
| 736 | lineStart = math.min(lineStart,index) | |
| 737 | lineEnd = math.max(lineEnd,index) | |
| 738 | end | |
| 739 | end | |
| 740 | --# the length of the line is the end minus the start positions, +1 because tables start at index 1 not 0 | |
| 741 | local length = lineEnd - lineStart + 1 | |
| 742 | --# check if its the max length | |
| 743 | maxWidth = math.max(maxWidth, length) | |
| 744 | end | |
| 745 | --# return the max length | |
| 746 | return maxWidth | |
| 747 | end | |
| 748 | return {getVersion = getVersion, getSize = getSize, fill = fill, fillScreen = fillScreen, createScene = createScene, setup = setup, exit = exit, drawBT = drawBT, drawText = drawText, drawInput = drawInput, drawSprite = drawSprite, drawImage = drawImage, setBackgroundColor = setBackgroundColor, setTextColor = setTextColor, clear = clear, isButton = isButton, isInput = isInput, moveSprite = moveSprite, isColiding = isColiding, lggSetDefBG = lggSetDefBG, getSpriteColider = getSpriteColider, clearBTNS = clearBTNS, getInput = getInput} |