Skip to content

Commit

Permalink
chore: client cleanup (core and entities) (#2326)
Browse files Browse the repository at this point in the history
* cleaning controls and input

* cleaning audio

* cleaning core files

* cleaning fade

* cleaning graphics

* cleaning entity

* cleaning events

* cleaning projectiles

* cleaning animation

* cleaning chat bubble

* cleaning friend instance

* cleaning hotbar instance

* cleaning party member

* cleaning critter

* cleaning dash

* cleaning resource

* cleaning status

* cleaning player
  • Loading branch information
WeylonSantana authored Jul 16, 2024
1 parent 8858757 commit a5df1c7
Show file tree
Hide file tree
Showing 45 changed files with 801 additions and 850 deletions.
4 changes: 2 additions & 2 deletions Intersect.Client.Framework/Entities/IAnimation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Intersect.GameObjects;
using Intersect.GameObjects;
using Intersect.Enums;

namespace Intersect.Client.Framework.Entities;
Expand All @@ -8,7 +8,7 @@ public interface IAnimation : IDisposable
bool AutoRotate { get; set; }
bool Hidden { get; set; }
bool InfiniteLoop { get; set; }
AnimationBase MyBase { get; set; }
AnimationBase? MyBase { get; set; }
Point Size { get; }

void Hide();
Expand Down
8 changes: 4 additions & 4 deletions Intersect.Client.Framework/Entities/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public interface IEntity : IDisposable
EntityType Type { get; }
string Name { get; }
Gender Gender { get; }
Color NameColor { get; }
Color? NameColor { get; }
Label FooterLabel { get; }
Label HeaderLabel { get; }
bool IsHidden { get; }
string Sprite { get; }
string TransformedSprite { get; }
string Face { get; }
GameTexture Texture { get; }
GameTexture? Texture { get; }
Color Color { get; }
FloatRect WorldPos { get; }
float OffsetX { get; }
Expand All @@ -30,10 +30,10 @@ public interface IEntity : IDisposable
bool IsStealthed { get; }
bool IsBlocking { get; }
bool IsDashing { get; }
IDash CurrentDash { get; }
IDash? CurrentDash { get; }
bool IsCasting { get; }
bool InView { get; }
IMapInstance MapInstance { get; }
IMapInstance? MapInstance { get; }
Guid MapId { get; }
Direction Dir { get; }
byte X { get; }
Expand Down
4 changes: 2 additions & 2 deletions Intersect.Client.Framework/Entities/IFriendInstance.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Intersect.Client.Framework.Entities;
namespace Intersect.Client.Framework.Entities;

public interface IFriendInstance
{
string Map { get; set; }
string? Map { get; set; }
string Name { get; set; }
bool Online { get; set; }
}
2 changes: 1 addition & 1 deletion Intersect.Client.Framework/Entities/IPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface IPlayer : IEntity
Guid[] HiddenQuests { get; }
bool IsInGuild { get; }
string GuildName { get; }
GuildRank GuildRank { get; }
GuildRank? GuildRank { get; }
bool IsBusy { get; }

bool TryGetRealLocation(ref int x, ref int y, ref Guid mapId);
Expand Down
5 changes: 2 additions & 3 deletions Intersect.Client.Framework/Entities/IResource.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Intersect.GameObjects;
using Intersect.GameObjects;

namespace Intersect.Client.Framework.Entities;

public interface IResource : IEntity
{
ResourceBase BaseResource { get; }
ResourceBase? BaseResource { get; }

bool IsDepleted { get; }

}
20 changes: 10 additions & 10 deletions Intersect.Client.Framework/Graphics/GameRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Intersect.Client.Framework.GenericClasses;
using Intersect.Client.Framework.GenericClasses;

namespace Intersect.Client.Framework.Graphics;

Expand Down Expand Up @@ -85,9 +85,9 @@ public abstract void DrawTexture(
float tw,
float th,
Color renderColor,
GameRenderTexture renderTarget = null,
GameRenderTexture? renderTarget = null,
GameBlendModes blendMode = GameBlendModes.None,
GameShader shader = null,
GameShader? shader = null,
float rotationDegrees = 0.0f,
bool isUi = false,
bool drawImmediate = false
Expand Down Expand Up @@ -118,9 +118,9 @@ void IGameRenderer.DrawTexture(
float tw,
float th,
Color renderColor,
GameRenderTexture renderTarget = null,
GameRenderTexture? renderTarget = null,
GameBlendModes blendMode = GameBlendModes.None,
GameShader shader = null,
GameShader? shader = null,
float rotationDegrees = 0.0f
) => DrawTexture(tex, sx, sy, sw, sh, tx, ty, tw, th, renderColor, renderTarget, blendMode, shader, rotationDegrees);

Expand All @@ -141,18 +141,18 @@ Func<Stream> createStream

public abstract GameTexture GetWhiteTexture();

public abstract Pointf MeasureText(string text, GameFont gameFont, float fontScale);
public abstract Pointf MeasureText(string text, GameFont? gameFont, float fontScale);

public abstract void DrawString(
string text,
GameFont gameFont,
GameFont? gameFont,
float x,
float y,
float fontScale,
Color fontColor,
Color? fontColor,
bool worldPos = true,
GameRenderTexture renderTexture = null,
Color borderColor = null
GameRenderTexture? renderTexture = null,
Color? borderColor = null
);

public abstract void DrawString(
Expand Down
42 changes: 13 additions & 29 deletions Intersect.Client/Core/Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

namespace Intersect.Client.Core;


public static partial class Audio
{

private static string sCurrentSong = "";

private static int sFadeRate;
Expand All @@ -22,7 +20,7 @@ public static partial class Audio
private static bool sFadingOut;

//Sounds
private static List<Sound> sGameSounds = new List<Sound>();
private static readonly List<Sound> sGameSounds = [];

private static bool sIsInitialized;

Expand All @@ -31,9 +29,9 @@ public static partial class Audio
private static bool sQueuedLoop;

//Music
private static string sQueuedMusic = "";
private static string? sQueuedMusic = "";

private static GameAudioInstance sMyMusic { get; set; }
private static GameAudioInstance? sMyMusic { get; set; }

//Init
public static void Init()
Expand All @@ -49,14 +47,10 @@ public static void Init()

public static void UpdateGlobalVolume()
{
if (sMyMusic != null)
{
sMyMusic.SetVolume(sMyMusic.GetVolume(), true);
}

sMyMusic?.SetVolume(sMyMusic.GetVolume(), true);
for (var i = 0; i < sGameSounds.Count; i++)
{
sGameSounds[i].Update();
_ = sGameSounds[i].Update();
if (!sGameSounds[i].Loaded)
{
sGameSounds.RemoveAt(i);
Expand All @@ -75,7 +69,7 @@ public static void Update()
if (sFadingOut)
{
sMyMusic.SetVolume(sMyMusic.GetVolume() - 1, true);
if (sMyMusic.GetVolume() <= 1)
if (sMyMusic.GetVolume() <= 1 && !string.IsNullOrEmpty(sQueuedMusic))
{
StopMusic();
PlayMusic(sQueuedMusic, 0, sQueuedFade, sQueuedLoop);
Expand All @@ -102,24 +96,18 @@ public static void Update()

for (var i = 0; i < sGameSounds.Count; i++)
{
sGameSounds[i].Update();
_ = sGameSounds[i].Update();
if (!sGameSounds[i].Loaded)
{
sGameSounds.RemoveAt(i);
}
}

// Update our pack sound cache if we have any packs loaded.
if (Globals.ContentManager.SoundPacks != null)
{
Globals.ContentManager.SoundPacks.UpdateCache();
}
Globals.ContentManager.SoundPacks?.UpdateCache();

// Update our pack music cache if we have any packs loaded.
if (Globals.ContentManager.MusicPacks != null)
{
Globals.ContentManager.MusicPacks.UpdateCache();
}
Globals.ContentManager.MusicPacks?.UpdateCache();
}

//Music
Expand Down Expand Up @@ -239,15 +227,15 @@ public static void StopMusic(int fadeout = 0)
}

//Sounds
public static MapSound AddMapSound(
public static MapSound? AddMapSound(
string filename,
int x,
int y,
Guid mapId,
bool loop,
int loopInterval,
int distance,
IEntity parent = null
IEntity? parent = null
)
{
if (sGameSounds?.Count > 128)
Expand All @@ -261,7 +249,7 @@ public static MapSound AddMapSound(
return sound;
}

public static Sound AddGameSound(string filename, bool loop)
public static Sound? AddGameSound(string filename, bool loop)
{
if (sGameSounds?.Count > 128)
{
Expand Down Expand Up @@ -292,11 +280,7 @@ public static void StopAllSounds()
{
for (var i = 0; i < sGameSounds.Count; i++)
{
if (sGameSounds[i] != null)
{
sGameSounds[i].Stop();
}
sGameSounds[i]?.Stop();
}
}

}
12 changes: 3 additions & 9 deletions Intersect.Client/Core/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

namespace Intersect.Client.Core;


internal static partial class Bootstrapper
{
public static ClientContext Context { get; private set; }
public static ClientContext? Context { get; private set; }

public static void Start(params string[] args)
{
Expand Down Expand Up @@ -42,7 +41,7 @@ public static void Start(params string[] args)

var packetHandlerRegistry = new PacketHandlerRegistry(packetTypeRegistry, logger);
var packetHelper = new PacketHelper(packetTypeRegistry, packetHandlerRegistry);
FactoryRegistry<IPluginBootstrapContext>.RegisterFactory(PluginBootstrapContext.CreateFactory(args, parser, packetHelper));
_ = FactoryRegistry<IPluginBootstrapContext>.RegisterFactory(PluginBootstrapContext.CreateFactory(args, parser, packetHelper));

var commandLineOptions = parser.ParseArguments<ClientCommandLineOptions>(args)
.MapResult(HandleParsedArguments, HandleParserErrors);
Expand Down Expand Up @@ -71,12 +70,8 @@ private static ClientCommandLineOptions HandleParsedArguments(ClientCommandLineO
private static ClientCommandLineOptions HandleParserErrors(IEnumerable<Error> errors)
{
var errorsAsList = errors?.ToList();

var fatalParsingError = errorsAsList?.Any(error => error?.StopsProcessing ?? false) ?? false;

var errorString = string.Join(
", ", errorsAsList?.ToList().Select(error => error?.ToString()) ?? Array.Empty<string>()
);
var errorString = string.Join(", ", errorsAsList?.ToList().Select(error => error?.ToString()) ?? []);

var exception = new ArgumentException(
$@"Error parsing command line arguments, received the following errors: {errorString}"
Expand All @@ -93,5 +88,4 @@ private static ClientCommandLineOptions HandleParserErrors(IEnumerable<Error> er

return default;
}

}
9 changes: 4 additions & 5 deletions Intersect.Client/Core/ClientCommandLineOptions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using CommandLine;
using CommandLine;

using Intersect.Client.Framework.Graphics;
using Intersect.Core;

namespace Intersect.Client.Core;

internal partial struct ClientCommandLineOptions : ICommandLineOptions
internal readonly partial struct ClientCommandLineOptions : ICommandLineOptions
{
public ClientCommandLineOptions(
bool borderlessWindow,
Expand Down Expand Up @@ -40,8 +40,7 @@ IEnumerable<string> pluginDirectories
public string WorkingDirectory { get; }

[Option('p', "plugin-directory", Default = null, Required = false)]
public IEnumerable<string> PluginDirectories { get; }

public Resolution ScreenResolution => new Resolution(ScreenWidth, ScreenHeight);
public IEnumerable<string>? PluginDirectories { get; }

public Resolution ScreenResolution => new(ScreenWidth, ScreenHeight);
}
6 changes: 3 additions & 3 deletions Intersect.Client/Core/ClientContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Intersect.Client.Networking;
using Intersect.Client.Networking;
using Intersect.Client.Plugins.Contexts;
using Intersect.Core;
using Intersect.Factories;
Expand All @@ -16,13 +16,13 @@ internal sealed partial class ClientContext : ApplicationContext<ClientContext,
{
internal static bool IsSinglePlayer { get; set; }

private IPlatformRunner mPlatformRunner;
private IPlatformRunner? mPlatformRunner;

internal ClientContext(ClientCommandLineOptions startupOptions, Logger logger, IPacketHelper packetHelper) : base(
startupOptions, logger, packetHelper
)
{
FactoryRegistry<IPluginContext>.RegisterFactory(new ClientPluginContext.Factory());
_ = FactoryRegistry<IPluginContext>.RegisterFactory(new ClientPluginContext.Factory());
}

protected override bool UsesMainThread => true;
Expand Down
13 changes: 1 addition & 12 deletions Intersect.Client/Core/Controls/ControlEnum.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
namespace Intersect.Client.Core.Controls;

namespace Intersect.Client.Core.Controls;

public enum Control
{

MoveUp,

MoveLeft,
Expand Down Expand Up @@ -79,13 +77,4 @@ public enum Control
HoldToZoomOut,

ToggleFullscreen,

// Submit,
//
// Cancel,
//
// Previous,
//
// Next,

}
2 changes: 1 addition & 1 deletion Intersect.Client/Core/Controls/ControlMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class ControlMap
public ControlMap(ControlValue binding, params ControlValue[] alternateBindings)
{
Bindings = new List<ControlValue>(1 + (alternateBindings?.Length ?? 0)) { binding };
Bindings.AddRange(alternateBindings ?? Array.Empty<ControlValue>());
Bindings.AddRange(alternateBindings ?? []);

if (Bindings.Count < 2)
{
Expand Down
Loading

0 comments on commit a5df1c7

Please sign in to comment.