Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supermatter crystal #1543

Merged
merged 42 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d1026ae
InitCommit
Alwayswannahunt Aug 6, 2024
b029a92
ThermodynamicsDone
Alwayswannahunt Aug 6, 2024
eceb3c8
AllAtmoInteraction
Alwayswannahunt Aug 7, 2024
357ec46
Added2DPlots
Alwayswannahunt Aug 7, 2024
15b1326
AnnoucesAndIntegrity
Alwayswannahunt Aug 8, 2024
aab67b9
SomeAdminLogging
Alwayswannahunt Aug 8, 2024
f4b8f61
WeekendSM
Alwayswannahunt Aug 12, 2024
c9214b4
UIFeatures
Alwayswannahunt Aug 13, 2024
3ee59f6
hallucinationSystem
Alwayswannahunt Aug 14, 2024
4176d13
ServerClientEvent
Alwayswannahunt Aug 14, 2024
07395fc
Merge branch 'master' of https://github.com/Alwayswannahunt/space-sta…
Alwayswannahunt Aug 14, 2024
a063398
FixAfterMerge
Alwayswannahunt Aug 14, 2024
4acb236
WorkingMonitoringConsole
Alwayswannahunt Aug 17, 2024
63475c3
BaseUIPlotEnd
Alwayswannahunt Aug 19, 2024
e15b5f5
ToolTipsForGasesBegin
Alwayswannahunt Aug 19, 2024
52e1000
AddedLocaleUI
Alwayswannahunt Aug 20, 2024
45ac629
AllLocalesUI
Alwayswannahunt Aug 20, 2024
1f0069d
SMEmitterStep1
Alwayswannahunt Aug 21, 2024
1b75255
smEmitterUIEnd
Alwayswannahunt Aug 23, 2024
fb9f589
SomeVisualEnded
Alwayswannahunt Aug 26, 2024
25e60ce
SmalVisualRefactor
Alwayswannahunt Aug 27, 2024
26ef83f
WorkingCartridge
Alwayswannahunt Aug 30, 2024
487e4cb
BugFixesandLocales
Alwayswannahunt Aug 31, 2024
1610293
GoingGold
Alwayswannahunt Sep 6, 2024
fde173c
SpriteFixes
Alwayswannahunt Sep 8, 2024
ed7f49e
GoingGoldyGold
Alwayswannahunt Sep 10, 2024
e876c68
afterFirstReviewChanges
Alwayswannahunt Sep 14, 2024
cac7e65
mergeMaster
Alwayswannahunt Sep 14, 2024
2a1d872
HallucinationsAlive
Alwayswannahunt Sep 21, 2024
8cf5dcf
PostReviewChanges
Alwayswannahunt Sep 23, 2024
0cc94b9
HalfwayDone
Alwayswannahunt Sep 26, 2024
3a2c00e
LastStep
Alwayswannahunt Oct 5, 2024
0966b0b
GuideBook
Alwayswannahunt Oct 6, 2024
5a973aa
MergeMaster
Alwayswannahunt Oct 6, 2024
cdfa7f0
TestFix
Alwayswannahunt Oct 6, 2024
217ffb2
TestFix2
Alwayswannahunt Oct 6, 2024
8f3be1d
MapFix
Alwayswannahunt Oct 6, 2024
b9b4186
FixTestFalling
Alwayswannahunt Oct 9, 2024
cb93437
FixesFixFixes
Alwayswannahunt Oct 10, 2024
7ed634d
FixAndClean
Alwayswannahunt Oct 10, 2024
72f003b
UiMemoryLeakFix
Alwayswannahunt Oct 13, 2024
4b34dd4
ReviewChages
Alwayswannahunt Oct 13, 2024
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
57 changes: 57 additions & 0 deletions Content.Client/SS220/Cartridges/SupermatterCartridgeObserverUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Client.UserInterface.Fragments;
using Robust.Client.UserInterface;
using Content.Shared.SS220.SuperMatter.Ui;

namespace Content.Client.SS220.Cartridges;

public sealed partial class SupermatterObserverUi : UIFragment
{
public bool IsInitd => _isInitd;

private SupermatterObserverUiFragment? _fragment;
private bool _isInitd = true;

public override Control GetUIFragmentRoot()
{
return _fragment!;
}
public override void Setup(BoundUserInterface userInterface, EntityUid? fragmentOwner)
{
_fragment = new SupermatterObserverUiFragment();
_isInitd = false;

_fragment.OnServerButtonPressed += (args, observerComp) =>
{
if (args.Button.Pressed)
_fragment.Observer = observerComp;
else
_fragment.Observer = null;
_fragment.CrystalKey = null;
_fragment.LoadCrystal();
};
_fragment.OnCrystalButtonPressed += (args, crystalKey) =>
{
if (args.Button.Pressed)
_fragment.CrystalKey = crystalKey;
else
_fragment.CrystalKey = null;
_fragment.LoadCachedData();
};
_fragment.OnRefreshButton += (_) =>
_isInitd = false;
}
public override void UpdateState(BoundUserInterfaceState state)
{
switch (state)
{
case SuperMatterObserverInitState msg:
_fragment?.LoadState(msg.ObserverEntity);
_isInitd = true;
break;
case SuperMatterObserverUpdateState msg:
_fragment?.UpdateState(msg);
break;
}
}
}
44 changes: 44 additions & 0 deletions Content.Client/SS220/Cartridges/SupermatterObserverUiFragment.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!-- © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -->
<cartridges:SupermatterObserverUiFragment
xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:pda="clr-namespace:Content.Client.PDA"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:cartridges="clr-namespace:Content.Client.SS220.Cartridges"
xmlns:plot="clr-namespace:Content.Client.SS220.UserInterface.PlotFigure"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" VerticalExpand="True" Margin="1 0 2 0">
<Control HorizontalExpand="True">
<PanelContainer>
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E"/>
</PanelContainer.PanelOverride>
</PanelContainer>
<BoxContainer Name="ContentHolderContainer" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True">
<BoxContainer Orientation="Horizontal" VerticalAlignment="Center" HorizontalExpand="True">
<BoxContainer Name="ServerNavigationBar" HorizontalAlignment="Left" VerticalAlignment="Center" HorizontalExpand="True" MinHeight="24" MaxHeight="24" Margin="2 2 6 2">
<!-- Here goes all avaible "Servers" with SM data -->
</BoxContainer>
<pda:PdaNavigationButton Name="RefreshButton" SetWidth="32" CurrentTabBorderThickness="0 0 2 0" IsCurrent="True"/>
</BoxContainer>
<PanelContainer StyleClasses="LowDivider" Margin="2 0 2 0"/>
<BoxContainer Name="CrystalNavigationBar" VerticalAlignment="Center" HorizontalExpand="True" MinHeight="24" MaxHeight="24" Margin="2 2 6 2">
<!-- Here goes all avaible "Servers" with SM data -->
</BoxContainer>
<PanelContainer StyleClasses="LowDivider" Margin="2 0 2 0"/>
<ScrollContainer VerticalExpand="True" HorizontalExpand="True">
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True">
<plot:PlotSequencedView Name="PlotValueOverTime" HorizontalExpand="True" MinSize="168 232" MouseFilter="Stop" Margin="2 4 20 4"/>
<PanelContainer StyleClasses="LowDivider" Margin="2 0 2 0"/>
<plot:Pseudo3DColoredView Name="ColorState" HorizontalExpand="True" MouseFilter="Stop" MinSize="168 232"
Margin="2 4 20 4" Offsets="1 1" Sizes="100 100" Steps="25 100"/>
</BoxContainer>
</ScrollContainer>
<BoxContainer Orientation="Vertical">
<PanelContainer StyleClasses="LowDivider" />
<BoxContainer Orientation="Horizontal" Margin="10 2 5 0" VerticalAlignment="Bottom">
<Label Text="{Loc 'smObserver-cartridge-footer-left'}" StyleClasses="WindowFooterText" />
</BoxContainer>
</BoxContainer>
</BoxContainer>
</Control>
</cartridges:SupermatterObserverUiFragment>
133 changes: 133 additions & 0 deletions Content.Client/SS220/Cartridges/SupermatterObserverUiFragment.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using System.Linq;
using System.Numerics;
using Content.Client.SS220.SuperMatter.Observer;
using Content.Client.SS220.UserInterface.PlotFigure;
using Content.Shared.SS220.SuperMatter.Functions;
using Content.Shared.SS220.SuperMatter.Ui;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Utility;

namespace Content.Client.SS220.Cartridges;

[GenerateTypedNameReferences]
public sealed partial class SupermatterObserverUiFragment : BoxContainer
{
[Dependency] private readonly ILocalizationManager _localization = default!;

public event Action<BaseButton.ButtonEventArgs, SuperMatterObserverComponent>? OnServerButtonPressed;
public event Action<BaseButton.ButtonEventArgs, int>? OnCrystalButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnRefreshButton;

public SuperMatterObserverComponent? Observer;
public int? CrystalKey;

public const int MAX_DATA_LENGTH = 120;

public SupermatterObserverUiFragment()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

RefreshButton.IconTexture = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/refresh.svg.192dpi.png"));
RefreshButton.IconScale = new Vector2(0.3f); //convert 192px to 32px... but weird
RefreshButton.OnPressed += args =>
OnRefreshButton?.Invoke(args);

PlotValueOverTime.SetLabels(_localization.GetString("smObserver-plotXLabel-integrity"), _localization.GetString("smObserver-plotYLabel-integrity"), _localization.GetString("smObserver-plotTitle-integrity"));

ColorState.EvalFunctionOnMeshgrid(GetIntegrityDamageMap);
ColorState.SetLabels(_localization.GetString("smObserver-plotXLabel-colorState"), _localization.GetString("smObserver-plotYLabel-colorState"), _localization.GetString("smObserver-plotTitle-colorState"));
}

private float GetIntegrityDamageMap(float matter, float internalEnergy)
{
return SuperMatterFunctions.EnergyToMatterDamageFactorFunction(internalEnergy
- SuperMatterFunctions.SafeInternalEnergyToMatterFunction(matter / SuperMatterFunctions.MatterNondimensionalization),
matter / SuperMatterFunctions.MatterNondimensionalization);
}
public void LoadCrystal()
{
CrystalNavigationBar.RemoveAllChildren();
if (Observer == null)
return;
foreach (var (crystalKey, name) in Observer.Names)
{
var crystalButton = new CrystalButton
{
Text = name,
StyleBoxOverride = new StyleBoxFlat(Color.DarkGray),
CrystalKey = crystalKey,
ToggleMode = true,
Margin = new Thickness(2, 0, 2, 0),
StyleClasses = { "OpenBoth" }
};

crystalButton.OnPressed += args =>
{
OnCrystalButtonPressed?.Invoke(args, crystalButton.CrystalKey);
};
CrystalNavigationBar.AddChild(crystalButton);
}
}
public void LoadCachedData()
{
if (Observer == null
|| CrystalKey == null)
return;
PlotValueOverTime.LoadPlot2DTimePoints(new PlotPoints2D(MAX_DATA_LENGTH, Observer.Integrities[CrystalKey.Value],
-1f, Observer.Integrities[CrystalKey.Value].Count));
ColorState.LoadMovingPoint(new Vector2(Observer.Matters[CrystalKey.Value].Last().Value, Observer.InternalEnergy[CrystalKey.Value].Last().Value),
new Vector2(Observer.Matters[CrystalKey.Value].Last().Derv, Observer.InternalEnergy[CrystalKey.Value].Last().Derv));
}
public void UpdateState(SuperMatterObserverUpdateState msg)
{
if (Disposed)
return;

if (Observer == null
|| CrystalKey == null)
return;
if (msg.Id != CrystalKey)
return;

PlotValueOverTime.AddPointToPlot(new Vector2(PlotValueOverTime.GetLastAddedPointX() + 1f, msg.Integrity));
ColorState.LoadMovingPoint(new Vector2(msg.Matter.Value, msg.InternalEnergy.Value), new Vector2(msg.Matter.Derivative, msg.InternalEnergy.Derivative));
}
public void LoadState(List<Entity<SuperMatterObserverComponent>> observerEntities)
{
if (Disposed)
return;

ServerNavigationBar.RemoveAllChildren();
foreach (var (observerUid, observerComp) in observerEntities)
{
var serverButton = new ServerButton
{
Text = observerUid.ToString(),
StyleBoxOverride = new StyleBoxFlat(Color.DarkGray),
ObserverComponent = observerComp,
Margin = new Thickness(2, 0, 2, 0),
ToggleMode = true,
StyleClasses = { "OpenBoth" }
};

serverButton.OnPressed += args =>
{
OnServerButtonPressed?.Invoke(args, serverButton.ObserverComponent);
};
ServerNavigationBar.AddChild(serverButton);
}
}
private sealed class ServerButton : Button
{
public SuperMatterObserverComponent? ObserverComponent;
}
private sealed class CrystalButton : Button
{
public int CrystalKey;
}
}
16 changes: 16 additions & 0 deletions Content.Client/SS220/Hallucination/HallucinationComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Shared.SS220.Hallucination;

namespace Content.Client.SS220.Hallucination;
/// <summary>
/// lmaoooooo??
/// </summary>
[RegisterComponent]
public sealed partial class HallucinationComponent : SharedHallucinationComponent
{
// yeah yeah make it to client only
/// <summary>
/// used only if it is localEntity of the client
/// </summary>
public List<TimeSpan> HallucinationSpawnerTimers = [];
}
99 changes: 99 additions & 0 deletions Content.Client/SS220/Hallucination/HallucinationSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using System.Linq;
using Content.Shared.Random.Helpers;
using Content.Shared.SS220.Hallucination;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Spawners;
using System.Numerics;
using Robust.Shared.Timing;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
namespace Content.Client.SS220.Hallucination;

public sealed class HallucinationSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<HallucinationComponent, ComponentHandleState>(HandleState);
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);

if (!TryComp<HallucinationComponent>(_playerManager.LocalEntity, out var hallucinationComponent))
return;

for (int i = 0; i < hallucinationComponent.HallucinationSpawnerTimers.Count; i++)
{
var nextHallucinationSpawnTime = hallucinationComponent.HallucinationSpawnerTimers[i];
if (_gameTiming.CurTime > nextHallucinationSpawnTime)
{
var hallucination = hallucinationComponent.Hallucinations[i];
MakeHallucination(hallucination);

var timeBetweenHallucination = TimeSpan.FromSeconds(hallucination.TimeParams.BetweenHallucinations);
hallucinationComponent.HallucinationSpawnerTimers[i] = _gameTiming.CurTime + timeBetweenHallucination;
}
}
}
/// <summary>
/// Specific handler for hallucination due to bound between timer and hallucinationSettings. Probably saving the same order as in server
/// </summary>
private void HandleState(Entity<HallucinationComponent> entity, ref ComponentHandleState args)
{
if (args.Current is not HallucinationComponentState state)
return;

var hallucinationSymmetricDifference = new List<HallucinationSetting>(entity.Comp.Hallucinations.Union(state.Hallucinations).
Except(entity.Comp.Hallucinations.Intersect(state.Hallucinations)));
var index = -1;

foreach (var hallucination in hallucinationSymmetricDifference)
{
// handle deleting hallucination in client
index = entity.Comp.Hallucinations.IndexOf(hallucination);
if (index != -1)
{
entity.Comp.Hallucinations.RemoveAt(index);
entity.Comp.HallucinationSpawnerTimers.RemoveAt(index);
}
//handle adding hallucination to client
index = state.Hallucinations.IndexOf(hallucination);
if (index != -1)
{
entity.Comp.Hallucinations.Add(hallucination);
entity.Comp.HallucinationSpawnerTimers.Add(_gameTiming.CurTime);
}
}
// some self-checks in case of my mistake
DebugTools.Assert(entity.Comp.Hallucinations.Count == state.Hallucinations.Count);
DebugTools.Assert(entity.Comp.Hallucinations.Count == entity.Comp.HallucinationSpawnerTimers.Count);
}
private void MakeHallucination(HallucinationSetting hallucination)
{
var randomWeightedPrototypes = _prototypeManager.Index(hallucination.RandomEntities);
if (!_prototypeManager.TryIndex<EntityPrototype>(randomWeightedPrototypes.Pick(_random), out var randomProto))
return;

var spawnedEntityUid = EntityManager.SpawnAtPosition(randomProto.ID,
Transform(_playerManager.LocalEntity!.Value).Coordinates);
var randomCoordinates = _transformSystem.GetWorldPosition(_playerManager.LocalEntity!.Value)
+ new Vector2(_random.NextFloat(-6f, 6f), _random.NextFloat(-6f, 6f));
_transformSystem.SetWorldPosition(spawnedEntityUid, randomCoordinates);

var lifeTime = _random.NextFloat(hallucination.TimeParams.HallucinationMinTime, hallucination.TimeParams.HallucinationMaxTime);
var timedDespawnComp = EnsureComp<TimedDespawnComponent>(spawnedEntityUid);
timedDespawnComp.Lifetime = lifeTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using System.Numerics;
using Robust.Client.GameObjects;
using Content.Shared.SS220.SuperMatter.Emitter;
using Content.Client.SS220.UserInterface.PlotFigure;
using Content.Shared.Projectiles;

namespace Content.Client.SS220.SuperMatter.Emitter;

public sealed class SuperMatterEmitterSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SuperMatterEmitterBoltComponent, ComponentInit>(OnComponentInit);
}

private void OnComponentInit(Entity<SuperMatterEmitterBoltComponent> entity, ref ComponentInit args)
{
if (!TryComp<SpriteComponent>(entity.Owner, out var spriteComponent))
return;
if (!TryComp<ProjectileComponent>(entity.Owner, out var projectileComponent))
return;
var shootAuthorUid = projectileComponent.Shooter;
if (!TryComp<SuperMatterEmitterExtensionComponent>(shootAuthorUid, out var superMatterEmitter))
return;

spriteComponent.Color = Colormaps.SMEmitter.GetCorrespondingColor(superMatterEmitter.EnergyToMatterRatio / 100f);
spriteComponent.Scale = new Vector2(MathF.Sqrt(superMatterEmitter.PowerConsumption / (float)SuperMatterEmitterExtensionConsts.BaseEnergyConsumption));
}
}
Loading
Loading