Skip to content

Commit

Permalink
Added option to use Spring.Restart instead of Spring.Start.
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogleFrog committed Jul 29, 2016
1 parent 7bab640 commit ef90836
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
6 changes: 6 additions & 0 deletions LuaUI/widgets/chobby/components/configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function Configuration:init()
self.notifyForAllChat = true
self.debugMode = false
self.onlyShowFeaturedMaps = true
self.useSpringRestart = false

self.font = {
[0] = {size = 10, shadow = false},
Expand Down Expand Up @@ -103,6 +104,8 @@ function Configuration:GetConfigData()
confirmation_mainMenuFromBattle = self.confirmation_mainMenuFromBattle,
confirmation_battleFromBattle = self.confirmation_battleFromBattle,
loadLocalWidgets = self.loadLocalWidgets,
onlyShowFeaturedMaps = self.onlyShowFeaturedMaps,
useSpringRestart = self.useSpringRestart,
}
end

Expand All @@ -115,6 +118,9 @@ function Configuration:SetConfigValue(key, value)
return
end
self[key] = value
if key == "useSpringRestart" then
lobby.useSpringRestart = value
end
self:_CallListeners("OnConfigurationChange", key, value)
end

Expand Down
2 changes: 1 addition & 1 deletion LuaUI/widgets/gui_battle_room_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ local function SetupInfoButtonsPanel(leftInfo, rightInfo, battle, battleID, myUs
if battle.isRunning then
battleLobby:ConnectToBattle()
else
battleLobby:StartBattle()
battleLobby:StartBattle(WG.Chobby.Configuration.useSpringRestart)
end
else
Spring.Echo("Do something if map or game is missing")
Expand Down
17 changes: 17 additions & 0 deletions LuaUI/widgets/gui_settings_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,23 @@ local function InitializeControls(window)
}
offset = offset + 30

local useSpringRestart = Checkbox:New {
x = 60,
width = 200,
y = offset,
height = 40,
parent = window,
boxalign = "right",
boxsize = 20,
caption = "Use Spring.Restart EXPERIMENTAL",
checked = Configuration.useSpringRestart or false,
font = Configuration:GetFont(2),
OnChange = {function (obj, newState)
Configuration:SetConfigValue("useSpringRestart", newState)
end},
}
offset = offset + 30

------------------------------------------------------------------
-- Ingame
------------------------------------------------------------------
Expand Down
12 changes: 8 additions & 4 deletions libs/liblobby/lobby/interface_skirmish.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local function ScriptTXT(script)
return string
end

function InterfaceSkirmish:_StartScript(gameName, mapName, playerName)
function InterfaceSkirmish:_StartScript(gameName, mapName, playerName, useSpringRestart)
local allyTeams = {}
local allyTeamCount = 0
local teams = {}
Expand Down Expand Up @@ -116,16 +116,20 @@ function InterfaceSkirmish:_StartScript(gameName, mapName, playerName)
local scriptTxt = ScriptTXT(script)
scriptFile:write(scriptTxt)
scriptFile:close()
Spring.Start(scriptFileName, "")
if useSpringRestart then
Spring.Restart(scriptFileName, "")
else
Spring.Start(scriptFileName, "")
end
end

-- TODO: Needs clean implementation in lobby.lua
function InterfaceSkirmish:StartBattle()
function InterfaceSkirmish:StartBattle(useSpringRestart)
local battle = self:GetBattle(self:GetMyBattleID())
if battle.gameName and battle.mapName then
self:_CallListeners("OnBattleAboutToStart")
self:_OnSaidBattleEx("Battle", "about to start")
self:_StartScript(battle.gameName, battle.mapName, self:GetMyUserName() or "noname")
self:_StartScript(battle.gameName, battle.mapName, self:GetMyUserName() or "noname", useSpringRestart)
end
return self
end
Expand Down
10 changes: 7 additions & 3 deletions libs/liblobby/lobby/lobby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function Lobby:SayBattleEx(message)
return self
end

function Lobby:ConnectToBattle()
function Lobby:ConnectToBattle(useSpringRestart)
if not self.myBattleID then
Spring.Echo("Cannot connect to battle.")
return
Expand All @@ -162,7 +162,11 @@ function Lobby:ConnectToBattle()
local battle = self:GetBattle(self.myBattleID)
local springURL = "spring://" .. self:GetMyUserName() .. ":" .. self:GetScriptPassword() .. "@" .. battle.ip .. ":" .. battle.port
Spring.Echo(springURL)
Spring.Start(springURL, "")
if useSpringRestart then
Spring.Restart(springURL, "")
else
Spring.Start(springURL, "")
end
--local scriptFileName = "scriptFile.txt"
--local scriptFile = io.open(scriptFileName, "w")
--local scriptTxt = GenerateScriptTxt(battleID)
Expand Down Expand Up @@ -310,7 +314,7 @@ function Lobby:_OnUpdateUserStatus(userName, status)
if self.myBattleID and status.isInGame then
local myBattle = self:GetBattle(self.myBattleID)
if myBattle and myBattle.founder == userName then
self:ConnectToBattle()
self:ConnectToBattle(self.useSpringRestart)
end
end
end
Expand Down

0 comments on commit ef90836

Please sign in to comment.