@vnejs/plugins.views.screens.checkers 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ import "@vnejs/contracts.common.grid";
2
+ import "@vnejs/contracts.common.turn";
1
3
  import "@vnejs/contracts.game.checkers";
2
4
  import "@vnejs/contracts.views.screens.checkers";
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import "@vnejs/contracts.common.grid";
2
+ import "@vnejs/contracts.common.turn";
1
3
  import "@vnejs/contracts.game.checkers";
2
4
  import "@vnejs/contracts.views.screens.checkers";
3
5
  import { regPlugin } from "@vnejs/shared";
@@ -10,6 +12,7 @@ import { CheckersViewControllerAccept } from "./modules/controller.accept.js";
10
12
  import { CheckersViewControllerGrid } from "./modules/controller.grid.js";
11
13
  import { CheckersViewPlayerInteract } from "./modules/player.interact.js";
12
14
  import { CheckersViewPlayerSelect } from "./modules/player.select.js";
15
+ import { CheckersViewStatus } from "./modules/status.js";
13
16
  import { CheckersViewView } from "./modules/view.js";
14
17
  regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
15
18
  CheckersViewBridge,
@@ -20,5 +23,6 @@ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
20
23
  CheckersViewPlayerSelect,
21
24
  CheckersViewClick,
22
25
  CheckersViewBoard,
26
+ CheckersViewStatus,
23
27
  CheckersViewView,
24
28
  ]);
@@ -1,9 +1,10 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
- import type { CheckersBoardChangedPayload } from "@vnejs/contracts.game.checkers";
2
+ import type { GridChangedPayload, GridUnsetPayload } from "@vnejs/contracts.common.grid";
3
3
  import type { CheckersViewPluginConstants, CheckersViewPluginEvents, CheckersViewPluginParams, CheckersViewPluginSettings } from "../types.js";
4
4
  import { type CheckersViewState } from "../utils/checkers.js";
5
5
  export declare class CheckersViewBoard extends ModuleCore<CheckersViewPluginEvents, CheckersViewPluginConstants, CheckersViewPluginSettings, CheckersViewPluginParams, CheckersViewState> {
6
6
  name: string;
7
7
  subscribe: () => void;
8
- onBoardChanged: (payload?: CheckersBoardChangedPayload) => Promise<void>;
8
+ onGridChanged: (payload?: GridChangedPayload) => Promise<void>;
9
+ onGridUnset: ({ id }?: GridUnsetPayload) => Promise<void>;
9
10
  }
@@ -1,16 +1,32 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
- import { buildGridItems, emptyBoard, fromBoardChanged } from "../utils/checkers.js";
2
+ import { buildGridItems, emptyBoard, fromGridChanged } from "../utils/checkers.js";
3
3
  export class CheckersViewBoard extends ModuleCore {
4
4
  name = "checkers_view.board";
5
5
  subscribe = () => {
6
- this.on(this.EVENTS.CHECKERS.BOARD_CHANGED, this.onBoardChanged);
6
+ this.on(this.EVENTS.GRID.CHANGED, this.onGridChanged);
7
+ this.on(this.EVENTS.GRID.UNSET, this.onGridUnset);
7
8
  this.on(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, this.updateState);
8
9
  };
9
- onBoardChanged = async (payload = {}) => {
10
- const mirror = fromBoardChanged(payload);
10
+ onGridChanged = async (payload = {}) => {
11
+ if (payload.id !== this.CONST.CHECKERS.GRID_ID)
12
+ return;
13
+ const mirror = fromGridChanged(payload);
11
14
  const board = mirror.board ?? this.state.board ?? emptyBoard();
12
15
  const gridItems = buildGridItems({ board, gridRow: this.state.gridRow ?? null, gridColumn: this.state.gridColumn ?? null });
13
16
  await this.emit(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, { ...mirror, board, gridItems });
14
17
  await this.emit(this.EVENTS.CHECKERS_VIEW.UPDATE_FAST);
15
18
  };
19
+ onGridUnset = async ({ id } = {}) => {
20
+ if (id !== this.CONST.CHECKERS.GRID_ID)
21
+ return;
22
+ const board = emptyBoard();
23
+ const gridItems = buildGridItems({ board, gridRow: this.state.gridRow ?? null, gridColumn: this.state.gridColumn ?? null });
24
+ await this.emit(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, {
25
+ board,
26
+ selected: null,
27
+ legalMoves: [],
28
+ gridItems,
29
+ });
30
+ await this.emit(this.EVENTS.CHECKERS_VIEW.UPDATE_FAST);
31
+ };
16
32
  }
@@ -3,6 +3,6 @@ import type { CheckersViewPluginConstants, CheckersViewPluginEvents, CheckersVie
3
3
  export declare class CheckersViewBridge extends ModuleCore<CheckersViewPluginEvents, CheckersViewPluginConstants, CheckersViewPluginSettings, CheckersViewPluginParams> {
4
4
  name: string;
5
5
  subscribe: () => void;
6
- onCheckersShow: () => Promise<unknown[]> | undefined;
7
- onCheckersHide: () => Promise<unknown[]> | undefined;
6
+ onCheckersShow: () => Promise<import("@vnejs/shared").EmitResults<"vne:checkers_view:show">> | undefined;
7
+ onCheckersHide: () => Promise<import("@vnejs/shared").EmitResults<"vne:checkers_view:hide">> | undefined;
8
8
  }
@@ -1,6 +1,7 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
2
  import type { CheckersViewPluginConstants, CheckersViewPluginEvents, CheckersViewPluginParams, CheckersViewPluginSettings } from "../types.js";
3
- import type { CheckersClickPayload, CheckersViewState } from "../utils/checkers.js";
3
+ import type { CheckersViewState } from "../utils/checkers.js";
4
+ import type { CheckersClickPayload } from "@vnejs/contracts.views.screens.checkers";
4
5
  export declare class CheckersViewClick extends ModuleCore<CheckersViewPluginEvents, CheckersViewPluginConstants, CheckersViewPluginSettings, CheckersViewPluginParams, CheckersViewState> {
5
6
  name: string;
6
7
  subscribe: () => void;
@@ -0,0 +1,18 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { TurnsChangedPayload, TurnsUnsetPayload } from "@vnejs/contracts.common.turn";
3
+ import type { CheckersFinishPayload } from "@vnejs/contracts.game.checkers";
4
+ import type { CheckersViewPluginConstants, CheckersViewPluginEvents, CheckersViewPluginParams, CheckersViewPluginSettings } from "../types.js";
5
+ import { type CheckersColor, type CheckersViewState } from "../utils/checkers.js";
6
+ export declare class CheckersViewStatus extends ModuleCore<CheckersViewPluginEvents, CheckersViewPluginConstants, CheckersViewPluginSettings, CheckersViewPluginParams, CheckersViewState> {
7
+ name: string;
8
+ subscribe: () => void;
9
+ applyStatus: ({ turn, winner, clearSelection }: {
10
+ turn?: CheckersColor;
11
+ winner: CheckersColor | null;
12
+ clearSelection?: boolean;
13
+ }) => Promise<void>;
14
+ onTurnsChanged: ({ id, owner }?: TurnsChangedPayload) => false | Promise<void>;
15
+ onTurnsUnset: ({ id }?: TurnsUnsetPayload) => false | Promise<void>;
16
+ onFinish: ({ winner }?: CheckersFinishPayload) => Promise<void>;
17
+ onShow: () => Promise<void>;
18
+ }
@@ -0,0 +1,24 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import { statusForTurn } from "../utils/checkers.js";
3
+ export class CheckersViewStatus extends ModuleCore {
4
+ name = "checkers_view.status";
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.TURNS.CHANGED, this.onTurnsChanged);
7
+ this.on(this.EVENTS.TURNS.UNSET, this.onTurnsUnset);
8
+ this.on(this.EVENTS.CHECKERS.FINISH, this.onFinish);
9
+ this.on(this.EVENTS.CHECKERS.SHOW, this.onShow);
10
+ this.on(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, this.updateState);
11
+ };
12
+ applyStatus = async ({ turn, winner, clearSelection = false }) => {
13
+ const next = { turn, winner, statusText: statusForTurn(turn, winner) };
14
+ if (clearSelection)
15
+ Object.assign(next, { selected: null, legalMoves: [] });
16
+ await this.emit(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, next);
17
+ await this.emit(this.EVENTS.CHECKERS_VIEW.UPDATE_FAST);
18
+ };
19
+ onTurnsChanged = ({ id, owner } = {}) => id === this.CONST.CHECKERS.TURN_ID &&
20
+ this.applyStatus({ turn: owner, winner: this.state.winner ?? null, clearSelection: true });
21
+ onTurnsUnset = ({ id } = {}) => id === this.CONST.CHECKERS.TURN_ID && this.applyStatus({ turn: undefined, winner: this.state.winner ?? null, clearSelection: true });
22
+ onFinish = ({ winner } = {}) => this.applyStatus({ turn: this.state.turn, winner: (winner ?? null) });
23
+ onShow = () => this.applyStatus({ turn: this.state.turn, winner: null });
24
+ }
package/dist/types.d.ts CHANGED
@@ -3,9 +3,11 @@ import type { Constants as AiConstants, Params as AiParams, PluginName as AiPlug
3
3
  import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
4
4
  import type { Constants as ScenarioConstants, PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
5
5
  import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
6
+ import type { PluginName as GridPluginName, SubscribeEvents as GridSubscribeEvents } from "@vnejs/contracts.common.grid";
7
+ import type { PluginName as TurnsPluginName, SubscribeEvents as TurnsSubscribeEvents } from "@vnejs/contracts.common.turn";
6
8
  import type { Constants as CheckersConstants, Params as CheckersParams, PluginName as CheckersPluginName, SubscribeEvents as CheckersSubscribeEvents } from "@vnejs/contracts.game.checkers";
7
9
  import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.views.screens.checkers";
8
- export type CheckersViewPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<CheckersPluginName, CheckersSubscribeEvents> & Record<AiPluginName, AiSubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<LogsPluginName, LogsSubscribeEvents>;
10
+ export type CheckersViewPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<CheckersPluginName, CheckersSubscribeEvents> & Record<GridPluginName, GridSubscribeEvents> & Record<TurnsPluginName, TurnsSubscribeEvents> & Record<AiPluginName, AiSubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<LogsPluginName, LogsSubscribeEvents>;
9
11
  export type CheckersViewPluginConstants = ModuleComponentsConstants & Record<CheckersPluginName, CheckersConstants> & Record<AiPluginName, AiConstants> & Record<ControlsPluginName, ControlsConstants> & Record<ScenarioPluginName, ScenarioConstants>;
10
12
  export type CheckersViewPluginSettings = ModuleComponentsSettings;
11
13
  export type CheckersViewPluginParams = ModuleComponentsParams & Record<PluginName, Params> & Record<CheckersPluginName, CheckersParams> & Record<AiPluginName, AiParams>;
@@ -1,4 +1,5 @@
1
- import type { CheckersBoardChangedPayload, CheckersMovePayload, CheckersPosPayload } from "@vnejs/contracts.game.checkers";
1
+ import type { GridChangedPayload } from "@vnejs/contracts.common.grid";
2
+ import type { CheckersMovePayload, CheckersPosPayload } from "@vnejs/contracts.game.checkers";
2
3
  export declare const BOARD_SIZE = 8;
3
4
  export type CheckersColor = "white" | "black";
4
5
  export type CheckersPiece = {
@@ -33,10 +34,6 @@ export type CheckersViewState = {
33
34
  gridIndex?: number;
34
35
  gridsCount?: number;
35
36
  };
36
- export type CheckersClickPayload = {
37
- row?: number;
38
- column?: number;
39
- };
40
37
  export declare const isDarkSquare: (row: number, column: number) => boolean;
41
38
  export declare const samePos: (a: CheckersPos, b: CheckersPos) => boolean;
42
39
  export declare const buildGridItems: ({ board, selected, legalMoves, gridRow, gridColumn, }: {
@@ -49,4 +46,4 @@ export declare const buildGridItems: ({ board, selected, legalMoves, gridRow, gr
49
46
  export declare const listBoardPieces: (board: CheckersBoard) => (CheckersPiece & CheckersPosPayload)[];
50
47
  export declare const emptyBoard: () => CheckersBoard;
51
48
  export declare const statusForTurn: (turn?: CheckersColor, winner?: CheckersColor | null) => "" | "Black to move" | "Black wins" | "White to move" | "White wins";
52
- export declare const fromBoardChanged: (payload?: CheckersBoardChangedPayload) => Partial<CheckersViewState>;
49
+ export declare const fromGridChanged: (payload?: GridChangedPayload) => Partial<CheckersViewState>;
@@ -39,16 +39,9 @@ export const statusForTurn = (turn, winner = null) => {
39
39
  return "";
40
40
  return turn === "white" ? "White to move" : "Black to move";
41
41
  };
42
- export const fromBoardChanged = (payload = {}) => {
43
- const turn = payload.turn;
44
- const winner = (payload.winner ?? null);
45
- return {
46
- board: payload.board,
47
- turn,
48
- winner,
49
- statusText: statusForTurn(turn, winner),
50
- // selection is view-only — reset on every game model change
51
- selected: null,
52
- legalMoves: [],
53
- };
54
- };
42
+ export const fromGridChanged = (payload = {}) => ({
43
+ board: payload.cells,
44
+ // selection is view-only reset on every game model change
45
+ selected: null,
46
+ legalMoves: [],
47
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.screens.checkers",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Checkers screen view (CHECKERS_VIEW)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,6 +31,8 @@
31
31
  "license": "ISC",
32
32
  "dependencies": {
33
33
  "@vnejs/contracts.ai": "~0.2.0",
34
+ "@vnejs/contracts.common.grid": "~0.2.0",
35
+ "@vnejs/contracts.common.turn": "~0.2.0",
34
36
  "@vnejs/contracts.game.checkers": "~0.2.0",
35
37
  "@vnejs/contracts.views.screens.checkers": "~0.2.0"
36
38
  },
@@ -50,6 +52,8 @@
50
52
  "@vnejs/configs.vitest": "~0.2.0",
51
53
  "@vnejs/test-utils": "~0.2.0",
52
54
  "@vnejs/contracts.ai": "~0.2.0",
55
+ "@vnejs/contracts.common.grid": "~0.2.0",
56
+ "@vnejs/contracts.common.turn": "~0.2.0",
53
57
  "@vnejs/contracts.controls": "~0.2.0",
54
58
  "@vnejs/contracts.game.checkers": "~0.2.0",
55
59
  "@vnejs/contracts.views.screens.checkers": "~0.2.0",
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import "@vnejs/contracts.common.grid";
2
+ import "@vnejs/contracts.common.turn";
1
3
  import "@vnejs/contracts.game.checkers";
2
4
  import "@vnejs/contracts.views.screens.checkers";
3
5
 
@@ -12,6 +14,7 @@ import { CheckersViewControllerAccept } from "./modules/controller.accept.js";
12
14
  import { CheckersViewControllerGrid } from "./modules/controller.grid.js";
13
15
  import { CheckersViewPlayerInteract } from "./modules/player.interact.js";
14
16
  import { CheckersViewPlayerSelect } from "./modules/player.select.js";
17
+ import { CheckersViewStatus } from "./modules/status.js";
15
18
  import { CheckersViewView } from "./modules/view.js";
16
19
 
17
20
  regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
@@ -23,5 +26,6 @@ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
23
26
  CheckersViewPlayerSelect,
24
27
  CheckersViewClick,
25
28
  CheckersViewBoard,
29
+ CheckersViewStatus,
26
30
  CheckersViewView,
27
31
  ]);
@@ -1,8 +1,8 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
- import type { CheckersBoardChangedPayload } from "@vnejs/contracts.game.checkers";
2
+ import type { GridChangedPayload, GridUnsetPayload } from "@vnejs/contracts.common.grid";
3
3
 
4
4
  import type { CheckersViewPluginConstants, CheckersViewPluginEvents, CheckersViewPluginParams, CheckersViewPluginSettings } from "../types.js";
5
- import { buildGridItems, emptyBoard, fromBoardChanged, type CheckersViewState } from "../utils/checkers.js";
5
+ import { buildGridItems, emptyBoard, fromGridChanged, type CheckersViewState } from "../utils/checkers.js";
6
6
 
7
7
  export class CheckersViewBoard extends ModuleCore<
8
8
  CheckersViewPluginEvents,
@@ -14,16 +14,34 @@ export class CheckersViewBoard extends ModuleCore<
14
14
  name = "checkers_view.board";
15
15
 
16
16
  subscribe = () => {
17
- this.on(this.EVENTS.CHECKERS.BOARD_CHANGED, this.onBoardChanged);
17
+ this.on(this.EVENTS.GRID.CHANGED, this.onGridChanged);
18
+ this.on(this.EVENTS.GRID.UNSET, this.onGridUnset);
18
19
  this.on(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, this.updateState);
19
20
  };
20
21
 
21
- onBoardChanged = async (payload: CheckersBoardChangedPayload = {}) => {
22
- const mirror = fromBoardChanged(payload);
22
+ onGridChanged = async (payload: GridChangedPayload = {}) => {
23
+ if (payload.id !== this.CONST.CHECKERS.GRID_ID) return;
24
+
25
+ const mirror = fromGridChanged(payload);
23
26
  const board = mirror.board ?? this.state.board ?? emptyBoard();
24
27
  const gridItems = buildGridItems({ board, gridRow: this.state.gridRow ?? null, gridColumn: this.state.gridColumn ?? null });
25
28
 
26
29
  await this.emit(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, { ...mirror, board, gridItems } satisfies Partial<CheckersViewState>);
27
30
  await this.emit(this.EVENTS.CHECKERS_VIEW.UPDATE_FAST);
28
31
  };
32
+
33
+ onGridUnset = async ({ id }: GridUnsetPayload = {}) => {
34
+ if (id !== this.CONST.CHECKERS.GRID_ID) return;
35
+
36
+ const board = emptyBoard();
37
+ const gridItems = buildGridItems({ board, gridRow: this.state.gridRow ?? null, gridColumn: this.state.gridColumn ?? null });
38
+
39
+ await this.emit(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, {
40
+ board,
41
+ selected: null,
42
+ legalMoves: [],
43
+ gridItems,
44
+ } satisfies Partial<CheckersViewState>);
45
+ await this.emit(this.EVENTS.CHECKERS_VIEW.UPDATE_FAST);
46
+ };
29
47
  }
@@ -2,7 +2,8 @@ import { ModuleCore } from "@vnejs/module.core";
2
2
  import type { CheckersPlayerInteractPayload } from "@vnejs/contracts.views.screens.checkers";
3
3
 
4
4
  import type { CheckersViewPluginConstants, CheckersViewPluginEvents, CheckersViewPluginParams, CheckersViewPluginSettings } from "../types.js";
5
- import type { CheckersClickPayload, CheckersViewState } from "../utils/checkers.js";
5
+ import type { CheckersViewState } from "../utils/checkers.js";
6
+ import type { CheckersClickPayload } from "@vnejs/contracts.views.screens.checkers";
6
7
 
7
8
  export class CheckersViewClick extends ModuleCore<
8
9
  CheckersViewPluginEvents,
@@ -0,0 +1,41 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { TurnsChangedPayload, TurnsUnsetPayload } from "@vnejs/contracts.common.turn";
3
+ import type { CheckersFinishPayload } from "@vnejs/contracts.game.checkers";
4
+
5
+ import type { CheckersViewPluginConstants, CheckersViewPluginEvents, CheckersViewPluginParams, CheckersViewPluginSettings } from "../types.js";
6
+ import { statusForTurn, type CheckersColor, type CheckersViewState } from "../utils/checkers.js";
7
+
8
+ export class CheckersViewStatus extends ModuleCore<
9
+ CheckersViewPluginEvents,
10
+ CheckersViewPluginConstants,
11
+ CheckersViewPluginSettings,
12
+ CheckersViewPluginParams,
13
+ CheckersViewState
14
+ > {
15
+ name = "checkers_view.status";
16
+
17
+ subscribe = () => {
18
+ this.on(this.EVENTS.TURNS.CHANGED, this.onTurnsChanged);
19
+ this.on(this.EVENTS.TURNS.UNSET, this.onTurnsUnset);
20
+ this.on(this.EVENTS.CHECKERS.FINISH, this.onFinish);
21
+ this.on(this.EVENTS.CHECKERS.SHOW, this.onShow);
22
+ this.on(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, this.updateState);
23
+ };
24
+
25
+ applyStatus = async ({ turn, winner, clearSelection = false }: { turn?: CheckersColor; winner: CheckersColor | null; clearSelection?: boolean }) => {
26
+ const next: Partial<CheckersViewState> = { turn, winner, statusText: statusForTurn(turn, winner) };
27
+
28
+ if (clearSelection) Object.assign(next, { selected: null, legalMoves: [] });
29
+
30
+ await this.emit(this.EVENTS.CHECKERS_VIEW.STATE_UPDATE, next);
31
+ await this.emit(this.EVENTS.CHECKERS_VIEW.UPDATE_FAST);
32
+ };
33
+
34
+ onTurnsChanged = ({ id, owner }: TurnsChangedPayload = {}) =>
35
+ id === this.CONST.CHECKERS.TURN_ID &&
36
+ this.applyStatus({ turn: owner as CheckersColor | undefined, winner: this.state.winner ?? null, clearSelection: true });
37
+ onTurnsUnset = ({ id }: TurnsUnsetPayload = {}) =>
38
+ id === this.CONST.CHECKERS.TURN_ID && this.applyStatus({ turn: undefined, winner: this.state.winner ?? null, clearSelection: true });
39
+ onFinish = ({ winner }: CheckersFinishPayload = {}) => this.applyStatus({ turn: this.state.turn, winner: (winner ?? null) as CheckersColor | null });
40
+ onShow = () => this.applyStatus({ turn: this.state.turn, winner: null });
41
+ }
@@ -1,4 +1,5 @@
1
1
  import { CONSTANTS as AI_CONST, PARAMS as AI_PARAMS, PLUGIN_NAME as AI, SUBSCRIBE_EVENTS as AI_EVENTS } from "@vnejs/contracts.ai";
2
+ import { PLUGIN_NAME as GRID, SUBSCRIBE_EVENTS as GRID_EVENTS } from "@vnejs/contracts.common.grid";
2
3
  import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
3
4
  import {
4
5
  CONSTANTS as CHECKERS_CONST,
@@ -15,6 +16,7 @@ export const registerCheckersViewPluginVne = () => {
15
16
  registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
16
17
  registerVnePlugin(AI, { constants: AI_CONST, events: AI_EVENTS, params: AI_PARAMS });
17
18
  registerVnePlugin(CHECKERS, { constants: CHECKERS_CONST, events: CHECKERS_EVENTS, params: CHECKERS_PARAMS });
19
+ registerVnePlugin(GRID, { events: GRID_EVENTS });
18
20
  registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS });
19
21
  };
20
22
 
@@ -36,10 +38,11 @@ export const createCheckersViewTestModule = <T extends Parameters<typeof baseCre
36
38
  stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
37
39
  stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.STATE_UPDATE);
38
40
  stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.GRID_UPDATE_ITEMS);
39
- stubSilentEvent(result.observer, CHECKERS_EVENTS.BOARD_CHANGE);
41
+ stubSilentEvent(result.observer, GRID_EVENTS.SET);
42
+ stubSilentEvent(result.observer, GRID_EVENTS.CHANGED);
40
43
  stubSilentEvent(result.observer, CHECKERS_EVENTS.FINISH);
41
44
 
42
45
  return result;
43
46
  };
44
47
 
45
- export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, CONTROLS_EVENTS, CHECKERS_EVENTS };
48
+ export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, CONTROLS_EVENTS, CHECKERS_EVENTS, GRID_EVENTS };
package/src/types.ts CHANGED
@@ -7,6 +7,8 @@ import type {
7
7
  SubscribeEvents as ScenarioSubscribeEvents,
8
8
  } from "@vnejs/contracts.core.scenario";
9
9
  import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/contracts.core.logs";
10
+ import type { PluginName as GridPluginName, SubscribeEvents as GridSubscribeEvents } from "@vnejs/contracts.common.grid";
11
+ import type { PluginName as TurnsPluginName, SubscribeEvents as TurnsSubscribeEvents } from "@vnejs/contracts.common.turn";
10
12
  import type {
11
13
  Constants as CheckersConstants,
12
14
  Params as CheckersParams,
@@ -18,6 +20,8 @@ import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.views
18
20
  export type CheckersViewPluginEvents = ModuleComponentsEvents &
19
21
  Record<PluginName, SubscribeEvents> &
20
22
  Record<CheckersPluginName, CheckersSubscribeEvents> &
23
+ Record<GridPluginName, GridSubscribeEvents> &
24
+ Record<TurnsPluginName, TurnsSubscribeEvents> &
21
25
  Record<AiPluginName, AiSubscribeEvents> &
22
26
  Record<ScenarioPluginName, ScenarioSubscribeEvents> &
23
27
  Record<LogsPluginName, LogsSubscribeEvents>;
@@ -1,4 +1,5 @@
1
- import type { CheckersBoardChangedPayload, CheckersMovePayload, CheckersPosPayload } from "@vnejs/contracts.game.checkers";
1
+ import type { GridChangedPayload } from "@vnejs/contracts.common.grid";
2
+ import type { CheckersMovePayload, CheckersPosPayload } from "@vnejs/contracts.game.checkers";
2
3
 
3
4
  export const BOARD_SIZE = 8;
4
5
 
@@ -42,11 +43,6 @@ export type CheckersViewState = {
42
43
  gridsCount?: number;
43
44
  };
44
45
 
45
- export type CheckersClickPayload = {
46
- row?: number;
47
- column?: number;
48
- };
49
-
50
46
  export const isDarkSquare = (row: number, column: number) => (row + column) % 2 === 1;
51
47
 
52
48
  export const samePos = (a: CheckersPos, b: CheckersPos) => a.row === b.row && a.column === b.column;
@@ -106,17 +102,9 @@ export const statusForTurn = (turn?: CheckersColor, winner: CheckersColor | null
106
102
  return turn === "white" ? "White to move" : "Black to move";
107
103
  };
108
104
 
109
- export const fromBoardChanged = (payload: CheckersBoardChangedPayload = {}): Partial<CheckersViewState> => {
110
- const turn = payload.turn as CheckersColor | undefined;
111
- const winner = (payload.winner ?? null) as CheckersColor | null;
112
-
113
- return {
114
- board: payload.board as CheckersBoard | undefined,
115
- turn,
116
- winner,
117
- statusText: statusForTurn(turn, winner),
118
- // selection is view-only — reset on every game model change
119
- selected: null,
120
- legalMoves: [],
121
- };
122
- };
105
+ export const fromGridChanged = (payload: GridChangedPayload = {}): Partial<CheckersViewState> => ({
106
+ board: payload.cells as CheckersBoard | undefined,
107
+ // selection is view-only reset on every game model change
108
+ selected: null,
109
+ legalMoves: [],
110
+ });