mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
85 lines
3 KiB
C#
85 lines
3 KiB
C#
using Content.Server.Access.Components;
|
|
using Content.Server.Station.Systems;
|
|
using Content.Shared.Access.Systems;
|
|
using Content.Shared.GameTicking;
|
|
using Content.Shared.Roles;
|
|
using Content.Shared.Station.Components;
|
|
|
|
namespace Content.Server.Access.Systems;
|
|
|
|
public sealed partial class PresetIdCardSystem : EntitySystem
|
|
{
|
|
[Dependency] private IdCardSystem _cardSystem = default!;
|
|
[Dependency] private SharedAccessSystem _accessSystem = default!;
|
|
[Dependency] private ServerStationSystem _stationSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<PresetIdCardComponent, MapInitEvent>(OnMapInit);
|
|
|
|
SubscribeLocalEvent<RulePlayerJobsAssignedEvent>(PlayerJobsAssigned);
|
|
}
|
|
|
|
private void PlayerJobsAssigned(RulePlayerJobsAssignedEvent ev)
|
|
{
|
|
// Go over all ID cards and make sure they're correctly configured for extended access.
|
|
|
|
var query = EntityQueryEnumerator<PresetIdCardComponent>();
|
|
while (query.MoveNext(out var uid, out var card))
|
|
{
|
|
var station = _stationSystem.GetOwningStation(uid);
|
|
|
|
// If we're not on an extended access station, the ID is already configured correctly from MapInit.
|
|
if (station == null || !TryComp<StationJobsComponent>(station.Value, out var jobsComp) || !jobsComp.ExtendedAccess)
|
|
continue;
|
|
|
|
SetupIdAccess(uid, card, true);
|
|
SetupIdName(uid, card);
|
|
}
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, PresetIdCardComponent id, MapInitEvent args)
|
|
{
|
|
// If a preset ID card is spawned on a station at setup time,
|
|
// the station may not exist,
|
|
// or may not yet know whether it is on extended access (players not spawned yet).
|
|
// PlayerJobsAssigned makes sure extended access is configured correctly in that case.
|
|
|
|
var station = _stationSystem.GetOwningStation(uid);
|
|
var extended = false;
|
|
|
|
// Station not guaranteed to have jobs (e.g. nukie outpost).
|
|
if (TryComp(station, out StationJobsComponent? stationJobs))
|
|
extended = stationJobs.ExtendedAccess;
|
|
|
|
SetupIdAccess(uid, id, extended);
|
|
SetupIdName(uid, id);
|
|
}
|
|
|
|
private void SetupIdName(EntityUid uid, PresetIdCardComponent id)
|
|
{
|
|
if (id.IdName == null)
|
|
return;
|
|
_cardSystem.TryChangeFullName(uid, id.IdName);
|
|
}
|
|
|
|
private void SetupIdAccess(EntityUid uid, PresetIdCardComponent id, bool extended)
|
|
{
|
|
if (id.JobName == null)
|
|
return;
|
|
|
|
if (!ProtoMan.TryIndex(id.JobName, out JobPrototype? job))
|
|
{
|
|
Log.Error($"Invalid job id ({id.JobName}) for preset card");
|
|
return;
|
|
}
|
|
|
|
_accessSystem.SetAccessToJob(uid, job, extended);
|
|
|
|
_cardSystem.TryChangeJobTitle(uid, job.LocalizedName);
|
|
_cardSystem.TryChangeJobDepartment(uid, job);
|
|
|
|
if (ProtoMan.Resolve(job.Icon, out var jobIcon))
|
|
_cardSystem.TryChangeJobIcon(uid, jobIcon);
|
|
}
|
|
}
|