From aa64929f8eb7ba65efcb38a3f8763c8ae606a435 Mon Sep 17 00:00:00 2001 From: wan-may Date: Sat, 16 Sep 2023 21:15:50 -0300 Subject: [PATCH] More menu tweaks; --- src/client/assets/strings/english.lua | 1 + src/client/config.lua | 50 ++++++--- src/client/connecting.lua | 37 ++++++- src/client/scene.lua | 3 +- src/client/test/browser.lua | 2 +- src/client/udp.lua | 9 +- src/client/ui/browser.lua | 149 +++++++++++++++----------- src/client/ui/button.lua | 8 +- src/client/ui/fonts.lua | 9 ++ src/client/ui/mainmenu.lua | 3 +- src/client/ui/menu.lua | 41 +++---- src/client/ui/options.lua | 3 +- src/client/ui/textinput.lua | 24 +++-- src/main.lua | 8 +- src/server.lua | 3 +- src/shared.lua | 4 + src/shared/print.lua | 13 +++ 17 files changed, 236 insertions(+), 131 deletions(-) create mode 100644 src/client/ui/fonts.lua create mode 100644 src/shared/print.lua diff --git a/src/client/assets/strings/english.lua b/src/client/assets/strings/english.lua index 38058de..c4440ff 100644 --- a/src/client/assets/strings/english.lua +++ b/src/client/assets/strings/english.lua @@ -18,4 +18,5 @@ return setmetatable({ ["svinfo_ip"] = "IP", ["svinfo_port"] = "Port", ["refresh_button"] = "Refresh", + ["cancel_button"] = "Cancel", }, {__index = function( t, k ) return k end } ) \ No newline at end of file diff --git a/src/client/config.lua b/src/client/config.lua index d0aaf74..4f59abb 100644 --- a/src/client/config.lua +++ b/src/client/config.lua @@ -1,17 +1,39 @@ -return { - name = "Player Name", - pronoun = "they/them/their", - colour = {0.8, 0.4, 0.4, 0.7}, +local config = {} + +local defaultConfig = { + plName = "Player Name", + plPronoun = "they/them/their", + plR = 0.8, + plG = 0.4, + plB = 0.4, gamma = 0.5, - keybinds = { - forward = "w", - back = "s", - left = "a", - right = "d", - chat = "t", - love = "q", - hate = "e", - }, + keyForward = "w", + keyBack = "s", + keyLeft = "a", + keyRight = "d", + keyChat = "t", + keyLove = "q", + keyHate = "e", serverIP = "192.168.2.15", serverPort = 51312, -} \ No newline at end of file + logFile = "../logs/log.txt", +} + +local function readConfigFile() + return dofile( "./cfg.lua" ) or defaultConfig +end + +local function dumpConfigFile() + print( "Saving Settings." ) + local cfg = assert(io.open( "./cfg.lua", "w" )) + cfg:write( "return {\n " ) + for k, v in pairs( config ) do + cfg:write( k ) + cfg:write( " = " ) + cfg:write( tostring( v ) ) + cfg:write( ",\n" ) + end + cfg:write( "}" ) +end + +return config \ No newline at end of file diff --git a/src/client/connecting.lua b/src/client/connecting.lua index 2e3546b..960f827 100644 --- a/src/client/connecting.lua +++ b/src/client/connecting.lua @@ -1,13 +1,38 @@ local scene = assert( require 'client.scene' ) local lg = assert( love.graphics ) local server = assert( require 'client.udp' ) +local button = assert( require 'client.ui.button' ) +local strings = assert( require 'client.assets.strings.strings' ) local connecting = {} -local time, ip, port +local time, ip, port, attempts = 0, 0, 0, 0 + +local cancelButton = button{ + x = lg.getWidth() / 4, + y = lg.getHeight() / 2, + w = lg.getWidth() / 2, + h = 100, + text = lg.newText( lg.getFont(), strings.cancel_button ), +} + +function connecting.mousemoved( x, y ) + cancelButton.selected = cancelButton:contains( x, y ) +end + +function connecting.mousepressed( x, y ) + if cancelButton:contains( x, y ) then return scene.browser() end +end + +function connecting.keypressed( x, y ) + return scene.browser() +end function connecting.draw() lg.setColor( 1,1,1,1 ) - lg.print( ("CONNECTING:\nTIME: %1.1fs\nADDRESS: %s:%d"):format(time, ip, port), 0, 0, 0 ) + lg.printf( "CONNECTING\nADDRESS\nATTEMPTS", + 15, 15, lg.getWidth() - 30, "left" ) + lg.printf( ("\n%s:%d\n%d"):format( ip, port, attempts ), 15, 15, lg.getWidth() - 30, "right" ) + cancelButton:draw() return false end @@ -19,7 +44,7 @@ function connecting.update(dt) time = time + dt if time > 5 then - return scene.loadScene( scene.game ) + --return scene.loadScene( scene.game ) end return false end @@ -29,7 +54,11 @@ function connecting:onLoad( params ) time = 0 params = params or { ip = "8.8.8.8", port = 8 } ip, port = params.ip, params.port - return server.connect( ip, port ) + return server.isValid( ip, port ) and server.connect( ip, port ) +end + +function connecting.exit() + end scene.connecting = connecting diff --git a/src/client/scene.lua b/src/client/scene.lua index 53959b1..b013f68 100644 --- a/src/client/scene.lua +++ b/src/client/scene.lua @@ -8,12 +8,11 @@ local callbacks = { keypressed = true, update = true, resize = true, + wheelmoved = true, } local mt = {} -print( 'scene', scene ) - function scene.loadScene( scen, params ) print( "Loading Scene:", scen.name ) for k, v in pairs( callbacks ) do diff --git a/src/client/test/browser.lua b/src/client/test/browser.lua index 4b30405..368af81 100644 --- a/src/client/test/browser.lua +++ b/src/client/test/browser.lua @@ -33,7 +33,7 @@ return { --Simulate getting server info from the metaserver. getTestServers = function() packet.get() - for i = 1, r( 1, 13 ) do randserver() end + for i = 1, r( 1, 125 ) do randserver() end return packet.deserialise( packet.get() ) end } \ No newline at end of file diff --git a/src/client/udp.lua b/src/client/udp.lua index 3d73d40..ab7b083 100644 --- a/src/client/udp.lua +++ b/src/client/udp.lua @@ -10,13 +10,20 @@ function udp.receive() return cxn:receive() end +function udp.isValid( ip, port ) + local s, e = socket.udp() + if s then s, e = s:setpeername( ip, port ) end + if s then return true + else return nil, e end --temporary socket, gc it, we just want the error +end + function udp.connect( ip, port ) assert( cxn:setpeername( ip, port ) ) return udp.send( packet.get( packet.heartbeat{ tick = 0, hash = 1234 } ) ) end function udp.disconnect( ) - + end function udp.send( s ) diff --git a/src/client/ui/browser.lua b/src/client/ui/browser.lua index 8a17850..2140a8f 100644 --- a/src/client/ui/browser.lua +++ b/src/client/ui/browser.lua @@ -5,18 +5,15 @@ local button = assert( require 'client.ui.button' ) local packet = assert( require 'shared.packet' ) local menu = assert( require 'client.ui.menu' ) local strings = assert( require 'client.assets.strings.strings' ) +local fonts = assert( require 'client.ui.fonts' ) local utf8 = assert( require 'utf8' ) local browser = {} local test = assert( require 'client.test.browser' ) - -local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 12 ) -local headerFont = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 36 ) -local midFont = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 24 ) - -local cw = font:getWidth( "w" ) +local font = fonts.font +local cw = fonts.font:getWidth( "w" ) local function joinServerCallback( button ) if button.ip and button.port then @@ -30,8 +27,8 @@ local function tryAdd( text, d, x ) end local function serverInfoToText( server ) - local cw = font:getWidth( "w" ) - local text = lg.newText( font ) + local cw = fonts.font:getWidth( "w" ) + local text = lg.newText( fonts.font ) tryAdd( text, server.svname, 0 ) tryAdd( text, server.map, cw * 16 ) text:add( tostring( server.ip ), cw * 32 ) @@ -42,25 +39,14 @@ local function serverInfoToText( server ) end -local serverButtons = {} -local color = { 1, 0.6, 0.6, 0.1 } -local headerButtons = { - button{ x = cw * 53, color = color, y = 135, text = lg.newText( font, strings.svinfo_capacity ) }, - button{ x = cw * 50, color = color, y = 135, text = lg.newText( font, strings.svinfo_players ) }, - button{ x = cw * 44, color = color, y = 135, text = lg.newText( font, strings.svinfo_port ) }, - button{ x = cw * 32, color = color, y = 135, text = lg.newText( font, strings.svinfo_ip ) }, - button{ x = cw * 16, color = color, y = 135, text = lg.newText( font, strings.svinfo_map ) }, - button{ x = cw , color = color, y = 135, text = lg.newText( font, strings.svinfo_name ) }, -} - local serverList = menu.new{ name = "serverList", - buttons = serverButtons, + buttons = {}, fg = lg.newMesh{ { 0.5, 0, 0.5, 0, 0, 0, 0, 0 }, - { 1, 0, 1, 0, 1, 1, 1, 1 }, - { 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 0, 1, 0, 1, 1, 1, 0.5 }, + { 1, 1, 1, 1, 1, 1, 1, 0.5 }, { 0.5, 1, 0.5, 1, 0, 0, 0, 0 }, }, bg = lg.newMesh{ @@ -70,25 +56,69 @@ local serverList = menu.new{ { 0, 1, 0, 1, 0.4, 0.05, 0.05, 0.9 }, }, - font = font, + font = fonts.font, subScene = true } serverList.selected = false serverList.x = 25 serverList.y = 0 serverList.h = 36 +local serverButtons = serverList.buttons +local color = { 1, 0.6, 0.6, 0.1 } +local ti = textInput.new{ + width = lg.getWidth(), + length = 20, + x = cw, + y = 35, + h = 55, + str = strings.ip_button, + font = fonts.midFont, + } +function ti:callback() return self:enterText( browser.joinIPString ) end +local headerButtons = { + + button{ + callback = function() return serverList.refresh( test.getTestServers() ) end, + text = lg.newText( fonts.midFont, strings.refresh_button ) , + color = color, + x = cw * 32, + y = 75, + w = 1400, + h = 36 + }, + + button{ + callback = function() return scene.mainmenu() end, + text = lg.newText( fonts.midFont, strings.mainmenu_button ) , + color = color, + x = cw, + y = 75, + w = 1400, + }, + + ti, + + button{ x = cw * 53, color = color, y = 135, text = lg.newText( font, strings.svinfo_capacity ) }, + button{ x = cw * 50, color = color, y = 135, text = lg.newText( font, strings.svinfo_players ) }, + button{ x = cw * 44, color = color, y = 135, text = lg.newText( font, strings.svinfo_port ) }, + button{ x = cw * 32, color = color, y = 135, text = lg.newText( font, strings.svinfo_ip ) }, + button{ x = cw * 16, color = color, y = 135, text = lg.newText( font, strings.svinfo_map ) }, + button{ x = cw , color = color, y = 135, text = lg.newText( font, strings.svinfo_name ) }, + +} + +for j, headerButton in ipairs( headerButtons ) do + serverButtons[j] = headerButton +end function serverList.refresh( serverInfo ) - - local n = 1 - for j, headerButton in ipairs( headerButtons ) do - serverButtons[j] = headerButton - n = n + 1 - end + local n = #headerButtons + 1 for i, server in ipairs( serverInfo ) do local b = serverButtons[n] or button{} b.space = 0 - b.y = 15 + n * 27 + b.x = cw + b.w = lg.getWidth() + b.y = 27 * i + 145 b.h = 24 b.color = { 0.3 + 0.1 * (n % 2), 0.3 + 0.1 * (n % 2), 0.8, 0.5 } b.callback = joinServerCallback @@ -96,28 +126,16 @@ function serverList.refresh( serverInfo ) b.ip = tostring( server.ip ) b.port = server.port b.text = serverInfoToText( server ) + b.active = ( b.y < lg.getHeight() ) serverButtons[n] = b n = n + 1 - print( "Button: ", i, b.y ) end - - for i = #headerButtons + #serverInfo + 1, #headerButtons + #serverButtons do serverButtons[i] = nil end - --for i = #headerButtons, 1, -1 do - -- table.insert( serverButtons, 1, headerButtons[i] ) - --end + for i = #headerButtons + #serverInfo + 1, #headerButtons + #serverButtons do serverButtons[i] = nil end + return serverList:paint() end -local refreshButton = button{ - callback = serverList.onRefresh, - text = lg.newText( midFont, strings.refresh_button ) , - color = { 1, 1, 1, 0.4 }, - x = 450, - y = 75, - w = 400, - h = 55 - } do local rs = serverList.resize @@ -128,7 +146,7 @@ do end return serverList:paint() end - + local ol = serverList.onLoad function serverList:onLoad() serverList.refresh( test.getTestServers() ) @@ -136,25 +154,26 @@ do end end -local ti = textInput.new{ - width = 300, - length = 20, - x = 150, - y = 75, - str = "8.8.8.8:1234" -} +function serverList.scroll( up ) + local minY = 170 + local maxY = lg.getHeight() + 40 + if up and serverButtons[ #headerButtons + 1 ].y > minY then return end + if ( not up ) and serverButtons[ #serverButtons ].y < maxY then return end + + up = 10 * ( up and 1 or -1 ) + for i = #headerButtons + 1, #serverButtons do + local sb = serverButtons[i] + sb.y = sb.y + up + sb.active = ( sb.y > minY ) and ( sb.y < maxY ) + end + return serverList:paint() +end browser.selected = false function browser.draw() - serverList.draw() lg.setColor( 1, 1, 1, 1 ) - lg.setFont( headerFont ) - lg.print( strings.server_browser, 15, 15 ) - lg.setFont( midFont ) - lg.print( strings.ip_button, 15, 85 ) - refreshButton:draw() - ti:draw() + serverList.draw() end function browser.update( dt ) @@ -167,17 +186,19 @@ function browser.onLoad( ) end function browser.mousemoved( x, y, dx, dy, istouch ) - refreshButton.selected = refreshButton:contains( x, y ) return serverList.mousemoved( x, y, dx, dy, istouch ) end +function browser.wheelmoved( x, y ) + if y == 0 then return end + return serverList.scroll( ( y > 0 ) ) +end + function browser.resize( x, y ) return serverList.resize( x, y ) end function browser.mousepressed(x, y, button, istouch, pressed) - if refreshButton.selected and refreshButton:contains( x, y ) then return serverList.refresh( test.getTestServers() ) end - if ti:contains( x, y ) then return ti:enterText( browser.joinIPString ) end return serverList.mousepressed( x, y, button, istouch, pressed ) end @@ -198,9 +219,7 @@ function browser.joinIP( ip, port ) end function browser.keypressed( key, code, isRepeat ) - if code == "q" then return serverList.refresh( test.getTestServers() ) end if code == "escape" then return scene.mainmenu() end - if code == "return" then return ti:enterText( browser.joinIPString ) end return serverList.keypressed( key, code, isRepeat ) end diff --git a/src/client/ui/button.lua b/src/client/ui/button.lua index 5b0ddf9..00528d9 100644 --- a/src/client/ui/button.lua +++ b/src/client/ui/button.lua @@ -26,6 +26,7 @@ function button:new( t ) t.color = t.color or { 0.5, 0.5, 0.5, 0.5 } t.callback = t.callback or function() print( "Clicked button:", t.text ) end t.selected = t.selected or false + if t.active == nil then t.active = true end button.y = button.y + t.h + button.space @@ -34,10 +35,11 @@ end function button:contains( x, y ) local mx, my, Mx, My = self.x, self.y, self.x + self.w, self.y + self.h - return (x < Mx and x > mx and y > my and y < My) + return self.active and (x < Mx and x > mx and y > my and y < My) end function button:draw( ) + if not self.active then return end lg.setColor( self.color ) lg.rectangle( "fill", self.x, self.y, self.w, self.h, 10) @@ -48,9 +50,9 @@ function button:draw( ) end lg.setColor( 0, 0, 0, 0.8 ) - lg.draw( self.text, self.x + 15, self.y + 6) + lg.draw( self.text, self.x + 15, self.y + self.h / 2 - self.text:getHeight() / 2 ) lg.setColor( 0, 0, 0, 0.2 ) - lg.draw( self.text, self.x + 18, self.y + 8) + lg.draw( self.text, self.x + 12, self.y + self.h / 2 - self.text:getHeight() / 2 )-- + self.h / 2 ) end return setmetatable( button, { __call = button.new } ) \ No newline at end of file diff --git a/src/client/ui/fonts.lua b/src/client/ui/fonts.lua new file mode 100644 index 0000000..3c5acad --- /dev/null +++ b/src/client/ui/fonts.lua @@ -0,0 +1,9 @@ +--References to font objects. +local lgnf = love.graphics.newFont + + +return { + font = lgnf( "client/assets/fonts/Montserrat-Bold.ttf", 14 ), + midFont = lgnf( "client/assets/fonts/Montserrat-Bold.ttf", 24 ), + headerFont = lgnf( "client/assets/fonts/Montserrat-Bold.ttf", 36 ) +} \ No newline at end of file diff --git a/src/client/ui/mainmenu.lua b/src/client/ui/mainmenu.lua index ac40751..e6382a9 100644 --- a/src/client/ui/mainmenu.lua +++ b/src/client/ui/mainmenu.lua @@ -4,8 +4,7 @@ local scene = assert( require 'client.scene' ) local strings = strings or assert( require 'client.assets.strings.english' ) local button = assert( require 'client.ui.button' ) local menu = assert( require 'client.ui.menu' ) - -local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 48 ) +local font = assert( require 'client.ui.fonts').headerFont return menu.new{ name = "mainmenu", diff --git a/src/client/ui/menu.lua b/src/client/ui/menu.lua index 8ee1cf1..f75a2be 100644 --- a/src/client/ui/menu.lua +++ b/src/client/ui/menu.lua @@ -1,7 +1,6 @@ local love = assert( love ) local lg = assert( love.graphics ) local scene = assert( require 'client.scene' ) -print( 'scene', scene ) local menu = {} --Static variables. @@ -30,14 +29,13 @@ function menu.new( t ) if t.subScene then setmetatable( t, t ) else scene[t.name] = t - print( 'scene', scene ) end getmetatable( t ).__index = menu return t end function menu:onLoad() - print( 'loading:', self.name ) + print( 'Loading Menu:', self.name ) currentMenu = self if self.font then lg.setFont( self.font ) end return menu.resize( lg.getDimensions() ) @@ -112,37 +110,28 @@ function menu.keypressed( key, code, isrepeat ) return button:callback() end - if code == "down" or code == "tab" or code == "up" then - local sbi = (selectedButtonIdx or 1) - if buttons[sbi] then buttons[sbi].selected = false end + if #buttons > 0 and (code == "down" or code == "tab" or code == "up") then + repeat + local sbi = (selectedButtonIdx or 1) + if buttons[sbi] then buttons[sbi].selected = false end - --Increment / decrement - sbi = sbi + ((code == "up") and -1 or 1) - if #buttons < 1 then selectedButtonIdx = false; return end - if sbi > #buttons then sbi = 1 end - if sbi < 1 then sbi = #buttons end + --Increment / decrement - --Assign - print( "Selected button: ", sbi ) - selectedButtonIdx = sbi - buttons[selectedButtonIdx].selected = true + sbi = sbi + ((code == "up") and -1 or 1) + if #buttons < 1 then selectedButtonIdx = false; return end + if sbi > #buttons then sbi = 1 end + if sbi < 1 then sbi = #buttons end + + selectedButtonIdx = sbi + buttons[selectedButtonIdx].selected = true + until buttons[selectedButtonIdx].active --Skip deactivated buttons. + print( "Selected button: ", selectedButtonIdx ) end return currentMenu:paint() end -function menu:randomColour() - - local r = math.random - local v = r() * 0.4 + 0.6 - local fg = self.fg - fg:setVertexAttribute( 2, 3, v * (0.7 + 0.2 * r()), v * (0.1 + 0.4 * r()), v * (0.1 * r()), 1 ) - fg:setVertexAttribute( 1, 3, 0.3 * ( 1 - v ), 0, 0, 0.4 * (1 - v) ) - fg:setVertexAttribute( 4, 3, 0.3 * ( 1 - v ), 0, 0, 0.4 * (1 - v) ) - fg:setVertexAttribute( 3, 3, v * (0.7 + 0.2 * r()), v * (0.1 + 0.4 * r()), v * (0.1 * r()), 1 ) -end - function menu:paint() lg.setCanvas( canvas ) diff --git a/src/client/ui/options.lua b/src/client/ui/options.lua index 1d0a299..c340fc0 100644 --- a/src/client/ui/options.lua +++ b/src/client/ui/options.lua @@ -5,8 +5,7 @@ local strings = strings or assert( require 'client.assets.strings.english' ) local button = assert( require 'client.ui.button' ) local menu = assert( require 'client.ui.menu' ) local config = assert( require 'client.config' ) - -local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 18 ) +local font = assert( require 'client.ui.fonts' ).midFont local function editSelectedOption( button ) diff --git a/src/client/ui/textinput.lua b/src/client/ui/textinput.lua index c3bf71a..1a76099 100644 --- a/src/client/ui/textinput.lua +++ b/src/client/ui/textinput.lua @@ -4,6 +4,7 @@ local lg = assert( love.graphics ) local utf8 = assert( require 'utf8' ) local string = assert( string ) +local button = assert( require 'client.ui.button' ) local _lt local _lkp @@ -13,9 +14,9 @@ local _callback local textInput = { } -local __mt = { __index = textInput } +local __mt = { __index = textInput } -local font = lg.newFont( 36 ) +local font = lg.getFont() -- There is only one active text input widget at a time. -- It takes exclusive control of key input. @@ -29,12 +30,13 @@ textInput.y = 0 function textInput.new( t ) t = t or {} t.str = t.str or "" - t.text = lg.newText( font, t.str ) + t.text = lg.newText( t.font or font, t.str ) return setmetatable( t, __mt ) end function textInput.keypressed(key, code, isRepeat) - if activeWidget and textInput[code] then return textInput[code]() end + if activeWidget and textInput[code] then textInput[code]() end + if _lkp then return _lkp() end end function textInput:clear() @@ -48,11 +50,12 @@ function textInput:contains(x, y) end function textInput:draw() - local w, h = self.text:getDimensions() + local w = self.text:getWidth() + local h = (self.font or font):getHeight() lg.setColor( 1, 1, 1, 0.5 ) - lg.rectangle( "fill", self.x, self.y, w, h ) - if activeWidget == self then lg.rectangle( "fill", self.x, self.y, self.width, font:getHeight(), 5 ) end - lg.rectangle( "line", self.x - 3, self.y - 3, self.width + 6, font:getHeight() + 6, 5 ) + if w > 1 then lg.rectangle( "fill", self.x, self.y, math.max( w, 30 ), h, 15, 15 ) end + if self.selected then lg.rectangle( "fill", self.x, self.y, self.width, h, 15, 15 ) end + lg.rectangle( "line", self.x - 3, self.y - 3, self.width + 6, h + 6, 15, 15 ) lg.setColor( 0, 0, 0, 1 ) lg.draw( self.text, self.x or 0, self.y or 0) end @@ -64,6 +67,7 @@ end function textInput.textInput( s ) activeWidget.str = activeWidget.str..s activeWidget.text:set( activeWidget.str ) + if _lkp then return _lkp() end end function textInput.backspace( ) @@ -83,7 +87,11 @@ function textInput:enterText( callback ) _callback = assert( callback ) love.textinput = textInput.textInput love.keypressed = textInput.keypressed + love.mousepressed = nil + love.mousemoved = nil self.oldStr = self.str + self.str = "" + self.text:set( self.str ) activeWidget = self end diff --git a/src/main.lua b/src/main.lua index 17bb1fe..c56f398 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1,9 +1,11 @@ ---Client starts here! local shared = assert( require 'shared' ) local love = assert( love ) function love.load() + print( "Client Started." ) + assert( require 'client.config' ) + --Crash unless coconut present and running luajit 2.1 loadstring( love.data.decode( "string", "base64","G0xKAgrbAQAACgALABY2AAAAOQABADkAAgAnAgMAJwMEADYEAAA5BAEEOQQFBCcGBgA2BwAAOQcHBzkHCAcnCQkAQgcCAEEEAQBBAAICBgAKAFgAAoArAAEAWAEBgCsAAgBMAAIALWQ4MmY3M2RkNjQ1MDcxNDZiNTkwNTMwYjg0NDcwMWZlMmJmYjdjZTkeY2xpZW50L2Fzc2V0cy9jb2NvbnV0LnBuZxFuZXdJbWFnZURhdGEKaW1hZ2UJc2hhMQloYXNoCGhleAtzdHJpbmcLZW5jb2RlCWRhdGEJbG92ZV0BAAUABQAONgAAADMCAQBCAAICDgAAAFgBB4A2AAIANAIAADUDAwA2BAAAPQQEA0IAAwJCAAECMgAAgEwAAgALX19jYWxsAQAAEXNldG1ldGF0YWJsZQAKcGNhbGwA" ))() @@ -17,4 +19,8 @@ function love.load() assert( require 'client.ui.mainmenu' ) assert( require 'client.connecting' ) scenes.loadScene( scenes.mainmenu ) +end + +function love.quit() + print( "Client Quit." ) end \ No newline at end of file diff --git a/src/server.lua b/src/server.lua index 1ec35ac..11b423c 100644 --- a/src/server.lua +++ b/src/server.lua @@ -25,8 +25,7 @@ local clients = {} do local _print = print function server.Print(...) - local time = os.date("!%Y-%m-%d %X") - _print( time, ... ) + _print( os.date("!%Y-%m-%d %X"), ... ) --server.logFile:write( table.concat({ ... }, "\t"), "\n" ) end end diff --git a/src/shared.lua b/src/shared.lua index b767801..9bc8e32 100644 --- a/src/shared.lua +++ b/src/shared.lua @@ -4,6 +4,10 @@ local shared = {} shared.ip = assert( require 'shared.ipstring' ) shared.packet = assert( require 'shared.packet' ) +shared.print = assert( require 'shared.print' ) + +--Turn on logging? +print = shared.print --World state. diff --git a/src/shared/print.lua b/src/shared/print.lua new file mode 100644 index 0000000..95fcb48 --- /dev/null +++ b/src/shared/print.lua @@ -0,0 +1,13 @@ +local _print = print +local log = assert( io.open( ("../logs/log_%04d.txt"):format( os.time() % 1000 ), "a" )) +return function( ... ) + + log:write( os.date("!%S") ) + for i, v in ipairs{...} do + log:write("\t") + log:write(tostring(v)) + end + log:write("\n") + + return _print( ... ) +end \ No newline at end of file