From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Dieter Deyke Newsgroups: gmane.emacs.devel Subject: [PATCH] elpa/packages/sokoban/sokoban.el Date: Tue, 25 Jul 2017 13:36:10 +0200 Message-ID: <87tw20hhp1.fsf@deyke2> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1500982694 7311 195.159.176.226 (25 Jul 2017 11:38:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 25 Jul 2017 11:38:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 25 13:38:10 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dZyAB-0001Va-5d for ged-emacs-devel@m.gmane.org; Tue, 25 Jul 2017 13:38:07 +0200 Original-Received: from localhost ([::1]:59933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZyAG-0002yH-Px for ged-emacs-devel@m.gmane.org; Tue, 25 Jul 2017 07:38:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZy8Z-000269-3X for emacs-devel@gnu.org; Tue, 25 Jul 2017 07:36:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dZy8V-0003C2-SG for emacs-devel@gnu.org; Tue, 25 Jul 2017 07:36:27 -0400 Original-Received: from [195.159.176.226] (port=47029 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dZy8V-0003B1-LL for emacs-devel@gnu.org; Tue, 25 Jul 2017 07:36:23 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dZy8M-0004MY-QU for emacs-devel@gnu.org; Tue, 25 Jul 2017 13:36:14 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 136 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:kdyUdzXNGwMf/ByauYYmJeb42kM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217014 Archived-At: Commit message: * sokoban.el: Add support for level data in xml format Add support for level data in xml format as found on http://www.sourcecode.se/sokoban/levels Unrelated additional changes: - add key binding 'F' to fit frame to buffer - show the number of levels available in level file Patch: diff --git a/sokoban.el b/sokoban.el index 2ebe7b4..0908209 100644 --- a/sokoban.el +++ b/sokoban.el @@ -4,7 +4,7 @@ ;; Author: Glynn Clements ;; Maintainer: Dieter Deyke -;; Version: 1.4.4 +;; Version: 1.4.5 ;; Created: 1997-09-11 ;; Keywords: games ;; Package-Type: multi @@ -57,6 +57,7 @@ (require 'cl)) (require 'gamegrid) +(require 'xml) ;; ;;;;;;;;;;;;; customization variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -508,6 +509,7 @@ static char * player_on_target_xpm[] = { (define-key map "n" 'sokoban-start-game) (define-key map "r" 'sokoban-restart-level) (define-key map "g" 'sokoban-goto-level) + (define-key map "F" 'fit-frame-to-buffer) (define-key map [left] 'sokoban-move-left) (define-key map [right] 'sokoban-move-right) @@ -536,11 +538,20 @@ static char * player_on_target_xpm[] = { (defun sokoban-init-level-data () (setq sokoban-level-data nil) - (with-current-buffer (find-file-noselect sokoban-level-file) - (if (fboundp 'read-only-mode) - (read-only-mode 1) - (setq buffer-read-only t)) - + (with-temp-buffer + (insert-file-contents sokoban-level-file) + (goto-char (point-min)) + (if (looking-at "<\\?xml version=") + (let ((n 0) (tree (xml-parse-region))) + (erase-buffer) + (dolist (SokobanLevels tree) + (dolist (LevelCollection (xml-get-children SokobanLevels 'LevelCollection)) + (dolist (Level (xml-get-children LevelCollection 'Level)) + (incf n) + (insert (format ";LEVEL %d\n" n)) + (dolist (L (xml-get-children Level 'L)) + (insert (car (xml-node-children L))) + (insert "\n"))))))) (setq sokoban-width 15 ; need at least 15 for score display sokoban-height 1) (goto-char (point-min)) @@ -567,21 +578,21 @@ static char * player_on_target_xpm[] = { (forward-char) (while (not (eobp)) (while (looking-at sokoban-comment-regexp) - (forward-line)) + (forward-line)) (let ((data (make-vector sokoban-height nil)) (fmt (format "%%-%ds" sokoban-width))) - (dotimes (y sokoban-height) + (dotimes (y sokoban-height) (cond ((or (eobp) (looking-at sokoban-comment-regexp)) - (aset data y (format fmt ""))) - (t - (let ((start (point)) + (aset data y (format fmt ""))) + (t + (let ((start (point)) (end (line-end-position))) (aset data y (format fmt (buffer-substring start end))) (goto-char (1+ end)))))) - (push data sokoban-level-data))) + (push data sokoban-level-data))) (kill-buffer (current-buffer)) (setq sokoban-level-data (nreverse sokoban-level-data)))) @@ -651,8 +662,8 @@ static char * player_on_target_xpm[] = { y (aref string x)))) (incf y))) (setq mode-line-format - (format "Sokoban: Level: %3d Moves: %05d Pushes: %05d Done: %d/%d" - sokoban-level sokoban-moves sokoban-pushes + (format "Sokoban: Level: %d/%d Moves: %05d Pushes: %05d Done: %d/%d" + sokoban-level (length sokoban-level-data) sokoban-moves sokoban-pushes sokoban-done sokoban-targets)) (force-mode-line-update)) @@ -870,7 +881,8 @@ static char * player_on_target_xpm[] = { '("Sokoban Commands" ["Restart this level" sokoban-restart-level] ["Start new game" sokoban-start-game] - ["Go to specific level" sokoban-goto-level])) + ["Go to specific level" sokoban-goto-level] + ["Fit frame to buffer" fit-frame-to-buffer])) (define-key sokoban-mode-map [down-mouse-3] sokoban-popup-menu)) (define-derived-mode sokoban-mode special-mode "Sokoban" @@ -884,8 +896,8 @@ sokoban-mode keybindings: '("Sokoban Commands" ["Restart this level" sokoban-restart-level] ["Start new game" sokoban-start-game] - ["Go to specific level" sokoban-goto-level]))) - + ["Go to specific level" sokoban-goto-level] + ["Fit frame to buffer" fit-frame-to-buffer]))) (set (make-local-variable 'gamegrid-use-glyphs) sokoban-use-glyphs) (set (make-local-variable 'gamegrid-use-color) sokoban-use-color) (set (make-local-variable 'gamegrid-font) sokoban-font) -- Dieter Deyke mailto:dieter.deyke@gmail.com Get my Gnupg key: gpg --keyserver keys.gnupg.net --recv-keys B116EA20