Multiplayer #1
2 changed files with 22 additions and 14 deletions
|
@ -134,7 +134,7 @@ export function Game(props: {
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error({error});
|
console.error({error});
|
||||||
//logDispatch(<div>{error}</div>);
|
logDispatch(<div>{error}</div>);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ export function Game(props: {
|
||||||
})
|
})
|
||||||
}}/>);
|
}}/>);
|
||||||
} else {
|
} else {
|
||||||
//logDispatch(<div>{error}</div>);
|
logDispatch(<div>{error}</div>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -539,7 +539,7 @@ export function Game(props: {
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error({error});
|
console.error({error});
|
||||||
//logDispatch(<div>{error}</div>);
|
logDispatch(<div>{error}</div>);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}>Pass
|
}}>Pass
|
||||||
|
|
|
@ -77,6 +77,7 @@ export type ClientToServerMessage = {
|
||||||
interface PromiseInput {
|
interface PromiseInput {
|
||||||
resolve: (value: GameEvent) => void
|
resolve: (value: GameEvent) => void
|
||||||
reject: (error: any) => void
|
reject: (error: any) => void
|
||||||
|
type: string // recorded for debug purposes
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WSAPI implements API{
|
export class WSAPI implements API{
|
||||||
|
@ -110,20 +111,27 @@ export class WSAPI implements API{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private register_promise(resolve: (value: GameEvent) => void, reject: (value: any) => void) {
|
private register_promise(resolve: (value: GameEvent) => void, reject: (value: any) => void, type: string) {
|
||||||
|
const newPromise = {
|
||||||
|
resolve: resolve,
|
||||||
|
reject: reject,
|
||||||
|
type: type,
|
||||||
|
};
|
||||||
|
|
||||||
if(this.currentPromiseInput != null) {
|
if(this.currentPromiseInput != null) {
|
||||||
console.error("We are setting a new promise before the current one has resolved")
|
console.error("We are setting a new promise before the current one has resolved")
|
||||||
this.currentPromiseInput.reject("New promise was registered");
|
console.error("Current promise: ", this.currentPromiseInput);
|
||||||
|
console.error("New promise: ", newPromise);
|
||||||
|
|
||||||
|
// Some of the rejects take statements from the server and log them; maybe don't send this to reject
|
||||||
|
//this.currentPromiseInput.reject("New promise was registered");
|
||||||
}
|
}
|
||||||
this.currentPromiseInput = {
|
this.currentPromiseInput = newPromise;
|
||||||
resolve: resolve,
|
|
||||||
reject: reject
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_to_dictionary(word: string): Promise<APIState> {
|
add_to_dictionary(word: string): Promise<APIState> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.register_promise(resolve, reject);
|
this.register_promise(resolve, reject, "AddToDictionary");
|
||||||
let event: ClientToServerMessage = {
|
let event: ClientToServerMessage = {
|
||||||
type: "GameMove",
|
type: "GameMove",
|
||||||
move: {
|
move: {
|
||||||
|
@ -140,7 +148,7 @@ export class WSAPI implements API{
|
||||||
|
|
||||||
exchange(selection: Array<boolean>): Promise<APIState> {
|
exchange(selection: Array<boolean>): Promise<APIState> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.register_promise(resolve, reject);
|
this.register_promise(resolve, reject, "Exchange");
|
||||||
let event: ClientToServerMessage = {
|
let event: ClientToServerMessage = {
|
||||||
type: "GameMove",
|
type: "GameMove",
|
||||||
move: {
|
move: {
|
||||||
|
@ -156,7 +164,7 @@ export class WSAPI implements API{
|
||||||
|
|
||||||
load(wait: boolean): Promise<APIState> {
|
load(wait: boolean): Promise<APIState> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.register_promise(resolve, reject);
|
this.register_promise(resolve, reject, `Load with wait=${wait}`);
|
||||||
if(!wait) {
|
if(!wait) {
|
||||||
let event: ClientToServerMessage = {
|
let event: ClientToServerMessage = {
|
||||||
type: "Load"
|
type: "Load"
|
||||||
|
@ -170,7 +178,7 @@ export class WSAPI implements API{
|
||||||
|
|
||||||
pass(): Promise<APIState> {
|
pass(): Promise<APIState> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.register_promise(resolve, reject);
|
this.register_promise(resolve, reject, "Pass");
|
||||||
let event: ClientToServerMessage = {
|
let event: ClientToServerMessage = {
|
||||||
type: "GameMove",
|
type: "GameMove",
|
||||||
move: {
|
move: {
|
||||||
|
@ -185,7 +193,7 @@ export class WSAPI implements API{
|
||||||
|
|
||||||
play(tiles: Array<PlayedTile>, commit: boolean): Promise<APIState> {
|
play(tiles: Array<PlayedTile>, commit: boolean): Promise<APIState> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.register_promise(resolve, reject);
|
this.register_promise(resolve, reject, "Play");
|
||||||
let event: ClientToServerMessage = {
|
let event: ClientToServerMessage = {
|
||||||
type: "GameMove",
|
type: "GameMove",
|
||||||
move: {
|
move: {
|
||||||
|
|
Loading…
Reference in a new issue