vitogit / vue-chessboard

Chessboard vue component to load positions, create positions and see threats
http://vitomd.com/vue-chessboard-examples/
GNU General Public License v3.0
165 stars 49 forks source link

How i can disable user moves? #15

Open facku opened 4 years ago

facku commented 4 years ago

Hi, i need disable user moves feature. I need only programmatically moves.

vitogit commented 4 years ago

Probably I will add that option in a future version (maybe next month), for now I think you can create a new component that extend vue-chessboard (https://github.com/vitogit/vue-chessboard#extended-component-play-vs-random-ai) and use the chessground viewonly option.

    <script>
    import { chessboard }  from 'vue-chessboard'

    export default {
      name: 'newboard',
      extends: chessboard,
      mounted() {
        this.board.set({
          viewOnly: true
        })
      }
    }
    </script>
jlincoln commented 3 years ago

I do this using a method that sets the state.movable.color attribute. It has the drawback of no longer allowing the user to scroll the page when pressing on the board though when run on a touch enabled device.

setBoardUnmovable: function() { this.$refs.echessboard.board.state.movable.color = ''; },