Browse Source

Finish cargoification; Goodbye require.lua;

bjorn 9 năm trước cách đây
mục cha
commit
cb20654e10
55 tập tin đã thay đổi với 295 bổ sung260 xóa
  1. 2 2
      app/core/game.lua
  2. 20 16
      app/core/net.lua
  3. 1 1
      app/core/server.lua
  4. 1 1
      app/core/spell.lua
  5. 1 1
      app/editor/context.lua
  6. 4 2
      app/hud/blood.lua
  7. 4 2
      app/hud/buffs.lua
  8. 12 10
      app/hud/chat.lua
  9. 13 11
      app/hud/classSelect.lua
  10. 20 18
      app/hud/controller.lua
  11. 4 2
      app/hud/dead.lua
  12. 4 2
      app/hud/debug.lua
  13. 9 7
      app/hud/feed.lua
  14. 6 4
      app/hud/gameOver.lua
  15. 6 4
      app/hud/health.lua
  16. 6 4
      app/hud/icons.lua
  17. 7 5
      app/hud/killPopup.lua
  18. 6 4
      app/hud/left.lua
  19. 4 2
      app/hud/players.lua
  20. 4 2
      app/hud/right.lua
  21. 10 8
      app/hud/scoreboard.lua
  22. 1 1
      app/map.lua
  23. 7 5
      app/menu/alert.lua
  24. 5 3
      app/menu/back.lua
  25. 4 2
      app/menu/background.lua
  26. 12 10
      app/menu/context.lua
  27. 11 9
      app/menu/input.lua
  28. 9 7
      app/menu/login.lua
  29. 9 7
      app/menu/main.lua
  30. 5 3
      app/menu/options.lua
  31. 5 4
      app/menu/ribbon.lua
  32. 7 6
      app/menu/serverList.lua
  33. 11 11
      app/netclient.lua
  34. 31 31
      app/netserver.lua
  35. 1 1
      app/patcher.lua
  36. 1 1
      app/player.lua
  37. 1 1
      app/playermain.lua
  38. 7 7
      app/players.lua
  39. 4 4
      app/playerserver.lua
  40. 1 1
      data/buff/adrenaline.lua
  41. 1 1
      data/mods/deathmatch.lua
  42. 4 4
      data/mods/epidemic.lua
  43. 1 1
      data/mods/scoring.lua
  44. 1 1
      data/prop/cartserver.lua
  45. 2 2
      data/skill/bloodlust.lua
  46. 1 1
      data/skill/cleave.lua
  47. 1 1
      data/skill/overexertion.lua
  48. 2 2
      data/skill/subterfuge.lua
  49. 1 1
      data/spell/lazor.lua
  50. 1 1
      data/spell/plasmacannon.lua
  51. 1 1
      data/spell/shotgun.lua
  52. 1 1
      data/spell/smg.lua
  53. 0 0
      lib/typo.lua
  54. 2 3
      main.lua
  55. 0 18
      require.lua

+ 2 - 2
app/core/game.lua

@@ -16,11 +16,11 @@ function Game:load(options)
   self.effects = app.core.effects()
   self.sound = app.core.sound()
   self.map = app.map()
-  self.hud = Hud()
+  self.hud = app.hud.controller()
 
   self.event:on('game.quit', function(data)
     app.core.context:remove(ctx)
-    app.core.context:add(Menu)
+    app.core.context:add(app.menu.context)
   end)
 end
 

+ 20 - 16
app/core/net.lua

@@ -1,22 +1,26 @@
 local Net = class()
 
-evtJoin = 1
-evtLeave = 2
-evtClass = 3
-evtSync = 4
-evtFire = 5
-evtDamage = 6
-evtDead = 7
-evtSpawn = 8
-evtChat = 9
-evtProp = 10
+Net.events = {
+  join = 1,
+  leave = 2,
+  class = 3,
+  sync = 4,
+  fire = 5,
+  damage = 6,
+  dead = 7,
+  spawn = 8,
+  chat = 9,
+  prop = 10
+}
 
-msgJoin  = 11
-msgLeave = 12
-msgSnapshot = 13
-msgClass = 14
-msgInput = 15
-msgChat = 16
+Net.messages = {
+  join  = 11,
+  leave = 12,
+  snapshot = 13,
+  class = 14,
+  input = 15,
+  chat = 16
+}
 
 function Net:init()
   self.inStream = app.core.stream()

+ 1 - 1
app/core/server.lua

@@ -14,7 +14,7 @@ function Server:load()
   for i = 1, 0 do
     local p = self.players.players[i]
     setmetatable(p, {__index = app.playerRobot})
-    self.net:emit(evtClass, {id = i, class = 1, team = i % 2})
+    self.net:emit(app.core.net.events.class, {id = i, class = 1, team = i % 2})
   end
 
   self.event:on('game.quit', function()

+ 1 - 1
app/core/spell.lua

@@ -109,7 +109,7 @@ function Spell:damage(enemies, amount)
   amount = f.val(amount)
 
   table.each(enemies, function(enemy)
-    ctx.net:emit(evtDamage, {id = enemy.id, from = self.owner.id, amount = amount(enemy), tick = tick})
+    ctx.net:emit(app.core.net.events.damage, {id = enemy.id, from = self.owner.id, amount = amount(enemy), tick = tick})
   end)
 end
 

+ 1 - 1
app/editor/context.lua

@@ -52,7 +52,7 @@ end
 function Editor:keyreleased(key)
   if key == 'escape' then
     app.core.context:remove(ctx)
-    app.core.context:add(Menu)
+    app.core.context:add(app.menu.context)
   end
 end
 

+ 4 - 2
data/hud/hudblood.lua → app/hud/blood.lua

@@ -1,6 +1,6 @@
-HudBlood = class()
+local Blood = class()
 
-function HudBlood:draw()
+function Blood:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   local p = ctx.players:get(ctx.id)
   if p then
@@ -11,3 +11,5 @@ function HudBlood:draw()
     love.graphics.draw(image, 0, 0, 0, u / image:getWidth(), v / image:getHeight())
   end
 end
+
+return Blood

+ 4 - 2
data/hud/hudbuffs.lua → app/hud/buffs.lua

@@ -1,8 +1,8 @@
-HudBuffs = class()
+local Buffs = class()
 
 local g = love.graphics
 
-function HudBuffs:draw()
+function Buffs:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   local p = ctx.players:get(ctx.id)
   if p then
@@ -16,3 +16,5 @@ function HudBuffs:draw()
     end)
   end
 end
+
+return Buffs

+ 12 - 10
data/hud/hudchat.lua → app/hud/chat.lua

@@ -1,9 +1,9 @@
-HudChat = class()
+local Chat = class()
 
 local g = love.graphics
 local w, h = g.width, g.height
 
-function HudChat:init()
+function Chat:init()
   self.active = false
   self.message = ''
   self.log = ''
@@ -12,14 +12,14 @@ function HudChat:init()
   self.richText = nil
 end
 
-function HudChat:update()
+function Chat:update()
   local u, v = ctx.hud.u, ctx.hud.v
   self.timer = timer.rot(self.timer)
   if self.active then self.timer = 2 end
   self.offset = math.lerp(self.offset, (self.timer == 0) and -(u * .35) - 4 or 0, math.min(tickRate * 30, 1))
 end
 
-function HudChat:draw()
+function Chat:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   local width = u * .35
   if not self.richText then return end
@@ -47,19 +47,19 @@ function HudChat:draw()
   end
 end
 
-function HudChat:textinput(character)
+function Chat:textinput(character)
   if self.active then
     self.message = self.message .. character
     ctx.event:emit('sound.play', {sound = 'click', gui = true})
   end
 end
 
-function HudChat:keypressed(key)
+function Chat:keypressed(key)
   if self.active then
     if key == 'backspace' then self.message = self.message:sub(1, -2)
     elseif key == 'return' or key == 'escape' then
       if #self.message > 0 and key ~= 'escape' then
-        ctx.net:send(msgChat, {
+        ctx.net:send(app.core.net.messages.chat, {
           message = self.message
         })
       end
@@ -76,7 +76,7 @@ function HudChat:keypressed(key)
   end
 end
 
-function HudChat:add(data)
+function Chat:add(data)
   local message = data.message
   local u, v = ctx.hud.u, ctx.hud.v
   local width = u * .35
@@ -97,12 +97,14 @@ function HudChat:add(data)
   self.timer = math.min(2 + (#message / 50), 5)
 end
 
-function HudChat:resize()
+function Chat:resize()
   self:refresh()
 end
 
-function HudChat:refresh(width)
+function Chat:refresh(width)
   local u, v = ctx.hud.u, ctx.hud.v
   local width = u * .35
   self.richText = lib.richtext:new({self.log, width, white = {255, 255, 255}, purple = {190, 160, 220}, orange = {240, 160, 140}, red = {255, 0, 0}, green = {0, 255, 0}})
 end
+
+return Chat

+ 13 - 11
data/hud/hudclassselect.lua → app/hud/classSelect.lua

@@ -1,8 +1,8 @@
-HudClassSelect = class()
+local ClassSelect = class()
 
 local g = love.graphics
 
-function HudClassSelect:init()
+function ClassSelect:init()
   self.team = love.math.random(purple, orange)
   self.angle = 0
   self.active = true
@@ -11,12 +11,12 @@ function HudClassSelect:init()
   self.utility = 0
   self.teamCt = {0, 0}
 
-  ctx.event:on(evtClass, function(data)
+  ctx.event:on(app.core.net.events.class, function(data)
     if data.id == ctx.id then self.active = false end
   end)
 end
 
-function HudClassSelect:update()
+function ClassSelect:update()
   self.angle = (self.angle + .65 * tickRate) % (2 * math.pi)
   if not love.mouse.isVisible() then love.mouse.setVisible(true) end
 
@@ -38,7 +38,7 @@ function HudClassSelect:update()
   end)
 end
 
-function HudClassSelect:draw()
+function ClassSelect:draw()
   local u, v = ctx.hud.u, ctx.hud.v
 
   g.setColor(0, 0, 0, 153)
@@ -105,14 +105,14 @@ function HudClassSelect:draw()
   g.print(self.teamCt[1], u * .5 + math.max(u * .05, g.getFont():getWidth(tostring(self.teamCt[0]))), v * .106)
 end
 
-function HudClassSelect:keypressed(key)
+function ClassSelect:keypressed(key)
   if key == 'escape' and ctx.players:get(ctx.id).class then self.active = not self.active end
 
   if self.active then
     for i = 1, #data.class do
       local class = data.class[data.class.list[i]]
       if not class.locked and key == tostring(i) then
-        ctx.net:send(msgClass, {
+        ctx.net:send(app.core.net.messages.class, {
           class = i,
           team = ctx.id > 1 and 1 or 0
         })
@@ -124,16 +124,16 @@ function HudClassSelect:keypressed(key)
   end
 end
 
-function HudClassSelect:mousepressed() return self.active end
+function ClassSelect:mousepressed() return self.active end
 
-function HudClassSelect:mousereleased(x, y, button)
+function ClassSelect:mousereleased(x, y, button)
   local u, v = ctx.hud.u, ctx.hud.v
   x, y = ctx.view:frameMouseX(), ctx.view:frameMouseY()
 
   if self.active and button == 'l' then
     for i = 1, #data.class.list do
       if not data.class[data.class.list[i]].locked and math.inside(x, y, u * .09 * i, v * .326, u * .08, u * .08) then
-        ctx.net:send(msgClass, {
+        ctx.net:send(app.core.net.messages.class, {
           class = i,
           team = self.team
         })
@@ -159,7 +159,7 @@ function HudClassSelect:mousereleased(x, y, button)
   return self.active
 end
 
-function HudClassSelect:drawClassDetails(class)
+function ClassSelect:drawClassDetails(class)
   local u, v = ctx.hud.u, ctx.hud.v
   local fh = g.getFont():getHeight()
   local yy = v * .318
@@ -202,3 +202,5 @@ function HudClassSelect:drawClassDetails(class)
   g.setFont('BebasNeue', v * .065)
   g.setColor(255, 255, 255)
 end
+
+return ClassSelect

+ 20 - 18
data/hud/hud.lua → app/hud/controller.lua

@@ -1,27 +1,27 @@
-Hud = class()
+local Hud = class()
 
 local g = love.graphics
 
 function Hud:init()
   self._debug = false
 
-  self.players = HudPlayers()
-  self.blood = HudBlood()
-  self.left = HudLeft()
-  self.health = HudHealth()
-  self.icons = HudIcons()
-  self.right = HudRight()
-  self.buffs = HudBuffs()
-  self.feed = HudFeed()
-  self.chat = HudChat()
-  self.scoreboard = HudScoreboard()
-  self.dead = HudDead()
-  self.killPopup = HudKillPopup()
-  self.gameOver = HudGameOver()
-  self.classSelect = HudClassSelect()
-  self.debug = HudDebug()
-
-  ctx.event:on(evtChat, function(data) self.chat:add(data) end)
+  self.players = app.hud.players()
+  self.blood = app.hud.blood()
+  self.left = app.hud.left()
+  self.health = app.hud.health()
+  self.icons = app.hud.icons()
+  self.right = app.hud.right()
+  self.buffs = app.hud.buffs()
+  self.feed = app.hud.feed()
+  self.chat = app.hud.chat()
+  self.scoreboard = app.hud.scoreboard()
+  self.dead = app.hud.dead()
+  self.killPopup = app.hud.killPopup()
+  self.gameOver = app.hud.gameOver()
+  self.classSelect = app.hud.classSelect()
+  self.debug = app.hud.debug()
+
+  ctx.event:on(app.core.net.events.chat, function(data) self.chat:add(data) end)
   ctx.view:register(self, 'gui')
 
   self.u = ctx.view.frame.width
@@ -120,3 +120,5 @@ function Hud:crosshair()
     end
   end
 end
+
+return Hud

+ 4 - 2
data/hud/huddead.lua → app/hud/dead.lua

@@ -1,6 +1,6 @@
-HudDead = class()
+local Dead = class()
 
-function HudDead:draw()
+function Dead:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   local p = ctx.players:get(ctx.id)
   if p and p.ded then
@@ -12,3 +12,5 @@ function HudDead:draw()
     love.graphics.printCenter(val, u * .5, v * .5)
   end
 end
+
+return Dead

+ 4 - 2
data/hud/huddebug.lua → app/hud/debug.lua

@@ -1,8 +1,8 @@
-HudDebug = class()
+local Debug = class()
 
 local g = love.graphics
 
-function HudDebug:draw()
+function Debug:draw()
   if env ~= 'release' then
     ctx.players:each(function(p)
       g.push()
@@ -32,3 +32,5 @@ function HudDebug:draw()
   g.setFont('aeromatics', ctx.hud.v * .02)
   g.print(debug, ctx.hud.u - g.getFont():getWidth(debug), ctx.hud.v - g.getFont():getHeight())
 end
+
+return Debug

+ 9 - 7
data/hud/hudfeed.lua → app/hud/feed.lua

@@ -1,15 +1,15 @@
-HudFeed = class()
+local Feed = class()
 
 local g = love.graphics
 
-function HudFeed:init()
+function Feed:init()
   self.entries = {}
   self.alpha = 0
 
-  ctx.event:on(evtDead, function(data) self:insert(data) end)
+  ctx.event:on(app.core.net.events.dead, function(data) self:insert(data) end)
 end
 
-function HudFeed:update()
+function Feed:update()
   for i = 1, #self.entries do
     local k = self.entries[i]
     k.x = math.lerp(k.x, k.targetX, 30 * tickRate)
@@ -23,7 +23,7 @@ function HudFeed:update()
   end
 end
 
-function HudFeed:draw()
+function Feed:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   g.setFont('pixel', 8)
   local font = g.getFont()
@@ -51,7 +51,7 @@ function HudFeed:draw()
   end
 end
 
-function HudFeed:insert(data)
+function Feed:insert(data)
   local u, v = ctx.hud.u, ctx.hud.v
   g.setFont('pixel', 8)
   local font = g.getFont()
@@ -71,7 +71,7 @@ function HudFeed:insert(data)
   self.alpha = 4
 end
 
-function HudFeed:resize()
+function Feed:resize()
   local u, v = ctx.hud.u, ctx.hud.v
   g.setFont('pixel', 8)
   local font = g.getFont()
@@ -87,3 +87,5 @@ function HudFeed:resize()
     entry.y = entry.targetY
   end
 end
+
+return Feed

+ 6 - 4
data/hud/hudgameover.lua → app/hud/gameOver.lua

@@ -1,10 +1,10 @@
-HudGameOver = class()
+local GameOver = class()
 
-function HudGameOver:init()
+function GameOver:init()
   self.alpha = 0
 end
 
-function HudGameOver:update()
+function GameOver:update()
   if ctx.map.mods.scoring and ctx.map.mods.scoring.winner then
     self.alpha = math.lerp(self.alpha, 1, math.min(5 * tickRate, 1))
   else
@@ -12,7 +12,7 @@ function HudGameOver:update()
   end
 end
 
-function HudGameOver:draw()
+function GameOver:draw()
   if not ctx.map.mods.scoring or not ctx.map.mods.scoring.winner then return end
   local u, v = ctx.hud.u, ctx.hud.v
   local p = ctx.players:get(ctx.id)
@@ -25,3 +25,5 @@ function HudGameOver:draw()
   g.setColor(p.team == ctx.map.mods.scoring.winner and (p.team == purple and {190, 160, 200} or {240, 160, 140}) or {150, 0, 0})
   g.printCenter(str, u * .5, v * .5)
 end
+
+return GameOver

+ 6 - 4
data/hud/hudhealth.lua → app/hud/health.lua

@@ -1,15 +1,15 @@
-HudHealth = class()
+Health = class()
 
 local g = love.graphics
 
-function HudHealth:init()
+function Health:init()
   local health = data.media.graphics.hud.health
   self.canvas = g.newCanvas(health:getWidth(), health:getHeight())
   self.val = 0
   self.prevVal = 0
 end
 
-function HudHealth:update()
+function Health:update()
   local p = ctx.players:get(ctx.id)
   if p then
     self.prevVal = self.val
@@ -17,7 +17,7 @@ function HudHealth:update()
   end
 end
 
-function HudHealth:draw()
+function Health:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   local p = ctx.players:get(ctx.id)
 
@@ -53,3 +53,5 @@ function HudHealth:draw()
     g.printCenter(math.ceil(p.health) .. ' / ' .. p.maxHealth, u * .5, data.media.graphics.hud.health:getHeight() * s / 2 + (v * .003))
   end
 end
+
+return Health

+ 6 - 4
data/hud/hudicons.lua → app/hud/icons.lua

@@ -1,9 +1,9 @@
-HudIcons = class()
+local Icons = class()
 
 local g = love.graphics
 local w, h = g.width, g.height
 
-function HudIcons:init()
+function Icons:init()
   self.prevLabelAlphas = {}
   self.labelAlphas = {}
   for i = 1, 5 do
@@ -12,7 +12,7 @@ function HudIcons:init()
   end
 end
 
-function HudIcons:update()
+function Icons:update()
   local p = ctx.players:get(ctx.id)
   if p then
     for i = 1, 5 do
@@ -28,7 +28,7 @@ function HudIcons:update()
   end
 end
 
-function HudIcons:draw()
+function Icons:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   local top = v * .1
   local p = ctx.players:get(ctx.id)
@@ -104,3 +104,5 @@ function HudIcons:draw()
     end
   end
 end
+
+return Icons

+ 7 - 5
data/hud/hudkillpopup.lua → app/hud/killPopup.lua

@@ -1,13 +1,13 @@
-HudKillPopup = class()
+local KillPopup = class()
 
 local g = love.graphics
 
-function HudKillPopup:init()
+function KillPopup:init()
   self.streak = {}
   self.multikill = {}
   self.multikillTick = {}
   self.feed = {}
-  ctx.event:on(evtDead, function(data)
+  ctx.event:on(app.core.net.events.dead, function(data)
     self.streak[data.id] = 0
     if data.id ~= data.kill then
       self.multikill[data.kill] = self.multikill[data.kill] or 0
@@ -31,7 +31,7 @@ function HudKillPopup:init()
   end)
 end
 
-function HudKillPopup:update()
+function KillPopup:update()
   local u, v = ctx.hud.u, ctx.hud.v
   local ty = v * .22
   for i = 1, #self.feed do
@@ -50,7 +50,7 @@ function HudKillPopup:update()
   end
 end
 
-function HudKillPopup:draw()
+function KillPopup:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   for i = 1, #self.feed do
     local f = self.feed[i]
@@ -75,3 +75,5 @@ function HudKillPopup:draw()
     g.printCenter(str, f.x, f.y + v * .038, true, false)
   end
 end
+
+return KillPopup

+ 6 - 4
data/hud/hudleft.lua → app/hud/left.lua

@@ -1,13 +1,13 @@
-HudLeft = class()
+local Left = class()
 
 local g = love.graphics
 
-function HudLeft:init()
+function Left:init()
   self.offset = -data.media.graphics.hud.left:getWidth() * ctx.view.scale
   self.prevOffset = self.offset
 end
 
-function HudLeft:update()
+function Left:update()
   local p = ctx.players:get(ctx.id)
   if p then
     self.prevOffset = self.offset
@@ -20,7 +20,7 @@ function HudLeft:update()
   end
 end
 
-function HudLeft:draw()
+function Left:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   local s = ctx.view.scale
   local offset = math.lerp(self.prevOffset, self.offset, tickDelta / tickRate)
@@ -58,3 +58,5 @@ function HudLeft:draw()
     end
   end
 end
+
+return Left

+ 4 - 2
data/hud/hudplayers.lua → app/hud/players.lua

@@ -1,8 +1,8 @@
-HudPlayers = class()
+local Players = class()
 
 local g = love.graphics
 
-function HudPlayers:draw()
+function Players:draw()
   g.setFont('pixel', 8)
   ctx.players:each(function(p)
     if not p.ded then
@@ -41,3 +41,5 @@ function HudPlayers:draw()
     end
   end
 end
+
+return Players

+ 4 - 2
data/hud/hudright.lua → app/hud/right.lua

@@ -1,8 +1,8 @@
-HudRight = class()
+local Right = class()
 
 local g = love.graphics
 
-function HudRight:draw()
+function Right:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   local s = ctx.view.scale
 
@@ -39,3 +39,5 @@ function HudRight:draw()
     end]]
   end
 end
+
+return Right

+ 10 - 8
data/hud/hudscoreboard.lua → app/hud/scoreboard.lua

@@ -1,11 +1,11 @@
-HudScoreboard = class()
+local Scoreboard = class()
 
 local g = love.graphics
 
-function HudScoreboard:init()
-  ctx.event:on(evtClass, function(data) self:refresh() end)
-  ctx.event:on(evtDead, function(data) self:refresh() end)
-  ctx.event:on(evtLeave, function(data) self:refresh() end)
+function Scoreboard:init()
+  ctx.event:on(app.core.net.events.class, function(data) self:refresh() end)
+  ctx.event:on(app.core.net.events.dead, function(data) self:refresh() end)
+  ctx.event:on(app.core.net.events.leave, function(data) self:refresh() end)
 
   self.names = {[0] = '', [1] = ''}
   self.ks = {[0] = '', [1] = ''}
@@ -21,7 +21,7 @@ function HudScoreboard:init()
   self.offset = {[0] = -love.graphics.getWidth(), [1] = love.graphics.getWidth() * 2}
 end
 
-function HudScoreboard:update()
+function Scoreboard:update()
   if love.keyboard.isDown('tab') then
     self.offset[0] = math.lerp(self.offset[0], 0, math.min(30 * tickRate, 1))
     self.offset[1] = math.lerp(self.offset[1], ctx.hud.u - self.width[1], math.min(30 * tickRate, 1))
@@ -37,7 +37,7 @@ function HudScoreboard:update()
   end
 end
 
-function HudScoreboard:draw()
+function Scoreboard:draw()
   local u, v = ctx.hud.u, ctx.hud.v
   g.setFont('pixel', 8)
   local font = g.getFont()
@@ -62,7 +62,7 @@ function HudScoreboard:draw()
   end
 end
 
-function HudScoreboard:refresh()
+function Scoreboard:refresh()
   self.teams = {[0] = {}, [1] = {}}
   ctx.players:each(function(p)
     table.insert(self.teams[p.team], {name = p.username, kills = p.kills, deaths = p.deaths})
@@ -97,3 +97,5 @@ function HudScoreboard:refresh()
     self.height[i] = (#self.teams[i] + 1) * font:getHeight() + 12
   end
 end
+
+return Scoreboard

+ 1 - 1
app/map.lua

@@ -114,7 +114,7 @@ function Map:init(name)
     end
   end
 
-  ctx.event:on(evtProp, function(data)
+  ctx.event:on(app.core.net.events.prop, function(data)
     local prop = self.props[data.id]
     prop.x, prop.y = data.x / 10, data.y / 10
   end)

+ 7 - 5
data/menu/menualert.lua → app/menu/alert.lua

@@ -1,17 +1,17 @@
-MenuAlert = class()
+local Alert = class()
 
 local g = love.graphics
 
-function MenuAlert:init()
+function Alert:init()
   self.message = nil
   self.alpha = 0
 end
 
-function MenuAlert:update()
+function Alert:update()
   self.alpha = math.max(self.alpha - tickRate, 0)
 end
 
-function MenuAlert:draw()
+function Alert:draw()
   if self.alpha < .001 then return end
   local u, v = ctx.u, ctx.v
 
@@ -26,8 +26,10 @@ function MenuAlert:draw()
   g.printCenter(str, .5 * u, .5 * v)
 end
 
-function MenuAlert:show(message, alpha)
+function Alert:show(message, alpha)
   alpha = alpha or 2
   self.alpha = alpha
   self.message = message
 end
+
+return Alert

+ 5 - 3
data/menu/menuback.lua → app/menu/back.lua

@@ -1,8 +1,8 @@
-MenuBack = class()
+local Back = class()
 
 local g = love.graphics
 
-function MenuBack:draw()
+function Back:draw()
   local u, v = ctx.u, ctx.v
   local active = ctx.page and ctx.page ~= 'login' and ctx.page ~= 'main'
   local mx, my = love.mouse.getPosition()
@@ -17,10 +17,12 @@ function MenuBack:draw()
   end
 end
 
-function MenuBack:mousereleased(x, y, button)
+function Back:mousereleased(x, y, button)
   local u, v = ctx.u, ctx.v
   if button == 'l' and math.inside(x, y, 0, .8 * v, u, .2 * v) then
     ctx:push('main')
     data.media.sounds.click:play()
   end
 end
+
+return Back

+ 4 - 2
data/menu/menubackground.lua → app/menu/background.lua

@@ -1,9 +1,9 @@
-MenuBackground = class()
+local Background = class()
 
 local g = love.graphics
 local w, h = g.width, g.height
 
-function MenuBackground:draw()
+function Background:draw()
   g.setColor(255, 255, 255)
   g.draw(data.media.graphics.menu.ggbg, 0, 0)
 
@@ -16,3 +16,5 @@ function MenuBackground:draw()
   g.setColor(0, 0, 0, 80)
   g.rectangle('fill', 0, h(.2), w(), h(.1))
 end
+
+return Background

+ 12 - 10
data/menu/menu.lua → app/menu/context.lua

@@ -1,4 +1,4 @@
-Menu = class()
+local Menu = class()
 
 function Menu:load(user)
   self.user = user or {}
@@ -11,17 +11,17 @@ function Menu:load(user)
   love.mouse.setVisible(true)
   love.keyboard.setKeyRepeat(true)
 
-  self.ribbon = MenuRibbon()
-  self.background = MenuBackground()
-  self.input = MenuInput()
-  self.options = MenuOptions()
-  self.back = MenuBack()
-  self.alert = MenuAlert()
+  self.ribbon = app.menu.ribbon()
+  self.background = app.menu.background()
+  self.input = app.menu.input()
+  self.options = app.menu.options()
+  self.back = app.menu.back()
+  self.alert = app.menu.alert()
 
   self.pages = {
-    login = MenuLogin(),
-    main = MenuMain(),
-    serverlist = MenuServerList()
+    login = app.menu.login(),
+    main = app.menu.main(),
+    serverlist = app.menu.serverList()
   }
 
   self:push(self.user.token and 'main' or 'login')
@@ -91,3 +91,5 @@ function Menu:connect(ip)
   app.core.context:add(app.core.game, self.options.data)
   love.keyboard.setKeyRepeat(false)
 end
+
+return Menu

+ 11 - 9
data/menu/menuinput.lua → app/menu/input.lua

@@ -1,11 +1,11 @@
-MenuInput = class()
+local Input = class()
 
-function MenuInput:init()
+function Input:init()
   self.inputs = {}
   self.focused = nil
 end
 
-function MenuInput:textinput(character)
+function Input:textinput(character)
   if self.focused then
     if character:match('%w') or character == '\b' then
       self.inputs[self.focused].val = self.inputs[self.focused].val .. character
@@ -14,7 +14,7 @@ function MenuInput:textinput(character)
   end
 end
 
-function MenuInput:keypressed(key)
+function Input:keypressed(key)
   if key == 'backspace' and self.focused and #self.inputs[self.focused].val > 0 then
     self.inputs[self.focused].val = self.inputs[self.focused].val:sub(1, -2)
     data.media.sounds.click:play()
@@ -32,12 +32,12 @@ function MenuInput:keypressed(key)
   end
 end
 
-function MenuInput:clear()
+function Input:clear()
   self.focused = nil
   table.clear(self.inputs)
 end
 
-function MenuInput:add(name, default)
+function Input:add(name, default)
   self.inputs[name] = {
     val = default,
     default = default
@@ -46,18 +46,20 @@ function MenuInput:add(name, default)
   table.insert(self.inputs, name)
 end
 
-function MenuInput:val(name)
+function Input:val(name)
   return self.inputs[name].val
 end
 
-function MenuInput:focus(input)
+function Input:focus(input)
   self:unfocus()
   self.focused = input
   if self.inputs[self.focused].default == self.inputs[self.focused].val then self.inputs[self.focused].val = '' end
 end
 
-function MenuInput:unfocus()
+function Input:unfocus()
   if not self.focused then return end
   if self.inputs[self.focused].val == '' and self.inputs[self.focused].default then self.inputs[self.focused].val = self.inputs[self.focused].default end
   self.focused = nil
 end
+
+return Input

+ 9 - 7
data/menu/menulogin.lua → app/menu/login.lua

@@ -1,8 +1,8 @@
-MenuLogin = class()
+local Login = class()
 
 local g = love.graphics
 
-function MenuLogin:activate()
+function Login:activate()
   ctx.ribbon.count = 2
   ctx.ribbon.margin = .1
 
@@ -10,7 +10,7 @@ function MenuLogin:activate()
   ctx.input:add('username', username or love.filesystem.read('username') or 'nick')
 end
 
-function MenuLogin:draw()
+function Login:draw()
   local u, v = ctx.u, ctx.v
   local anchor = (.3 + (.8 - .3) / 2) * v
   local input = ctx.input
@@ -30,27 +30,27 @@ function MenuLogin:draw()
   g.printCenter('Enter', .05 * u, anchor + ctx.ribbon.margin * v / 2, false, true)
 end
 
-function MenuLogin:mousepressed(x, y, button)
+function Login:mousepressed(x, y, button)
   local ribbon = ctx.ribbon:test(x, y)
 
   if ribbon == 1 then ctx.input:focus('username')
   elseif ribbon == 2 then self:login() end
 end
 
-function MenuLogin:keypressed(key)
+function Login:keypressed(key)
   if key == 'return' then self:login()
   elseif key == 'backspace' and self.focused then
     self[self.focused] = self[self.focused]:sub(1, -2)
   end
 end
 
-function MenuLogin:textinput(char)
+function Login:textinput(char)
   if self.focused then
     self[self.focused] = self[self.focused] .. char
   end
 end
 
-function MenuLogin:login()
+function Login:login()
   local username = ctx.input:val('username')
   if #username == 0 then return end
 
@@ -63,3 +63,5 @@ function MenuLogin:login()
     ctx.alert:show('Problem logging in.')
   end
 end
+
+return Login

+ 9 - 7
data/menu/menumain.lua → app/menu/main.lua

@@ -1,8 +1,8 @@
-MenuMain = class()
+local Main = class()
 
 local g = love.graphics
 
-function MenuMain:activate()
+function Main:activate()
   ctx.ribbon.count = 4
   ctx.ribbon.margin = .1
 
@@ -11,7 +11,7 @@ function MenuMain:activate()
   end
 end
 
-function MenuMain:draw()
+function Main:draw()
   local u, v = ctx.u, ctx.v
   local anchor = (.3 + (.8 - .3) / 2) * v
 
@@ -24,7 +24,7 @@ function MenuMain:draw()
   g.printCenter('Exit', .05 * u, anchor + ctx.ribbon.margin * v * 1.5, false, true)
 end
 
-function MenuMain:mousepressed(x, y, button)
+function Main:mousepressed(x, y, button)
   if button == 'l' then
     local ribbon = ctx.ribbon:test(x, y)
 
@@ -35,7 +35,7 @@ function MenuMain:mousepressed(x, y, button)
   end
 end
 
-function MenuMain:host()
+function Main:host()
   local success = app.goregous:createServer()
   if success then
     local server = app.core.context:add(app.core.server)
@@ -46,11 +46,13 @@ function MenuMain:host()
   end
 end
 
-function MenuMain:join()
+function Main:join()
   ctx:push('serverlist')
 end
 
-function MenuMain:edit()
+function Main:edit()
   app.core.context:remove(ctx)
   app.core.context:add(app.editor.context, ctx.options.data)
 end
+
+return Main

+ 5 - 3
data/menu/menuoptions.lua → app/menu/options.lua

@@ -1,6 +1,6 @@
-MenuOptions = class()
+local Options = class()
 
-MenuOptions.defaults = {
+Options.defaults = {
   fullscreen = false,
   borderless = true,
   windowWidth = 800,
@@ -19,6 +19,8 @@ local function safeLoad(file)
   return result
 end
 
-function MenuOptions:init()
+function Options:init()
   self.data = table.merge(safeLoad('options.lua'), self.defaults)
 end
+
+return Options

+ 5 - 4
data/menu/menuribbon.lua → app/menu/ribbon.lua

@@ -1,14 +1,14 @@
-MenuRibbon = class()
+local Ribbon = class()
 
 local g = love.graphics
 
-function MenuRibbon:init()
+function Ribbon:init()
   self.ribbons = {0, 0, 0, 0, 0}
   self.count = 3
   self.margin = .1
 end
 
-function MenuRibbon:test(x, y)
+function Ribbon:test(x, y)
   local u, v = ctx.u, ctx.v
   local anchor = (.3 + (.8 - .3) / 2) * v
 
@@ -23,7 +23,7 @@ function MenuRibbon:test(x, y)
   return nil
 end
 
-function MenuRibbon:draw()
+function Ribbon:draw()
   local u, v = ctx.u, ctx.v
   local anchor = (.3 + (.8 - .3) / 2) * v
 
@@ -45,3 +45,4 @@ function MenuRibbon:draw()
   end
 end
 
+return Ribbon

+ 7 - 6
data/menu/menuserverlist.lua → app/menu/serverList.lua

@@ -1,13 +1,13 @@
-MenuServerList = class()
+local ServerList = class()
 
 local g = love.graphics
 
-function MenuServerList:activate()
+function ServerList:activate()
   ctx.ribbon.count = 0
   self:refresh()
 end
 
-function MenuServerList:draw()
+function ServerList:draw()
   local u, v = ctx.u, ctx.v
   local mx, my = love.mouse.getPosition()
   local hover = math.inside(mx, my, 0, .2 * v, u, .1 * v)
@@ -40,11 +40,11 @@ function MenuServerList:draw()
 
 end
 
-function MenuServerList:keypressed(key)
+function ServerList:keypressed(key)
   if key == 'r' then self:refresh() end
 end
 
-function MenuServerList:mousepressed(x, y, button)
+function ServerList:mousepressed(x, y, button)
   local u, v = ctx.u, ctx.v
   if button == 'l' then
     for i = 1, #self.servers do
@@ -60,7 +60,8 @@ function MenuServerList:mousepressed(x, y, button)
   end
 end
 
-function MenuServerList:refresh()
+function ServerList:refresh()
   self.servers = app.goregous:listServers()
 end
 
+return ServerList

+ 11 - 11
app/netclient.lua

@@ -1,27 +1,27 @@
 local NetClient = extend(app.core.net)
 
 NetClient.signatures = {}
-NetClient.signatures[msgJoin] = {{'username', 'string'}, important = true}
-NetClient.signatures[msgLeave] = {important = true}
-NetClient.signatures[msgClass] = {{'class', '4bits'}, {'team', '1bit'}, important = true}
-NetClient.signatures[msgInput] = {
+NetClient.signatures[app.core.net.messages.join] = {{'username', 'string'}, important = true}
+NetClient.signatures[app.core.net.messages.leave] = {important = true}
+NetClient.signatures[app.core.net.messages.class] = {{'class', '4bits'}, {'team', '1bit'}, important = true}
+NetClient.signatures[app.core.net.messages.input] = {
   {'tick', '16bits'},
   {'w', 'bool'}, {'a', 'bool'}, {'s', 'bool'}, {'d', 'bool'},
   {'x', '12bits'}, {'y', '12bits'}, {'l', 'bool'}, {'r', 'bool'},
   {'slot', '3bits'}, {'reload', 'bool'},
   delta = {{'w', 'a', 's', 'd'}, {'x', 'y'}, 'l', 'r', 'slot', 'reload'}
 }
-NetClient.signatures[msgChat] = {{'message', 'string'}, important = true}
+NetClient.signatures[app.core.net.messages.chat] = {{'message', 'string'}, important = true}
 
 NetClient.receive = {}
 NetClient.receive['default'] = function(self, event) ctx.event:emit(event.msg, event.data) end
 
-NetClient.receive[msgJoin] = function(self, event)
+NetClient.receive[app.core.net.messages.join] = function(self, event)
   ctx.id = event.data.id
   setmetatable(ctx.players:get(ctx.id), {__index = app.playerMain})
 end
 
-NetClient.receive[msgSnapshot] = function(self, event)
+NetClient.receive[app.core.net.messages.snapshot] = function(self, event)
   ctx.tick = event.data.tick + math.floor(((event.peer:round_trip_time() / 2) / 1000) / tickRate)
   if env ~= 'release' then ctx.tick = event.data.tick end
   --ctx.map:load(event.data.map)
@@ -40,11 +40,11 @@ function NetClient:init()
   self:connectTo(serverIp, 6061)
   self.messageBuffer = {}
 
-  ctx.event:on(evtJoin, function(data)
+  ctx.event:on(app.core.net.events.join, function(data)
     ctx.players:get(data.id).username = data.username
   end)
 
-  ctx.event:on(evtSync, function(data)
+  ctx.event:on(app.core.net.events.sync, function(data)
     local p = ctx.players:get(data.id)
     if p and p.active then
       p:trace(data)
@@ -59,14 +59,14 @@ function NetClient:init()
 end
 
 function NetClient:quit()
-  self:send(msgLeave)
+  self:send(app.core.net.messages.leave)
   self.host:flush()
   self.server:disconnect()
 end
 
 function NetClient:connect(event)
   self.server = event.peer
-  self:send(msgJoin, {username = username})
+  self:send(app.core.net.messages.join, {username = username})
   event.peer:ping_interval(100)
   event.peer:ping()
 end

+ 31 - 31
app/netserver.lua

@@ -1,10 +1,10 @@
 local NetServer = extend(app.core.net)
 
 NetServer.signatures = {}
-NetServer.signatures[evtJoin] = {{'id', '4bits'}, {'username', 'string'}, important = true}
-NetServer.signatures[evtLeave] = {{'id', '4bits'}, {'reason', 'string'}, important = true}
-NetServer.signatures[evtClass] = {{'id', '4bits'}, {'class', '4bits'}, {'team', '1bit'}, important = true}
-NetServer.signatures[evtSync] = {
+NetServer.signatures[app.core.net.events.join] = {{'id', '4bits'}, {'username', 'string'}, important = true}
+NetServer.signatures[app.core.net.events.leave] = {{'id', '4bits'}, {'reason', 'string'}, important = true}
+NetServer.signatures[app.core.net.events.class] = {{'id', '4bits'}, {'class', '4bits'}, {'team', '1bit'}, important = true}
+NetServer.signatures[app.core.net.events.sync] = {
   {'id', '4bits'},
   {'tick', '16bits'},
   {'ack', '16bits'},
@@ -14,17 +14,17 @@ NetServer.signatures[evtSync] = {
   {'weapon', '3bits'}, {'skill', '3bits'},
   delta = {'x', 'y', 'z', 'angle', 'health', 'shield', 'weapon', 'skill'}
 }
-NetServer.signatures[evtFire] = {
+NetServer.signatures[app.core.net.events.fire] = {
   {'id', '4bits'}, {'slot', '3bits'}, {'mx', '12bits'}, {'my', '12bits'},
   delta = {{'mx', 'my'}}
 }
-NetServer.signatures[evtDamage] = {{'id', '4bits'}, {'amount', 'string'}, {'from', '4bits'}}
-NetServer.signatures[evtDead] = {{'id', '4bits'}, {'kill', '4bits'}, {'assists', {{'id', '4bits'}}}, important = true}
-NetServer.signatures[evtSpawn] = {{'id', '4bits'}, important = true}
-NetServer.signatures[evtChat] = {{'message', 'string'}, important = true}
-NetServer.signatures[evtProp] = {{'id', '16bits'}, {'x', '16bits'}, {'y', '16bits'}}
-NetServer.signatures[msgJoin] = {{'id', '4bits'}, important = true}
-NetServer.signatures[msgSnapshot] = {
+NetServer.signatures[app.core.net.events.damage] = {{'id', '4bits'}, {'amount', 'string'}, {'from', '4bits'}}
+NetServer.signatures[app.core.net.events.dead] = {{'id', '4bits'}, {'kill', '4bits'}, {'assists', {{'id', '4bits'}}}, important = true}
+NetServer.signatures[app.core.net.events.spawn] = {{'id', '4bits'}, important = true}
+NetServer.signatures[app.core.net.events.chat] = {{'message', 'string'}, important = true}
+NetServer.signatures[app.core.net.events.prop] = {{'id', '16bits'}, {'x', '16bits'}, {'y', '16bits'}}
+NetServer.signatures[app.core.net.messages.join] = {{'id', '4bits'}, important = true}
+NetServer.signatures[app.core.net.messages.snapshot] = {
   {'tick', '16bits'},
   {'map', 'string'},
   {'players', {{'id', '4bits'}, {'username', 'string'}, {'class', '4bits'}, {'team', '1bit'}}},
@@ -34,26 +34,26 @@ NetServer.signatures[msgSnapshot] = {
 NetServer.receive = {}
 NetServer.receive['default'] = f.empty
 
-NetServer.receive[msgJoin] = function(self, event)
+NetServer.receive[app.core.net.messages.join] = function(self, event)
   local pid = self.peerToPlayer[event.peer]
   ctx.players:get(pid).username = event.data.username
-  self:send(msgJoin, event.peer, {id = pid})
-  self:emit(evtJoin, {id = pid, username = event.data.username})
-  self:emit(evtChat, {message = '{white}' .. event.data.username .. ' has joined!'})
+  self:send(app.core.net.messages.join, event.peer, {id = pid})
+  self:emit(app.core.net.events.join, {id = pid, username = event.data.username})
+  self:emit(app.core.net.events.chat, {message = '{white}' .. event.data.username .. ' has joined!'})
   self:snapshot(event.peer)
 end
 
-NetServer.receive[msgLeave] = function(self, event) self:disconnect(event) end
+NetServer.receive[app.core.net.messages.leave] = function(self, event) self:disconnect(event) end
 
-NetServer.receive[msgClass] = function(self, event)
-  self:emit(evtClass, {id = self.peerToPlayer[event.peer], class = event.data.class, team = event.data.team})
+NetServer.receive[app.core.net.messages.class] = function(self, event)
+  self:emit(app.core.net.events.class, {id = self.peerToPlayer[event.peer], class = event.data.class, team = event.data.team})
 end
 
-NetServer.receive[msgInput] = function(self, event)
+NetServer.receive[app.core.net.messages.input] = function(self, event)
   ctx.players:get(self.peerToPlayer[event.peer]):trace(event.data, event.peer:round_trip_time())
 end
 
-NetServer.receive[msgChat] = function(self, event)
+NetServer.receive[app.core.net.messages.chat] = function(self, event)
   local pid = self.peerToPlayer[event.peer]
   local username = ctx.players:get(pid).username
   local color = ctx.players:get(pid).team == 0 and 'purple' or 'orange'
@@ -63,7 +63,7 @@ NetServer.receive[msgChat] = function(self, event)
     for word in string.gmatch(message, '([^ ]+)') do
       table.insert(data, word)
     end
-    local function reply(message) self:send(evtChat, event.peer, {message = '{red}' .. message}) end
+    local function reply(message) self:send(app.core.net.events.chat, event.peer, {message = '{red}' .. message}) end
     local handlers = {
       ['/restart'] = function(data)
         if username ~= ctx.owner then return reply('permission denied') end
@@ -79,25 +79,25 @@ NetServer.receive[msgChat] = function(self, event)
         for i = 1, ctx.players.max do
           if ctx.players:get(i).username == data[2] then player = i break end
         end
-        if not player then return self:send(evtChat, event.peer, {message = '{red}couldn\'t find player "' .. data[2] .. '"'}) end
+        if not player then return self:send(app.core.net.events.chat, event.peer, {message = '{red}couldn\'t find player "' .. data[2] .. '"'}) end
         for i = 1, ctx.players.max do
           local p = self.host:get_peer(i)
           if self.peerToPlayer[p] == player then peer = p break end
         end
-        if not peer then return self:send(evtChat, event.peer, {message = '{red}"' .. data[2] .. '" doesn\'t seem to be connected'}) end
+        if not peer then return self:send(app.core.net.events.chat, event.peer, {message = '{red}"' .. data[2] .. '" doesn\'t seem to be connected'}) end
         self:disconnect({peer = peer, reason = 'kicked'})
       end,
 
       ['/roll'] = function(data)
-        self:emit(evtChat, {message = '{red}' .. username .. ' rolled {green}' .. love.math.random(1, 100)})
+        self:emit(app.core.net.events.chat, {message = '{red}' .. username .. ' rolled {green}' .. love.math.random(1, 100)})
       end,
 
       ['/bjorn'] = function(data)
-        self:emit(evtChat, {message = '{purple}-_-'})
+        self:emit(app.core.net.events.chat, {message = '{purple}-_-'})
       end,
 
       default = function(data)
-        self:send(evtChat, event.peer, {message = '{red}unknown command "' .. data[1]:sub(2) .. '"'})
+        self:send(app.core.net.events.chat, event.peer, {message = '{red}unknown command "' .. data[1]:sub(2) .. '"'})
       end
     }
     handlers['/reset'] = handlers['/restart']
@@ -106,7 +106,7 @@ NetServer.receive[msgChat] = function(self, event)
 
     return (handlers[data[1]] or handlers.default)(data)
   end
-  self:emit(evtChat, {message = '{' .. color .. '}' .. username .. '{white}: ' .. message})
+  self:emit(app.core.net.events.chat, {message = '{' .. color .. '}' .. username .. '{white}: ' .. message})
 end
 
 function NetServer:init()
@@ -145,8 +145,8 @@ function NetServer:disconnect(event)
   local pid = self.peerToPlayer[event.peer]
   local username = ctx.players:get(pid).username
   local reason = event.reason or 'left'
-  self:emit(evtChat, {message = '{white}' .. username .. ' has left (' .. reason .. ')'})
-  self:emit(evtLeave, {id = pid, reason = reason})
+  self:emit(app.core.net.events.chat, {message = '{white}' .. username .. ' has left (' .. reason .. ')'})
+  self:emit(app.core.net.events.leave, {id = pid, reason = reason})
   self.peerToPlayer[event.peer] = nil
   event.peer:disconnect_now()
   if username == ctx.owner then
@@ -204,7 +204,7 @@ function NetServer:snapshot(peer)
       })
     end
   end
-  self:send(msgSnapshot, peer, {tick = tick, map = 'testArena', ['players'] = players})
+  self:send(app.core.net.messages.snapshot, peer, {tick = tick, map = 'testArena', ['players'] = players})
 end
 
 function NetServer:nextPlayerId()

+ 1 - 1
app/patcher.lua

@@ -11,7 +11,7 @@ function Patcher:load()
     love.event.quit()
   else
     app.core.context:remove(self)
-    app.core.context:add(Menu)
+    app.core.context:add(app.menu.context)
   end
 end
 

+ 1 - 1
app/player.lua

@@ -218,7 +218,7 @@ function Player:slot(input, prev)
     local msg = {id = self.id, slot = slot, mx = obj.needsMouse and input.x, my = obj.needsMouse and input.y}
     obj:fire(self, input.x, input.y)
     if obj.targeted then obj.targeting = false end
-    ctx.net:emit(evtFire, msg)
+    ctx.net:emit(app.core.net.events.fire, msg)
   end
 
   for i = 1, 5 do

+ 1 - 1
app/playermain.lua

@@ -52,7 +52,7 @@ function PlayerMain:update()
     end
   end
 
-  ctx.net:send(msgInput, input)
+  ctx.net:send(app.core.net.messages.input, input)
 
   app.player.update(self)
 

+ 7 - 7
app/players.lua

@@ -10,15 +10,15 @@ function Players:init()
     self.players[i].id = i
   end
 
-  ctx.event:on(evtLeave, function(data)
+  ctx.event:on(app.core.net.events.leave, function(data)
     self:deactivate(data.id)
   end)
 
-  ctx.event:on(evtClass, function(data)
+  ctx.event:on(app.core.net.events.class, function(data)
     self:setClass(data.id, data.class, data.team)
   end)
 
-  ctx.event:on(evtFire, function(data)
+  ctx.event:on(app.core.net.events.fire, function(data)
     if ctx.id and data.id ~= ctx.id then
       local p = self:get(data.id)
       local slot = p.slots[data.slot]
@@ -26,7 +26,7 @@ function Players:init()
     end
   end)
 
-  ctx.event:on(evtDamage, function(data)
+  ctx.event:on(app.core.net.events.damage, function(data)
     local to, from = self:get(data.id), self:get(data.from)
     to.lastHurt = tick
     if data.id ~= data.from then
@@ -50,7 +50,7 @@ function Players:init()
     })
   end)
 
-  ctx.event:on(evtDead, function(data)
+  ctx.event:on(app.core.net.events.dead, function(data)
     local killer, victim = self:get(data.kill), self:get(data.id)
     if data.kill ~= data.id then
       killer.kills = killer.kills + 1
@@ -60,7 +60,7 @@ function Players:init()
     victim:die()
   end)
 
-  ctx.event:on(evtSpawn, function(data)
+  ctx.event:on(app.core.net.events.spawn, function(data)
     local p = self:get(data.id)
     p.ded = false
     p:spawn()
@@ -68,7 +68,7 @@ function Players:init()
 
   ctx.event:on('game.restart', function(data)
     self:each(function(p)
-      ctx.net:emit(evtSpawn, {id = p.id})
+      ctx.net:emit(app.core.net.events.spawn, {id = p.id})
     end)
   end)
 end

+ 4 - 4
app/playerserver.lua

@@ -60,7 +60,7 @@ function PlayerServer:update()
       if spawn.team == self.team then
         self.health = math.min(self.health + amount, self.maxHealth)
       else
-        ctx.event:emit(evtDamage, {id = self.id, amount = amount, from = self.id, tick = tick})
+        ctx.event:emit(app.core.net.events.damage, {id = self.id, amount = amount, from = self.id, tick = tick})
       end
     else
       self.spawnMultiplier = 0
@@ -137,7 +137,7 @@ function PlayerServer:trace(data, ping)
     msg.id = self.id
     msg.tick = tick
     msg.ack = self.ack
-    ctx.net:emit(evtSync, msg)
+    ctx.net:emit(app.core.net.events.sync, msg)
 
     -- Undo lag compensation
     ctx.players:each(function(p)
@@ -151,7 +151,7 @@ function PlayerServer:trace(data, ping)
 end
 
 function PlayerServer:time()
-  self.ded = timer.rot(self.ded, function() ctx.net:emit(evtSpawn, {id = self.id}) end)
+  self.ded = timer.rot(self.ded, function() ctx.net:emit(app.core.net.events.spawn, {id = self.id}) end)
   if self.ded == 0 then self.ded = false end
 end
 
@@ -194,7 +194,7 @@ function PlayerServer:hurt(data)
         if playerHurt[2][2] > 0 then table.insert(assists, {id = playerHurt[2][1]}) end
       end
 
-      ctx.net:emit(evtDead, {id = self.id, kill = data.from, assists = assists})
+      ctx.net:emit(app.core.net.events.dead, {id = self.id, kill = data.from, assists = assists})
     else
       f.exe(self.shields[1].callback, self)
       table.remove(self.shields, 1)

+ 1 - 1
data/buff/adrenaline.lua

@@ -29,7 +29,7 @@ function Adrenaline:update()
   self.hurtTimer = self.hurtTimer - 1
   if self.hurtTimer <= 0 then
     local amt = math.min(Adrenaline.drain * Adrenaline.rate, self.owner.health - 1)
-    ctx.net:emit(evtDamage, {id = self.owner.id, amount = amt, from = self.owner.id, tick = tick})
+    ctx.net:emit(app.core.net.events.damage, {id = self.owner.id, amount = amt, from = self.owner.id, tick = tick})
     self.hurtTimer = math.round(Adrenaline.rate / tickRate)
     for _ = 1, 8 do
       ctx.event:emit('particle.create', {

+ 1 - 1
data/mods/deathmatch.lua

@@ -5,7 +5,7 @@ Deathmatch.pointsPerKill = 1
 Deathmatch.experiencePerKill = 0
 
 function Deathmatch:init()
-  ctx.event:on(evtDead, function(data)
+  ctx.event:on(app.core.net.events.dead, function(data)
     if data.id == data.kill then return end
 
     local killer = ctx.players:get(data.kill)

+ 4 - 4
data/mods/epidemic.lua

@@ -4,19 +4,19 @@ Epidemic.code = 'epidemic'
 function Epidemic:init(map)
   self.timer = 5 * 60
 
-  ctx.event:on(evtDead, function(_data)
+  ctx.event:on(app.core.net.events.dead, function(_data)
     if _data.id == _data.kill then return end
     local p = ctx.players:get(_data.id)
     if p.team == purple then
-      ctx.net:emit(evtClass, {id = _data.id, class = p.class.id, team = orange})
+      ctx.net:emit(app.core.net.events.class, {id = _data.id, class = p.class.id, team = orange})
       ctx.players:each(function(p)
         if p.team == orange then ctx.buffs:add(p, 'zombieboost') end
       end)
     end
   end)
 
-  ctx.event:on(evtClass, function(data) self:refresh() end)
-  ctx.event:on(msgLeave, function(data) self:refresh() end)
+  ctx.event:on(app.core.net.events.class, function(data) self:refresh() end)
+  ctx.event:on(app.core.net.messages.leave, function(data) self:refresh() end)
 
   for i = #map.props, 1, -1 do
     local p = map.props[i]

+ 1 - 1
data/mods/scoring.lua

@@ -34,7 +34,7 @@ function Scoring:score(team, amount)
 end
 
 function Scoring:win(team)
-  ctx.net:emit(evtChat, {message = (team == 0 and 'purple' or 'orange') .. ' team wins!'})
+  ctx.net:emit(app.core.net.events.chat, {message = (team == 0 and 'purple' or 'orange') .. ' team wins!'})
   self.winner = team
   self.restartTimer = 6
 end

+ 1 - 1
data/prop/cartserver.lua

@@ -70,7 +70,7 @@ function CartServer:update()
       ctx.map:modExec('scoring', 'win', purple)
     end
 
-    ctx.net:emit(evtProp, {id = self.id, x = math.round(self.x * 10), y = math.round(self.y * 10)})
+    ctx.net:emit(app.core.net.events.prop, {id = self.id, x = math.round(self.x * 10), y = math.round(self.y * 10)})
   end
 end
 

+ 2 - 2
data/skill/bloodlust.lua

@@ -13,7 +13,7 @@ Bloodlust.type = 'passive'
 -- Behavior
 ----------------
 function Bloodlust:activate(owner)
-  ctx.event:on(evtDead, function(data)
+  ctx.event:on(app.core.net.events.dead, function(data)
     if data.kill == owner.id and data.id ~= owner.id then
       ctx.buffs:add(owner, 'bloodlust')
     end
@@ -21,7 +21,7 @@ function Bloodlust:activate(owner)
 end
 
 function Bloodlust:deactivate(owner)
-  ctx.event:remove(evtDead, self)
+  ctx.event:remove(app.core.net.events.dead, self)
 end
 
 function Bloodlust:value(owner)

+ 1 - 1
data/skill/cleave.lua

@@ -23,7 +23,7 @@ end
 
 function Cleave:fire(owner)
   ctx.spells:activate(owner.id, data.spell.cleave)
-  ctx.net:emit(evtDamage, {id = owner.id, amount = self.cost, from = owner.id, tick = tick})
+  ctx.net:emit(app.core.net.events.damage, {id = owner.id, amount = self.cost, from = owner.id, tick = tick})
   self.timer = self.cooldown
 end
 

+ 1 - 1
data/skill/overexertion.lua

@@ -12,7 +12,7 @@ function Overexertion:canFire(owner)
 end
 
 function Overexertion:fire(owner)
-  ctx.net:emit(evtDamage, {id = owner.id, amount = self.cost, from = owner.id, tick = tick})
+  ctx.net:emit(app.core.net.events.damage, {id = owner.id, amount = self.cost, from = owner.id, tick = tick})
   ctx.buffs:add(owner, 'overexertion')
 end
 

+ 2 - 2
data/skill/subterfuge.lua

@@ -6,7 +6,7 @@ Subterfuge.text = 'When you get a kill you cloak.'
 Subterfuge.type = 'passive'
 
 function Subterfuge:activate(owner)
-	ctx.event:on(evtDead, function(data)
+	ctx.event:on(app.core.net.events.dead, function(data)
 		if data.kill == owner.id then
 			ctx.buffs:add(owner, 'subterfuge')
 		end
@@ -14,7 +14,7 @@ function Subterfuge:activate(owner)
 end
 
 function Subterfuge:deactivate(owner)
-  ctx.event:remove(evtDead, self)
+  ctx.event:remove(app.core.net.events.dead, self)
 end
 
 function Subterfuge:value(owner)

+ 1 - 1
data/spell/lazor.lua

@@ -34,7 +34,7 @@ function Lazor:update()
         hit[p.id] = true
         local buff = ctx.buffs:get(p, 'plasmasickness')
         local damage = 70 + 50 * (buff and buff.stacks or 0)
-        ctx.net:emit(evtDamage, {id = p.id, from = self.owner.id, amount = damage, tick = tick})
+        ctx.net:emit(app.core.net.events.damage, {id = p.id, from = self.owner.id, amount = damage, tick = tick})
         ctx.buffs:remove(p, 'plasmasickness')
       end)
     end

+ 1 - 1
data/spell/plasmacannon.lua

@@ -57,7 +57,7 @@ function PlasmaCannon:update()
     self.x, self.y = self.x + math.dx(dis, self.angle), self.y + math.dy(dis, self.angle)
     local targets = ctx.collision:circleTest(self.x, self.y, self.radius, {tag = 'player', fn = function(p) return p.team ~= self.owner.team end, all = true})
     table.each(targets, function(p)
-      ctx.net:emit(evtDamage, {id = p.id, amount = self.damage, from = self.owner.id, tick = tick})
+      ctx.net:emit(app.core.net.events.damage, {id = p.id, amount = self.damage, from = self.owner.id, tick = tick})
       ctx.buffs:add(p, 'plasmasickness')
     end)
     ctx.event:emit('particle.create', {

+ 1 - 1
data/spell/shotgun.lua

@@ -45,7 +45,7 @@ Shotgun.activate = function(self)
         local n, f = self.len * .25, self.len * .75
         local l, h = data.weapon.shotgun.damage * .4, data.weapon.shotgun.damage * 1
         local damage = l + ((h - l) * ((f - math.clamp(len, n, f)) / f))
-        ctx.net:emit(evtDamage, {id = p.id, amount = damage, from = self.owner.id, tick = tick})
+        ctx.net:emit(app.core.net.events.damage, {id = p.id, amount = damage, from = self.owner.id, tick = tick})
       end
 
       table.insert(self.bullets, {

+ 1 - 1
data/spell/smg.lua

@@ -38,7 +38,7 @@ SMG.activate = function(self)
 
   if target then
     self.len = math.distance(self.x, self.y, target.x, target.y)
-    ctx.net:emit(evtDamage, {id = target.id, amount = data.weapon.smg.damage, from = self.owner.id, tick = tick})
+    ctx.net:emit(app.core.net.events.damage, {id = target.id, amount = data.weapon.smg.damage, from = self.owner.id, tick = tick})
   end
 
   for _ = 1, 4 do

+ 0 - 0
app/core/typo.lua → lib/typo.lua


+ 2 - 3
main.lua

@@ -1,11 +1,10 @@
+require 'enet'
 require 'lib/love'
 require 'lib/util'
 require 'lib/slam'
+require 'lib/typo'
 setmetatable(_G, {
   __index = require('lib/cargo').init('/')
 })
 
-require 'require'
-
 app.core.context:bind(app.patcher)
-

+ 0 - 18
require.lua

@@ -1,18 +0,0 @@
-local function load(dir)
-  for _, file in pairs(love.filesystem.getDirectoryItems(dir)) do
-    local path = dir .. '/' .. file
-    if string.find(path, '%.lua') and not string.find(path, '%..+%.lua') then
-      require(path:gsub('%.lua', ''))
-    end
-  end
-
-  if love.filesystem.exists(dir .. '.lua') then require(dir) end
-end
-
-require 'enet'
-load 'app/core'
-load 'app'
-load 'app/editor'
-load 'app/goregous'
-load 'data/menu'
-load 'data/hud'