Skip to content

Commit

Permalink
Merge pull request #11 from DeltaZen/adb/update-to-changes-in-webxdc-…
Browse files Browse the repository at this point in the history
…notify-api

update to changes in webxdc notify API
  • Loading branch information
adbenitez authored Nov 26, 2024
2 parents 4ed9437 + dddf517 commit cf57a8a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function getSummary() {
summary = "Game over, it is a draw! 🤝";
} else {
// game still on
summary = `${name} it's your turn`;
summary = `Turn: ${name}`;
if (state.game.inCheck()) {
summary += " (in check!)";
}
Expand Down
11 changes: 6 additions & 5 deletions src/components/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@ function onDrop(source, target) {
};
if (state.game.isGameOver()) {
update.info = update.summary;
update.notify = ["all"];
update.notify = { "*": update.info };
} else {
update.notify = [
state.game.turn() === "w" ? state.whiteAddr : state.blackAddr,
];
const info =
"It's your turn" + (state.game.inCheck() ? " (in check!)" : "");
const addr = state.game.turn() === "w" ? state.whiteAddr : state.blackAddr;
update.notify = { [addr]: info };
}
window.webxdc.sendUpdate(update, "");
}
Expand Down Expand Up @@ -255,7 +256,7 @@ function surrender() {
payload: { surrenderAddr: window.webxdc.selfAddr },
info: summary,
summary,
notify: ["all"],
notify: { "*": summary },
};
window.webxdc.sendUpdate(update, "");
}
4 changes: 2 additions & 2 deletions src/components/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function joinGame() {
payload: { whiteAddr: addr, whiteName: name },
info,
summary: info,
notify: ["all"],
notify: { "*": info },
};
window.webxdc.sendUpdate(update, "");
} else if (!state.blackAddr && state.whiteAddr !== addr) {
Expand All @@ -74,7 +74,7 @@ function joinGame() {
name,
},
info,
notify: ["all"],
notify: { [state.whiteAddr]: info },
};
window.webxdc.sendUpdate(update, "");
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ function receiveUpdate(update) {
blackName: state.blackName,
},
info,
summary: info,
notify: ["all"],
summary: getSummary(),
notify: { "*": info },
};
window.webxdc.sendUpdate(update, "");
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Webxdc, SendingStatusUpdate } from "@webxdc/types";

interface SendingUpdate extends SendingStatusUpdate<any> {
notify?: string[];
notify?: { [key: string]: string };
}

declare global {
Expand Down

0 comments on commit cf57a8a

Please sign in to comment.