Mercurial > emacs
annotate lisp/play/gamegrid.el @ 97958:dae412744e36
* isearch.el (isearch-highlight-regexp): Fix last change, quoting
non-alphabetical characters properly.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Wed, 03 Sep 2008 00:01:10 +0000 |
parents | b4e36ff621b3 |
children | 814d2d823dd7 |
rev | line source |
---|---|
38425
c6e12c6b1498
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
22490
diff
changeset
|
1 ;;; gamegrid.el --- library for implementing grid-based games on Emacs |
22490 | 2 |
95841
b4e36ff621b3
Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents:
94675
diff
changeset
|
3 ;; Copyright (C) 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
b4e36ff621b3
Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents:
94675
diff
changeset
|
4 ;; 2008 Free Software Foundation, Inc. |
22490 | 5 |
6 ;; Author: Glynn Clements <glynn@sensei.co.uk> | |
7 ;; Version: 1.02 | |
8 ;; Created: 1997-08-13 | |
9 ;; Keywords: games | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
94675
949bd6ad1ba4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
22490 | 14 ;; it under the terms of the GNU General Public License as published by |
94675
949bd6ad1ba4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
949bd6ad1ba4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; (at your option) any later version. |
22490 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
94675
949bd6ad1ba4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
22490 | 25 |
26 ;;; Commentary: | |
27 | |
38425
c6e12c6b1498
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
22490
diff
changeset
|
28 ;;; Code: |
c6e12c6b1498
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
22490
diff
changeset
|
29 |
22490 | 30 (eval-when-compile |
31 (require 'cl)) | |
32 | |
33 ;; ;;;;;;;;;;;;; buffer-local variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
34 | |
35 (defvar gamegrid-use-glyphs t | |
36 "Non-nil means use glyphs when available.") | |
37 | |
38 (defvar gamegrid-use-color t | |
39 "Non-nil means use color when available.") | |
40 | |
41 (defvar gamegrid-font "-*-courier-medium-r-*-*-*-140-100-75-*-*-iso8859-*" | |
42 "Name of the font used in X mode.") | |
43 | |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
44 (defvar gamegrid-face nil |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
45 "Indicates the face to use as a default.") |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
46 (make-variable-buffer-local 'gamegrid-face) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
47 |
22490 | 48 (defvar gamegrid-display-options nil) |
49 | |
50 (defvar gamegrid-buffer-width 0) | |
51 (defvar gamegrid-buffer-height 0) | |
52 (defvar gamegrid-blank 0) | |
53 | |
54 (defvar gamegrid-timer nil) | |
55 | |
56 (defvar gamegrid-display-mode nil) | |
57 | |
58 (defvar gamegrid-display-table) | |
59 | |
60 (defvar gamegrid-face-table nil) | |
61 | |
62 (defvar gamegrid-buffer-start 1) | |
63 | |
64 (defvar gamegrid-score-file-length 50 | |
65 "Number of high scores to keep") | |
66 | |
81348
fc9041cfe332
(gamegrid-user-score-file-directory): Use user-emacs-directory.
Chong Yidong <cyd@stupidchicken.com>
parents:
76282
diff
changeset
|
67 (defvar gamegrid-user-score-file-directory |
fc9041cfe332
(gamegrid-user-score-file-directory): Use user-emacs-directory.
Chong Yidong <cyd@stupidchicken.com>
parents:
76282
diff
changeset
|
68 (concat user-emacs-directory "games") |
45085
9cd63d47f45f
(gamegrid-user-score-file-directory): New variable.
Colin Walters <walters@gnu.org>
parents:
44989
diff
changeset
|
69 "A directory for game scores which can't be shared. |
9cd63d47f45f
(gamegrid-user-score-file-directory): New variable.
Colin Walters <walters@gnu.org>
parents:
44989
diff
changeset
|
70 If Emacs was built without support for shared game scores, then this |
9cd63d47f45f
(gamegrid-user-score-file-directory): New variable.
Colin Walters <walters@gnu.org>
parents:
44989
diff
changeset
|
71 directory will be used.") |
9cd63d47f45f
(gamegrid-user-score-file-directory): New variable.
Colin Walters <walters@gnu.org>
parents:
44989
diff
changeset
|
72 |
22490 | 73 (make-variable-buffer-local 'gamegrid-use-glyphs) |
74 (make-variable-buffer-local 'gamegrid-use-color) | |
75 (make-variable-buffer-local 'gamegrid-font) | |
76 (make-variable-buffer-local 'gamegrid-display-options) | |
77 (make-variable-buffer-local 'gamegrid-buffer-width) | |
78 (make-variable-buffer-local 'gamegrid-buffer-height) | |
79 (make-variable-buffer-local 'gamegrid-blank) | |
80 (make-variable-buffer-local 'gamegrid-timer) | |
81 (make-variable-buffer-local 'gamegrid-display-mode) | |
82 (make-variable-buffer-local 'gamegrid-display-table) | |
83 (make-variable-buffer-local 'gamegrid-face-table) | |
84 (make-variable-buffer-local 'gamegrid-buffer-start) | |
85 (make-variable-buffer-local 'gamegrid-score-file-length) | |
86 | |
87 ;; ;;;;;;;;;;;;; global variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
88 | |
89 (defvar gamegrid-grid-x-face nil) | |
90 (defvar gamegrid-mono-x-face nil) | |
91 (defvar gamegrid-mono-tty-face nil) | |
92 | |
93 ;; ;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
94 | |
95 (defconst gamegrid-glyph-height 16) | |
96 | |
97 (defconst gamegrid-xpm "\ | |
98 /* XPM */ | |
99 static char *noname[] = { | |
100 /* width height ncolors chars_per_pixel */ | |
101 \"16 16 3 1\", | |
102 /* colors */ | |
103 \"+ s col1\", | |
104 \". s col2\", | |
105 \"- s col3\", | |
106 /* pixels */ | |
107 \"---------------+\", | |
108 \"--------------++\", | |
109 \"--............++\", | |
110 \"--............++\", | |
111 \"--............++\", | |
112 \"--............++\", | |
113 \"--............++\", | |
114 \"--............++\", | |
115 \"--............++\", | |
116 \"--............++\", | |
117 \"--............++\", | |
118 \"--............++\", | |
119 \"--............++\", | |
120 \"--............++\", | |
121 \"-+++++++++++++++\", | |
122 \"++++++++++++++++\" | |
123 }; | |
124 " | |
125 "XPM format image used for each square") | |
126 | |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
127 (defvar gamegrid-xbm "\ |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
128 /* gamegrid XBM */ |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
129 #define gamegrid_width 16 |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
130 #define gamegrid_height 16 |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
131 static unsigned char gamegrid_bits[] = { |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
132 0xff, 0xff, 0xff, 0x7f, 0xff, 0x3f, 0xaf, 0x0a, 0x57, 0x15, 0xaf, 0x0a, |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
133 0x57, 0x15, 0xaf, 0x0a, 0x57, 0x15, 0xaf, 0x0a, 0x57, 0x15, 0xaf, 0x0a, |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
134 0x57, 0x15, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00 };" |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
135 "XBM format image used for each square.") |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
136 |
22490 | 137 ;; ;;;;;;;;;;;;;;;; miscellaneous functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
138 | |
139 (defsubst gamegrid-characterp (arg) | |
140 (if (fboundp 'characterp) | |
141 (characterp arg) | |
142 (integerp arg))) | |
143 | |
144 (defsubst gamegrid-event-x (event) | |
145 (if (fboundp 'event-x) | |
146 (event-x event) | |
147 (car (posn-col-row (event-end event))))) | |
148 | |
149 (defsubst gamegrid-event-y (event) | |
150 (if (fboundp 'event-y) | |
151 (event-y event) | |
152 (cdr (posn-col-row (event-end event))))) | |
153 | |
154 ;; ;;;;;;;;;;;;; display functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
155 | |
156 (defun gamegrid-color (color shade) | |
157 (let* ((v (floor (* shade 255))) | |
158 (r (* v (aref color 0))) | |
159 (g (* v (aref color 1))) | |
160 (b (* v (aref color 2)))) | |
161 (format "#%02x%02x%02x" r g b))) | |
162 | |
163 (defun gamegrid-set-font (face) | |
164 (if gamegrid-font | |
165 (condition-case nil | |
166 (set-face-font face gamegrid-font) | |
43651
3075554223d1
(gamegrid-set-font, gamegrid-setup-face)
Richard M. Stallman <rms@gnu.org>
parents:
43117
diff
changeset
|
167 (error nil)))) |
22490 | 168 |
169 (defun gamegrid-setup-face (face color) | |
170 (set-face-foreground face color) | |
171 (set-face-background face color) | |
172 (gamegrid-set-font face) | |
173 (condition-case nil | |
174 (set-face-background-pixmap face [nothing]);; XEmacs | |
43651
3075554223d1
(gamegrid-set-font, gamegrid-setup-face)
Richard M. Stallman <rms@gnu.org>
parents:
43117
diff
changeset
|
175 (error nil)) |
22490 | 176 (condition-case nil |
177 (set-face-background-pixmap face nil);; Emacs | |
43651
3075554223d1
(gamegrid-set-font, gamegrid-setup-face)
Richard M. Stallman <rms@gnu.org>
parents:
43117
diff
changeset
|
178 (error nil))) |
22490 | 179 |
180 (defun gamegrid-make-mono-tty-face () | |
181 (let ((face (make-face 'gamegrid-mono-tty-face))) | |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
182 (set-face-inverse-video-p face t) |
22490 | 183 face)) |
184 | |
185 (defun gamegrid-make-color-tty-face (color) | |
47380
05670dbe9339
(gamegrid-make-color-tty-face): Handle string as COLOR arg.
Richard M. Stallman <rms@gnu.org>
parents:
45085
diff
changeset
|
186 (let* ((color-str (if (symbolp color) (symbol-value color) color)) |
43117
7541bec297e3
(gamegrid-display-type): Treat any
Eli Zaretskii <eliz@gnu.org>
parents:
41560
diff
changeset
|
187 (name (intern (format "gamegrid-color-tty-face-%s" color-str))) |
22490 | 188 (face (make-face name))) |
43117
7541bec297e3
(gamegrid-display-type): Treat any
Eli Zaretskii <eliz@gnu.org>
parents:
41560
diff
changeset
|
189 (gamegrid-setup-face face color-str) |
22490 | 190 face)) |
191 | |
192 (defun gamegrid-make-grid-x-face () | |
193 (let ((face (make-face 'gamegrid-x-border-face))) | |
194 (gamegrid-set-font face) | |
195 face)) | |
196 | |
197 (defun gamegrid-make-mono-x-face () | |
198 (let ((face (make-face 'gamegrid-mono-x-face)) | |
199 (color (face-foreground 'default))) | |
200 (if (null color) | |
201 (setq color | |
202 (cdr-safe (assq 'foreground-color (frame-parameters))))) | |
203 (gamegrid-setup-face face color) | |
204 face)) | |
205 | |
206 (defun gamegrid-make-color-x-face (color) | |
207 (let* ((hex (gamegrid-color color 1.0)) | |
208 (name (intern (format "gamegrid-color-x-face-%s" hex))) | |
209 (face (make-face name))) | |
43117
7541bec297e3
(gamegrid-display-type): Treat any
Eli Zaretskii <eliz@gnu.org>
parents:
41560
diff
changeset
|
210 (gamegrid-setup-face face hex) |
22490 | 211 face)) |
212 | |
213 (defun gamegrid-make-face (data-spec-list color-spec-list) | |
214 (let ((data (gamegrid-match-spec-list data-spec-list)) | |
215 (color (gamegrid-match-spec-list color-spec-list))) | |
216 (case data | |
217 ('color-x | |
218 (gamegrid-make-color-x-face color)) | |
219 ('grid-x | |
220 (unless gamegrid-grid-x-face | |
221 (setq gamegrid-grid-x-face (gamegrid-make-grid-x-face))) | |
222 gamegrid-grid-x-face) | |
223 ('mono-x | |
224 (unless gamegrid-mono-x-face | |
225 (setq gamegrid-mono-x-face (gamegrid-make-mono-x-face))) | |
226 gamegrid-mono-x-face) | |
227 ('color-tty | |
228 (gamegrid-make-color-tty-face color)) | |
229 ('mono-tty | |
230 (unless gamegrid-mono-tty-face | |
231 (setq gamegrid-mono-tty-face (gamegrid-make-mono-tty-face))) | |
232 gamegrid-mono-tty-face)))) | |
233 | |
234 (defun gamegrid-colorize-glyph (color) | |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
235 (find-image `((:type xpm :data ,gamegrid-xpm |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
236 :ascent center |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47587
diff
changeset
|
237 :color-symbols |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
238 (("col1" . ,(gamegrid-color color 0.6)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
239 ("col2" . ,(gamegrid-color color 0.8)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
240 ("col3" . ,(gamegrid-color color 1.0)))) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
241 (:type xbm :data ,gamegrid-xbm |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
242 :ascent center |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
243 :foreground ,(gamegrid-color color 1.0) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
244 :background ,(gamegrid-color color 0.5))))) |
22490 | 245 |
246 (defun gamegrid-match-spec (spec) | |
247 (let ((locale (car spec)) | |
248 (value (cadr spec))) | |
249 (and (or (eq locale t) | |
250 (and (listp locale) | |
251 (memq gamegrid-display-mode locale)) | |
252 (and (symbolp locale) | |
253 (eq gamegrid-display-mode locale))) | |
254 value))) | |
255 | |
256 (defun gamegrid-match-spec-list (spec-list) | |
257 (and spec-list | |
258 (or (gamegrid-match-spec (car spec-list)) | |
259 (gamegrid-match-spec-list (cdr spec-list))))) | |
260 | |
261 (defun gamegrid-make-glyph (data-spec-list color-spec-list) | |
262 (let ((data (gamegrid-match-spec-list data-spec-list)) | |
263 (color (gamegrid-match-spec-list color-spec-list))) | |
264 (cond ((gamegrid-characterp data) | |
265 (vector data)) | |
266 ((eq data 'colorize) | |
267 (gamegrid-colorize-glyph color)) | |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
268 ((listp data) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
269 (find-image data)) ;untested! |
22490 | 270 ((vectorp data) |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
271 (gamegrid-make-image-from-vector data))))) |
22490 | 272 |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
273 (defun gamegrid-make-image-from-vector (vect) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
274 "Convert an XEmacs style \"glyph\" to an image-spec." |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
275 (let ((l (list 'image :type))) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
276 (dotimes (n (length vect)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
277 (setf l (nconc l (list (aref vect n))))) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
278 (nconc l (list :ascent 'center)))) |
22490 | 279 |
280 (defun gamegrid-display-type () | |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
281 (cond ((and gamegrid-use-glyphs |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
282 (display-images-p)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
283 'glyph) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
284 ((and gamegrid-use-color |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
285 (display-graphic-p) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
286 (display-color-p)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
287 'color-x) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
288 ((display-graphic-p) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
289 'mono-x) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
290 ((and gamegrid-use-color |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
291 (display-color-p)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
292 'color-tty) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
293 ((display-multi-font-p) ;??? |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
294 'mono-tty) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
295 (t |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
296 'emacs-tty))) |
22490 | 297 |
298 (defun gamegrid-set-display-table () | |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
299 (if (featurep 'xemacs) |
22490 | 300 (add-spec-to-specifier current-display-table |
301 gamegrid-display-table | |
302 (current-buffer) | |
303 nil | |
304 'remove-locale) | |
305 (setq buffer-display-table gamegrid-display-table))) | |
306 | |
95841
b4e36ff621b3
Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents:
94675
diff
changeset
|
307 (declare-function image-size "image.c" (spec &optional pixels frame)) |
b4e36ff621b3
Add some compiler declarations, for builds without X.
Glenn Morris <rgm@gnu.org>
parents:
94675
diff
changeset
|
308 |
22490 | 309 (defun gamegrid-setup-default-font () |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
310 (setq gamegrid-face |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
311 (copy-face 'default |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
312 (intern (concat "gamegrid-face-" (buffer-name))))) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
313 (when (eq gamegrid-display-mode 'glyph) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
314 (let ((max-height nil)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
315 (loop for c from 0 to 255 do |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
316 (let ((glyph (aref gamegrid-display-table c))) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
317 (when (and (listp glyph) (eq (car glyph) 'image)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
318 (let ((height (cdr (image-size glyph)))) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
319 (if (or (null max-height) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
320 (< max-height height)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
321 (setq max-height height)))))) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
322 (when (and max-height (< max-height 1)) |
91013
850287d64489
(gamegrid-setup-default-font): Calculate a font
Kenichi Handa <handa@m17n.org>
parents:
90996
diff
changeset
|
323 (let ((default-font-height (face-attribute 'default :height)) |
850287d64489
(gamegrid-setup-default-font): Calculate a font
Kenichi Handa <handa@m17n.org>
parents:
90996
diff
changeset
|
324 (resy (/ (display-pixel-height) (/ (display-mm-height) 25.4))) |
850287d64489
(gamegrid-setup-default-font): Calculate a font
Kenichi Handa <handa@m17n.org>
parents:
90996
diff
changeset
|
325 point-size pixel-size) |
850287d64489
(gamegrid-setup-default-font): Calculate a font
Kenichi Handa <handa@m17n.org>
parents:
90996
diff
changeset
|
326 (setq point-size (/ (* (float default-font-height) max-height) 10) |
850287d64489
(gamegrid-setup-default-font): Calculate a font
Kenichi Handa <handa@m17n.org>
parents:
90996
diff
changeset
|
327 pixel-size (floor (* resy (/ point-size 72.27))) |
850287d64489
(gamegrid-setup-default-font): Calculate a font
Kenichi Handa <handa@m17n.org>
parents:
90996
diff
changeset
|
328 point-size (* (/ pixel-size resy) 72.27)) |
91041 | 329 (face-spec-set gamegrid-face |
330 `((t :height ,(floor (* point-size 10)))))))))) | |
22490 | 331 |
332 (defun gamegrid-initialize-display () | |
333 (setq gamegrid-display-mode (gamegrid-display-type)) | |
334 (setq gamegrid-display-table (make-display-table)) | |
335 (setq gamegrid-face-table (make-vector 256 nil)) | |
336 (loop for c from 0 to 255 do | |
337 (let* ((spec (aref gamegrid-display-options c)) | |
338 (glyph (gamegrid-make-glyph (car spec) (caddr spec))) | |
339 (face (gamegrid-make-face (cadr spec) (caddr spec)))) | |
340 (aset gamegrid-face-table c face) | |
341 (aset gamegrid-display-table c glyph))) | |
342 (gamegrid-setup-default-font) | |
343 (gamegrid-set-display-table) | |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
344 (setq cursor-type nil)) |
22490 | 345 |
346 | |
347 (defun gamegrid-set-face (c) | |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
348 (if (eq gamegrid-display-mode 'glyph) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
349 (add-text-properties (1- (point)) (point) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
350 (list 'display (list (aref gamegrid-display-table c)))) |
22490 | 351 (put-text-property (1- (point)) |
352 (point) | |
353 'face | |
354 (aref gamegrid-face-table c)))) | |
355 | |
356 (defun gamegrid-cell-offset (x y) | |
357 (+ gamegrid-buffer-start | |
358 (* (1+ gamegrid-buffer-width) y) | |
359 x)) | |
360 | |
361 ;; ;;;;;;;;;;;;;;;; grid functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
362 | |
363 (defun gamegrid-get-cell (x y) | |
364 (char-after (gamegrid-cell-offset x y))) | |
365 | |
366 (defun gamegrid-set-cell (x y c) | |
367 (save-excursion | |
368 (let ((buffer-read-only nil)) | |
369 (goto-char (gamegrid-cell-offset x y)) | |
370 (delete-char 1) | |
371 (insert-char c 1) | |
372 (gamegrid-set-face c)))) | |
373 | |
374 (defun gamegrid-init-buffer (width height blank) | |
375 (setq gamegrid-buffer-width width | |
376 gamegrid-buffer-height height) | |
377 (let ((line (concat | |
378 (make-string width blank) | |
379 "\n")) | |
380 (buffer-read-only nil)) | |
381 (erase-buffer) | |
382 (setq gamegrid-buffer-start (point)) | |
383 (dotimes (i height) | |
41560
7428670426b2
(gamegrid-init-buffer): Use insert instead of insert-string.
Pavel Janík <Pavel@Janik.cz>
parents:
38425
diff
changeset
|
384 (insert line)) |
47587
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
385 ;; Adjust the height of the default face to the height of the |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
386 ;; images. Unlike XEmacs, Emacs doesn't allow to make the default |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
387 ;; face buffer-local; so we do this with an overlay. |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
388 (when (eq gamegrid-display-mode 'glyph) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
389 (overlay-put (make-overlay (point-min) (point-max)) |
7e861822d947
(gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents:
47380
diff
changeset
|
390 'face gamegrid-face)) |
22490 | 391 (goto-char (point-min)))) |
392 | |
393 (defun gamegrid-init (options) | |
394 (setq buffer-read-only t | |
395 truncate-lines t | |
82927
58255c61eccf
(gamegrid-init): Set line-spacing to 0.
Kenichi Handa <handa@m17n.org>
parents:
82140
diff
changeset
|
396 line-spacing 0 |
22490 | 397 gamegrid-display-options options) |
398 (buffer-disable-undo (current-buffer)) | |
399 (gamegrid-initialize-display)) | |
400 | |
401 ;; ;;;;;;;;;;;;;;;; timer functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
402 | |
403 (defun gamegrid-start-timer (period func) | |
404 (setq gamegrid-timer | |
85847
baa28899f76f
* ediff-util.el (ediff-nuke-selective-display): Move definition to
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85093
diff
changeset
|
405 (if (featurep 'xemacs) |
22490 | 406 (start-itimer "Gamegrid" |
407 func | |
408 period | |
409 period | |
410 nil | |
411 t | |
412 (current-buffer)) | |
413 (run-with-timer period | |
414 period | |
415 func | |
416 (current-buffer))))) | |
417 | |
418 (defun gamegrid-set-timer (delay) | |
419 (if gamegrid-timer | |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
420 (if (fboundp 'set-itimer-restart) |
22490 | 421 (set-itimer-restart gamegrid-timer delay) |
422 (timer-set-time gamegrid-timer | |
423 (list (aref gamegrid-timer 1) | |
424 (aref gamegrid-timer 2) | |
425 (aref gamegrid-timer 3)) | |
426 delay)))) | |
427 | |
428 (defun gamegrid-kill-timer () | |
429 (if gamegrid-timer | |
85847
baa28899f76f
* ediff-util.el (ediff-nuke-selective-display): Move definition to
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85093
diff
changeset
|
430 (if (featurep 'xemacs) |
22490 | 431 (delete-itimer gamegrid-timer) |
75483
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
432 (cancel-timer gamegrid-timer))) |
22490 | 433 (setq gamegrid-timer nil)) |
434 | |
435 ;; ;;;;;;;;;;;;;;; high score functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
436 | |
437 (defun gamegrid-add-score (file score) | |
49986
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
438 "Add the current score to the high score file. |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
439 |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
440 On POSIX systems there may be a shared game directory for all users in |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
441 which the scorefiles are kept. On such systems Emacs doesn't create |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
442 the score file FILE in this directory, if it doesn't already exist. In |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
443 this case Emacs searches for FILE in the directory specified by |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
444 `gamegrid-user-score-file-directory' and creates it there, if |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
445 necessary. |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
446 |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
447 To add the score file for a game to the system wide shared game |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
448 directory, create the file with the shell command \"touch\" in this |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
449 directory and make sure that it is owned by the correct user and |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
450 group. You probably need special user privileges to do this. |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
451 |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
452 On non-POSIX systems Emacs searches for FILE in the directory |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
453 specified by the variable `temporary-file-directory'. If necessary, |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
454 FILE is created there." |
44565
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
455 (case system-type |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
456 ((ms-dos windows-nt) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
457 (gamegrid-add-score-insecure file score)) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
458 (t |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
459 (gamegrid-add-score-with-update-game-score file score)))) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
460 |
50734
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
461 |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
462 ;; On POSIX systems there are four cases to distinguish: |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
463 |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
464 ;; 1. FILE is an absolute filename. Then it should be a file in |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
465 ;; temporary file directory. This is the way, |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
466 ;; `gamegrid-add-score' was supposed to be used in the past and |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
467 ;; is covered here for backward-compatibility. |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
468 ;; |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
469 ;; 2. The helper program "update-game-score" is setuid and the |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
470 ;; file FILE does already exist in a system wide shared game |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
471 ;; directory. This should be the normal case on POSIX systems, |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
472 ;; if the game was installed system wide. Use |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
473 ;; "update-game-score" to add the score to the file in the |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
474 ;; shared game directory. |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
475 ;; |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
476 ;; 3. "update-game-score" is setuid, but the file FILE does *not* |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
477 ;; exist in the system wide shared game directory. Use |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
478 ;; `gamegrid-add-score-insecure' to create--if necessary--and |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
479 ;; update FILE. This is for the case that a user has installed |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
480 ;; a game on her own. |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
481 ;; |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
482 ;; 4. "update-game-score" is not setuid. Use it to create/update |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
483 ;; FILE in the user's home directory. There is presumably no |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
484 ;; shared game directory. |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
485 |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
486 (defvar gamegrid-shared-game-dir) |
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
487 |
44565
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
488 (defun gamegrid-add-score-with-update-game-score (file score) |
49986
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
489 (let* ((result nil) ;; What is this good for? -- os |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
490 (gamegrid-shared-game-dir |
44989
78b836bc2213
(gamegrid-add-score-with-update-game-score): Test whether or not
Colin Walters <walters@gnu.org>
parents:
44792
diff
changeset
|
491 (not (zerop (logand (file-modes |
78b836bc2213
(gamegrid-add-score-with-update-game-score): Test whether or not
Colin Walters <walters@gnu.org>
parents:
44792
diff
changeset
|
492 (expand-file-name "update-game-score" |
78b836bc2213
(gamegrid-add-score-with-update-game-score): Test whether or not
Colin Walters <walters@gnu.org>
parents:
44792
diff
changeset
|
493 exec-directory)) |
49986
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
494 #o4000))))) |
50734
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
495 (cond ((file-name-absolute-p file) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
496 (gamegrid-add-score-insecure file score)) |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
497 ((and gamegrid-shared-game-dir |
50734
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
498 (file-exists-p (expand-file-name file shared-game-score-directory))) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
499 ;; Use the setuid "update-game-score" program to update a |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
500 ;; system-wide score file. |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
501 (gamegrid-add-score-with-update-game-score-1 file |
50734
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
502 (expand-file-name file shared-game-score-directory) score)) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
503 ;; Else: Add the score to a score file in the user's home |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
504 ;; directory. |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
505 (gamegrid-shared-game-dir |
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
506 ;; If `gamegrid-shared-game-dir' is non-nil, then |
50734
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
507 ;; "update-gamescore" program is setuid, so don't use it. |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
508 (unless (file-exists-p |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
509 (directory-file-name gamegrid-user-score-file-directory)) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
510 (make-directory gamegrid-user-score-file-directory t)) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
511 (gamegrid-add-score-insecure file score |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
512 gamegrid-user-score-file-directory)) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
513 (t (let ((f (expand-file-name |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
514 gamegrid-user-score-file-directory))) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
515 (when (file-writable-p f) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
516 (unless (eq (car-safe (file-attributes f)) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
517 t) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
518 (make-directory f)) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
519 (setq f (expand-file-name file f)) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
520 (unless (file-exists-p f) |
17be3e4887ea
Added a comment explaining the various ways to save a game score on POSIX
Juanma Barranquero <lekktu@gmail.com>
parents:
49986
diff
changeset
|
521 (write-region "" nil f nil 'silent nil 'excl))) |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
522 (gamegrid-add-score-with-update-game-score-1 file f score)))))) |
49986
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
523 |
64390
d5c99d67c76d
(gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
524 (defun gamegrid-add-score-with-update-game-score-1 (file target score) |
49986
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
525 (let ((default-directory "/") |
76282
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
526 (errbuf (generate-new-buffer " *update-game-score loss*")) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
527 (marker-string (concat |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
528 (user-full-name) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
529 " <" |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
530 (cond ((fboundp 'user-mail-address) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
531 (user-mail-address)) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
532 ((boundp 'user-mail-address) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
533 user-mail-address) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
534 (t "")) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
535 "> " |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
536 (current-time-string)))) |
75483
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
537 ;; This can be called from a timer, so enable local quits. |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
538 (with-local-quit |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
539 (apply |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
540 'call-process |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
541 (append |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
542 (list |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
543 (expand-file-name "update-game-score" exec-directory) |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
544 nil errbuf nil |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
545 "-m" (int-to-string gamegrid-score-file-length) |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
546 "-d" (if gamegrid-shared-game-dir |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
547 (expand-file-name shared-game-score-directory) |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
548 (file-name-directory target)) |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
549 file |
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
550 (int-to-string score) |
76282
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
551 marker-string)))) |
44494 | 552 (if (buffer-modified-p errbuf) |
553 (progn | |
554 (display-buffer errbuf) | |
555 (error "Failed to update game score file")) | |
556 (kill-buffer errbuf)) | |
75483
4b3089985bc1
(gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents:
75347
diff
changeset
|
557 (let ((buf (find-buffer-visiting target))) |
76282
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
558 (save-excursion |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
559 (if buf |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
560 (progn |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
561 (switch-to-buffer buf) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
562 (revert-buffer nil t nil) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
563 (display-buffer buf)) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
564 (find-file-read-only target)) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
565 (goto-char (point-min)) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
566 (search-forward (concat (int-to-string score) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
567 " " (user-login-name) " " |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
568 marker-string)) |
5c5cfff568a1
(gamegrid-add-score-with-update-game-score-1): Jump to the line where new score
Eli Zaretskii <eliz@gnu.org>
parents:
75483
diff
changeset
|
569 (beginning-of-line))))) |
44792
4648f6129f7f
(gamegrid-add-score-with-update-game-score): Handle the case where
Colin Walters <walters@gnu.org>
parents:
44565
diff
changeset
|
570 |
49986
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
571 (defun gamegrid-add-score-insecure (file score &optional directory) |
44565
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
572 (save-excursion |
49986
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
573 (setq file (expand-file-name file (or directory |
755c2ca7f6cf
(gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
49598
diff
changeset
|
574 temporary-file-directory))) |
44565
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
575 (find-file-other-window file) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
576 (setq buffer-read-only nil) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
577 (goto-char (point-max)) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
578 (insert (format "%05d\t%s\t%s <%s>\n" |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
579 score |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
580 (current-time-string) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
581 (user-full-name) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
582 (cond ((fboundp 'user-mail-address) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
583 (user-mail-address)) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
584 ((boundp 'user-mail-address) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
585 user-mail-address) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
586 (t "")))) |
54716
1ffff21d0989
(gamegrid-add-score-insecure): Use sort-fields.
Jesper Harder <harder@ifa.au.dk>
parents:
52401
diff
changeset
|
587 (sort-fields 1 (point-min) (point-max)) |
44565
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
588 (reverse-region (point-min) (point-max)) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
589 (goto-line (1+ gamegrid-score-file-length)) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
590 (delete-region (point) (point-max)) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
591 (setq buffer-read-only t) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
592 (save-buffer))) |
9bdd94e7a205
(gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents:
44494
diff
changeset
|
593 |
22490 | 594 |
595 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
596 | |
597 (provide 'gamegrid) | |
38425
c6e12c6b1498
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
22490
diff
changeset
|
598 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91327
diff
changeset
|
599 ;; arch-tag: a96c2ff4-1c12-427e-bd3d-faeaf174cd46 |
38425
c6e12c6b1498
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
22490
diff
changeset
|
600 ;;; gamegrid.el ends here |