Skip to content

Commit

Permalink
cleanup EntryPoint.cs + move this to maek style load
Browse files Browse the repository at this point in the history
  • Loading branch information
LetterN committed Dec 27, 2023
1 parent bd2d8bc commit bdd8cd5
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 77 deletions.
18 changes: 9 additions & 9 deletions OpenDreamClient/ClientContentIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
using OpenDreamClient.Resources;
using OpenDreamClient.States;

namespace OpenDreamClient {
public static class ClientContentIoC {
public static void Register() {
IoCManager.Register<IDreamInterfaceManager, DreamInterfaceManager>();
IoCManager.Register<IClickMapManager, ClickMapManager>();
IoCManager.Register<IDreamResourceManager, DreamResourceManager>();
IoCManager.Register<DreamUserInterfaceStateManager>();
IoCManager.Register<IDreamSoundEngine, DreamSoundEngine>();
}
namespace OpenDreamClient;

internal static class ClientContentIoC {
public static void Register() {
IoCManager.Register<IDreamInterfaceManager, DreamInterfaceManager>();
IoCManager.Register<IClickMapManager, ClickMapManager>();
IoCManager.Register<IDreamResourceManager, DreamResourceManager>();
IoCManager.Register<DreamUserInterfaceStateManager>();
IoCManager.Register<IDreamSoundEngine, DreamSoundEngine>();
}
}
139 changes: 71 additions & 68 deletions OpenDreamClient/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,100 +3,103 @@
using OpenDreamClient.Interface;
using OpenDreamClient.Resources;
using OpenDreamClient.States;
using OpenDreamClient.States.MainMenu;
using OpenDreamShared;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Map;
using Robust.Client.State;
using Robust.Client.UserInterface;
using Robust.Client.WebView;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
using Robust.Shared.Timing;

namespace OpenDreamClient {
public sealed class EntryPoint : GameClient {
[Dependency] private readonly IDreamInterfaceManager _dreamInterface = default!;
[Dependency] private readonly IDreamResourceManager _dreamResource = default!;
[Dependency] private readonly IDreamSoundEngine _soundEngine = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly ILightManager _lightManager = default!;

private const string UserAgent =
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)";

public override void PreInit() {
var config = IoCManager.Resolve<IConfigurationManager>();
if (config.GetCVar(OpenDreamCVars.SpoofIEUserAgent)) {
config.OverrideDefault(WCVars.WebUserAgentOverride, UserAgent);
}

IoCManager.Resolve<IEntitySystemManager>().SystemLoaded += OnEntitySystemLoaded;
namespace OpenDreamClient;

public sealed class EntryPoint : GameClient {
[Dependency] private readonly IDreamInterfaceManager _dreamInterface = default!;
[Dependency] private readonly IDreamResourceManager _dreamResource = default!;
[Dependency] private readonly IDreamSoundEngine _soundEngine = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly ILightManager _lightManager = default!;
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly ILocalizationManager _contentLoc = default!;

private const string UserAgent =
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)";

public override void PreInit() {
var config = IoCManager.Resolve<IConfigurationManager>();
if (config.GetCVar(OpenDreamCVars.SpoofIEUserAgent)) {
config.OverrideDefault(WCVars.WebUserAgentOverride, UserAgent);
}

public override void Init() {
IoCManager.Resolve<IConfigurationManager>().OverrideDefault(CVars.NetPredict, false);

IComponentFactory componentFactory = IoCManager.Resolve<IComponentFactory>();
componentFactory.DoAutoRegistrations();

ClientContentIoC.Register();

// This needs to happen after all IoC registrations, but before IoC.BuildGraph();
foreach (var callback in TestingCallbacks) {
var cast = (ClientModuleTestingCallbacks) callback;
cast.ClientBeforeIoC?.Invoke();
}
IoCManager.Resolve<IEntitySystemManager>().SystemLoaded += OnEntitySystemLoaded;
}

IoCManager.BuildGraph();
IoCManager.InjectDependencies(this);
public override void Init() {
ClientContentIoC.Register();

IoCManager.Resolve<DreamUserInterfaceStateManager>().Initialize();
// This needs to happen after all IoC registrations, but before IoC.BuildGraph();
foreach (var callback in TestingCallbacks) {
var cast = (ClientModuleTestingCallbacks) callback;
cast.ClientBeforeIoC?.Invoke();
}

componentFactory.GenerateNetIds();
IoCManager.BuildGraph();
IoCManager.InjectDependencies(this);

_dreamResource.Initialize();
_componentFactory.DoAutoRegistrations();

// Load localization. Needed for some engine texts, such as the ones in Robust ViewVariables.
IoCManager.Resolve<ILocalizationManager>().LoadCulture(new CultureInfo("en-US"));
_componentFactory.GenerateNetIds();
// Load localization. Needed for some engine texts, such as the ones in Robust ViewVariables.
_contentLoc.LoadCulture(new CultureInfo("en-US"));
_dreamResource.Initialize();

IoCManager.Resolve<IClyde>().SetWindowTitle("OpenDream");
}
_configManager.OverrideDefault(CVars.NetPredict, false);
}

public override void PostInit() {
_lightManager.Enabled = false;
public override void PostInit() {
base.PostInit();
_lightManager.Enabled = false;

// In PostInit() since the engine stylesheet gets set in Init()
IoCManager.Resolve<IUserInterfaceManager>().Stylesheet = DreamStylesheet.Make();
// In PostInit() since the engine stylesheet gets set in Init()
_userInterfaceManager.Stylesheet = DreamStylesheet.Make();
IoCManager.Resolve<DreamUserInterfaceStateManager>().Initialize(); // later hooked for stylesheet
_stateManager.RequestStateChange<MainMenuState>(); // reset state

_dreamInterface.Initialize();
IoCManager.Resolve<IDreamSoundEngine>().Initialize();
}
_dreamInterface.Initialize();
IoCManager.Resolve<IDreamSoundEngine>().Initialize();
}

protected override void Dispose(bool disposing) {
_dreamResource.Shutdown();
}
protected override void Dispose(bool disposing) {
_dreamResource.Shutdown();
}

public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs) {
switch (level) {
case ModUpdateLevel.FramePostEngine:
_dreamInterface.FrameUpdate(frameEventArgs);
break;
case ModUpdateLevel.PostEngine:
_soundEngine.StopFinishedChannels();
break;
}
public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs) {
switch (level) {
case ModUpdateLevel.FramePostEngine:
_dreamInterface.FrameUpdate(frameEventArgs);
break;
case ModUpdateLevel.PostEngine:
_soundEngine.StopFinishedChannels();
break;
}
}

// As of RobustToolbox v0.90.0.0 there's a TileEdgeOverlay that breaks our rendering
// because we don't have an ITileDefinition for each tile.
// This removes that overlay immediately after MapSystem adds it.
// TODO: Fix this engine-side
private void OnEntitySystemLoaded(object? sender, SystemChangedArgs e) {
if (e.System is not MapSystem)
return;
// As of RobustToolbox v0.90.0.0 there's a TileEdgeOverlay that breaks our rendering
// because we don't have an ITileDefinition for each tile.
// This removes that overlay immediately after MapSystem adds it.
// TODO: Fix this engine-side
private void OnEntitySystemLoaded(object? sender, SystemChangedArgs e) {
if (e.System is not MapSystem)
return;

_overlayManager.RemoveOverlay<TileEdgeOverlay>();
}
_overlayManager.RemoveOverlay<TileEdgeOverlay>();
}
}

0 comments on commit bdd8cd5

Please sign in to comment.