Skip to content

Commit

Permalink
Make vent data initialization much cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Apr 10, 2021
1 parent 7764987 commit 1d66f07
Show file tree
Hide file tree
Showing 25 changed files with 310 additions and 208 deletions.
7 changes: 5 additions & 2 deletions src/Impostor.Api/Events/Game/Player/IPlayerEnterVentEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Impostor.Api.Events.Player
{
/// <summary>
/// Called whenever a player enters a vent.
/// </summary>
public interface IPlayerEnterVentEvent : IPlayerEvent
{
/// <summary>
/// Gets get the id of the used vent.
/// Gets the entered vent.
/// </summary>
public Vent Vent { get; }
public IVent Vent { get; }
}
}
7 changes: 5 additions & 2 deletions src/Impostor.Api/Events/Game/Player/IPlayerExitVentEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Impostor.Api.Events.Player
{
/// <summary>
/// Called whenever a player exits a vent.
/// </summary>
public interface IPlayerExitVentEvent : IPlayerEvent
{
/// <summary>
/// Gets get the id of the used vent.
/// Gets the exited vent.
/// </summary>
public Vent Vent { get; }
public IVent Vent { get; }
}
}
7 changes: 5 additions & 2 deletions src/Impostor.Api/Events/Game/Player/IPlayerVentEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Impostor.Api.Events.Player
{
/// <summary>
/// Called whenever a player moves to another vent.
/// </summary>
public interface IPlayerVentEvent : IPlayerEvent
{
/// <summary>
/// Gets get the id of the used vent.
/// Gets the vent player moved to.
/// </summary>
public Vent Vent { get; }
public IVent NewVent { get; }
}
}
16 changes: 16 additions & 0 deletions src/Impostor.Api/Extensions/DictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Impostor.Api
{
public static class DictionaryExtensions
{
/// <summary>Returns a read-only <see cref="T:System.Collections.ObjectModel.ReadOnlyDictionary`2" /> wrapper for the dictionary.</summary>
/// <returns>An object that acts as a read-only wrapper around the <see cref="T:System.Collections.Generic.IDictionary`2" />.</returns>
public static ReadOnlyDictionary<TKey, TValue> AsReadOnly<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
where TKey : notnull
{
return new ReadOnlyDictionary<TKey, TValue>(dictionary);
}
}
}
19 changes: 19 additions & 0 deletions src/Impostor.Api/Innersloth/IVent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Numerics;

namespace Impostor.Api.Innersloth
{
public interface IVent
{
int Id { get; }

string Name { get; }

Vector2 Position { get; }

IVent? Left { get; }

IVent? Center { get; }

IVent? Right { get; }
}
}
53 changes: 21 additions & 32 deletions src/Impostor.Api/Innersloth/Maps/AirshipData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,34 @@

namespace Impostor.Api.Innersloth.Maps
{
public class AirshipData : MapData
public class AirshipData : IMapData
{
private readonly IReadOnlyDictionary<int, IVent> _vents;

public AirshipData()
{
Vents = new[]
var vents = new[]
{
new AirshipVent(AirshipVent.Ids.Vault, new Vector2(-12.6322f, 8.4735f)),
new AirshipVent(AirshipVent.Ids.Cockpit, new Vector2(-22.099f, -1.512f)),
new AirshipVent(AirshipVent.Ids.ViewingDeck, new Vector2(-15.659f, -11.6991f)),
new AirshipVent(AirshipVent.Ids.EngineRoom, new Vector2(0.203f, -2.5361f)),
new AirshipVent(AirshipVent.Ids.Kitchen, new Vector2(-2.6019f, -9.338f)),
new AirshipVent(AirshipVent.Ids.MainHallBottom, new Vector2(7.021f, -3.730999f)),
new AirshipVent(AirshipVent.Ids.GapRight, new Vector2(9.814f, 3.206f)),
new AirshipVent(AirshipVent.Ids.GapLeft, new Vector2(12.663f, 5.922f)),
new AirshipVent(AirshipVent.Ids.MainHallTop, new Vector2(3.605f, 6.923f)),
new AirshipVent(AirshipVent.Ids.Showers, new Vector2(23.9869f, -1.386f)),
new AirshipVent(AirshipVent.Ids.Records, new Vector2(23.2799f, 8.259998f)),
new AirshipVent(AirshipVent.Ids.CargoBay, new Vector2(30.4409f, -3.577f)),
}.ToDictionary(x => x.Id, x => (Vent)x);
new AirshipVent(this, AirshipVent.Ids.Vault, new Vector2(-12.6322f, 8.4735f), left: AirshipVent.Ids.Cockpit),
new AirshipVent(this, AirshipVent.Ids.Cockpit, new Vector2(-22.099f, -1.512f), left: AirshipVent.Ids.Vault, right: AirshipVent.Ids.ViewingDeck),
new AirshipVent(this, AirshipVent.Ids.ViewingDeck, new Vector2(-15.659f, -11.6991f), left: AirshipVent.Ids.Cockpit),
new AirshipVent(this, AirshipVent.Ids.EngineRoom, new Vector2(0.203f, -2.5361f), left: AirshipVent.Ids.Kitchen, right: AirshipVent.Ids.MainHallBottom),
new AirshipVent(this, AirshipVent.Ids.Kitchen, new Vector2(-2.6019f, -9.338f), left: AirshipVent.Ids.EngineRoom, right: AirshipVent.Ids.MainHallBottom),
new AirshipVent(this, AirshipVent.Ids.MainHallBottom, new Vector2(7.021f, -3.730999f), left: AirshipVent.Ids.EngineRoom, right: AirshipVent.Ids.Kitchen),
new AirshipVent(this, AirshipVent.Ids.GapRight, new Vector2(9.814f, 3.206f), left: AirshipVent.Ids.MainHallTop, right: AirshipVent.Ids.GapLeft),
new AirshipVent(this, AirshipVent.Ids.GapLeft, new Vector2(12.663f, 5.922f), left: AirshipVent.Ids.MainHallTop, right: AirshipVent.Ids.GapRight),
new AirshipVent(this, AirshipVent.Ids.MainHallTop, new Vector2(3.605f, 6.923f), left: AirshipVent.Ids.GapLeft, right: AirshipVent.Ids.GapRight),
new AirshipVent(this, AirshipVent.Ids.Showers, new Vector2(23.9869f, -1.386f), left: AirshipVent.Ids.Records, right: AirshipVent.Ids.CargoBay),
new AirshipVent(this, AirshipVent.Ids.Records, new Vector2(23.2799f, 8.259998f), left: AirshipVent.Ids.Showers, right: AirshipVent.Ids.CargoBay),
new AirshipVent(this, AirshipVent.Ids.CargoBay, new Vector2(30.4409f, -3.577f), left: AirshipVent.Ids.Showers, right: AirshipVent.Ids.Records),
};

ConnectVents(AirshipVent.Ids.Vault, left: AirshipVent.Ids.Cockpit);
ConnectVents(AirshipVent.Ids.Cockpit, left: AirshipVent.Ids.Vault, right: AirshipVent.Ids.ViewingDeck);
ConnectVents(AirshipVent.Ids.ViewingDeck, left: AirshipVent.Ids.Cockpit);
ConnectVents(AirshipVent.Ids.EngineRoom, left: AirshipVent.Ids.Kitchen, right: AirshipVent.Ids.MainHallBottom);
ConnectVents(AirshipVent.Ids.Kitchen, left: AirshipVent.Ids.EngineRoom, right: AirshipVent.Ids.MainHallBottom);
ConnectVents(AirshipVent.Ids.MainHallBottom, left: AirshipVent.Ids.EngineRoom, right: AirshipVent.Ids.Kitchen);
ConnectVents(AirshipVent.Ids.GapRight, left: AirshipVent.Ids.MainHallTop, right: AirshipVent.Ids.GapLeft);
ConnectVents(AirshipVent.Ids.GapLeft, left: AirshipVent.Ids.MainHallTop, right: AirshipVent.Ids.GapRight);
ConnectVents(AirshipVent.Ids.MainHallTop, left: AirshipVent.Ids.GapLeft, right: AirshipVent.Ids.GapRight);
ConnectVents(AirshipVent.Ids.Showers, left: AirshipVent.Ids.Records, right: AirshipVent.Ids.CargoBay);
ConnectVents(AirshipVent.Ids.Records, left: AirshipVent.Ids.Showers, right: AirshipVent.Ids.CargoBay);
ConnectVents(AirshipVent.Ids.CargoBay, left: AirshipVent.Ids.Showers, right: AirshipVent.Ids.Records);
Vents = vents.ToDictionary(x => x.Id, x => x).AsReadOnly();
_vents = vents.ToDictionary(x => (int)x.Id, x => (IVent)x).AsReadOnly();
}

public override IReadOnlyDictionary<int, Vent> Vents { get; }
public IReadOnlyDictionary<AirshipVent.Ids, AirshipVent> Vents { get; }

private void ConnectVents(AirshipVent.Ids vent, AirshipVent.Ids? left = null, AirshipVent.Ids? center = null, AirshipVent.Ids? right = null)
{
ConnectVents((int)vent, (int?)left, (int?)center, (int?)right);
}
IReadOnlyDictionary<int, IVent> IMapData.Vents => _vents;
}
}
17 changes: 17 additions & 0 deletions src/Impostor.Api/Innersloth/Maps/IMapData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace Impostor.Api.Innersloth.Maps
{
public interface IMapData
{
public static IReadOnlyDictionary<MapTypes, IMapData> Maps { get; } = new Dictionary<MapTypes, IMapData>
{
[MapTypes.Skeld] = new SkeldData(),
[MapTypes.MiraHQ] = new MiraData(),
[MapTypes.Polus] = new PolusData(),
[MapTypes.Airship] = new AirshipData(),
}.AsReadOnly();

IReadOnlyDictionary<int, IVent> Vents { get; }
}
}
24 changes: 0 additions & 24 deletions src/Impostor.Api/Innersloth/Maps/MapData.cs

This file was deleted.

50 changes: 20 additions & 30 deletions src/Impostor.Api/Innersloth/Maps/MiraData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,33 @@

namespace Impostor.Api.Innersloth.Maps
{
public class MiraData : MapData
public class MiraData : IMapData
{
private readonly IReadOnlyDictionary<int, IVent> _vents;

public MiraData()
{
Vents = new[]
var vents = new[]
{
new MiraVent(MiraVent.Ids.Balcony, new Vector2(23.77f, -1.94f)),
new MiraVent(MiraVent.Ids.Cafeteria, new Vector2(23.9f, 7.18f)),
new MiraVent(MiraVent.Ids.Reactor, new Vector2(0.4800001f, 10.697f)),
new MiraVent(MiraVent.Ids.Laboratory, new Vector2(11.606f, 13.816f)),
new MiraVent(MiraVent.Ids.Office, new Vector2(13.28f, 20.13f)),
new MiraVent(MiraVent.Ids.Admin, new Vector2(22.39f, 17.23f)),
new MiraVent(MiraVent.Ids.Greenhouse, new Vector2(17.85f, 25.23f)),
new MiraVent(MiraVent.Ids.Medbay, new Vector2(15.41f, -1.82f)),
new MiraVent(MiraVent.Ids.Decontamination, new Vector2(6.83f, 3.145f)),
new MiraVent(MiraVent.Ids.LockerRoom, new Vector2(4.29f, 0.5299997f)),
new MiraVent(MiraVent.Ids.Launchpad, new Vector2(-6.18f, 3.56f)),
}.ToDictionary(x => x.Id, x => (Vent)x);
new MiraVent(this, MiraVent.Ids.Balcony, new Vector2(23.77f, -1.94f), left: MiraVent.Ids.Medbay, right: MiraVent.Ids.Cafeteria),
new MiraVent(this, MiraVent.Ids.Cafeteria, new Vector2(23.9f, 7.18f), left: MiraVent.Ids.Admin, right: MiraVent.Ids.Balcony),
new MiraVent(this, MiraVent.Ids.Reactor, new Vector2(0.4800001f, 10.697f), left: MiraVent.Ids.Laboratory, center: MiraVent.Ids.Decontamination, right: MiraVent.Ids.Launchpad),
new MiraVent(this, MiraVent.Ids.Laboratory, new Vector2(11.606f, 13.816f), left: MiraVent.Ids.Reactor, center: MiraVent.Ids.Decontamination, right: MiraVent.Ids.Office),
new MiraVent(this, MiraVent.Ids.Office, new Vector2(13.28f, 20.13f), left: MiraVent.Ids.Laboratory, center: MiraVent.Ids.Admin, right: MiraVent.Ids.Greenhouse),
new MiraVent(this, MiraVent.Ids.Admin, new Vector2(22.39f, 17.23f), left: MiraVent.Ids.Greenhouse, center: MiraVent.Ids.Cafeteria, right: MiraVent.Ids.Office),
new MiraVent(this, MiraVent.Ids.Greenhouse, new Vector2(17.85f, 25.23f), left: MiraVent.Ids.Admin, right: MiraVent.Ids.Office),
new MiraVent(this, MiraVent.Ids.Medbay, new Vector2(15.41f, -1.82f), left: MiraVent.Ids.Balcony, right: MiraVent.Ids.LockerRoom),
new MiraVent(this, MiraVent.Ids.Decontamination, new Vector2(6.83f, 3.145f), left: MiraVent.Ids.Reactor, center: MiraVent.Ids.LockerRoom, right: MiraVent.Ids.Laboratory),
new MiraVent(this, MiraVent.Ids.LockerRoom, new Vector2(4.29f, 0.5299997f), left: MiraVent.Ids.Medbay, center: MiraVent.Ids.Launchpad, right: MiraVent.Ids.Decontamination),
new MiraVent(this, MiraVent.Ids.Launchpad, new Vector2(-6.18f, 3.56f), left: MiraVent.Ids.Reactor, right: MiraVent.Ids.LockerRoom),
};

ConnectVents(MiraVent.Ids.Balcony, left: MiraVent.Ids.Medbay, right: MiraVent.Ids.Cafeteria);
ConnectVents(MiraVent.Ids.Cafeteria, left: MiraVent.Ids.Admin, right: MiraVent.Ids.Balcony);
ConnectVents(MiraVent.Ids.Reactor, left: MiraVent.Ids.Laboratory, center: MiraVent.Ids.Decontamination, right: MiraVent.Ids.Launchpad);
ConnectVents(MiraVent.Ids.Laboratory, left: MiraVent.Ids.Reactor, center: MiraVent.Ids.Decontamination, right: MiraVent.Ids.Office);
ConnectVents(MiraVent.Ids.Office, left: MiraVent.Ids.Laboratory, center: MiraVent.Ids.Admin, right: MiraVent.Ids.Greenhouse);
ConnectVents(MiraVent.Ids.Admin, left: MiraVent.Ids.Greenhouse, center: MiraVent.Ids.Cafeteria, right: MiraVent.Ids.Office);
ConnectVents(MiraVent.Ids.Greenhouse, left: MiraVent.Ids.Admin, right: MiraVent.Ids.Office);
ConnectVents(MiraVent.Ids.Medbay, left: MiraVent.Ids.Balcony, right: MiraVent.Ids.LockerRoom);
ConnectVents(MiraVent.Ids.Decontamination, left: MiraVent.Ids.Reactor, center: MiraVent.Ids.LockerRoom, right: MiraVent.Ids.Laboratory);
ConnectVents(MiraVent.Ids.LockerRoom, left: MiraVent.Ids.Medbay, center: MiraVent.Ids.Launchpad, right: MiraVent.Ids.Decontamination);
ConnectVents(MiraVent.Ids.Launchpad, left: MiraVent.Ids.Reactor, right: MiraVent.Ids.LockerRoom);
Vents = vents.ToDictionary(x => x.Id, x => x).AsReadOnly();
_vents = vents.ToDictionary(x => (int)x.Id, x => (IVent)x).AsReadOnly();
}

public override IReadOnlyDictionary<int, Vent> Vents { get; }
public IReadOnlyDictionary<MiraVent.Ids, MiraVent> Vents { get; }

private void ConnectVents(MiraVent.Ids vent, MiraVent.Ids? left = null, MiraVent.Ids? center = null, MiraVent.Ids? right = null)
{
ConnectVents((int)vent, (int?)left, (int?)center, (int?)right);
}
IReadOnlyDictionary<int, IVent> IMapData.Vents => _vents;
}
}
53 changes: 21 additions & 32 deletions src/Impostor.Api/Innersloth/Maps/PolusData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,34 @@

namespace Impostor.Api.Innersloth.Maps
{
public class PolusData : MapData
public class PolusData : IMapData
{
private readonly IReadOnlyDictionary<int, IVent> _vents;

public PolusData()
{
Vents = new[]
var vents = new[]
{
new PolusVent(PolusVent.Ids.Security, new Vector2(1.929f, -9.558001f)),
new PolusVent(PolusVent.Ids.Electrical, new Vector2(6.9f, -14.41f)),
new PolusVent(PolusVent.Ids.O2, new Vector2(3.51f, -16.58f)),
new PolusVent(PolusVent.Ids.Communications, new Vector2(12.304f, -18.898f)),
new PolusVent(PolusVent.Ids.Office, new Vector2(16.379f, -19.599f)),
new PolusVent(PolusVent.Ids.Admin, new Vector2(20.089f, -25.517f)),
new PolusVent(PolusVent.Ids.Laboratory, new Vector2(32.963f, -9.526f)),
new PolusVent(PolusVent.Ids.Lava, new Vector2(30.907f, -11.86f)),
new PolusVent(PolusVent.Ids.Storage, new Vector2(22f, -12.19f)),
new PolusVent(PolusVent.Ids.RightStabilizer, new Vector2(24.02f, -8.39f)),
new PolusVent(PolusVent.Ids.LeftStabilizer, new Vector2(9.64f, -7.72f)),
new PolusVent(PolusVent.Ids.OutsideAdmin, new Vector2(18.93f, -24.85f)),
}.ToDictionary(x => x.Id, x => (Vent)x);
new PolusVent(this, PolusVent.Ids.Security, new Vector2(1.929f, -9.558001f), left: PolusVent.Ids.O2, right: PolusVent.Ids.Electrical),
new PolusVent(this, PolusVent.Ids.Electrical, new Vector2(6.9f, -14.41f), left: PolusVent.Ids.O2, right: PolusVent.Ids.Security),
new PolusVent(this, PolusVent.Ids.O2, new Vector2(3.51f, -16.58f), left: PolusVent.Ids.Electrical, right: PolusVent.Ids.Security),
new PolusVent(this, PolusVent.Ids.Communications, new Vector2(12.304f, -18.898f), left: PolusVent.Ids.Storage, right: PolusVent.Ids.Office),
new PolusVent(this, PolusVent.Ids.Office, new Vector2(16.379f, -19.599f), left: PolusVent.Ids.Communications, right: PolusVent.Ids.Storage),
new PolusVent(this, PolusVent.Ids.Admin, new Vector2(20.089f, -25.517f), left: PolusVent.Ids.OutsideAdmin, right: PolusVent.Ids.Lava),
new PolusVent(this, PolusVent.Ids.Laboratory, new Vector2(32.963f, -9.526f), right: PolusVent.Ids.Lava),
new PolusVent(this, PolusVent.Ids.Lava, new Vector2(30.907f, -11.86f), left: PolusVent.Ids.Laboratory, right: PolusVent.Ids.Admin),
new PolusVent(this, PolusVent.Ids.Storage, new Vector2(22f, -12.19f), left: PolusVent.Ids.Communications, right: PolusVent.Ids.Office),
new PolusVent(this, PolusVent.Ids.RightStabilizer, new Vector2(24.02f, -8.39f), left: PolusVent.Ids.LeftStabilizer),
new PolusVent(this, PolusVent.Ids.LeftStabilizer, new Vector2(9.64f, -7.72f), left: PolusVent.Ids.RightStabilizer),
new PolusVent(this, PolusVent.Ids.OutsideAdmin, new Vector2(18.93f, -24.85f), right: PolusVent.Ids.Admin),
};

ConnectVents(PolusVent.Ids.Security, left: PolusVent.Ids.O2, right: PolusVent.Ids.Electrical);
ConnectVents(PolusVent.Ids.Electrical, left: PolusVent.Ids.O2, right: PolusVent.Ids.Security);
ConnectVents(PolusVent.Ids.O2, left: PolusVent.Ids.Electrical, right: PolusVent.Ids.Security);
ConnectVents(PolusVent.Ids.Communications, left: PolusVent.Ids.Storage, right: PolusVent.Ids.Office);
ConnectVents(PolusVent.Ids.Office, left: PolusVent.Ids.Communications, right: PolusVent.Ids.Storage);
ConnectVents(PolusVent.Ids.Admin, left: PolusVent.Ids.OutsideAdmin, right: PolusVent.Ids.Lava);
ConnectVents(PolusVent.Ids.Laboratory, right: PolusVent.Ids.Lava);
ConnectVents(PolusVent.Ids.Lava, left: PolusVent.Ids.Laboratory, right: PolusVent.Ids.Admin);
ConnectVents(PolusVent.Ids.Storage, left: PolusVent.Ids.Communications, right: PolusVent.Ids.Office);
ConnectVents(PolusVent.Ids.RightStabilizer, left: PolusVent.Ids.LeftStabilizer);
ConnectVents(PolusVent.Ids.LeftStabilizer, left: PolusVent.Ids.RightStabilizer);
ConnectVents(PolusVent.Ids.OutsideAdmin, right: PolusVent.Ids.Admin);
Vents = vents.ToDictionary(x => x.Id, x => x).AsReadOnly();
_vents = vents.ToDictionary(x => (int)x.Id, x => (IVent)x).AsReadOnly();
}

public override IReadOnlyDictionary<int, Vent> Vents { get; }
public IReadOnlyDictionary<PolusVent.Ids, PolusVent> Vents { get; }

private void ConnectVents(PolusVent.Ids vent, PolusVent.Ids? left = null, PolusVent.Ids? center = null, PolusVent.Ids? right = null)
{
ConnectVents((int)vent, (int?)left, (int?)center, (int?)right);
}
IReadOnlyDictionary<int, IVent> IMapData.Vents => _vents;
}
}
Loading

0 comments on commit 1d66f07

Please sign in to comment.