Skip to content

Commit 50a7675

Browse files
committed
Fixing minor bugs
- renaming a.cs to DrawBackToMainMenuSystem.cs - PlayerDefinition and WorldDefinition are simplified and easier to work with - fixing Start Server option in main menu - fixing SinglePlayerReload
1 parent 05a60e2 commit 50a7675

13 files changed

Lines changed: 43 additions & 37 deletions

Common/Configs/ConfigElements/PlayerPicker/PlayerDefinition.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ModReloader.Core.Features;
2+
using Terraria.IO;
23
using Terraria.ModLoader.Config;
34

45

@@ -11,6 +12,8 @@ public class PlayerDefinition : EntityDefinition
1112
/// </summary>
1213
public override int Type => Utilities.FindPlayerId(Name);
1314

15+
public PlayerFileData File => IsUnloaded ? null : Main.PlayerList[Type];
16+
1417
public override bool IsUnloaded
1518
=> Type <= -1 || Name == null;
1619

@@ -20,7 +23,7 @@ public PlayerDefinition() : base()
2023

2124
}
2225

23-
public PlayerDefinition(int type) : base(Utilities.FindPlayer(type).Path)
26+
public PlayerDefinition(int type) : base(Utilities.FindPlayer(type)?.Path ?? "None")
2427
{
2528

2629
}

Common/Configs/ConfigElements/PlayerPicker/PlayerDefinitionElement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ protected override List<DefinitionOptionElement<PlayerDefinition>> GetPassedOpti
9494
foreach (var o in Options)
9595
{
9696
// If player is journey and user is searching for journey, add it
97-
bool isJourney = Utilities.FindPlayer(o.Type).Player.difficulty == GameModeID.Creative;
97+
bool isJourney = o.Definition.File?.Player?.difficulty == GameModeID.Creative;
9898

9999
// Filter name
100-
if (!Utilities.FindPlayer(o.Type).Name.Contains(filter, StringComparison.OrdinalIgnoreCase))
100+
if (!o.Definition.File?.Name.Contains(filter, StringComparison.OrdinalIgnoreCase) ?? true)
101101
continue;
102102

103103
passed.Add(o);

Common/Configs/ConfigElements/PlayerPicker/PlayerDefinitionOptionElement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void SetItem(PlayerDefinition definition)
3838
return;
3939
}
4040

41-
PlayerFileData file = Utilities.FindPlayer(definition.Type);
41+
PlayerFileData file = definition.File;
4242

4343
Player player = file.Player;
4444
player.dead = false;

Common/Configs/ConfigElements/WorldPicker/WorldDefinition.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using ModReloader.Core.Features;
22
using System.IO;
3+
using Terraria.IO;
34
using Terraria.ModLoader.Config;
45

56

@@ -12,15 +13,17 @@ public class WorldDefinition : EntityDefinition
1213
/// </summary>
1314
public override int Type => Utilities.FindWorldId(Name);
1415

16+
public WorldFileData File => IsUnloaded ? null : Main.WorldList[Type];
17+
1518
public override bool IsUnloaded
16-
=> Type <= -1 || Name == null;
19+
=> Type <= -1;
1720

1821
public WorldDefinition() : base()
1922
{
2023

2124
}
2225

23-
public WorldDefinition(int type) : base(Utilities.FindWorld(type).Path)
26+
public WorldDefinition(int type) : base(Utilities.FindWorld(type)?.Path ?? "None")
2427
{
2528

2629
}

Common/Configs/ConfigElements/WorldPicker/WorldDefinitionOptionElement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public override void SetItem(WorldDefinition definition)
3131
return;
3232
}
3333

34-
var file = Utilities.FindWorld(definition.Type);
34+
var file = definition.File;
3535

3636
// Get icon asset
3737
_iconAsset = GetIconAsset(file);

Core/Features/MainMenuFeatures/a.cs renamed to Core/Features/MainMenuFeatures/DrawBackToMainMenuSystem.cs

File renamed without changes.

Core/Features/MainMenuFeatures/MainMenuActions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public static void StartServer()
175175
throw new Exception("No worlds found.");
176176

177177
// Getting Player and World from ClientDataHandler
178-
var world = Main.WorldList.FirstOrDefault(p => p.Path.Equals(ClientDataMemoryStorage.WorldPath)) ?? throw new Exception("World not found: " + ClientDataMemoryStorage.WorldPath);
178+
var world = Conf.C.World.File ?? throw new Exception("World not found: " + Conf.C.World.Name);
179179
if (string.IsNullOrEmpty(world.Path))
180180
{
181181
Log.Error($"World {world.Name} has an invalid or null path.");

Core/Features/MainMenuFeatures/MainMenuState.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,8 @@ private void AddSingleplayerSection(TooltipPanel tooltipPanel)
199199
Main.LoadPlayers();
200200
Main.LoadWorlds();
201201

202-
int playerIdx = Conf.C.Player.Type;
203-
int worldIdx = Conf.C.World.Type;
204-
205-
string pName = (playerIdx >= 0 && playerIdx < Main.PlayerList.Count)
206-
? Main.PlayerList[playerIdx].Name
207-
: "";
208-
string wName = (worldIdx >= 0 && worldIdx < Main.WorldList.Count)
209-
? Main.WorldList[worldIdx].Name
210-
: "";
202+
string pName = Conf.C.Player.File?.Name ?? "Undefined";
203+
string wName = Conf.C.World.File?.Name ?? "Undefined";
211204

212205
if (string.IsNullOrEmpty(pName) || string.IsNullOrEmpty(wName))
213206
return Loc.Get("MainMenu.JoinSingleplayerTooltipNoData");

Core/Features/Reload/AutoloadPlayerInWorldSystem.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ public static void EnterSingleplayerWorld()
7676
else
7777
{
7878
Log.Error("Failed to select player and world for singleplayer.");
79-
if (TryMoveToRejectionMenuIfNeeded())
80-
return;
79+
if (!TryMoveToRejectionMenuIfNeeded())
80+
Main.menuMode = 0;
8181
}
82+
8283
}
8384

8485
/// <summary>

Core/Features/Reload/ReloadUtilities.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,12 @@ public static async Task SinglePlayerReload()
4646

4747
if (Main.netMode == NetmodeID.SinglePlayer)
4848
{
49-
// Prepare client. Use singleplayer by default for now.
5049
PrepareClient(
51-
clientMode: ClientMode.SinglePlayer,
52-
playerID: Conf.C.Player.Name,
53-
worldID: Conf.C.World.Name
50+
clientMode: ClientMode.SinglePlayer
5451
);
5552

56-
57-
// Exit the game.
5853
await ExitWorld();
5954

60-
// Mod was found, we can Reload
6155
BuildOrReloadMods();
6256
return;
6357
}
@@ -384,7 +378,7 @@ private static void PrepareClient(ClientMode clientMode, string playerID, string
384378
ClientDataMemoryStorage.ClientMode = clientMode;
385379
ClientDataMemoryStorage.PlayerPath = playerID;
386380
ClientDataMemoryStorage.WorldPath = worldID;
387-
Log.Info("set player and worldid to " + ClientDataMemoryStorage.PlayerPath + " and " + ClientDataMemoryStorage.WorldPath);
381+
Log.Info("set player and world to " + ClientDataMemoryStorage.PlayerPath + " and " + ClientDataMemoryStorage.WorldPath);
388382
}
389383

390384
/// <summary>

0 commit comments

Comments
 (0)