浏览代码

cargo: app; app/core;

bjorn 9 年之前
父节点
当前提交
8d850cf096

+ 3 - 1
app/core/buffs.lua

@@ -1,4 +1,4 @@
-Buffs = class()
+local Buffs = class()
 
 function Buffs:init()
   self.buffs = {}
@@ -47,3 +47,5 @@ function Buffs:get(player, code)
     end
   end
 end
+
+return Buffs

+ 3 - 1
app/core/collision.lua

@@ -1,4 +1,4 @@
-Collision = class()
+local Collision = class()
 Collision.cellSize = 128
 Collision.onCollide = function(_, a, b, dx, dy)
   a, b = a.owner, b.owner
@@ -131,3 +131,5 @@ function Collision:circleTest(x, y, r, options)
   self.hc.remove(circle)
   return res
 end
+
+return Collision

+ 3 - 1
app/core/context.lua

@@ -1,4 +1,4 @@
-Context = {
+local Context = {
   list = {}
 }
 
@@ -57,3 +57,5 @@ setmetatable(Context, {
     return function(...) return t:run(k, ...) end
   end
 })
+
+return Context

+ 3 - 1
app/core/effects.lua

@@ -1,4 +1,4 @@
-Effects = class()
+local Effects = class()
 
 function Effects:init()
   self.active = love.graphics.isSupported('shader')
@@ -43,3 +43,5 @@ end
 function Effects:get(code)
   return self.effects[code]
 end
+
+return Effects

+ 3 - 1
app/core/event.lua

@@ -1,4 +1,4 @@
-Event = class()
+local Event = class()
 
 function Event:init()
   self.handlers = {}
@@ -25,3 +25,5 @@ function Event:remove(event, context)
     self.handlers[event][context] = nil
   end
 end
+
+return Event

+ 17 - 15
app/core/game.lua

@@ -1,26 +1,26 @@
-Game = class()
+local Game = class()
 
 Game.tag = 'client'
 
 function Game:load(options)
 	self.options = options
-  self.event = Event()
-  self.net = NetClient()
-  self.input = Input()
-  self.view = View()
-  self.collision = Collision()
-  self.players = Players()
-  self.spells = Spells()
-  self.buffs = Buffs()
-  self.particles = Particles()
-  self.effects = Effects()
-  self.sound = Sound()
-  self.map = Map()
+  self.event = app.core.event()
+  self.net = app.netClient()
+  self.input = app.core.input()
+  self.view = app.core.view()
+  self.collision = app.core.collision()
+  self.players = app.players()
+  self.spells = app.core.spells()
+  self.buffs = app.core.buffs()
+  self.particles = app.core.particles()
+  self.effects = app.core.effects()
+  self.sound = app.core.sound()
+  self.map = app.map()
   self.hud = Hud()
 
   self.event:on('game.quit', function(data)
-    Context:remove(ctx)
-    Context:add(Menu)
+    app.core.context:remove(ctx)
+    app.core.context:add(Menu)
   end)
 end
 
@@ -56,3 +56,5 @@ function Game:resize()
   self.hud:resize()
   self.effects:resize()
 end
+
+return Game

+ 3 - 1
app/core/input.lua

@@ -1,4 +1,4 @@
-Input = class()
+local Input = class()
 
 function Input:init()
   self.keyboardEnabled = true
@@ -12,3 +12,5 @@ end
 function Input:keyDown(k)
   return self.keyboardEnabled and love.keyboard.isDown(k)
 end
+
+return Input

+ 5 - 3
app/core/net.lua

@@ -1,4 +1,4 @@
-Net = class()
+local Net = class()
 
 evtJoin = 1
 evtLeave = 2
@@ -19,8 +19,8 @@ msgInput = 15
 msgChat = 16
 
 function Net:init()
-  self.inStream = Stream()
-  self.outStream = Stream()
+  self.inStream = app.core.stream()
+  self.outStream = app.core.stream()
 end
 
 function Net:listen(port)
@@ -65,3 +65,5 @@ function Net:unpack()
   if not self.other.signatures[msg] then return false end
   return msg, self.inStream:unpack(self.other.signatures[msg])
 end
+
+return Net

+ 3 - 1
app/core/particles.lua

@@ -1,4 +1,4 @@
-Particles = class()
+local Particles = class()
 
 function Particles:init()
   self.particles = {}
@@ -27,3 +27,5 @@ function Particles:update()
     end
   end
 end
+
+return Particles

+ 12 - 10
app/core/server.lua

@@ -1,25 +1,25 @@
-Server = class()
+local Server = class()
 
 Server.tag = 'server'
 
 function Server:load()
-  self.event = Event()
-  self.players = Players()
-  self.spells = Spells()
-  self.collision = Collision()
-  self.buffs = Buffs()
-  self.net = NetServer()
-  self.map = Map()
+  self.event = app.core.event()
+  self.players = app.players()
+  self.spells = app.core.spells()
+  self.collision = app.core.collision()
+  self.buffs = app.core.buffs()
+  self.net = app.netServer()
+  self.map = app.map()
 
   for i = 1, 0 do
     local p = self.players.players[i]
-    setmetatable(p, {__index = PlayerRobot})
+    setmetatable(p, {__index = app.playerRobot})
     self.net:emit(evtClass, {id = i, class = 1, team = i % 2})
   end
 
   self.event:on('game.quit', function()
     goregous:send({'killServer'})
-    Context:remove(ctx)
+    app.core.context:remove(ctx)
   end)
 end
 
@@ -35,3 +35,5 @@ end
 function Server:quit()
   self.net:quit()
 end
+
+return Server

+ 3 - 1
app/core/sound.lua

@@ -1,4 +1,4 @@
-Sound = class()
+local Sound = class()
 
 function Sound:init()
   self.mute = false
@@ -47,3 +47,5 @@ function Sound:mute()
   self.mute = not self.mute
   love.audio.tag.all.stop()
 end
+
+return Sound

+ 3 - 1
app/core/spell.lua

@@ -1,4 +1,4 @@
-Spell = class()
+local Spell = class()
 
 function Spell:mirrorOwner()
   self.x, self.y, self.angle = self.owner.x, self.owner.y, self.owner.angle
@@ -160,3 +160,5 @@ function Spell:playSound(sound, options)
   options.y = options.y or self.y
   ctx.event:emit('sound.play', table.merge({sound = sound}, options))
 end
+
+return Spell

+ 3 - 1
app/core/spells.lua

@@ -1,4 +1,4 @@
-Spells = class()
+local Spells = class()
 
 function Spells:init()
   self.spells = {}
@@ -26,3 +26,5 @@ end
 function Spells:draw()
   table.with(self.spells, 'draw')
 end
+
+return Spells

+ 3 - 1
app/core/stream.lua

@@ -1,4 +1,4 @@
-Stream = class()
+local Stream = class()
 
 local function byteExtract(x, a, b)
   b = b or a
@@ -212,3 +212,5 @@ function Stream:unpack(signature)
   end
   return data
 end
+
+return Stream

+ 3 - 1
app/core/view.lua

@@ -1,4 +1,4 @@
-View = class()
+local View = class()
 
 local g = love.graphics
 
@@ -223,3 +223,5 @@ function View:worldPush()
   g.scale(s)
   g.translate(-x, -y)
 end
+
+return View

+ 3 - 1
app/core/weapon.lua

@@ -1,4 +1,4 @@
-Weapon = class()
+local Weapon = class()
 
 function Weapon:activate(owner)
   self.timers = {}
@@ -68,3 +68,5 @@ end
 function Weapon:ammoValue(owner)
   return self.currentClip, self.currentAmmo
 end
+
+return Weapon

+ 6 - 6
app/editor/editor.lua

@@ -5,11 +5,11 @@ function Editor:load(options)
   self.grid = EditorGrid()
 
   self.view = EditorView()
-  self.effects = Effects()
+  self.effects = app.core.effects()
   self.effects:remove('deathDesaturate')
-  self.event = Event()
-  self.collision = Collision()
-  self.map = Map()
+  self.event = app.core.event()
+  self.collision = app.core.collision()
+  self.map = app.map()
   self.dragger = EditorDragger()
   self.scaler = EditorScaler()
   self.selector = EditorSelector()
@@ -51,8 +51,8 @@ end
 
 function Editor:keyreleased(key)
   if key == 'escape' then
-    Context:remove(ctx)
-    Context:add(Menu)
+    app.core.context:remove(ctx)
+    app.core.context:add(Menu)
   end
 end
 

+ 3 - 5
app/editor/editorview.lua

@@ -1,6 +1,4 @@
-require 'app/core/view'
-
-EditorView = extend(View)
+EditorView = extend(app.core.view)
 
 function EditorView:init()
   self.targetScale = 1
@@ -9,11 +7,11 @@ function EditorView:init()
   self.yVel = 0
   self.maxSpeed = 20
 
-  View.init(self)
+  app.core.view.init(self)
 end
 
 function EditorView:update()
-  View.update(self)
+  app.core.view.update(self)
 
   if not love.keyboard.isDown('lctrl') then
     if love.keyboard.isDown('w') then

+ 3 - 1
app/map.lua

@@ -1,4 +1,4 @@
-Map = class()
+local Map = class()
 
 -- ...
 purple = 0
@@ -137,3 +137,5 @@ function Map:modExec(mod, fn, ...)
     mod[fn](mod, ...)
   end
 end
+
+return Map

+ 6 - 4
app/netclient.lua

@@ -1,4 +1,4 @@
-NetClient = extend(Net)
+local NetClient = extend(app.core.net)
 
 NetClient.signatures = {}
 NetClient.signatures[msgJoin] = {{'username', 'string'}, important = true}
@@ -18,7 +18,7 @@ NetClient.receive['default'] = function(self, event) ctx.event:emit(event.msg, e
 
 NetClient.receive[msgJoin] = function(self, event)
   ctx.id = event.data.id
-  setmetatable(ctx.players:get(ctx.id), {__index = PlayerMain})
+  setmetatable(ctx.players:get(ctx.id), {__index = app.playerMain})
 end
 
 NetClient.receive[msgSnapshot] = function(self, event)
@@ -36,7 +36,7 @@ NetClient.receive[msgSnapshot] = function(self, event)
 end
 
 function NetClient:init()
-  self.other = NetServer
+  self.other = app.netServer
   self:connectTo(serverIp, 6061)
   self.messageBuffer = {}
 
@@ -55,7 +55,7 @@ function NetClient:init()
     self:quit()
   end)
 
-  Net.init(self)
+  app.core.net.init(self)
 end
 
 function NetClient:quit()
@@ -87,3 +87,5 @@ function NetClient:send(msg, data)
 end
 
 NetClient.emit = f.empty
+
+return NetClient

+ 5 - 3
app/netserver.lua

@@ -1,4 +1,4 @@
-NetServer = extend(Net)
+local NetServer = extend(app.core.net)
 
 NetServer.signatures = {}
 NetServer.signatures[evtJoin] = {{'id', '4bits'}, {'username', 'string'}, important = true}
@@ -110,7 +110,7 @@ NetServer.receive[msgChat] = function(self, event)
 end
 
 function NetServer:init()
-  self.other = NetClient
+  self.other = app.netClient
 
   self:listen(6061)
   self.peerToPlayer = {}
@@ -121,7 +121,7 @@ function NetServer:init()
     self:quit()
   end)
 
-  Net.init(self)
+  app.core.net.init(self)
 end
 
 function NetServer:quit()
@@ -212,3 +212,5 @@ function NetServer:nextPlayerId()
     if #ctx.players:get(i).username == 0 then return i end
   end
 end
+
+return NetServer

+ 12 - 10
app/patcher.lua

@@ -1,18 +1,18 @@
-Patcher = class()
+local Patcher = class()
 
 function Patcher:load()
-	local fs = love.filesystem
-	local version = fs.exists('version') and fs.read('version'):match('%w+') or ''
+  local fs = love.filesystem
+  local version = fs.exists('version') and fs.read('version'):match('%w+') or ''
   local os = love.system.getOS()
   if os == 'OS X' then os = 'OSX' end
 
-	local code, gameData = Goregous:patch(version, os)
-	if false and code and f.exe(self['patch' .. os], self, code, gameData) then
-		love.event.quit()
-	else
-		Context:remove(self)
-		Context:add(Menu)
-	end
+  local code, gameData = Goregous:patch(version, os)
+  if false and code and f.exe(self['patch' .. os], self, code, gameData) then
+    love.event.quit()
+  else
+    app.core.context:remove(self)
+    app.core.context:add(Menu)
+  end
 end
 
 function Patcher:patchWindows(code, data)
@@ -43,3 +43,5 @@ function Patcher:patchOSX(code, data)
   os.execute('rm ' .. zip)
   os.execute('open ' .. app .. ' --args local')
 end
+
+return Patcher

+ 3 - 1
app/player.lua

@@ -1,4 +1,4 @@
-Player = class()
+local Player = class()
 
 Player.radius = 28
 Player.collision = {
@@ -366,3 +366,5 @@ function Player:refreshCanvas()
 
   self.canvasDirty = false
 end
+
+return Player

+ 6 - 4
app/playerdummy.lua

@@ -1,11 +1,11 @@
-PlayerDummy = extend(Player)
+local PlayerDummy = extend(app.player)
 
 local function drawTick() return tick - (interp / tickRate) end
 
 function PlayerDummy:activate()
   self.history = {}
 
-  Player.activate(self)
+  app.player.activate(self)
 end
 
 function PlayerDummy:update()
@@ -15,7 +15,7 @@ function PlayerDummy:update()
 
   self:slot()
 
-  Player.update(self)
+  app.player.update(self)
 end
 
 function PlayerDummy:get(t)
@@ -58,7 +58,7 @@ function PlayerDummy:draw()
   self.drawAngle = lerpd.angle
   self.drawX, self.drawY = ctx.view:three(lerpd.x, lerpd.y, lerpd.z)
   self.drawScale = 1 + (ctx.view:convertZ(lerpd.z) / 500)
-  Player.draw(lerpd)
+  app.player.draw(lerpd)
 end
 
 function PlayerDummy:trace(data)
@@ -78,3 +78,5 @@ function PlayerDummy:trace(data)
   self.health, self.shield = data.health or self.health, data.shield or self.shield
   self.weapon, self.skill = data.weapon or self.weapon, data.skill or self.skill
 end
+
+return PlayerDummy

+ 8 - 6
app/playermain.lua

@@ -1,4 +1,4 @@
-PlayerMain = extend(Player)
+local PlayerMain = extend(app.player)
 
 function PlayerMain:activate()
   self.prev = setmetatable({}, self.meta)
@@ -13,7 +13,7 @@ function PlayerMain:activate()
 
   ctx.view.target = self
 
-  Player.activate(self)
+  app.player.activate(self)
 end
 
 function PlayerMain:get(t)
@@ -28,7 +28,7 @@ function PlayerMain:update()
   if self.ded then
     self.ded = timer.rot(self.ded)
     self:fade()
-    return Player.update(self)
+    return app.player.update(self)
   end
 
   self.prev.x = self.x
@@ -54,7 +54,7 @@ function PlayerMain:update()
 
   ctx.net:send(msgInput, input)
 
-  Player.update(self)
+  app.player.update(self)
 
   self.prev.input = input
 end
@@ -65,7 +65,7 @@ function PlayerMain:draw()
   self.drawAngle = lerpd.angle
   self.drawX, self.drawY = ctx.view:three(lerpd.x, lerpd.y, lerpd.z)
   self.drawScale = 1 + (ctx.view:convertZ(lerpd.z) / 500)
-  Player.draw(lerpd)
+  app.player.draw(lerpd)
 end
 
 function PlayerMain:trace(data)
@@ -132,8 +132,10 @@ end
 
 function PlayerMain:die()
   if self.heartbeatSound then self.heartbeatSound:pause() end
-  Player.die(self)
+  app.player.die(self)
   ctx.view:screenshake(20)
   ctx.view.target = nil
   ctx.view.target = self.killer
 end
+
+return PlayerMain

+ 4 - 4
app/playerrobot.lua

@@ -1,9 +1,7 @@
-require 'app/playerserver'
-
-PlayerRobot = extend(PlayerServer)
+local PlayerRobot = extend(app.playerServer)
 
 function PlayerRobot:activate()
-  PlayerServer.activate(self)
+  app.playerServer.activate(self)
 
   self.username = 'robot'
 
@@ -102,3 +100,5 @@ function PlayerRobot:rateDirection(dir)
   score = math.clamp(score, 0, 1)
   return score
 end
+
+return PlayerRobot

+ 4 - 2
app/players.lua

@@ -1,4 +1,4 @@
-Players = class()
+local Players = class()
 Players.max = 15
 
 function Players:init()
@@ -6,7 +6,7 @@ function Players:init()
   self.active = {}
 
   for i = 1, self.max do
-    self.players[i] = ctx.tag == 'server' and PlayerServer() or PlayerDummy()
+    self.players[i] = ctx.tag == 'server' and app.playerServer() or app.playerDummy()
     self.players[i].id = i
   end
 
@@ -109,3 +109,5 @@ function Players:setClass(id, class, team)
   p.team = team
   p:activate()
 end
+
+return Players

+ 8 - 6
app/playerserver.lua

@@ -1,4 +1,4 @@
-PlayerServer = extend(Player)
+local PlayerServer = extend(app.player)
 
 function PlayerServer:activate()
   self.shields = {}
@@ -13,7 +13,7 @@ function PlayerServer:activate()
   self.spawnTimer = 0
   self.spawnMultiplier = 0
 
-  Player.activate(self)
+  app.player.activate(self)
 end
 
 function PlayerServer:get(t)
@@ -37,7 +37,7 @@ end
 function PlayerServer:update()
   if self.ded then
     self:time()
-    return Player.update(self)
+    return app.player.update(self)
   end
 
   self:time()
@@ -69,7 +69,7 @@ function PlayerServer:update()
     self.spawnTimer = .5
   end
 
-  Player.update(self)
+  app.player.update(self)
 end
 
 function PlayerServer:trace(data, ping)
@@ -156,7 +156,7 @@ function PlayerServer:time()
 end
 
 function PlayerServer:spell(kind)
-  Player.spell(self, kind)
+  app.player.spell(self, kind)
 end
 
 function PlayerServer:hurt(data)
@@ -210,7 +210,9 @@ function PlayerServer:spawn()
   table.clear(self.hurtHistory)
   table.clear(self.helpHistory)
 
-  Player.spawn(self)
+  app.player.spawn(self)
 end
 
 PlayerServer.logic = f.empty
+
+return PlayerServer

+ 2 - 2
data/menu/menu.lua

@@ -87,7 +87,7 @@ end
 function Menu:connect(ip)
   serverIp = ip
   serverPort = 6061
-  Context:remove(self)
-  Context:add(Game, self.options.data)
+  app.core.context:remove(self)
+  app.core.context:add(app.core.game, self.options.data)
   love.keyboard.setKeyRepeat(false)
 end

+ 3 - 3
data/menu/menumain.lua

@@ -38,7 +38,7 @@ end
 function MenuMain:host()
   local success = Goregous:createServer()
   if success then
-    local server = Context:add(Server)
+    local server = app.core.context:add(app.core.server)
     server.owner = username
     ctx:connect('localhost')
   else
@@ -51,6 +51,6 @@ function MenuMain:join()
 end
 
 function MenuMain:edit()
-  Context:remove(ctx)
-  Context:add(Editor, ctx.options.data)
+  app.core.context:remove(ctx)
+  app.core.context:add(Editor, ctx.options.data)
 end

+ 1 - 1
data/spell/battleaxe.lua

@@ -1,4 +1,4 @@
-local BattleAxe = extend(Spell)
+local BattleAxe = extend(app.core.spell)
 BattleAxe.code = 'battleaxe'
 BattleAxe.duration = .5
 BattleAxe.radius = 45

+ 1 - 1
data/spell/cleave.lua

@@ -1,4 +1,4 @@
-local Cleave = extend(Spell)
+local Cleave = extend(app.core.spell)
 
 Cleave.code = 'cleave'
 Cleave.radius = 175

+ 1 - 1
data/spell/dagger.lua

@@ -1,4 +1,4 @@
-local Dagger = extend(Spell)
+local Dagger = extend(app.core.spell)
 Dagger.code = 'dagger'
 Dagger.radius = 18
 Dagger.distance = 45

+ 1 - 1
data/spell/dusk.lua

@@ -1,4 +1,4 @@
-local Dusk = extend(Spell)
+local Dusk = extend(app.core.spell)
 
 Dusk.code = 'dusk'
 Dusk.maxDistance = 300

+ 1 - 1
data/spell/energyrifle.lua

@@ -1,4 +1,4 @@
-local EnergyRifle = extend(Spell)
+local EnergyRifle = extend(app.core.spell)
 EnergyRifle.code = 'energyrifle'
 
 EnergyRifle.image = data.media.graphics.effects.pulse

+ 1 - 1
data/spell/lazor.lua

@@ -1,4 +1,4 @@
-local Lazor = extend(Spell)
+local Lazor = extend(app.core.spell)
 Lazor.code = 'lazor'
 
 Lazor.maxCharge = 1.2

+ 1 - 1
data/spell/plasmacannon.lua

@@ -1,4 +1,4 @@
-local PlasmaCannon = extend(Spell)
+local PlasmaCannon = extend(app.core.spell)
 PlasmaCannon.code = 'plasmacannon'
 
 function PlasmaCannon:activate(charge)

+ 1 - 1
data/spell/rocketboots.lua

@@ -1,4 +1,4 @@
-local RocketBoots = extend(Spell)
+local RocketBoots = extend(app.core.spell)
 
 RocketBoots.code = 'rocketboots'
 RocketBoots.maxDistance = 410

+ 1 - 1
data/spell/shotgun.lua

@@ -1,4 +1,4 @@
-local Shotgun = extend(Spell)
+local Shotgun = extend(app.core.spell)
 Shotgun.code = 'shotgun'
 
 Shotgun.duration = .1

+ 1 - 1
data/spell/smg.lua

@@ -1,4 +1,4 @@
-local SMG = extend(Spell)
+local SMG = extend(app.core.spell)
 SMG.code = 'smg'
 
 SMG.duration = .12

+ 1 - 1
data/weapon/energyrifle.lua

@@ -1,4 +1,4 @@
-local EnergyRifle = extend(Weapon)
+local EnergyRifle = extend(app.core.weapon)
 
 ----------------
 -- Meta

+ 2 - 2
data/weapon/plasmacannon.lua

@@ -62,11 +62,11 @@ function PlasmaCannon:update()
 end
 
 function PlasmaCannon:draw(owner)
-  Weapon.draw(self, owner)
+  app.core.weapon.draw(self, owner)
 end
 
 function PlasmaCannon:select(owner)
-  Weapon.select(self, owner)
+  app.core.weapon.select(self, owner)
   self.charge = 0
 end
 

+ 1 - 1
data/weapon/shotgun.lua

@@ -1,4 +1,4 @@
-local Shotgun = extend(Weapon)
+local Shotgun = extend(app.core.weapon)
 
 ----------------
 -- Meta

+ 1 - 1
data/weapon/smg.lua

@@ -1,4 +1,4 @@
-local SMG = extend(Weapon)
+local SMG = extend(app.core.weapon)
 
 ----------------
 -- Meta

+ 0 - 0
app/love.lua → lib/love.lua


+ 2 - 1
main.lua

@@ -1,3 +1,4 @@
+require 'lib/love'
 require 'lib/util'
 require 'lib/slam'
 setmetatable(_G, {
@@ -6,5 +7,5 @@ setmetatable(_G, {
 
 require 'require'
 
-Context:bind(Patcher)
+app.core.context:bind(app.patcher)