]> code.delx.au - gnu-emacs-elpa/blobdiff - chess-sound.el
Try to improve the promotion situation on ICS by allowing chess-ply to query for...
[gnu-emacs-elpa] / chess-sound.el
index e5b0de37f1a446e6caa6fecb1fa42b0b6fb6d910..ed1ce532d5e51984c5fb988b74305ea5022a3e69 100644 (file)
@@ -3,7 +3,6 @@
 ;; This is very similar to chess-announce, except it uses specific
 ;; .WAV files instead of text-to-speech.
 ;;
-;; $Revision$
 
 (require 'chess-game)
 
   :group 'chess-sound)
 
 (defsubst chess-sound (file)
-  (funcall chess-sound-play-function
-          (expand-file-name (concat file ".wav")
-                            chess-sound-directory)))
+  (ignore-errors
+    (funcall chess-sound-play-function
+            (expand-file-name (concat file ".wav")
+                              chess-sound-directory))))
 
 (defsubst chess-sound-play (file)
   (apply 'call-process chess-sound-program
         nil nil nil (append chess-sound-args (list file))))
 
-(defun chess-sound-handler (event &rest args)
-  "This display module presents a standard chessboard.
-See `chess-display-type' for the different kinds of displays."
+(defun chess-sound-handler (game event &rest args)
   (cond
    ((eq event 'initialize)
-    (kill-buffer (current-buffer))
-    (set-buffer (generate-new-buffer " *chess-sound*"))
     (and (file-directory-p chess-sound-directory)
         (file-readable-p (expand-file-name "move.wav"
                                            chess-sound-directory))
         (or (eq chess-sound-play-function 'play-sound-file)
-            (file-executable-p chess-sound-program))))
+            (and chess-sound-program
+                 (file-executable-p chess-sound-program)))))
 
    ((eq event 'move)
-    (let* ((ply (chess-game-ply chess-display-game
-                               (1- (chess-game-index chess-display-game))))
+    (let* ((ply (chess-game-ply game (1- (chess-game-index game))))
           (pos (chess-ply-pos ply)))
-      (if (eq (chess-game-data chess-display-game 'my-color)
+      (if (eq (chess-game-data game 'my-color)
              (chess-pos-side-to-move pos))
          (if chess-sound-my-moves
              (chess-sound "move"))
        (let* ((source (chess-ply-source ply))
               (target (chess-ply-target ply))
-              (s-piece (chess-pos-piece pos source))
-              (t-piece (chess-pos-piece pos target))
+              (s-piece (and source (chess-pos-piece pos source)))
+              (t-piece (and target (chess-pos-piece pos target)))
               (which (chess-ply-keyword ply :which))
               text)
          (cond
@@ -83,12 +79,12 @@ See `chess-display-type' for the different kinds of displays."
            (chess-sound "O-O"))
           ((chess-ply-keyword ply :long-castle)
            (chess-sound "O-O-O"))
-          ((= t-piece ? )
+          ((and s-piece t-piece (= t-piece ? ) target)
            (if which
                (chess-sound (char-to-string which)))
            (chess-sound (format "%c_" (downcase s-piece)))
            (chess-sound (chess-index-to-coord target)))
-          (t
+          ((and s-piece t-piece target)
            (if which
                (chess-sound (char-to-string which)))
            (chess-sound (format "%c_" (downcase s-piece)))
@@ -96,6 +92,12 @@ See `chess-display-type' for the different kinds of displays."
            (chess-sound (format "%c_" (downcase t-piece)))
            (chess-sound (chess-index-to-coord target))))
 
+         (if (chess-ply-keyword ply :promote)
+             (chess-sound
+              (format "%c_" (downcase
+                             (chess-ply-keyword ply :promote)))))
+         (if (chess-ply-keyword ply :en-passant)
+             (chess-sound "enpassant"))
          (if (chess-ply-keyword ply :check)
              (chess-sound "+_"))
          (if (chess-ply-keyword ply :checkmate)