-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
198 lines (187 loc) · 3.8 KB
/
init.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
-- vim:et
require "readline"
local readline=Readline:new(15)
local nick=""
local addr=""
local init_st=1
net_err=nil
repiter=nil
replay=false
conf={}
function save_conf()
local f=love.filesystem.newFile("netwars.cfg")
f:open("w")
f:write("return {\n")
for k,v in pairs(conf) do
if type(v)=="number" then
f:write(string.format("%s=%s;\n",k,v))
end
if type(v)=="string" then
f:write(string.format("%s=\"%s\";\n",k,v))
end
end
f:write("}\n")
f:close()
end
function load_conf()
if love.filesystem.exists("netwars.cfg") then
local chunk=love.filesystem.load("netwars.cfg")
local t=chunk()
if t.ver==CVER then
conf=t
return true
end
end
conf.ver=CVER
conf.graph_width=graph.getWidth()
conf.graph_height=graph.getHeight()
conf.chat_timeout=5.0
save_conf()
chat.timeout=conf.chat_timeout
return false
end
function set_graph()
graph.setMode(conf.graph_width,conf.graph_height)
end
function init_graph()
local font=graph.newFont(12)
graph.setFont(font)
eye.sx=graph.getWidth()
eye.sy=graph.getHeight()
eye.cx=eye.sx/2
eye.cy=eye.sy/2
eye.x=eye.vx+eye.cx/eye.s
eye.y=eye.vy+eye.cy/eye.s
graph.setBackgroundColor(0,0,0)
end
function init_gui()
local o
local cl={"R","t","V"}
local x=25
local objs={}
for i,v in ipairs(cl) do
if d_cl[v] then
o=d_cl[v]:new(nil,x,eye.sy-25)
end
if u_cl[v] then
o=u_cl[v]:new(nil,x,eye.sy-25)
end
o.hud=true
objs[i]=o
x=x+40
end
buydevs[1]=objs
cl={"B"}
x=25
objs={}
for i,v in ipairs(cl) do
o=d_cl[v]:new(nil,x,eye.sy-25)
o.hud=true
objs[i]=o
x=x+40
end
buydevs[2]=objs
end
local function init_enter()
buf={}
if init_st==1 then
if readline.str:len()>15 or readline.str:len()<1 then
readline:clr()
return
end
if readline.str:match("[%a%d_%-]*")~=readline.str then
readline:clr()
return
end
nick=readline.str
readline:clr()
readline.sz=30
init_st=2
return
end
if init_st==2 then
if readline.str:len()>30 or readline.str:len()<1 then
readline:clr()
return
end
if readline.str:match("[%a%d%.%-]*")~=readline.str then
readline:clr()
return
end
addr=readline.str
readline:clr()
init_st=3
return
end
end
function init_keypressed(key,ch)
if console.input then
console.input=console.keypressed(key,ch)
return
end
if key=="escape" then
love.event.push("q")
return
end
if key=="return" then
return init_enter()
end
if key=="`" or key=="f1" then
console.input=true
return
end
readline:key(key,ch)
end
function init_draw()
graph.push()
graph.scale(2)
graph.setColor(255,255,255)
if init_st==1 then
readline:draw(50,eye.cy/2-20,"Nick: ")
graph.print("Host: "..addr,50,eye.cy/2)
end
if init_st==2 then
graph.print("Nick: "..nick,50,eye.cy/2-20)
readline:draw(50,eye.cy/2,"Host: ")
end
if init_st>2 then
graph.print("Nick: "..nick,50,eye.cy/2-20)
graph.print("Host: "..addr,50,eye.cy/2)
graph.print("connecting...",50,eye.cy/2+30)
end
if net_err then
graph.print(net_err,50,eye.cy/2+50)
end
graph.pop()
console.draw()
end
local cr_dt=0
function init_update(dt)
cr_dt=cr_dt+dt
if cr_dt>=0.5 then
cr_dt=cr_dt-0.5
readline.cr=not readline.cr
end
if init_st==3 then
net_conn(addr,nick)
init_st=9
end
if init_st>8 then
if net_sync() then
if ME then
love.draw=main_draw
love.update=main_update
love.quit=main_quit
love.keypressed=main_keypressed
love.keyreleased=main_keyreleased
love.mousepressed=main_mousepressed
love.mousereleased=main_mousereleased
end
end
if net_err then
net_abort()
init_st=1
end
end
console.update(dt)
end