Adds Research, unlockable technologies, Protolathes... (#264)
* Work on Research so far More work on UI... Fix ResearchClient and Protolathe UI stuff. Fix infinite select -> request state -> select -> ... loop Add UI to ResearchClient, etc. Technology Database states, and a bit of work on the research console ui A bit of work on Research Console UI Protolathe sync Stuff that actually does things Protolathe databases yay Alright got my motivation back Yeah, no. It's almost 3 AM already Fix serialization bug again More work on stuff Stuff Adds files for most new components/systems. * Protolathes actually work now * Research. Just Research. * Adds icons from Eris. * Address reviews * Change LatheMenu resize behaviour * Update Content.Client/GameObjects/Components/Research/ResearchConsoleBoundUserInterface.cs Co-Authored-By: Pieter-Jan Briers <pieterjan.briers@gmail.com> * Update Content.Client/Research/ResearchConsoleMenu.cs Co-Authored-By: Pieter-Jan Briers <pieterjan.briers@gmail.com> * Move IoC Resolve out of for loop * Address review * Localize stuff
This commit is contained in:
committed by
Pieter-Jan Briers
parent
b62fb4a318
commit
ba8b495ec0
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Research;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Research
|
||||
{
|
||||
public class SharedTechnologyDatabaseComponent : Component, IEnumerable<TechnologyPrototype>
|
||||
{
|
||||
public override string Name => "TechnologyDatabase";
|
||||
public override uint? NetID => ContentNetIDs.TECHNOLOGY_DATABASE;
|
||||
public override Type StateType => typeof(TechnologyDatabaseState);
|
||||
|
||||
protected List<TechnologyPrototype> _technologies = new List<TechnologyPrototype>();
|
||||
|
||||
/// <summary>
|
||||
/// A read-only list of unlocked technologies.
|
||||
/// </summary>
|
||||
public IReadOnlyList<TechnologyPrototype> Technologies => _technologies;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
if (serializer.Reading)
|
||||
{
|
||||
var techs = serializer.ReadDataField("technologies", new List<string>());
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
foreach (var id in techs)
|
||||
{
|
||||
if (!prototypeManager.TryIndex(id, out TechnologyPrototype tech)) continue;
|
||||
_technologies.Add(tech);
|
||||
}
|
||||
} else if (serializer.Writing)
|
||||
{
|
||||
var techs = GetTechnologyIdList();
|
||||
serializer.DataField(ref techs, "technologies", new List<string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user