forked from WWhiteDreamProject/wwdpublic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
151 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Content.Server.Everwood.Immersive; | ||
|
||
[RegisterComponent] | ||
public sealed partial class ImmersiveComponent : Component | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using Content.Server.Administration; | ||
using Content.Server.Administration.Logs; | ||
using Content.Shared.Telescope; | ||
using Content.Shared.Administration; | ||
using Content.Shared.Everwood.CCVar; | ||
using Content.Shared.Database; | ||
using Content.Shared.Humanoid; | ||
using Content.Shared.Movement.Components; | ||
using Robust.Shared.Configuration; | ||
using Robust.Shared.Console; | ||
using Robust.Shared.GameObjects; | ||
|
||
namespace Content.Server.Everwood.Immersive; | ||
|
||
public sealed class ImmersiveSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedTelescopeSystem _telescope = default!; | ||
[Dependency] private readonly IConfigurationManager _configurationManager = default!; | ||
[Dependency] private readonly IConsoleHost _console = default!; | ||
[Dependency] private readonly IAdminLogManager _adminLog = default!; | ||
|
||
private bool _immersiveEnabled; | ||
private const float TelescopeDivisor = 0.8f; // 2 tiles further than normal | ||
private const float TelescopeLerpAmount = 0.1f; // Looks nice. | ||
|
||
private EntityQuery<ContentEyeComponent> _eyeQuery; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<ImmersiveComponent, MapInitEvent>(OnPlayerSpawn); | ||
|
||
Subs.CVar(_configurationManager, EverwoodCCVars.ImmersiveEnabled, OnValueChanged, true); | ||
|
||
_console.RegisterCommand("setImmersive", SetImmersiveCommand); | ||
_eyeQuery = GetEntityQuery<ContentEyeComponent>(); | ||
} | ||
|
||
private void OnValueChanged(bool value) | ||
{ | ||
_immersiveEnabled = value; | ||
if (value) | ||
{ | ||
OnStarted(); | ||
} | ||
else | ||
{ | ||
Ended(); | ||
} | ||
} | ||
|
||
[AdminCommand(AdminFlags.Fun)] | ||
private void SetImmersiveCommand(IConsoleShell shell, string str, string[] args) | ||
{ | ||
_configurationManager.SetCVar(EverwoodCCVars.ImmersiveEnabled, !_immersiveEnabled); | ||
shell.WriteLine($"Immersive set in {_immersiveEnabled}"); | ||
_adminLog.Add(LogType.AdminMessage, | ||
LogImpact.Extreme, | ||
$"Admin {(shell.Player != null ? shell.Player.Name : "An administrator")} immersive set in {_immersiveEnabled}"); | ||
} | ||
|
||
private void OnStarted() | ||
{ | ||
var humans = EntityQueryEnumerator<HumanoidAppearanceComponent, ContentEyeComponent>(); | ||
|
||
while (humans.MoveNext(out var entity, out _, out _)) | ||
{ | ||
AddTelescope(entity, TelescopeDivisor, TelescopeLerpAmount); | ||
} | ||
} | ||
|
||
private void Ended() | ||
{ | ||
var humans = EntityQueryEnumerator<HumanoidAppearanceComponent, ContentEyeComponent, TelescopeComponent>(); | ||
while (humans.MoveNext(out var entity, out _, out _, out _)) | ||
{ | ||
RemCompDeferred<TelescopeComponent>(entity); | ||
} | ||
} | ||
|
||
private void AddTelescope(EntityUid human, float divisor, float lerpAmount) | ||
{ | ||
_telescope.SetParameters((human, EnsureComp<TelescopeComponent>(human)), divisor, lerpAmount); | ||
} | ||
|
||
private void OnPlayerSpawn(Entity<ImmersiveComponent> ent, ref MapInitEvent ev) | ||
{ | ||
if (!_immersiveEnabled) | ||
return; | ||
|
||
if (!_eyeQuery.HasComp(ent)) | ||
return; | ||
|
||
AddTelescope(ent, TelescopeDivisor, TelescopeLerpAmount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Robust.Shared; | ||
using Robust.Shared.Configuration; | ||
|
||
namespace Content.Shared.Everwood.CCVar | ||
{ | ||
[CVarDefs] | ||
public sealed class EverwoodCCVars : CVars | ||
{ | ||
|
||
/* | ||
* Immersive | ||
*/ | ||
|
||
public static readonly CVarDef<bool> ImmersiveEnabled = | ||
CVarDef.Create("immersive.enabled", true, CVar.SERVERONLY); | ||
|
||
} | ||
} |