Can now somewhat reliably join a party

This commit is contained in:
watsonb8
2019-07-06 15:52:28 -04:00
parent 0d64c0732e
commit 2a3290defc
15 changed files with 140 additions and 125 deletions

View File

@ -27,7 +27,6 @@
<hs:HostSelector
Grid.Row="0"
Hostname="{Binding Hostname}"
Port="{Binding Port}"
HostCommand="{Binding HostCommand}"
JoinCommand="{Binding JoinCommand}"
IsVisible="{Binding IsSelectingHost}"/>

View File

@ -1,9 +1,7 @@
using System;
using System.Collections.ObjectModel;
using Aurora.Executors;
using Aurora.Design.Components.HostSelector;
using Aurora.Services;
using Aurora.Models;
using Aurora.Proto;
using Xamarin.Forms;
namespace Aurora.Design.Views.Party
@ -23,8 +21,6 @@ namespace Aurora.Design.Views.Party
private string _hostname;
private string _port;
private ObservableCollection<PartyMember> _members;
@ -66,12 +62,6 @@ namespace Aurora.Design.Views.Party
set { SetProperty(ref _hostname, value); }
}
public string Port
{
get { return _port; }
set { SetProperty(ref _port, value); }
}
#endregion Properties
@ -86,8 +76,10 @@ namespace Aurora.Design.Views.Party
private void OnJoinExecute()
{
_executor = BaseExecutor.CreateExecutor<ClientExecutor>();
Int32.TryParse(this.Port, out int intPort);
_executor.Initialize();
_executor.Connect(this.Hostname);
SetUpMembers();
State(PartyState.Connecting);
}
@ -98,24 +90,12 @@ namespace Aurora.Design.Views.Party
private void OnHostExecute()
{
Int32.TryParse(this.Port, out int intPort);
//Init gRPC server
ServerService.Instance.Initialize(this.Hostname, intPort);
//Instantiate and initialize all executors
_executor = BaseExecutor.CreateExecutor<HostExecutor>();
_executor.Initialize();
_executor.Connect(this.Hostname);
//start gRPC server
ServerService.Instance.Start();
_members = _executor.PartyMembers;
OnPropertyChanged("Members");
_executor.PartyMembers.CollectionChanged += (sender, e) =>
{
OnPropertyChanged("Members");
};
SetUpMembers();
//Change state
State(PartyState.Connecting);
@ -129,5 +109,18 @@ namespace Aurora.Design.Views.Party
#endregion Commands
private void SetUpMembers()
{
_members = _executor.PartyMembers;
OnPropertyChanged("Members");
_executor.PartyMembers.CollectionChanged += (sender, e) =>
{
if (_executor != null)
{
_members = _executor.PartyMembers;
}
OnPropertyChanged("Members");
};
}
}
}

View File

@ -9,10 +9,19 @@
<StackLayout
Orientation="Horizontal">
<Label
VerticalOptions="Center"
Text="Username"/>
<Entry
Text="{Binding Username}"/>
</StackLayout>
<StackLayout
Orientation="Horizontal">
<Label
VerticalOptions="Center"
Text="Default Port"/>
<Entry
Text="{Binding Port}"/>
</StackLayout>
</StackLayout>
</ContentView.Content>
</ContentView>

View File

@ -19,5 +19,16 @@ namespace Aurora.Design.Views.Profile
OnPropertyChanged("Username");
}
}
public string Port
{
get { return SettingsService.Instance.DefaultPort.ToString(); }
set
{
Int32.TryParse(value, out int portNum);
SettingsService.Instance.DefaultPort = portNum;
OnPropertyChanged("Port");
}
}
}
}