Skip to content

Commit

Permalink
Fix compiler errors
Browse files Browse the repository at this point in the history
  • Loading branch information
KCFindstr committed Jun 25, 2022
1 parent 4666b08 commit d0d75ac
Show file tree
Hide file tree
Showing 121 changed files with 558 additions and 292 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"editor.tabSize": 2,
"editor.tabSize": 4,
"editor.formatOnSave": true,
"omnisharp.enableImportCompletion": true,
"omnisharp.organizeImportsOnFormat": true,
Expand Down
17 changes: 17 additions & 0 deletions Actions/AgariAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using RabiRiichi.Core;
using RabiRiichi.Events.InGame;
using RabiRiichi.Generated.Actions;
using RabiRiichi.Patterns;

namespace RabiRiichi.Actions {
Expand All @@ -11,6 +12,10 @@ public AgariAction(int playerId, AgariInfo agariInfo, GameTile incoming, int pri
this.incoming = incoming;
priority = ActionPriority.Ron + priorityDelta;
}

public virtual AgariActionMsg ToProto() {
return new AgariActionMsg();
}
}

public class RonAction : AgariAction {
Expand All @@ -19,6 +24,12 @@ public RonAction(AgariInfo agariInfo, GameTile incoming, int priorityDelta = 0)
: base(agariInfo.playerId, agariInfo, incoming, priorityDelta) { }
public RonAction(int playerId, ScoreStorage scores, GameTile incoming, int priorityDelta = 0)
: base(playerId, new AgariInfo(playerId, scores), incoming, priorityDelta) { }

public override AgariActionMsg ToProto() {
var ret = base.ToProto();
ret.Type = AgariType.Ron;
return ret;
}
}

public class TsumoAction : AgariAction {
Expand All @@ -27,5 +38,11 @@ public TsumoAction(AgariInfo agariInfo, GameTile incoming, int priorityDelta = 0
: base(agariInfo.playerId, agariInfo, incoming, priorityDelta) { }
public TsumoAction(int playerId, ScoreStorage scores, GameTile incoming, int priorityDelta = 0)
: this(new AgariInfo(playerId, scores), incoming, priorityDelta) { }

public override AgariActionMsg ToProto() {
var ret = base.ToProto();
ret.Type = AgariType.Tsumo;
return ret;
}
}
}
10 changes: 9 additions & 1 deletion Actions/ChiiAction.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
using RabiRiichi.Core;
using RabiRiichi.Generated.Actions;
using System.Collections.Generic;

using System.Linq;

namespace RabiRiichi.Actions {
public class ChiiAction : ChooseTilesAction {
public override string name => "chii";
public ChiiAction(int playerId, List<List<GameTile>> tiles, int priorityDelta = 0) : base(playerId, tiles) {
priority = ActionPriority.Chii + priorityDelta;
}

public ChiiActionMsg ToProto() {
var ret = new ChiiActionMsg();
ret.TileGroups.AddRange(options.Select(o =>
MenLike.From(((ChooseTilesActionOption)o).tiles).ToProto()));
return ret;
}
}
}
10 changes: 9 additions & 1 deletion Actions/KanAction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using RabiRiichi.Communication;
using RabiRiichi.Core;
using RabiRiichi.Generated.Actions;
using System.Collections.Generic;

using System.Linq;

namespace RabiRiichi.Actions {
[RabiPrivate]
Expand All @@ -10,5 +11,12 @@ public class KanAction : ChooseTilesAction {
public KanAction(int playerId, List<List<GameTile>> tiles, int priorityDelta = 0) : base(playerId, tiles) {
priority = ActionPriority.Kan + priorityDelta;
}

public KanActionMsg ToProto() {
var ret = new KanActionMsg();
ret.TileGroups.AddRange(options.Select(o =>
MenLike.From(((ChooseTilesActionOption)o).tiles).ToProto()));
return ret;
}
}
}
10 changes: 9 additions & 1 deletion Actions/PlayTileAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using RabiRiichi.Core;
using RabiRiichi.Generated.Actions;
using System.Collections.Generic;

using System.Linq;

namespace RabiRiichi.Actions {
public class PlayTileAction : ChooseTileAction {
Expand All @@ -14,5 +15,12 @@ public PlayTileAction(int playerId, List<GameTile> tiles, GameTile defaultTile,
response = index;
}
}

public PlayTileActionMsg ToProto() {
var ret = new PlayTileActionMsg();
ret.Tiles.AddRange(options.Select(
o => ((ChooseTileActionOption)o).tile.ToProto()));
return ret;
}
}
}
1 change: 1 addition & 0 deletions Actions/PlayerAction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RabiRiichi.Communication;
using RabiRiichi.Generated.Actions;
using RabiRiichi.Util;
using System;
using System.Text.Json;
Expand Down
10 changes: 9 additions & 1 deletion Actions/PonAction.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
using RabiRiichi.Core;
using RabiRiichi.Generated.Actions;
using System.Collections.Generic;

using System.Linq;

namespace RabiRiichi.Actions {
public class PonAction : ChooseTilesAction {
public override string name => "pon";
public PonAction(int playerId, List<List<GameTile>> tiles, int priorityDelta = 0) : base(playerId, tiles) {
priority = ActionPriority.Pon + priorityDelta;
}

public PonActionMsg ToProto() {
var ret = new PonActionMsg();
ret.TileGroups.AddRange(options.Select(o =>
MenLike.From(((ChooseTilesActionOption)o).tiles).ToProto()));
return ret;
}
}
}
1 change: 1 addition & 0 deletions Actions/Resolver/KanResolver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RabiRiichi.Core;
using RabiRiichi.Generated.Core;
using System.Collections.Generic;
using System.Linq;

Expand Down
10 changes: 9 additions & 1 deletion Actions/RiichiAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using RabiRiichi.Core;
using RabiRiichi.Generated.Actions;
using System.Collections.Generic;

using System.Linq;

namespace RabiRiichi.Actions {

Expand All @@ -10,5 +11,12 @@ public class RiichiAction : PlayTileAction {
public RiichiAction(int playerId, List<GameTile> tiles, GameTile defaultTile, int priorityDelta = 0) : base(playerId, tiles, defaultTile) {
priority = ActionPriority.Riichi + priorityDelta;
}

public new RiichiActionMsg ToProto() {
var ret = new RiichiActionMsg();
ret.Tiles.AddRange(options.Select(
o => ((ChooseTileActionOption)o).tile.ToProto()));
return ret;
}
}
}
8 changes: 7 additions & 1 deletion Actions/RyuukyokuAction.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using RabiRiichi.Communication;
using RabiRiichi.Events.InGame;

using RabiRiichi.Generated.Actions;

namespace RabiRiichi.Actions {

Expand All @@ -12,5 +12,11 @@ public RyuukyokuAction(int playerId, RyuukyokuEvent ev, int priorityDelta = 0) :
this.ev = ev;
this.priority = ActionPriority.Ryuukyoku + priorityDelta;
}

public RyuukyokuActionMsg ToProto() {
return new RyuukyokuActionMsg {
Reason = reason
};
}
}
}
9 changes: 9 additions & 0 deletions Actions/SinglePlayerInquiry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using RabiRiichi.Communication;
using RabiRiichi.Communication.Proto;
using RabiRiichi.Generated.Actions;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace RabiRiichi.Actions {
[RabiMessage]
Expand Down Expand Up @@ -66,5 +69,11 @@ public bool OnResponse(int index, string response) {
hasResponded = true;
return true;
}

public SinglePlayerInquiryMsg ToProto() {
var ret = new SinglePlayerInquiryMsg();
ret.Actions.AddRange(actions.Select(action => ProtoConverters.ToProto(action)));
return ret;
}
}
}
6 changes: 6 additions & 0 deletions Actions/SkipAction.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
using RabiRiichi.Generated.Actions;

namespace RabiRiichi.Actions {
public class SkipAction : ConfirmAction {
public override string name => "skip";

public SkipAction(int playerId, int priorityDelta = 0) : base(playerId) {
priority = ActionPriority.Skip + priorityDelta;
}

public virtual SkipActionMsg ToProto() {
return new SkipActionMsg();
}
}
}
92 changes: 92 additions & 0 deletions Communication/Proto/Converters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using RabiRiichi.Actions;
using RabiRiichi.Events;
using RabiRiichi.Events.InGame;
using RabiRiichi.Generated.Actions;
using RabiRiichi.Generated.Events;
using System;

namespace RabiRiichi.Communication.Proto {
public static class ProtoConverters {
public static PlayerActionMsg ToProto(IPlayerAction action) {
var ret = new PlayerActionMsg();
if (action is AgariAction agariAction) {
ret.AgariAction = agariAction.ToProto();
} else if (action is ChiiAction chiiAction) {
ret.ChiiAction = chiiAction.ToProto();
} else if (action is PonAction ponAction) {
ret.PonAction = ponAction.ToProto();
} else if (action is KanAction kanAction) {
ret.KanAction = kanAction.ToProto();
} else if (action is RiichiAction riichiAction) {
ret.RiichiAction = riichiAction.ToProto();
} else if (action is RyuukyokuAction ryuukyokuAction) {
ret.RyuukyokuAction = ryuukyokuAction.ToProto();
} else if (action is PlayTileAction playTileAction) {
ret.PlayTileAction = playTileAction.ToProto();
} else if (action is SkipAction skipAction) {
ret.SkipAction = skipAction.ToProto();
} else {
throw new ArgumentException($"Unknown action type: {action.GetType()}");
}
return ret;
}

public static EventMsg ToProto(EventBase ev, int playerId) {
var ret = new EventMsg();
if (ev is AddKanEvent addKanEvent) {
ret.AddKanEvent = addKanEvent.ToProto();
} else if (ev is AddTileEvent addTileEvent) {
ret.AddTileEvent = addTileEvent.ToProto(playerId);
} else if (ev is AgariEvent agariEvent) {
ret.AgariEvent = agariEvent.ToProto();
} else if (ev is ApplyScoreEvent applyScoreEvent) {
ret.ApplyScoreEvent = applyScoreEvent.ToProto();
} else if (ev is BeginGameEvent beginGameEvent) {
ret.BeginGameEvent = beginGameEvent.ToProto();
} else if (ev is CalcScoreEvent calcScoreEvent) {
ret.CalcScoreEvent = calcScoreEvent.ToProto();
} else if (ev is ClaimTileEvent claimTileEvent) {
ret.ClaimTileEvent = claimTileEvent.ToProto();
} else if (ev is ConcludeGameEvent concludeGameEvent) {
ret.ConcludeGameEvent = concludeGameEvent.ToProto();
} else if (ev is DealerFirstTurnEvent dealerFirstTurnEvent) {
ret.DealerFirstTurnEvent = dealerFirstTurnEvent.ToProto(playerId);
} else if (ev is DealHandEvent dealHandEvent) {
ret.DealHandEvent = dealHandEvent.ToProto();
} else if (ev is DiscardTileEvent discardTileEvent) {
ret.DiscardTileEvent = discardTileEvent.ToProto(playerId);
} else if (ev is DrawTileEvent drawTileEvent) {
ret.DrawTileEvent = drawTileEvent.ToProto(playerId);
} else if (ev is IncreaseJunEvent increaseJunEvent) {
ret.IncreaseJunEvent = increaseJunEvent.ToProto();
} else if (ev is KanEvent kanEvent) {
ret.KanEvent = kanEvent.ToProto();
} else if (ev is LateClaimTileEvent lateClaimTileEvent) {
ret.LateClaimTileEvent = lateClaimTileEvent.ToProto();
} else if (ev is NextGameEvent nextGameEvent) {
ret.NextGameEvent = nextGameEvent.ToProto();
} else if (ev is NextPlayerEvent nextPlayerEvent) {
ret.NextPlayerEvent = nextPlayerEvent.ToProto();
} else if (ev is RevealDoraEvent revealDoraEvent) {
ret.RevealDoraEvent = revealDoraEvent.ToProto();
} else if (ev is RyuukyokuEvent ryuukyokuEvent) {
ret.RyuukyokuEvent = ryuukyokuEvent.ToProto();
} else if (ev is SetFuritenEvent setFuritenEvent) {
ret.SetFuritenEvent = setFuritenEvent.ToProto();
} else if (ev is SetIppatsuEvent setIppatsuEvent) {
ret.SetIppatsuEvent = setIppatsuEvent.ToProto();
} else if (ev is SetMenzenEvent setMenzenEvent) {
ret.SetMenzenEvent = setMenzenEvent.ToProto();
} else if (ev is SetRiichiEvent setRiichiEvent) {
ret.SetRiichiEvent = setRiichiEvent.ToProto();
} else if (ev is StopGameEvent stopGameEvent) {
ret.StopGameEvent = stopGameEvent.ToProto();
} else if (ev is SyncGameStateEvent syncGameStateEvent) {
ret.SyncGameStateEvent = syncGameStateEvent.ToProto(playerId);
} else {
throw new ArgumentException($"Unknown event type: {ev.GetType()}");
}
return ret;
}
}
}
2 changes: 2 additions & 0 deletions Core/Wall.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using RabiRiichi.Core.Config;
using RabiRiichi.Generated.Core;
using RabiRiichi.Generated.Patterns;
using RabiRiichi.Util;
using System;
using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion Events/InGame/ConcludeGameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ConcludeGameEvent(EventBase parent, ConcludeGameReason reason, int[] tenp
this.tenpaiPlayers = tenpaiPlayers;
}

public ConcludeGameEventMsg ToProto(int playerId) {
public ConcludeGameEventMsg ToProto() {
return new ConcludeGameEventMsg {
Doras = doras.ToString(),
Uradoras = uradoras.ToString(),
Expand Down
1 change: 1 addition & 0 deletions Events/InGame/Listener/CalcScoreListener.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using RabiRiichi.Core;
using RabiRiichi.Core.Config;
using RabiRiichi.Generated.Events.InGame;
using RabiRiichi.Util;
using System.Collections.Generic;
using System.Linq;
Expand Down
1 change: 1 addition & 0 deletions Events/InGame/Listener/ClaimTileListener.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RabiRiichi.Core;
using RabiRiichi.Generated.Core;
using System.Threading.Tasks;

namespace RabiRiichi.Events.InGame.Listener {
Expand Down
1 change: 1 addition & 0 deletions Events/InGame/Listener/DealerFirstTurnListener.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using RabiRiichi.Actions.Resolver;
using RabiRiichi.Core;
using RabiRiichi.Generated.Core;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand Down
1 change: 1 addition & 0 deletions Events/InGame/Listener/DrawTileListener.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using RabiRiichi.Actions;
using RabiRiichi.Actions.Resolver;
using RabiRiichi.Core;
using RabiRiichi.Generated.Core;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand Down
1 change: 1 addition & 0 deletions Events/InGame/Listener/NextPlayerListener.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RabiRiichi.Core;
using RabiRiichi.Generated.Core;
using System.Threading.Tasks;

namespace RabiRiichi.Events.InGame.Listener {
Expand Down
1 change: 1 addition & 0 deletions Events/InGame/Listener/RyuukyokuListener.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using RabiRiichi.Core;
using RabiRiichi.Core.Config;
using RabiRiichi.Generated.Events.InGame;
using RabiRiichi.Util;
using System;
using System.Linq;
Expand Down
Loading

0 comments on commit d0d75ac

Please sign in to comment.