forked from wesnoth/wesnoth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
join-gui2.lua
156 lines (119 loc) · 3.77 KB
/
join-gui2.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
-- join.lua --
-- Try to join a game called "Test"
local function plugin()
local function log(text)
std_print("join: " .. text)
end
local counter = 0
local events, context, info
local helper = wesnoth.require("lua/helper.lua")
local function find_test_game(info)
local g = info.game_list()
if g then
local gamelist = helper.get_child(g, "gamelist")
if gamelist then
for i = 1, #gamelist do
local t = gamelist[i]
if t[1] == "game" then
local game = t[2]
if game.scenario == "Test" then
return game.id
end
end
end
end
end
return nil
end
local function idle_text(text)
counter = counter + 1
if counter >= 100 then
counter = 0
log("idling " .. text)
end
end
log("hello world")
wesnoth.preferences.new_lobby = true
repeat
events, context, info = coroutine.yield()
idle_text("in " .. info.name .. " waiting for titlescreen or lobby")
until info.name == "titlescreen" or info.name == "Multiplayer Lobby"
local tries = 0
while info.name == "titlescreen" and tries < 100 do
context.play_multiplayer({})
tries = tries + 1
log("playing multiplayer...")
events, context, info = coroutine.yield()
end
if info.name == "titlescreen" then
context.exit({code = 1})
coroutine.yield()
end
repeat
events, context, info = coroutine.yield()
idle_text("in " .. info.name .. " waiting for lobby")
until info.name == "Multiplayer Lobby"
events, context, info = coroutine.yield()
context.chat({message = "waiting for test game to join..."})
local test_game = nil
repeat
events, context, info = coroutine.yield()
idle_text("in " .. info.name .. " waiting for test game")
for i,v in ipairs(events) do
if v[1] == "chat" then
std_print("chat:", v[2].message)
end
end
test_game = find_test_game(info)
until test_game
log("found a test game, joining... id = " .. test_game)
context.chat({message = "found test game"})
context.select_game({id = test_game})
events, context, info = coroutine.yield()
context.chat({message = "going to join"})
context.join({})
events, context, info = coroutine.yield()
context.chat({message = "done first join"})
while not (info.name == "Dialog" or info.name == "Multiplayer Wait") do
if context.join then
context.join({})
else
std_print("did not find join...")
end
events, context, info = coroutine.yield()
idle_text("in " .. info.name .. " waiting for leader select dialog")
end
if info.name == "Dialog" then
log("got a leader select dialog...")
context.skip_dialog({})
events, context, info = coroutine.yield()
repeat
events, context, info = coroutine.yield()
idle_text("in " .. info.name .. " waiting for mp wait")
until info.name == "Multiplayer Wait"
end
log("got to multiplayer wait...")
context.chat({message = "ready"})
repeat
events, context, info = coroutine.yield()
idle_text("in " .. info.name .. " waiting for game")
until info.name == "Game"
log("got to a game context...")
repeat
events, context, info = coroutine.yield()
idle_text("in " .. info.name .. " waiting for the last scenario")
until info.scenario_name ~= nil and info.scenario_name().scenario_name == "Multiplayer Unit Test test2"
repeat
events, context, info = coroutine.yield()
idle_text("in " .. info.name .. " waiting for not game")
until info.name ~= "Game"
log("left a game context...")
repeat
context.quit({})
log("quitting a " .. info.name .. " context...")
events, context, info = coroutine.yield()
until info.name == "titlescreen"
context.exit({code = 0})
coroutine.yield()
end
return plugin