Skip to content

Commit 03bb48b

Browse files
committed
Reset Game.cs after build in a defer block
1 parent 7958075 commit 03bb48b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

build.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ func Build() error {
3535
}
3636
}
3737

38-
func buildClient(gameName, output, url, os, arch string) error {
38+
func buildClient(gameName, output, url, os, arch string) (err error) {
3939
cli.BeginLoading("Building...")
4040
gameDir := toPascal(gameName)
41-
err := replaceInFile(filepath.Join(gameDir, "Game.cs"), "throw new InvalidOperationException(\"The CG_GAME_URL environment variable must be set.\")", "return \""+url+"\"")
41+
err = replaceInFile(filepath.Join(gameDir, "Game.cs"), "throw new InvalidOperationException(\"The CG_GAME_URL environment variable must be set.\")", "return \""+url+"\"")
4242
if err != nil {
4343
return err
4444
}
45+
defer func() {
46+
err2 := replaceInFile(filepath.Join(gameDir, "Game.cs"), "return \""+url+"\"", "throw new InvalidOperationException(\"The CG_GAME_URL environment variable must be set.\")")
47+
if err == nil && err2 != nil {
48+
err = err2
49+
}
50+
}()
4551

4652
args := []string{"publish", "--nologo", "--configuration", "Release", "--self-contained"}
4753
if os == "current" {
@@ -59,10 +65,6 @@ func buildClient(gameName, output, url, os, arch string) error {
5965
return err
6066
}
6167

62-
err = replaceInFile(filepath.Join(gameDir, "Game.cs"), "return \""+url+"\"", "throw new InvalidOperationException(\"The CG_GAME_URL environment variable must be set.\")")
63-
if err != nil {
64-
return err
65-
}
6668
cli.FinishLoading()
6769

6870
return nil

templates/new/client/Game.cs.tmpl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public partial class Game : IDisposable
3636
/// </summary>
3737
public GameConfig Config { get; private set; }
3838
/// <summary>
39-
/// Whether the socket is connected in spectate mode.
39+
/// Whether the socket is connected as a spectator.
4040
/// </summary>
4141
public bool Spectating { get; private set; }
4242
/// <summary>
@@ -47,21 +47,21 @@ public partial class Game : IDisposable
4747
private GameSocket socket;
4848

4949
/// <summary>
50-
/// Parses the command line arguments and creates a new game depending on which flags and commands were used.
50+
/// Parses the command line arguments and creates a new game depending on which flags and commands are used.
5151
/// <para>
5252
/// Commands:
5353
/// <list type="bullet">
54-
/// <item>create (Creates a new game and joins it.)</item>
55-
/// <item>join (Joins an existing game.)</item>
56-
/// <item>reconnect (Reconnects to an existing session.)</item>
54+
/// <item>create Creates a new game and joins it.</item>
55+
/// <item>join Joins an existing game.</item>
56+
/// <item>reconnect Reconnects to an existing session.</item>
5757
/// </list>
5858
/// </para>
5959
/// <para>
6060
/// Flags:
6161
/// <list type="bullet">
62-
/// <item>--public (Makes the created game public)</item>
63-
/// <item>--protected (Makes the created game protected.</item>
64-
/// <item>--spectate (Spectates the game instead of joining it. (the username is not necessary if this flag is set)</item>
62+
/// <item>--public Makes the created game public.</item>
63+
/// <item>--protected Makes the created game protected.</item>
64+
/// <item>--spectate Spectates the game instead of joining it. (the username is not necessary if this flag is set)</item>
6565
/// </list>
6666
/// </para>
6767
/// </summary>

0 commit comments

Comments
 (0)