Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Not Alone
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mamadou Saliou DIALLO
Not Alone
Commits
a669937e
Commit
a669937e
authored
Dec 27, 2020
by
Mamadou Saliou DIALLO
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:handle multiple player service
parent
0a730747
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
5 deletions
+32
-5
not-alone-player/src/handler/client-service-handler.ts
not-alone-player/src/handler/client-service-handler.ts
+32
-5
No files found.
not-alone-player/src/handler/client-service-handler.ts
View file @
a669937e
import
{
ITPlayer
}
from
'
src/codegen/common/TPlayer
'
;
import
{
JoinRequest
}
from
'
./../codegen/common/JoinRequest
'
;
import
{
GameProxy
}
from
'
./../thrift/game-proxy
'
;
import
{
ICard
,
IJoinRequest
,
IPhase
,
IPhaseArgs
,
IPlace
,
IResponseArgs
,
IToken
,
TPlayer
}
from
'
../codegen/common
'
;
...
...
@@ -5,7 +6,7 @@ import { IHandler } from '../codegen/common/GameService';
import
{
PlayerService
}
from
'
../player/player-service
'
;
export
class
ClientServiceHandler
<
Context
>
implements
IHandler
<
Context
>
{
private
service
:
PlayerService
[]
=
[];
private
service
s
:
PlayerService
[];
private
proxy
:
GameProxy
;
private
PROXY_CONFIG
=
{
hostName
:
'
localhost
'
,
...
...
@@ -13,24 +14,50 @@ export class ClientServiceHandler<Context> implements IHandler<Context> {
}
constructor
()
{
this
.
proxy
=
new
GameProxy
(
this
.
PROXY_CONFIG
)
this
.
proxy
=
new
GameProxy
(
this
.
PROXY_CONFIG
);
this
.
services
=
[];
}
createGame
(
creator
:
TPlayer
,
numberOfPlayers
:
number
,
context
?:
Context
):
number
|
Promise
<
number
>
{
this
.
addPlayerService
(
creator
);
return
this
.
proxy
.
createGame
(
creator
,
numberOfPlayers
);
}
/**
* Create new PlayerService and add it to the playerService list.
* @param player player to add
*/
private
addPlayerService
(
player
:
TPlayer
):
void
{
const
playerService
:
PlayerService
=
new
PlayerService
(
player
);
this
.
services
.
push
(
playerService
);
}
/**
* Convert ITPlayer object to TPlayer.
* @param iplayer ITPlayer instance to convert
*/
private
ITPlayerToTPlayer
(
iplayer
:
ITPlayer
):
TPlayer
{
return
new
TPlayer
(
iplayer
)
}
join
(
request
:
IJoinRequest
,
context
?:
Context
):
number
|
Promise
<
number
>
{
const
joinRequest
=
new
JoinRequest
({
gameId
:
request
.
gameId
,
player
:
request
.
player
})
return
this
.
proxy
.
join
(
joinRequest
);
return
this
.
proxy
.
join
(
joinRequest
).
then
(
gameID
=>
{
if
(
gameID
>
0
)
{
if
(
request
.
player
!=
undefined
)
{
this
.
addPlayerService
(
this
.
ITPlayerToTPlayer
(
request
.
player
))
}
}
return
gameID
;
});
}
nextPhase
(
phase
:
IPhase
,
context
?:
Context
):
IPhaseArgs
|
Promise
<
IPhaseArgs
>
{
return
this
.
nextPhase
(
phase
);
return
this
.
proxy
.
nextPhase
(
phase
);
}
resits
(
hunted
:
any
,
context
?:
Context
):
IResponseArgs
|
Promise
<
IResponseArgs
>
{
return
this
.
resits
(
hunted
);
return
this
.
proxy
.
resits
(
hunted
);
}
letGo
(
hunted
:
any
,
context
?:
Context
):
IResponseArgs
|
Promise
<
IResponseArgs
>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment