Giter VIP home page Giter VIP logo

isepic-chess-ui's Introduction

IcUi logo

isepic-chess-ui

Isepic Chess UI is the user interface for isepic-chess.js. It uses jQuery for DOM manipulation and animations.

📌 Table of contents

🖱️ How to use?

  1. Add the necessary files (the order of the .js files is important):
<link rel="stylesheet" href="./css/isepic-chess-ui.css" />

<script src="./js/jquery-3.3.1.min.js"></script>
<script src="./js/isepic-chess.js"></script>
<script src="./js/isepic-chess-ui.js"></script>
  1. Wrap your code inside $(function(){...}); to wait for the DOM to be ready.
<script>
  $(function () {
    //you can overwrite configuration options
    IcUi.setCfg('soundEffects', false);
    IcUi.setCfg('scrollNavigation', false);
    IcUi.setCfg('animationTime', 150);

    //initialize a board
    var board = Ic.initBoard({
      boardName: 'main',
    });
  });
</script>

Note: documentation for Ic.initBoard() can be found here.

  1. Add some components (don't add them more than once) inside <body>.

  2. Open the .html file.

👁️ Demo

https://ajax333221.github.io/isepic-chess-ui/

🚀 Features

  • Responsive board size
  • Both drag-and-drop and click-from-click-to in parallel
  • Highlight last move, legal moves and checks
  • Components:
  • Automatic component binding, no need to do anything manually to the DOM elements (they will simply work just by having their correct id property at any given time)
  • Piece displacement animation
  • Chess fonts:
    • Merida
    • isepic-chess-font (by ajax333221)
  • Chess themes: "wood" (default), "olive", "magenta" and "aqua"
  • Sound effects
  • Move navigation via scrolling and arrow keys
  • Puzzle mode (:construction: work in progress :construction:)
  • Push alerts (:construction: work in progress :construction:)
    • The idea is to have dimissible boxes with game events, board events, ui events, debug errors, etc.

📖 Documentation

Note: make sure to also read the isepic-chess.js Documentation.

📄 Copyright and license

Copyright © 2023 Ajax Isepic (ajax333221)

Licensed under MIT License: http://opensource.org/licenses/mit-license.php

isepic-chess-ui's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

isepic-chess-ui's Issues

Problems when not having the Board component

Not having a Board component currently generates a bunch of "error board not found" console log messages when interacting with other components or simply clicking stuff around.

This is because at some point the data-boardname attribute of the Board component is used to get the board name. But all of this can be avoided if there is some internal _CURRENT_BOARD_NAME privately. This would not only solve the issue but be a bit more performant since it would not transverse the DOM tree with jQuery to get the board name (but just a bit, since after all, it is matching an element by ID which should not be slow at all).

Historically, each component had their own data-boardname attribute, then as a major rewrite it was changed to only check for it in the Board component, but it actually makes more sense to go one step ahead and make everything internally. The more we don't rely on the DOM, the better.

Drag-and-drop pieces

Allow to drag and drop pieces with the mouse.

Enabled by default, but the feature can be disabled.

Consider having the current "click=select-move-from click=move-to" work alongside the new drag and drop when the user clicks a piece but immediately drops it without having dragged a bit.

Prevent scrollbars from appearing when dragging in some scenarios

Sometimes when the window is zoomed in and you start dragging a piece, scrollbars will appear (horizontal and vertical).

Also when the console is open, the dragged piece will go a bit further and create scrollbars. Some research need to be done in the differences of using document, document.body and window.

Feature request: allow boards smaller than 8x8

Hello,

Some games (problems for young players for example) require boards which are smaller than 8x8.

Do you think you could add the ability to create smaller boards than 8x8?

For example, it could be nice to initialize the board with FEN string like: 3k2/1Qnp2/2r3/3N2/6/K5 w - - 1 1

Thanks in advance for your answer and have a nice day.

Variety of themes and chess-fonts

Create some variety of themes that can be applied like: IcUi.setTheme("wood") this is tentative and it should probably not be done this way (maybe should be a board property to be consistent with the "isUnlabeled" board property).

It should be only just 1 class that gets added to the board and have everything from the theme cascading down to each element.

Set-up position mode

Some way to enter a setup mode allowing to place pieces (probably dragged and dropped from somewhere, or click to toggle between all pieces) and then exiting the setup mode triggers a position validation and only allows to exit the setup/edit mode when the fen is legal.

With some component to help in clearing/emptying the board and to specify en passant square, castling rights, half/full move clocks, etc.

Dragging pieces after content changes is glitchy

When the window is resized it works fine, however when the window change in size as resulting of something in the page loading, the drag and drop becomes a broken.

The piece would jump and follow the cursor with some vertical empty space difference, also the dragging limits get calculated incorrectly.

Ignoring the wrong position of the piece, dropping the piece (as if it were correctly following the cursor) sends the correct move though. But still, this is super broken and high priority bug to fix.

API for show/hide labels

The recent removal of UI-only board properties in isepic-chess.js v6.0.0 (board.isUnlabeled for that matter) makes it impossible to show/hide board labels without manually modifying the source-code of isepic-chess-ui.js (var _HIDE_LABELS=false;).

A new API method should be added to bring back this possibility, preferably not per-board but to all boards rendered.

Arrows and square highlights

Most likely done via Right clicking (once for red square highlight toggle and click+drag for arrow drawing).

Left clicking a square should clear all arrows and red squares.

Config. to have this disabled.

Maybe there should also be a way to describe these arrows in a PGN comment or NAG so they get drawn as the replayer reads the move.

If you have a selected piece, you should be able to click&drag it

What happens in lichess is:

  • You have a selected piece without having mouse pressed (either you selected via clicking it, or dragging and dropping on the same square)
  • You can immediately start dragging it elsewhere
  • If you drop it again on the square it now unselects it.

Currently we are doing -> if you have a selected piece (while not having anything pressed) -> as soon as you click it, it unselects it and doesn't let you start dragging it.

NuxtJS compatibility?

Are isepic-chess and its UI compatible as Nuxt modules? Has anyone tried this yet?

Improve the drag and drop

Few things were a bit rushed:

  • The rook is not animated on drag and drop castling (it works with the "click from > click to").
  • Center the piece only after the dragging starts to remove the jumpy feeling when using "click from > click to" instead of drag and drop.
  • Some code cleanup.

move puzzle logic into board.playMove() and remove _playMoveCaller()

Currently the only need for _playMoveCaller() to exist is to wrap the calls and do something different when in puzzle mode _CFG.puzzleMode.

But the problem is, sending via the console a board.playMove() move while in puzzle mode will not work.

We should replace the x2 calls on _playMoveCaller() with the native board.playMove() calls. But with the above changes we still need to manually pass _CFG.puzzleMode into some new p option "isPuzzle" or something.

Another alternative is to make something similar to _WIN.IcUi.refreshUi.apply(that, [animation_type, play_sounds]);.

Still unclear which is the best approach, but ideally, the flag of "is puzzle mode?" should live in IcUi, and the logic on how to play puzzle moves should live on Ic.

Interactive promotion choices window

When a pawn reaches the last rank, that square and the next 3 squares towards the center of the board should turn into: Q R B N (sorted in the most promoted piece to least promoted pieces).

Pressing ESC or clicking outside should revert the move. And also there should be an option for not allowing to cancel. Maybe some API function to select them so people only using the console don't get stuck in there.

Inside board labels

Allow the ABCD... 1234... labels to appear inside instead of outside the board.

It should be compliant with the existing _CFG.boardLabels to actually show them or not.

Support for multiple boards

It is currently not possible to display more than one board at a time (even though we can have multiple virtual boards) because the limitation of not being allowed to have multiple DOM elements sharing the same id.

It would be good not to force the components to have those very specific mandatory id-attributes and rewrite them in a way that we can work with multiple boards visually and no just internally.

The way the auto binding of components work makes this change very hard to implement, a big rewrite needs to take place for this to work.

Feedback on target squares when making a move

It would be great to have this feature:

When you are dragging: you will see the square you are hovering, some kind of highlight or ghost piece.

When you are click-to-move and have selected a piece: when you hover a square you see some kind of highlight or ghost piece.

Default will be turned off

Improve IcUi.setCfg() method

  • Only overwrite known existing options (keys).
  • Some safety checks and sanitization for the input (values).
  • Accept object, array or read N arguments to be able to change more than a single option per call.

Done in v4.6.1:

  • Return value (did the value change to a new value?).
  • Only refresh UI if config changed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.