Browse Source

Environment; Goregous class; Click sound change;

bjorn 11 years ago
parent
commit
d0c9ed4bf6
7 changed files with 31 additions and 43 deletions
  1. 20 27
      data/goregous/goregous.lua
  2. 4 5
      data/menu/menu.lua
  3. 1 4
      data/menu/menulogin.lua
  4. 1 3
      data/menu/menumain.lua
  5. 1 2
      data/menu/menuserverlist.lua
  6. 3 2
      main.lua
  7. 1 0
      require.lua

+ 20 - 27
data/goregous/goregous.lua

@@ -1,38 +1,31 @@
-require 'love.filesystem'
-local timer = require 'love.timer'
+Goregous = class()
 
-local inbox = love.thread.getChannel('goregous.in')
-local outbox = love.thread.getChannel('goregous.out')
-
-local socket = (require('socket')).tcp()
-socket:settimeout(10)
-
-local _, e = socket:connect('107.4.63.70', 6060)
-if e then error('Can\'t connect to goregous') end 
-
-socket:settimeout(0)
-
-while true do
-  while inbox:getCount() > 0 do
-    local data = inbox:pop()
-    if data == 'quit' then
-      socket:close()
-      return
-    end
-    print('Sending ' .. data[1])
-    socket:send(table.concat(data, ',') .. '\n')
-  end
+function Goregous:init()
+  self.socket = (require('socket')).tcp()
+  self.socket:settimeout(10)
+  local ip = (env == 'local') and '127.0.0.1' or '71.210.238.44'
+  local _, e = self.socket:connect(ip, 6060)
+  if e then error('Can\'t connect to goregous') end
+  self.socket:settimeout(0)
+  self.messages = {}
+end
 
+function Goregous:update()
   while true do
-    local str = socket:receive('*l')
+    str = self.socket:receive('*l')
     if not str then break end
-    print('Received "' .. str .. '"')
     local data = {}
     for word in string.gmatch(str, '([^,]+)') do
       table.insert(data, word)
     end
-    outbox:push(data)
+    table.insert(self.messages, data)
   end
+end
 
-  love.timer.sleep(.1)
+function Goregous:quit()
+  self.socket:close()
 end
+
+function Goregous:send(data)
+  self.socket:send(table.concat(data, ',') .. '\n')
+end

+ 4 - 5
data/menu/menu.lua

@@ -29,14 +29,12 @@ function Menu:load()
   
   self.container = Container()
 
-  local goregous = love.thread.newThread('data/goregous/goregous.lua')
-  goregous:start()
+  goregous = goregous or Context:add(Goregous)
 end
 
 function Menu:update()
-  local outbox = love.thread.getChannel('goregous.out')
-  while outbox:getCount() > 0 do
-    local data = outbox:pop()
+  while #goregous.messages > 0 do
+    local data = goregous.messages[1]
     if data[1] == 'login' then
       self.loader:deactivate()
       if data[2] == 'ok' then
@@ -61,6 +59,7 @@ function Menu:update()
       self.serverlist:setServers(data)
       self.loader:deactivate()
     end
+    table.remove(goregous.messages, 1)
   end
 
   self.loader:update()

+ 1 - 4
data/menu/menulogin.lua

@@ -16,8 +16,6 @@ function MenuLogin:mousepressed(x, y, button)
 
   if ribbon == 1 then ctx.input:focusInput('nickname')
   elseif ribbon == 2 then self:login() end
-
-  if ribbon then data.media.sounds.click:play() end
 end
 
 function MenuLogin:keypressed(key)
@@ -47,7 +45,6 @@ function MenuLogin:login()
   username = ctx.input:val('nickname')
   if #username == 0 then return end
 
-  love.thread.getChannel('goregous.in'):push({'login', username})
+  goregous:send({'login', username})
   ctx.loader:activate('Logging in')
-  data.media.sounds.click:play()
 end

+ 1 - 3
data/menu/menumain.lua

@@ -32,13 +32,11 @@ function MenuMain:mousepressed(x, y, button)
     elseif ribbon == 2 then self:join()
     elseif ribbon == 3 then self:edit()
     elseif ribbon == 4 then love.event.quit() end
-
-    if ribbon then data.media.sounds.click:play() end
   end
 end
 
 function MenuMain:host()
-  love.thread.getChannel('goregous.in'):push({'createServer'})
+  goregous:send({'createServer'})
   ctx.loader:activate('Creating server')
 end
 

+ 1 - 2
data/menu/menuserverlist.lua

@@ -64,9 +64,8 @@ function MenuServerList:mousepressed(x, y, button)
 end
 
 function MenuServerList:refresh()
-  love.thread.getChannel('goregous.in'):push({'listServers'})
+  goregous:send({'listServers'})
   ctx.loader:activate('Finding servers')
-  data.media.sounds.click:play()
 end
 
 function MenuServerList:setServers(servers)

+ 3 - 2
main.lua

@@ -1,6 +1,6 @@
 require 'require'
 
-function love.load(arg)  
+function love.load(arg)
   data.load()
   Context:add(Menu)
 end
@@ -11,4 +11,5 @@ love.quit = Context.quit
 
 love.handlers = setmetatable({}, {__index = Context})
 
-if arg[2] == 'test' then require 'test/test' end
+env = arg[2] or 'release'
+if env == 'test' then require 'test/test' end

+ 1 - 0
require.lua

@@ -20,3 +20,4 @@ load 'lib/gooey'
 load 'data/loader'
 load 'data/hud'
 load 'data/menu'
+load 'data/goregous'