Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ node_modules/
*.dsw
*.dsp

# Visual Studio 6 technical files
# Visual Studio 6 technical files
*.ncb
*.aps

Expand Down Expand Up @@ -399,4 +399,4 @@ Dependencies/*
!Dependencies/*.md

# Custom output directory for HAT mod
[Oo]ut/
Comment thread
Jenna1337 marked this conversation as resolved.
[Oo]ut/
33 changes: 21 additions & 12 deletions FEZUG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,27 @@ public override void Initialize()

DrawingTools.Init();

Features = [];
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.IsClass && typeof(IFezugFeature).IsAssignableFrom(t) && !t.IsAbstract))
{
IFezugFeature feature = (IFezugFeature)Activator.CreateInstance(type);
ServiceHelper.InjectServices(feature);
Features.Add(feature);
}

foreach (var feature in Features)
{
feature.Initialize();
Features = new();

try {
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in types.Where(t => t.IsClass && typeof(IFezugFeature).IsAssignableFrom(t) && !t.IsAbstract))
{
IFezugFeature feature = (IFezugFeature)Activator.CreateInstance(type);
ServiceHelper.InjectServices(feature);
Features.Add(feature);
}

foreach (var feature in Features)
{
feature.Initialize();
}
} catch (ReflectionTypeLoadException e) {
string message = "Error while attempting to load types in this assembly!!! The classes in the following error messages are the ones with issues:\n";
foreach (Exception ex in e.LoaderExceptions) {
message += "\n" + ex.Message;
}
throw new Exception(message);
}
}

Expand Down
6 changes: 3 additions & 3 deletions FEZUG.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<LangVersion>11.0</LangVersion>

<ImplicitUsings>enable</ImplicitUsings>

<DebugType>full</DebugType>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions Features/ArtObjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ArtObjectInfo()

public void Initialize() { }

public List<string> Autocomplete(string[] _args) { return []; }
public List<string> Autocomplete(string[] _args) { return new(); }

public bool Execute(string[] args)
{
Expand Down Expand Up @@ -163,7 +163,7 @@ public ArtObjectWarp()

public void Initialize() { }

public List<string> Autocomplete(string[] _args) { return []; }
public List<string> Autocomplete(string[] _args) { return new(); }

public bool Execute(string[] args)
{
Expand Down
12 changes: 6 additions & 6 deletions Features/ArtifactItemSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ internal class ArtifactItemSet : IFezugCommand
[ServiceDependency]
public IGameStateManager GameState { private get; set; }

public readonly ActorType[] AllowedActorTypes =
[
public readonly ActorType[] AllowedActorTypes = new ActorType[]
{
ActorType.Tome,
ActorType.TriSkull,
ActorType.LetterCube,
ActorType.NumberCube
];
};

public List<string> Autocomplete(string[] args)
{
if (args.Length == 1)
{
return [.. new string[] { "give", "remove", "list" }.Where(s => s.StartsWith(args[0], StringComparison.OrdinalIgnoreCase))];
return new string[] { "give", "remove", "list" }.Where(s => s.StartsWith(args[0], StringComparison.OrdinalIgnoreCase)).ToList();
}
if (args.Length == 2)
{
return [.. AllowedActorTypes
return AllowedActorTypes
.Select(s => s.ToString().ToLower())
.Where(s => s.StartsWith(args[1], StringComparison.OrdinalIgnoreCase))];
.Where(s => s.StartsWith(args[1], StringComparison.OrdinalIgnoreCase)).ToList();
}
return null;
}
Expand Down
12 changes: 5 additions & 7 deletions Features/BindingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class BindingSystem : IFezugFeature
private const int GamePadKeysOffset = 0x300000;

private InputHelper InputHelper { get; } = InputHelper.Instance;

public BindList Binds { get; private set; }

public static BindingSystem Instance;
Expand All @@ -28,7 +28,7 @@ internal class BindingSystem : IFezugFeature
public BindingSystem()
{
Instance = this;
Binds = [];
Binds = new();
}

public void Initialize() {
Expand Down Expand Up @@ -68,8 +68,6 @@ public static void SetBind(Keys key, string command)
if (command.Length > 0)
Instance.Binds.Add(key, command);


string configPath = Path.Combine(Util.LocalConfigFolder, BindConfigFileName);
Comment thread
Jenna1337 marked this conversation as resolved.
SaveBinds();
}

Expand All @@ -94,7 +92,7 @@ private static void LoadBinds()
var bindFileLines = File.ReadAllLines(bindFilePath);
foreach(var line in bindFileLines)
{
string[] tokens = line.Split([' '], 2);
string[] tokens = line.Split(new char[] {' '}, 2);
if (tokens.Length < 2) continue;

if(TryParseBindName(tokens[0], out Keys key))
Expand Down Expand Up @@ -124,7 +122,7 @@ private static bool TryConvertKeysToGamepadButtons(Keys key, out Buttons button)
}
private static List<string> GetAutoCompleteOptions(string arg)
{
return [..Enum.GetNames(typeof(Keys)).Select(s => s.ToLower()).Concat(Enum.GetNames(typeof(Buttons)).Select(b => GamePadPrefix + b)).Where(s => s.StartsWith(arg, StringComparison.OrdinalIgnoreCase))] ;
return Enum.GetNames(typeof(Keys)).Select(s => s.ToLower()).Concat(Enum.GetNames(typeof(Buttons)).Select(b => GamePadPrefix + b)).Where(s => s.StartsWith(arg, StringComparison.OrdinalIgnoreCase)).ToList();
}
private static bool TryParseBindName(string str, out Keys key)
{
Expand Down Expand Up @@ -162,7 +160,7 @@ public List<string> Autocomplete(string[] args)
if (args.Length == 2 && Enum.TryParse<Keys>(args[0], true, out var key)
&& HasBind(key) && GetBind(key).StartsWith(args[1], StringComparison.OrdinalIgnoreCase))
{
return [GetBind(key)];
return new() {GetBind(key)};
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions Features/BlackHoleManip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public BlackHoleManip()

public List<string> Autocomplete(string[] args)
{
return [.. new string[] { "on", "off", "lock", "unlock" }.Where(s => s.StartsWith(args[0]))];
return new string[] { "on", "off", "lock", "unlock" }.Where(s => s.StartsWith(args[0])).ToList();
}

public bool Execute(string[] args)
Expand Down Expand Up @@ -73,7 +73,7 @@ public bool Execute(string[] args)

private bool AreBlackHolesEnabled()
{
var blackHole = LevelManager.Volumes.Values.Where((Volume x) => x.ActorSettings != null && x.ActorSettings.IsBlackHole);
var blackHole = LevelManager.Volumes.Values.Where(x => x.ActorSettings != null && x.ActorSettings.IsBlackHole);
if (blackHole.Count() == 0) return false;
return blackHole.First().Enabled;
}
Expand Down
6 changes: 3 additions & 3 deletions Features/Console/CommandHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public bool Execute(string[] args)
var helpStrings = new List<string>();
helpStrings.AddRange(cmdList.Select(cmd => cmd.HelpText));
helpStrings.AddRange(varList.Select(var => $"{var.Name} - {var.HelpText}"));
helpStrings = [.. helpStrings
.SelectMany(str => str.Split(['\n']))
.OrderBy(str => str)];
helpStrings = helpStrings
.SelectMany(str => str.Split(new[] {'\n'}))
.OrderBy(str => str).ToList();

int pageCount = (int)Math.Ceiling(helpStrings.Count / (float)CommandListPageSize);
pageNumber = Math.Min(Math.Max(pageNumber, 1), pageCount);
Expand Down
24 changes: 12 additions & 12 deletions Features/Console/FezugConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FezugConsole : IFezugFeature
public class ParsedCommand : List<string>
{
public string Command => this.Count() == 0 ? "" : this[0];
public string[] Arguments => this.Count() <= 1 ? [] : [.. this.Skip(1)];
public string[] Arguments => this.Count() <= 1 ? new string[0] : this.Skip(1).ToArray();
}

public class ParsedCommandSequence : List<ParsedCommand>
Expand Down Expand Up @@ -63,7 +63,7 @@ private void Parse(string commandString)
if (endOfCommand)
{
Add(currentTokens);
currentTokens = [];
currentTokens = new();
}

if (quote)
Expand Down Expand Up @@ -107,7 +107,7 @@ public AutocompletionManager(CommandHandler consoleLine)
{
ConsoleLine = consoleLine;

SuggestedWords = [""];
SuggestedWords = new() {""};
previousCommandSequence = new ParsedCommandSequence("");
}

Expand Down Expand Up @@ -141,8 +141,8 @@ public void Refresh(ParsedCommandSequence commandSequence)
// only one word in current command - autocomplete from all available commands and variables
if (command.Count == 1)
{
SuggestedWords.AddRange([.. matchingCommands.Select(c => c.Name)]);
SuggestedWords.AddRange([.. matchingVariables.Select(c => $"{c.Name} {c.ValueString}")]);
SuggestedWords.AddRange(matchingCommands.Select(c => c.Name));
SuggestedWords.AddRange(matchingVariables.Select(c => $"{c.Name} {c.ValueString}"));
}
// more than one words - get a command-specific or variable-specific autocompletion
else if(command.Count > 1)
Expand Down Expand Up @@ -238,7 +238,7 @@ public CommandHandler()

TextInputEXT.TextInput += OnTextInput;

Commands = [];
Commands = new();
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.IsClass && typeof(IFezugCommand).IsAssignableFrom(t) && !t.IsAbstract && t.GetConstructor(Type.EmptyTypes) != null))
{
Expand All @@ -261,7 +261,7 @@ public CommandHandler()
Enabled = false;
Buffer = "";

previousBufferInputs = [];
previousBufferInputs = new();

Autocompletion = new AutocompletionManager(this);
BufferChanged += Autocompletion.Refresh;
Expand Down Expand Up @@ -571,7 +571,7 @@ private struct ConsoleOutput
};

//Note: this is a ConcurrentQueue for thread safety, just in case another mod wants to use a separate thread to write to the console
private ConcurrentQueue<ConsoleOutput> outputBuffer = [];
private readonly ConcurrentQueue<ConsoleOutput> outputBuffer = new();
private float blinkingTime;
private int previousCursor = 0;

Expand Down Expand Up @@ -610,7 +610,7 @@ public void Update(GameTime gameTime)
public void UnfixedUpdate(GameTime gameTime)
{
var unscaledTime = Timescaler.GetUnscaledGameTime(gameTime);

Handler.Update(unscaledTime);

if (!Handler.Enabled) return;
Expand All @@ -635,7 +635,7 @@ private void Print(ConsoleOutput output)

public static void Print(string text, Color color)
{
foreach(var splitText in text.Split(['\n']))
foreach(var splitText in text.Split(new[] {'\n'}))
{
Instance.Print(new ConsoleOutput
{
Expand All @@ -658,7 +658,7 @@ public static void ExecuteCommand(string command)
public void DrawHUD(GameTime gameTime)
{
UnfixedUpdate(gameTime);

if (!Handler.Enabled) return;

Viewport viewport = DrawingTools.GetViewport();
Expand Down Expand Up @@ -728,7 +728,7 @@ public void DrawHUD(GameTime gameTime)
var outputItemPos = 0;
foreach (var outputLine in outputBuffer.Reverse())
{
List<string> lines = [];
List<string> lines = new();
string lineBuffer = "";
foreach(var word in outputLine.Text.Split(' '))
{
Expand Down
6 changes: 3 additions & 3 deletions Features/Console/FezugVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class FezugVariable
{
public const string VariablesFileName = "FezugVars";

public static List<FezugVariable> DefinedList { get; private set; } = [];
public static List<FezugVariable> DefinedList { get; private set; } = new();
private static Dictionary<string, string> LoadedVariables { get; set; }

public readonly string Name;
Expand Down Expand Up @@ -130,14 +130,14 @@ private static void SaveVariables()
private static void LoadVariables()
{
if (LoadedVariables != null) return;
LoadedVariables = [];
LoadedVariables = new();

var varsFilePath = GetVariablesFilePath();
if (!File.Exists(varsFilePath)) return;
var varsFileLines = File.ReadAllLines(varsFilePath);
foreach (var line in varsFileLines)
{
string[] tokens = line.Split([' '], 2);
string[] tokens = line.Split(new char[] {' '}, 2);
if (tokens.Length < 2) continue;

LoadedVariables[tokens[0]] = tokens[1];
Expand Down
8 changes: 4 additions & 4 deletions Features/Console/GenericFezugCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ internal class GenericFezugCommand : IFezugCommand

public string HelpText { get; }

private Func<string[], List<string>> AutocompleteProvider;
private readonly Func<string[], List<string>> AutocompleteProvider;
public List<string> Autocomplete(string[] args)
{
return AutocompleteProvider(args);
}

private Func<string[], bool> ExecuteCommand;
private readonly Func<string[], bool> ExecuteCommand;
public bool Execute(string[] args)
{
return ExecuteCommand(args);
Expand All @@ -23,8 +23,8 @@ public GenericFezugCommand(string name, string helpText, Func<string[], List<str
{
this.Name = name;
this.HelpText = helpText;
AutocompleteProvider = autocompleteProvider ?? (_ => []);
AutocompleteProvider = autocompleteProvider ?? (_ => new());
ExecuteCommand = executeCommand ?? (_ => false);
}
}
}
}
2 changes: 1 addition & 1 deletion Features/FullBright.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public FullBright()

public List<string> Autocomplete(string[] args)
{
return [.. new[] { "on", "off" }.Where(s => s.StartsWith(args[0]))];
return new[] { "on", "off" }.Where(s => s.StartsWith(args[0])).ToList();
}

public bool Execute(string[] args)
Expand Down
4 changes: 2 additions & 2 deletions Features/GetTrileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public List<string> Autocomplete(string[] args)
default: return null;
}

return [value.ToString("0", CultureInfo.InvariantCulture)];
return new() {value.ToString("0", CultureInfo.InvariantCulture)};
}


public bool Execute(string[] args)
{
if (!Teleport.TryParseCoords(args,
if (!Teleport.TryParseCoords(args,
PlayerManager.Ground.First?.Emplacement.AsVector ?? PlayerManager.Position.Round(),
out Vector3 coords))
{
Expand Down
2 changes: 1 addition & 1 deletion Features/GomezHitboxDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public GomezHitboxDraw() : base()

protected override Mesh[] RefreshBoundingBoxMeshs()
{
return [GomezBoundingBox = CreateHitboxMesh(Color.Red)];
return new Mesh[] {GomezBoundingBox = CreateHitboxMesh(Color.Red)};
}

public override void DrawLevel(GameTime gameTime)
Expand Down
Loading