main.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. local Main = class()
  2. local g = love.graphics
  3. function Main:activate()
  4. ctx.ribbon.count = 4
  5. ctx.ribbon.margin = .1
  6. if love.system.getClipboardText():match('%d+%.%d+%.%d+%.%d+') then
  7. ctx:connect(love.system.getClipboardText())
  8. end
  9. end
  10. function Main:draw()
  11. local u, v = ctx.u, ctx.v
  12. local anchor = (.3 + (.8 - .3) / 2) * v
  13. g.setFont('BebasNeue', .065 * v)
  14. g.setColor(160, 160, 160)
  15. g.printCenter('Host Game', .05 * u, anchor - ctx.ribbon.margin * v * 1.5, false, true)
  16. g.printCenter('Join Game', .05 * u, anchor - ctx.ribbon.margin * v * .5, false, true)
  17. g.printCenter('Editor', .05 * u, anchor + ctx.ribbon.margin * v * .5, false, true)
  18. g.printCenter('Exit', .05 * u, anchor + ctx.ribbon.margin * v * 1.5, false, true)
  19. end
  20. function Main:mousepressed(x, y, button)
  21. if button == 'l' then
  22. local ribbon = ctx.ribbon:test(x, y)
  23. if ribbon == 1 then self:host()
  24. elseif ribbon == 2 then self:join()
  25. elseif ribbon == 3 then self:edit()
  26. elseif ribbon == 4 then love.event.quit() end
  27. end
  28. end
  29. function Main:host()
  30. local success = app.net.goregous:createServer()
  31. if success then
  32. local server = app.util.context:add(app.context.server)
  33. server.owner = username
  34. ctx:connect('localhost')
  35. else
  36. ctx.alert:show('Problem creating server.')
  37. end
  38. end
  39. function Main:join()
  40. ctx:push('serverlist')
  41. end
  42. function Main:edit()
  43. app.util.context:remove(ctx)
  44. app.util.context:add(app.context.editor, ctx.options.data)
  45. end
  46. return Main