diff --git a/dist/__scripts__/bot.js b/dist/__scripts__/bot.js index 3e71bf4..80914ed 100644 --- a/dist/__scripts__/bot.js +++ b/dist/__scripts__/bot.js @@ -4,13 +4,18 @@ const forgescript_1 = require("@tryforge/forgescript"); const dotenv_1 = require("dotenv"); const __1 = require(".."); (0, dotenv_1.config)(); +const chess = new __1.ForgeChess({ + events: ["start", "move"], +}); const client = new forgescript_1.ForgeClient({ prefixes: ["!"], token: process.env.Token, intents: ["MessageContent", "GuildMessages", "Guilds"], events: ["messageCreate", "clientReady"], - extensions: [new __1.ForgeChess()], + extensions: [chess], }); +chess.commands.add({ type: "start", code: "$log[started game with id: $js[ctx.runtime.extras.id]]" }); +chess.commands.add({ type: "move", code: "$log[Move played: $lastPlayedMove[;algebraic]]" }); client.commands.add({ name: "ping", type: "messageCreate", @@ -19,7 +24,7 @@ client.commands.add({ client.commands.add({ type: "messageCreate", name: "chess", - code: "$let[id;$default[$message[0];$randomNumber[1;10]]] $chess[$get[id]; $sendMessage[$channelID;$get[id] $codeblock[$displayChess[;Ascii]]]]", + code: "$let[id;$username] $chess[$get[id]; $sendMessage[$channelID;$get[id] $codeblock[$displayChess[;Ascii]]]]", }, { type: "messageCreate", name: "data", @@ -29,7 +34,7 @@ client.commands.add({ type: "messageCreate", name: "play", disableConsoleErrors: true, - code: "$let[id;$message[0]] $if[$argCount>1;$chessMove[$get[id];$message[1]]] `$chessMoves[$get[id];, ;true]` $codeblock[$displayChess[$get[id]]]", + code: "$let[id;$username] $if[$argCount>0;$chessMove[$get[id];$message]] `$chessMoves[$get[id];, ;true]` $codeblock[$displayChess[$get[id]]]", }); client.commands.add({ name: "eval", diff --git a/dist/__scripts__/bot.js.map b/dist/__scripts__/bot.js.map index 83737a2..45c4153 100644 --- a/dist/__scripts__/bot.js.map +++ b/dist/__scripts__/bot.js.map @@ -1 +1 @@ -{"version":3,"file":"bot.js","sourceRoot":"","sources":["../../src/__scripts__/bot.ts"],"names":[],"mappings":";;AAAA,uDAAmD;A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AQ,CAAC,GAAG,CAAC;IAClB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE;;iEAEyD;CAChE,CAAC,CAAA;AAEF,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;IAClB,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,KAAK;IACX,IAAI,EAAE;;;;;CAKP;CACA,CAAC,CAAA;AAEF,MAAM,CAAC,KAAK,EAAE,CAAA"} \ No newline at end of file diff --git a/dist/classes/chess.d.ts b/dist/classes/chess.d.ts index bea9216..8ff9bbf 100644 --- a/dist/classes/chess.d.ts +++ b/dist/classes/chess.d.ts @@ -1,5 +1,16 @@ -import { ChessBoard, PlayedMove } from "chess"; -import { DeepPartial } from ".."; +import { ChessBoard, PlayedMove, Square } from "chess"; +import { ChessManager, DeepPartial } from ".."; +export type AttackSquare = Record<"attackingSquare" | "kingSquare", Square>; +export interface ChessEventCallback extends Record<"move" | "undo" | "castle" | "enPassant", (move: PlayedMove) => unknown | Promise> { + promote: (square: Square) => unknown | Promise; + check: (attack: AttackSquare) => unknown | Promise; + checkmate: (attack: AttackSquare) => unknown | Promise; +} +export type ChessEvent = keyof ChessEventCallback; +export declare enum ChessOptions { + FlipBoard = 0, + ShowCoordinates = 1 +} export interface IChessOptions { display: { flip: boolean; @@ -8,10 +19,13 @@ export interface IChessOptions { } export declare class Chess { id: string; + manager: ChessManager; client: import("chess").AlgebraicGameClient; options: IChessOptions; lastPlayedMove: PlayedMove | null; - constructor(id: string, options?: DeepPartial); + constructor(id: string, options: DeepPartial | undefined, manager: ChessManager); + private addListeners; + on(event: T, callback: ChessEventCallback[T]): void; get moveCount(): number; currentPlayer(): "white" | "black"; availableMoves(san?: boolean): string[]; @@ -37,4 +51,5 @@ export declare enum ChessBoardDisplayType { FEN = "fen", Json = "json" } +export declare function isChessInstance(v: any): v is Chess; //# sourceMappingURL=chess.d.ts.map \ No newline at end of file diff --git a/dist/classes/chess.d.ts.map b/dist/classes/chess.d.ts.map index 9699bba..34e882b 100644 --- a/dist/classes/chess.d.ts.map +++ b/dist/classes/chess.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"chess.d.ts","sourceRoot":"","sources":["../../src/classes/chess.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAEhC,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE;QACP,IAAI,EAAE,OAAO,CAAA;QACb,MAAM,EAAE,OAAO,CAAA;KAChB,CAAA;CACF;AACD,qBAAa,KAAK;IAMP,EAAE,EAAE,MAAM;IALZ,MAAM,sCAA8B;IACpC,OAAO,EAAE,aAAa,CAAA;IAEtB,cAAc,EAAE,UAAU,GAAG,IAAI,CAAO;gBAEtC,EAAE,EAAE,MAAM,EACjB,OAAO,GAAE,WAAW,CAAC,aAAa,CAAM;IAU1C,IAAW,SAAS,WAEnB;IAEM,aAAa;IAQb,cAAc,CAAC,GAAG,UAAO;IAKzB,OAAO,CAAC,WAAW,EAAE,qBAAqB,CAAC,IAAI,GAAG,UAAU;IAC5D,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,qBAAqB,EAAE,qBAAqB,CAAC,IAAI,CAAC,GAAG,MAAM;IAcxF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU;IAqCtC,QAAQ;IAIR,MAAM;;;;;;;;;;;;CAcd;AAED,oBAAY,qBAAqB;IAC/B,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,IAAI,SAAS;CACd"} \ No newline at end of file +{"version":3,"file":"chess.d.ts","sourceRoot":"","sources":["../../src/classes/chess.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAE7D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAc,MAAM,IAAI,CAAA;AAE1D,MAAM,MAAM,YA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AAqB,CAAC,IAAI,GAAG,UAAU;IAC5D,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,qBAAqB,EAAE,qBAAqB,CAAC,IAAI,CAAC,GAAG,MAAM;IAcxF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU;IAqCtC,QAAQ;IAIR,MAAM;;;;;;;;;;;;CAcd;AAED,oBAAY,qBAAqB;IAC/B,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AACD,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,IAAI,KAAK,CAElD"} \ No newline at end of file diff --git a/dist/classes/chess.js b/dist/classes/chess.js index 5dc9445..95cbffa 100644 --- a/dist/classes/chess.js +++ b/dist/classes/chess.js @@ -3,22 +3,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.ChessBoardDisplayType = exports.Chess = void 0; +exports.ChessBoardDisplayType = exports.Chess = exports.ChessOptions = void 0; +exports.isChessInstance = isChessInstance; const chess_1 = __importDefault(require("chess")); const util_1 = require("./util"); +const __1 = require(".."); +var ChessOptions; +(function (ChessOptions) { + ChessOptions[ChessOptions["FlipBoard"] = 0] = "FlipBoard"; + ChessOptions[ChessOptions["ShowCoordinates"] = 1] = "ShowCoordinates"; +})(ChessOptions || (exports.ChessOptions = ChessOptions = {})); class Chess { id; + manager; client = chess_1.default.create({ PGN: true }); options; lastPlayedMove = null; - constructor(id, options = {}) { + constructor(id, options = {}, manager) { this.id = id; + this.manager = manager; this.options = { display: { flip: options.display?.flip ?? true, coords: options.display?.coords ?? true, }, }; + this.addListeners(manager.client.getExtension(__1.ForgeChess, true).options.events?.filter((e) => !["start"].includes(e)) ?? []); + } + addListeners(events) { + events.forEach((e) => this.on(e, (...args) => this.manager.client.getExtension(__1.ForgeChess, true).emitter.emit(e, this, ...args))); + } + on(event, callback) { + this.client.on(event, callback); } get moveCount() { return this.client.game.moveHistory?.length ?? 0; @@ -92,4 +108,7 @@ var ChessBoardDisplayType; ChessBoardDisplayType["FEN"] = "fen"; ChessBoardDisplayType["Json"] = "json"; })(ChessBoardDisplayType || (exports.ChessBoardDisplayType = ChessBoardDisplayType = {})); +function isChessInstance(v) { + return v && v instanceof Chess; +} //# sourceMappingURL=chess.js.map \ No newline at end of file diff --git a/dist/classes/chess.js.map b/dist/classes/chess.js.map index fe1ac4d..f8c03ca 100644 --- a/dist/classes/chess.js.map +++ b/dist/classes/chess.js.map @@ -1 +1 @@ -{"version":3,"file":"chess.js","sourceRoot":"","sources":["../../src/classes/chess.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAqD;AACrD,iCAAqC;AASrC,MAAa,KAAK;IAMP;IALF,MAAM,GAAG,eAAK,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;IACpC,OAAO,CAAe;IAEtB,cAAc,GAAsB,IAAI,CAAA;IAC/C,YACS,EAAU,EACjB,UAAsC,EAAE;QADjC,OAAE,GAAF,EAAE,CAAQ;QAGjB,IAAI,CAAC,OAAO,GAAG;YACb,OAAO,EAAE;gBACP,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,IAAI,IAAI;gBACnC,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,IAAI,IAAI;aACxC;SACF,CAAA;IACH,CAAC;IAED,IAAW,SAAS;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC,CAAA;IAClD,CAAC;IAEM,aAAa;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc;YAC1C,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,IAAI,OAAO;gBAC1D,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,OAAO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ts b/dist/classes/commands.d.ts new file mode 100644 index 0000000..9f42b04 --- /dev/null +++ b/dist/classes/commands.d.ts @@ -0,0 +1,7 @@ +import { BaseCommandManager } from "@tryforge/forgescript"; +import { IChessEvents } from "./event"; +export declare const ChessEventManagerName = "ChessEvents"; +export declare class ForgeChessCommandManager extends BaseCommandManager { + handlerName: string; +} +//# sourceMappingURL=commands.d.ts.map \ No newline at end of file diff --git a/dist/classes/commands.d.ts.map b/dist/classes/commands.d.ts.map new file mode 100644 index 0000000..83da577 --- /dev/null +++ b/dist/classes/commands.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/classes/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,eAAO,MAAM,qBAAqB,gBAAgB,CAAA;AAElD,qBAAa,wBAAyB,SAAQ,kBAAkB,CAAC,MAAM,YAAY,CAAC;IAClF,WAAW,SAAwB;CACpC"} \ No newline at end of file diff --git a/dist/classes/commands.js b/dist/classes/commands.js new file mode 100644 index 0000000..3a85e27 --- /dev/null +++ b/dist/classes/commands.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ForgeChessCommandManager = exports.ChessEventManagerName = void 0; +const forgescript_1 = require("@tryforge/forgescript"); +exports.ChessEventManagerName = "ChessEvents"; +class ForgeChessCommandManager extends forgescript_1.BaseCommandManager { + handlerName = exports.ChessEventManagerName; +} +exports.ForgeChessCommandManager = ForgeChessCommandManager; +//# sourceMappingURL=commands.js.map \ No newline at end of file diff --git a/dist/classes/commands.js.map b/dist/classes/commands.js.map new file mode 100644 index 0000000..a292cb9 --- /dev/null +++ b/dist/classes/commands.js.map @@ -0,0 +1 @@ +{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/classes/commands.ts"],"names":[],"mappings":";;;AAAA,uDAA0D;AAG7C,QAAA,qBAAqB,GAAG,aAAa,CAAA;AAElD,MAAa,wBAAyB,SAAQ,gCAAsC;IAClF,WAAW,GAAG,6BAAqB,CAAA;CACpC;AAFD,4DAEC"} \ No newline at end of file diff --git a/dist/classes/event.d.ts b/dist/classes/event.d.ts new file mode 100644 index 0000000..30dda04 --- /dev/null +++ b/dist/classes/event.d.ts @@ -0,0 +1,19 @@ +import { BaseEventHandler } from "@tryforge/forgescript"; +import { AttackSquare, Chess } from "./chess"; +import { ForgeClient } from "@tryforge/forgescript/dist/core"; +import { PlayedMove, Square } from "chess"; +export interface IChessEvents { + start: [Chess]; + move: [Chess, PlayedMove]; + undo: [Chess, PlayedMove]; + capture: [Chess, PlayedMove]; + enPassant: [Chess, PlayedMove]; + castle: [Chess, PlayedMove]; + promote: [Chess, Square]; + check: [Chess, AttackSquare]; + checkmate: [Chess, AttackSquare]; +} +export declare class ForgeChessEventHandler extends BaseEventHandler { + register(client: ForgeClient): void; +} +//# sourceMappingURL=event.d.ts.map \ No newline at end of file diff --git a/dist/classes/event.d.ts.map b/dist/classes/event.d.ts.map new file mode 100644 index 0000000..8734881 --- /dev/null +++ b/dist/classes/event.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/classes/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAE1C,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,CAAC,KAAK,CAAC,CAAA;IACd,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IACzB,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IACzB,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC5B,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC9B,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC3B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IACxB,KAAK,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAC5B,SAAS,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;CACjC;AACD,qBAAa,sBAAsB,CAAC,CAAC,SAAS,MAAM,YAAY,CAAE,SAAQ,gBAAgB,CAAC,YAAY,EAAE,CAAC,CAAC;IACzG,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;CAIpC"} \ No newline at end of file diff --git a/dist/classes/event.js b/dist/classes/event.js new file mode 100644 index 0000000..e691412 --- /dev/null +++ b/dist/classes/event.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ForgeChessEventHandler = void 0; +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +class ForgeChessEventHandler extends forgescript_1.BaseEventHandler { + register(client) { + client.getExtension(__1.ForgeChess, true).emitter.on(this.name, this.listener.bind(client)); + } +} +exports.ForgeChessEventHandler = ForgeChessEventHandler; +//# sourceMappingURL=event.js.map \ No newline at end of file diff --git a/dist/classes/event.js.map b/dist/classes/event.js.map new file mode 100644 index 0000000..e0b23b4 --- /dev/null +++ b/dist/classes/event.js.map @@ -0,0 +1 @@ +{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/classes/event.ts"],"names":[],"mappings":";;;AAAA,uDAAwD;AAGxD,0BAA+B;AAc/B,MAAa,sBAAqD,SAAQ,8BAAiC;IACzG,QAAQ,CAAC,MAAmB;QAE1B,MAAM,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IACzF,CAAC;CACF;AALD,wDAKC"} \ No newline at end of file diff --git a/dist/classes/manager.d.ts b/dist/classes/manager.d.ts index 2f6fde5..55dd1ae 100644 --- a/dist/classes/manager.d.ts +++ b/dist/classes/manager.d.ts @@ -1,9 +1,11 @@ +import { ForgeClient } from "@tryforge/forgescript"; import { DeepPartial } from ".."; import { Chess, IChessOptions } from "./chess"; export declare class ChessManager { + client: ForgeClient; map: Map; current: Chess[]; - constructor(); + constructor(client: ForgeClient); get lastCurrent(): Chess; get(id: string): Chess | undefined; remove(id: string): void; diff --git a/dist/classes/manager.d.ts.map b/dist/classes/manager.d.ts.map index 834571b..5f1de57 100644 --- a/dist/classes/manager.d.ts.map +++ b/dist/classes/manager.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/classes/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE9C,qBAAa,YAAY;IAChB,GAAG,qBAA2B;IAC9B,OAAO,EAAE,KAAK,EAAE,CAAK;;IAG5B,IAAW,WAAW,UAErB;IAEM,GAAG,CAAC,EAAE,EAAE,MAAM;IAGd,MAAM,CAAC,EAAE,EAAE,MAAM;IAIxB,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IACvB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,GAAG,IAAI;IAOjD,IAAI;CAGZ"} \ No newline at end of file +{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/classes/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE9C,qBAAa,YAAY;IAGG,MAAM,EAAE,WAAW;IAFtC,GAAG,qBAA2B;IAC9B,OAAO,EAAE,KAAK,EAAE,CAAK;gBACF,MAAM,EAAE,WAAW;IAE7C,IAAW,WAAW,UAErB;IAEM,GAAG,CAAC,EAAE,EAAE,MAAM;IAGd,MAAM,CAAC,EAAE,EAAE,MAAM;IAIxB,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IACvB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,GAAG,IAAI;IAOjD,IAAI;CAGZ"} \ No newline at end of file diff --git a/dist/classes/manager.js b/dist/classes/manager.js index 2e3f9d0..599eff6 100644 --- a/dist/classes/manager.js +++ b/dist/classes/manager.js @@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.ChessManager = void 0; const chess_1 = require("./chess"); class ChessManager { + client; map = new Map(); current = []; - constructor() { } + constructor(client) { + this.client = client; + } get lastCurrent() { return this.current[this.current.length - 1]; } @@ -17,7 +20,7 @@ class ChessManager { } set(chessOrId, opts) { return typeof chessOrId == "string" - ? this.map.set(chessOrId, new chess_1.Chess(chessOrId, opts ?? {})) + ? this.map.set(chessOrId, new chess_1.Chess(chessOrId, opts ?? {}, this)) : this.map.set(chessOrId.id, chessOrId); } list() { diff --git a/dist/classes/manager.js.map b/dist/classes/manager.js.map index d18049a..b98d8b7 100644 --- a/dist/classes/manager.js.map +++ b/dist/classes/manager.js.map @@ -1 +1 @@ -{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/classes/manager.ts"],"names":[],"mappings":";;;AACA,mCAA8C;AAE9C,MAAa,YAAY;IAChB,GAAG,GAAG,IAAI,GAAG,EAAiB,CAAA;IAC9B,OAAO,GAAY,EAAE,CAAA;IAC5B,gBAAsB,CAAC;IAEvB,IAAW,WA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M,MAAM,CAAC,EAAU;QACtB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACrB,CAAC;IAIM,GAAG,CAAC,SAAyB,EAAE,IAAiC;QACrE,OAAO,OAAO,SAAS,IAAI,QAAQ;YACjC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,aAAK,CAAC,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;YACjE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,CAAC,CAAA;IAC3C,CAAC;IAEM,IAAI;QACT,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAA;IACtC,CAAC;CACF;AA3BD,oCA2BC"} \ No newline at end of file diff --git a/dist/classes/util.d.ts b/dist/classes/util.d.ts index 3276dfd..6521f5c 100644 --- a/dist/classes/util.d.ts +++ b/dist/classes/util.d.ts @@ -3,6 +3,7 @@ export declare const BoardDisplay: { readonly Ascii: (board: ChessBoard, whiteAtBottom?: boolean, coords?: boolean) => string; }; export declare enum FCError { - NoChess = "No chess game found." + NoChess = "No chess game found.", + InvalidChess = "This is not a chess game." } //# sourceMappingURL=util.d.ts.map \ No newline at end of file diff --git a/dist/classes/util.d.ts.map b/dist/classes/util.d.ts.map index 52e107f..2995959 100644 --- a/dist/classes/util.d.ts.map +++ b/dist/classes/util.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/classes/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAIlC,eAAO,MAAM,YAAY;4BACV,UAAU,kBAAiB,OAAO,WAAiB,OAAO;CAoC/D,CAAA;AAEV,oBAAY,OAAO;IACjB,OAAO,yBAAyB;CACjC"} \ No newline at end of file +{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/classes/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAIlC,eAAO,MAAM,YAAY;4BACV,UAAU,kBAAiB,OAAO,WAAiB,OAAO;CAoC/D,CAAA;AAEV,oBAAY,OAAO;IACjB,OAAO,yBAAyB;IAChC,YAAY,8BAA8B;CAC3C"} \ No newline at end of file diff --git a/dist/classes/util.js b/dist/classes/util.js index 5aee920..990f708 100644 --- a/dist/classes/util.js +++ b/dist/classes/util.js @@ -31,5 +31,6 @@ exports.BoardDisplay = { var FCError; (function (FCError) { FCError["NoChess"] = "No chess game found."; + FCError["InvalidChess"] = "This is not a chess game."; })(FCError || (exports.FCError = FCError = {})); //# sourceMappingURL=util.js.map \ No newline at end of file diff --git a/dist/classes/util.js.map b/dist/classes/util.js.map index 9a14001..2314d62 100644 --- a/dist/classes/util.js.map +++ b/dist/classes/util.js.map @@ -1 +1 @@ -{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/classes/util.ts"],"names":[],"mappings":";;;AAEA,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEzC,QAAA,YAAY,GAAG;IAC1B,KAAK,CAAC,KAAiB,EAAE,gBAAyB,IAAI,EAAE,SAAkB,IAAI;QAC5E,IAAI,MAAM,GAAG,EAAE,CAAA;QAEf,MAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QAEjF,MAAM,KAAK,GAAG,aAAa,C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,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAClE,EAAE,CAAA;gBACH,MAAM,IAAI,KAAK,GAAG,GAAG,CAAA;YACvB,CAAC;YAED,MAAM,IAAI,IAAI,CAAA;QAChB,CAAC;QAGD,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;YACnD,MAAM,IAAI,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACpC,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACO,CAAA;AAEV,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,2CAAgC,CAAA;IAChC,qDAA0C,CAAA;AAC5C,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB"} \ No newline at end of file diff --git a/dist/events/capture.d.ts b/dist/events/capture.d.ts new file mode 100644 index 0000000..e2dab88 --- /dev/null +++ b/dist/events/capture.d.ts @@ -0,0 +1,4 @@ +import { ForgeChessEventHandler } from "../classes/event"; +declare const _default: ForgeChessEventHandler<"capture">; +export default _default; +//# sourceMappingURL=capture.d.ts.map \ No newline at end of file diff --git a/dist/events/capture.d.ts.map b/dist/events/capture.d.ts.map new file mode 100644 index 0000000..bceb163 --- /dev/null +++ b/dist/events/capture.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../src/events/capture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;;AAEzD,wBAmBE"} \ No newline at end of file diff --git a/dist/events/capture.js b/dist/events/capture.js new file mode 100644 index 0000000..f42539c --- /dev/null +++ b/dist/events/capture.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +const event_1 = require("../classes/event"); +exports.default = new event_1.ForgeChessEventHandler({ + name: "capture", + version: "1.0.0", + description: "Runs when a piece is captured.", + listener(chess, move) { + const commands = this.getExtension(__1.ForgeChess, true).commands.get("capture"); + for (const command of commands) { + forgescript_1.Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }); + } + }, +}); +//# sourceMappingURL=capture.js.map \ No newline at end of file diff --git a/dist/events/capture.js.map b/dist/events/capture.js.map new file mode 100644 index 0000000..fe65132 --- /dev/null +++ b/dist/events/capture.js.map @@ -0,0 +1 @@ +{"version":3,"file":"capture.js","sourceRoot":"","sources":["../../src/events/capture.ts"],"names":[],"mappings":";;AAAA,uDAAmD;AACnD,0BAA+B;AAC/B,4CAAyD;AAEzD,kBAAe,IAAI,8BAAsB,CAAC;IACxC,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,gCAAgC;IAC7C,QAAQ,CAAC,KAAK,EAAE,IAAI;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QAC5E,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,yBAAW,CAAC,GAAG,CAAC;gBACd,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,KAAK;gBACb,WAAW,EAAE;oBACX,IAAI;iBACL;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/events/castle.d.ts b/dist/events/castle.d.ts new file mode 100644 index 0000000..3a518bc --- /dev/null +++ b/dist/events/castle.d.ts @@ -0,0 +1,4 @@ +import { ForgeChessEventHandler } from "../classes/event"; +declare const _default: ForgeChessEventHandler<"castle">; +export default _default; +//# sourceMappingURL=castle.d.ts.map \ No newline at end of file diff --git a/dist/events/castle.d.ts.map b/dist/events/castle.d.ts.map new file mode 100644 index 0000000..e826f5f --- /dev/null +++ b/dist/events/castle.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"castle.d.ts","sourceRoot":"","sources":["../../src/events/castle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;;AAEzD,wBAmBE"} \ No newline at end of file diff --git a/dist/events/castle.js b/dist/events/castle.js new file mode 100644 index 0000000..7f5333c --- /dev/null +++ b/dist/events/castle.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +const event_1 = require("../classes/event"); +exports.default = new event_1.ForgeChessEventHandler({ + name: "castle", + version: "1.0.0", + description: "Runs when king castles.", + listener(chess, move) { + const commands = this.getExtension(__1.ForgeChess, true).commands.get("castle"); + for (const command of commands) { + forgescript_1.Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }); + } + }, +}); +//# sourceMappingURL=castle.js.map \ No newline at end of file diff --git a/dist/events/castle.js.map b/dist/events/castle.js.map new file mode 100644 index 0000000..5a3f9c7 --- /dev/null +++ b/dist/events/castle.js.map @@ -0,0 +1 @@ +{"version":3,"file":"castle.js","sourceRoot":"","sources":["../../src/events/castle.ts"],"names":[],"mappings":";;AAAA,uDAAmD;AACnD,0BAA+B;AAC/B,4CAAyD;AAEzD,kBAAe,IAAI,8BAAsB,CAAC;IACxC,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,yBAAyB;IACtC,QAAQ,CAAC,KAAK,EAAE,IAAI;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC3E,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,yBAAW,CAAC,GAAG,CAAC;gBACd,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,KAAK;gBACb,WAAW,EAAE;oBACX,IAAI;iBACL;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/events/check.d.ts b/dist/events/check.d.ts new file mode 100644 index 0000000..5387eb7 --- /dev/null +++ b/dist/events/check.d.ts @@ -0,0 +1,4 @@ +import { ForgeChessEventHandler } from "../classes/event"; +declare const _default: ForgeChessEventHandler<"check">; +export default _default; +//# sourceMappingURL=check.d.ts.map \ No newline at end of file diff --git a/dist/events/check.d.ts.map b/dist/events/check.d.ts.map new file mode 100644 index 0000000..315ab41 --- /dev/null +++ b/dist/events/check.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/events/check.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;;AAEzD,wBAmBE"} \ No newline at end of file diff --git a/dist/events/check.js b/dist/events/check.js new file mode 100644 index 0000000..db84cee --- /dev/null +++ b/dist/events/check.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +const event_1 = require("../classes/event"); +exports.default = new event_1.ForgeChessEventHandler({ + name: "check", + version: "1.0.0", + description: "Runs when the king is in check.", + listener(chess, attack) { + const commands = this.getExtension(__1.ForgeChess, true).commands.get("check"); + for (const command of commands) { + forgescript_1.Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + attack, + }, + }); + } + }, +}); +//# sourceMappingURL=check.js.map \ No newline at end of file diff --git a/dist/events/check.js.map b/dist/events/check.js.map new file mode 100644 index 0000000..7b4f40d --- /dev/null +++ b/dist/events/check.js.map @@ -0,0 +1 @@ +{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/events/check.ts"],"names":[],"mappings":";;AAAA,uDAAmD;AACnD,0BAA+B;AAC/B,4CAAyD;AAEzD,kBAAe,IAAI,8BAAsB,CAAC;IACxC,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,iCAAiC;IAC9C,QAAQ,CAAC,KAAK,EAAE,MAAM;QACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC1E,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,yBAAW,CAAC,GAAG,CAAC;gBACd,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,KAAK;gBACb,WAAW,EAAE;oBACX,MAAM;iBACP;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/events/checkmate.d.ts b/dist/events/checkmate.d.ts new file mode 100644 index 0000000..d137627 --- /dev/null +++ b/dist/events/checkmate.d.ts @@ -0,0 +1,4 @@ +import { ForgeChessEventHandler } from "../classes/event"; +declare const _default: ForgeChessEventHandler<"checkmate">; +export default _default; +//# sourceMappingURL=checkmate.d.ts.map \ No newline at end of file diff --git a/dist/events/checkmate.d.ts.map b/dist/events/checkmate.d.ts.map new file mode 100644 index 0000000..abd7e55 --- /dev/null +++ b/dist/events/checkmate.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"checkmate.d.ts","sourceRoot":"","sources":["../../src/events/checkmate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;;AAEzD,wBAmBE"} \ No newline at end of file diff --git a/dist/events/checkmate.js b/dist/events/checkmate.js new file mode 100644 index 0000000..cf83549 --- /dev/null +++ b/dist/events/checkmate.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +const event_1 = require("../classes/event"); +exports.default = new event_1.ForgeChessEventHandler({ + name: "checkmate", + version: "1.0.0", + description: "Runs when the king is checkmated.", + listener(chess, attack) { + const commands = this.getExtension(__1.ForgeChess, true).commands.get("checkmate"); + for (const command of commands) { + forgescript_1.Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + attack, + }, + }); + } + }, +}); +//# sourceMappingURL=checkmate.js.map \ No newline at end of file diff --git a/dist/events/checkmate.js.map b/dist/events/checkmate.js.map new file mode 100644 index 0000000..18b7228 --- /dev/null +++ b/dist/events/checkmate.js.map @@ -0,0 +1 @@ +{"version":3,"file":"checkmate.js","sourceRoot":"","sources":["../../src/events/checkmate.ts"],"names":[],"mappings":";;AAAA,uDAAmD;AACnD,0BAA+B;AAC/B,4CAAyD;AAEzD,kBAAe,IAAI,8BAAsB,CAAC;IACxC,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,mCAAmC;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM;QACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QAC9E,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,yBAAW,CAAC,GAAG,CAAC;gBACd,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,KAAK;gBACb,WAAW,EAAE;oBACX,MAAM;iBACP;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/events/enPassant.d.ts b/dist/events/enPassant.d.ts new file mode 100644 index 0000000..e4a8423 --- /dev/null +++ b/dist/events/enPassant.d.ts @@ -0,0 +1,4 @@ +import { ForgeChessEventHandler } from "../classes/event"; +declare const _default: ForgeChessEventHandler<"enPassant">; +export default _default; +//# sourceMappingURL=enPassant.d.ts.map \ No newline at end of file diff --git a/dist/events/enPassant.d.ts.map b/dist/events/enPassant.d.ts.map new file mode 100644 index 0000000..b9fbd4e --- /dev/null +++ b/dist/events/enPassant.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"enPassant.d.ts","sourceRoot":"","sources":["../../src/events/enPassant.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;;AAEzD,wBAmBE"} \ No newline at end of file diff --git a/dist/events/enPassant.js b/dist/events/enPassant.js new file mode 100644 index 0000000..84df509 --- /dev/null +++ b/dist/events/enPassant.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +const event_1 = require("../classes/event"); +exports.default = new event_1.ForgeChessEventHandler({ + name: "enPassant", + version: "1.0.0", + description: "Runs when en passant is occured.", + listener(chess, move) { + const commands = this.getExtension(__1.ForgeChess, true).commands.get("enPassant"); + for (const command of commands) { + forgescript_1.Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }); + } + }, +}); +//# sourceMappingURL=enPassant.js.map \ No newline at end of file diff --git a/dist/events/enPassant.js.map b/dist/events/enPassant.js.map new file mode 100644 index 0000000..1471ad3 --- /dev/null +++ b/dist/events/enPassant.js.map @@ -0,0 +1 @@ +{"version":3,"file":"enPassant.js","sourceRoot":"","sources":["../../src/events/enPassant.ts"],"names":[],"mappings":";;AAAA,uDAAmD;AACnD,0BAA+B;AAC/B,4CAAyD;AAEzD,kBAAe,IAAI,8BAAsB,CAAC;IACxC,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,kCAAkC;IAC/C,QAAQ,CAAC,KAAK,EAAE,IAAI;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QAC9E,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,yBAAW,CAAC,GAAG,CAAC;gBACd,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,KAAK;gBACb,WAAW,EAAE;oBACX,IAAI;iBACL;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/events/move.d.ts b/dist/events/move.d.ts new file mode 100644 index 0000000..d8fd056 --- /dev/null +++ b/dist/events/move.d.ts @@ -0,0 +1,4 @@ +import { ForgeChessEventHandler } from "../classes/event"; +declare const _default: ForgeChessEventHandler<"move">; +export default _default; +//# sourceMappingURL=move.d.ts.map \ No newline at end of file diff --git a/dist/events/move.d.ts.map b/dist/events/move.d.ts.map new file mode 100644 index 0000000..1680988 --- /dev/null +++ b/dist/events/move.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"move.d.ts","sourceRoot":"","sources":["../../src/events/move.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;;AAEzD,wBAmBE"} \ No newline at end of file diff --git a/dist/events/move.js b/dist/events/move.js new file mode 100644 index 0000000..3e94efb --- /dev/null +++ b/dist/events/move.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +const event_1 = require("../classes/event"); +exports.default = new event_1.ForgeChessEventHandler({ + name: "move", + version: "1.0.0", + description: "Runs when a move is played.", + listener(chess, move) { + const commands = this.getExtension(__1.ForgeChess, true).commands.get("move"); + for (const command of commands) { + forgescript_1.Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }); + } + }, +}); +//# sourceMappingURL=move.js.map \ No newline at end of file diff --git a/dist/events/move.js.map b/dist/events/move.js.map new file mode 100644 index 0000000..1b98622 --- /dev/null +++ b/dist/events/move.js.map @@ -0,0 +1 @@ +{"version":3,"file":"move.js","sourceRoot":"","sources":["../../src/events/move.ts"],"names":[],"mappings":";;AAAA,uDAAmD;AACnD,0BAA+B;AAC/B,4CAAyD;AAEzD,kBAAe,IAAI,8BAAsB,CAAC;IACxC,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,6BAA6B;IAC1C,QAAQ,CAAC,KAAK,EAAE,IAAI;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACzE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,yBAAW,CAAC,GAAG,CAAC;gBACd,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,KAAK;gBACb,WAAW,EAAE;oBACX,IAAI;iBACL;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/events/promote.d.ts b/dist/events/promote.d.ts new file mode 100644 index 0000000..0ac84ad --- /dev/null +++ b/dist/events/promote.d.ts @@ -0,0 +1,4 @@ +import { ForgeChessEventHandler } from "../classes/event"; +declare const _default: ForgeChessEventHandler<"promote">; +export default _default; +//# sourceMappingURL=promote.d.ts.map \ No newline at end of file diff --git a/dist/events/promote.d.ts.map b/dist/events/promote.d.ts.map new file mode 100644 index 0000000..7a4052e --- /dev/null +++ b/dist/events/promote.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../src/events/promote.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;;AAEzD,wBAmBE"} \ No newline at end of file diff --git a/dist/events/promote.js b/dist/events/promote.js new file mode 100644 index 0000000..4cc8924 --- /dev/null +++ b/dist/events/promote.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +const event_1 = require("../classes/event"); +exports.default = new event_1.ForgeChessEventHandler({ + name: "promote", + version: "1.0.0", + description: "Runs when a pawn is promoted.", + listener(chess, square) { + const commands = this.getExtension(__1.ForgeChess, true).commands.get("promote"); + for (const command of commands) { + forgescript_1.Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + square, + }, + }); + } + }, +}); +//# sourceMappingURL=promote.js.map \ No newline at end of file diff --git a/dist/events/promote.js.map b/dist/events/promote.js.map new file mode 100644 index 0000000..39ad7ae --- /dev/null +++ b/dist/events/promote.js.map @@ -0,0 +1 @@ +{"version":3,"file":"promote.js","sourceRoot":"","sources":["../../src/events/promote.ts"],"names":[],"mappings":";;AAAA,uDAAmD;AACnD,0BAA+B;AAC/B,4CAAyD;AAEzD,kBAAe,IAAI,8BAAsB,CAAC;IACxC,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,+BAA+B;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM;QACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QAC5E,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,yBAAW,CAAC,GAAG,CAAC;gBACd,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,KAAK;gBACb,WAAW,EAAE;oBACX,MAAM;iBACP;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/events/start.d.ts b/dist/events/start.d.ts new file mode 100644 index 0000000..1f64b2f --- /dev/null +++ b/dist/events/start.d.ts @@ -0,0 +1,4 @@ +import { ForgeChessEventHandler } from "../classes/event"; +declare const _default: ForgeChessEventHandler<"start">; +export default _default; +//# sourceMappingURL=start.d.ts.map \ No newline at end of file diff --git a/dist/events/start.d.ts.map b/dist/events/start.d.ts.map new file mode 100644 index 0000000..9ac66b7 --- /dev/null +++ b/dist/events/start.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/events/start.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;;AAEzD,wBAgBE"} \ No newline at end of file diff --git a/dist/events/start.js b/dist/events/start.js new file mode 100644 index 0000000..3118d1c --- /dev/null +++ b/dist/events/start.js @@ -0,0 +1,23 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +const event_1 = require("../classes/event"); +exports.default = new event_1.ForgeChessEventHandler({ + name: "start", + version: "1.0.0", + description: "Runs when a chess game has started.", + listener(chess) { + const commands = this.getExtension(__1.ForgeChess, true).commands.get("start"); + for (const command of commands) { + forgescript_1.Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + }); + } + }, +}); +//# sourceMappingURL=start.js.map \ No newline at end of file diff --git a/dist/events/start.js.map b/dist/events/start.js.map new file mode 100644 index 0000000..dc8001b --- /dev/null +++ b/dist/events/start.js.map @@ -0,0 +1 @@ +{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/events/start.ts"],"names":[],"mappings":";;AAAA,uDAAmD;AACnD,0BAA+B;AAC/B,4CAAyD;AAEzD,kBAAe,IAAI,8BAAsB,CAAC;IACxC,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,qCAAqC;IAClD,QAAQ,CAAC,KAAK;QACZ,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC1E,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,yBAAW,CAAC,GAAG,CAAC;gBACd,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,KAAK;aACd,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/events/undo.d.ts b/dist/events/undo.d.ts new file mode 100644 index 0000000..9b7ad90 --- /dev/null +++ b/dist/events/undo.d.ts @@ -0,0 +1,4 @@ +import { ForgeChessEventHandler } from "../classes/event"; +declare const _default: ForgeChessEventHandler<"undo">; +export default _default; +//# sourceMappingURL=undo.d.ts.map \ No newline at end of file diff --git a/dist/events/undo.d.ts.map b/dist/events/undo.d.ts.map new file mode 100644 index 0000000..a1d9e16 --- /dev/null +++ b/dist/events/undo.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"undo.d.ts","sourceRoot":"","sources":["../../src/events/undo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;;AAEzD,wBAmBE"} \ No newline at end of file diff --git a/dist/events/undo.js b/dist/events/undo.js new file mode 100644 index 0000000..6816925 --- /dev/null +++ b/dist/events/undo.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const __1 = require(".."); +const event_1 = require("../classes/event"); +exports.default = new event_1.ForgeChessEventHandler({ + name: "undo", + version: "1.0.0", + description: "Runs when a move is undo.", + listener(chess, move) { + const commands = this.getExtension(__1.ForgeChess, true).commands.get("undo"); + for (const command of commands) { + forgescript_1.Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }); + } + }, +}); +//# sourceMappingURL=undo.js.map \ No newline at end of file diff --git a/dist/events/undo.js.map b/dist/events/undo.js.map new file mode 100644 index 0000000..6775769 --- /dev/null +++ b/dist/events/undo.js.map @@ -0,0 +1 @@ +{"version":3,"file":"undo.js","sourceRoot":"","sources":["../../src/events/undo.ts"],"names":[],"mappings":";;AAAA,uDAAmD;AACnD,0BAA+B;AAC/B,4CAAyD;AAEzD,kBAAe,IAAI,8BAAsB,CAAC;IACxC,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,2BAA2B;IACxC,QAAQ,CAAC,KAAK,EAAE,IAAI;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,cAAU,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACzE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,yBAAW,CAAC,GAAG,CAAC;gBACd,GAAG,EAAE,EAAE;gBACP,MAAM,EAAE,IAAI;gBACZ,OAAO;gBACP,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,KAAK;gBACb,WAAW,EAAE;oBACX,IAAI;iBACL;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/chessGameData.d.ts.map b/dist/functions/game/chessGameData.d.ts.map index ac5af32..935206e 100644 --- a/dist/functions/game/chessGameData.d.ts.map +++ b/dist/functions/game/chessGameData.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"chessGameData.d.ts","sourceRoot":"","sources":["../../../src/functions/game/chessGameData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO,EAAuB,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;;AAE9E,wBAmBE"} \ No newline at end of file +{"version":3,"file":"chessGameData.d.ts","sourceRoot":"","sources":["../../../src/functions/game/chessGameData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO,EAAuB,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;;AAE9E,wBAoBE"} \ No newline at end of file diff --git a/dist/functions/game/chessGameData.js b/dist/functions/game/chessGameData.js index 4723995..5e4b19e 100644 --- a/dist/functions/game/chessGameData.js +++ b/dist/functions/game/chessGameData.js @@ -17,9 +17,11 @@ exports.default = new forgescript_1.NativeFunction({ ], output: [forgescript_1.ArgType.Json, forgescript_1.ArgType.Unknown], async execute(ctx, [id, prop, sep]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent; + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); if (!chess) return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); if (!prop) return this.successJSON(chess.toJSON()); return this.success(game_1.ChessGameProperties[prop](chess, sep ?? ", ")); diff --git a/dist/functions/game/chessGameData.js.map b/dist/functions/game/chessGameData.js.map index 33c7b9b..a81cec0 100644 --- a/dist/functions/game/chessGameData.js.map +++ b/dist/functions/game/chessGameData.js.map @@ -1 +1 @@ -{"version":3,"file":"chessGameData.js","sourceRoot":"","sources":["../../../src/functions/game/chessGameData.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAuC;AACvC,gDAA8E;AAE9E,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,CAAC,oBAAoB,EAAE,eAAe,CAAC;IAChD,WAAW,EAAE,gCAAgC;IAC7C,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE;QACJ,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC;QAChD,iBAAG,CAAC,YAAY,CAAC,wBAAiB,EAAE,UAAU,EAAE,sBAAsB,CAAC;QACvE,iBAAG,CAAC,cAAc,CAAC,KAAK,EAAE,sCAAsC,CAAC;KAClE;IACD,MAAM,EAAE,CAAC,qBAAO,CAAC,IAAI,EAAE,qBAAO,CAAC,OAAO,CAAC;IACvC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC;QAChC,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAA;QAC1F,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;QAClD,OAAO,IAAI,CAAC,OAAO,CAAC,0BAAmB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAA;IACpE,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"chessGameData.js","sourceRoot":"","sources":["../../../src/functions/game/chessGameData.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAwD;AACxD,gDAA8E;AAE9E,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,CAAC,oBAAoB,EAAE,eAAe,CAAC;IAChD,WAAW,EAAE,gCAAgC;IAC7C,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE;QACJ,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC;QAChD,iBAAG,CAAC,YAAY,CAAC,wBAAiB,EAAE,UAAU,EAAE,sBAAsB,CAAC;QACvE,iBAAG,CAAC,cAAc,CAAC,KAAK,EAAE,sCAAsC,CAAC;KAClE;IACD,MAAM,EAAE,CAAC,qBAAO,CAAC,IAAI,EAAE,qBAAO,CAAC,OAAO,CAAC;IACvC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC;QAChC,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAClH,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAA,yBAAe,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,YAAY,CAAC,CAAA;QAC1E,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;QAClD,OAAO,IAAI,CAAC,OAAO,CAAC,0BAAmB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAA;IACpE,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/chessMove.d.ts.map b/dist/functions/game/chessMove.d.ts.map index b875926..0c5f001 100644 --- a/dist/functions/game/chessMove.d.ts.map +++ b/dist/functions/game/chessMove.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"chessMove.d.ts","sourceRoot":"","sources":["../../../src/functions/game/chessMove.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAGpE,wBAoBE"} \ No newline at end of file +{"version":3,"file":"chessMove.d.ts","sourceRoot":"","sources":["../../../src/functions/game/chessMove.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAGpE,wBAqBE"} \ No newline at end of file diff --git a/dist/functions/game/chessMove.js b/dist/functions/game/chessMove.js index a930cd0..b83c3bf 100644 --- a/dist/functions/game/chessMove.js +++ b/dist/functions/game/chessMove.js @@ -11,9 +11,11 @@ exports.default = new forgescript_1.NativeFunction({ unwrap: true, args: [forgescript_1.Arg.optionalString("id", "ID of the chess game"), forgescript_1.Arg.restString("moves", "The moves to play")], async execute(ctx, [id, moves]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent; + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); if (!chess) return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); for (const move of moves) { try { chess.makeMove(move.replace(" ", "")); diff --git a/dist/functions/game/chessMove.js.map b/dist/functions/game/chessMove.js.map index 7ad099e..beaffff 100644 --- a/dist/functions/game/chessMove.js.map +++ b/dist/functions/game/chessMove.js.map @@ -1 +1 @@ -{"version":3,"file":"chessMove.js","sourceRoot":"","sources":["../../../src/functions/game/chessMove.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAuC;AAEvC,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,CAAC,gBAAgB,CAAC;IAC3B,WAAW,EAAE,uBAAuB;IACpC,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,EAAE,iBAAG,CAAC,UAAU,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IACtG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;QAC5B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAA;QAC1F,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;YACvC,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;YAChC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAA;IACvB,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"chessMove.js","sourceRoot":"","sources":["../../../src/functions/game/chessMove.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAwD;AAExD,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,CAAC,gBAAgB,CAAC;IAC3B,WAAW,EAAE,uBAAuB;IACpC,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,EAAE,iBAAG,CAAC,UAAU,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IACtG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;QAC5B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAClH,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAA,yBAAe,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,YAAY,CAAC,CAAA;QAC1E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC;gBACH,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;YACvC,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;YAChC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAA;IACvB,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/chessMoveCount.d.ts.map b/dist/functions/game/chessMoveCount.d.ts.map index f81c775..8da76b2 100644 --- a/dist/functions/game/chessMoveCount.d.ts.map +++ b/dist/functions/game/chessMoveCount.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"chessMoveCount.d.ts","sourceRoot":"","sources":["../../../src/functions/game/chessMoveCount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAGpE,wBAaE"} \ No newline at end of file +{"version":3,"file":"chessMoveCount.d.ts","sourceRoot":"","sources":["../../../src/functions/game/chessMoveCount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAGpE,wBAcE"} \ No newline at end of file diff --git a/dist/functions/game/chessMoveCount.js b/dist/functions/game/chessMoveCount.js index 5a36e02..531c762 100644 --- a/dist/functions/game/chessMoveCount.js +++ b/dist/functions/game/chessMoveCount.js @@ -11,9 +11,11 @@ exports.default = new forgescript_1.NativeFunction({ args: [forgescript_1.Arg.optionalString("id", "ID of the chess game")], output: forgescript_1.ArgType.Number, async execute(ctx, [id]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent; + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); if (!chess) return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); return this.success(chess.moveCount); }, }); diff --git a/dist/functions/game/chessMoveCount.js.map b/dist/functions/game/chessMoveCount.js.map index 40909ba..276f0be 100644 --- a/dist/functions/game/chessMoveCount.js.map +++ b/dist/functions/game/chessMoveCount.js.map @@ -1 +1 @@ -{"version":3,"file":"chessMoveCount.js","sourceRoot":"","sources":["../../../src/functions/game/chessMoveCount.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAuC;AAEvC,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,6BAA6B;IAC1C,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IACxD,MAAM,EAAE,qBAAO,CAAC,MAAM;IACtB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAA;QAC1F,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACtC,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"chessMoveCount.js","sourceRoot":"","sources":["../../../src/functions/game/chessMoveCount.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAwD;AAExD,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,6BAA6B;IAC1C,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IACxD,MAAM,EAAE,qBAAO,CAAC,MAAM;IACtB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAClH,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAA,yBAAe,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,YAAY,CAAC,CAAA;QAC1E,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACtC,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/chessMoveList.d.ts.map b/dist/functions/game/chessMoveList.d.ts.map index 9a323b2..a35b139 100644 --- a/dist/functions/game/chessMoveList.d.ts.map +++ b/dist/functions/game/chessMoveList.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"chessMoveList.d.ts","sourceRoot":"","sources":["../../../src/functions/game/chessMoveList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAIpE,wBAkBE"} \ No newline at end of file +{"version":3,"file":"chessMoveList.d.ts","sourceRoot":"","sources":["../../../src/functions/game/chessMoveList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAIpE,wBAmBE"} \ No newline at end of file diff --git a/dist/functions/game/chessMoveList.js b/dist/functions/game/chessMoveList.js index 606b38f..0211ec8 100644 --- a/dist/functions/game/chessMoveList.js +++ b/dist/functions/game/chessMoveList.js @@ -20,9 +20,11 @@ exports.default = new forgescript_1.NativeFunction({ ], output: (0, array_1.default)(), async execute(ctx, [id, sep, san]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent; + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); if (!chess) return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); return this.success(chess.availableMoves(san ?? true).join(sep ?? ", ")); }, }); diff --git a/dist/functions/game/chessMoveList.js.map b/dist/functions/game/chessMoveList.js.map index c4b7a14..1751d64 100644 --- a/dist/functions/game/chessMoveList.js.map +++ b/dist/functions/game/chessMoveList.js.map @@ -1 +1 @@ -{"version":3,"file":"chessMoveList.js","sourceRoot":"","sources":["../../../src/functions/game/chessMoveList.ts"],"names":[],"mappings":";;;;;AAAA,uDAAoE;AACpE,uFAA8D;AAC9D,2CAAuC;AAEvC,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,CAAC,sBAAsB,EAAE,aAAa,CAAC;IAChD,WAAW,EAAE,yBAAyB;IACtC,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE;QACJ,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC;QAChD,iBAAG,CAAC,cAAc,CAAC,KAAK,EAAE,sBAAsB,CAAC;QACjD,iBAAG,CAAC,eAAe,CAAC,KAAK,EAAE,6BAA6B,CAAC;KAC1D;IACD,MAAM,EAAE,IAAA,eAAK,GAAkB;IAC/B,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC;QAC/B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAA;QAC1F,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAA;IAC1E,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"chessMoveList.js","sourceRoot":"","sources":["../../../src/functions/game/chessMoveList.ts"],"names":[],"mappings":";;;;;AAAA,uDAAoE;AACpE,uFAA8D;AAC9D,2CAAwD;AAExD,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,CAAC,sBAAsB,EAAE,aAAa,CAAC;IAChD,WAAW,EAAE,yBAAyB;IACtC,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE;QACJ,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC;QAChD,iBAAG,CAAC,cAAc,CAAC,KAAK,EAAE,sBAAsB,CAAC;QACjD,iBAAG,CAAC,eAAe,CAAC,KAAK,EAAE,6BAA6B,CAAC;KAC1D;IACD,MAAM,EAAE,IAAA,eAAK,GAAkB;IAC/B,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC;QAC/B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAClH,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAA,yBAAe,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,YAAY,CAAC,CAAA;QAC1E,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAA;IAC1E,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/createChess.d.ts.map b/dist/functions/game/createChess.d.ts.map index 59d48da..90fa8cb 100644 --- a/dist/functions/game/createChess.d.ts.map +++ b/dist/functions/game/createChess.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"createChess.d.ts","sourceRoot":"","sources":["../../../src/functions/game/createChess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAG3D,wBAiCE"} \ No newline at end of file +{"version":3,"file":"createChess.d.ts","sourceRoot":"","sources":["../../../src/functions/game/createChess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAI3D,wBAkCE"} \ No newline at end of file diff --git a/dist/functions/game/createChess.js b/dist/functions/game/createChess.js index 00cab05..c46f256 100644 --- a/dist/functions/game/createChess.js +++ b/dist/functions/game/createChess.js @@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const forgescript_1 = require("@tryforge/forgescript"); const classes_1 = require("../../classes"); +const __1 = require("../.."); exports.default = new forgescript_1.NativeFunction({ name: "$createChess", aliases: ["$chess", "$chessGame"], @@ -18,14 +19,15 @@ exports.default = new forgescript_1.NativeFunction({ return this.customError("No ID is provided."); if (this.data.fields.length >= 1) { if (!ctx.client.chessManager || !(ctx.client.chessManager instanceof classes_1.ChessManager)) - ctx.client.chessManager = new classes_1.ChessManager(); - ctx.client.chessManager.current.push(new classes_1.Chess(id)); + ctx.client.chessManager = new classes_1.ChessManager(ctx.client); + ctx.client.chessManager.current.push(new classes_1.Chess(id, {}, ctx.client.chessManager)); } for (let i = 1; i < this.data.fields.length; i++) { await this["resolveCode"](ctx, this.data.fields[i]); } if (!ctx.client.chessManager || ctx.client.chessManager.current.length === 0) return this.customError("Couldnt create the chess game."); + ctx.client.getExtension(__1.ForgeChess, true).emitter.emit("start", ctx.client.chessManager.lastCurrent); ctx.client.chessManager.set(ctx.client.chessManager.lastCurrent); ctx.client.chessManager.current = ctx.client.chessManager.current.slice(0, ctx.client.chessManager.current.length - 1); return this.success(); diff --git a/dist/functions/game/createChess.js.map b/dist/functions/game/createChess.js.map index e73ed00..167f5b3 100644 --- a/dist/functions/game/createChess.js.map +++ b/dist/functions/game/createChess.js.map @@ -1 +1 @@ -{"version":3,"file":"createChess.js","sourceRoot":"","sources":["../../../src/functions/game/createChess.ts"],"names":[],"mappings":";;AAAA,uDAA2D;AAC3D,2CAAmD;AAEnD,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC;IACjC,WAAW,EAAE,0BAA0B;IACvC,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,EAAE,iBAAG,CAAC,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAC/F,KAAK,CAAC,OAAO,CAAC,GAAG;QACf,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;QAC5C,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,IAA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AO,CAAC,MAAM,GAAG,CAAC,CAC3C,CAAA;QACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAA;IACvB,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"createChess.js","sourceRoot":"","sources":["../../../src/functions/game/createChess.ts"],"names":[],"mappings":";;AAAA,uDAA2D;AAC3D,2CAAmD;AACnD,6BAAkC;AAElC,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC;IACjC,WAAW,EAAE,0BAA0B;IACvC,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,EAAE,iBAAG,CAAC,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAC/F,KAAK,CAAC,OAAO,CAAC,GAAG;QACf,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;QAC5C,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAA2B,CAAA;QAE7F,IAAI,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAA;QAEtD,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACjC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,YAAY,sBAAY,CAAC;gBAChF,GAAG,CAAC,MAAM,CAAC,YAAY,GAAG,IAAI,sBAAY,CAAC,GAAG,CAAC,MAA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22bbd7f..21d2b77 100644 --- a/dist/functions/game/currentPlayer.d.ts.map +++ b/dist/functions/game/currentPlayer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"currentPlayer.d.ts","sourceRoot":"","sources":["../../../src/functions/game/currentPlayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAGpE,wBAcE"} \ No newline at end of file +{"version":3,"file":"currentPlayer.d.ts","sourceRoot":"","sources":["../../../src/functions/game/currentPlayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAGpE,wBAeE"} \ No newline at end of file diff --git a/dist/functions/game/currentPlayer.js b/dist/functions/game/currentPlayer.js index 844ab87..870cc3b 100644 --- a/dist/functions/game/currentPlayer.js +++ b/dist/functions/game/currentPlayer.js @@ -12,9 +12,11 @@ exports.default = new forgescript_1.NativeFunction({ args: [forgescript_1.Arg.optionalString("id", "ID of the chess game")], output: forgescript_1.ArgType.String, async execute(ctx, [id]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent; + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); if (!chess) return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); return this.success(chess.currentPlayer()); }, }); diff --git a/dist/functions/game/currentPlayer.js.map b/dist/functions/game/currentPlayer.js.map index e79fba2..44012e9 100644 --- a/dist/functions/game/currentPlayer.js.map +++ b/dist/functions/game/currentPlayer.js.map @@ -1 +1 @@ -{"version":3,"file":"currentPlayer.js","sourceRoot":"","sources":["../../../src/functions/game/currentPlayer.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAuC;AAEvC,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,qBAAqB;IAC3B,OAAO,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;IAC1C,WAAW,EAAE,uDAAuD;IACpE,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IACxD,MAAM,EAAE,qBAAO,CAAC,MAAM;IACtB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAA;QAC1F,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAA;IAC5C,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"currentPlayer.js","sourceRoot":"","sources":["../../../src/functions/game/currentPlayer.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAwD;AAExD,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,qBAAqB;IAC3B,OAAO,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;IAC1C,WAAW,EAAE,uDAAuD;IACpE,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IACxD,MAAM,EAAE,qBAAO,CAAC,MAAM;IACtB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAClH,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAA,yBAAe,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,YAAY,CAAC,CAAA;QAC1E,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAA;IAC5C,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/deleteChess.d.ts b/dist/functions/game/deleteChess.d.ts new file mode 100644 index 0000000..0e21276 --- /dev/null +++ b/dist/functions/game/deleteChess.d.ts @@ -0,0 +1,4 @@ +import { ArgType, NativeFunction } from "@tryforge/forgescript"; +declare const _default: NativeFunction<[import("@tryforge/forgescript").IArg], true>; +export default _default; +//# sourceMappingURL=deleteChess.d.ts.map \ No newline at end of file diff --git a/dist/functions/game/deleteChess.d.ts.map b/dist/functions/game/deleteChess.d.ts.map new file mode 100644 index 0000000..3083271 --- /dev/null +++ b/dist/functions/game/deleteChess.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"deleteChess.d.ts","sourceRoot":"","sources":["../../../src/functions/game/deleteChess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAEpE,wBAgBE"} \ No newline at end of file diff --git a/dist/functions/game/deleteChess.js b/dist/functions/game/deleteChess.js new file mode 100644 index 0000000..c8e9875 --- /dev/null +++ b/dist/functions/game/deleteChess.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const classes_1 = require("../../classes"); +exports.default = new forgescript_1.NativeFunction({ + name: "$deleteChess", + aliases: ["$deleteClassGame"], + description: "Deletes the chess game from the manager.", + version: "1.0.0", + brackets: false, + unwrap: true, + args: [forgescript_1.Arg.optionalString("id", "ID of the chess game")], + output: forgescript_1.ArgType.Boolean, + async execute(ctx, [id]) { + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); + if (!chess) + return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); + ctx.client.chessManager?.remove(chess.id); + return this.success(true); + }, +}); +//# sourceMappingURL=deleteChess.js.map \ No newline at end of file diff --git a/dist/functions/game/deleteChess.js.map b/dist/functions/game/deleteChess.js.map new file mode 100644 index 0000000..47a2369 --- /dev/null +++ b/dist/functions/game/deleteChess.js.map @@ -0,0 +1 @@ +{"version":3,"file":"deleteChess.js","sourceRoot":"","sources":["../../../src/functions/game/deleteChess.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAwD;AACxD,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,CAAC,kBAAkB,CAAC;IAC7B,WAAW,EAAE,0CAA0C;IACvD,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IACxD,MAAM,EAAE,qBAAO,CAAC,OAAO;IACvB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAClH,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAA,yBAAe,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,YAAY,CAAC,CAAA;QAC1E,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/displayChessBoard.d.ts.map b/dist/functions/game/displayChessBoard.d.ts.map index d363ebc..f65d44d 100644 --- a/dist/functions/game/displayChessBoard.d.ts.map +++ b/dist/functions/game/displayChessBoard.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"displayChessBoard.d.ts","sourceRoot":"","sources":["../../../src/functions/game/displayChessBoard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,qBAAqB,EAAW,MAAM,eAAe,CAAA;;AAE9D,wBAkBE"} \ No newline at end of file +{"version":3,"file":"displayChessBoard.d.ts","sourceRoot":"","sources":["../../../src/functions/game/displayChessBoard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,qBAAqB,EAA4B,MAAM,eAAe,CAAA;;AAE/E,wBAmBE"} \ No newline at end of file diff --git a/dist/functions/game/displayChessBoard.js b/dist/functions/game/displayChessBoard.js index 070b851..8f280c7 100644 --- a/dist/functions/game/displayChessBoard.js +++ b/dist/functions/game/displayChessBoard.js @@ -15,9 +15,11 @@ exports.default = new forgescript_1.NativeFunction({ ], output: [forgescript_1.ArgType.String, forgescript_1.ArgType.Json], async execute(ctx, [id, type]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent; + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); if (!chess) return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); if (type == classes_1.ChessBoardDisplayType.Json) return this.successJSON(chess.display(type)); return this.success(chess.display(type ?? classes_1.ChessBoardDisplayType.Ascii)); diff --git a/dist/functions/game/displayChessBoard.js.map b/dist/functions/game/displayChessBoard.js.map index 621925b..cb3da18 100644 --- a/dist/functions/game/displayChessBoard.js.map +++ b/dist/functions/game/displayChessBoard.js.map @@ -1 +1 @@ -{"version":3,"file":"displayChessBoard.js","sourceRoot":"","sources":["../../../src/functions/game/displayChessBoard.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAA8D;AAE9D,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,oBAAoB;IAC1B,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,CAAC,eAAe,EAAE,aAAa,CAAC;IACzC,WAAW,EAAE,sBAAsB;IACnC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE;QACJ,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC;QAChD,iBAAG,CAAC,YAAY,CAAC,+BAAqB,EAAE,MAAM,EAAE,oBAAoB,CAAC;KACtE;IACD,MAAM,EAAE,CAAC,qBAAO,CAAC,MAAM,EAAE,qBAAO,CAAC,IAAI,CAAC;IACtC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC;QAC3B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAA;QAC1F,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,IAAI,IAAI,+BAAqB,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;QACpF,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,IAAI,+BAAqB,CAAC,KAAK,CAAC,CAAC,CAAA;IACzE,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"displayChessBoard.js","sourceRoot":"","sources":["../../../src/functions/game/displayChessBoard.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAA+E;AAE/E,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,oBAAoB;IAC1B,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,CAAC,eAAe,EAAE,aAAa,CAAC;IACzC,WAAW,EAAE,sBAAsB;IACnC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE;QACJ,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC;QAChD,iBAAG,CAAC,YAAY,CAAC,+BAAqB,EAAE,MAAM,EAAE,oBAAoB,CAAC;KACtE;IACD,MAAM,EAAE,CAAC,qBAAO,CAAC,MAAM,EAAE,qBAAO,CAAC,IAAI,CAAC;IACtC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC;QAC3B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAClH,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAA,yBAAe,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,YAAY,CAAC,CAAA;QAC1E,IAAI,IAAI,IAAI,+BAAqB,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;QACpF,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,IAAI,+BAAqB,CAAC,KAAK,CAAC,CAAC,CAAA;IACzE,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/lastPlayedMove.d.ts.map b/dist/functions/game/lastPlayedMove.d.ts.map index d986244..d11fbc7 100644 --- a/dist/functions/game/lastPlayedMove.d.ts.map +++ b/dist/functions/game/lastPlayedMove.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"lastPlayedMove.d.ts","sourceRoot":"","sources":["../../../src/functions/game/lastPlayedMove.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO,EAAsB,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;;AAEhF,wBAmBE"} \ No newline at end of file +{"version":3,"file":"lastPlayedMove.d.ts","sourceRoot":"","sources":["../../../src/functions/game/lastPlayedMove.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO,EAAsB,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;;AAEhF,wBAoBE"} \ No newline at end of file diff --git a/dist/functions/game/lastPlayedMove.js b/dist/functions/game/lastPlayedMove.js index e456ff8..531c1c1 100644 --- a/dist/functions/game/lastPlayedMove.js +++ b/dist/functions/game/lastPlayedMove.js @@ -16,9 +16,11 @@ exports.default = new forgescript_1.NativeFunction({ ], output: [forgescript_1.ArgType.Json, forgescript_1.ArgType.Unknown], async execute(ctx, [id, prop]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent; + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); if (!chess) return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); if (!chess.lastPlayedMove) return this.success(); if (!prop) diff --git a/dist/functions/game/lastPlayedMove.js.map b/dist/functions/game/lastPlayedMove.js.map index d8101b7..acdd1b3 100644 --- a/dist/functions/game/lastPlayedMove.js.map +++ b/dist/functions/game/lastPlayedMove.js.map @@ -1 +1 @@ -{"version":3,"file":"lastPlayedMove.js","sourceRoot":"","sources":["../../../src/functions/game/lastPlayedMove.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAuC;AACvC,wDAAgF;AAEhF,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,iBAAiB;IACvB,OAAO,EAAE,CAAC,gBAAgB,EAAE,oBAAoB,CAAC;IACjD,WAAW,EAAE,yCAAyC;IACtD,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE;QACJ,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC;QAChD,iBAAG,CAAC,YAAY,CAAC,2BAAgB,EAAE,UAAU,EAAE,sBAAsB,CAAC;KACvE;IACD,MAAM,EAAE,CAAC,qBAAO,CAAC,IAAI,EAAE,qBAAO,CAAC,OAAO,CAAC;IACvC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC;QAC3B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAA;QAC1F,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,KAAK,CAAC,cAAc;YAAE,OAAO,IAAI,CAAC,OAAO,EAAE,CAAA;QAChD,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,6BAAkB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAA;IACrE,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"lastPlayedMove.js","sourceRoot":"","sources":["../../../src/functions/game/lastPlayedMove.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAwD;AACxD,wDAAgF;AAEhF,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,iBAAiB;IACvB,OAAO,EAAE,CAAC,gBAAgB,EAAE,oBAAoB,CAAC;IACjD,WAAW,EAAE,yCAAyC;IACtD,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE;QACJ,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC;QAChD,iBAAG,CAAC,YAAY,CAAC,2BAAgB,EAAE,UAAU,EAAE,sBAAsB,CAAC;KACvE;IACD,MAAM,EAAE,CAAC,qBAAO,CAAC,IAAI,EAAE,qBAAO,CAAC,OAAO,CAAC;IACvC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC;QAC3B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAClH,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAA,yBAAe,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,YAAY,CAAC,CAAA;QAC1E,IAAI,CAAC,KAAK,CAAC,cAAc;YAAE,OAAO,IAAI,CAAC,OAAO,EAAE,CAAA;QAChD,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;QACxD,OAAO,IAAI,CAAC,OAAO,CAAC,6BAAkB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAA;IACrE,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/listChess.js b/dist/functions/game/listChess.js index 9105ffc..399c905 100644 --- a/dist/functions/game/listChess.js +++ b/dist/functions/game/listChess.js @@ -17,7 +17,7 @@ exports.default = new forgescript_1.NativeFunction({ output: (0, array_1.default)(), async execute(ctx, [sep]) { if (!ctx.client.chessManager || !(ctx.client.chessManager instanceof classes_1.ChessManager)) - ctx.client.chessManager = new classes_1.ChessManager(); + ctx.client.chessManager = new classes_1.ChessManager(ctx.client); return this.success(ctx.client.chessManager .list() .map((x) => x.id) diff --git a/dist/functions/game/listChess.js.map b/dist/functions/game/listChess.js.map index 8b2dad2..cf10080 100644 --- a/dist/functions/game/listChess.js.map +++ b/dist/functions/game/listChess.js.map @@ -1 +1 @@ -{"version":3,"file":"listChess.js","sourceRoot":"","sources":["../../../src/functions/game/listChess.ts"],"names":[],"mappings":";;;;;AAAA,uDAAoE;AACpE,uFAA8D;AAC9D,2CAA4C;AAE5C,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAC/C,WAAW,EAAE,8BAA8B;IAC3C,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;IACzD,MAAM,EAAE,IAAA,eAAK,GAAkB;IAC/B,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,YAAY,sBAAY,CAAC;YAChF,GAAG,CAAC,MAAM,CAAC,YAAY,GAAG,IAAI,sBAAY,EAAE,CAAA;QAC9C,OAAO,IAAI,CAAC,OAAO,CACjB,GAAG,CAAC,MAAM,CAAC,YAAY;aACpB,IAAI,EAAE;aACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChB,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,CACrB,CAAA;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"listChess.js","sourceRoot":"","sources":["../../../src/functions/game/listChess.ts"],"names":[],"mappings":";;;;;AAAA,uDAAoE;AACpE,uFAA8D;AAC9D,2CAA4C;AAE5C,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAC/C,WAAW,EAAE,8BAA8B;IAC3C,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;IACzD,MAAM,EAAE,IAAA,eAAK,GAAkB;IAC/B,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,YAAY,sBAAY,CAAC;YAChF,GAAG,CAAC,MAAM,CAAC,YAAY,GAAG,IAAI,sBAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACxD,OAAO,IAAI,CAAC,OAAO,CACjB,GAAG,CAAC,MAAM,CAAC,YAAY;aACpB,IAAI,EAAE;aACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChB,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,CACrB,CAAA;IACH,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/functions/game/setChessOption.d.ts b/dist/functions/game/setChessOption.d.ts new file mode 100644 index 0000000..8f0fb12 --- /dev/null +++ b/dist/functions/game/setChessOption.d.ts @@ -0,0 +1,5 @@ +import { ArgType, NativeFunction } from "@tryforge/forgescript"; +import { ChessOptions } from "../../classes"; +declare const _default: NativeFunction<[import("@tryforge/forgescript").IArg, import("@tryforge/forgescript").IArg, import("@tryforge/forgescript").IArg], true>; +export default _default; +//# sourceMappingURL=setChessOption.d.ts.map \ No newline at end of file diff --git a/dist/functions/game/setChessOption.d.ts.map b/dist/functions/game/setChessOption.d.ts.map new file mode 100644 index 0000000..4eb8a6b --- /dev/null +++ b/dist/functions/game/setChessOption.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"setChessOption.d.ts","sourceRoot":"","sources":["../../../src/functions/game/setChessOption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,EAAE,YAAY,EAA4B,MAAM,eAAe,CAAA;;AAEtE,wBA8BE"} \ No newline at end of file diff --git a/dist/functions/game/setChessOption.js b/dist/functions/game/setChessOption.js new file mode 100644 index 0000000..f4f22a9 --- /dev/null +++ b/dist/functions/game/setChessOption.js @@ -0,0 +1,40 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const forgescript_1 = require("@tryforge/forgescript"); +const classes_1 = require("../../classes"); +exports.default = new forgescript_1.NativeFunction({ + name: "$setChessOption", + aliases: ["$setChessGameOption", "$chessOption"], + description: "Set the game options", + version: "1.0.0", + brackets: true, + unwrap: true, + args: [ + forgescript_1.Arg.requiredString("id", "ID of the chess game"), + forgescript_1.Arg.requiredEnum(classes_1.ChessOptions, "option", "The option to update."), + forgescript_1.Arg.requiredString("value", "The value to set."), + ], + output: forgescript_1.ArgType.Json, + async execute(ctx, [id, opt, value]) { + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); + if (!chess) + return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); + switch (opt) { + case classes_1.ChessOptions.FlipBoard: + chess.options.display.flip = bool(value, true); + break; + case classes_1.ChessOptions.ShowCoordinates: + chess.options.display.coords = bool(value, true); + break; + default: + break; + } + return this.successJSON(chess.options); + }, +}); +function bool(value, def) { + return value.toLowerCase() == "true" ? true : value.toLowerCase() == "false" ? false : def; +} +//# sourceMappingURL=setChessOption.js.map \ No newline at end of file diff --git a/dist/functions/game/setChessOption.js.map b/dist/functions/game/setChessOption.js.map new file mode 100644 index 0000000..00caef7 --- /dev/null +++ b/dist/functions/game/setChessOption.js.map @@ -0,0 +1 @@ +{"version":3,"file":"setChessOption.js","sourceRoot":"","sources":["../../../src/functions/game/setChessOption.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAsE;AAEtE,kBAAe,IAAI,4BAAc,CAAC;IAChC,IA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A;gBAChD,MAAK;YACP;gBACE,MAAK;QACT,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACxC,CAAC;CACF,CAAC,CAAA;AAEF,SAAS,IAAI,CAAC,KAAa,EAAE,GAAY;IACvC,OAAO,KAAK,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAA;AAC5F,CAAC"} \ No newline at end of file diff --git a/dist/functions/game/undoMove.d.ts.map b/dist/functions/game/undoMove.d.ts.map index 1cb7101..ce10792 100644 --- a/dist/functions/game/undoMove.d.ts.map +++ b/dist/functions/game/undoMove.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"undoMove.d.ts","sourceRoot":"","sources":["../../../src/functions/game/undoMove.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAGpE,wBAcE"} \ No newline at end of file +{"version":3,"file":"undoMove.d.ts","sourceRoot":"","sources":["../../../src/functions/game/undoMove.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;;AAGpE,wBAeE"} \ No newline at end of file diff --git a/dist/functions/game/undoMove.js b/dist/functions/game/undoMove.js index 91274b9..bdbd269 100644 --- a/dist/functions/game/undoMove.js +++ b/dist/functions/game/undoMove.js @@ -12,9 +12,11 @@ exports.default = new forgescript_1.NativeFunction({ args: [forgescript_1.Arg.optionalString("id", "ID of the chess game")], output: forgescript_1.ArgType.Boolean, async execute(ctx, [id]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent; + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras); if (!chess) return this.customError(classes_1.FCError.NoChess); + if (!(0, classes_1.isChessInstance)(chess)) + return this.customError(classes_1.FCError.InvalidChess); return this.success(chess.undoMove()); }, }); diff --git a/dist/functions/game/undoMove.js.map b/dist/functions/game/undoMove.js.map index 44aae8e..075e38f 100644 --- a/dist/functions/game/undoMove.js.map +++ b/dist/functions/game/undoMove.js.map @@ -1 +1 @@ -{"version":3,"file":"undoMove.js","sourceRoot":"","sources":["../../../src/functions/game/undoMove.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAuC;AAEvC,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAC5C,WAAW,EAAE,mCAAmC;IAChD,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IACxD,MAAM,EAAE,qBAAO,CAAC,OAAO;IACvB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAA;QAC1F,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;IACvC,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"undoMove.js","sourceRoot":"","sources":["../../../src/functions/game/undoMove.ts"],"names":[],"mappings":";;AAAA,uDAAoE;AACpE,2CAAwD;AAExD,kBAAe,IAAI,4BAAc,CAAC;IAChC,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAC5C,WAAW,EAAE,mCAAmC;IAChD,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,CAAC,iBAAG,CAAC,cAAc,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IACxD,MAAM,EAAE,qBAAO,CAAC,OAAO;IACvB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAClH,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,IAAA,yBAAe,EAAC,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC,iBAAO,CAAC,YAAY,CAAC,CAAA;QAC1E,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;IACvC,CAAC;CACF,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index b5bdae4..460f50f 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,12 +1,26 @@ import { ForgeClient, ForgeExtension } from "@tryforge/forgescript"; import { ChessManager } from "./classes"; +import { TypedEmitter } from "tiny-typed-emitter"; +import { IChessEvents } from "./classes/event"; +import { ForgeChessCommandManager } from "./classes/commands"; +export interface IForgeChessOptions { + events?: Array; +} +export type TransformEvents = { + [P in keyof T]: T[P] extends any[] ? (...args: T[P]) => any : never; +}; export type DeepPartial = { [P in keyof T]?: DeepPartial | undefined; }; export declare class ForgeChess extends ForgeExtension { + readonly options: IForgeChessOptions; name: string; description: string; version: string; + emitter: TypedEmitter>; + private client; + commands: ForgeChessCommandManager; + constructor(options: IForgeChessOptions); init(client: ForgeClient): void; } declare module "@tryforge/forgescript" { diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map index 28eec4b..e55d3c0 100644 --- a/dist/index.d.ts.map +++ b/dist/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAAE,CAAA;AAC/E,qBAAa,UAAW,SAAQ,cAAc;IACrC,IAAI,EAAE,MAAM,CAAe;IAC3B,WAAW,EAAE,MAAM,CAAyC;IAC5D,OAAO,EAAE,MAAM,CAAqC;IAEpD,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;CAGvC;AAED,OAAO,QAAQ,uBAAuB,CAAC;IACrC,UAAU,WAAW;QACnB,YAAY,CAAC,EAAE,YAAY,CAAA;KAC5B;CACF;AAED,cAAc,WAAW,CAAA"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAyB,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAEpF,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,YAAY,CAAC,CAAA;CACnC;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;KAC9B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,KAAK;CACpE,CAAA;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS;CAAE,CAAA;AAC/E,qBAAa,UAAW,SAAQ,cAAc;aAST,OAAO,EAAE,kBAAkB;IARvD,IAAI,EAAE,MAAM,CAAe;IAC3B,WAAW,EAAE,MAAM,CAAyC;IAC5D,OAAO,EAAE,MAAM,CAAqC;IAEpD,OAAO,8CAAoD;IAClE,OAAO,CAAC,MAAM,CAAc;IACrB,QAAQ,EAAG,wBAAwB,CAAA;gBAEP,OAAO,EAAE,kBAAkB;IAIvD,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;CAQvC;AAED,OAAO,QAAQ,uBAAuB,CAAC;IACrC,UAAU,WAAW;QACnB,YAAY,CAAC,EAAE,YAAY,CAAA;KAC5B;CACF;AAED,cAAc,WAAW,CAAA"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 36bfc64..2b536eb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -17,12 +17,27 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.ForgeChess = void 0; const forgescript_1 = require("@tryforge/forgescript"); const path_1 = require("path"); +const tiny_typed_emitter_1 = require("tiny-typed-emitter"); +const commands_1 = require("./classes/commands"); class ForgeChess extends forgescript_1.ForgeExtension { + options; name = "ForgeChess"; description = require("../package.json").description; version = require("../package.json").version; + emitter = new tiny_typed_emitter_1.TypedEmitter(); + client; + commands; + constructor(options) { + super(); + this.options = options; + } init(client) { + this.client = client; + this.commands = new commands_1.ForgeChessCommandManager(client); + forgescript_1.EventManager.load(commands_1.ChessEventManagerName, __dirname + "/events"); this.load((0, path_1.join)(__dirname, "functions")); + if (this.options.events?.length) + this.client.events.load(commands_1.ChessEventManagerName, this.options.events); } } exports.ForgeChess = ForgeChess; diff --git a/dist/index.js.map b/dist/index.js.map index b4b6416..0fc0b29 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uDAAmE;AACnE,+BAA2B;AAI3B,MAAa,UAAW,SAAQ,4BAAc;IACrC,IAAI,GAAW,YAAY,CAAA;IAC3B,WAAW,GAAW,OAAO,CAAC,iBAAiB,CAAC,CAAC,WAAW,CAAA;IAC5D,OAAO,GAAW,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAA;IAEpD,IAAI,CAAC,MAAmB;QAC7B,IAAI,CAAC,IAAI,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAA;IACzC,CAAC;CACF;AARD,gCAQC;AAQD,4CAAyB"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uDAAiF;AACjF,+BAA2B;AAE3B,2DAAiD;AAEjD,iDAAoF;AAWpF,MAAa,UAAW,SAAQ,4BAAc;IAST;IAR5B,IAAI,GAAW,YAAY,CAAA;IAC3B,WAAW,GAAW,OAAO,CAAC,iBAAiB,CAAC,CAAC,WAAW,CAAA;IAC5D,OAAO,GAAW,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAA;IAEpD,OAAO,GAAG,IAAI,iCAAY,EAAiC,CAAA;IAC1D,MAAM,CAAc;IACrB,QAAQ,CAA2B;IAE1C,YAAmC,OAA2B;QAC5D,KAAK,EAAE,CAAA;QAD0B,YAAO,GAAP,OAAO,CAAoB;IAE9D,CAAC;IAEM,IAAI,CAAC,MAAmB;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,mCAAwB,CAAC,MAAM,CAAC,CAAA;QACpD,0BAAY,CAAC,IAAI,CAAC,gCAAqB,EAAE,SAAS,GAAG,SAAS,CAAC,CAAA;QAC/D,IAAI,CAAC,IAAI,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAA;QAEvC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM;YAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAqB,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACtG,CAAC;CACF;AArBD,gCAqBC;AAQD,4CAAyB"} \ No newline at end of file diff --git a/docs/assets/navigation.js b/docs/assets/navigation.js index b40c3b0..8604341 100644 --- a/docs/assets/navigation.js +++ b/docs/assets/navigation.js @@ -1 +1 @@ -window.navigationData = "eJx90U0LwjAMBuD/kvNwOvFrRz8GHkQP3sRD1OiKXVeSKg7xvwsyXKfOa9+8TwrZ3MHRzUEMk5RExjnyYarEaizWhSUIwKJLIQYyl0zCn0Ot1GUaAjgrc4B4+AjeZjKZMef8qZTPzb3Xmqq11yhC5fZ6qxN99RZo8ETcUC/Tf0qS84kavlBl/4T5a2JpncqNhyjjiI+4JwlrE3Uq6vU9akpkV8hOoa4gV1iS0Is+hPZo0OlFnuKfrGKuyAp3miT087rVjR7bJ6JzuQA=" \ No newline at end of file +window.navigationData = "eJyF01FPgzAQB/Dv0mciDt1U3pRtCQ9GE/dmfLixYzSUUntlkZh9dxOCoe1gvPK/+93RwucvM/hjWMySAoleatCHNScloN21ClnAFJiCxQxlU1E4WnRTmEqwgJVcHlj8eA5c800ZXksapfpsWtgmG61r7Tf3j2cmD12ZACLsh7pdi+ii7xUkHFFPtPfpNWVb6yNOrDBks3tsTihNAkLsISsHiUuDOofsfyGnzEWj5cpC0/H7sLx0+lY8aniNq95F2TX02RjIyo/vBrT15ZlWIYV25hm3Tw+LZTR6eL4yJHPGGlG9gzYchI9Y0Zyy0yApr3XVzSRf8uI5zf7xBuoEmsNeIIV27lp3NsOpO4ZUkgGZWSedNzLrLin0SlxsdX/++gNGb26l" \ No newline at end of file diff --git a/docs/assets/search.js b/docs/assets/search.js index 81e067b..5366c45 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = "eJytmduOnDgQht/Fc4tmusp9vstOEimRcpB2tTdoFJHGk7ChAQE9u6PRvPvKnFyF3bQb5apbUPVX2f6qMOZFlPm/ldiHL+JXksVivw1EFh2V2Iv7n6qq/sijMn6bVEUaPf/1XCgRiFOZir1Q2elY3Tltbn/Wx1QE4pBGVaUqsRfiNej1YT0EeFMdksRb8CbqzIlsIIqoVFl9Nltn3PfvPvtHfVTZ74j5scoz/6D/tNbzopoVfH//rizzchS3u+q7Sp/zJuCEyE2WHzoTd8Z9HkQfR5wN8p1COzuTOa4AB41DnlV1eTrUZLS20g03m5hemuoClyZOmmirqRC9xQz1JJ5Sbu7OUE2jqv6aRs8q/pQ/qakI2rJoLI+t5YxoeVEneTa1njfGxE8f1whLE0Hndp+fppdBGx06I88oi6VhMnqKkjT6nio9ZZODGSyPneWMaIdTqc2aRZrmtzUsesMZseK2Z0xFMSYz9I/RL3WJM21zFWEsQp1//PPL5yn9Or/cQM+pn7I4v5S/trmuQsbt7lOURT/OrXV38/c1Pyro3wP7HM+1wpZFn4iD5fxox6jwiNRaXRVl1Fx0C7z3Hpm2njk6Bt0P5ROttZofJU0qr0G1ZvPjlH1xX4pUenSBC7Eqr5mrrp85WrLv8/KHcm9TzK3fUq4jOa9iJdmdKZ5YVYcy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l/BJs4jhGguEixB2W1vDA+U4YAGmCOgZnmFKQNmNWBW8xZ1he8HGpRG89Zf8P+LRjXYpFha/VFyMFegTSnekOr+gzuxhwDtxfLQaY+0gIkCBFvedI8H2MG4QCaKV+jhtB6YLtB7DYPkh0js073L0tyJu/XD6+v/Ac6vVwE="; \ No newline at end of file diff --git a/docs/classes/Chess.html b/docs/classes/Chess.html index e0f418e..665864b 100644 --- a/docs/classes/Chess.html +++ b/docs/classes/Chess.html @@ -1,13 +1,15 @@ -Chess | @weebforge/chess
@weebforge/chess
    Preparing search index...

    Class Chess

    Index

    Constructors

    constructor +Chess | @weebforge/chess
    @weebforge/chess
      Preparing search index...

      Class Chess

      Index

      Constructors

      Properties

      client: AlgebraicGameClient = ...
      id: string
      lastPlayedMove: PlayedMove | null = null
      options: IChessOptions

      Accessors

      Methods

      • Parameters

        • san: boolean = true

        Returns string[]

      • Parameters

        • notation: string

        Returns PlayedMove

      • Returns {
            captures: Piece[];
            fen: string;
            id: string;
            moves: {
                history: Move[];
                notated: Record<string, NotatedMove>;
                valid: ValidMove[];
            };
            options: IChessOptions;
            status: AlgebraicGameStatus;
        }

      +

      Constructors

      Properties

      client: AlgebraicGameClient = ...
      id: string
      lastPlayedMove: PlayedMove | null = null
      manager: ChessManager
      options: IChessOptions

      Accessors

      Methods

      • Parameters

        • san: boolean = true

        Returns string[]

      • Parameters

        • notation: string

        Returns PlayedMove

      • Returns {
            captures: Piece[];
            fen: string;
            id: string;
            moves: {
                history: Move[];
                notated: Record<string, NotatedMove>;
                valid: ValidMove[];
            };
            options: IChessOptions;
            status: AlgebraicGameStatus;
        }

      diff --git a/docs/classes/ChessManager.html b/docs/classes/ChessManager.html index 071e3ba..56ce3ce 100644 --- a/docs/classes/ChessManager.html +++ b/docs/classes/ChessManager.html @@ -1,9 +1,10 @@ -ChessManager | @weebforge/chess
      @weebforge/chess
        Preparing search index...

        Class ChessManager

        Index

        Constructors

        Properties

        current +ChessManager | @weebforge/chess
        @weebforge/chess
          Preparing search index...

          Class ChessManager

          Index

          Constructors

          Properties

          Accessors

          Methods

          Constructors

          Properties

          current: Chess[] = []
          map: Map<string, Chess> = ...

          Accessors

          Methods

          +

          Constructors

          Properties

          client: ForgeClient
          current: Chess[] = []
          map: Map<string, Chess> = ...

          Accessors

          Methods

          diff --git a/docs/classes/ForgeChess.html b/docs/classes/ForgeChess.html index 70d948a..fc24f1f 100644 --- a/docs/classes/ForgeChess.html +++ b/docs/classes/ForgeChess.html @@ -1,6 +1,9 @@ -ForgeChess | @weebforge/chess
          @weebforge/chess
            Preparing search index...

            Class ForgeChess

            Hierarchy

            • ForgeExtension
              • ForgeChess
            Index

            Constructors

            Properties

            description +ForgeChess | @weebforge/chess
            @weebforge/chess
              Preparing search index...

              Class ForgeChess

              Hierarchy

              • ForgeExtension
                • ForgeChess
              Index

              Constructors

              Properties

              description: string = ...
              name: string = "ForgeChess"
              requireExtensions?: string[]

              A list of extension names this extension requires

              +

              Constructors

              Properties

              commands: ForgeChessCommandManager
              description: string = ...
              emitter: TypedEmitter<TransformEvents<IChessEvents>> = ...
              name: string = "ForgeChess"
              requireExtensions?: string[]

              A list of extension names this extension requires

              targetVersions?: string[]

              Only the versions written here will be allowed

              -
              version: string = ...

              Methods

              • Returns any

              • Parameters

                • client: ForgeClient

                Returns void

              • Parameters

                • path: string

                Returns void

              • Parameters

                • client: ForgeClient

                Returns void

              +
              version: string = ...

              Methods

              • Returns any

              • Parameters

                • client: ForgeClient

                Returns void

              • Parameters

                • path: string

                Returns void

              • Parameters

                • client: ForgeClient

                Returns void

              diff --git a/docs/enums/ChessBoardDisplayType.html b/docs/enums/ChessBoardDisplayType.html index 576cb60..115bf22 100644 --- a/docs/enums/ChessBoardDisplayType.html +++ b/docs/enums/ChessBoardDisplayType.html @@ -1,4 +1,4 @@ -ChessBoardDisplayType | @weebforge/chess
              @weebforge/chess
                Preparing search index...

                Enumeration ChessBoardDisplayType

                Index

                Enumeration Members

                Ascii +ChessBoardDisplayType | @weebforge/chess
                @weebforge/chess
                  Preparing search index...

                  Enumeration ChessBoardDisplayType

                  Index

                  Enumeration Members

                  Enumeration Members

                  Ascii: "ascii"
                  FEN: "fen"
                  Json: "json"
                  +

                  Enumeration Members

                  Ascii: "ascii"
                  FEN: "fen"
                  Json: "json"
                  diff --git a/docs/enums/ChessOptions.html b/docs/enums/ChessOptions.html new file mode 100644 index 0000000..7de8a09 --- /dev/null +++ b/docs/enums/ChessOptions.html @@ -0,0 +1,4 @@ +ChessOptions | @weebforge/chess
                  @weebforge/chess
                    Preparing search index...

                    Enumeration ChessOptions

                    For set option function

                    +
                    Index

                    Enumeration Members

                    Enumeration Members

                    FlipBoard: 0
                    ShowCoordinates: 1
                    diff --git a/docs/enums/FCError.html b/docs/enums/FCError.html index dfcd66d..c7cbcbf 100644 --- a/docs/enums/FCError.html +++ b/docs/enums/FCError.html @@ -1,2 +1,3 @@ -FCError | @weebforge/chess
                    @weebforge/chess
                      Preparing search index...

                      Enumeration FCError

                      Index

                      Enumeration Members

                      Enumeration Members

                      NoChess: "No chess game found."
                      +FCError | @weebforge/chess
                      @weebforge/chess
                        Preparing search index...

                        Enumeration FCError

                        Index

                        Enumeration Members

                        Enumeration Members

                        InvalidChess: "This is not a chess game."
                        NoChess: "No chess game found."
                        diff --git a/docs/functions/isChessInstance.html b/docs/functions/isChessInstance.html new file mode 100644 index 0000000..b4df603 --- /dev/null +++ b/docs/functions/isChessInstance.html @@ -0,0 +1 @@ +isChessInstance | @weebforge/chess
                        @weebforge/chess
                          Preparing search index...

                          Function isChessInstance

                          diff --git a/docs/interfaces/ChessEventCallback.html b/docs/interfaces/ChessEventCallback.html new file mode 100644 index 0000000..845bd23 --- /dev/null +++ b/docs/interfaces/ChessEventCallback.html @@ -0,0 +1,8 @@ +ChessEventCallback | @weebforge/chess
                          @weebforge/chess
                            Preparing search index...

                            Interface ChessEventCallback

                            interface ChessEventCallback {
                                castle: (move: PlayedMove) => unknown;
                                check: (attack: AttackSquare) => unknown;
                                checkmate: (attack: AttackSquare) => unknown;
                                enPassant: (move: PlayedMove) => unknown;
                                move: (move: PlayedMove) => unknown;
                                promote: (square: Square) => unknown;
                                undo: (move: PlayedMove) => unknown;
                            }

                            Hierarchy

                            • Record<
                                  "move"
                                  | "undo"
                                  | "castle"
                                  | "enPassant",
                                  (move: PlayedMove) => unknown | Promise<unknown>,
                              >
                              • ChessEventCallback
                            Index

                            Properties

                            castle: (move: PlayedMove) => unknown
                            check: (attack: AttackSquare) => unknown
                            checkmate: (attack: AttackSquare) => unknown
                            enPassant: (move: PlayedMove) => unknown
                            move: (move: PlayedMove) => unknown
                            promote: (square: Square) => unknown
                            undo: (move: PlayedMove) => unknown
                            diff --git a/docs/interfaces/IChessOptions.html b/docs/interfaces/IChessOptions.html index 96cc133..5ed6739 100644 --- a/docs/interfaces/IChessOptions.html +++ b/docs/interfaces/IChessOptions.html @@ -1,2 +1,2 @@ -IChessOptions | @weebforge/chess
                            @weebforge/chess
                              Preparing search index...

                              Interface IChessOptions

                              interface IChessOptions {
                                  display: { coords: boolean; flip: boolean };
                              }
                              Index

                              Properties

                              Properties

                              display: { coords: boolean; flip: boolean }
                              +IChessOptions | @weebforge/chess
                              @weebforge/chess
                                Preparing search index...

                                Interface IChessOptions

                                interface IChessOptions {
                                    display: { coords: boolean; flip: boolean };
                                }
                                Index

                                Properties

                                Properties

                                display: { coords: boolean; flip: boolean }
                                diff --git a/docs/interfaces/IForgeChessOptions.html b/docs/interfaces/IForgeChessOptions.html new file mode 100644 index 0000000..deb14e3 --- /dev/null +++ b/docs/interfaces/IForgeChessOptions.html @@ -0,0 +1,2 @@ +IForgeChessOptions | @weebforge/chess
                                @weebforge/chess
                                  Preparing search index...

                                  Interface IForgeChessOptions

                                  interface IForgeChessOptions {
                                      events?: (keyof IChessEvents)[];
                                  }
                                  Index

                                  Properties

                                  Properties

                                  events?: (keyof IChessEvents)[]
                                  diff --git a/docs/modules.html b/docs/modules.html index f441852..fa19bda 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -1 +1 @@ -@weebforge/chess
                                  @weebforge/chess
                                    Preparing search index...

                                      @weebforge/chess

                                      Enumerations

                                      ChessBoardDisplayType
                                      FCError

                                      Classes

                                      Chess
                                      ChessManager
                                      ForgeChess

                                      Interfaces

                                      IChessOptions

                                      Type Aliases

                                      DeepPartial

                                      Variables

                                      BoardDisplay
                                      +@weebforge/chess
                                      @weebforge/chess
                                        Preparing search index...
                                        diff --git a/docs/types/AttackSquare.html b/docs/types/AttackSquare.html new file mode 100644 index 0000000..e1cba85 --- /dev/null +++ b/docs/types/AttackSquare.html @@ -0,0 +1 @@ +AttackSquare | @weebforge/chess
                                        @weebforge/chess
                                          Preparing search index...

                                          Type Alias AttackSquare

                                          AttackSquare: Record<"attackingSquare" | "kingSquare", Square>
                                          diff --git a/docs/types/ChessEvent.html b/docs/types/ChessEvent.html new file mode 100644 index 0000000..6fddb2a --- /dev/null +++ b/docs/types/ChessEvent.html @@ -0,0 +1 @@ +ChessEvent | @weebforge/chess
                                          @weebforge/chess
                                            Preparing search index...

                                            Type Alias ChessEvent

                                            ChessEvent: keyof ChessEventCallback
                                            diff --git a/docs/types/DeepPartial.html b/docs/types/DeepPartial.html index 19d9abf..a4b725e 100644 --- a/docs/types/DeepPartial.html +++ b/docs/types/DeepPartial.html @@ -1 +1 @@ -DeepPartial | @weebforge/chess
                                            @weebforge/chess
                                              Preparing search index...

                                              Type Alias DeepPartial<T>

                                              DeepPartial: { [P in keyof T]?: DeepPartial<T[P]> }

                                              Type Parameters

                                              • T
                                              +DeepPartial | @weebforge/chess
                                              @weebforge/chess
                                                Preparing search index...

                                                Type Alias DeepPartial<T>

                                                DeepPartial: { [P in keyof T]?: DeepPartial<T[P]> }

                                                Type Parameters

                                                • T
                                                diff --git a/docs/types/TransformEvents.html b/docs/types/TransformEvents.html new file mode 100644 index 0000000..99fe145 --- /dev/null +++ b/docs/types/TransformEvents.html @@ -0,0 +1 @@ +TransformEvents | @weebforge/chess
                                                @weebforge/chess
                                                  Preparing search index...

                                                  Type Alias TransformEvents<T>

                                                  TransformEvents: {
                                                      [P in keyof T]: T[P] extends any[] ? (...args: T[P]) => any : never
                                                  }

                                                  Type Parameters

                                                  • T
                                                  diff --git a/docs/variables/BoardDisplay.html b/docs/variables/BoardDisplay.html index f937545..3dfaa8d 100644 --- a/docs/variables/BoardDisplay.html +++ b/docs/variables/BoardDisplay.html @@ -1 +1 @@ -BoardDisplay | @weebforge/chess
                                                  @weebforge/chess
                                                    Preparing search index...

                                                    Variable BoardDisplayConst

                                                    BoardDisplay: {
                                                        Ascii(
                                                            board: ChessBoard,
                                                            whiteAtBottom?: boolean,
                                                            coords?: boolean,
                                                        ): string;
                                                    } = ...

                                                    Type Declaration

                                                    • Ascii: function
                                                      • Parameters

                                                        • board: ChessBoard
                                                        • whiteAtBottom: boolean = true
                                                        • coords: boolean = true

                                                        Returns string

                                                    +BoardDisplay | @weebforge/chess
                                                    @weebforge/chess
                                                      Preparing search index...

                                                      Variable BoardDisplayConst

                                                      BoardDisplay: {
                                                          Ascii(
                                                              board: ChessBoard,
                                                              whiteAtBottom?: boolean,
                                                              coords?: boolean,
                                                          ): string;
                                                      } = ...

                                                      Type Declaration

                                                      • Ascii: function
                                                        • Parameters

                                                          • board: ChessBoard
                                                          • whiteAtBottom: boolean = true
                                                          • coords: boolean = true

                                                          Returns string

                                                      diff --git a/metadata/changelogs.json b/metadata/changelogs.json index b8ab57f..1402dba 100644 --- a/metadata/changelogs.json +++ b/metadata/changelogs.json @@ -1 +1 @@ -{"1.0.0":[{"message":"Game data and Last move properties and functions","timestamp":"2026-02-11T07:39:18.043Z","author":"user-lezi"},{"message":"Undo Move","timestamp":"2026-02-11T06:46:32.060Z","author":"user-lezi"},{"message":"Output fix for chess display","timestamp":"2026-02-11T06:33:19.626Z","author":"user-lezi"},{"message":"Minor Fixes","timestamp":"2026-02-11T06:29:06.208Z","author":"user-lezi"},{"message":"Basic Functions","timestamp":"2026-02-10T15:33:31.601Z","author":"user-lezi"},{"message":"Initialize ForgeChess","timestamp":"2026-02-09T13:13:39.211Z","author":"user-lezi"}]} \ No newline at end of file +{"1.0.0":[{"message":"Chess Options Updater","timestamp":"2026-02-19T12:21:47.236Z","author":"user-lezi"},{"message":"Added chess events","timestamp":"2026-02-19T11:48:53.304Z","author":"user-lezi"},{"message":"Chess Instance from the evenet now supported in all the functions","timestamp":"2026-02-19T10:39:22.678Z","author":"user-lezi"},{"message":"Start event","timestamp":"2026-02-19T10:19:32.519Z","author":"user-lezi"},{"message":"Delete game function","timestamp":"2026-02-12T09:15:09.459Z","author":"user-lezi"},{"message":"Game data and Last move properties and functions","timestamp":"2026-02-11T07:39:18.043Z","author":"user-lezi"},{"message":"Undo Move","timestamp":"2026-02-11T06:46:32.060Z","author":"user-lezi"},{"message":"Output fix for chess display","timestamp":"2026-02-11T06:33:19.626Z","author":"user-lezi"},{"message":"Minor Fixes","timestamp":"2026-02-11T06:29:06.208Z","author":"user-lezi"},{"message":"Basic Functions","timestamp":"2026-02-10T15:33:31.601Z","author":"user-lezi"},{"message":"Initialize ForgeChess","timestamp":"2026-02-09T13:13:39.211Z","author":"user-lezi"}]} \ No newline at end of file diff --git a/metadata/enums.json b/metadata/enums.json index 6901c04..a81a729 100644 --- a/metadata/enums.json +++ b/metadata/enums.json @@ -1 +1 @@ -{"ChessGameProperty":["id","isStalement","isCheckmate","isCheck","isRepetition","fen","moveCount","availableMoves","movesHistory","player","lastMove"],"ChessBoardDisplayType":["Ascii","FEN","Json"],"LastMoveProperty":["algebraic","castle","enPassant","source","destination","piece","player","capture","capturedPiece"]} \ No newline at end of file +{"ChessGameProperty":["id","isStalement","isCheckmate","isCheck","isRepetition","fen","moveCount","availableMoves","movesHistory","player","lastMove"],"ChessBoardDisplayType":["Ascii","FEN","Json"],"LastMoveProperty":["algebraic","castle","enPassant","source","destination","piece","player","capture","capturedPiece"],"ChessOptions":["FlipBoard","ShowCoordinates"]} \ No newline at end of file diff --git a/metadata/functions.json b/metadata/functions.json index f1b27a8..331958f 100644 --- a/metadata/functions.json +++ b/metadata/functions.json @@ -1 +1 @@ -[{"name":"$chessGameData","aliases":["$chessGameProperty","$getChessGame"],"description":"Get the data about chess game.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"property","description":"The property to pull","rest":false,"type":"Enum","enum":["id","isStalement","isCheckmate","isCheck","isRepetition","fen","moveCount","availableMoves","movesHistory","player","lastMove"],"enumName":"ChessGameProperty"},{"name":"sep","description":"The seperator to use incase of array","rest":false,"type":"String"}],"output":["Json","Unknown"],"category":"game"},{"name":"$chessMove","aliases":["$playChessMove"],"description":"Play a move in chess.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"moves","description":"The moves to play","rest":true,"required":false,"type":"String"}],"category":"game"},{"name":"$chessMoveCount","description":"Move count of a chess game.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"}],"output":["Number"],"category":"game"},{"name":"$chessMoveList","aliases":["$availableChessMoves","$chessMoves"],"description":"List of playable moves.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"sep","description":"The seperator to use","rest":false,"type":"String"},{"name":"san","description":"Standard Algebraic Notation","rest":false,"type":"Boolean"}],"output":["String[]"],"category":"game"},{"name":"$createChess","aliases":["$chess","$chessGame"],"description":"Create a new chess game.","version":"1.0.0","brackets":true,"unwrap":false,"args":[{"name":"id","description":"An unique game ID","rest":false,"required":true,"type":"String"},{"name":"functions","description":"Functions","rest":true,"required":false,"type":"String"}],"category":"game"},{"name":"$currentChessPlayer","aliases":["$chessPlayer","$playerToPlay"],"description":"Current player turn of a chess game. (black or white)","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"}],"output":["String"],"category":"game"},{"name":"$displayChessBoard","version":"1.0.0","aliases":["$displayChess","$chessBoard"],"description":"Display chess board.","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"type","description":"Board display type","rest":false,"type":"Enum","enum":["Ascii","FEN","Json"],"enumName":"ChessBoardDisplayType"}],"output":["String","Json"],"category":"game"},{"name":"$lastPlayedMove","aliases":["$lastChessMove","$getLastPlayedMove"],"description":"Get the data about the last played move","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"property","description":"The property to pull","rest":false,"type":"Enum","enum":["algebraic","castle","enPassant","source","destination","piece","player","capture","capturedPiece"],"enumName":"LastMoveProperty"}],"output":["Json","Unknown"],"category":"game"},{"name":"$listChess","aliases":["$listChessGames","$chessGamesList"],"description":"List all the chess game IDs.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"sep","description":"The separator to use","rest":false,"type":"String"}],"output":["String[]"],"category":"game"},{"name":"$undoMove","aliases":["$undoLastMove","$undoChessMove"],"description":"Undo the last Move in chess game.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"}],"output":["Boolean"],"category":"game"}] \ No newline at end of file +[{"name":"$chessGameData","aliases":["$chessGameProperty","$getChessGame"],"description":"Get the data about chess game.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"property","description":"The property to pull","rest":false,"type":"Enum","enum":["id","isStalement","isCheckmate","isCheck","isRepetition","fen","moveCount","availableMoves","movesHistory","player","lastMove"],"enumName":"ChessGameProperty"},{"name":"sep","description":"The seperator to use incase of array","rest":false,"type":"String"}],"output":["Json","Unknown"],"category":"game"},{"name":"$chessMove","aliases":["$playChessMove"],"description":"Play a move in chess.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"moves","description":"The moves to play","rest":true,"required":false,"type":"String"}],"category":"game"},{"name":"$chessMoveCount","description":"Move count of a chess game.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"}],"output":["Number"],"category":"game"},{"name":"$chessMoveList","aliases":["$availableChessMoves","$chessMoves"],"description":"List of playable moves.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"sep","description":"The seperator to use","rest":false,"type":"String"},{"name":"san","description":"Standard Algebraic Notation","rest":false,"type":"Boolean"}],"output":["String[]"],"category":"game"},{"name":"$createChess","aliases":["$chess","$chessGame"],"description":"Create a new chess game.","version":"1.0.0","brackets":true,"unwrap":false,"args":[{"name":"id","description":"An unique game ID","rest":false,"required":true,"type":"String"},{"name":"functions","description":"Functions","rest":true,"required":false,"type":"String"}],"category":"game"},{"name":"$currentChessPlayer","aliases":["$chessPlayer","$playerToPlay"],"description":"Current player turn of a chess game. (black or white)","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"}],"output":["String"],"category":"game"},{"name":"$deleteChess","aliases":["$deleteClassGame"],"description":"Deletes the chess game from the manager.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"}],"output":["Boolean"],"category":"game"},{"name":"$displayChessBoard","version":"1.0.0","aliases":["$displayChess","$chessBoard"],"description":"Display chess board.","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"type","description":"Board display type","rest":false,"type":"Enum","enum":["Ascii","FEN","Json"],"enumName":"ChessBoardDisplayType"}],"output":["String","Json"],"category":"game"},{"name":"$lastPlayedMove","aliases":["$lastChessMove","$getLastPlayedMove"],"description":"Get the data about the last played move","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"},{"name":"property","description":"The property to pull","rest":false,"type":"Enum","enum":["algebraic","castle","enPassant","source","destination","piece","player","capture","capturedPiece"],"enumName":"LastMoveProperty"}],"output":["Json","Unknown"],"category":"game"},{"name":"$listChess","aliases":["$listChessGames","$chessGamesList"],"description":"List all the chess game IDs.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"sep","description":"The separator to use","rest":false,"type":"String"}],"output":["String[]"],"category":"game"},{"name":"$setChessOption","aliases":["$setChessGameOption","$chessOption"],"description":"Set the game options","version":"1.0.0","brackets":true,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"required":true,"type":"String"},{"name":"option","description":"The option to update.","rest":false,"required":true,"type":"Enum","enum":["FlipBoard","ShowCoordinates"],"enumName":"ChessOptions"},{"name":"value","description":"The value to set.","rest":false,"required":true,"type":"String"}],"output":["Json"],"category":"game"},{"name":"$undoMove","aliases":["$undoLastMove","$undoChessMove"],"description":"Undo the last Move in chess game.","version":"1.0.0","brackets":false,"unwrap":true,"args":[{"name":"id","description":"ID of the chess game","rest":false,"type":"String"}],"output":["Boolean"],"category":"game"}] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0013fed..eef2791 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "1.0.0", "license": "GPL-3.0-or-later", "dependencies": { - "chess": "^1.5.1" + "chess": "^1.5.1", + "tiny-typed-emitter": "^2.1.0" }, "devDependencies": { "@tryforge/forgescript": "github:tryforge/ForgeScript#dev", @@ -1932,7 +1933,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz", "integrity": "sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==", - "dev": true, "license": "MIT" }, "node_modules/tinyglobby": { diff --git a/package.json b/package.json index e3276d3..7e1f71d 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "typescript": "^5.9.3" }, "dependencies": { - "chess": "^1.5.1" + "chess": "^1.5.1", + "tiny-typed-emitter": "^2.1.0" } } diff --git a/src/__scripts__/bot.ts b/src/__scripts__/bot.ts index 3069f24..fcc2cad 100644 --- a/src/__scripts__/bot.ts +++ b/src/__scripts__/bot.ts @@ -4,14 +4,21 @@ import { ForgeChess } from ".." config() +const chess = new ForgeChess({ + events: ["start", "move"], +}) + const client = new ForgeClient({ prefixes: ["!"], token: process.env.Token!, intents: ["MessageContent", "GuildMessages", "Guilds"], events: ["messageCreate", "clientReady"], - extensions: [new ForgeChess()], + extensions: [chess], }) +chess.commands.add({ type: "start", code: "$log[started game with id: $js[ctx.runtime.extras.id]]" }) +chess.commands.add({ type: "move", code: "$log[Move played: $lastPlayedMove[;algebraic]]" }) + client.commands.add({ name: "ping", type: "messageCreate", @@ -22,7 +29,7 @@ client.commands.add( { type: "messageCreate", name: "chess", - code: "$let[id;$default[$message[0];$randomNumber[1;10]]] $chess[$get[id]; $sendMessage[$channelID;$get[id] $codeblock[$displayChess[;Ascii]]]]", + code: "$let[id;$username] $chess[$get[id]; $sendMessage[$channelID;$get[id] $codeblock[$displayChess[;Ascii]]]]", }, { @@ -36,7 +43,7 @@ client.commands.add( type: "messageCreate", name: "play", disableConsoleErrors: true, - code: "$let[id;$message[0]] $if[$argCount>1;$chessMove[$get[id];$message[1]]] `$chessMoves[$get[id];, ;true]` $codeblock[$displayChess[$get[id]]]", + code: "$let[id;$username] $if[$argCount>0;$chessMove[$get[id];$message]] `$chessMoves[$get[id];, ;true]` $codeblock[$displayChess[$get[id]]]", } ) diff --git a/src/classes/chess.ts b/src/classes/chess.ts index 2dc2b92..26f4a04 100644 --- a/src/classes/chess.ts +++ b/src/classes/chess.ts @@ -1,7 +1,23 @@ -import chess, { ChessBoard, PlayedMove } from "chess" +import chess, { ChessBoard, PlayedMove, Square } from "chess" import { BoardDisplay } from "./util" -import { DeepPartial } from ".." +import { ChessManager, DeepPartial, ForgeChess } from ".." + +export type AttackSquare = Record<"attackingSquare" | "kingSquare", Square> +export interface ChessEventCallback extends Record< + "move" | "undo" | "castle" | "enPassant", + (move: PlayedMove) => unknown | Promise +> { + promote: (square: Square) => unknown | Promise + check: (attack: AttackSquare) => unknown | Promise + checkmate: (attack: AttackSquare) => unknown | Promise +} +export type ChessEvent = keyof ChessEventCallback +/** For set option function */ +export enum ChessOptions { + FlipBoard, + ShowCoordinates, +} export interface IChessOptions { display: { flip: boolean @@ -15,7 +31,8 @@ export class Chess { public lastPlayedMove: PlayedMove | null = null public constructor( public id: string, - options: DeepPartial = {} + options: DeepPartial = {}, + public manager: ChessManager ) { this.options = { display: { @@ -23,6 +40,22 @@ export class Chess { coords: options.display?.coords ?? true, }, } + this.addListeners( + // @ts-ignore - someone help me + manager.client.getExtension(ForgeChess, true).options.events?.filter((e) => !["start"].includes(e)) ?? [] + ) + } + private addListeners(events: ChessEvent[]) { + events.forEach((e) => + this.on(e, (...args: any[]) => + this.manager.client.getExtension(ForgeChess, true).emitter.emit(e as any, this, ...args) + ) + ) + } + + public on(event: T, callback: ChessEventCallback[T]) { + // @ts-ignore + this.client.on(event, callback) } public get moveCount() { @@ -119,3 +152,6 @@ export enum ChessBoardDisplayType { FEN = "fen", Json = "json", } +export function isChessInstance(v: any): v is Chess { + return v && v instanceof Chess +} diff --git a/src/classes/commands.ts b/src/classes/commands.ts new file mode 100644 index 0000000..f532ecc --- /dev/null +++ b/src/classes/commands.ts @@ -0,0 +1,8 @@ +import { BaseCommandManager } from "@tryforge/forgescript" +import { IChessEvents } from "./event" + +export const ChessEventManagerName = "ChessEvents" + +export class ForgeChessCommandManager extends BaseCommandManager { + handlerName = ChessEventManagerName +} diff --git a/src/classes/event.ts b/src/classes/event.ts new file mode 100644 index 0000000..9733abd --- /dev/null +++ b/src/classes/event.ts @@ -0,0 +1,23 @@ +import { BaseEventHandler } from "@tryforge/forgescript" +import { AttackSquare, Chess } from "./chess" +import { ForgeClient } from "@tryforge/forgescript/dist/core" +import { ForgeChess } from ".." +import { PlayedMove, Square } from "chess" + +export interface IChessEvents { + start: [Chess] + move: [Chess, PlayedMove] + undo: [Chess, PlayedMove] + capture: [Chess, PlayedMove] + enPassant: [Chess, PlayedMove] + castle: [Chess, PlayedMove] + promote: [Chess, Square] + check: [Chess, AttackSquare] + checkmate: [Chess, AttackSquare] +} +export class ForgeChessEventHandler extends BaseEventHandler { + register(client: ForgeClient): void { + // @ts-ignore + client.getExtension(ForgeChess, true).emitter.on(this.name, this.listener.bind(client)) + } +} diff --git a/src/classes/manager.ts b/src/classes/manager.ts index 07fe815..9709849 100644 --- a/src/classes/manager.ts +++ b/src/classes/manager.ts @@ -1,10 +1,11 @@ +import { ForgeClient } from "@tryforge/forgescript" import { DeepPartial } from ".." import { Chess, IChessOptions } from "./chess" export class ChessManager { public map = new Map() public current: Chess[] = [] - public constructor() {} + public constructor(public client: ForgeClient) {} public get lastCurrent() { return this.current[this.current.length - 1] @@ -21,7 +22,7 @@ export class ChessManager { set(id: string, opts?: DeepPartial): void public set(chessOrId: Chess | string, opts?: DeepPartial) { return typeof chessOrId == "string" - ? this.map.set(chessOrId, new Chess(chessOrId, opts ?? {})) + ? this.map.set(chessOrId, new Chess(chessOrId, opts ?? {}, this)) : this.map.set(chessOrId.id, chessOrId) } diff --git a/src/classes/util.ts b/src/classes/util.ts index 5174877..f644643 100644 --- a/src/classes/util.ts +++ b/src/classes/util.ts @@ -43,4 +43,5 @@ export const BoardDisplay = { export enum FCError { NoChess = "No chess game found.", + InvalidChess = "This is not a chess game.", } diff --git a/src/events/capture.ts b/src/events/capture.ts new file mode 100644 index 0000000..57000e4 --- /dev/null +++ b/src/events/capture.ts @@ -0,0 +1,24 @@ +import { Interpreter } from "@tryforge/forgescript" +import { ForgeChess } from ".." +import { ForgeChessEventHandler } from "../classes/event" + +export default new ForgeChessEventHandler({ + name: "capture", + version: "1.0.0", + description: "Runs when a piece is captured.", + listener(chess, move) { + const commands = this.getExtension(ForgeChess, true).commands.get("capture") + for (const command of commands) { + Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }) + } + }, +}) diff --git a/src/events/castle.ts b/src/events/castle.ts new file mode 100644 index 0000000..85f10de --- /dev/null +++ b/src/events/castle.ts @@ -0,0 +1,24 @@ +import { Interpreter } from "@tryforge/forgescript" +import { ForgeChess } from ".." +import { ForgeChessEventHandler } from "../classes/event" + +export default new ForgeChessEventHandler({ + name: "castle", + version: "1.0.0", + description: "Runs when king castles.", + listener(chess, move) { + const commands = this.getExtension(ForgeChess, true).commands.get("castle") + for (const command of commands) { + Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }) + } + }, +}) diff --git a/src/events/check.ts b/src/events/check.ts new file mode 100644 index 0000000..46c8dd4 --- /dev/null +++ b/src/events/check.ts @@ -0,0 +1,24 @@ +import { Interpreter } from "@tryforge/forgescript" +import { ForgeChess } from ".." +import { ForgeChessEventHandler } from "../classes/event" + +export default new ForgeChessEventHandler({ + name: "check", + version: "1.0.0", + description: "Runs when the king is in check.", + listener(chess, attack) { + const commands = this.getExtension(ForgeChess, true).commands.get("check") + for (const command of commands) { + Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + attack, + }, + }) + } + }, +}) diff --git a/src/events/checkmate.ts b/src/events/checkmate.ts new file mode 100644 index 0000000..b46d70a --- /dev/null +++ b/src/events/checkmate.ts @@ -0,0 +1,24 @@ +import { Interpreter } from "@tryforge/forgescript" +import { ForgeChess } from ".." +import { ForgeChessEventHandler } from "../classes/event" + +export default new ForgeChessEventHandler({ + name: "checkmate", + version: "1.0.0", + description: "Runs when the king is checkmated.", + listener(chess, attack) { + const commands = this.getExtension(ForgeChess, true).commands.get("checkmate") + for (const command of commands) { + Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + attack, + }, + }) + } + }, +}) diff --git a/src/events/enPassant.ts b/src/events/enPassant.ts new file mode 100644 index 0000000..d12e1ef --- /dev/null +++ b/src/events/enPassant.ts @@ -0,0 +1,24 @@ +import { Interpreter } from "@tryforge/forgescript" +import { ForgeChess } from ".." +import { ForgeChessEventHandler } from "../classes/event" + +export default new ForgeChessEventHandler({ + name: "enPassant", + version: "1.0.0", + description: "Runs when en passant is occured.", + listener(chess, move) { + const commands = this.getExtension(ForgeChess, true).commands.get("enPassant") + for (const command of commands) { + Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }) + } + }, +}) diff --git a/src/events/move.ts b/src/events/move.ts new file mode 100644 index 0000000..50fc8b5 --- /dev/null +++ b/src/events/move.ts @@ -0,0 +1,24 @@ +import { Interpreter } from "@tryforge/forgescript" +import { ForgeChess } from ".." +import { ForgeChessEventHandler } from "../classes/event" + +export default new ForgeChessEventHandler({ + name: "move", + version: "1.0.0", + description: "Runs when a move is played.", + listener(chess, move) { + const commands = this.getExtension(ForgeChess, true).commands.get("move") + for (const command of commands) { + Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }) + } + }, +}) diff --git a/src/events/promote.ts b/src/events/promote.ts new file mode 100644 index 0000000..f834eed --- /dev/null +++ b/src/events/promote.ts @@ -0,0 +1,24 @@ +import { Interpreter } from "@tryforge/forgescript" +import { ForgeChess } from ".." +import { ForgeChessEventHandler } from "../classes/event" + +export default new ForgeChessEventHandler({ + name: "promote", + version: "1.0.0", + description: "Runs when a pawn is promoted.", + listener(chess, square) { + const commands = this.getExtension(ForgeChess, true).commands.get("promote") + for (const command of commands) { + Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + square, + }, + }) + } + }, +}) diff --git a/src/events/start.ts b/src/events/start.ts new file mode 100644 index 0000000..64b757d --- /dev/null +++ b/src/events/start.ts @@ -0,0 +1,21 @@ +import { Interpreter } from "@tryforge/forgescript" +import { ForgeChess } from ".." +import { ForgeChessEventHandler } from "../classes/event" + +export default new ForgeChessEventHandler({ + name: "start", + version: "1.0.0", + description: "Runs when a chess game has started.", + listener(chess) { + const commands = this.getExtension(ForgeChess, true).commands.get("start") + for (const command of commands) { + Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + }) + } + }, +}) diff --git a/src/events/undo.ts b/src/events/undo.ts new file mode 100644 index 0000000..11ffd7e --- /dev/null +++ b/src/events/undo.ts @@ -0,0 +1,24 @@ +import { Interpreter } from "@tryforge/forgescript" +import { ForgeChess } from ".." +import { ForgeChessEventHandler } from "../classes/event" + +export default new ForgeChessEventHandler({ + name: "undo", + version: "1.0.0", + description: "Runs when a move is undo.", + listener(chess, move) { + const commands = this.getExtension(ForgeChess, true).commands.get("undo") + for (const command of commands) { + Interpreter.run({ + obj: {}, + client: this, + command, + data: command.compiled.code, + extras: chess, + environment: { + move, + }, + }) + } + }, +}) diff --git a/src/functions/game/chessGameData.ts b/src/functions/game/chessGameData.ts index b246b1b..bef718f 100644 --- a/src/functions/game/chessGameData.ts +++ b/src/functions/game/chessGameData.ts @@ -1,5 +1,5 @@ import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" -import { FCError } from "../../classes" +import { FCError, isChessInstance } from "../../classes" import { ChessGameProperties, ChessGameProperty } from "../../properties/game" export default new NativeFunction({ @@ -16,8 +16,9 @@ export default new NativeFunction({ ], output: [ArgType.Json, ArgType.Unknown], async execute(ctx, [id, prop, sep]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) if (!prop) return this.successJSON(chess.toJSON()) return this.success(ChessGameProperties[prop](chess, sep ?? ", ")) }, diff --git a/src/functions/game/chessMove.ts b/src/functions/game/chessMove.ts index 558c2f3..dfb6d3a 100644 --- a/src/functions/game/chessMove.ts +++ b/src/functions/game/chessMove.ts @@ -1,5 +1,5 @@ import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" -import { FCError } from "../../classes" +import { FCError, isChessInstance } from "../../classes" export default new NativeFunction({ name: "$chessMove", @@ -10,8 +10,9 @@ export default new NativeFunction({ unwrap: true, args: [Arg.optionalString("id", "ID of the chess game"), Arg.restString("moves", "The moves to play")], async execute(ctx, [id, moves]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) for (const move of moves) { try { chess.makeMove(move.replace(" ", "")) diff --git a/src/functions/game/chessMoveCount.ts b/src/functions/game/chessMoveCount.ts index a03973e..f8add4a 100644 --- a/src/functions/game/chessMoveCount.ts +++ b/src/functions/game/chessMoveCount.ts @@ -1,5 +1,5 @@ import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" -import { FCError } from "../../classes" +import { FCError, isChessInstance } from "../../classes" export default new NativeFunction({ name: "$chessMoveCount", @@ -10,8 +10,9 @@ export default new NativeFunction({ args: [Arg.optionalString("id", "ID of the chess game")], output: ArgType.Number, async execute(ctx, [id]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) return this.success(chess.moveCount) }, }) diff --git a/src/functions/game/chessMoveList.ts b/src/functions/game/chessMoveList.ts index eef052c..d4da567 100644 --- a/src/functions/game/chessMoveList.ts +++ b/src/functions/game/chessMoveList.ts @@ -1,6 +1,6 @@ import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" import array from "@tryforge/forgescript/dist/functions/array" -import { FCError } from "../../classes" +import { FCError, isChessInstance } from "../../classes" export default new NativeFunction({ name: "$chessMoveList", @@ -16,8 +16,9 @@ export default new NativeFunction({ ], output: array(), async execute(ctx, [id, sep, san]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) return this.success(chess.availableMoves(san ?? true).join(sep ?? ", ")) }, }) diff --git a/src/functions/game/createChess.ts b/src/functions/game/createChess.ts index bccb252..65481a3 100644 --- a/src/functions/game/createChess.ts +++ b/src/functions/game/createChess.ts @@ -1,5 +1,6 @@ import { Arg, NativeFunction } from "@tryforge/forgescript" import { Chess, ChessManager } from "../../classes" +import { ForgeChess } from "../.." export default new NativeFunction({ name: "$createChess", @@ -17,8 +18,8 @@ export default new NativeFunction({ if (this.data.fields.length >= 1) { if (!ctx.client.chessManager || !(ctx.client.chessManager instanceof ChessManager)) - ctx.client.chessManager = new ChessManager() - ctx.client.chessManager.current.push(new Chess(id)) + ctx.client.chessManager = new ChessManager(ctx.client) + ctx.client.chessManager.current.push(new Chess(id, {}, ctx.client.chessManager!)) } for (let i = 1; i < this.data.fields.length; i++) { @@ -27,6 +28,7 @@ export default new NativeFunction({ if (!ctx.client.chessManager || ctx.client.chessManager.current.length === 0) return this.customError("Couldnt create the chess game.") + ctx.client.getExtension(ForgeChess, true).emitter.emit("start", ctx.client.chessManager.lastCurrent) ctx.client.chessManager.set(ctx.client.chessManager.lastCurrent) ctx.client.chessManager.current = ctx.client.chessManager.current.slice( 0, diff --git a/src/functions/game/currentPlayer.ts b/src/functions/game/currentPlayer.ts index 1bf9f8f..7a874b2 100644 --- a/src/functions/game/currentPlayer.ts +++ b/src/functions/game/currentPlayer.ts @@ -1,5 +1,5 @@ import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" -import { FCError } from "../../classes" +import { FCError, isChessInstance } from "../../classes" export default new NativeFunction({ name: "$currentChessPlayer", @@ -11,8 +11,9 @@ export default new NativeFunction({ args: [Arg.optionalString("id", "ID of the chess game")], output: ArgType.String, async execute(ctx, [id]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) return this.success(chess.currentPlayer()) }, }) diff --git a/src/functions/game/deleteChess.ts b/src/functions/game/deleteChess.ts new file mode 100644 index 0000000..ef2504e --- /dev/null +++ b/src/functions/game/deleteChess.ts @@ -0,0 +1,19 @@ +import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" +import { FCError, isChessInstance } from "../../classes" +export default new NativeFunction({ + name: "$deleteChess", + aliases: ["$deleteClassGame"], + description: "Deletes the chess game from the manager.", + version: "1.0.0", + brackets: false, + unwrap: true, + args: [Arg.optionalString("id", "ID of the chess game")], + output: ArgType.Boolean, + async execute(ctx, [id]) { + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) + if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) + ctx.client.chessManager?.remove(chess.id) + return this.success(true) + }, +}) diff --git a/src/functions/game/displayChessBoard.ts b/src/functions/game/displayChessBoard.ts index 6fa9320..81437b9 100644 --- a/src/functions/game/displayChessBoard.ts +++ b/src/functions/game/displayChessBoard.ts @@ -1,5 +1,5 @@ import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" -import { ChessBoardDisplayType, FCError } from "../../classes" +import { ChessBoardDisplayType, FCError, isChessInstance } from "../../classes" export default new NativeFunction({ name: "$displayChessBoard", @@ -14,8 +14,9 @@ export default new NativeFunction({ ], output: [ArgType.String, ArgType.Json], async execute(ctx, [id, type]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) if (type == ChessBoardDisplayType.Json) return this.successJSON(chess.display(type)) return this.success(chess.display(type ?? ChessBoardDisplayType.Ascii)) }, diff --git a/src/functions/game/lastPlayedMove.ts b/src/functions/game/lastPlayedMove.ts index b4f63a6..b302189 100644 --- a/src/functions/game/lastPlayedMove.ts +++ b/src/functions/game/lastPlayedMove.ts @@ -1,5 +1,5 @@ import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" -import { FCError } from "../../classes" +import { FCError, isChessInstance } from "../../classes" import { LastMoveProperties, LastMoveProperty } from "../../properties/lastMove" export default new NativeFunction({ @@ -15,8 +15,9 @@ export default new NativeFunction({ ], output: [ArgType.Json, ArgType.Unknown], async execute(ctx, [id, prop]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) if (!chess.lastPlayedMove) return this.success() if (!prop) return this.successJSON(chess.lastPlayedMove) return this.success(LastMoveProperties[prop](chess.lastPlayedMove)) diff --git a/src/functions/game/listChess.ts b/src/functions/game/listChess.ts index 867b148..270a14c 100644 --- a/src/functions/game/listChess.ts +++ b/src/functions/game/listChess.ts @@ -13,7 +13,7 @@ export default new NativeFunction({ output: array(), async execute(ctx, [sep]) { if (!ctx.client.chessManager || !(ctx.client.chessManager instanceof ChessManager)) - ctx.client.chessManager = new ChessManager() + ctx.client.chessManager = new ChessManager(ctx.client) return this.success( ctx.client.chessManager .list() diff --git a/src/functions/game/setChessOption.ts b/src/functions/game/setChessOption.ts new file mode 100644 index 0000000..ae1972f --- /dev/null +++ b/src/functions/game/setChessOption.ts @@ -0,0 +1,38 @@ +import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" +import { ChessOptions, FCError, isChessInstance } from "../../classes" + +export default new NativeFunction({ + name: "$setChessOption", + aliases: ["$setChessGameOption", "$chessOption"], + description: "Set the game options", + version: "1.0.0", + brackets: true, + unwrap: true, + args: [ + Arg.requiredString("id", "ID of the chess game"), + Arg.requiredEnum(ChessOptions, "option", "The option to update."), + Arg.requiredString("value", "The value to set."), + ], + output: ArgType.Json, + async execute(ctx, [id, opt, value]) { + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) + if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) + + switch (opt) { + case ChessOptions.FlipBoard: + chess.options.display.flip = bool(value, true) + break + case ChessOptions.ShowCoordinates: + chess.options.display.coords = bool(value, true) + break + default: + break + } + return this.successJSON(chess.options) + }, +}) + +function bool(value: string, def: boolean) { + return value.toLowerCase() == "true" ? true : value.toLowerCase() == "false" ? false : def +} diff --git a/src/functions/game/undoMove.ts b/src/functions/game/undoMove.ts index feb94c8..ea83a3f 100644 --- a/src/functions/game/undoMove.ts +++ b/src/functions/game/undoMove.ts @@ -1,5 +1,5 @@ import { Arg, ArgType, NativeFunction } from "@tryforge/forgescript" -import { FCError } from "../../classes" +import { FCError, isChessInstance } from "../../classes" export default new NativeFunction({ name: "$undoMove", @@ -11,8 +11,9 @@ export default new NativeFunction({ args: [Arg.optionalString("id", "ID of the chess game")], output: ArgType.Boolean, async execute(ctx, [id]) { - const chess = id ? ctx.client.chessManager?.get(id) : ctx.client.chessManager?.lastCurrent + const chess = id ? ctx.client.chessManager?.get(id) : (ctx.client.chessManager?.lastCurrent ?? ctx.runtime.extras) if (!chess) return this.customError(FCError.NoChess) + if (!isChessInstance(chess)) return this.customError(FCError.InvalidChess) return this.success(chess.undoMove()) }, }) diff --git a/src/index.ts b/src/index.ts index 15f5245..ae05bb0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,17 @@ -import { ForgeClient, ForgeExtension } from "@tryforge/forgescript" +import { EventManager, ForgeClient, ForgeExtension } from "@tryforge/forgescript" import { join } from "path" import { ChessManager } from "./classes" +import { TypedEmitter } from "tiny-typed-emitter" +import { IChessEvents } from "./classes/event" +import { ChessEventManagerName, ForgeChessCommandManager } from "./classes/commands" + +export interface IForgeChessOptions { + events?: Array +} + +export type TransformEvents = { + [P in keyof T]: T[P] extends any[] ? (...args: T[P]) => any : never +} export type DeepPartial = { [P in keyof T]?: DeepPartial | undefined } export class ForgeChess extends ForgeExtension { @@ -8,8 +19,21 @@ export class ForgeChess extends ForgeExtension { public description: string = require("../package.json").description public version: string = require("../package.json").version + public emitter = new TypedEmitter>() + private client!: ForgeClient + public commands!: ForgeChessCommandManager + + public constructor(public readonly options: IForgeChessOptions) { + super() + } + public init(client: ForgeClient): void { + this.client = client + this.commands = new ForgeChessCommandManager(client) + EventManager.load(ChessEventManagerName, __dirname + "/events") this.load(join(__dirname, "functions")) + + if (this.options.events?.length) this.client.events.load(ChessEventManagerName, this.options.events) } }