-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use [Record] attribute for refresh/warp data objects and remove inter…
…faces
- Loading branch information
1 parent
c1249b6
commit 28edf4c
Showing
6 changed files
with
41 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,23 @@ | ||
using EOLib.Net.Translators; | ||
using Amadevus.RecordGenerator; | ||
using EOLib.Net.Translators; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Map | ||
{ | ||
public class RefreshReplyData : IRefreshReplyData | ||
[Record] | ||
public sealed partial class RefreshReplyData : ITranslatedData | ||
{ | ||
public IReadOnlyList<Character.Character> Characters { get; private set; } | ||
public IReadOnlyList<Character.Character> Characters { get; } | ||
|
||
public IReadOnlyList<NPC.NPC> NPCs { get; private set; } | ||
public IReadOnlyList<NPC.NPC> NPCs { get; } | ||
|
||
public IReadOnlyList<MapItem> Items { get; private set; } | ||
public IReadOnlyList<MapItem> Items { get; } | ||
|
||
public RefreshReplyData() | ||
{ | ||
Characters = new List<Character.Character>(); | ||
NPCs = new List<NPC.NPC>(); | ||
Items = new List<MapItem>(); | ||
} | ||
|
||
public IRefreshReplyData WithCharacters(IEnumerable<Character.Character> characters) | ||
{ | ||
var newData = MakeCopy(this); | ||
newData.Characters = new List<Character.Character>(characters); | ||
return newData; | ||
} | ||
|
||
public IRefreshReplyData WithNPCs(IEnumerable<NPC.NPC> npcs) | ||
{ | ||
var newData = MakeCopy(this); | ||
newData.NPCs = new List<NPC.NPC>(npcs); | ||
return newData; | ||
} | ||
|
||
public IRefreshReplyData WithItems(IEnumerable<MapItem> items) | ||
{ | ||
var newData = MakeCopy(this); | ||
newData.Items = new List<MapItem>(items); | ||
return newData; | ||
} | ||
|
||
private static RefreshReplyData MakeCopy(IRefreshReplyData source) | ||
{ | ||
return new RefreshReplyData | ||
{ | ||
Characters = new List<Character.Character>(source.Characters), | ||
NPCs = new List<NPC.NPC>(source.NPCs), | ||
Items = new List<MapItem>(source.Items) | ||
}; | ||
} | ||
} | ||
|
||
public interface IRefreshReplyData : ITranslatedData | ||
{ | ||
IReadOnlyList<Character.Character> Characters { get; } | ||
|
||
IReadOnlyList<NPC.NPC> NPCs { get; } | ||
|
||
IReadOnlyList<MapItem> Items { get; } | ||
|
||
IRefreshReplyData WithCharacters(IEnumerable<Character.Character> characters); | ||
|
||
IRefreshReplyData WithNPCs(IEnumerable<NPC.NPC> npcs); | ||
|
||
IRefreshReplyData WithItems(IEnumerable<MapItem> items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,27 @@ | ||
using EOLib.Domain.Character; | ||
using Amadevus.RecordGenerator; | ||
using EOLib.Net.Translators; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Map | ||
{ | ||
public class WarpAgreePacketData : IWarpAgreePacketData | ||
[Record] | ||
public sealed partial class WarpAgreePacketData : ITranslatedData | ||
{ | ||
public short MapID { get; private set; } | ||
public short MapID { get; } | ||
|
||
public WarpAnimation WarpAnimation { get; private set; } | ||
public WarpAnimation WarpAnimation { get; } | ||
|
||
public IReadOnlyList<Character.Character> Characters { get; private set; } | ||
public IReadOnlyList<Character.Character> Characters { get; } | ||
|
||
public IReadOnlyList<NPC.NPC> NPCs { get; private set; } | ||
public IReadOnlyList<NPC.NPC> NPCs { get; } | ||
|
||
public IReadOnlyList<MapItem> Items { get; private set; } | ||
public IReadOnlyList<MapItem> Items { get; } | ||
|
||
public WarpAgreePacketData() | ||
{ | ||
Characters = new List<Character.Character>(); | ||
NPCs = new List<NPC.NPC>(); | ||
Items = new List<MapItem>(); | ||
} | ||
|
||
public IWarpAgreePacketData WithMapID(short mapID) | ||
{ | ||
var newData = MakeCopy(this); | ||
newData.MapID = mapID; | ||
return newData; | ||
} | ||
|
||
public IWarpAgreePacketData WithWarpAnimation(WarpAnimation warpAnimation) | ||
{ | ||
var newData = MakeCopy(this); | ||
newData.WarpAnimation = warpAnimation; | ||
return newData; | ||
} | ||
|
||
public IWarpAgreePacketData WithCharacters(IEnumerable<Character.Character> characters) | ||
{ | ||
var newData = MakeCopy(this); | ||
newData.Characters = new List<Character.Character>(characters); | ||
return newData; | ||
} | ||
|
||
public IWarpAgreePacketData WithNPCs(IEnumerable<NPC.NPC> npcs) | ||
{ | ||
var newData = MakeCopy(this); | ||
newData.NPCs = new List<NPC.NPC>(npcs); | ||
return newData; | ||
} | ||
|
||
public IWarpAgreePacketData WithItems(IEnumerable<MapItem> items) | ||
{ | ||
var newData = MakeCopy(this); | ||
newData.Items = new List<MapItem>(items); | ||
return newData; | ||
} | ||
|
||
private static WarpAgreePacketData MakeCopy(IWarpAgreePacketData source) | ||
{ | ||
return new WarpAgreePacketData | ||
{ | ||
MapID = source.MapID, | ||
WarpAnimation = source.WarpAnimation, | ||
Characters = new List<Character.Character>(source.Characters), | ||
NPCs = new List<NPC.NPC>(source.NPCs), | ||
Items = new List<MapItem>(source.Items) | ||
}; | ||
} | ||
} | ||
|
||
public interface IWarpAgreePacketData : ITranslatedData | ||
{ | ||
short MapID { get; } | ||
|
||
WarpAnimation WarpAnimation { get; } | ||
|
||
IReadOnlyList<Character.Character> Characters { get; } | ||
|
||
IReadOnlyList<NPC.NPC> NPCs { get; } | ||
|
||
IReadOnlyList<MapItem> Items { get; } | ||
|
||
IWarpAgreePacketData WithMapID(short mapID); | ||
|
||
IWarpAgreePacketData WithWarpAnimation(WarpAnimation warpAnimation); | ||
|
||
IWarpAgreePacketData WithCharacters(IEnumerable<Character.Character> characters); | ||
|
||
IWarpAgreePacketData WithNPCs(IEnumerable<NPC.NPC> npcs); | ||
|
||
IWarpAgreePacketData WithItems(IEnumerable<MapItem> items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Map; | ||
using System.Linq; | ||
|
||
namespace EOLib.Net.Translators | ||
{ | ||
[AutoMappedType] | ||
public class RefreshReplyPacketTranslator : MapStatePacketTranslator<IRefreshReplyData> | ||
public class RefreshReplyPacketTranslator : MapStatePacketTranslator<RefreshReplyData> | ||
{ | ||
public RefreshReplyPacketTranslator(ICharacterFromPacketFactory characterFromPacketFactory) | ||
: base(characterFromPacketFactory) { } | ||
|
||
public override IRefreshReplyData TranslatePacket(IPacket packet) | ||
public override RefreshReplyData TranslatePacket(IPacket packet) | ||
{ | ||
var characters = GetCharacters(packet); | ||
var npcs = GetNPCs(packet); | ||
var items = GetMapItems(packet); | ||
|
||
IRefreshReplyData data = new RefreshReplyData(); | ||
|
||
return data.WithCharacters(characters) | ||
.WithNPCs(npcs) | ||
.WithItems(items); | ||
return new RefreshReplyData.Builder | ||
{ | ||
Characters = characters.ToList(), | ||
NPCs = npcs.ToList(), | ||
Items = items.ToList(), | ||
}.ToImmutable(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters