Skip to content

Commit

Permalink
Added fixes from code review
Browse files Browse the repository at this point in the history
Changed arrays to accept any IEnumerable or their type
  • Loading branch information
ggggg committed Oct 24, 2020
1 parent dd68ab1 commit 4718c0b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/BP-CoreLib/OptionMenu/ActionLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,41 @@ public ActionLabel(string name, Action<ShPlayer, string> action)

internal class OptionMenu
{
public static Dictionary<string, OptionMenu> Menus = new Dictionary<string, OptionMenu>();

private readonly string _title;
public Dictionary<string, ActionLabel> Actions { get; private set; }
private readonly LabelID[] _options;
private readonly string _menuId;

public OptionMenu(string title, LabelID[] labels, ActionLabel[] actions)
public OptionMenu(string title, IEnumerable<LabelID> labels, IEnumerable<ActionLabel> actions)
{
this._title = title;
this._options = labels;
this.menuId = Guid.NewGuid().ToString();
Menus.Add(menuId, this);
_title = title;
_options = labels.ToArray();
_menuId = Guid.NewGuid().ToString();
Menus.Add(_menuId, this);
Actions = new Dictionary<string, ActionLabel>();
foreach (var action in actions)
{
Actions.Add(Guid.NewGuid().ToString(), action);
}
}

public static Dictionary<string, OptionMenu> Menus = new Dictionary<string, OptionMenu>();

internal void SendToPlayer(ShPlayer player)
{
var actions = new LabelID[this.Actions.Count];
int i = 0;
foreach (var action in this.Actions)
var actions = new LabelID[Actions.Count];
for (var i = 0; i < actions.Length; i++)
{
var action = Actions.ElementAt(i);
actions[i++] = new LabelID(action.Value.Name, action.Key);
}
player.svPlayer.SendOptionMenu(_title, player.ID, menuId, _options, actions);
player.svPlayer.SendOptionMenu(_title, player.ID, _menuId, _options, actions);
}
}

public static class Extension
{
public static void SendOptionMenu(this ShPlayer player, string title, LabelID[] labels, ActionLabel[] actions)
public static void SendOptionMenu(this ShPlayer player, string title, IEnumerable<LabelID> labels, IEnumerable<ActionLabel> actions)
{
(new OptionMenu(title, labels, actions)).SendToPlayer(player);
}
Expand All @@ -80,4 +80,4 @@ public void OnOptionAction(ShPlayer player, int targetID, string menuID, string
menu.Actions[actionID].Action.Invoke(player, optionID);
}
}
}
}

0 comments on commit 4718c0b

Please sign in to comment.