refactor storm components to ui/puz

puzzle-racer-road-translate
Thibault Duplessis 2021-03-03 13:22:42 +01:00
parent 92b2aaaa16
commit 419744040f
13 changed files with 32 additions and 29 deletions

View File

@ -15,7 +15,7 @@ mkdir -p public/compiled
apps1="common"
apps2="chess ceval game tree chat nvui puz"
apps3="site swiss msg chat cli challenge notify learn insight editor puzzle round analyse lobby tournament tournamentSchedule tournamentCalendar simul dasher speech palantir serviceWorker dgt storm racer"
apps3="site swiss msg chat cli challenge notify learn insight editor puzzle round analyse lobby tournament tournamentSchedule tournamentCalendar simul dasher speech palantir serviceWorker dgt storm"
site_plugins="tvEmbed puzzleEmbed analyseEmbed user modUser clas coordinate captcha expandText team forum account coachShow coachForm challengePage checkout login passwordComplexity tourForm teamBattleForm gameSearch userComplete infiniteScroll flatpickr teamAdmin appeal modGames"
round_plugins="nvui keyboardMove"
analyse_plugins="nvui studyTopicForm"

View File

@ -8,7 +8,7 @@
"author": "Thibault Duplessis",
"license": "AGPL-3.0-or-later",
"scripts": {
"compile": "../../node_modules/typescript/bin/tsc --incremental --outDir ./dist --declaration --inlineSourceMap",
"compile": "../../node_modules/typescript/bin/tsc",
"dev": "yarn run compile",
"prod": "yarn run compile"
},

View File

@ -1,3 +1,16 @@
import { Role } from 'chessground/types';
import { VNode } from 'snabbdom/vnode';
export type MaybeVNode = VNode | string | null | undefined;
export type MaybeVNodes = MaybeVNode[];
export type Redraw = () => void;
export interface Promotion {
start(orig: Key, dest: Key, callback: (orig: Key, dest: Key, prom: Role) => void): boolean;
cancel(): void;
view(): MaybeVNode;
}
export interface Prefs {
coords: 0 | 1 | 2;
is3d: boolean;

View File

@ -1,8 +1,6 @@
import changeColorHandle from 'common/coordsColor';
import resizeHandle from 'common/resize';
import { Config as CgConfig } from 'chessground/config';
import { h } from 'snabbdom';
import { VNode } from 'snabbdom/vnode';
import { Prefs, UserMove } from '../interfaces';
export function makeConfig(opts: CgConfig, pref: Prefs, userMove: UserMove): CgConfig {

View File

@ -1,4 +1,8 @@
{
"extends": "../tsconfig.base.json",
"include": ["src"]
"extends": "../tsconfig_module.base.json",
"include": ["src"],
"exclude": [],
"compilerOptions": {
"outDir": "."
}
}

View File

@ -17,8 +17,9 @@
},
"dependencies": {
"chessground": "^7.11.0",
"snabbdom": "^0.7.4",
"common": "2.0.0",
"snabbdom": "^0.7.4"
"puz": "2.0.0"
},
"scripts": {
"dev": "rollup --config",

View File

@ -1,17 +1,18 @@
import * as xhr from './xhr';
import config from './config';
import makePromotion from './promotion';
import makePromotion from 'puz/promotion';
import sign from './sign';
import { Api as CgApi } from 'chessground/api';
import { Chess } from 'chessops/chess';
import { chessgroundDests } from 'chessops/compat';
import { Config as CgConfig } from 'chessground/config';
import { getNow } from './util';
import { getNow } from 'puz/util';
import { parseFen, makeFen } from 'chessops/fen';
import { parseUci, opposite } from 'chessops/util';
import { prop, Prop } from 'common';
import { Role } from 'chessground/types';
import { StormOpts, StormData, StormPuzzle, StormVm, Promotion, TimeMod, StormRun, StormPrefs } from './interfaces';
import { StormOpts, StormData, StormPuzzle, StormVm, TimeMod, StormRun, StormPrefs } from './interfaces';
import { Promotion } from 'puz/interfaces';
export default class StormCtrl {
private data: StormData;
@ -206,9 +207,6 @@ export default class StormCtrl {
dests: chessgroundDests(pos),
}
: undefined,
premovable: {
enabled: false,
},
check: !!pos.isCheck(),
lastMove: this.uciToLastMove(this.line()[this.vm.moveIndex]),
};

View File

@ -1,10 +1,4 @@
import { Role } from 'chessground/types';
import { Prop } from 'common';
import { VNode } from 'snabbdom/vnode';
export type MaybeVNode = VNode | string | null | undefined;
export type MaybeVNodes = MaybeVNode[];
export type Redraw = () => void;
export interface StormOpts {
data: StormData;
@ -74,12 +68,6 @@ export interface StormPuzzle {
rating: number;
}
export interface Promotion {
start(orig: Key, dest: Key, callback: (orig: Key, dest: Key, prom: Role) => void): boolean;
cancel(): void;
view(): MaybeVNode;
}
export interface DailyBest {
score: number;
prev?: number;

View File

@ -1,6 +1,6 @@
import StormCtrl from '../ctrl';
import { defined } from 'common';
import { getNow } from '../util';
import { getNow } from 'puz/util';
import { h } from 'snabbdom';
import { VNode } from 'snabbdom/vnode';
import { TimeMod } from '../interfaces';

View File

@ -1,7 +1,7 @@
import * as miniBoard from 'common/mini-board';
import StormCtrl from '../ctrl';
import { Chess } from 'chessops/chess';
import { getNow, onInsert } from '../util';
import { getNow, onInsert } from 'puz/util';
import { h } from 'snabbdom';
import { numberSpread } from 'common/number';
import { parseFen, makeFen } from 'chessops/fen';

View File

@ -4,7 +4,7 @@ import config from '../config';
import renderClock from './clock';
import renderEnd from './end';
import StormCtrl from '../ctrl';
import { getNow, onInsert } from '../util';
import { getNow, onInsert } from 'puz/util';
import { h } from 'snabbdom';
import { VNode } from 'snabbdom/vnode';
@ -37,7 +37,8 @@ const playModifiers = (ctrl: StormCtrl) => {
const chessground = (ctrl: StormCtrl): VNode =>
h('div.cg-wrap', {
hook: {
insert: vnode => ctrl.ground(Chessground(vnode.elm as HTMLElement, makeCgConfig(ctrl))),
insert: vnode =>
ctrl.ground(Chessground(vnode.elm as HTMLElement, makeCgConfig(ctrl.makeCgOpts(), ctrl.pref, ctrl.userMove))),
destroy: _ => ctrl.withGround(g => g.destroy()),
},
});