-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.lua
175 lines (147 loc) · 3.97 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
function love.load()
lovernetlib = require("lovernet")
server = require "server"
if headless then server.start() return end
client = require "client"
math.randomseed(os.time())
demo_name = nil
demo_ip = "50.116.63.25"
options = {
{
label = "name",
name = function() return "Change name: "..(demo_name or "[Lover]") end,
action = function()
demo_name = nil
end,
},
{
name = function() return "Connect to " .. (demo_ip and "remote" or "localhost") .. " server" end,
action = function()
client.start{ip=demo_ip,name=demo_name}
end,
},
{
label = "ip",
name = function() return "Change demo server ip: "..(demo_ip or "[localhost]") end,
action = function()
demo_ip = nil
end,
},
{
name = function() return server_data and
--"Stop Server"
"Server Hosted" or "Host Server" end,
action = function()
if server_data then
--server.stop()
else
server.start()
demo_ip = nil
end
end,
},
{
name = function()
return "Host Config: " .. (confetti and "Disable Confetti" or "Enable Confetti")
end,
action = function()
confetti = not confetti
end,
},
{
name = function()
return "Toggle Game Of Life: " .. (not conway and 'Dead' or 'Alive')
end,
action = function()
conway = not conway
end,
},
{
name = function() return "Quit" end,
action = love.event.quit,
},
}
current_option = 1
logo = love.graphics.newImage("mascot-and-logo-demo.png")
icon = love.graphics.newImage("icon.png")
icon:setFilter("nearest")
love.window.setIcon( love.image.newImageData("icon.png") )
end
function love.draw()
love.graphics.setColor(255,255,255)
love.graphics.draw(logo,love.graphics.getWidth()-logo:getWidth(),0)
if not client_data then
local offset = (love.graphics.getHeight() - #options*24)/2
love.graphics.printf("Demo",
0,
offset-24,
love.graphics.getWidth(),
"center")
for i,v in pairs(options) do
local name = i == current_option and "> " .. v.name() or v.name()
love.graphics.printf(name,
0,
i*24+offset,
love.graphics.getWidth(),
"center")
end
end
if server_data then server.draw() end
if client_data then client.draw() end
end
function love.keypressed(key)
if not client_data then
if key == "up" then
current_option = current_option - 1
if current_option < 1 then
current_option = #options
end
elseif key == "down" then
current_option = current_option + 1
if current_option > #options then
current_option = 1
end
elseif key == "return" then
options[current_option].action()
elseif key == "backspace" then
if options[current_option].label == "name" then
if demo_name then
demo_name = string.sub(demo_name,1,-2)
if demo_name == "" then demo_name = nil end
end
elseif options[current_option].label == "ip" then
if demo_ip then
demo_ip = string.sub(demo_ip,1,-2)
if demo_ip == "" then demo_ip = nil end
end
end
end
end
if key == "escape" then
if client_data then
client.stop()
--elseif server_data then
--server.stop()
else
love.event.quit()
end
end
end
function love.textinput(letter)
if options[current_option].label == "name" then
demo_name = (demo_name or "" ) .. letter
elseif options[current_option].label == "ip" then
demo_ip = (demo_ip or "") .. letter
end
end
function love.mousepressed(x,y,button)
if client_data then client.mousepressed(x,y,button) end
end
function love.update(dt)
if client_data then client.update(dt) end
if server_data then server.update(dt) end
end
function love.quit()
if client_data then client.stop() end
if server_data then server.stop() end
end