annotate lisp/play/gamegrid.el @ 91013:850287d64489

(gamegrid-setup-default-font): Calculate a font height that doesn't exceed the requested height by rounding off.
author Kenichi Handa <handa@m17n.org>
date Thu, 23 Aug 2007 12:13:24 +0000
parents f55f9811f5d7
children b83d0dadb2a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
74509
f7702c5f335d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68634
diff changeset
3 ;; Copyright (C) 1997, 1998, 2001, 2002, 2003, 2004,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 74509
diff changeset
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: Glynn Clements <glynn@sensei.co.uk>
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Version: 1.02
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Created: 1997-08-13
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; Keywords: games
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
78227
527f752989fc Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 76282
diff changeset
15 ;; the Free Software Foundation; either version 3, or (at your option)
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; any later version.
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62249
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62249
diff changeset
26 ;; Boston, MA 02110-1301, USA.
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
38425
c6e12c6b1498 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 22490
diff changeset
30 ;;; Code:
c6e12c6b1498 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 22490
diff changeset
31
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (eval-when-compile
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 (require 'cl))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; ;;;;;;;;;;;;; buffer-local variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 (defvar gamegrid-use-glyphs t
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 "Non-nil means use glyphs when available.")
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (defvar gamegrid-use-color t
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 "Non-nil means use color when available.")
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (defvar gamegrid-font "-*-courier-medium-r-*-*-*-140-100-75-*-*-iso8859-*"
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 "Name of the font used in X mode.")
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
47587
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
46 (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
47 "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
48 (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
49
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (defvar gamegrid-display-options nil)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (defvar gamegrid-buffer-width 0)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (defvar gamegrid-buffer-height 0)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (defvar gamegrid-blank 0)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (defvar gamegrid-timer nil)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (defvar gamegrid-display-mode nil)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (defvar gamegrid-display-table)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (defvar gamegrid-face-table nil)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (defvar gamegrid-buffer-start 1)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (defvar gamegrid-score-file-length 50
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 "Number of high scores to keep")
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68
81348
fc9041cfe332 (gamegrid-user-score-file-directory): Use user-emacs-directory.
Chong Yidong <cyd@stupidchicken.com>
parents: 76282
diff changeset
69 (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
70 (concat user-emacs-directory "games")
45085
9cd63d47f45f (gamegrid-user-score-file-directory): New variable.
Colin Walters <walters@gnu.org>
parents: 44989
diff changeset
71 "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
72 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
73 directory will be used.")
9cd63d47f45f (gamegrid-user-score-file-directory): New variable.
Colin Walters <walters@gnu.org>
parents: 44989
diff changeset
74
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (make-variable-buffer-local 'gamegrid-use-glyphs)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (make-variable-buffer-local 'gamegrid-use-color)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (make-variable-buffer-local 'gamegrid-font)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (make-variable-buffer-local 'gamegrid-display-options)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (make-variable-buffer-local 'gamegrid-buffer-width)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (make-variable-buffer-local 'gamegrid-buffer-height)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (make-variable-buffer-local 'gamegrid-blank)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (make-variable-buffer-local 'gamegrid-timer)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (make-variable-buffer-local 'gamegrid-display-mode)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (make-variable-buffer-local 'gamegrid-display-table)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (make-variable-buffer-local 'gamegrid-face-table)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (make-variable-buffer-local 'gamegrid-buffer-start)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (make-variable-buffer-local 'gamegrid-score-file-length)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; ;;;;;;;;;;;;; global variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (defvar gamegrid-grid-x-face nil)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (defvar gamegrid-mono-x-face nil)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (defvar gamegrid-mono-tty-face nil)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; ;;;;;;;;;;;;; constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (defconst gamegrid-glyph-height 16)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (defconst gamegrid-xpm "\
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 /* XPM */
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 static char *noname[] = {
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 /* width height ncolors chars_per_pixel */
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 \"16 16 3 1\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 /* colors */
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 \"+ s col1\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 \". s col2\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 \"- s col3\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 /* pixels */
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 \"---------------+\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 \"--------------++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 \"--............++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 \"-+++++++++++++++\",
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 \"++++++++++++++++\"
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 };
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 "
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 "XPM format image used for each square")
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
47587
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
129 (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
130 /* gamegrid XBM */
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
131 #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
132 #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
133 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
134 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
135 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
136 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
137 "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
138
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;; ;;;;;;;;;;;;;;;; miscellaneous functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (defsubst gamegrid-characterp (arg)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (if (fboundp 'characterp)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (characterp arg)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (integerp arg)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (defsubst gamegrid-event-x (event)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (if (fboundp 'event-x)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (event-x event)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (car (posn-col-row (event-end event)))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defsubst gamegrid-event-y (event)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (if (fboundp 'event-y)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (event-y event)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (cdr (posn-col-row (event-end event)))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 ;; ;;;;;;;;;;;;; display functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (defun gamegrid-color (color shade)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (let* ((v (floor (* shade 255)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (r (* v (aref color 0)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (g (* v (aref color 1)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (b (* v (aref color 2))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (format "#%02x%02x%02x" r g b)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (defun gamegrid-set-font (face)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (if gamegrid-font
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (condition-case nil
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (set-face-font face gamegrid-font)
43651
3075554223d1 (gamegrid-set-font, gamegrid-setup-face)
Richard M. Stallman <rms@gnu.org>
parents: 43117
diff changeset
169 (error nil))))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (defun gamegrid-setup-face (face color)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (set-face-foreground face color)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (set-face-background face color)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (gamegrid-set-font face)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (condition-case nil
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (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
177 (error nil))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (condition-case nil
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (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
180 (error nil)))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (defun gamegrid-make-mono-tty-face ()
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (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
184 (set-face-inverse-video-p face t)
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 face))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (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
188 (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
189 (name (intern (format "gamegrid-color-tty-face-%s" color-str)))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (face (make-face name)))
43117
7541bec297e3 (gamegrid-display-type): Treat any
Eli Zaretskii <eliz@gnu.org>
parents: 41560
diff changeset
191 (gamegrid-setup-face face color-str)
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 face))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (defun gamegrid-make-grid-x-face ()
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (let ((face (make-face 'gamegrid-x-border-face)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (gamegrid-set-font face)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 face))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (defun gamegrid-make-mono-x-face ()
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (let ((face (make-face 'gamegrid-mono-x-face))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (color (face-foreground 'default)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (if (null color)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (setq color
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (cdr-safe (assq 'foreground-color (frame-parameters)))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (gamegrid-setup-face face color)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 face))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (defun gamegrid-make-color-x-face (color)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (let* ((hex (gamegrid-color color 1.0))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (name (intern (format "gamegrid-color-x-face-%s" hex)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (face (make-face name)))
43117
7541bec297e3 (gamegrid-display-type): Treat any
Eli Zaretskii <eliz@gnu.org>
parents: 41560
diff changeset
212 (gamegrid-setup-face face hex)
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 face))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (defun gamegrid-make-face (data-spec-list color-spec-list)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (let ((data (gamegrid-match-spec-list data-spec-list))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (color (gamegrid-match-spec-list color-spec-list)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (case data
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ('color-x
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (gamegrid-make-color-x-face color))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ('grid-x
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (unless gamegrid-grid-x-face
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (setq gamegrid-grid-x-face (gamegrid-make-grid-x-face)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 gamegrid-grid-x-face)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 ('mono-x
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (unless gamegrid-mono-x-face
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (setq gamegrid-mono-x-face (gamegrid-make-mono-x-face)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 gamegrid-mono-x-face)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ('color-tty
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (gamegrid-make-color-tty-face color))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 ('mono-tty
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (unless gamegrid-mono-tty-face
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (setq gamegrid-mono-tty-face (gamegrid-make-mono-tty-face)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 gamegrid-mono-tty-face))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (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
237 (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
238 :ascent center
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47587
diff changeset
239 :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
240 (("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
241 ("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
242 ("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
243 (: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
244 :ascent center
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
245 :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
246 :background ,(gamegrid-color color 0.5)))))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (defun gamegrid-match-spec (spec)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (let ((locale (car spec))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (value (cadr spec)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (and (or (eq locale t)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (and (listp locale)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (memq gamegrid-display-mode locale))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (and (symbolp locale)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (eq gamegrid-display-mode locale)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 value)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (defun gamegrid-match-spec-list (spec-list)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (and spec-list
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (or (gamegrid-match-spec (car spec-list))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (gamegrid-match-spec-list (cdr spec-list)))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (defun gamegrid-make-glyph (data-spec-list color-spec-list)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (let ((data (gamegrid-match-spec-list data-spec-list))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (color (gamegrid-match-spec-list color-spec-list)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (cond ((gamegrid-characterp data)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (vector data))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 ((eq data 'colorize)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (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
270 ((listp data)
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
271 (find-image data)) ;untested!
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 ((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
273 (gamegrid-make-image-from-vector data)))))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
47587
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
275 (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
276 "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
277 (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
278 (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
279 (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
280 (nconc l (list :ascent 'center))))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (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
283 (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
284 (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
285 'glyph)
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
286 ((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
287 (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
288 (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
289 'color-x)
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
290 ((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
291 'mono-x)
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
292 ((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
293 (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
294 'color-tty)
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
295 ((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
296 'mono-tty)
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
297 (t
7e861822d947 (gamegrid-face): new variable to emulate a buffer-local default face.
Richard M. Stallman <rms@gnu.org>
parents: 47380
diff changeset
298 'emacs-tty)))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (defun gamegrid-set-display-table ()
64390
d5c99d67c76d (gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
301 (if (featurep 'xemacs)
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (add-spec-to-specifier current-display-table
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 gamegrid-display-table
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (current-buffer)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 nil
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 'remove-locale)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (setq buffer-display-table gamegrid-display-table)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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))
850287d64489 (gamegrid-setup-default-font): Calculate a font
Kenichi Handa <handa@m17n.org>
parents: 90996
diff changeset
329 (set-face-attribute gamegrid-face nil
850287d64489 (gamegrid-setup-default-font): Calculate a font
Kenichi Handa <handa@m17n.org>
parents: 90996
diff changeset
330 :height (floor (* point-size 10))))))))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (defun gamegrid-initialize-display ()
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (setq gamegrid-display-mode (gamegrid-display-type))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (setq gamegrid-display-table (make-display-table))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (setq gamegrid-face-table (make-vector 256 nil))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (loop for c from 0 to 255 do
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (let* ((spec (aref gamegrid-display-options c))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (glyph (gamegrid-make-glyph (car spec) (caddr spec)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (face (gamegrid-make-face (cadr spec) (caddr spec))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (aset gamegrid-face-table c face)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (aset gamegrid-display-table c glyph)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (gamegrid-setup-default-font)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (put-text-property (1- (point))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (point)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 'face
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (aref gamegrid-face-table c))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (defun gamegrid-cell-offset (x y)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (+ gamegrid-buffer-start
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (* (1+ gamegrid-buffer-width) y)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 x))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 ;; ;;;;;;;;;;;;;;;; grid functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (defun gamegrid-get-cell (x y)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (char-after (gamegrid-cell-offset x y)))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (defun gamegrid-set-cell (x y c)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (save-excursion
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (let ((buffer-read-only nil))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (goto-char (gamegrid-cell-offset x y))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (delete-char 1)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (insert-char c 1)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (gamegrid-set-face c))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (defun gamegrid-init-buffer (width height blank)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (setq gamegrid-buffer-width width
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 gamegrid-buffer-height height)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (let ((line (concat
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (make-string width blank)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 "\n"))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (buffer-read-only nil))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (erase-buffer)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (setq gamegrid-buffer-start (point))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (goto-char (point-min))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (defun gamegrid-init (options)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (setq buffer-read-only t
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 truncate-lines t
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 gamegrid-display-options options)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (buffer-disable-undo (current-buffer))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (gamegrid-initialize-display))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 ;; ;;;;;;;;;;;;;;;; timer functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (defun gamegrid-start-timer (period func)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (setq gamegrid-timer
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (if (featurep 'itimer)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (start-itimer "Gamegrid"
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 func
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 period
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 period
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 nil
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 t
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (current-buffer))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (run-with-timer period
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 period
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 func
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (current-buffer)))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (defun gamegrid-set-timer (delay)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (if gamegrid-timer
64390
d5c99d67c76d (gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
419 (if (fboundp 'set-itimer-restart)
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (set-itimer-restart gamegrid-timer delay)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (timer-set-time gamegrid-timer
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (list (aref gamegrid-timer 1)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (aref gamegrid-timer 2)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (aref gamegrid-timer 3))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 delay))))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (defun gamegrid-kill-timer ()
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (if gamegrid-timer
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (if (featurep 'itimer)
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (delete-itimer gamegrid-timer)
75483
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
431 (cancel-timer gamegrid-timer)))
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (setq gamegrid-timer nil))
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 ;; ;;;;;;;;;;;;;;; high score functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (defun gamegrid-add-score (file score)
49986
755c2ca7f6cf (gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 49598
diff changeset
437 "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
438
755c2ca7f6cf (gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 49598
diff changeset
439 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
440 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
441 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
442 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
443 `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
444 necessary.
755c2ca7f6cf (gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 49598
diff changeset
445
755c2ca7f6cf (gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 49598
diff changeset
446 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
447 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
448 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
449 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
450
755c2ca7f6cf (gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 49598
diff changeset
451 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
452 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
453 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
454 (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
455 ((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
456 (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
457 (t
9bdd94e7a205 (gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents: 44494
diff changeset
458 (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
459
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
460
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 ;; 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
462
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 ;; 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
464 ;; 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
465 ;; `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
466 ;; 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
467 ;;
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 ;; 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
469 ;; 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
470 ;; 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
471 ;; 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
472 ;; "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
473 ;; 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
474 ;;
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 ;; 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
476 ;; 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
477 ;; `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
478 ;; 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
479 ;; 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
480 ;;
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 ;; 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
482 ;; 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
483 ;; 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
484
64390
d5c99d67c76d (gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
485 (defvar gamegrid-shared-game-dir)
d5c99d67c76d (gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
486
44565
9bdd94e7a205 (gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents: 44494
diff changeset
487 (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
488 (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
489 (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
490 (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
491 (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
492 exec-directory))
49986
755c2ca7f6cf (gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 49598
diff changeset
493 #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
494 (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
495 (gamegrid-add-score-insecure file score))
64390
d5c99d67c76d (gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
496 ((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
497 (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
498 ;; 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
499 ;; system-wide score file.
64390
d5c99d67c76d (gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
500 (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
501 (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
502 ;; 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
503 ;; directory.
64390
d5c99d67c76d (gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
504 (gamegrid-shared-game-dir
d5c99d67c76d (gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
505 ;; 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
506 ;; "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
507 (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
508 (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
509 (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
510 (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
511 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
512 (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
513 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
514 (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
515 (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
516 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
517 (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
518 (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
519 (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
520 (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
521 (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
522
64390
d5c99d67c76d (gamegrid-shared-game-dir): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 64085
diff changeset
523 (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
524 (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
525 (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
526 (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
527 (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
528 " <"
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 (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
530 (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 ((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
532 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 (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
534 "> "
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 (current-time-string))))
75483
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
536 ;; 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
537 (with-local-quit
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
538 (apply
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
539 'call-process
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
540 (append
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
541 (list
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
542 (expand-file-name "update-game-score" exec-directory)
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
543 nil errbuf nil
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
544 "-m" (int-to-string gamegrid-score-file-length)
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
545 "-d" (if gamegrid-shared-game-dir
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
546 (expand-file-name shared-game-score-directory)
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
547 (file-name-directory target))
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
548 file
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
549 (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
550 marker-string))))
44494
bca3cc7821fe Fix previous change.
Colin Walters <walters@gnu.org>
parents: 44483
diff changeset
551 (if (buffer-modified-p errbuf)
bca3cc7821fe Fix previous change.
Colin Walters <walters@gnu.org>
parents: 44483
diff changeset
552 (progn
bca3cc7821fe Fix previous change.
Colin Walters <walters@gnu.org>
parents: 44483
diff changeset
553 (display-buffer errbuf)
bca3cc7821fe Fix previous change.
Colin Walters <walters@gnu.org>
parents: 44483
diff changeset
554 (error "Failed to update game score file"))
bca3cc7821fe Fix previous change.
Colin Walters <walters@gnu.org>
parents: 44483
diff changeset
555 (kill-buffer errbuf))
75483
4b3089985bc1 (gamegrid-kill-timer): Cancel timer directly.
Chong Yidong <cyd@stupidchicken.com>
parents: 75347
diff changeset
556 (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
557 (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
558 (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
559 (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
560 (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
561 (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
562 (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
563 (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
564 (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
565 (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
566 " " (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
567 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
568 (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
569
49986
755c2ca7f6cf (gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 49598
diff changeset
570 (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
571 (save-excursion
49986
755c2ca7f6cf (gamegrid-add-score): Add info to docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 49598
diff changeset
572 (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
573 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
574 (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
575 (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
576 (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
577 (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
578 score
9bdd94e7a205 (gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents: 44494
diff changeset
579 (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
580 (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
581 (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
582 (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 ((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
584 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 (t ""))))
54716
1ffff21d0989 (gamegrid-add-score-insecure): Use sort-fields.
Jesper Harder <harder@ifa.au.dk>
parents: 52401
diff changeset
586 (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
587 (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
588 (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
589 (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
590 (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
591 (save-buffer)))
9bdd94e7a205 (gamegrid-add-score-with-update-game-score): Renamed from `gamegrid-add-score'.
Colin Walters <walters@gnu.org>
parents: 44494
diff changeset
592
22490
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595
75a50246a099 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (provide 'gamegrid)
38425
c6e12c6b1498 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 22490
diff changeset
597
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 50734
diff changeset
598 ;;; 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
599 ;;; gamegrid.el ends here