main.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. io.stdout:setvbuf("no")
  2. love.graphics.setDefaultFilter("nearest")
  3. require("api")
  4. function love.mousepressed(x,y,button,istouch)
  5. local x,y = _ScreenToLiko(x,y) if x < 0 or x > 192 or y < 0 or y > 128 then return end
  6. _auto_mpress(x,y,button,istouch)
  7. end
  8. function love.mousemoved(x,y,dx,dy,istouch)
  9. local x, y = _ScreenToLiko(x,y) if x < 0 or x > 192 or y < 0 or y > 128 then return end
  10. _auto_mmove(x,y,dx,dy,istouch)
  11. end
  12. function love.mousereleased(x,y,button,istouch)
  13. local x, y = _ScreenToLiko(x,y) if x < 0 or x > 192 or y < 0 or y > 128 then return end
  14. _auto_mrelease(x,y,button,istouch)
  15. end
  16. function love.wheelmoved(x,y)
  17. _auto_mmove(x,y,0,0,false,true) --Mouse button 0 is the wheel
  18. end
  19. function love.touchpressed(id,x,y,dx,dy,pressure)
  20. local x, y = _ScreenToLiko(x,y) if x < 0 or x > 192 or y < 0 or y > 128 then return end
  21. _auto_tpress(id,x,y,pressure)
  22. end
  23. function love.touchmoved(id,x,y,dx,dy,pressure)
  24. local x, y = _ScreenToLiko(x,y) if x < 0 or x > 192 or y < 0 or y > 128 then return end
  25. _auto_tmove(id,x,y,pressure)
  26. end
  27. function love.touchreleased(id,x,y,dx,dy,pressure)
  28. local x, y = _ScreenToLiko(x,y) if x < 0 or x > 192 or y < 0 or y > 128 then return end
  29. _auto_trelease(id,x,y,pressure)
  30. end
  31. function love.keypressed(key,scancode,isrepeat)
  32. _auto_kpress(key,scancode,isrepeat)
  33. end
  34. function love.keyreleased(key,scancode)
  35. _auto_krelease(key,scancode)
  36. end
  37. function love.textinput(text)
  38. _auto_tinput(text)
  39. end
  40. --Internal Callbacks--
  41. function love.load()
  42. --love.keyboard.setTextInput(true)
  43. loadDefaultCursors()
  44. _ScreenCanvas = love.graphics.newCanvas(192,128)
  45. _ScreenCanvas:setFilter("nearest")
  46. love.graphics.clear(0,0,0,255)
  47. love.graphics.setCanvas(_ScreenCanvas)
  48. love.graphics.clear(0,0,0,255)
  49. love.graphics.translate(_ScreenTX,_ScreenTY)
  50. love.resize(love.graphics.getDimensions())
  51. love.graphics.setLineStyle("rough")
  52. love.graphics.setLineJoin("miter")
  53. love.graphics.setFont(_Font)
  54. clear() --Clear the canvas for the first time
  55. stroke(1)
  56. require("autorun")
  57. --require("debugrun")
  58. --require("editor")
  59. _auto_startup()
  60. end
  61. function love.resize(w,h)
  62. _ScreenWidth, _ScreenHeight = w, h
  63. local TSX, TSY = w/192, h/128 --TestScaleX, TestScaleY
  64. if TSX < TSY then
  65. _ScreenScaleX, _ScreenScaleY, _ScreenScale = w/192, w/192, w/192
  66. _ScreenX, _ScreenY = 0, (_ScreenHeight-128*_ScreenScaleY)/2
  67. else
  68. _ScreenScaleX, _ScreenScaleY, _ScreenScale = h/128, h/128, h/128
  69. _ScreenX, _ScreenY = (_ScreenWidth-192*_ScreenScaleX)/2, 0
  70. end
  71. clearCursorsCache()
  72. _ShouldDraw = true
  73. end
  74. function love.update(dt)
  75. local mx, my = _ScreenToLiko(love.mouse.getPosition())
  76. love.window.setTitle(_ScreenTitle.." FPS: "..love.timer.getFPS().." ShouldDraw: "..(_ForceDraw and "FORCE" or (_ShouldDraw and "Yes" or "No")).." MX, MY: "..mx..","..my)
  77. _auto_update(dt)
  78. end
  79. function love.visible(v)
  80. _ForceDraw = not v
  81. _ShouldDraw = v
  82. end
  83. function love.focus(f)
  84. _ForceDraw = not f
  85. ShouldDraw = f
  86. end
  87. function love.run()
  88. if love.math then
  89. love.math.setRandomSeed(os.time())
  90. end
  91. if love.load then love.load(arg) end
  92. -- We don't want the first frame's dt to include time taken by love.load.
  93. if love.timer then love.timer.step() end
  94. local dt = 0
  95. -- Main loop time.
  96. while true do
  97. -- Process events.
  98. if love.event then
  99. love.event.pump()
  100. for name, a,b,c,d,e,f in love.event.poll() do
  101. if name == "quit" then
  102. if not love.quit or not love.quit() then
  103. return a
  104. end
  105. end
  106. love.handlers[name](a,b,c,d,e,f)
  107. end
  108. end
  109. -- Update dt, as we'll be passing it to update
  110. if love.timer then
  111. love.timer.step()
  112. dt = love.timer.getDelta()
  113. end
  114. -- Call update and draw
  115. if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
  116. if love.graphics and love.graphics.isActive() and (_ShouldDraw or _ForceDraw) then
  117. love.graphics.setCanvas()
  118. love.graphics.origin()
  119. love.graphics.setColor(255,255,255)
  120. love.graphics.draw(_ScreenCanvas, _ScreenX,_ScreenY, 0, _ScreenScaleX,_ScreenScaleY)
  121. --love.graphics.points(1,1,_ScreenWidth,_ScreenHeight)
  122. love.graphics.present()
  123. love.graphics.setCanvas(_ScreenCanvas)
  124. love.graphics.translate(_ScreenTX,_ScreenTY)
  125. _ShouldDraw = false
  126. end
  127. if love.timer then love.timer.sleep(0.001) end
  128. end
  129. end