Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,73 @@
#nullable enable
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Research.Components
{
public class SharedResearchClientComponent : Component
{
public override string Name => "ResearchClient";
/// <summary>
/// Request that the server updates the client.
/// </summary>
[Serializable, NetSerializable]
public class ResearchClientSyncMessage : BoundUserInterfaceMessage
{
public ResearchClientSyncMessage()
{
}
}
/// <summary>
/// Sent to the server when the client chooses a research server.
/// </summary>
[Serializable, NetSerializable]
public class ResearchClientServerSelectedMessage : BoundUserInterfaceMessage
{
public int ServerId;
public ResearchClientServerSelectedMessage(int serverId)
{
ServerId = serverId;
}
}
/// <summary>
/// Sent to the server when the client deselects a research server.
/// </summary>
[Serializable, NetSerializable]
public class ResearchClientServerDeselectedMessage : BoundUserInterfaceMessage
{
public ResearchClientServerDeselectedMessage()
{
}
}
[NetSerializable, Serializable]
public enum ResearchClientUiKey
{
Key,
}
[Serializable, NetSerializable]
public sealed class ResearchClientBoundInterfaceState : BoundUserInterfaceState
{
public int ServerCount;
public string[] ServerNames;
public int[] ServerIds;
public int SelectedServerId;
public ResearchClientBoundInterfaceState(int serverCount, string[] serverNames, int[] serverIds, int selectedServerId = -1)
{
ServerCount = serverCount;
ServerNames = serverNames;
ServerIds = serverIds;
SelectedServerId = selectedServerId;
}
}
}
}

View File

@@ -0,0 +1,57 @@
#nullable enable
using System;
using Content.Shared.NetIDs;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.Research.Components
{
public class SharedResearchConsoleComponent : Component
{
public override string Name => "ResearchConsole";
public override uint? NetID => ContentNetIDs.RESEARCH_CONSOLE;
[NetSerializable, Serializable]
public enum ResearchConsoleUiKey
{
Key,
}
[Serializable, NetSerializable]
public class ConsoleUnlockTechnologyMessage : BoundUserInterfaceMessage
{
public string Id;
public ConsoleUnlockTechnologyMessage(string id)
{
Id = id;
}
}
[Serializable, NetSerializable]
public class ConsoleServerSyncMessage : BoundUserInterfaceMessage
{
public ConsoleServerSyncMessage()
{}
}
[Serializable, NetSerializable]
public class ConsoleServerSelectionMessage : BoundUserInterfaceMessage
{
public ConsoleServerSelectionMessage()
{}
}
[Serializable, NetSerializable]
public sealed class ResearchConsoleBoundInterfaceState : BoundUserInterfaceState
{
public int Points;
public int PointsPerSecond;
public ResearchConsoleBoundInterfaceState(int points, int pointsPerSecond)
{
Points = points;
PointsPerSecond = pointsPerSecond;
}
}
}
}

View File

@@ -0,0 +1,131 @@
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
using Content.Shared.NetIDs;
using Content.Shared.Research.Prototypes;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Research.Components
{
public class SharedTechnologyDatabaseComponent : Component, IEnumerable<TechnologyPrototype>, ISerializationHooks
{
public override string Name => "TechnologyDatabase";
public override uint? NetID => ContentNetIDs.TECHNOLOGY_DATABASE;
[DataField("technologies")] private List<string> _technologyIds = new();
protected List<TechnologyPrototype> _technologies = new();
/// <summary>
/// A read-only list of unlocked technologies.
/// </summary>
public IReadOnlyList<TechnologyPrototype> Technologies => _technologies;
void ISerializationHooks.BeforeSerialization()
{
var techIds = new List<string>();
foreach (var tech in _technologies)
{
techIds.Add(tech.ID);
}
_technologyIds = techIds;
}
void ISerializationHooks.AfterDeserialization()
{
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in _technologyIds)
{
if (prototypeManager.TryIndex(id, out TechnologyPrototype? tech))
{
_technologies.Add(tech);
}
}
}
public IEnumerator<TechnologyPrototype> GetEnumerator()
{
return Technologies.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
/// <summary>
/// Returns a list with the IDs of all unlocked technologies.
/// </summary>
/// <returns>A list of technology IDs</returns>
public List<string> GetTechnologyIdList()
{
List<string> techIds = new List<string>();
foreach (var tech in _technologies)
{
techIds.Add(tech.ID);
}
return techIds;
}
/// <summary>
/// Returns whether a technology is unlocked on this database or not.
/// </summary>
/// <param name="technology">The technology to be checked</param>
/// <returns>Whether it is unlocked or not</returns>
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
{
return _technologies.Contains(technology);
}
/// <summary>
/// Returns whether a technology can be unlocked on this database,
/// taking parent technologies into account.
/// </summary>
/// <param name="technology">The technology to be checked</param>
/// <returns>Whether it could be unlocked or not</returns>
public bool CanUnlockTechnology(TechnologyPrototype technology)
{
if (technology == null || IsTechnologyUnlocked(technology)) return false;
var protoMan = IoCManager.Resolve<IPrototypeManager>();
foreach (var technologyId in technology.RequiredTechnologies)
{
protoMan.TryIndex(technologyId, out TechnologyPrototype? requiredTechnology);
if (requiredTechnology == null)
return false;
if (!IsTechnologyUnlocked(requiredTechnology))
return false;
}
return true;
}
}
[Serializable, NetSerializable]
public class TechnologyDatabaseState : ComponentState
{
public List<string> Technologies;
public TechnologyDatabaseState(List<string> technologies) : base(ContentNetIDs.TECHNOLOGY_DATABASE)
{
Technologies = technologies;
}
public TechnologyDatabaseState(List<TechnologyPrototype> technologies) : base(ContentNetIDs.TECHNOLOGY_DATABASE)
{
Technologies = new List<string>();
foreach (var technology in technologies)
{
Technologies.Add(technology.ID);
}
}
}
}