Unstable 1.2.1.0
This commit is contained in:
@@ -7,6 +7,7 @@ using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using Barotrauma.IO;
|
||||
@@ -40,8 +41,8 @@ namespace Barotrauma
|
||||
{
|
||||
public partial class Command
|
||||
{
|
||||
public readonly string[] names;
|
||||
public readonly string help;
|
||||
public readonly ImmutableArray<Identifier> Names;
|
||||
public readonly string Help;
|
||||
|
||||
public Action<string[]> OnExecute;
|
||||
|
||||
@@ -57,8 +58,8 @@ namespace Barotrauma
|
||||
/// </summary>
|
||||
public Command(string name, string help, Action<string[]> onExecute, Func<string[][]> getValidArgs = null, bool isCheat = false)
|
||||
{
|
||||
names = name.Split('|');
|
||||
this.help = help;
|
||||
Names = name.Split('|').ToIdentifiers().ToImmutableArray();
|
||||
this.Help = help;
|
||||
|
||||
this.OnExecute = onExecute;
|
||||
|
||||
@@ -76,7 +77,8 @@ namespace Barotrauma
|
||||
#endif
|
||||
if (!allowCheats && !CheatsEnabled && IsCheat)
|
||||
{
|
||||
NewMessage("You need to enable cheats using the command \"enablecheats\" before you can use the command \"" + names[0] + "\".", Color.Red);
|
||||
NewMessage(
|
||||
$"You need to enable cheats using the command \"enablecheats\" before you can use the command \"{Names.First()}\".", Color.Red);
|
||||
#if USE_STEAM
|
||||
NewMessage("Enabling cheats will disable Steam achievements during this play session.", Color.Red);
|
||||
#endif
|
||||
@@ -88,7 +90,7 @@ namespace Barotrauma
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return names[0].GetHashCode();
|
||||
return Names.First().GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +166,7 @@ namespace Barotrauma
|
||||
|
||||
private static void AssignOnExecute(string names, Action<string[]> onExecute)
|
||||
{
|
||||
var matchingCommand = commands.Find(c => c.names.Intersect(names.Split('|')).Count() > 0);
|
||||
var matchingCommand = commands.Find(c => c.Names.Intersect(names.Split('|').ToIdentifiers()).Any());
|
||||
if (matchingCommand == null)
|
||||
{
|
||||
throw new Exception("AssignOnExecute failed. Command matching the name(s) \"" + names + "\" not found.");
|
||||
@@ -187,13 +189,13 @@ namespace Barotrauma
|
||||
{
|
||||
foreach (Command c in commands)
|
||||
{
|
||||
if (string.IsNullOrEmpty(c.help)) continue;
|
||||
if (string.IsNullOrEmpty(c.Help)) continue;
|
||||
ShowHelpMessage(c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var matchingCommand = commands.Find(c => c.names.Any(name => name == args[0]));
|
||||
var matchingCommand = commands.Find(c => c.Names.Any(name => name == args[0]));
|
||||
if (matchingCommand == null)
|
||||
{
|
||||
NewMessage("Command " + args[0] + " not found.", Color.Red);
|
||||
@@ -208,7 +210,7 @@ namespace Barotrauma
|
||||
{
|
||||
return new string[][]
|
||||
{
|
||||
commands.SelectMany(c => c.names).ToArray(),
|
||||
commands.SelectMany(c => c.Names).Select(n => n.Value).ToArray(),
|
||||
Array.Empty<string>()
|
||||
};
|
||||
}));
|
||||
@@ -403,7 +405,7 @@ namespace Barotrauma
|
||||
return new string[][]
|
||||
{
|
||||
GameMain.NetworkMember.ConnectedClients.Select(c => c.Name).ToArray(),
|
||||
commands.Select(c => c.names[0]).Union(new string[]{ "All" }).ToArray()
|
||||
commands.Select(c => c.Names.First().Value).Union(new []{ "All" }).ToArray()
|
||||
};
|
||||
}));
|
||||
|
||||
@@ -415,7 +417,7 @@ namespace Barotrauma
|
||||
return new string[][]
|
||||
{
|
||||
GameMain.NetworkMember.ConnectedClients.Select(c => c.Name).ToArray(),
|
||||
commands.Select(c => c.names[0]).Union(new string[]{ "All" }).ToArray()
|
||||
commands.Select(c => c.Names.First().Value).Union(new []{ "All" }).ToArray()
|
||||
};
|
||||
}));
|
||||
|
||||
@@ -1133,7 +1135,7 @@ namespace Barotrauma
|
||||
}
|
||||
},null));
|
||||
|
||||
commands.Add(new Command("teleportsub", "teleportsub [start/end/cursor]: Teleport the submarine to the position of the cursor, or the start or end of the level. WARNING: does not take outposts into account, so often leads to physics glitches. Only use for debugging.", (string[] args) =>
|
||||
commands.Add(new Command("teleportsub", "teleportsub [start/end/endoutpost/cursor]: Teleport the submarine to the position of the cursor, or the start or end of the level. The 'endoutpost' argument also automatically docks the sub with the outpost at the end of the level. WARNING: does not take outposts into account, so often leads to physics glitches. Only use for debugging.", (string[] args) =>
|
||||
{
|
||||
if (Submarine.MainSub == null) { return; }
|
||||
|
||||
@@ -1159,7 +1161,7 @@ namespace Barotrauma
|
||||
}
|
||||
Submarine.MainSub.SetPosition(pos);
|
||||
}
|
||||
else
|
||||
else if (args[0].Equals("end", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (Level.Loaded == null)
|
||||
{
|
||||
@@ -1172,13 +1174,29 @@ namespace Barotrauma
|
||||
pos -= Vector2.UnitY * (Submarine.MainSub.Borders.Height + Level.Loaded.EndOutpost.Borders.Height) / 2;
|
||||
}
|
||||
Submarine.MainSub.SetPosition(pos);
|
||||
}
|
||||
else if (args[0].Equals("endoutpost", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Submarine.MainSub.SetPosition(Level.Loaded.EndExitPosition - Vector2.UnitY * Submarine.MainSub.Borders.Height);
|
||||
|
||||
var submarineDockingPort = DockingPort.List.FirstOrDefault(d => d.Item.Submarine == Submarine.MainSub);
|
||||
if (Level.Loaded?.EndOutpost == null)
|
||||
{
|
||||
NewMessage("Can't teleport the sub to the end outpost (no outpost at the end of the level).", Color.Red);
|
||||
return;
|
||||
}
|
||||
var outpostDockingPort = DockingPort.List.FirstOrDefault(d => d.Item.Submarine == Level.Loaded.EndOutpost);
|
||||
if (submarineDockingPort != null && outpostDockingPort != null)
|
||||
{
|
||||
submarineDockingPort.Dock(outpostDockingPort);
|
||||
}
|
||||
}
|
||||
},
|
||||
() =>
|
||||
{
|
||||
return new string[][]
|
||||
{
|
||||
new string[] { "start", "end", "cursor" }
|
||||
new string[] { "start", "end", "endoutpost", "cursor" }
|
||||
};
|
||||
}, isCheat: true));
|
||||
|
||||
@@ -1959,7 +1977,7 @@ namespace Barotrauma
|
||||
|
||||
InitProjectSpecific();
|
||||
|
||||
commands.Sort((c1, c2) => c1.names[0].CompareTo(c2.names[0]));
|
||||
commands.Sort((c1, c2) => c1.Names.First().CompareTo(c2.Names.First()));
|
||||
}
|
||||
|
||||
public static string AutoComplete(string command, int increment = 1)
|
||||
@@ -1970,14 +1988,14 @@ namespace Barotrauma
|
||||
//if an argument is given or the last character is a space, attempt to autocomplete the argument
|
||||
if (args.Length > 0 || (splitCommand.Length > 0 && command.Last() == ' '))
|
||||
{
|
||||
Command matchingCommand = commands.Find(c => c.names.Contains(splitCommand[0]));
|
||||
if (matchingCommand == null || matchingCommand.GetValidArgs == null) return command;
|
||||
Command matchingCommand = commands.Find(c => c.Names.Contains(splitCommand[0].ToIdentifier()));
|
||||
if (matchingCommand?.GetValidArgs == null) { return command; }
|
||||
|
||||
int autoCompletedArgIndex = args.Length > 0 && command.Last() != ' ' ? args.Length - 1 : args.Length;
|
||||
|
||||
//get all valid arguments for the given command
|
||||
string[][] allArgs = matchingCommand.GetValidArgs();
|
||||
if (allArgs == null || allArgs.GetLength(0) < autoCompletedArgIndex + 1) return command;
|
||||
if (allArgs == null || allArgs.GetLength(0) < autoCompletedArgIndex + 1) { return command; }
|
||||
|
||||
if (string.IsNullOrEmpty(currentAutoCompletedCommand))
|
||||
{
|
||||
@@ -1989,7 +2007,7 @@ namespace Barotrauma
|
||||
currentAutoCompletedCommand.Trim().Length <= arg.Length &&
|
||||
arg.Substring(0, currentAutoCompletedCommand.Trim().Length).ToLower() == currentAutoCompletedCommand.Trim().ToLower()).ToArray();
|
||||
|
||||
if (validArgs.Length == 0) return command;
|
||||
if (validArgs.Length == 0) { return command; }
|
||||
|
||||
currentAutoCompletedIndex = MathUtils.PositiveModulo(currentAutoCompletedIndex + increment, validArgs.Length);
|
||||
string autoCompletedArg = validArgs[currentAutoCompletedIndex];
|
||||
@@ -2010,13 +2028,13 @@ namespace Barotrauma
|
||||
currentAutoCompletedCommand = command;
|
||||
}
|
||||
|
||||
List<string> matchingCommands = new List<string>();
|
||||
List<Identifier> matchingCommands = new List<Identifier>();
|
||||
foreach (Command c in commands)
|
||||
{
|
||||
foreach (string name in c.names)
|
||||
foreach (var name in c.Names)
|
||||
{
|
||||
if (currentAutoCompletedCommand.Length > name.Length) continue;
|
||||
if (currentAutoCompletedCommand == name.Substring(0, currentAutoCompletedCommand.Length))
|
||||
if (currentAutoCompletedCommand.Length > name.Value.Length) { continue; }
|
||||
if (name.StartsWith(currentAutoCompletedCommand))
|
||||
{
|
||||
matchingCommands.Add(name);
|
||||
}
|
||||
@@ -2026,7 +2044,7 @@ namespace Barotrauma
|
||||
if (matchingCommands.Count == 0) return command;
|
||||
|
||||
currentAutoCompletedIndex = MathUtils.PositiveModulo(currentAutoCompletedIndex + increment, matchingCommands.Count);
|
||||
return matchingCommands[currentAutoCompletedIndex];
|
||||
return matchingCommands[currentAutoCompletedIndex].Value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2064,9 +2082,9 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
string firstCommand = splitCommand[0].ToLowerInvariant();
|
||||
Identifier firstCommand = splitCommand[0].ToIdentifier();
|
||||
|
||||
if (!firstCommand.Equals("admin", StringComparison.OrdinalIgnoreCase))
|
||||
if (firstCommand != "admin")
|
||||
{
|
||||
NewCommand(command);
|
||||
}
|
||||
@@ -2074,7 +2092,7 @@ namespace Barotrauma
|
||||
#if CLIENT
|
||||
if (GameMain.Client != null)
|
||||
{
|
||||
Command matchingCommand = commands.Find(c => c.names.Contains(firstCommand));
|
||||
Command matchingCommand = commands.Find(c => c.Names.Contains(firstCommand));
|
||||
if (matchingCommand == null)
|
||||
{
|
||||
//if the command is not defined client-side, we'll relay it anyway because it may be a custom command at the server's side
|
||||
@@ -2095,12 +2113,12 @@ namespace Barotrauma
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!IsCommandPermitted(splitCommand[0].ToLowerInvariant(), GameMain.Client))
|
||||
if (!IsCommandPermitted(firstCommand, GameMain.Client))
|
||||
{
|
||||
#if DEBUG
|
||||
AddWarning($"You're not permitted to use the command \"{splitCommand[0].ToLowerInvariant()}\". Executing the command anyway because this is a debug build.");
|
||||
AddWarning($"You're not permitted to use the command \"{firstCommand}\". Executing the command anyway because this is a debug build.");
|
||||
#else
|
||||
ThrowError($"You're not permitted to use the command \"{splitCommand[0].ToLowerInvariant()}\"!");
|
||||
ThrowError($"You're not permitted to use the command \"{firstCommand}\"!");
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
@@ -2110,7 +2128,7 @@ namespace Barotrauma
|
||||
bool commandFound = false;
|
||||
foreach (Command c in commands)
|
||||
{
|
||||
if (!c.names.Contains(firstCommand)) { continue; }
|
||||
if (!c.Names.Contains(firstCommand)) { continue; }
|
||||
c.Execute(splitCommand.Skip(1).ToArray());
|
||||
commandFound = true;
|
||||
break;
|
||||
@@ -2397,8 +2415,13 @@ namespace Barotrauma
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void LogError(string msg, Color? color = null)
|
||||
public static void LogError(string msg, Color? color = null, ContentPackage contentPackage = null)
|
||||
{
|
||||
if (contentPackage != null)
|
||||
{
|
||||
string colorStr = XMLExtensions.ToStringHex(Color.MediumPurple);
|
||||
msg = $"‖color:{colorStr}‖[{contentPackage.Name}]‖color:end‖ {msg}";
|
||||
}
|
||||
color ??= Color.Red;
|
||||
NewMessage(msg, color.Value, isCommand: false, isError: true);
|
||||
}
|
||||
@@ -2515,7 +2538,7 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Command FindCommand(string commandName) => commands.Find(c => c.names.Any(n => n.Equals(commandName, StringComparison.OrdinalIgnoreCase)));
|
||||
public static Command FindCommand(string commandName) => commands.Find(c => c.Names.Contains(commandName.ToIdentifier()));
|
||||
|
||||
public static void Log(LocalizedString message) => Log(message?.Value);
|
||||
|
||||
@@ -2532,8 +2555,13 @@ namespace Barotrauma
|
||||
ThrowError(error.Value, e, createMessageBox, appendStackTrace);
|
||||
}
|
||||
|
||||
public static void ThrowError(string error, Exception e = null, bool createMessageBox = false, bool appendStackTrace = false)
|
||||
public static void ThrowError(string error, Exception e = null, ContentPackage contentPackage = null, bool createMessageBox = false, bool appendStackTrace = false)
|
||||
{
|
||||
if (contentPackage != null)
|
||||
{
|
||||
string color = XMLExtensions.ToStringHex(Color.MediumPurple);
|
||||
error = $"‖color:{color}‖[{contentPackage.Name}]‖color:end‖ {error}";
|
||||
}
|
||||
if (e != null)
|
||||
{
|
||||
error += " {" + e.Message + "}\n";
|
||||
@@ -2547,7 +2575,7 @@ namespace Barotrauma
|
||||
error += "\n\nInner exception: " + innermost.Message + "\n";
|
||||
if (innermost.StackTrace != null)
|
||||
{
|
||||
error += innermost.StackTrace.CleanupStackTrace(); ;
|
||||
error += innermost.StackTrace.CleanupStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2580,10 +2608,16 @@ namespace Barotrauma
|
||||
errorMsg);
|
||||
}
|
||||
|
||||
public static void AddWarning(string warning)
|
||||
public static void AddWarning(string warning, ContentPackage contentPackage = null)
|
||||
{
|
||||
warning = $"WARNING: {warning}";
|
||||
if (contentPackage != null)
|
||||
{
|
||||
string color = XMLExtensions.ToStringHex(Color.MediumPurple);
|
||||
warning = $"‖color:{color}‖[{contentPackage.Name}]‖color:end‖ {warning}";
|
||||
}
|
||||
System.Diagnostics.Debug.WriteLine(warning);
|
||||
NewMessage($"WARNING: {warning}", Color.Yellow);
|
||||
NewMessage(warning, Color.Yellow);
|
||||
}
|
||||
|
||||
#if CLIENT
|
||||
|
||||
Reference in New Issue
Block a user