Update host.lua and join.lua in light of recent changes
* Use the wesnoth.plugin module * Use .tag and .contents instead of [1] and [2] * Remove superfluous parentheses on function calls
This commit is contained in:
parent
68105ed4cc
commit
1b4fe1b61b
2 changed files with 77 additions and 95 deletions
|
@ -9,8 +9,6 @@ local function plugin()
|
||||||
|
|
||||||
local counter = 0
|
local counter = 0
|
||||||
|
|
||||||
local events, context, info
|
|
||||||
|
|
||||||
local function idle_text(text)
|
local function idle_text(text)
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
if counter >= 100 then
|
if counter >= 100 then
|
||||||
|
@ -21,59 +19,56 @@ local function plugin()
|
||||||
|
|
||||||
log("hello world")
|
log("hello world")
|
||||||
|
|
||||||
repeat
|
local events, context, info = wesnoth.plugin.wait_until_any({"titlescreen", "Multiplayer Lobby"}, function(name)
|
||||||
events, context, info = coroutine.yield()
|
idle_text("in " .. name .. " waiting for titlescreen or lobby")
|
||||||
idle_text("in " .. info.name .. " waiting for titlescreen or lobby")
|
end)
|
||||||
until info.name == "titlescreen" or info.name == "Multiplayer Lobby"
|
|
||||||
|
|
||||||
local tries = 0
|
local tries = 0
|
||||||
while info.name == "titlescreen" and tries < 100 do
|
while info.name == "titlescreen" and tries < 100 do
|
||||||
context.play_multiplayer({})
|
context.play_multiplayer{}
|
||||||
tries = tries + 1
|
tries = tries + 1
|
||||||
log("playing multiplayer...")
|
log("playing multiplayer...")
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
end
|
end
|
||||||
if info.name == "titlescreen" then
|
if info.name == "titlescreen" then
|
||||||
context.exit({code = 1})
|
context.exit{code = 1}
|
||||||
coroutine.yield()
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
repeat
|
events, context, info = wesnoth.plugin.wait_until("Multiplayer Lobby", function(name)
|
||||||
events, context, info = coroutine.yield()
|
idle_text("in " .. name .. " waiting for lobby")
|
||||||
idle_text("in " .. info.name .. " waiting for lobby")
|
end)
|
||||||
until info.name == "Multiplayer Lobby"
|
|
||||||
|
|
||||||
context.chat({message = "hosting"})
|
context.chat{message = "hosting"}
|
||||||
log("creating a game")
|
log("creating a game")
|
||||||
context.create({})
|
context.create{}
|
||||||
|
|
||||||
repeat
|
events, context, info = wesnoth.plugin.wait_until("Multiplayer Create", function(name)
|
||||||
events, context, info = coroutine.yield()
|
idle_text("in " .. name .. " waiting for create")
|
||||||
idle_text("in " .. info.name .. " waiting for create")
|
end)
|
||||||
until info.name == "Multiplayer Create"
|
|
||||||
|
|
||||||
context.select_type({type = "scenario"})
|
context.select_type{type = "scenario"}
|
||||||
local s = info.find_level({id = "test1"})
|
local s = info.find_level{id = "test1"}
|
||||||
if s.index < 0 then
|
if s.index < 0 then
|
||||||
log(" error: Could not find scenario with id=test1")
|
log(" error: Could not find scenario with id=test1")
|
||||||
end
|
end
|
||||||
context.select_level({index = s.index})
|
context.select_level{index = s.index}
|
||||||
|
|
||||||
log("configuring a game")
|
log("configuring a game")
|
||||||
context.set_name({name = "Test"})
|
context.set_name{name = "Test"}
|
||||||
context.update_settings({registered_users = false})
|
context.update_settings{registered_users = false}
|
||||||
|
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
|
|
||||||
context.create({})
|
context.create{}
|
||||||
|
|
||||||
local ready = nil
|
local ready = nil
|
||||||
repeat
|
repeat
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
for i,v in ipairs(events) do
|
for i,v in ipairs(events) do
|
||||||
if v[1] == "chat" then
|
if v.tag == "chat" then
|
||||||
std_print(events[i][2])
|
std_print(events[i].contents.message)
|
||||||
if v[2].message == "ready" then
|
if v.contents.message == "ready" then
|
||||||
ready = true
|
ready = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -82,31 +77,28 @@ local function plugin()
|
||||||
until ready
|
until ready
|
||||||
|
|
||||||
log("starting game...")
|
log("starting game...")
|
||||||
context.chat({message = "starting"})
|
context.chat{message = "starting"}
|
||||||
context.launch({})
|
context.launch{}
|
||||||
|
|
||||||
repeat
|
events, context, info = wesnoth.plugin.wait_until("Game", function(name)
|
||||||
events, context, info = coroutine.yield()
|
idle_text("in " .. name .. " waiting for game")
|
||||||
idle_text("in " .. info.name .. " waiting for game")
|
end)
|
||||||
until info.name == "Game"
|
|
||||||
|
|
||||||
log("got to a game context...")
|
log("got to a game context...")
|
||||||
|
|
||||||
repeat
|
events, context, info = wesnoth.plugin.wait_until_not("Game", function(name)
|
||||||
events, context, info = coroutine.yield()
|
idle_text("in " .. name .. " waiting for not game")
|
||||||
idle_text("in " .. info.name .. " waiting for not game")
|
end)
|
||||||
until info.name ~= "Game"
|
|
||||||
|
|
||||||
log("left a game context...")
|
log("left a game context...")
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
context.quit({})
|
context.quit({})
|
||||||
log("quitting a " .. info.name .. " context...")
|
log("quitting a " .. info.name .. " context...")
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
until info.name == "titlescreen"
|
until info.name == "titlescreen"
|
||||||
|
|
||||||
context.exit({code = 0})
|
context.exit({code = 0})
|
||||||
coroutine.yield()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return plugin
|
return plugin
|
||||||
|
|
|
@ -9,8 +9,6 @@ local function plugin()
|
||||||
|
|
||||||
local counter = 0
|
local counter = 0
|
||||||
|
|
||||||
local events, context, info
|
|
||||||
|
|
||||||
local function find_test_game(game_info)
|
local function find_test_game(game_info)
|
||||||
local g = game_info.game_list()
|
local g = game_info.game_list()
|
||||||
if g then
|
if g then
|
||||||
|
@ -18,8 +16,8 @@ local function plugin()
|
||||||
if gamelist then
|
if gamelist then
|
||||||
for i = 1, #gamelist do
|
for i = 1, #gamelist do
|
||||||
local t = gamelist[i]
|
local t = gamelist[i]
|
||||||
if t[1] == "game" then
|
if t.tag == "game" then
|
||||||
local game = t[2]
|
local game = t.contents
|
||||||
if game.scenario == "Test" then
|
if game.scenario == "Test" then
|
||||||
return game.id
|
return game.id
|
||||||
end
|
end
|
||||||
|
@ -40,41 +38,39 @@ local function plugin()
|
||||||
|
|
||||||
log("hello world")
|
log("hello world")
|
||||||
|
|
||||||
repeat
|
local events, context, info = wesnoth.plugin.wait_until_any({"titlescreen", "Multiplayer Lobby"}, function(name)
|
||||||
events, context, info = coroutine.yield()
|
idle_text("in " .. name .. " waiting for titlescreen or lobby")
|
||||||
idle_text("in " .. info.name .. " waiting for titlescreen or lobby")
|
end)
|
||||||
until info.name == "titlescreen" or info.name == "Multiplayer Lobby"
|
|
||||||
|
|
||||||
local tries = 0
|
local tries = 0
|
||||||
while info.name == "titlescreen" and tries < 100 do
|
while info.name == "titlescreen" and tries < 100 do
|
||||||
context.play_multiplayer({})
|
context.play_multiplayer{}
|
||||||
tries = tries + 1
|
tries = tries + 1
|
||||||
log("playing multiplayer...")
|
log("playing multiplayer...")
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
end
|
end
|
||||||
if info.name == "titlescreen" then
|
if info.name == "titlescreen" then
|
||||||
context.exit({code = 1})
|
context.exit{code = 1}
|
||||||
coroutine.yield()
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
repeat
|
events, context, info = wesnoth.plugin.wait_until("Multiplayer Lobby", function(name)
|
||||||
events, context, info = coroutine.yield()
|
idle_text("in " .. name .. " waiting for lobby")
|
||||||
idle_text("in " .. info.name .. " waiting for lobby")
|
end)
|
||||||
until info.name == "Multiplayer Lobby"
|
|
||||||
|
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
|
|
||||||
context.chat({message = "waiting for test game to join..."})
|
context.chat{message = "waiting for test game to join..."}
|
||||||
|
|
||||||
local test_game = nil
|
local test_game = nil
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
idle_text("in " .. info.name .. " waiting for test game")
|
idle_text("in " .. info.name .. " waiting for test game")
|
||||||
|
|
||||||
for i,v in ipairs(events) do
|
for i,v in ipairs(events) do
|
||||||
if v[1] == "chat" then
|
if v.tag == "chat" then
|
||||||
std_print("chat:", v[2].message)
|
std_print("chat:", v.contents.message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,76 +78,70 @@ local function plugin()
|
||||||
until test_game
|
until test_game
|
||||||
|
|
||||||
log("found a test game, joining... id = " .. test_game)
|
log("found a test game, joining... id = " .. test_game)
|
||||||
context.chat({message = "found test game"})
|
context.chat{message = "found test game"}
|
||||||
context.select_game({id = test_game})
|
context.select_game{id = test_game}
|
||||||
|
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
|
|
||||||
context.chat({message = "going to join"})
|
context.chat{message = "going to join"}
|
||||||
|
|
||||||
context.join({})
|
context.join{}
|
||||||
|
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
|
|
||||||
-- Don't know why THIS context has to chat member but it doesn't
|
-- Don't know why THIS context has no chat member but it doesn't
|
||||||
-- Adding the guard if to bypass a script crash and get mp_tests running.
|
-- Adding the guard if to bypass a script crash and get mp_tests running.
|
||||||
-- GAL 28NOV2017
|
-- GAL 28NOV2017
|
||||||
if context.chat then
|
if context.chat then
|
||||||
context.chat({message = "done first join"})
|
context.chat{message = "done first join"}
|
||||||
end
|
end
|
||||||
|
|
||||||
while not (info.name == "Dialog" or info.name == "Multiplayer Join") do
|
while not (info.name == "Dialog" or info.name == "Multiplayer Join") do
|
||||||
if context.join then
|
if context.join then
|
||||||
context.join({})
|
context.join{}
|
||||||
else
|
else
|
||||||
std_print("did not find join...")
|
std_print("did not find join...")
|
||||||
end
|
end
|
||||||
|
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
idle_text("in " .. info.name .. " waiting for leader select dialog")
|
idle_text("in " .. info.name .. " waiting for leader select dialog")
|
||||||
end
|
end
|
||||||
|
|
||||||
if info.name == "Dialog" then
|
if info.name == "Dialog" then
|
||||||
log("got a leader select dialog...")
|
log("got a leader select dialog...")
|
||||||
context.skip_dialog({})
|
context.skip_dialog{}
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.wait_until("Multiplayer Join", function(name)
|
||||||
|
idle_text("in " .. name .. " waiting for mp join")
|
||||||
repeat
|
end)
|
||||||
events, context, info = coroutine.yield()
|
|
||||||
idle_text("in " .. info.name .. " waiting for mp join")
|
|
||||||
until info.name == "Multiplayer Join"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
log("got to multiplayer join...")
|
log("got to multiplayer join...")
|
||||||
context.chat({message = "ready"})
|
context.chat{message = "ready"}
|
||||||
|
|
||||||
repeat
|
events, context, info = wesnoth.plugin.wait_until("Game", function(name)
|
||||||
events, context, info = coroutine.yield()
|
idle_text("in " .. name .. " waiting for game")
|
||||||
idle_text("in " .. info.name .. " waiting for game")
|
end)
|
||||||
until info.name == "Game"
|
|
||||||
|
|
||||||
log("got to a game context...")
|
log("got to a game context...")
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
idle_text("in " .. info.name .. " waiting for the last scenario")
|
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"
|
until info.scenario_name ~= nil and info.scenario_name().scenario_name == "Multiplayer Unit Test test2"
|
||||||
|
|
||||||
repeat
|
events, context, info = wesnoth.plugin.wait_until_not("Game", function(name)
|
||||||
events, context, info = coroutine.yield()
|
idle_text("in " .. name .. " waiting for not game")
|
||||||
idle_text("in " .. info.name .. " waiting for not game")
|
end)
|
||||||
until info.name ~= "Game"
|
|
||||||
|
|
||||||
log("left a game context...")
|
log("left a game context...")
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
context.quit({})
|
context.quit{}
|
||||||
log("quitting a " .. info.name .. " context...")
|
log("quitting a " .. info.name .. " context...")
|
||||||
events, context, info = coroutine.yield()
|
events, context, info = wesnoth.plugin.next_slice()
|
||||||
until info.name == "titlescreen"
|
until info.name == "titlescreen"
|
||||||
|
|
||||||
context.exit({code = 0})
|
context.exit{code = 0}
|
||||||
coroutine.yield()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return plugin
|
return plugin
|
||||||
|
|
Loading…
Add table
Reference in a new issue