fix: Restore move error messages appearing

This commit is contained in:
Joel Therrien 2024-12-26 10:34:17 -08:00
parent 40a03fb4ea
commit 1d363204e2
2 changed files with 22 additions and 14 deletions

View file

@ -134,7 +134,7 @@ export function Game(props: {
})
.catch((error) => {
console.error({error});
//logDispatch(<div>{error}</div>);
logDispatch(<div>{error}</div>);
});
}
@ -511,7 +511,7 @@ export function Game(props: {
})
}}/>);
} else {
//logDispatch(<div>{error}</div>);
logDispatch(<div>{error}</div>);
}
@ -539,7 +539,7 @@ export function Game(props: {
})
.catch((error) => {
console.error({error});
//logDispatch(<div>{error}</div>);
logDispatch(<div>{error}</div>);
});
}
}}>Pass

View file

@ -77,6 +77,7 @@ export type ClientToServerMessage = {
interface PromiseInput {
resolve: (value: GameEvent) => void
reject: (error: any) => void
type: string // recorded for debug purposes
}
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) {
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 = {
resolve: resolve,
reject: reject
};
this.currentPromiseInput = newPromise;
}
add_to_dictionary(word: string): Promise<APIState> {
return new Promise((resolve, reject) => {
this.register_promise(resolve, reject);
this.register_promise(resolve, reject, "AddToDictionary");
let event: ClientToServerMessage = {
type: "GameMove",
move: {
@ -140,7 +148,7 @@ export class WSAPI implements API{
exchange(selection: Array<boolean>): Promise<APIState> {
return new Promise((resolve, reject) => {
this.register_promise(resolve, reject);
this.register_promise(resolve, reject, "Exchange");
let event: ClientToServerMessage = {
type: "GameMove",
move: {
@ -156,7 +164,7 @@ export class WSAPI implements API{
load(wait: boolean): Promise<APIState> {
return new Promise((resolve, reject) => {
this.register_promise(resolve, reject);
this.register_promise(resolve, reject, `Load with wait=${wait}`);
if(!wait) {
let event: ClientToServerMessage = {
type: "Load"
@ -170,7 +178,7 @@ export class WSAPI implements API{
pass(): Promise<APIState> {
return new Promise((resolve, reject) => {
this.register_promise(resolve, reject);
this.register_promise(resolve, reject, "Pass");
let event: ClientToServerMessage = {
type: "GameMove",
move: {
@ -185,7 +193,7 @@ export class WSAPI implements API{
play(tiles: Array<PlayedTile>, commit: boolean): Promise<APIState> {
return new Promise((resolve, reject) => {
this.register_promise(resolve, reject);
this.register_promise(resolve, reject, "Play");
let event: ClientToServerMessage = {
type: "GameMove",
move: {