Add statusControl and roleControl to ChessBuilder
In ChessServer, the ChessBuilder function and instantiation now take parameters for the statusControl and roleControl elements. This change improves flexibility by allowing these controls to be passed in from the invoking context, rather than being statically defined within the ChessBuilder function.
This commit is contained in:
@@ -11,7 +11,9 @@
|
|||||||
window.addEventListener('DOMContentLoaded', async () => {
|
window.addEventListener('DOMContentLoaded', async () => {
|
||||||
var playerId = getUserId();
|
var playerId = getUserId();
|
||||||
var playerColor = await getPlayerColor(@Model.GameId);
|
var playerColor = await getPlayerColor(@Model.GameId);
|
||||||
let anduinChessBoard = new ChessBuilder(playerColor).default();
|
var statusControl = document.getElementById("status");
|
||||||
|
var roleControl = document.getElementById("role");
|
||||||
|
let anduinChessBoard = new ChessBuilder(playerColor, statusControl, roleControl).default();
|
||||||
anduinChessBoard.run(playerId, @Model.GameId);
|
anduinChessBoard.run(playerId, @Model.GameId);
|
||||||
|
|
||||||
document.body.addEventListener('pointerdown', (e) => {
|
document.body.addEventListener('pointerdown', (e) => {
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ import {
|
|||||||
* let chessBoard = new ChessBuilder().default();
|
* let chessBoard = new ChessBuilder().default();
|
||||||
* ```
|
* ```
|
||||||
* @param {string} color currently color, w or b
|
* @param {string} color currently color, w or b
|
||||||
|
* @param {HTMLElement} statusControl status control element
|
||||||
|
* @param {HTMLElement} roleControl role control element
|
||||||
*/
|
*/
|
||||||
function ChessBuilder(color) {
|
function ChessBuilder(color, statusControl, roleControl) {
|
||||||
this.onDragStart = undefined;
|
this.onDragStart = undefined;
|
||||||
this.onDrop = undefined;
|
this.onDrop = undefined;
|
||||||
this.onSnapEnd = undefined;
|
this.onSnapEnd = undefined;
|
||||||
@@ -31,8 +33,8 @@ function ChessBuilder(color) {
|
|||||||
anduinChessBoard.config.onDragStart = buildOnDragStart(anduinChessBoard);
|
anduinChessBoard.config.onDragStart = buildOnDragStart(anduinChessBoard);
|
||||||
anduinChessBoard.config.onDrop = buildOnDrop(anduinChessBoard);
|
anduinChessBoard.config.onDrop = buildOnDrop(anduinChessBoard);
|
||||||
anduinChessBoard.config.onSnapEnd = buildOnSnapEnd(anduinChessBoard);
|
anduinChessBoard.config.onSnapEnd = buildOnSnapEnd(anduinChessBoard);
|
||||||
anduinChessBoard.statusControl = document.getElementById("status");
|
anduinChessBoard.statusControl = statusControl;
|
||||||
anduinChessBoard.roleControl = document.getElementById("role");
|
anduinChessBoard.roleControl = roleControl;
|
||||||
|
|
||||||
return anduinChessBoard;
|
return anduinChessBoard;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user